Skip to content

Commit ecd393a

Browse files
committed
fixes
1 parent 3083d3a commit ecd393a

File tree

433 files changed

+439299
-107342
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

433 files changed

+439299
-107342
lines changed

NativeScript/ffi/Closure.mm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ inline void JSCallbackInner(Closure* closure, napi_value func, napi_value thisAr
2525
size_t argc, bool* done, void* ret) {
2626
napi_env env = closure->env;
2727

28-
#ifdef ENABLE_JS_RUNTIME
29-
NapiScope scope(env);
30-
#endif
31-
32-
napi_value result;
28+
napi_value result;
3329

3430
napi_get_and_clear_last_exception(env, &result);
3531

@@ -69,6 +65,11 @@ inline void JSCallbackInner(Closure* closure, napi_value func, napi_value thisAr
6965
void JSMethodCallback(ffi_cif* cif, void* ret, void* args[], void* data) {
7066
Closure* closure = (Closure*)data;
7167
napi_env env = closure->env;
68+
69+
#ifdef ENABLE_JS_RUNTIME
70+
NapiScope scope(env);
71+
#endif
72+
7273
auto bridgeState = ObjCBridgeState::InstanceData(env);
7374

7475
napi_value constructor = get_ref_value(env, closure->thisConstructor);
@@ -135,6 +136,10 @@ void JSBlockCallback(ffi_cif* cif, void* ret, void* args[], void* data) {
135136
Closure* closure = (Closure*)data;
136137
napi_env env = closure->env;
137138

139+
#ifdef ENABLE_JS_RUNTIME
140+
NapiScope scope(env);
141+
#endif
142+
138143
auto currentThreadId = std::this_thread::get_id();
139144

140145
JSBlockCallContext ctx;
@@ -157,7 +162,9 @@ void JSBlockCallback(ffi_cif* cif, void* ret, void* args[], void* data) {
157162
ctx.cv.wait(lock, [&ctx] { return ctx.done; });
158163
napi_release_threadsafe_function(closure->tsfn, napi_tsfn_release);
159164
#else
160-
assert(false && "Threadsafe functions are not supported");
165+
NSLog(@"Threadsafe functions are not supported");
166+
// assert(false && "Threadsafe functions are not supported");
167+
Closure::callBlockFromMainThread(env, get_ref_value(env, closure->func), closure, &ctx);
161168
#endif // ENABLE_JS_RUNTIME
162169
}
163170
}

NativeScript/ffi/TypeConv.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,8 @@ void toNative(napi_env env, napi_value value, void* result, bool* shouldFree,
956956
public:
957957
StringTypeConv() { type = &ffi_type_pointer; }
958958

959-
napi_value toJS(napi_env env, void* value, uint32_t flags) override {
959+
napi_value toJS(napi_env env, void* cont, uint32_t flags) override {
960+
void *value = *((void**)cont);
960961
napi_value result;
961962
napi_create_string_utf8(env, (char*)value, NAPI_AUTO_LENGTH, &result);
962963
return result;

NativeScript/runtime/modules/console/Console.cpp

Lines changed: 104 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sstream>
44
#include <string>
55

6+
#include "ffi/NativeScriptException.h"
67
#include "js_native_api.h"
78
#include "native_api_util.h"
89
#include "runtime/RuntimeConfig.h"
@@ -85,34 +86,34 @@ std::string buildStringFromArg(napi_env env, napi_value val) {
8586
return napi_util::get_string_value(env, funcString);
8687
} else if (napi_util::is_array(env, val)) {
8788
napi_value cachedSelf = val;
88-
89+
8990
// Get array length
9091
uint32_t arrayLength;
9192
napi_get_array_length(env, val, &arrayLength);
92-
93+
9394
std::stringstream arrayStr;
9495
arrayStr << "[";
95-
96+
9697
for (uint32_t i = 0; i < arrayLength; i++) {
9798
napi_value propertyValue;
9899
napi_get_element(env, val, i, &propertyValue);
99-
100+
100101
// Check for circular reference
101102
bool isStrictEqual = false;
102103
napi_strict_equals(env, propertyValue, cachedSelf, &isStrictEqual);
103-
104+
104105
if (isStrictEqual) {
105106
arrayStr << "[Circular]";
106107
} else {
107108
std::string elementString = buildStringFromArg(env, propertyValue);
108109
arrayStr << elementString;
109110
}
110-
111+
111112
if (i != arrayLength - 1) {
112113
arrayStr << ", ";
113114
}
114115
}
115-
116+
116117
arrayStr << "]";
117118
return arrayStr.str();
118119
} else if (type == napi_object) {
@@ -152,118 +153,122 @@ std::string buildLogString(napi_env env, napi_callback_info info,
152153
}
153154

154155
JS_METHOD(Console::Log) {
155-
if (!RuntimeConfig.LogToSystemConsole) {
156-
return UNDEFINED;
157-
}
156+
try {
157+
if (!RuntimeConfig.LogToSystemConsole) {
158+
return UNDEFINED;
159+
}
158160

159-
size_t argc = 0;
160-
ConsoleLogType stream;
161-
void* data = nullptr;
161+
size_t argc = 0;
162+
ConsoleLogType stream;
163+
void* data = nullptr;
162164

163-
napi_get_cb_info(env, cbinfo, &argc, nullptr, nullptr, &data);
165+
napi_get_cb_info(env, cbinfo, &argc, nullptr, nullptr, &data);
164166

165-
stream = ConsoleLogType((unsigned long)data);
167+
stream = ConsoleLogType((unsigned long)data);
166168

167-
size_t initialArg = 0;
169+
size_t initialArg = 0;
168170

169-
if (stream == kConsoleLogTypeAssert) {
170-
bool passes = false;
171+
if (stream == kConsoleLogTypeAssert) {
172+
bool passes = false;
171173

172-
if (argc > 0) {
173-
napi_value firstArg = nullptr;
174-
napi_get_cb_info(env, cbinfo, &argc, &firstArg, nullptr, nullptr);
175-
napi_coerce_to_bool(env, firstArg, &firstArg);
176-
napi_get_value_bool(env, firstArg, &passes);
177-
}
174+
if (argc > 0) {
175+
napi_value firstArg = nullptr;
176+
napi_get_cb_info(env, cbinfo, &argc, &firstArg, nullptr, nullptr);
177+
napi_coerce_to_bool(env, firstArg, &firstArg);
178+
napi_get_value_bool(env, firstArg, &passes);
179+
}
178180

179-
if (!passes) {
180-
initialArg = 1;
181-
} else {
182-
return UNDEFINED;
181+
if (!passes) {
182+
initialArg = 1;
183+
} else {
184+
return UNDEFINED;
185+
}
183186
}
184-
}
185187

186-
napi_value argv[argc];
187-
napi_get_cb_info(env, cbinfo, &argc, argv, nullptr, nullptr);
188-
189-
napi_value global, Symbol, SymbolFor, symbolDescription, symbol;
190-
napi_get_global(env, &global);
191-
napi_get_named_property(env, global, "Symbol", &Symbol);
192-
napi_get_named_property(env, Symbol, "for", &SymbolFor);
193-
napi_create_string_utf8(env, "nodejs.util.inspect.custom", NAPI_AUTO_LENGTH,
194-
&symbolDescription);
195-
napi_call_function(env, global, SymbolFor, 1, &symbolDescription, &symbol);
196-
197-
std::stringstream log;
198-
199-
// TODO(dj): what if we made this pretty?
200-
201-
log << "CONSOLE";
202-
switch (stream) {
203-
case kConsoleLogTypeLog:
204-
log << " LOG";
205-
break;
206-
case kConsoleLogTypeError:
207-
log << " ERROR";
208-
break;
209-
case kConsoleLogTypeWarn:
210-
log << " WARN";
211-
break;
212-
case kConsoleLogTypeInfo:
213-
log << " INFO";
214-
break;
215-
case kConsoleLogTypeAssert:
216-
log << " ASSERT FAILED";
217-
break;
218-
}
219-
log << ": ";
188+
napi_value argv[argc];
189+
napi_get_cb_info(env, cbinfo, &argc, argv, nullptr, nullptr);
190+
191+
napi_value global, Symbol, SymbolFor, symbolDescription, symbol;
192+
napi_get_global(env, &global);
193+
napi_get_named_property(env, global, "Symbol", &Symbol);
194+
napi_get_named_property(env, Symbol, "for", &SymbolFor);
195+
napi_create_string_utf8(env, "nodejs.util.inspect.custom", NAPI_AUTO_LENGTH,
196+
&symbolDescription);
197+
napi_call_function(env, global, SymbolFor, 1, &symbolDescription, &symbol);
198+
199+
std::stringstream log;
200+
201+
// TODO(dj): what if we made this pretty?
202+
203+
log << "CONSOLE";
204+
switch (stream) {
205+
case kConsoleLogTypeLog:
206+
log << " LOG";
207+
break;
208+
case kConsoleLogTypeError:
209+
log << " ERROR";
210+
break;
211+
case kConsoleLogTypeWarn:
212+
log << " WARN";
213+
break;
214+
case kConsoleLogTypeInfo:
215+
log << " INFO";
216+
break;
217+
case kConsoleLogTypeAssert:
218+
log << " ASSERT FAILED";
219+
break;
220+
}
221+
log << ": ";
220222

221-
log << buildLogString(env, cbinfo, initialArg);
223+
log << buildLogString(env, cbinfo, initialArg);
222224

223-
log << "\n";
225+
log << "\n";
224226

225-
std::string logString = log.str();
227+
std::string logString = log.str();
226228

227229
#ifdef __APPLE__
228-
NSLog(CFSTR("%s"), logString.c_str());
230+
NSLog(CFSTR("%s"), logString.c_str());
229231
#else
230-
switch (stream) {
231-
case kConsoleLogTypeLog:
232-
case kConsoleLogTypeInfo:
233-
std::cout << logString;
234-
break;
235-
case kConsoleLogTypeError:
236-
case kConsoleLogTypeWarn:
237-
case kConsoleLogTypeAssert:
238-
std::cerr << logString;
239-
break;
240-
}
232+
switch (stream) {
233+
case kConsoleLogTypeLog:
234+
case kConsoleLogTypeInfo:
235+
std::cout << logString;
236+
break;
237+
case kConsoleLogTypeError:
238+
case kConsoleLogTypeWarn:
239+
case kConsoleLogTypeAssert:
240+
std::cerr << logString;
241+
break;
242+
}
241243
#endif
242244

243245
#ifdef TARGET_ENGINE_V8
244-
v8_inspector::ConsoleAPIType method;
245-
switch (stream) {
246-
case kConsoleLogTypeLog:
247-
method = v8_inspector::ConsoleAPIType::kLog;
248-
break;
249-
case kConsoleLogTypeError:
250-
method = v8_inspector::ConsoleAPIType::kError;
251-
break;
252-
case kConsoleLogTypeWarn:
253-
method = v8_inspector::ConsoleAPIType::kWarning;
254-
break;
255-
case kConsoleLogTypeInfo:
256-
method = v8_inspector::ConsoleAPIType::kInfo;
257-
break;
258-
case kConsoleLogTypeAssert:
259-
method = v8_inspector::ConsoleAPIType::kAssert;
260-
break;
261-
default:
262-
break;
263-
}
246+
v8_inspector::ConsoleAPIType method;
247+
switch (stream) {
248+
case kConsoleLogTypeLog:
249+
method = v8_inspector::ConsoleAPIType::kLog;
250+
break;
251+
case kConsoleLogTypeError:
252+
method = v8_inspector::ConsoleAPIType::kError;
253+
break;
254+
case kConsoleLogTypeWarn:
255+
method = v8_inspector::ConsoleAPIType::kWarning;
256+
break;
257+
case kConsoleLogTypeInfo:
258+
method = v8_inspector::ConsoleAPIType::kInfo;
259+
break;
260+
case kConsoleLogTypeAssert:
261+
method = v8_inspector::ConsoleAPIType::kAssert;
262+
break;
263+
default:
264+
break;
265+
}
264266

265-
sendToDevToolsFrontEnd(env, method, logString);
267+
sendToDevToolsFrontEnd(env, method, logString);
266268
#endif
269+
} catch (NativeScriptException& e) {
270+
e.ReThrowToJS(env);
271+
}
267272

268273
return UNDEFINED;
269274
}

NativeScript/runtime/modules/module/ModuleInternal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ napi_value ModuleInternal::LoadModule(napi_env env,
593593

594594
// napi_status status = js_execute_script(
595595
// env, script, EnsureFileProtocol(modulePath).c_str(), &moduleFunc);
596-
napi_status status = napi_run_script(
597-
env, script, &moduleFunc);
596+
napi_status status = napi_run_script_source(
597+
env, script, modulePath.c_str(), &moduleFunc);
598598
if (status != napi_ok) {
599599
bool pendingException;
600600
napi_is_exception_pending(env, &pendingException);

build_all_ios.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rm -rf ./dist
88
# ./update_version.sh
99
# fi
1010
./build_metadata_generator.sh
11-
./build_nativescript.sh --no-vision $1
11+
./build_nativescript.sh --no-vision $1 $2
1212
./build_tklivesync.sh --no-vision
1313
./prepare_dSYMs.sh
1414
./build_npm_ios.sh

build_nativescript.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ checkpoint "Building NativeScript for macOS"
124124

125125
cmake_build macos
126126

127+
cp "$DIST/intermediates/macos/$CONFIG_BUILD/libNativeScript.dylib" "$DIST/../packages/macos/dist/macos/NativeScript.node"
128+
127129
fi
128130

129131
if $BUILD_VISION; then
@@ -162,10 +164,6 @@ if $BUILD_IPHONE; then
162164
-debug-symbols "$DIST/intermediates/ios/$CONFIG_BUILD-iphoneos/NativeScript.framework.dSYM" )
163165
fi
164166

165-
if $BUILD_MACOS; then
166-
XCFRAMEWORKS+=( -framework "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework"
167-
-debug-symbols "$DIST/intermediates/macos/$CONFIG_BUILD/NativeScript.framework.dSYM" )
168-
fi
169167

170168
if $BUILD_VISION; then
171169
XCFRAMEWORKS+=( -framework "$DIST/intermediates/visionos/$CONFIG_BUILD-xros/NativeScript.framework"

cli_tests/threadsafe.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// NSOperationQueue.mainQueue.addOperationWithBlock(() => {
2+
// console.log("Hello from the main queue");
3+
// });
4+
5+
// const bgQueue = NSOperationQueue.new();
6+
7+
// bgQueue.addOperationWithBlock(() => {
8+
// console.log("Hello from the background queue");
9+
// });
10+
11+
dispatch_async(dispatch_get_current_queue(), () => {
12+
console.log("Hello from the main queue");
13+
});
14+
15+
dispatch_async(dispatch_get_global_queue(qos_class_t.DEFAULT, 0), () => {
16+
console.log("Hello from the background queue");
17+
});
18+
19+
NSApplicationMain(0, null);

0 commit comments

Comments
 (0)