├── .gitignore ├── JavaScriptCore ├── deps │ ├── ASL.dll │ ├── CoreFoundation.dll │ ├── JavaScriptCore.dll │ ├── WTF.dll │ ├── icudt49.dll │ ├── libdispatch.dll │ ├── libicuin.dll │ ├── libicuuc.dll │ └── objc.dll ├── include │ └── JavaScriptCore │ │ ├── APICast.h │ │ ├── APIShims.h │ │ ├── JSBase.h │ │ ├── JSContextRef.h │ │ ├── JSContextRefPrivate.h │ │ ├── JSObjectRef.h │ │ ├── JSObjectRefPrivate.h │ │ ├── JSRetainPtr.h │ │ ├── JSStringRef.h │ │ ├── JSStringRefBSTR.h │ │ ├── JSStringRefCF.h │ │ ├── JSValueRef.h │ │ ├── JSWeakObjectMapRefInternal.h │ │ ├── JSWeakObjectMapRefPrivate.h │ │ ├── JavaScript.h │ │ ├── JavaScriptCore.h │ │ ├── OpaqueJSString.h │ │ └── WebKitAvailability.h └── lib │ └── JavaScriptCore.lib ├── LICENSE.md ├── package.json ├── packager.sh ├── react-native.sln ├── readme.md ├── src ├── JSCoreExecutor │ ├── JSCoreExecutor.csproj │ ├── JavaScriptCoreExecutor.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── ReactNative │ ├── Framework │ │ ├── Converters │ │ │ ├── ColorToBrushConverter.cs │ │ │ └── StringToOrientationConverter.cs │ │ ├── EventDispatcher.cs │ │ ├── ExtensionMethods.cs │ │ ├── IBridgeModule.cs │ │ ├── IJavaScriptExecutor.cs │ │ ├── IReactAssemblyProvider.cs │ │ ├── IReactBridge.cs │ │ ├── ModuleData.cs │ │ ├── ModuleLoader.cs │ │ ├── ModuleMethod.cs │ │ ├── ReactBridgeImpl.cs │ │ ├── ReactComponentBase.cs │ │ ├── ReactComponentData.cs │ │ ├── ReactContainerComponentBase.cs │ │ ├── ReactEventsExtensions.cs │ │ ├── ReactMethodAttribute.cs │ │ ├── ReactModuleAttribute.cs │ │ ├── RelayCommand.cs │ │ ├── UIManager.cs │ │ ├── ViewManager.cs │ │ ├── Views │ │ │ ├── ButtonViewManager.cs │ │ │ ├── ContainerViewManager.cs │ │ │ ├── ReactItemsControl.cs │ │ │ ├── ReactRootViewModel.cs │ │ │ ├── ReactTextBlockView.cs │ │ │ ├── StackPanelViewManager.cs │ │ │ ├── TextBlockViewManager.cs │ │ │ └── VisualTreeExtensions.cs │ │ └── WebSocketExecutor.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ReactNative.csproj │ └── packages.config ├── SampleApp │ ├── App.config │ ├── App.xaml │ ├── App.xaml.cs │ ├── CefJavascriptExecutor.cs │ ├── CefSampleView.xaml │ ├── CefSampleView.xaml.cs │ ├── CefSampleViewModel.cs │ ├── IShell.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── SampleApp.csproj │ ├── SampleAppBootstrapper.cs │ ├── ShellView.xaml │ ├── ShellView.xaml.cs │ ├── ShellViewModel.cs │ ├── WebSocketSampleView.xaml │ ├── WebSocketSampleView.xaml.cs │ ├── WebSocketSampleViewModel.cs │ └── packages.config └── react-native │ ├── AssemblyInfo.cpp │ ├── JSCoreMarshal.cpp │ ├── JSCoreMarshal.h │ ├── JSCoreObjectWrapper.cpp │ ├── JSCoreObjectWrapper.h │ ├── JSObject.cpp │ ├── JSObject.h │ ├── Logger.cpp │ ├── Logger.h │ ├── MyWrapper.cpp │ ├── MyWrapper.h │ ├── ReadMe.txt │ ├── Stdafx.cpp │ ├── Stdafx.h │ ├── app.aps │ ├── app.ico │ ├── app.rc │ ├── react-native.cpp │ ├── react-native.h │ ├── react-native.vcxproj │ ├── react-native.vcxproj.filters │ └── resource.h └── wpf ├── Button.js ├── Container.js ├── ReactNativeDefaultInjection.wpf.js ├── StackPanel.js ├── TextBlock.js ├── index.ios.js ├── react-native-wpf.js └── renderApplication.wpf.js /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | .vs/ 3 | bin/ 4 | obj/ 5 | Debug/ 6 | Release/ 7 | ipch/ 8 | node_modules/ 9 | packages/ 10 | 11 | *.sdf 12 | *.opensdf 13 | *.suo 14 | *.user 15 | *.log 16 | -------------------------------------------------------------------------------- /JavaScriptCore/deps/ASL.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/ASL.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/CoreFoundation.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/CoreFoundation.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/JavaScriptCore.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/JavaScriptCore.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/WTF.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/WTF.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/icudt49.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/icudt49.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/libdispatch.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/libdispatch.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/libicuin.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/libicuin.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/libicuuc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/libicuuc.dll -------------------------------------------------------------------------------- /JavaScriptCore/deps/objc.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/deps/objc.dll -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/APICast.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef APICast_h 27 | #define APICast_h 28 | 29 | #include "JSAPIValueWrapper.h" 30 | #include "JSGlobalObject.h" 31 | #include "JSValue.h" 32 | #include 33 | 34 | namespace JSC { 35 | class ExecState; 36 | class PropertyNameArray; 37 | class JSGlobalData; 38 | class JSObject; 39 | class JSValue; 40 | } 41 | 42 | typedef const struct OpaqueJSContextGroup* JSContextGroupRef; 43 | typedef const struct OpaqueJSContext* JSContextRef; 44 | typedef struct OpaqueJSContext* JSGlobalContextRef; 45 | typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; 46 | typedef const struct OpaqueJSValue* JSValueRef; 47 | typedef struct OpaqueJSValue* JSObjectRef; 48 | 49 | /* Opaque typing convenience methods */ 50 | 51 | inline JSC::ExecState* toJS(JSContextRef c) 52 | { 53 | ASSERT(c); 54 | return reinterpret_cast(const_cast(c)); 55 | } 56 | 57 | inline JSC::ExecState* toJS(JSGlobalContextRef c) 58 | { 59 | ASSERT(c); 60 | return reinterpret_cast(c); 61 | } 62 | 63 | inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v) 64 | { 65 | ASSERT_UNUSED(exec, exec); 66 | ASSERT(v); 67 | #if USE(JSVALUE32_64) 68 | JSC::JSCell* jsCell = reinterpret_cast(const_cast(v)); 69 | if (!jsCell) 70 | return JSC::JSValue(); 71 | if (jsCell->isAPIValueWrapper()) 72 | return static_cast(jsCell)->value(); 73 | return jsCell; 74 | #else 75 | return JSC::JSValue::decode(reinterpret_cast(const_cast(v))); 76 | #endif 77 | } 78 | 79 | inline JSC::JSValue toJSForGC(JSC::ExecState* exec, JSValueRef v) 80 | { 81 | ASSERT_UNUSED(exec, exec); 82 | ASSERT(v); 83 | #if USE(JSVALUE32_64) 84 | JSC::JSCell* jsCell = reinterpret_cast(const_cast(v)); 85 | if (!jsCell) 86 | return JSC::JSValue(); 87 | return jsCell; 88 | #else 89 | return JSC::JSValue::decode(reinterpret_cast(const_cast(v))); 90 | #endif 91 | } 92 | 93 | inline JSC::JSObject* toJS(JSObjectRef o) 94 | { 95 | return reinterpret_cast(o); 96 | } 97 | 98 | inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a) 99 | { 100 | return reinterpret_cast(a); 101 | } 102 | 103 | inline JSC::JSGlobalData* toJS(JSContextGroupRef g) 104 | { 105 | return reinterpret_cast(const_cast(g)); 106 | } 107 | 108 | inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v) 109 | { 110 | #if USE(JSVALUE32_64) 111 | if (!v) 112 | return 0; 113 | if (!v.isCell()) 114 | return reinterpret_cast(JSC::jsAPIValueWrapper(exec, v).asCell()); 115 | return reinterpret_cast(v.asCell()); 116 | #else 117 | UNUSED_PARAM(exec); 118 | return reinterpret_cast(JSC::JSValue::encode(v)); 119 | #endif 120 | } 121 | 122 | inline JSObjectRef toRef(JSC::JSObject* o) 123 | { 124 | return reinterpret_cast(o); 125 | } 126 | 127 | inline JSObjectRef toRef(const JSC::JSObject* o) 128 | { 129 | return reinterpret_cast(const_cast(o)); 130 | } 131 | 132 | inline JSContextRef toRef(JSC::ExecState* e) 133 | { 134 | return reinterpret_cast(e); 135 | } 136 | 137 | inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e) 138 | { 139 | ASSERT(e == e->lexicalGlobalObject()->globalExec()); 140 | return reinterpret_cast(e); 141 | } 142 | 143 | inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l) 144 | { 145 | return reinterpret_cast(l); 146 | } 147 | 148 | inline JSContextGroupRef toRef(JSC::JSGlobalData* g) 149 | { 150 | return reinterpret_cast(g); 151 | } 152 | 153 | #endif // APICast_h 154 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/APIShims.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef APIShims_h 27 | #define APIShims_h 28 | 29 | #include "CallFrame.h" 30 | #include "GCActivityCallback.h" 31 | #include "JSLock.h" 32 | #include 33 | 34 | namespace JSC { 35 | 36 | class APIEntryShimWithoutLock { 37 | protected: 38 | APIEntryShimWithoutLock(JSGlobalData* globalData, bool registerThread) 39 | : m_globalData(globalData) 40 | , m_entryIdentifierTable(wtfThreadData().setCurrentIdentifierTable(globalData->identifierTable)) 41 | { 42 | UNUSED_PARAM(registerThread); 43 | if (registerThread) 44 | globalData->heap.machineThreads().addCurrentThread(); 45 | m_globalData->heap.activityCallback()->synchronize(); 46 | m_globalData->timeoutChecker.start(); 47 | } 48 | 49 | ~APIEntryShimWithoutLock() 50 | { 51 | m_globalData->timeoutChecker.stop(); 52 | wtfThreadData().setCurrentIdentifierTable(m_entryIdentifierTable); 53 | } 54 | 55 | private: 56 | JSGlobalData* m_globalData; 57 | IdentifierTable* m_entryIdentifierTable; 58 | }; 59 | 60 | class APIEntryShim : public APIEntryShimWithoutLock { 61 | public: 62 | // Normal API entry 63 | APIEntryShim(ExecState* exec, bool registerThread = true) 64 | : APIEntryShimWithoutLock(&exec->globalData(), registerThread) 65 | , m_lock(exec) 66 | { 67 | } 68 | 69 | // JSPropertyNameAccumulator only has a globalData. 70 | APIEntryShim(JSGlobalData* globalData, bool registerThread = true) 71 | : APIEntryShimWithoutLock(globalData, registerThread) 72 | , m_lock(globalData->isSharedInstance() ? LockForReal : SilenceAssertionsOnly) 73 | { 74 | } 75 | 76 | private: 77 | JSLock m_lock; 78 | }; 79 | 80 | class APICallbackShim { 81 | public: 82 | APICallbackShim(ExecState* exec) 83 | : m_dropAllLocks(exec) 84 | , m_globalData(&exec->globalData()) 85 | { 86 | wtfThreadData().resetCurrentIdentifierTable(); 87 | } 88 | 89 | ~APICallbackShim() 90 | { 91 | m_globalData->heap.activityCallback()->synchronize(); 92 | wtfThreadData().setCurrentIdentifierTable(m_globalData->identifierTable); 93 | } 94 | 95 | private: 96 | JSLock::DropAllLocks m_dropAllLocks; 97 | JSGlobalData* m_globalData; 98 | }; 99 | 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSBase_h 27 | #define JSBase_h 28 | 29 | #ifndef __cplusplus 30 | #include 31 | #endif 32 | 33 | /* JavaScript engine interface */ 34 | 35 | /*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */ 36 | typedef const struct OpaqueJSContextGroup* JSContextGroupRef; 37 | 38 | /*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */ 39 | typedef const struct OpaqueJSContext* JSContextRef; 40 | 41 | /*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */ 42 | typedef struct OpaqueJSContext* JSGlobalContextRef; 43 | 44 | /*! @typedef JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript. */ 45 | typedef struct OpaqueJSString* JSStringRef; 46 | 47 | /*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */ 48 | typedef struct OpaqueJSClass* JSClassRef; 49 | 50 | /*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */ 51 | typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef; 52 | 53 | /*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */ 54 | typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef; 55 | 56 | 57 | /* JavaScript data types */ 58 | 59 | /*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */ 60 | typedef const struct OpaqueJSValue* JSValueRef; 61 | 62 | /*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */ 63 | typedef struct OpaqueJSValue* JSObjectRef; 64 | 65 | /* JavaScript symbol exports */ 66 | /* These rules should stay the same as in WebKit2/Shared/API/c/WKBase.h */ 67 | 68 | #undef JS_EXPORT 69 | #if defined(JS_NO_EXPORT) 70 | #define JS_EXPORT 71 | #elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__) 72 | #define JS_EXPORT __attribute__((visibility("default"))) 73 | #elif defined(WIN32) || defined(_WIN32) || defined(_WIN32_WCE) || defined(__CC_ARM) || defined(__ARMCC__) 74 | #if defined(BUILDING_JavaScriptCore) || defined(BUILDING_WTF) 75 | #define JS_EXPORT __declspec(dllexport) 76 | #else 77 | #define JS_EXPORT __declspec(dllimport) 78 | #endif 79 | #else /* !defined(JS_NO_EXPORT) */ 80 | #define JS_EXPORT 81 | #endif /* defined(JS_NO_EXPORT) */ 82 | 83 | /* JS tests uses WTF but has no config.h, so we need to set the export defines here. */ 84 | #ifndef WTF_EXPORT_PRIVATE 85 | #define WTF_EXPORT_PRIVATE JS_EXPORT 86 | #endif 87 | 88 | #ifdef __cplusplus 89 | extern "C" { 90 | #endif 91 | 92 | /* Script Evaluation */ 93 | 94 | /*! 95 | @function JSEvaluateScript 96 | @abstract Evaluates a string of JavaScript. 97 | @param ctx The execution context to use. 98 | @param script A JSString containing the script to evaluate. 99 | @param thisObject The object to use as "this," or NULL to use the global object as "this." 100 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 101 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. 102 | @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception. 103 | @result The JSValue that results from evaluating script, or NULL if an exception is thrown. 104 | */ 105 | JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 106 | 107 | /*! 108 | @function JSCheckScriptSyntax 109 | @abstract Checks for syntax errors in a string of JavaScript. 110 | @param ctx The execution context to use. 111 | @param script A JSString containing the script to check for syntax errors. 112 | @param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions. 113 | @param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. 114 | @param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception. 115 | @result true if the script is syntactically correct, otherwise false. 116 | */ 117 | JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception); 118 | 119 | /*! 120 | @function JSGarbageCollect 121 | @abstract Performs a JavaScript garbage collection. 122 | @param ctx The execution context to use. 123 | @discussion JavaScript values that are on the machine stack, in a register, 124 | protected by JSValueProtect, set as the global object of an execution context, 125 | or reachable from any such value will not be collected. 126 | 127 | During JavaScript execution, you are not required to call this function; the 128 | JavaScript engine will garbage collect as needed. JavaScript values created 129 | within a context group are automatically destroyed when the last reference 130 | to the context group is released. 131 | */ 132 | JS_EXPORT void JSGarbageCollect(JSContextRef ctx); 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* JSBase_h */ 139 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSContextRef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSContextRef_h 27 | #define JSContextRef_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifndef __cplusplus 34 | #include 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /*! 42 | @function 43 | @abstract Creates a JavaScript context group. 44 | @discussion A JSContextGroup associates JavaScript contexts with one another. 45 | Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging 46 | JavaScript objects between contexts in different groups will produce undefined behavior. 47 | When objects from the same context group are used in multiple threads, explicit 48 | synchronization is required. 49 | @result The created JSContextGroup. 50 | */ 51 | JS_EXPORT JSContextGroupRef JSContextGroupCreate() AVAILABLE_IN_WEBKIT_VERSION_4_0; 52 | 53 | /*! 54 | @function 55 | @abstract Retains a JavaScript context group. 56 | @param group The JSContextGroup to retain. 57 | @result A JSContextGroup that is the same as group. 58 | */ 59 | JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) AVAILABLE_IN_WEBKIT_VERSION_4_0; 60 | 61 | /*! 62 | @function 63 | @abstract Releases a JavaScript context group. 64 | @param group The JSContextGroup to release. 65 | */ 66 | JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) AVAILABLE_IN_WEBKIT_VERSION_4_0; 67 | 68 | /*! 69 | @function 70 | @abstract Creates a global JavaScript execution context. 71 | @discussion JSGlobalContextCreate allocates a global object and populates it with all the 72 | built-in JavaScript objects, such as Object, Function, String, and Array. 73 | 74 | In WebKit version 4.0 and later, the context is created in a unique context group. 75 | Therefore, scripts may execute in it concurrently with scripts executing in other contexts. 76 | However, you may not use values created in the context in other contexts. 77 | @param globalObjectClass The class to use when creating the global object. Pass 78 | NULL to use the default object class. 79 | @result A JSGlobalContext with a global object of class globalObjectClass. 80 | */ 81 | JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER; 82 | 83 | /*! 84 | @function 85 | @abstract Creates a global JavaScript execution context in the context group provided. 86 | @discussion JSGlobalContextCreateInGroup allocates a global object and populates it with 87 | all the built-in JavaScript objects, such as Object, Function, String, and Array. 88 | @param globalObjectClass The class to use when creating the global object. Pass 89 | NULL to use the default object class. 90 | @param group The context group to use. The created global context retains the group. 91 | Pass NULL to create a unique group for the context. 92 | @result A JSGlobalContext with a global object of class globalObjectClass and a context 93 | group equal to group. 94 | */ 95 | JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) AVAILABLE_IN_WEBKIT_VERSION_4_0; 96 | 97 | /*! 98 | @function 99 | @abstract Retains a global JavaScript execution context. 100 | @param ctx The JSGlobalContext to retain. 101 | @result A JSGlobalContext that is the same as ctx. 102 | */ 103 | JS_EXPORT JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx); 104 | 105 | /*! 106 | @function 107 | @abstract Releases a global JavaScript execution context. 108 | @param ctx The JSGlobalContext to release. 109 | */ 110 | JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx); 111 | 112 | /*! 113 | @function 114 | @abstract Gets the global object of a JavaScript execution context. 115 | @param ctx The JSContext whose global object you want to get. 116 | @result ctx's global object. 117 | */ 118 | JS_EXPORT JSObjectRef JSContextGetGlobalObject(JSContextRef ctx); 119 | 120 | /*! 121 | @function 122 | @abstract Gets the context group to which a JavaScript execution context belongs. 123 | @param ctx The JSContext whose group you want to get. 124 | @result ctx's group. 125 | */ 126 | JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) AVAILABLE_IN_WEBKIT_VERSION_4_0; 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif /* JSContextRef_h */ 133 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSContextRefPrivate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSContextRefPrivate_h 27 | #define JSContextRefPrivate_h 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifndef __cplusplus 34 | #include 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /*! 42 | @function 43 | @abstract Gets the global context of a JavaScript execution context. 44 | @param ctx The JSContext whose global context you want to get. 45 | @result ctx's global context. 46 | */ 47 | JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx); 48 | 49 | 50 | /*! 51 | @function 52 | @abstract Gets a Backtrace for the existing context 53 | @param ctx The JSContext whose backtrace you want to get 54 | @result A string containing the backtrace 55 | */ 56 | JS_EXPORT JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize) AVAILABLE_IN_WEBKIT_VERSION_4_0; 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* JSContextRefPrivate_h */ 63 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSObjectRefPrivate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 | * THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSObjectRefPrivate_h 27 | #define JSObjectRefPrivate_h 28 | 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /*! 36 | @function 37 | @abstract Sets a private property on an object. This private property cannot be accessed from within JavaScript. 38 | @param ctx The execution context to use. 39 | @param object The JSObject whose private property you want to set. 40 | @param propertyName A JSString containing the property's name. 41 | @param value A JSValue to use as the property's value. This may be NULL. 42 | @result true if object can store private data, otherwise false. 43 | @discussion This API allows you to store JS values directly an object in a way that will be ensure that they are kept alive without exposing them to JavaScript code and without introducing the reference cycles that may occur when using JSValueProtect. 44 | 45 | The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private properties. 46 | */ 47 | JS_EXPORT bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value); 48 | 49 | /*! 50 | @function 51 | @abstract Gets a private property from an object. 52 | @param ctx The execution context to use. 53 | @param object The JSObject whose private property you want to get. 54 | @param propertyName A JSString containing the property's name. 55 | @result The property's value if object has the property, otherwise NULL. 56 | */ 57 | JS_EXPORT JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 58 | 59 | /*! 60 | @function 61 | @abstract Deletes a private property from an object. 62 | @param ctx The execution context to use. 63 | @param object The JSObject whose private property you want to delete. 64 | @param propertyName A JSString containing the property's name. 65 | @result true if object can store private data, otherwise false. 66 | @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data. 67 | */ 68 | JS_EXPORT bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif // JSObjectRefPrivate_h 75 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSRetainPtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 | * its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef JSRetainPtr_h 30 | #define JSRetainPtr_h 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | inline void JSRetain(JSStringRef string) { JSStringRetain(string); } 37 | inline void JSRelease(JSStringRef string) { JSStringRelease(string); } 38 | inline void JSRetain(JSGlobalContextRef context) { JSGlobalContextRetain(context); } 39 | inline void JSRelease(JSGlobalContextRef context) { JSGlobalContextRelease(context); } 40 | 41 | enum AdoptTag { Adopt }; 42 | 43 | template class JSRetainPtr { 44 | public: 45 | JSRetainPtr() : m_ptr(0) { } 46 | JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); } 47 | JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { } 48 | JSRetainPtr(const JSRetainPtr&); 49 | template JSRetainPtr(const JSRetainPtr&); 50 | ~JSRetainPtr(); 51 | 52 | T get() const { return m_ptr; } 53 | 54 | void clear(); 55 | T leakRef(); 56 | 57 | T operator->() const { return m_ptr; } 58 | 59 | bool operator!() const { return !m_ptr; } 60 | 61 | // This conversion operator allows implicit conversion to bool but not to other integer types. 62 | typedef T JSRetainPtr::*UnspecifiedBoolType; 63 | operator UnspecifiedBoolType() const { return m_ptr ? &JSRetainPtr::m_ptr : 0; } 64 | 65 | JSRetainPtr& operator=(const JSRetainPtr&); 66 | template JSRetainPtr& operator=(const JSRetainPtr&); 67 | JSRetainPtr& operator=(T); 68 | template JSRetainPtr& operator=(U*); 69 | 70 | void adopt(T); 71 | 72 | void swap(JSRetainPtr&); 73 | 74 | private: 75 | T m_ptr; 76 | }; 77 | 78 | template inline JSRetainPtr::JSRetainPtr(const JSRetainPtr& o) 79 | : m_ptr(o.m_ptr) 80 | { 81 | if (m_ptr) 82 | JSRetain(m_ptr); 83 | } 84 | 85 | template template inline JSRetainPtr::JSRetainPtr(const JSRetainPtr& o) 86 | : m_ptr(o.get()) 87 | { 88 | if (m_ptr) 89 | JSRetain(m_ptr); 90 | } 91 | 92 | template inline JSRetainPtr::~JSRetainPtr() 93 | { 94 | if (m_ptr) 95 | JSRelease(m_ptr); 96 | } 97 | 98 | template inline void JSRetainPtr::clear() 99 | { 100 | if (T ptr = m_ptr) { 101 | m_ptr = 0; 102 | JSRelease(ptr); 103 | } 104 | } 105 | 106 | template inline T JSRetainPtr::leakRef() 107 | { 108 | T ptr = m_ptr; 109 | m_ptr = 0; 110 | return ptr; 111 | } 112 | 113 | template inline JSRetainPtr& JSRetainPtr::operator=(const JSRetainPtr& o) 114 | { 115 | T optr = o.get(); 116 | if (optr) 117 | JSRetain(optr); 118 | T ptr = m_ptr; 119 | m_ptr = optr; 120 | if (ptr) 121 | JSRelease(ptr); 122 | return *this; 123 | } 124 | 125 | template template inline JSRetainPtr& JSRetainPtr::operator=(const JSRetainPtr& o) 126 | { 127 | T optr = o.get(); 128 | if (optr) 129 | JSRetain(optr); 130 | T ptr = m_ptr; 131 | m_ptr = optr; 132 | if (ptr) 133 | JSRelease(ptr); 134 | return *this; 135 | } 136 | 137 | template inline JSRetainPtr& JSRetainPtr::operator=(T optr) 138 | { 139 | if (optr) 140 | JSRetain(optr); 141 | T ptr = m_ptr; 142 | m_ptr = optr; 143 | if (ptr) 144 | JSRelease(ptr); 145 | return *this; 146 | } 147 | 148 | template inline void JSRetainPtr::adopt(T optr) 149 | { 150 | T ptr = m_ptr; 151 | m_ptr = optr; 152 | if (ptr) 153 | JSRelease(ptr); 154 | } 155 | 156 | template template inline JSRetainPtr& JSRetainPtr::operator=(U* optr) 157 | { 158 | if (optr) 159 | JSRetain(optr); 160 | T ptr = m_ptr; 161 | m_ptr = optr; 162 | if (ptr) 163 | JSRelease(ptr); 164 | return *this; 165 | } 166 | 167 | template inline void JSRetainPtr::swap(JSRetainPtr& o) 168 | { 169 | std::swap(m_ptr, o.m_ptr); 170 | } 171 | 172 | template inline void swap(JSRetainPtr& a, JSRetainPtr& b) 173 | { 174 | a.swap(b); 175 | } 176 | 177 | template inline bool operator==(const JSRetainPtr& a, const JSRetainPtr& b) 178 | { 179 | return a.get() == b.get(); 180 | } 181 | 182 | template inline bool operator==(const JSRetainPtr& a, U* b) 183 | { 184 | return a.get() == b; 185 | } 186 | 187 | template inline bool operator==(T* a, const JSRetainPtr& b) 188 | { 189 | return a == b.get(); 190 | } 191 | 192 | template inline bool operator!=(const JSRetainPtr& a, const JSRetainPtr& b) 193 | { 194 | return a.get() != b.get(); 195 | } 196 | 197 | template inline bool operator!=(const JSRetainPtr& a, U* b) 198 | { 199 | return a.get() != b; 200 | } 201 | 202 | template inline bool operator!=(T* a, const JSRetainPtr& b) 203 | { 204 | return a != b.get(); 205 | } 206 | 207 | 208 | #endif // JSRetainPtr_h 209 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSStringRef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSStringRef_h 27 | #define JSStringRef_h 28 | 29 | #include 30 | 31 | #ifndef __cplusplus 32 | #include 33 | #endif 34 | #include /* for size_t */ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #if !defined(WIN32) && !defined(_WIN32) \ 41 | && !((defined(__CC_ARM) || defined(__ARMCC__)) && !defined(__linux__)) /* RVCT */ 42 | /*! 43 | @typedef JSChar 44 | @abstract A Unicode character. 45 | */ 46 | typedef unsigned short JSChar; 47 | #else 48 | typedef wchar_t JSChar; 49 | #endif 50 | 51 | /*! 52 | @function 53 | @abstract Creates a JavaScript string from a buffer of Unicode characters. 54 | @param chars The buffer of Unicode characters to copy into the new JSString. 55 | @param numChars The number of characters to copy from the buffer pointed to by chars. 56 | @result A JSString containing chars. Ownership follows the Create Rule. 57 | */ 58 | JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars); 59 | /*! 60 | @function 61 | @abstract Creates a JavaScript string from a null-terminated UTF8 string. 62 | @param string The null-terminated UTF8 string to copy into the new JSString. 63 | @result A JSString containing string. Ownership follows the Create Rule. 64 | */ 65 | JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string); 66 | 67 | /*! 68 | @function 69 | @abstract Retains a JavaScript string. 70 | @param string The JSString to retain. 71 | @result A JSString that is the same as string. 72 | */ 73 | JS_EXPORT JSStringRef JSStringRetain(JSStringRef string); 74 | /*! 75 | @function 76 | @abstract Releases a JavaScript string. 77 | @param string The JSString to release. 78 | */ 79 | JS_EXPORT void JSStringRelease(JSStringRef string); 80 | 81 | /*! 82 | @function 83 | @abstract Returns the number of Unicode characters in a JavaScript string. 84 | @param string The JSString whose length (in Unicode characters) you want to know. 85 | @result The number of Unicode characters stored in string. 86 | */ 87 | JS_EXPORT size_t JSStringGetLength(JSStringRef string); 88 | /*! 89 | @function 90 | @abstract Returns a pointer to the Unicode character buffer that 91 | serves as the backing store for a JavaScript string. 92 | @param string The JSString whose backing store you want to access. 93 | @result A pointer to the Unicode character buffer that serves as string's 94 | backing store, which will be deallocated when string is deallocated. 95 | */ 96 | JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string); 97 | 98 | /*! 99 | @function 100 | @abstract Returns the maximum number of bytes a JavaScript string will 101 | take up if converted into a null-terminated UTF8 string. 102 | @param string The JSString whose maximum converted size (in bytes) you 103 | want to know. 104 | @result The maximum number of bytes that could be required to convert string into a 105 | null-terminated UTF8 string. The number of bytes that the conversion actually ends 106 | up requiring could be less than this, but never more. 107 | */ 108 | JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string); 109 | /*! 110 | @function 111 | @abstract Converts a JavaScript string into a null-terminated UTF8 string, 112 | and copies the result into an external byte buffer. 113 | @param string The source JSString. 114 | @param buffer The destination byte buffer into which to copy a null-terminated 115 | UTF8 representation of string. On return, buffer contains a UTF8 string 116 | representation of string. If bufferSize is too small, buffer will contain only 117 | partial results. If buffer is not at least bufferSize bytes in size, 118 | behavior is undefined. 119 | @param bufferSize The size of the external buffer in bytes. 120 | @result The number of bytes written into buffer (including the null-terminator byte). 121 | */ 122 | JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize); 123 | 124 | /*! 125 | @function 126 | @abstract Tests whether two JavaScript strings match. 127 | @param a The first JSString to test. 128 | @param b The second JSString to test. 129 | @result true if the two strings match, otherwise false. 130 | */ 131 | JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b); 132 | /*! 133 | @function 134 | @abstract Tests whether a JavaScript string matches a null-terminated UTF8 string. 135 | @param a The JSString to test. 136 | @param b The null-terminated UTF8 string to test. 137 | @result true if the two strings match, otherwise false. 138 | */ 139 | JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b); 140 | 141 | #ifdef __cplusplus 142 | } 143 | #endif 144 | 145 | #endif /* JSStringRef_h */ 146 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSStringRefBSTR.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 | * its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef JSStringRefBSTR_h 30 | #define JSStringRefBSTR_h 31 | 32 | #include "JSBase.h" 33 | 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /* COM convenience methods */ 41 | 42 | /*! 43 | @function 44 | @abstract Creates a JavaScript string from a BSTR. 45 | @param string The BSTR to copy into the new JSString. 46 | @result A JSString containing string. Ownership follows the Create Rule. 47 | */ 48 | JS_EXPORT JSStringRef JSStringCreateWithBSTR(const BSTR string); 49 | 50 | /*! 51 | @function 52 | @abstract Creates a BSTR from a JavaScript string. 53 | @param string The JSString to copy into the new BSTR. 54 | @result A BSTR containing string. Ownership follows the Create Rule. 55 | */ 56 | JS_EXPORT BSTR JSStringCopyBSTR(const JSStringRef string); 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* JSStringRefBSTR_h */ 63 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSStringRefCF.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006, 2007 Apple Computer, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSStringRefCF_h 27 | #define JSStringRefCF_h 28 | 29 | #include "JSBase.h" 30 | //#include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* CFString convenience methods */ 37 | 38 | /*! 39 | @function 40 | @abstract Creates a JavaScript string from a CFString. 41 | @discussion This function is optimized to take advantage of cases when 42 | CFStringGetCharactersPtr returns a valid pointer. 43 | @param string The CFString to copy into the new JSString. 44 | @result A JSString containing string. Ownership follows the Create Rule. 45 | */ 46 | //JS_EXPORT JSStringRef JSStringCreateWithCFString(CFStringRef string); 47 | /*! 48 | @function 49 | @abstract Creates a CFString from a JavaScript string. 50 | @param alloc The alloc parameter to pass to CFStringCreate. 51 | @param string The JSString to copy into the new CFString. 52 | @result A CFString containing string. Ownership follows the Create Rule. 53 | */ 54 | //JS_EXPORT CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* JSStringRefCF_h */ 61 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSWeakObjectMapRefInternal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 | * THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSWeakObjectMapRefInternal_h 27 | #define JSWeakObjectMapRefInternal_h 28 | 29 | #include "WeakGCMap.h" 30 | #include 31 | 32 | namespace JSC { 33 | 34 | class JSObject; 35 | 36 | } 37 | 38 | typedef void (*JSWeakMapDestroyedCallback)(struct OpaqueJSWeakObjectMap*, void*); 39 | 40 | typedef JSC::WeakGCMap WeakMapType; 41 | 42 | struct OpaqueJSWeakObjectMap : public RefCounted { 43 | public: 44 | static PassRefPtr create(void* data, JSWeakMapDestroyedCallback callback) 45 | { 46 | return adoptRef(new OpaqueJSWeakObjectMap(data, callback)); 47 | } 48 | 49 | WeakMapType& map() { return m_map; } 50 | 51 | ~OpaqueJSWeakObjectMap() 52 | { 53 | m_callback(this, m_data); 54 | } 55 | 56 | private: 57 | OpaqueJSWeakObjectMap(void* data, JSWeakMapDestroyedCallback callback) 58 | : m_data(data) 59 | , m_callback(callback) 60 | { 61 | } 62 | WeakMapType m_map; 63 | void* m_data; 64 | JSWeakMapDestroyedCallback m_callback; 65 | }; 66 | 67 | 68 | #endif // JSWeakObjectMapInternal_h 69 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JSWeakObjectMapRefPrivate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 | * THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JSWeakObjectMapRefPrivate_h 27 | #define JSWeakObjectMapRefPrivate_h 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /*! @typedef JSWeakObjectMapRef A weak map for storing JSObjectRefs */ 37 | typedef struct OpaqueJSWeakObjectMap* JSWeakObjectMapRef; 38 | 39 | /*! 40 | @typedef JSWeakMapDestroyedCallback 41 | @abstract The callback invoked when a JSWeakObjectMapRef is being destroyed. 42 | @param map The map that is being destroyed. 43 | @param data The private data (if any) that was associated with the map instance. 44 | */ 45 | typedef void (*JSWeakMapDestroyedCallback)(JSWeakObjectMapRef map, void* data); 46 | 47 | /*! 48 | @function 49 | @abstract Creates a weak value map that can be used to reference user defined objects without preventing them from being collected. 50 | @param ctx The execution context to use. 51 | @param data A void* to set as the map's private data. Pass NULL to specify no private data. 52 | @param destructor A function to call when the weak map is destroyed. 53 | @result A JSWeakObjectMapRef bound to the given context, data and destructor. 54 | @discussion The JSWeakObjectMapRef can be used as a storage mechanism to hold custom JS objects without forcing those objects to 55 | remain live as JSValueProtect would. 56 | */ 57 | JS_EXPORT JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef ctx, void* data, JSWeakMapDestroyedCallback destructor); 58 | 59 | /*! 60 | @function 61 | @abstract Associates a JSObjectRef with the given key in a JSWeakObjectMap. 62 | @param ctx The execution context to use. 63 | @param map The map to operate on. 64 | @param key The key to associate a weak reference with. 65 | @param object The user defined object to associate with the key. 66 | */ 67 | JS_EXPORT void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef); 68 | 69 | /*! 70 | @function 71 | @abstract Retrieves the JSObjectRef associated with a key. 72 | @param ctx The execution context to use. 73 | @param map The map to query. 74 | @param key The key to search for. 75 | @result Either the live object associated with the provided key, or NULL. 76 | */ 77 | JS_EXPORT JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key); 78 | 79 | /*! 80 | @function 81 | @abstract Removes the entry for the given key if the key is present, otherwise it has no effect. 82 | @param ctx The execution context to use. 83 | @param map The map to use. 84 | @param key The key to remove. 85 | */ 86 | JS_EXPORT void JSWeakObjectMapRemove(JSContextRef ctx, JSWeakObjectMapRef map, void* key); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif // JSWeakObjectMapPrivate_h 93 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JavaScript.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 Apple Inc. All rights reserved. 3 | * Copyright (C) 2008 Alp Toker 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef JavaScript_h 28 | #define JavaScript_h 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif /* JavaScript_h */ 37 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/JavaScriptCore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef JavaScriptCore_h 27 | #define JavaScriptCore_h 28 | 29 | #include 30 | #include 31 | 32 | #endif /* JavaScriptCore_h */ 33 | -------------------------------------------------------------------------------- /JavaScriptCore/include/JavaScriptCore/OpaqueJSString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef OpaqueJSString_h 27 | #define OpaqueJSString_h 28 | 29 | #include 30 | #include 31 | 32 | namespace JSC { 33 | class Identifier; 34 | class JSGlobalData; 35 | } 36 | 37 | struct OpaqueJSString : public ThreadSafeRefCounted { 38 | 39 | static PassRefPtr create() // null 40 | { 41 | return adoptRef(new OpaqueJSString); 42 | } 43 | 44 | static PassRefPtr create(const UChar* characters, unsigned length) 45 | { 46 | return adoptRef(new OpaqueJSString(characters, length)); 47 | } 48 | 49 | JS_EXPORT_PRIVATE static PassRefPtr create(const JSC::UString&); 50 | 51 | UChar* characters() { return this ? m_characters : 0; } 52 | unsigned length() { return this ? m_length : 0; } 53 | 54 | JSC::UString ustring() const; 55 | JSC::Identifier identifier(JSC::JSGlobalData*) const; 56 | 57 | private: 58 | friend class WTF::ThreadSafeRefCounted; 59 | 60 | OpaqueJSString() 61 | : m_characters(0) 62 | , m_length(0) 63 | { 64 | } 65 | 66 | OpaqueJSString(const UChar* characters, unsigned length) 67 | : m_length(length) 68 | { 69 | m_characters = new UChar[length]; 70 | memcpy(m_characters, characters, length * sizeof(UChar)); 71 | } 72 | 73 | ~OpaqueJSString() 74 | { 75 | delete[] m_characters; 76 | } 77 | 78 | UChar* m_characters; 79 | unsigned m_length; 80 | }; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /JavaScriptCore/lib/JavaScriptCore.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/JavaScriptCore/lib/JavaScriptCore.lib -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Joseph T. McBride 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-wpf", 3 | "version": "0.0.1", 4 | "description": "React Native for WPF", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "bundle":"react-native bundle --platform wpf --root ./wpf --out ./build/main.jsbundle", 9 | "wpf":"packager.sh --port 3333 --root ./wpf" 10 | }, 11 | "author": "", 12 | "license": "MIT", 13 | "devDependencies": { 14 | "babel": "^5.8.21", 15 | "babel-core": "^5.8.22", 16 | "babel-loader": "^5.3.2", 17 | "webpack": "^1.11.0" 18 | }, 19 | "dependencies": { 20 | "react-native": "^0.9.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | "node_modules/react-native/packager/packager.sh" "$@" 4 | -------------------------------------------------------------------------------- /react-native.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNative", "src\ReactNative\ReactNative.csproj", "{EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "src\SampleApp\SampleApp.csproj", "{DCBB1279-E1E8-4790-A306-6EDC62A539B6}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JSCoreExecutor", "src\JSCoreExecutor\JSCoreExecutor.csproj", "{5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "react-native", "src\react-native\react-native.vcxproj", "{447594E4-FB31-4097-A8E5-D58290AD1CF4}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Debug|Mixed Platforms = Debug|Mixed Platforms 18 | Debug|Win32 = Debug|Win32 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Release|Any CPU = Release|Any CPU 22 | Release|Mixed Platforms = Release|Mixed Platforms 23 | Release|Win32 = Release|Win32 24 | Release|x64 = Release|x64 25 | Release|x86 = Release|x86 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 31 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 32 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Win32.ActiveCfg = Debug|Any CPU 33 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|Win32.Build.0 = Debug|Any CPU 34 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|x64.Build.0 = Debug|Any CPU 36 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|x86.ActiveCfg = Debug|x86 37 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Debug|x86.Build.0 = Debug|x86 38 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 41 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Mixed Platforms.Build.0 = Release|Any CPU 42 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Win32.ActiveCfg = Release|Any CPU 43 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|Win32.Build.0 = Release|Any CPU 44 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|x64.ActiveCfg = Release|Any CPU 45 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|x64.Build.0 = Release|Any CPU 46 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|x86.ActiveCfg = Release|Any CPU 47 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF}.Release|x86.Build.0 = Release|Any CPU 48 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 51 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 52 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Win32.ActiveCfg = Debug|Any CPU 53 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|Win32.Build.0 = Debug|Any CPU 54 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|x64.ActiveCfg = Debug|Any CPU 55 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|x64.Build.0 = Debug|Any CPU 56 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|x86.ActiveCfg = Debug|x86 57 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Debug|x86.Build.0 = Debug|x86 58 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Any CPU.ActiveCfg = Release|Any CPU 59 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Any CPU.Build.0 = Release|Any CPU 60 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 61 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Mixed Platforms.Build.0 = Release|Any CPU 62 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Win32.ActiveCfg = Release|Any CPU 63 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|Win32.Build.0 = Release|Any CPU 64 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|x64.ActiveCfg = Release|Any CPU 65 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|x64.Build.0 = Release|Any CPU 66 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|x86.ActiveCfg = Release|Any CPU 67 | {DCBB1279-E1E8-4790-A306-6EDC62A539B6}.Release|x86.Build.0 = Release|Any CPU 68 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 69 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Any CPU.Build.0 = Debug|Any CPU 70 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 71 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 72 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Win32.ActiveCfg = Debug|Any CPU 73 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|Win32.Build.0 = Debug|Any CPU 74 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|x64.ActiveCfg = Debug|Any CPU 75 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|x64.Build.0 = Debug|Any CPU 76 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|x86.ActiveCfg = Debug|Any CPU 77 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Debug|x86.Build.0 = Debug|Any CPU 78 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Any CPU.ActiveCfg = Release|Any CPU 79 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Any CPU.Build.0 = Release|Any CPU 80 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 81 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Mixed Platforms.Build.0 = Release|Any CPU 82 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Win32.ActiveCfg = Release|Any CPU 83 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|Win32.Build.0 = Release|Any CPU 84 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|x64.ActiveCfg = Release|Any CPU 85 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|x64.Build.0 = Release|Any CPU 86 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|x86.ActiveCfg = Release|Any CPU 87 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93}.Release|x86.Build.0 = Release|Any CPU 88 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|Any CPU.ActiveCfg = Debug|Win32 89 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 90 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32 91 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|Win32.ActiveCfg = Debug|Win32 92 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|Win32.Build.0 = Debug|Win32 93 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|x64.ActiveCfg = Debug|x64 94 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|x64.Build.0 = Debug|x64 95 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|x86.ActiveCfg = Debug|Win32 96 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Debug|x86.Build.0 = Debug|Win32 97 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|Any CPU.ActiveCfg = Release|Win32 98 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32 99 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|Mixed Platforms.Build.0 = Release|Win32 100 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|Win32.ActiveCfg = Release|Win32 101 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|Win32.Build.0 = Release|Win32 102 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|x64.ActiveCfg = Release|x64 103 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|x64.Build.0 = Release|x64 104 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|x86.ActiveCfg = Release|Win32 105 | {447594E4-FB31-4097-A8E5-D58290AD1CF4}.Release|x86.Build.0 = Release|Win32 106 | EndGlobalSection 107 | GlobalSection(SolutionProperties) = preSolution 108 | HideSolutionNode = FALSE 109 | EndGlobalSection 110 | EndGlobal 111 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # React Native WPF 2 | 3 | [2 minute React Native WPF Demo Video](https://www.youtube.com/watch?v=9n5aJfY0ewY) 4 | 5 | > UPDATE: The official ReactWindows project now appears to support .NET 4.6. https://github.com/ReactWindows/react-native-windows/pull/868 6 | 7 | ![](http://i.imgur.com/ZO9MGLu.png) 8 | 9 | ## Noted Dependencies 10 | 11 | * VS2015 12 | * react-native 0.9.0 13 | * react-native-cli 0.1.4 14 | * JavaScriptCore (written in C) .NET wrapper (included) 15 | * CefSharp (alternate for embedded runtime) 16 | * Caliburn.Micro 17 | 18 | ## Getting Started 19 | 20 | ``` 21 | npm install 22 | ``` 23 | 24 | ``` 25 | npm install -g react-native-cli@0.1.4 26 | ``` 27 | 28 | You will need to edit one of the core React Native files because a custom application renderer is required. Find `AppRegistry.js` file (should be at `node_modules\react-native\Libraries\AppRegistry\AppRegistry.js`) and change `require('renderApplication')` to `require('renderApplicationWPF')`. 29 | 30 | ``` 31 | npm run wpf 32 | ``` 33 | 34 | This will run the React Native packager. Browse to: 35 | 36 | ``` 37 | http://localhost:3333/debugger-ui 38 | ``` 39 | 40 | Build and run the WPF project. This should run and connect to the packager server via websockets. Note that if you do not have C++ installed or do not want to use the JavaScriptCore embedded runtime, you can remove those projects from the solution or set them to not build. 41 | 42 | The sample application source files can be found in the root directory. 43 | 44 | ``` 45 | /wpf/index.ios.js 46 | ``` 47 | 48 | You can build the stand-alone bundle with the following command (you will need react-native-cli installed): 49 | 50 | ``` 51 | npm run bundle 52 | ``` 53 | 54 | ## Help 55 | 56 | * If you are trying to run the JavaScriptCore version, ensure the dlls found in `/JavaScriptCore/deps/` are in the bin directory. 57 | * Sometimes the CefSharp files can get locked during the build process. I've found just canceling the build and re-running it helps. 58 | 59 | ## Why 60 | 61 | This is a prototype to see if react-native could drive WPF. This is not production ready and a lot of this code is "spike code". I am also not a C++ developer so please excuse any atrocities there. The main purpose was to see if this could be integrated into an existing WPF codebase (for the purpose of eventually moving the entire app to the web). If you are starting a new desktop project and want to use JavaScript, use something like github's [Electron](http://electron.atom.io/). 62 | 63 | ## Roadmap 64 | 65 | As of right now I have no plans to further this project, though it would be interesting to see how React 0.14 could change things. As always though, pull requests accepted. 66 | -------------------------------------------------------------------------------- /src/JSCoreExecutor/JSCoreExecutor.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {5DABD3D7-1F18-4BAB-B60E-39BDF3648D93} 8 | Library 9 | Properties 10 | JSCoreExecutor 11 | JSCoreExecutor 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | False 35 | ..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | {447594e4-fb31-4097-a8e5-d58290ad1cf4} 53 | react-native 54 | 55 | 56 | {ea7e20b2-21a4-42b9-b7ea-6cab709fd5af} 57 | ReactNative 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /src/JSCoreExecutor/JavaScriptCoreExecutor.cs: -------------------------------------------------------------------------------- 1 | using reactnative; 2 | using ReactNative.Framework; 3 | using System.Threading.Tasks; 4 | 5 | namespace ReactNative.JavaScriptCore 6 | { 7 | public class JavaScriptCoreExecutor : IJavaScriptExecutor 8 | { 9 | private reactnative.ReactBridge _bridge; 10 | 11 | public Task Execute(string script, string sourceUrl) 12 | { 13 | var result = _bridge.Execute(script); 14 | return Task.FromResult(result); 15 | } 16 | 17 | public Task ExecuteJSCall(string name, string method, object[] arguments) 18 | { 19 | var result = _bridge.ExecuteJSCall(name, method, arguments); 20 | return Task.FromResult(result); 21 | } 22 | 23 | public Task InjectJSON(string objectName, string json) 24 | { 25 | _bridge.InjectJSONText(objectName, json); 26 | return Task.FromResult(true); 27 | } 28 | 29 | public void Setup() 30 | { 31 | _bridge = new ReactBridge(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/JSCoreExecutor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("JSCoreExecutor")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Towers Watson")] 12 | [assembly: AssemblyProduct("JSCoreExecutor")] 13 | [assembly: AssemblyCopyright("Copyright © Towers Watson 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("5dabd3d7-1f18-4bab-b60e-39bdf3648d93")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/Converters/ColorToBrushConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Media; 5 | 6 | namespace ReactNative.Framework.Converters 7 | { 8 | public class ColorToBrushConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | if (value == null) 13 | return new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); 14 | 15 | if (value is Color) 16 | return new SolidColorBrush((Color)value); 17 | 18 | if (value is string) 19 | { 20 | var converter = new BrushConverter(); 21 | return converter.ConvertFromString((string)value); 22 | } 23 | 24 | throw new NotSupportedException("ColorToBrushConverter only supports converting from Color and String"); 25 | } 26 | 27 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 28 | { 29 | throw new NotSupportedException(); 30 | } 31 | 32 | private static Color Parse(string color) 33 | { 34 | var offset = color.StartsWith("#") ? 1 : 0; 35 | 36 | var a = Byte.Parse(color.Substring(0 + offset, 2), NumberStyles.HexNumber); 37 | var r = Byte.Parse(color.Substring(2 + offset, 2), NumberStyles.HexNumber); 38 | var g = Byte.Parse(color.Substring(4 + offset, 2), NumberStyles.HexNumber); 39 | var b = Byte.Parse(color.Substring(6 + offset, 2), NumberStyles.HexNumber); 40 | 41 | return Color.FromArgb(a, r, g, b); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/Converters/StringToOrientationConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Controls; 4 | using System.Windows.Data; 5 | 6 | namespace ReactNative.Framework.Converters 7 | { 8 | public class StringToOrientationConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 11 | { 12 | var result = Orientation.Vertical; 13 | var orientation = value?.ToString(); 14 | Enum.TryParse(orientation, true, out result); 15 | return result; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/EventDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace ReactNative.Framework 5 | { 6 | public abstract class BaseEvent 7 | { 8 | public long? ViewTag { get; set; } 9 | public string EventName { get; set; } 10 | public IDictionary Body { get; set; } 11 | 12 | public abstract string ModuleDotMethod { get; } 13 | } 14 | 15 | public interface IEventDispatcher 16 | { 17 | void SendInputEventWithName(string name, IDictionary body); 18 | } 19 | 20 | public class EventDispatcher : IEventDispatcher 21 | { 22 | private readonly IReactBridge _bridge; 23 | 24 | public EventDispatcher(IReactBridge bridge) 25 | { 26 | _bridge = bridge; 27 | } 28 | 29 | public void SendInputEventWithName(string name, IDictionary body) 30 | { 31 | Debug.Assert(body["target"] is long, "Event body dictionary must include a 'target' property containing the React tag"); 32 | 33 | name = name.NormalizeInputEventName(); 34 | _bridge.ExecuteJSCall("RCTEventEmitter", "receiveEvent", 35 | new[] {body["target"], name, body}); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace ReactNative.Framework 5 | { 6 | public static class ExtensionMethods 7 | { 8 | public static void Apply(this IEnumerable items, Action action) 9 | { 10 | var index = 0; 11 | foreach (var item in items) 12 | { 13 | action(item, index); 14 | index++; 15 | } 16 | } 17 | public static IEnumerable Apply(this IEnumerable items, Func action) 18 | { 19 | var index = 0; 20 | var results = new List(); 21 | foreach (var item in items) 22 | { 23 | var result = action(item, index); 24 | results.Add(result); 25 | index++; 26 | } 27 | 28 | return results; 29 | } 30 | 31 | public static string ToFormat(this string format, params object[] args) 32 | { 33 | return string.Format(format, args); 34 | } 35 | 36 | public static bool IsReactRootView(this IReactComponent component) 37 | { 38 | return component != null && component.ReactTag.HasValue && component.ReactTag.Value%10 == 1; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/IBridgeModule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | public interface IBridgeModule 6 | { 7 | void Initialize(IReactBridge bridge); 8 | 9 | IDictionary ConstantsToExport(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/IJavaScriptExecutor.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | public interface IJavaScriptExecutor 6 | { 7 | Task Execute(string script, string sourceUrl); 8 | Task ExecuteJSCall(string name, string method, object[] arguments); 9 | Task InjectJSON(string objectName, string json); 10 | void Setup(); 11 | } 12 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/IReactAssemblyProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | 5 | namespace ReactNative.Framework 6 | { 7 | public interface IReactAssemblyProvider 8 | { 9 | IEnumerable Assemblies(); 10 | } 11 | 12 | public class ReactAssemblyProvider : IReactAssemblyProvider 13 | { 14 | private readonly Func> _provideAssemblies; 15 | 16 | public ReactAssemblyProvider(Func> provideAssemblies) 17 | { 18 | _provideAssemblies = provideAssemblies; 19 | } 20 | 21 | public IEnumerable Assemblies() 22 | { 23 | return _provideAssemblies(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/IReactBridge.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | 4 | namespace ReactNative.Framework 5 | { 6 | public interface IReactBridge 7 | { 8 | IEnumerable Modules { get; } 9 | 10 | Task LoadApplicationScript(string bundle, string sourceUrl); 11 | 12 | Task RunApplication(string moduleName, long rootTag, IDictionary initialProperties); 13 | 14 | Task Execute(string script, string sourceUrl); 15 | 16 | Task ExecuteJSCall(string name, string method, object[] arguments); 17 | 18 | void Reset(); 19 | } 20 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ModuleData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace ReactNative.Framework 7 | { 8 | public class ModuleData 9 | { 10 | private readonly IBridgeModule _module; 11 | private ModuleMethod[] _methods; 12 | 13 | public ModuleData(int id, string name, IBridgeModule module) 14 | { 15 | Id = id; 16 | Name = name; 17 | _module = module; 18 | } 19 | 20 | public int Id { get; private set; } 21 | 22 | public string Name { get; private set; } 23 | 24 | public IBridgeModule Instance { 25 | get { return _module; } 26 | } 27 | 28 | public ModuleMethod[] Methods 29 | { 30 | get 31 | { 32 | if (_methods == null) 33 | { 34 | var moduleType = _module.GetType(); 35 | var methods = moduleType 36 | .GetMethods(BindingFlags.Instance | BindingFlags.Public) 37 | .Where(m => Attribute.IsDefined((MemberInfo) m, typeof (ReactMethodAttribute))); 38 | 39 | _methods = methods.Select(method => 40 | { 41 | var attr = method.GetCustomAttribute(); 42 | var name = !string.IsNullOrWhiteSpace(attr.Name) ? attr.Name : method.Name; 43 | 44 | return new ModuleMethod 45 | { 46 | Name = method.Name, 47 | JavaScriptName = name, 48 | MethodInfo = method 49 | }; 50 | }).ToArray(); 51 | } 52 | return _methods; 53 | } 54 | } 55 | 56 | public IDictionary Config() 57 | { 58 | var config = new Dictionary(); 59 | config["moduleID"] = Id; 60 | 61 | var constants = Instance.ConstantsToExport(); 62 | if (constants != null) 63 | { 64 | config["constants"] = constants; 65 | } 66 | 67 | var methods = new Dictionary(); 68 | 69 | Methods.Apply((method, index) => 70 | { 71 | methods[method.JavaScriptName] = new 72 | { 73 | methodID = index, 74 | type = "remote" 75 | }; 76 | }); 77 | 78 | config["methods"] = methods; 79 | 80 | return config; 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ModuleLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Reflection; 6 | using Caliburn.Micro; 7 | 8 | namespace ReactNative.Framework 9 | { 10 | public interface IModuleLoader 11 | { 12 | IEnumerable Load(IReactBridge bridge, IEnumerable assemblies); 13 | List Build(IEnumerable assemblies); 14 | IDictionary ModuleConfig(IEnumerable modules); 15 | } 16 | 17 | public class ModuleLoader : IModuleLoader 18 | { 19 | public IEnumerable Load(IReactBridge bridge, IEnumerable assemblies) 20 | { 21 | var modules = Build(assemblies); 22 | return modules; 23 | } 24 | 25 | public List Build(IEnumerable assemblies) 26 | { 27 | var moduleTypes = assemblies 28 | .SelectMany(a => 29 | a.GetTypes().Where(t => Attribute.IsDefined((MemberInfo) t, typeof(ReactModuleAttribute))) 30 | ) 31 | .ToList(); 32 | 33 | var modules = moduleTypes 34 | .Apply((moduleType, index) => 35 | { 36 | var attr = moduleType.GetCustomAttribute(); 37 | var typeToRegister = attr.Type ?? moduleType; 38 | var module = (IBridgeModule) IoC.GetInstance(typeToRegister, null); 39 | 40 | Debug.Assert(module != null, 41 | "Null module for {0}, is it registered in the container?" 42 | .ToFormat(typeToRegister.Name)); 43 | 44 | var name = !string.IsNullOrWhiteSpace(attr.Name) ? attr.Name : moduleType.Name; 45 | return new ModuleData(index, name, module); 46 | }) 47 | .ToList(); 48 | 49 | return modules; 50 | } 51 | 52 | public IDictionary ModuleConfig(IEnumerable modules) 53 | { 54 | var moduleConfig = new Dictionary(); 55 | modules.Apply(module => moduleConfig[module.Name] = module.Config()); 56 | 57 | var container = new Dictionary(); 58 | container["remoteModuleConfig"] = moduleConfig; 59 | return container; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ModuleMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using Newtonsoft.Json.Linq; 7 | 8 | namespace ReactNative.Framework 9 | { 10 | public class ModuleMethod 11 | { 12 | public string Name { get; set; } 13 | 14 | public string JavaScriptName { get; set; } 15 | 16 | public MethodInfo MethodInfo { get; set; } 17 | 18 | public void Invoke(object instance, object[] parameters) 19 | { 20 | var methodParams = MethodInfo.GetParameters(); 21 | 22 | for (var i = 0; i < parameters.Length; i++) 23 | { 24 | var param = parameters[i]; 25 | 26 | // convert JArray to generic list of method param type 27 | if (param is JArray) 28 | { 29 | var arr = (JArray)param; 30 | var methodParam = methodParams[i]; 31 | var elementType = methodParam.ParameterType.GetGenericArguments()[0]; 32 | 33 | var genericListType = typeof (List<>).MakeGenericType(elementType); 34 | var newArray = (IList)Activator.CreateInstance(genericListType); 35 | var values = arr.Values().ToArray(); 36 | foreach (var token in values) 37 | { 38 | newArray.Add(token.ToObject()); 39 | } 40 | 41 | parameters[i] = newArray; 42 | } 43 | } 44 | 45 | MethodInfo.Invoke(instance, parameters); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactBridgeImpl.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Timers; 8 | 9 | namespace ReactNative.Framework 10 | { 11 | public class ReactBridgeImpl : IReactBridge 12 | { 13 | private readonly IReactAssemblyProvider _assemblyProvider; 14 | private readonly IModuleLoader _moduleLoader; 15 | private readonly IJavaScriptExecutor _executor; 16 | private readonly IUIManager _uiManager; 17 | private List _modules; 18 | 19 | private readonly Timer _timer; 20 | 21 | public ReactBridgeImpl( 22 | IReactAssemblyProvider assemblyProvider, 23 | IModuleLoader moduleLoader, 24 | IJavaScriptExecutor executor, 25 | IUIManager uiManager) 26 | { 27 | _assemblyProvider = assemblyProvider; 28 | _moduleLoader = moduleLoader; 29 | _executor = executor; 30 | _uiManager = uiManager; 31 | 32 | _timer = new Timer(16.67); 33 | // _timer = new Timer(5000); 34 | _timer.Elapsed += (e, a) => 35 | { 36 | PollQueue(); 37 | }; 38 | } 39 | 40 | public IEnumerable Modules 41 | { 42 | get { return _modules; } 43 | } 44 | 45 | public async Task LoadApplicationScript(string bundle, string sourceUrl) 46 | { 47 | Reset(); 48 | 49 | _modules = _moduleLoader.Load(this, _assemblyProvider.Assemblies()).ToList(); 50 | 51 | _modules.Apply(m => m.Instance.Initialize(this)); 52 | 53 | System.Diagnostics.Debug.WriteLine("Executor Setup"); 54 | _executor.Setup(); 55 | 56 | System.Diagnostics.Debug.WriteLine("Injecting Modules"); 57 | InjectModules(); 58 | 59 | System.Diagnostics.Debug.WriteLine("Executing Script"); 60 | await _executor.Execute(bundle, sourceUrl); 61 | 62 | System.Diagnostics.Debug.WriteLine("flushing"); 63 | var results = await _executor.ExecuteJSCall("BatchedBridge", "flushedQueue", null); 64 | HandleBuffer(results); 65 | _timer.Enabled = true; 66 | 67 | return true; 68 | } 69 | 70 | public async Task RunApplication(string moduleName, long rootTag, IDictionary initialProperties) 71 | { 72 | var appParams = new Dictionary 73 | { 74 | {"rootTag", rootTag}, 75 | {"initialProps", initialProperties} 76 | }; 77 | 78 | var json = await _executor.ExecuteJSCall( 79 | "AppRegistry", 80 | "runApplication", 81 | new object[] {moduleName, appParams}); 82 | 83 | HandleBuffer(json); 84 | } 85 | 86 | public Task Execute(string script, string sourceUrl) 87 | { 88 | return _executor.Execute(script, sourceUrl); 89 | } 90 | 91 | public Task ExecuteJSCall(string name, string method, object[] arguments) 92 | { 93 | return _executor.ExecuteJSCall(name, method, arguments); 94 | } 95 | 96 | public void InjectModules() 97 | { 98 | var moduleConfig = _moduleLoader.ModuleConfig(_modules); 99 | var json = JsonConvert.SerializeObject(moduleConfig, Formatting.Indented); 100 | 101 | System.Diagnostics.Debug.WriteLine("__fbBatchedBridgeConfig:\n{0}".ToFormat(json)); 102 | 103 | _executor.InjectJSON("__fbBatchedBridgeConfig", json); 104 | } 105 | 106 | public void HandleBuffer(string json) 107 | { 108 | if (string.IsNullOrWhiteSpace(json) || json == "null" || json == "undefined") 109 | { 110 | return; 111 | } 112 | 113 | var requestsArray = JArray.Parse(json); 114 | 115 | if (requestsArray != null) 116 | { 117 | var modulesIds = requestsArray[0]; 118 | var methodIds = requestsArray[1]; 119 | var paramsArrays = requestsArray[2]; 120 | 121 | for (var i = 0; i < modulesIds.Count(); i++) 122 | { 123 | var moduleId = modulesIds[i].ToObject(); 124 | var methodId = methodIds[i].ToObject(); 125 | var arguments = ConvertArguments(paramsArrays[i]); 126 | 127 | HandleRequestNumber(moduleId, methodId, arguments); 128 | } 129 | } 130 | } 131 | 132 | private object[] ConvertArguments(JToken token) 133 | { 134 | var arguments = token.ToObject(); 135 | for (var y = 0; y < arguments.Length; y++) 136 | { 137 | var arg = arguments[y]; 138 | if (arg is JObject) 139 | { 140 | arguments[y] = ((JObject) arg).ToObject>(); 141 | } 142 | 143 | // JArray is converted in ModuleMethod class 144 | } 145 | 146 | return arguments; 147 | } 148 | 149 | public void HandleRequestNumber(int moduleId, int methodId, object[] arguments) 150 | { 151 | var module = _modules[moduleId]; 152 | var method = module.Methods[methodId]; 153 | method.Invoke(module.Instance, arguments); 154 | } 155 | 156 | public async void PollQueue() 157 | { 158 | var json = await _executor.ExecuteJSCall("BatchedBridge", "flushedQueue", null); 159 | HandleBuffer(json); 160 | } 161 | 162 | public void Reset() 163 | { 164 | _timer.Enabled = false; 165 | _uiManager.Reset(); 166 | } 167 | } 168 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactComponentBase.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | public class ReactComponentBase : PropertyChangedBase, IReactComponent 6 | { 7 | private long? _reactTag; 8 | private string _backgroundColor; 9 | 10 | public long? ReactTag 11 | { 12 | get { return _reactTag; } 13 | set 14 | { 15 | _reactTag = value; 16 | NotifyOfPropertyChange(() => ReactTag); 17 | } 18 | } 19 | 20 | public string BackgroundColor 21 | { 22 | get { return _backgroundColor; } 23 | set 24 | { 25 | _backgroundColor = value; 26 | NotifyOfPropertyChange(() => BackgroundColor); 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactComponentData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using Caliburn.Micro; 4 | 5 | namespace ReactNative.Framework 6 | { 7 | public interface IReactComponentData 8 | { 9 | string Name { get; } 10 | IViewManager Manager { get; } 11 | IReactComponent CreateViewWithTag(long tag); 12 | void SetPropsForView(IDictionary props, IReactComponent view); 13 | IDictionary ViewConfig(); 14 | } 15 | 16 | public class ReactComponentData : IReactComponentData 17 | { 18 | private IReactComponent _defaultView; 19 | 20 | public ReactComponentData(IViewManager manager) 21 | { 22 | Manager = manager; 23 | 24 | var managerType = manager.GetType(); 25 | var moduleAttr = managerType.GetCustomAttribute(); 26 | var name = moduleAttr.Name; 27 | 28 | if (string.IsNullOrWhiteSpace(name)) 29 | { 30 | name = managerType.Name; 31 | 32 | if (name.EndsWith("Manager")) 33 | { 34 | name = name.Substring(0, name.Length - "Manager".Length); 35 | } 36 | } 37 | 38 | Name = name; 39 | } 40 | 41 | public string Name { get; private set; } 42 | public IViewManager Manager { get; private set; } 43 | 44 | public IReactComponent CreateViewWithTag(long tag) 45 | { 46 | var view = Manager.View(); 47 | view.ReactTag = tag; 48 | return view; 49 | } 50 | 51 | public void SetPropsForView(IDictionary props, IReactComponent view) 52 | { 53 | if (view == null || props == null) 54 | { 55 | return; 56 | } 57 | 58 | if (_defaultView == null) 59 | { 60 | _defaultView = CreateViewWithTag(-1); 61 | } 62 | 63 | Execute.OnUIThread(() => 64 | { 65 | props.Keys.Apply(key => 66 | { 67 | SetPropertyForKey(view, key, props[key]); 68 | }); 69 | }); 70 | } 71 | 72 | public void SetPropertyForKey(object view, string key, object value) 73 | { 74 | var propInfo = view 75 | .GetType() 76 | .GetProperty(key, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance); 77 | propInfo.SetValue(view, value); 78 | } 79 | 80 | public IDictionary ViewConfig() 81 | { 82 | return null; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactContainerComponentBase.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | public class ReactContainerComponentBase : ReactComponentBase, IReactContainerComponent 6 | { 7 | private readonly BindableCollection _views = new BindableCollection(); 8 | 9 | public IObservableCollection Views 10 | { 11 | get { return _views; } 12 | } 13 | 14 | public void AddView(IReactComponent view) 15 | { 16 | _views.Add(view); 17 | } 18 | 19 | public void AddViewAtIndex(IReactComponent view, int index) 20 | { 21 | _views.Insert(index, view); 22 | } 23 | 24 | public void RemoveView(IReactComponent child) 25 | { 26 | _views.Remove(child); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactEventsExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace ReactNative.Framework 2 | { 3 | public static class ReactEventsExtensions 4 | { 5 | public static string NormalizeInputEventName(this string eventName) 6 | { 7 | if (eventName.StartsWith("on")) 8 | { 9 | eventName = "top" + eventName.Substring(2); 10 | } 11 | else if (!eventName.StartsWith("top")) 12 | { 13 | eventName = "top" + eventName.Substring(0, 1).ToUpper() + eventName.Substring(1); 14 | } 15 | 16 | return eventName; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactMethodAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | [AttributeUsage(AttributeTargets.Method)] 6 | public class ReactMethodAttribute : Attribute 7 | { 8 | public string Name { get; set; } 9 | 10 | public ReactMethodAttribute() 11 | { 12 | } 13 | 14 | public ReactMethodAttribute(string name) 15 | { 16 | Name = name; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/ReactModuleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ReactNative.Framework 4 | { 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class ReactModuleAttribute : Attribute 7 | { 8 | public string Name { get; set; } 9 | 10 | public Type Type { get; set; } 11 | 12 | public ReactModuleAttribute() 13 | { 14 | } 15 | 16 | public ReactModuleAttribute(string name) 17 | { 18 | Name = name; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/RelayCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Windows.Input; 4 | 5 | namespace ReactNative.Framework 6 | { 7 | /// 8 | /// A command whose sole purpose is to 9 | /// relay its functionality to other 10 | /// objects by invoking delegates. The 11 | /// default return value for the CanExecute 12 | /// method is 'true'. 13 | /// 14 | public class RelayCommand : ICommand 15 | { 16 | readonly Action _execute; 17 | readonly Predicate _canExecute; 18 | 19 | /// 20 | /// Creates a new command that can always execute. 21 | /// 22 | /// The execution logic. 23 | public RelayCommand(Action execute) 24 | : this(execute, null) 25 | { 26 | } 27 | 28 | /// 29 | /// Creates a new command. 30 | /// 31 | /// The execution logic. 32 | /// The execution status logic. 33 | public RelayCommand(Action execute, Predicate canExecute) 34 | { 35 | if (execute == null) 36 | throw new ArgumentNullException("execute"); 37 | 38 | _execute = execute; 39 | _canExecute = canExecute; 40 | } 41 | 42 | [DebuggerStepThrough] 43 | public bool CanExecute(object parameters) 44 | { 45 | return _canExecute == null ? true : _canExecute(parameters); 46 | } 47 | 48 | public event EventHandler CanExecuteChanged 49 | { 50 | add { CommandManager.RequerySuggested += value; } 51 | remove { CommandManager.RequerySuggested -= value; } 52 | } 53 | 54 | public void Execute(object parameters) 55 | { 56 | _execute(parameters); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/ViewManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace ReactNative.Framework 5 | { 6 | public interface IViewManager : IBridgeModule 7 | { 8 | IReactComponent View(); 9 | IEnumerable CustomBubblingEventTypes(); 10 | IEnumerable CustomDirectEventTypes(); 11 | } 12 | 13 | public abstract class ViewManager : IViewManager 14 | { 15 | protected IReactBridge Bridge { get; set; } 16 | 17 | public object ViewManagerRegistry { get; set; } 18 | public object ViewRegistry { get; set; } 19 | 20 | public virtual void Initialize(IReactBridge bridge) 21 | { 22 | Bridge = bridge; 23 | } 24 | 25 | public virtual IDictionary ConstantsToExport() 26 | { 27 | return null; 28 | } 29 | 30 | public virtual IEnumerable CustomBubblingEventTypes() 31 | { 32 | yield return "click"; 33 | } 34 | 35 | public virtual IEnumerable CustomDirectEventTypes() 36 | { 37 | return Enumerable.Empty(); 38 | } 39 | 40 | public abstract IReactComponent View(); 41 | } 42 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/ButtonViewManager.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | using System.Collections.Generic; 3 | using System.Windows.Controls; 4 | using System.Windows.Input; 5 | 6 | namespace ReactNative.Framework.Views 7 | { 8 | public class ReactButtonView : Button 9 | { 10 | public ReactButtonView() 11 | { 12 | SetBinding(ContentProperty, "Text"); 13 | SetBinding(CommandProperty, "ClickCommand"); 14 | } 15 | } 16 | 17 | public class ReactButtonViewModel : ReactComponentBase 18 | { 19 | private readonly IEventDispatcher _eventDispatcher; 20 | private ICommand _clickCommand; 21 | 22 | public ReactButtonViewModel(IEventDispatcher eventDispatcher) 23 | { 24 | _eventDispatcher = eventDispatcher; 25 | } 26 | 27 | public string Text { get; set; } 28 | 29 | public ICommand ClickCommand 30 | { 31 | get 32 | { 33 | if (_clickCommand == null) 34 | { 35 | _clickCommand = new RelayCommand(param => Click(), param => true); 36 | } 37 | return _clickCommand; 38 | } 39 | } 40 | 41 | public void Click() 42 | { 43 | _eventDispatcher.SendInputEventWithName("click", new Dictionary 44 | { 45 | { "target", ReactTag.Value } 46 | }); 47 | } 48 | } 49 | 50 | [ReactModule("ReactButton")] 51 | public class ButtonViewManager : ViewManager 52 | { 53 | public override IReactComponent View() 54 | { 55 | return IoC.Get(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/ContainerViewManager.cs: -------------------------------------------------------------------------------- 1 | namespace ReactNative.Framework.Views 2 | { 3 | public class ReactContainerView : ReactItemsControl 4 | { 5 | } 6 | 7 | public class ReactContainerViewModel : ReactContainerComponentBase 8 | { 9 | } 10 | 11 | [ReactModule("ReactContainer")] 12 | public class ContainerViewManager : ViewManager 13 | { 14 | public override IReactComponent View() 15 | { 16 | return new ReactContainerViewModel(); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/ReactItemsControl.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | using Caliburn.Micro; 3 | 4 | namespace ReactNative.Framework.Views 5 | { 6 | public class ReactItemsControl : ItemsControl 7 | { 8 | public ReactItemsControl() 9 | { 10 | SetBinding(ItemsSourceProperty, "Views"); 11 | ItemTemplate = ConventionManager.DefaultItemTemplate; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/ReactRootViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace ReactNative.Framework.Views 4 | { 5 | public class ReactRootView : ReactItemsControl 6 | { 7 | } 8 | 9 | public class ReactRootViewModel : ReactContainerComponentBase 10 | { 11 | private readonly IReactBridge _bridge; 12 | 13 | public ReactRootViewModel(IUIManager uiManager, IReactBridge bridge) 14 | { 15 | _bridge = bridge; 16 | uiManager.RegisterRootView(this); 17 | } 18 | 19 | public async void RunApplication(string moduleName, string bundle, string sourceUrl) 20 | { 21 | await _bridge.LoadApplicationScript(bundle, sourceUrl); 22 | await _bridge.RunApplication(moduleName, ReactTag ?? 0, null); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/ReactTextBlockView.cs: -------------------------------------------------------------------------------- 1 | using ReactNative.Framework.Converters; 2 | using System.Windows.Controls; 3 | using System.Windows.Data; 4 | 5 | namespace ReactNative.Framework.Views 6 | { 7 | public class ReactTextBlockView : TextBlock 8 | { 9 | public ReactTextBlockView() 10 | { 11 | SetBinding(TextProperty, "Text"); 12 | 13 | var backgroundBinding = new Binding("BackgroundColor"); 14 | backgroundBinding.Converter = new ColorToBrushConverter(); 15 | SetBinding(BackgroundProperty, backgroundBinding); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/StackPanelViewManager.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | using System.Windows.Controls; 3 | using System.Windows.Data; 4 | using System.Windows.Markup; 5 | using ReactNative.Framework.Converters; 6 | 7 | namespace ReactNative.Framework.Views 8 | { 9 | public class ReactStackPanelView : ReactItemsControl 10 | { 11 | public ReactStackPanelView() 12 | { 13 | var template = 14 | " " + 16 | "" + 17 | ""; 18 | 19 | ItemsPanel = XamlReader.Parse(template) as ItemsPanelTemplate; 20 | Loaded += StackPanel_Loaded; 21 | } 22 | 23 | private void StackPanel_Loaded(object sender, RoutedEventArgs e) 24 | { 25 | var panel = this.FindChild("PART_Panel"); 26 | var binding = new Binding("Orientation") 27 | { 28 | Converter = new StringToOrientationConverter() 29 | }; 30 | panel.SetBinding(StackPanel.OrientationProperty, binding); 31 | } 32 | } 33 | 34 | public class ReactStackPanelViewModel : ReactContainerComponentBase 35 | { 36 | private string _orientation; 37 | 38 | public string Orientation 39 | { 40 | get { return _orientation; } 41 | set 42 | { 43 | _orientation = value; 44 | NotifyOfPropertyChange(() => Orientation); 45 | } 46 | } 47 | } 48 | 49 | [ReactModule("ReactStackPanel")] 50 | public class StackPanelViewManager : ViewManager 51 | { 52 | public override IReactComponent View() 53 | { 54 | return new ReactStackPanelViewModel(); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/TextBlockViewManager.cs: -------------------------------------------------------------------------------- 1 | namespace ReactNative.Framework.Views 2 | { 3 | public class ReactTextBlockViewModel : ReactComponentBase 4 | { 5 | private string _text; 6 | 7 | public string Text 8 | { 9 | get { return _text; } 10 | set 11 | { 12 | _text = value; 13 | NotifyOfPropertyChange(() => Text); 14 | } 15 | } 16 | } 17 | 18 | [ReactModule("ReactTextBlock")] 19 | public class TextBlockViewManager : ViewManager 20 | { 21 | public override IReactComponent View() 22 | { 23 | return new ReactTextBlockViewModel(); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/Views/VisualTreeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Media; 4 | 5 | namespace ReactNative.Framework.Views 6 | { 7 | public static class VisualTreeExtensions 8 | { 9 | public static T FindChild(this FrameworkElement obj, string name) 10 | { 11 | var dep = obj as DependencyObject; 12 | T ret = default(T); 13 | 14 | if (dep != null) 15 | { 16 | int childcount = VisualTreeHelper.GetChildrenCount(dep); 17 | for (int i = 0; i < childcount; i++) 18 | { 19 | DependencyObject childDep = VisualTreeHelper.GetChild(dep, i); 20 | FrameworkElement child = childDep as FrameworkElement; 21 | 22 | if (child.GetType() == typeof(T) && child.Name == name) 23 | { 24 | ret = (T)Convert.ChangeType(child, typeof(T)); 25 | break; 26 | } 27 | 28 | ret = child.FindChild(name); 29 | if (ret != null) 30 | break; 31 | } 32 | } 33 | return ret; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/ReactNative/Framework/WebSocketExecutor.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | using WebSocketSharp; 6 | 7 | namespace ReactNative.Framework 8 | { 9 | public class WebSocketExecutor : IJavaScriptExecutor, IDisposable 10 | { 11 | public static int Port = 3333; 12 | 13 | private static long LastID = 100; 14 | 15 | private WebSocket _webSocket; 16 | private readonly Dictionary _injectables = new Dictionary(); 17 | private readonly Dictionary> _callbacks = new Dictionary>(); 18 | 19 | public Task Execute(string script, string sourceUrl) 20 | { 21 | System.Diagnostics.Debug.WriteLine("Executing Script: {0}".ToFormat(sourceUrl)); 22 | var tcs = new TaskCompletionSource(); 23 | SendMessage(new Dictionary 24 | { 25 | {"method", "executeApplicationScript"}, 26 | {"url", sourceUrl}, 27 | {"inject", _injectables} 28 | }, res => tcs.TrySetResult(res)); 29 | return tcs.Task; 30 | } 31 | 32 | public Task ExecuteJSCall(string name, string method, object[] arguments) 33 | { 34 | // System.Diagnostics.Debug.WriteLine("Executing JSCall: {0}.{1}".ToFormat(name, method)); 35 | var tcs = new TaskCompletionSource(); 36 | SendMessage(new Dictionary 37 | { 38 | {"method", "executeJSCall"}, 39 | {"moduleName", name}, 40 | {"moduleMethod", method}, 41 | {"arguments", arguments} 42 | }, res => tcs.TrySetResult(res)); 43 | return tcs.Task; 44 | } 45 | 46 | public Task InjectJSON(string objectName, string json) 47 | { 48 | _injectables[objectName] = json; 49 | var tcs = new TaskCompletionSource(); 50 | tcs.TrySetResult(true); 51 | return tcs.Task; 52 | } 53 | 54 | public void Setup() 55 | { 56 | if (_webSocket == null) 57 | { 58 | Connect().Wait(); 59 | } 60 | else 61 | { 62 | PrepareJSRuntime().Wait(); 63 | } 64 | } 65 | 66 | public Task Connect() 67 | { 68 | var tcs = new TaskCompletionSource(); 69 | 70 | _webSocket = new WebSocket("ws://127.0.0.1:{0}/debugger-proxy".ToFormat(Port)); 71 | _webSocket.OnOpen += async (sender, args) => 72 | { 73 | System.Diagnostics.Debug.WriteLine("WS: Opened"); 74 | await PrepareJSRuntime(); 75 | tcs.TrySetResult(true); 76 | }; 77 | _webSocket.OnClose += (sender, args) => 78 | { 79 | System.Diagnostics.Debug.WriteLine("WS: Closed"); 80 | }; 81 | _webSocket.OnMessage += (sender, args) => 82 | { 83 | HandleJson(args.Data); 84 | }; 85 | _webSocket.ConnectAsync(); 86 | 87 | return tcs.Task; 88 | } 89 | 90 | public Task PrepareJSRuntime() 91 | { 92 | var tcs = new TaskCompletionSource(); 93 | SendMessage(new Dictionary { {"method", "prepareJSRuntime" } }, res => 94 | { 95 | System.Diagnostics.Debug.WriteLine("WS: Prepare Reply"); 96 | tcs.TrySetResult(true); 97 | }); 98 | 99 | return tcs.Task; 100 | } 101 | 102 | public void SendMessage(Dictionary message, Action callback = null) 103 | { 104 | var id = LastID++; 105 | message["id"] = id; 106 | 107 | _callbacks[id] = callback; 108 | 109 | var json = JsonConvert.SerializeObject(message); 110 | _webSocket.SendAsync(json, success => { }); 111 | } 112 | 113 | public void HandleJson(string json) 114 | { 115 | var reply = JsonConvert.DeserializeObject>(json); 116 | if (reply == null || !reply.ContainsKey("replyID")) return; 117 | var replyId = long.Parse(reply["replyID"].ToString()); 118 | if (_callbacks.ContainsKey(replyId)) 119 | { 120 | var callback = _callbacks[replyId]; 121 | var resultJson = string.Empty; 122 | if (reply.ContainsKey("result")) 123 | { 124 | resultJson = reply["result"]?.ToString(); 125 | if (!string.IsNullOrWhiteSpace(resultJson) && resultJson != "null") 126 | { 127 | System.Diagnostics.Debug.WriteLine("WS: {0}".ToFormat(json)); 128 | } 129 | } 130 | callback?.Invoke(resultJson); 131 | } 132 | } 133 | 134 | public void Dispose() 135 | { 136 | _webSocket.CloseAsync(CloseStatusCode.Normal); 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/ReactNative/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ReactNative")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Towers Watson")] 12 | [assembly: AssemblyProduct("ReactNative")] 13 | [assembly: AssemblyCopyright("Copyright © Towers Watson 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ea7e20b2-21a4-42b9-b7ea-6cab709fd5af")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/ReactNative/ReactNative.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {EA7E20B2-21A4-42B9-B7EA-6CAB709FD5AF} 8 | Library 9 | Properties 10 | ReactNative 11 | ReactNative 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | x86 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | true 35 | bin\x86\Debug\ 36 | DEBUG;TRACE 37 | full 38 | x86 39 | prompt 40 | MinimumRecommendedRules.ruleset 41 | 42 | 43 | bin\x86\Release\ 44 | TRACE 45 | true 46 | pdbonly 47 | x86 48 | prompt 49 | MinimumRecommendedRules.ruleset 50 | 51 | 52 | 53 | False 54 | ..\..\packages\Caliburn.Micro.Core.2.0.2\lib\net45\Caliburn.Micro.dll 55 | 56 | 57 | False 58 | ..\..\packages\Caliburn.Micro.2.0.2\lib\net45\Caliburn.Micro.Platform.dll 59 | 60 | 61 | ..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 62 | True 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | ..\..\packages\WebSocketSharp.1.0.3-rc9\lib\websocket-sharp.dll 78 | True 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 127 | -------------------------------------------------------------------------------- /src/ReactNative/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/SampleApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/SampleApp/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/SampleApp/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace SampleApp 4 | { 5 | public partial class App : Application 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/SampleApp/CefJavascriptExecutor.cs: -------------------------------------------------------------------------------- 1 | using CefSharp; 2 | using Newtonsoft.Json; 3 | using ReactNative.Framework; 4 | using System.Threading.Tasks; 5 | 6 | namespace SampleApp 7 | { 8 | public class CefJavascriptExecutor : IJavaScriptExecutor 9 | { 10 | private readonly IWebBrowser _webBrowser; 11 | 12 | public CefJavascriptExecutor(IWebBrowser webBrowser) 13 | { 14 | _webBrowser = webBrowser; 15 | } 16 | 17 | public async Task Execute(string script, string sourceUrl) 18 | { 19 | var res = await _webBrowser.EvaluateScriptAsync(script); 20 | return "{0}".ToFormat(res.Result); 21 | } 22 | 23 | public async Task ExecuteJSCall(string name, string method, object[] arguments) 24 | { 25 | var argJson = JsonConvert.SerializeObject(arguments); 26 | 27 | // react-native 28 | // var script = "(function(g){{\nreturn require('{0}').{1}.apply(undefined, {2});\n}})(this);".ToFormat(name, method, argJson); 29 | var script = "(function(g){{\nreturn g.{0}.{1}.apply(undefined, {2});\n}})(this);".ToFormat(name, method, argJson); 30 | var res = await _webBrowser.EvaluateScriptAsync(script); 31 | string json = null; 32 | if (res.Success) 33 | { 34 | json = JsonConvert.SerializeObject(res.Result); 35 | } 36 | return json; 37 | } 38 | 39 | public async Task InjectJSON(string objectName, string json) 40 | { 41 | var script = "(function(g){{ g.{0} = {1}; }})(this)".ToFormat(objectName, json); 42 | await _webBrowser.EvaluateScriptAsync(script); 43 | } 44 | 45 | public void Setup() 46 | { 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/SampleApp/CefSampleView.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 31 | 32 | 33 | 36 | 39 | 40 | 43 | 44 | 47 | 50 | 53 | 54 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/SampleApp/CefSampleView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Controls; 2 | 3 | namespace SampleApp 4 | { 5 | public partial class CefSampleView : UserControl 6 | { 7 | public CefSampleView() 8 | { 9 | InitializeComponent(); 10 | 11 | browser.RegisterJsObject("bound", new JSObject {SomeValue = "A value"}); 12 | browser.ConsoleMessage += Browser_ConsoleMessage; 13 | } 14 | 15 | private void Browser_ConsoleMessage(object sender, CefSharp.ConsoleMessageEventArgs e) 16 | { 17 | System.Diagnostics.Debug.WriteLine("CEF ({0}): {1}", e.Line, e.Message); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/SampleApp/CefSampleViewModel.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | using CefSharp; 3 | using CefSharp.Wpf; 4 | using Newtonsoft.Json; 5 | using ReactNative.Framework; 6 | using ReactNative.Framework.Views; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows; 12 | 13 | namespace SampleApp 14 | { 15 | public class JSObject 16 | { 17 | private string _someValue; 18 | 19 | public string SomeValue 20 | { 21 | get { return _someValue; } 22 | set 23 | { 24 | _someValue = value; 25 | } 26 | } 27 | } 28 | 29 | public class CefSampleViewModel : Screen 30 | { 31 | private ReactRootViewModel _reactScreen; 32 | private string _message; 33 | private IWpfWebBrowser _webBrowser; 34 | private string _script; 35 | private IJavaScriptExecutor _javaScriptExecutor; 36 | private string _address; 37 | 38 | public CefSampleViewModel() 39 | { 40 | _script = "myGlobal.echo = function(arg) {\n console.log('echo ' + JSON.stringify(arg));\n};"; 41 | } 42 | 43 | public IWpfWebBrowser WebBrowser 44 | { 45 | get { return _webBrowser; } 46 | set 47 | { 48 | _webBrowser = value; 49 | NotifyOfPropertyChange(() => WebBrowser); 50 | 51 | if (_webBrowser != null) 52 | { 53 | LoadReact(_webBrowser); 54 | } 55 | } 56 | } 57 | 58 | public string Script 59 | { 60 | get { return _script; } 61 | set 62 | { 63 | _script = value; 64 | NotifyOfPropertyChange(() => Script); 65 | } 66 | } 67 | 68 | public string Message 69 | { 70 | get { return _message; } 71 | set 72 | { 73 | _message = value; 74 | NotifyOfPropertyChange(() => Message); 75 | } 76 | } 77 | 78 | public string Address 79 | { 80 | get { return _address; } 81 | set 82 | { 83 | _address = value; 84 | NotifyOfPropertyChange(() => Address); 85 | } 86 | } 87 | 88 | public void Go() 89 | { 90 | if (_webBrowser != null) 91 | { 92 | _webBrowser.Load(Address); 93 | } 94 | } 95 | 96 | public void ShowDevTools() 97 | { 98 | if (_webBrowser != null) 99 | { 100 | _webBrowser.ShowDevTools(); 101 | } 102 | } 103 | 104 | public async Task LoadReact(IWebBrowser browser) 105 | { 106 | _javaScriptExecutor = new CefJavascriptExecutor(browser); 107 | 108 | await LoadPageAsync(browser, "
Reactify
"); 109 | } 110 | 111 | public static Task LoadPageAsync(IWebBrowser browser, string html = null) 112 | { 113 | var tcs = new TaskCompletionSource(); 114 | 115 | EventHandler handler = null; 116 | handler = (sender, args) => 117 | { 118 | //Wait for while page to finish loading not just the first frame 119 | if (!args.IsLoading) 120 | { 121 | browser.LoadingStateChanged -= handler; 122 | tcs.TrySetResult(true); 123 | } 124 | }; 125 | 126 | browser.LoadingStateChanged += handler; 127 | 128 | if (!string.IsNullOrWhiteSpace(html)) 129 | { 130 | browser.LoadHtml(html, "http://react.local"); 131 | } 132 | return tcs.Task; 133 | } 134 | 135 | public void FlushQueue() 136 | { 137 | _javaScriptExecutor 138 | .ExecuteJSCall("BatchedBridge", "flushedQueue", null) 139 | .ContinueWith(res => 140 | { 141 | AddMessage(res.Result); 142 | }); 143 | } 144 | 145 | public void AddGlobal() 146 | { 147 | var moduleConfig = new Dictionary(); 148 | moduleConfig["one"] = 123; 149 | moduleConfig["two"] = new Dictionary { {"three", 456} }; 150 | 151 | var configJSON = JsonConvert.SerializeObject(moduleConfig); 152 | _javaScriptExecutor.InjectJSON("myGlobal", configJSON); 153 | } 154 | 155 | public void ExecuteGlobal() 156 | { 157 | var moduleConfig = new Dictionary(); 158 | moduleConfig["two"] = new Dictionary { {"three", 456} }; 159 | _javaScriptExecutor.ExecuteJSCall("myGlobal", "echo", new object[] {moduleConfig}); 160 | } 161 | 162 | public void Run() 163 | { 164 | ExecuteScript(Script); 165 | } 166 | 167 | private async void ExecuteScript(string script) 168 | { 169 | try 170 | { 171 | var response = await _webBrowser.EvaluateScriptAsync(script); 172 | if (response.Success && response.Result is IJavascriptCallback) 173 | { 174 | response = await ((IJavascriptCallback)response.Result).ExecuteAsync("This is a callback from EvaluateJavaScript"); 175 | } 176 | 177 | var message = "{0}".ToFormat(response.Success 178 | ? (response.Result ?? "null") 179 | : response.Message); 180 | AddMessage(message); 181 | } 182 | catch (Exception e) 183 | { 184 | MessageBox.Show("Error while evaluating Javascript: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); 185 | } 186 | } 187 | 188 | private void AddMessage(string message) 189 | { 190 | var sb = new StringBuilder(Message); 191 | sb.AppendLine("{0}: {1}".ToFormat(DateTime.Now, message)); 192 | Message = sb.ToString(); 193 | } 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/SampleApp/IShell.cs: -------------------------------------------------------------------------------- 1 | namespace SampleApp 2 | { 3 | public interface IShell 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/SampleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("SampleApp")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("Towers Watson")] 14 | [assembly: AssemblyProduct("SampleApp")] 15 | [assembly: AssemblyCopyright("Copyright © Towers Watson 2015")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /src/SampleApp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleApp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SampleApp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/SampleApp/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /src/SampleApp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleApp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SampleApp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/SampleApp/SampleAppBootstrapper.cs: -------------------------------------------------------------------------------- 1 | using Caliburn.Micro; 2 | using ReactNative.Framework; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Windows; 8 | using ReactNative.Framework.Views; 9 | using ReactNative.JavaScriptCore; 10 | 11 | namespace SampleApp 12 | { 13 | public class SampleAppBootstrapper : BootstrapperBase 14 | { 15 | private SimpleContainer _container; 16 | 17 | public SampleAppBootstrapper() 18 | { 19 | Initialize(); 20 | } 21 | 22 | protected override void Configure() 23 | { 24 | _container = new SimpleContainer(); 25 | _container.Instance(_container); 26 | _container.Singleton(); 27 | _container.Singleton(); 28 | 29 | _container.Singleton(); 30 | _container.Singleton(); 31 | 32 | _container.Singleton(); 33 | _container.Singleton(); 34 | _container.Singleton(); 35 | _container.Singleton(); 36 | 37 | _container.Instance(new ReactAssemblyProvider(SelectAssemblies)); 38 | 39 | // _container.PerRequest(); 40 | _container.PerRequest(); 41 | _container.Singleton(); 42 | _container.PerRequest(); 43 | _container.PerRequest(); 44 | _container.PerRequest(); 45 | _container.PerRequest(); 46 | _container.PerRequest(); 47 | 48 | _container.PerRequest(); 49 | _container.PerRequest(); 50 | _container.PerRequest(); 51 | } 52 | 53 | protected override IEnumerable SelectAssemblies() 54 | { 55 | var result = base.SelectAssemblies().ToList(); 56 | result.Add(typeof(IReactBridge).Assembly); 57 | return result; 58 | } 59 | 60 | protected override object GetInstance(Type service, string key) 61 | { 62 | return _container.GetInstance(service, key); 63 | } 64 | 65 | protected override IEnumerable GetAllInstances(Type service) 66 | { 67 | return _container.GetAllInstances(service); 68 | } 69 | 70 | protected override void BuildUp(object instance) 71 | { 72 | _container.BuildUp(instance); 73 | } 74 | 75 | protected override void OnStartup(object sender, StartupEventArgs e) 76 | { 77 | DisplayRootViewFor(); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/SampleApp/ShellView.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/SampleApp/ShellView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System.Windows; 2 | 3 | namespace SampleApp 4 | { 5 | public partial class ShellView : Window 6 | { 7 | public ShellView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/SampleApp/ShellViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using Caliburn.Micro; 3 | using ReactNative.Framework.Views; 4 | 5 | namespace SampleApp 6 | { 7 | public class ShellViewModel : Screen, IShell 8 | { 9 | public ShellViewModel() 10 | { 11 | // JavaScriptCore 12 | // var root = IoC.Get(); 13 | // Screen = root; 14 | // var bundle = File.ReadAllText("..\\..\\..\\..\\..\\build\\main.jsbundle"); 15 | // root.RunApplication("SampleApp", bundle, null); 16 | 17 | // CefSharp Demos 18 | // CefScreen = IoC.Get(); 19 | 20 | // WebSockets with Chrome 21 | SocketScreen = IoC.Get(); 22 | } 23 | 24 | public object Screen { get; set; } 25 | 26 | public object CefScreen { get; set; } 27 | 28 | public object SocketScreen { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/SampleApp/WebSocketSampleView.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/SampleApp/WebSocketSampleView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using System.Windows.Controls; 8 | using System.Windows.Data; 9 | using System.Windows.Documents; 10 | using System.Windows.Input; 11 | using System.Windows.Media; 12 | using System.Windows.Media.Imaging; 13 | using System.Windows.Navigation; 14 | using System.Windows.Shapes; 15 | 16 | namespace SampleApp 17 | { 18 | /// 19 | /// Interaction logic for WebSocketSampleView.xaml 20 | /// 21 | public partial class WebSocketSampleView : UserControl 22 | { 23 | public WebSocketSampleView() 24 | { 25 | InitializeComponent(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/SampleApp/WebSocketSampleViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading.Tasks; 3 | using Caliburn.Micro; 4 | using ReactNative.Framework; 5 | using ReactNative.Framework.Views; 6 | 7 | namespace SampleApp 8 | { 9 | public class WebSocketSampleViewModel : Screen 10 | { 11 | private const int Port = 3333; 12 | 13 | private readonly HttpClient _httpClient; 14 | private ReactRootViewModel _reactScreen; 15 | private bool _autoReload = true; 16 | 17 | public WebSocketSampleViewModel() 18 | { 19 | _httpClient = new HttpClient(); 20 | 21 | ReactScreen = IoC.Get(); 22 | Reload(); 23 | } 24 | 25 | public ReactRootViewModel ReactScreen 26 | { 27 | get { return _reactScreen; } 28 | set 29 | { 30 | _reactScreen = value; 31 | NotifyOfPropertyChange(() => ReactScreen); 32 | } 33 | } 34 | 35 | public bool AutoReload 36 | { 37 | get { return _autoReload; } 38 | set 39 | { 40 | _autoReload = value; 41 | NotifyOfPropertyChange(() => AutoReload); 42 | 43 | if (value) 44 | { 45 | WatchForChanges(); 46 | } 47 | else 48 | { 49 | _httpClient.CancelPendingRequests(); 50 | } 51 | } 52 | } 53 | 54 | public void Reload() 55 | { 56 | var sourceUrl = "http://localhost:{0}/wpf/index.ios.bundle".ToFormat(Port); 57 | ReactScreen.RunApplication("SampleApp", null, sourceUrl); 58 | 59 | if (AutoReload) 60 | { 61 | WatchForChanges(); 62 | } 63 | } 64 | 65 | public async Task WatchForChanges() 66 | { 67 | var url = "http://localhost:{0}/onchange".ToFormat(Port); 68 | 69 | _httpClient.CancelPendingRequests(); 70 | 71 | await _httpClient.GetAsync(url); 72 | 73 | if (AutoReload) 74 | { 75 | Reload(); 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/SampleApp/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/react-native/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | using namespace System; 4 | using namespace System::Reflection; 5 | using namespace System::Runtime::CompilerServices; 6 | using namespace System::Runtime::InteropServices; 7 | using namespace System::Security::Permissions; 8 | 9 | // 10 | // General Information about an assembly is controlled through the following 11 | // set of attributes. Change these attribute values to modify the information 12 | // associated with an assembly. 13 | // 14 | [assembly:AssemblyTitleAttribute(L"reactnative")]; 15 | [assembly:AssemblyDescriptionAttribute(L"")]; 16 | [assembly:AssemblyConfigurationAttribute(L"")]; 17 | [assembly:AssemblyCompanyAttribute(L"")]; 18 | [assembly:AssemblyProductAttribute(L"reactnative")]; 19 | [assembly:AssemblyCopyrightAttribute(L"Copyright (c) Joe McBride 2015")]; 20 | [assembly:AssemblyTrademarkAttribute(L"")]; 21 | [assembly:AssemblyCultureAttribute(L"")]; 22 | 23 | // 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the value or you can default the Revision and Build Numbers 32 | // by using the '*' as shown below: 33 | 34 | [assembly:AssemblyVersionAttribute("1.0.*")]; 35 | 36 | [assembly:ComVisible(false)]; 37 | 38 | [assembly:CLSCompliantAttribute(true)]; -------------------------------------------------------------------------------- /src/react-native/JSCoreMarshal.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2009, Peter Nelson(charn.opcode@gmail.com) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met : 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and / or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #include "stdafx.h" 28 | #include "string.h" 29 | #include "JSCoreMarshal.h" 30 | 31 | using namespace reactnative; 32 | 33 | JSStringRef JSCoreMarshal::StringToJSString(String ^ value) 34 | { 35 | if (value != nullptr) 36 | { 37 | JSChar * chars = (JSChar *)Marshal::StringToBSTR(value).ToPointer(); 38 | JSStringRef str = JSStringCreateWithCharacters(chars, wcslen(chars)); 39 | Marshal::FreeBSTR(IntPtr(chars)); 40 | 41 | // TODO: find out if we should return JSStringRetain(str) instead 42 | return str; 43 | } 44 | else 45 | { 46 | return NULL; 47 | } 48 | } 49 | 50 | String ^ JSCoreMarshal::JSStringToString(JSStringRef string) 51 | { 52 | size_t len = JSStringGetLength(string); 53 | 54 | if (len == 0) 55 | { 56 | return nullptr; 57 | } 58 | 59 | JSChar * cStr = (JSChar *)JSStringGetCharactersPtr(string); 60 | 61 | // TODO: does this copy the string, or point to it? 62 | // Do we need to clean up afterwards? 63 | return Marshal::PtrToStringAuto(IntPtr((void *)cStr), len); 64 | } 65 | 66 | String^ JSCoreMarshal::JSValueToJSONString(JSContextRef context, JSValueRef value, int indent) 67 | { 68 | JSStringRef string = JSValueCreateJSONString(context, value, indent, NULL); 69 | return JSCoreMarshal::JSStringToString(string); 70 | } 71 | 72 | String^ JSCoreMarshal::JSValueToString(JSContextRef context, JSValueRef value) 73 | { 74 | JSStringRef string = JSValueToStringCopy(context, value, NULL); 75 | return JSCoreMarshal::JSStringToString(string); 76 | } 77 | 78 | Exception^ JSCoreMarshal::JSErrorToException(JSContextRef context, JSValueRef jsError) 79 | { 80 | String^ errorMessage = jsError ? JSCoreMarshal::JSValueToString(context, jsError) : L"unknown JS error"; 81 | String^ details = jsError ? JSCoreMarshal::JSValueToJSONString(context, jsError, 2) : L"no details"; 82 | 83 | return gcnew Exception(errorMessage + L"\n" + details); 84 | } 85 | -------------------------------------------------------------------------------- /src/react-native/JSCoreMarshal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2009, Peter Nelson(charn.opcode@gmail.com) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met : 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and / or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | * CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 | * CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) 23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 | * POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | using namespace System; 32 | using namespace System::Runtime::InteropServices; 33 | 34 | namespace reactnative { 35 | 36 | class JSCoreMarshal 37 | { 38 | private: 39 | JSCoreMarshal() {} 40 | 41 | public: 42 | static JSStringRef StringToJSString(String ^ value); 43 | static String^ JSStringToString(JSStringRef string); 44 | static String^ JSValueToJSONString(JSContextRef context, JSValueRef value, int indent); 45 | static String^ JSValueToString(JSContextRef context, JSValueRef value); 46 | static Exception^ JSErrorToException(JSContextRef context, JSValueRef value); 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /src/react-native/JSCoreObjectWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using namespace System; 4 | using namespace System::Runtime::InteropServices; 5 | using namespace System::Reflection; 6 | using namespace System::Collections::Generic; 7 | using namespace System::Windows::Threading; 8 | using namespace System::Threading; 9 | using namespace reactnative; 10 | 11 | extern JSClassDefinition wrapperClass; 12 | 13 | JSValueRef getJSValueRefFromObject(JSContextRef ctx, Object ^ object, JSValueRef * exception); 14 | 15 | Object ^ getObjectFromJSValueRef(JSContextRef ctx, Type ^ type, JSValueRef value, JSValueRef * exception); 16 | 17 | void wrapper_Finalize(JSObjectRef object); 18 | bool wrapper_HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); 19 | JSValueRef wrapper_GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); 20 | bool wrapper_SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, 21 | JSValueRef* exception); 22 | void wrapper_GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames); 23 | JSValueRef wrapper_CallAsAnonymousFunction (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, 24 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 25 | JSValueRef wrapper_CallAsFunction (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, 26 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 27 | JSValueRef wrapper_ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception); 28 | -------------------------------------------------------------------------------- /src/react-native/JSObject.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #include "JSValue.h" 4 | #include "JSObject.h" 5 | #include "JSContext.h" 6 | #include "JSCoreMarshal.h" 7 | //#include "JSCoreObjectWrapper.h" 8 | 9 | using namespace reactnative; 10 | 11 | 12 | JSObject::JSObject(JSContext ^ context, JSObjectRef object) 13 | : JSValue(context, (JSValueRef)object) 14 | { 15 | } 16 | 17 | bool JSObject::HasProperty(String ^ propertyName) 18 | { 19 | JSStringRef str = JSCoreMarshal::StringToJSString(propertyName); 20 | bool val = JSObjectHasProperty(_context->context(), (JSObjectRef)_value, str); 21 | JSStringRelease(str); 22 | return val; 23 | } 24 | 25 | JSValue ^ JSObject::GetProperty(String ^ propertyName) 26 | { 27 | JSStringRef str = JSCoreMarshal::StringToJSString(propertyName); 28 | 29 | JSValueRef val = JSObjectGetProperty(_context->context(), (JSObjectRef)_value, str, NULL); 30 | 31 | JSStringRelease(str); 32 | return gcnew JSValue(_context, val); 33 | } 34 | 35 | void JSObject::SetProperty(String ^ propertyName, bool value) 36 | { 37 | SetProperty(propertyName, JSValueMakeBoolean(_context->context(), value)); 38 | } 39 | 40 | void JSObject::SetProperty(String ^ propertyName, double value) 41 | { 42 | SetProperty(propertyName, JSValueMakeNumber(_context->context(), value)); 43 | } 44 | 45 | void JSObject::SetProperty(String ^ propertyName, System::Object ^ value) 46 | { 47 | JSValueRef jsVal = NULL;//getJSValueRefFromObject(_context->context(), value, NULL); 48 | SetProperty(propertyName, jsVal); 49 | } 50 | 51 | void JSObject::SetProperty(String ^ propertyName, System::String ^ value) 52 | { 53 | JSStringRef jsStr = JSCoreMarshal::StringToJSString(value); 54 | SetProperty(propertyName, JSValueMakeString(_context->context(), jsStr)); 55 | JSStringRelease(jsStr); 56 | } 57 | 58 | void JSObject::SetProperty(String ^ propertyName, JSValueRef value) 59 | { 60 | JSStringRef jsStr = JSCoreMarshal::StringToJSString(propertyName); 61 | JSObjectSetProperty(_context->context(), (JSObjectRef)_value, jsStr, value, NULL, NULL); 62 | JSStringRelease(jsStr); 63 | } 64 | 65 | void JSObject::SetProperty(String ^ propertyName, EventDelegate ^ func) 66 | { 67 | JSValueRef jsVal = NULL;//getJSValueRefFromObject(_context->context(), func, NULL); 68 | SetProperty(propertyName, jsVal); 69 | } 70 | 71 | void JSObject::SetProperty(String ^ propertyName, ActionDelegate ^ func) 72 | { 73 | JSValueRef jsVal = NULL;//getJSValueRefFromObject(_context->context(), func, NULL); 74 | SetProperty(propertyName, jsVal); 75 | } 76 | 77 | JSValue ^ JSObject::CallAsFunction(array ^ variableArgs) 78 | { 79 | JSContextRef ctx = _context->context(); 80 | 81 | JSValueRef * args = new JSValueRef[variableArgs->Length]; 82 | for(int i = 0; i < variableArgs->Length; i++) 83 | { 84 | //args[i] = getJSValueRefFromObject(ctx, variableArgs[i], NULL); 85 | } 86 | 87 | JSValueRef ret = JSObjectCallAsFunction(ctx, (JSObjectRef)_value, NULL, variableArgs->Length, args, NULL); 88 | 89 | for(int i = 0; i < variableArgs->Length; i++) 90 | { 91 | JSValueUnprotect(ctx, args[i]); 92 | } 93 | delete[] args; 94 | return gcnew JSValue(_context, ret); 95 | } 96 | 97 | JSValue ^ JSObject::CallFunction(String ^ methodName, ... array ^ variableArgs) 98 | { 99 | JSStringRef str = JSCoreMarshal::StringToJSString(methodName); 100 | 101 | JSObjectRef val = (JSObjectRef)JSObjectGetProperty(_context->context(), (JSObjectRef)_value, str, NULL); 102 | 103 | bool x = JSValueIsObject(_context->context(), val); 104 | JSStringRelease(str); 105 | 106 | JSValueRef * args = new JSValueRef[variableArgs->Length]; 107 | for(int i = 0; i < variableArgs->Length; i++) 108 | { 109 | //args[i] = getJSValueRefFromObject(_context->context(), variableArgs[i], NULL); 110 | } 111 | 112 | JSValueRef ret = JSObjectCallAsFunction(_context->context(), val, (JSObjectRef)_value, variableArgs->Length, args, NULL); 113 | 114 | for(int i = 0; i < variableArgs->Length; i++) 115 | { 116 | JSValueUnprotect(_context->context(), args[i]); 117 | } 118 | delete[] args; 119 | return gcnew JSValue(_context, ret); 120 | } 121 | 122 | Dictionary^ JSObject::ToDictionary() 123 | { 124 | return ToDictionary(false); 125 | } 126 | 127 | Dictionary^ JSObject::ToDictionary(bool recursive) 128 | { 129 | JSObjectRef o = (JSObjectRef)_value; 130 | JSContextRef ctx = _context->context(); 131 | 132 | JSPropertyNameArrayRef properties = JSObjectCopyPropertyNames(ctx, o); 133 | size_t count = JSPropertyNameArrayGetCount(properties); 134 | 135 | Dictionary^ resultsDict = gcnew Dictionary(); 136 | 137 | for (size_t i = 0; i < count; i++) { 138 | JSStringRef jsNameRef = JSPropertyNameArrayGetNameAtIndex(properties, i); 139 | 140 | String^ name = JSCoreMarshal::JSStringToString(jsNameRef); 141 | JSValueRef propertyValue = JSObjectGetProperty(ctx, o, jsNameRef, NULL); 142 | 143 | Object^ value = nullptr; 144 | 145 | //value = getObjectFromJSValueRef(ctx, nullptr, propertyValue, NULL); 146 | if (value->GetType() == JSObject::typeid && recursive) 147 | { 148 | value = ((JSObject^)value)->ToDictionary(recursive); 149 | } 150 | 151 | resultsDict->Add((Object^)name, value); 152 | } 153 | 154 | JSPropertyNameArrayRelease(properties); 155 | 156 | return resultsDict; 157 | } -------------------------------------------------------------------------------- /src/react-native/JSObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using namespace System; 4 | using namespace System::Collections::Generic; 5 | using namespace System::Runtime::InteropServices; 6 | 7 | namespace reactnative { 8 | 9 | public delegate void ActionDelegate(array^ args); 10 | 11 | public delegate Object^ EventDelegate(array^ args); 12 | 13 | public delegate Object^ JavaScriptFunction(JSContext ^context, ... array ^ variableArgs); 14 | 15 | 16 | ref class JSValue; 17 | ref class JSContext; 18 | 19 | public ref class JSObject : public reactnative::JSValue 20 | { 21 | public: 22 | JSObject(JSContext ^ context, JSObjectRef object); 23 | bool HasProperty(String ^ propertyName); 24 | JSValue ^ GetProperty(String ^ propertyName); 25 | void SetProperty(String ^ propertyName, bool value); 26 | void SetProperty(String ^ propertyName, double value); 27 | void SetProperty(String ^ propertyName, System::Object ^ value); 28 | void SetProperty(String ^ propertyName, System::String ^ value); 29 | void SetProperty(String ^ propertyName, EventDelegate ^ func); 30 | void SetProperty(String ^ propertyName, ActionDelegate ^ func); 31 | JSValue ^ CallAsFunction(array ^ variableArgs); 32 | JSValue ^ CallFunction(String ^ methodName, ... array ^ variableArgs); 33 | 34 | Dictionary^ ToDictionary(); 35 | Dictionary^ ToDictionary(bool recursive); 36 | 37 | internal: 38 | 39 | private: 40 | void SetProperty(String ^ propertyName, JSValueRef value); 41 | }; 42 | } -------------------------------------------------------------------------------- /src/react-native/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Logger.h" 3 | 4 | Logger::Logger() 5 | { 6 | } 7 | 8 | void Logger::WriteLog(LogLevel level, String^ message) 9 | { 10 | String^ levelName = Enum::GetName(LogLevel::typeid, (Object^)level); 11 | Console::WriteLine("[{0}] [{1}] {2}", DateTime::Now.ToString(L"HH:mm:ss"), levelName, message); 12 | } 13 | 14 | void Logger::Log(String^ message) 15 | { 16 | Logger:WriteLog(LogLevel::Log, message); 17 | } 18 | 19 | void Logger::Error(String^ message) 20 | { 21 | Logger:WriteLog(LogLevel::Error, message); 22 | } 23 | 24 | void Logger::Error(String^ message, Exception^ exc) 25 | { 26 | String^ levelName = Enum::GetName(LogLevel::typeid, (Object^)LogLevel::Error); 27 | String^ msg = !String::IsNullOrEmpty(message) ? message + L" " : L""; 28 | Console::WriteLine("[{0}] [{1}] {2}{3}", DateTime::Now.ToString(L"HH:mm:ss"), levelName, msg, exc); 29 | } 30 | 31 | void Logger::Error(Exception^ exc) 32 | { 33 | Logger::Error(L"", exc); 34 | } 35 | -------------------------------------------------------------------------------- /src/react-native/Logger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using namespace System; 4 | 5 | public enum class LogLevel 6 | { 7 | Trace = 0, 8 | Log = 1, 9 | Info = 2, 10 | Warn = 3, 11 | Error = 4 12 | }; 13 | 14 | ref class Logger 15 | { 16 | public: 17 | Logger(); 18 | 19 | static void WriteLog(LogLevel level, String^ message); 20 | static void Log(String^ message); 21 | static void Error(String^ message); 22 | static void Error(String^ message, Exception^ exc); 23 | static void Error(Exception^ exc); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /src/react-native/MyWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "MyWrapper.h" 3 | #include "Logger.h" 4 | 5 | using namespace reactnative; 6 | 7 | JSValueRef wrapper_nativeLogging(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, 8 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) 9 | { 10 | if (argumentCount > 0) { 11 | JSStringRef messageRef = JSValueToStringCopy(context, arguments[0], NULL); 12 | if (messageRef == nullptr) { 13 | return JSValueMakeUndefined(context); 14 | } 15 | 16 | LogLevel level = LogLevel::Trace; 17 | String^ message = JSCoreMarshal::JSStringToString(messageRef); 18 | JSStringRelease(messageRef); 19 | 20 | if (argumentCount > 1) { 21 | level = (LogLevel)(Int32)JSValueToNumber(context, arguments[1], NULL); 22 | } 23 | 24 | Logger::WriteLog(level, message); 25 | } 26 | 27 | return JSValueMakeUndefined(context); 28 | } 29 | -------------------------------------------------------------------------------- /src/react-native/MyWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "JSCoreMarshal.h" 4 | 5 | JSValueRef wrapper_nativeLogging(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, 6 | size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); 7 | -------------------------------------------------------------------------------- /src/react-native/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | DYNAMIC LINK LIBRARY : react-native Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this react-native DLL for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your react-native application. 9 | 10 | react-native.vcxproj 11 | This is the main project file for VC++ projects generated using an Application Wizard. 12 | It contains information about the version of Visual C++ that generated the file, and 13 | information about the platforms, configurations, and project features selected with the 14 | Application Wizard. 15 | 16 | react-native.vcxproj.filters 17 | This is the filters file for VC++ projects generated using an Application Wizard. 18 | It contains information about the association between the files in your project 19 | and the filters. This association is used in the IDE to show grouping of files with 20 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 21 | "Source Files" filter). 22 | 23 | react-native.cpp 24 | This is the main DLL source file. 25 | 26 | react-native.h 27 | This file contains a class declaration. 28 | 29 | AssemblyInfo.cpp 30 | Contains custom attributes for modifying assembly metadata. 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | Other notes: 34 | 35 | AppWizard uses "TODO:" to indicate parts of the source code you 36 | should add to or customize. 37 | 38 | ///////////////////////////////////////////////////////////////////////////// 39 | -------------------------------------------------------------------------------- /src/react-native/Stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // react-native.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | -------------------------------------------------------------------------------- /src/react-native/Stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, 3 | // but are changed infrequently 4 | 5 | #pragma once 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/react-native/app.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/src/react-native/app.aps -------------------------------------------------------------------------------- /src/react-native/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/src/react-native/app.ico -------------------------------------------------------------------------------- /src/react-native/app.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joemcbride/react-native-wpf/c0558b7c316da1664d2abd224b1a47b0b5d5be46/src/react-native/app.rc -------------------------------------------------------------------------------- /src/react-native/react-native.cpp: -------------------------------------------------------------------------------- 1 | // This is the main DLL file. 2 | 3 | #include "stdafx.h" 4 | #include 5 | 6 | #include "react-native.h" 7 | #include "JSCoreMarshal.h" 8 | #include "MyWrapper.h" 9 | #include "Logger.h" 10 | 11 | using namespace System; 12 | using namespace System::Runtime::InteropServices; 13 | using namespace System::Windows::Threading; 14 | using namespace reactnative; 15 | 16 | ReactBridge::ReactBridge() { 17 | ctx = JSGlobalContextCreate(nullptr); 18 | 19 | AddNativeHook(L"nativeLoggingHook", wrapper_nativeLogging); 20 | } 21 | 22 | String^ ReactBridge::Execute(String^ scriptText) 23 | { 24 | JSValueRef exception = nullptr; 25 | JSStringRef script = JSCoreMarshal::StringToJSString(scriptText); 26 | JSValueRef result = JSEvaluateScript(ctx, script, nullptr, nullptr, 0, &exception); 27 | JSStringRelease(script); 28 | 29 | String^ strResult; 30 | 31 | if (exception != nullptr) { 32 | Exception^ exc = JSCoreMarshal::JSErrorToException(ctx, exception); 33 | Logger::Error(exc); 34 | return strResult; 35 | } 36 | 37 | if (result != nullptr) 38 | { 39 | JSStringRef str = JSValueToStringCopy(ctx, result, nullptr); 40 | strResult = JSCoreMarshal::JSStringToString(str); 41 | JSStringRelease(str); 42 | } 43 | return strResult; 44 | } 45 | 46 | String^ ReactBridge::ExecuteJSCall(String^ name, String^ method, array^ arguments) 47 | { 48 | String^ argsString = Newtonsoft::Json::JsonConvert::SerializeObject(arguments); 49 | 50 | JSValueRef errorJSRef = nullptr; 51 | JSValueRef resultJSRef = nullptr; 52 | JSGlobalContextRef contextJSRef = ctx; 53 | JSObjectRef globalObjectJSRef = JSContextGetGlobalObject(ctx); 54 | 55 | // get require 56 | JSStringRef requireNameJSStringRef = JSCoreMarshal::StringToJSString(L"require"); 57 | JSValueRef requireJSRef = JSObjectGetProperty(contextJSRef, globalObjectJSRef, requireNameJSStringRef, &errorJSRef); 58 | JSStringRelease(requireNameJSStringRef); 59 | 60 | // get module 61 | JSStringRef moduleNameJSStringRef = JSCoreMarshal::StringToJSString(name); 62 | JSValueRef moduleNameJSRef = JSValueMakeString(contextJSRef, moduleNameJSStringRef); 63 | JSValueRef moduleJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)requireJSRef, NULL, 1, (const JSValueRef *)&moduleNameJSRef, &errorJSRef); 64 | JSStringRelease(moduleNameJSStringRef); 65 | 66 | // get method 67 | JSStringRef methodNameJSStringRef = JSCoreMarshal::StringToJSString(method); 68 | JSValueRef methodJSRef = JSObjectGetProperty(contextJSRef, (JSObjectRef)moduleJSRef, methodNameJSStringRef, &errorJSRef); 69 | JSStringRelease(methodNameJSStringRef); 70 | 71 | // invoke method no arguments 72 | if (arguments == nullptr || arguments->Length == 0) { 73 | resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)methodJSRef, (JSObjectRef)moduleJSRef, 0, NULL, &errorJSRef); 74 | } 75 | 76 | // invoke method with 1 argument 77 | else if (arguments != nullptr && arguments->Length == 1) 78 | { 79 | JSStringRef argsJSStringRef = JSCoreMarshal::StringToJSString(argsString); 80 | JSValueRef argsJSRef = JSValueMakeFromJSONString(contextJSRef, argsJSStringRef); 81 | resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)methodJSRef, (JSObjectRef)moduleJSRef, 1, &argsJSRef, &errorJSRef); 82 | JSStringRelease(argsJSStringRef); 83 | } 84 | 85 | // invoke method with multiple arguments 86 | else 87 | { 88 | // apply invoke with array of arguments 89 | JSStringRef applyNameJSStringRef = JSCoreMarshal::StringToJSString("apply"); 90 | JSValueRef applyJSRef = JSObjectGetProperty(contextJSRef, (JSObjectRef)methodJSRef, applyNameJSStringRef, &errorJSRef); 91 | JSStringRelease(applyNameJSStringRef); 92 | 93 | if (applyJSRef != NULL && errorJSRef == NULL) { 94 | // invoke apply 95 | JSStringRef argsJSStringRef = JSCoreMarshal::StringToJSString(argsString); 96 | JSValueRef argsJSRef = JSValueMakeFromJSONString(contextJSRef, argsJSStringRef); 97 | 98 | JSValueRef args[2]; 99 | args[0] = JSValueMakeNull(contextJSRef); 100 | args[1] = argsJSRef; 101 | 102 | resultJSRef = JSObjectCallAsFunction(contextJSRef, (JSObjectRef)applyJSRef, (JSObjectRef)methodJSRef, 2, args, &errorJSRef); 103 | JSStringRelease(argsJSStringRef); 104 | } 105 | } 106 | 107 | if (errorJSRef != nullptr) 108 | { 109 | Exception^ exc = JSCoreMarshal::JSErrorToException(ctx, errorJSRef); 110 | Logger::Error(L"ExecuteJSCall", exc); 111 | } 112 | 113 | JSStringRef str = JSValueCreateJSONString(ctx, resultJSRef, 0, nullptr); 114 | String^ jsonString = nullptr; 115 | 116 | if (str != nullptr) 117 | { 118 | jsonString = JSCoreMarshal::JSStringToString(str); 119 | JSStringRelease(str); 120 | } 121 | 122 | return jsonString; 123 | } 124 | 125 | void ReactBridge::InjectJSONText(String^ objectName, String^ json) 126 | { 127 | JSStringRef execJSString = JSCoreMarshal::StringToJSString(json); 128 | JSValueRef valueToInject = JSValueMakeFromJSONString(ctx, execJSString); 129 | JSStringRelease(execJSString); 130 | 131 | if (valueToInject == nullptr) { 132 | Logger::Error("InjectJSONText - invalid JSON?"); 133 | return; 134 | } 135 | 136 | JSValueRef exception = nullptr; 137 | JSObjectRef globalObject = JSContextGetGlobalObject(ctx); 138 | JSStringRef JSName = JSCoreMarshal::StringToJSString(objectName); 139 | JSObjectSetProperty(ctx, globalObject, JSName, valueToInject, kJSPropertyAttributeNone, &exception); 140 | JSStringRelease(JSName); 141 | 142 | if (exception != nullptr) { 143 | Exception^ exc = JSCoreMarshal::JSErrorToException(ctx, exception); 144 | Logger::Error(L"InjectJSONText - could not set global", exc); 145 | } 146 | } 147 | 148 | void ReactBridge::AddNativeHook(String^ name, JSObjectCallAsFunctionCallback hook) 149 | { 150 | JSObjectRef globalObject = JSContextGetGlobalObject(ctx); 151 | 152 | JSStringRef JSName = JSCoreMarshal::StringToJSString(name); 153 | JSValueRef cb = JSObjectMakeFunctionWithCallback(ctx, JSName, hook); 154 | JSObjectSetProperty(ctx, globalObject, JSName, cb, kJSPropertyAttributeNone, NULL); 155 | JSStringRelease(JSName); 156 | } 157 | -------------------------------------------------------------------------------- /src/react-native/react-native.h: -------------------------------------------------------------------------------- 1 | // react-native.h 2 | 3 | #pragma once 4 | 5 | #include "JavaScriptCore\JavaScriptCore.h" 6 | 7 | using namespace System; 8 | using namespace System::Collections::Generic; 9 | 10 | namespace reactnative { 11 | public ref class ReactBridge 12 | { 13 | public: 14 | ReactBridge(); 15 | String^ Execute(String^ script); 16 | String^ ExecuteJSCall(String^ name, String^ method, array ^ arguments); 17 | void InjectJSONText(String^ objectName, String^ json); 18 | 19 | private: 20 | JSGlobalContextRef ctx; 21 | 22 | void AddNativeHook(String^ name, JSObjectCallAsFunctionCallback hook); 23 | 24 | ~ReactBridge() { 25 | JSGlobalContextRelease(ctx); 26 | ctx = nullptr; 27 | } 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /src/react-native/react-native.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Resource Files 63 | 64 | 65 | 66 | 67 | Resource Files 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/react-native/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by app.rc 4 | -------------------------------------------------------------------------------- /wpf/Button.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule Button 3 | */ 4 | 5 | var createReactNativeComponentClass = 6 | require('createReactNativeComponentClass'); 7 | 8 | 9 | var viewConfig = { 10 | validAttributes: { 11 | text: true, 12 | backgroundColor: true 13 | }, 14 | uiViewClassName: 'ReactButton', 15 | }; 16 | 17 | var Button = createReactNativeComponentClass(viewConfig); 18 | 19 | module.exports = Button; 20 | -------------------------------------------------------------------------------- /wpf/Container.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule Container 3 | */ 4 | 5 | var createReactNativeComponentClass = 6 | require('createReactNativeComponentClass'); 7 | 8 | 9 | var viewConfig = { 10 | validAttributes: { 11 | backgroundColor: true 12 | }, 13 | uiViewClassName: 'ReactContainer', 14 | }; 15 | 16 | var Container = createReactNativeComponentClass(viewConfig); 17 | 18 | module.exports = Container; 19 | -------------------------------------------------------------------------------- /wpf/ReactNativeDefaultInjection.wpf.js: -------------------------------------------------------------------------------- 1 | /* 2 | * @providesModule ReactNativeDefaultInjectionWPF 3 | * @flow 4 | */ 5 | 'use strict'; 6 | 7 | var EventPluginHub = require('EventPluginHub'); 8 | var EventPluginUtils = require('EventPluginUtils'); 9 | var IOSDefaultEventPluginOrder = require('IOSDefaultEventPluginOrder'); 10 | var IOSNativeBridgeEventPlugin = require('IOSNativeBridgeEventPlugin'); 11 | var ReactComponentEnvironment = require('ReactComponentEnvironment'); 12 | var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy'); 13 | var ReactInstanceHandles = require('ReactInstanceHandles'); 14 | var ResponderEventPlugin = require('ResponderEventPlugin'); 15 | var ReactNativeComponentEnvironment = require('ReactNativeComponentEnvironment'); 16 | var ReactNativeGlobalInteractionHandler = require('ReactNativeGlobalInteractionHandler'); 17 | var ReactNativeGlobalResponderHandler = require('ReactNativeGlobalResponderHandler'); 18 | var ReactNativeMount = require('ReactNativeMount'); 19 | var ReactUpdates = require('ReactUpdates'); 20 | var ResponderEventPlugin = require('ResponderEventPlugin'); 21 | 22 | require('RCTEventEmitter'); 23 | 24 | function inject() { 25 | EventPluginHub.injection.injectEventPluginOrder(IOSDefaultEventPluginOrder); 26 | EventPluginHub.injection.injectInstanceHandle(ReactInstanceHandles); 27 | 28 | ResponderEventPlugin.injection.injectGlobalResponderHandler( 29 | ReactNativeGlobalResponderHandler 30 | ); 31 | 32 | ResponderEventPlugin.injection.injectGlobalInteractionHandler( 33 | ReactNativeGlobalInteractionHandler 34 | ); 35 | 36 | /** 37 | * Some important event plugins included by default (without having to require 38 | * them). 39 | */ 40 | EventPluginHub.injection.injectEventPluginsByName({ 41 | 'ResponderEventPlugin': ResponderEventPlugin, 42 | 'IOSNativeBridgeEventPlugin': IOSNativeBridgeEventPlugin 43 | }); 44 | 45 | ReactUpdates.injection.injectReconcileTransaction( 46 | ReactNativeComponentEnvironment.ReactReconcileTransaction 47 | ); 48 | 49 | ReactUpdates.injection.injectBatchingStrategy( 50 | ReactDefaultBatchingStrategy 51 | ); 52 | 53 | ReactComponentEnvironment.injection.injectEnvironment( 54 | ReactNativeComponentEnvironment 55 | ); 56 | 57 | EventPluginUtils.injection.injectMount(ReactNativeMount); 58 | } 59 | 60 | module.exports = { 61 | inject: inject 62 | }; 63 | -------------------------------------------------------------------------------- /wpf/StackPanel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule StackPanel 3 | */ 4 | 5 | var createReactNativeComponentClass = 6 | require('createReactNativeComponentClass'); 7 | 8 | 9 | var viewConfig = { 10 | validAttributes: { 11 | backgroundColor: true, 12 | orientation: true 13 | }, 14 | uiViewClassName: 'ReactStackPanel', 15 | }; 16 | 17 | var Container = createReactNativeComponentClass(viewConfig); 18 | 19 | module.exports = Container; 20 | -------------------------------------------------------------------------------- /wpf/TextBlock.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @providesModule TextBlock 3 | */ 4 | 5 | var createReactNativeComponentClass = 6 | require('createReactNativeComponentClass'); 7 | 8 | 9 | var viewConfig = { 10 | validAttributes: { 11 | text: true, 12 | backgroundColor: true 13 | }, 14 | uiViewClassName: 'ReactTextBlock', 15 | }; 16 | 17 | var TextBlock = createReactNativeComponentClass(viewConfig); 18 | 19 | module.exports = TextBlock; 20 | -------------------------------------------------------------------------------- /wpf/index.ios.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const React = require('ReactNativeWPF'); 4 | const AppRegistry = require('AppRegistry'); 5 | const TextBlock = require('TextBlock'); 6 | const Button = require('Button'); 7 | const Container = require('Container'); // ItemsControl 8 | const StackPanel = require('StackPanel'); 9 | 10 | class SampleApp extends React.Component { 11 | 12 | constructor(props) { 13 | super(props); 14 | 15 | this.state = { 16 | text: 'Hello WPF from React Native', 17 | backgroundColor: '#efefef', 18 | likes: 0, 19 | toggle: false, 20 | orientation: 'horizontal' 21 | }; 22 | 23 | this.like = this.like.bind(this); 24 | this.reset = this.reset.bind(this); 25 | this.toggle = this.toggle.bind(this); 26 | } 27 | 28 | like() { 29 | console.log('liked'); 30 | let likes = this.state.likes +1; 31 | this.setState({ 32 | text: 'Hello WPF from React Native +' + likes, 33 | backgroundColor: '#33ff33', 34 | likes 35 | }); 36 | } 37 | 38 | toggle() { 39 | console.log('toggle'); 40 | let { toggle } = this.state; 41 | let newToggle = !toggle; 42 | let or = newToggle ? 'vertical' : 'horizontal'; 43 | this.setState({ 44 | toggle: newToggle, 45 | orientation: or 46 | }); 47 | } 48 | 49 | reset() { 50 | this.setState({ 51 | text: 'Hello WPF from React Native', 52 | backgroundColor: '#efefef', 53 | likes: 0, 54 | toggle: false, 55 | orientation: 'horizontal' 56 | }); 57 | } 58 | 59 | render() { 60 | let displayText = null; 61 | if(this.state.toggle) { 62 | displayText = ; 63 | } 64 | return ( 65 | 66 | 69 | {displayText} 70 | 71 |