Skip to content

Commit 505a68b

Browse files
committed
more macos tests
1 parent f89c0e7 commit 505a68b

32 files changed

Lines changed: 825 additions & 277 deletions

NativeScript/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ target_sources(
290290
"NativeScript.h"
291291
)
292292

293+
if(TARGET_ENGINE_V8 AND TARGET_PLATFORM_IOS)
294+
# iOS V8 slices are built with pointer compression enabled. Keep embedder
295+
# build flags in sync to satisfy V8::Initialize() build config checks.
296+
target_compile_definitions(
297+
${NAME}
298+
PRIVATE
299+
V8_COMPRESS_POINTERS
300+
V8_31BIT_SMIS_ON_64BIT_ARCH
301+
)
302+
endif()
303+
293304
set(FRAMEWORK_VERSION_VALUE "${VERSION}")
294305
if(TARGET_PLATFORM_MACOS)
295306
# macOS framework consumers (including Xcode's copy/sign phases) expect

NativeScript/napi/v8/jsr.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@
88
#include <ctime>
99
#include <fstream>
1010

11+
#if defined(__APPLE__)
12+
#include <TargetConditionals.h>
13+
#endif
14+
1115
#include "libplatform/libplatform.h"
1216
#include "v8-fast-api-calls.h"
1317

1418
using namespace v8;
1519
using namespace tns;
1620

21+
#if defined(__APPLE__) && TARGET_OS_IPHONE
22+
static_assert(v8::internal::PointerCompressionIsEnabled(),
23+
"iOS V8 embedder must be built with pointer compression enabled");
24+
static_assert(v8::internal::SmiValuesAre31Bits(),
25+
"iOS V8 embedder must use 31-bit smis on 64-bit arch");
26+
#endif
27+
1728
tns::SimpleAllocator g_allocator;
1829

1930
static void divide(const FunctionCallbackInfo<Value>& args) {

NativeScript/napi/v8/v8_inspector/src/base/base-export.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_BASE_EXPORT_H_
66
#define V8_BASE_BASE_EXPORT_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99

1010
#if V8_OS_WIN
1111

NativeScript/napi/v8/v8_inspector/src/base/bounds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_BOUNDS_H_
66
#define V8_BASE_BOUNDS_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99
#include "src/base/macros.h"
1010

1111
namespace v8 {

NativeScript/napi/v8/v8_inspector/src/base/build_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_BUILD_CONFIG_H_
66
#define V8_BASE_BUILD_CONFIG_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99

1010
// Processor architecture detection. For more info on what's defined, see:
1111
// http://msdn.microsoft.com/en-us/library/b0084kay.aspx

NativeScript/napi/v8/v8_inspector/src/base/compiler-specific.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_COMPILER_SPECIFIC_H_
66
#define V8_BASE_COMPILER_SPECIFIC_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99

1010
// Annotation to silence compiler warnings about unused
1111
// types/functions/variables. Use like:

NativeScript/napi/v8/v8_inspector/src/base/immediate-crash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_IMMEDIATE_CRASH_H_
66
#define V8_BASE_IMMEDIATE_CRASH_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99
#include "src/base/build_config.h"
1010

1111
// Crashes in the fastest possible way with no attempt at logging.

NativeScript/napi/v8/v8_inspector/src/base/platform/platform-posix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_BASE_PLATFORM_PLATFORM_POSIX_H_
66
#define V8_BASE_PLATFORM_PLATFORM_POSIX_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99
#include "src/base/platform/platform.h"
1010
#include "src/base/timezone-cache.h"
1111

NativeScript/napi/v8/v8_inspector/src/inspector/test-interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#ifndef V8_INSPECTOR_TEST_INTERFACE_H_
66
#define V8_INSPECTOR_TEST_INTERFACE_H_
77

8-
#include "include/v8config.h"
8+
#include "v8config.h"
99

1010
namespace v8_inspector {
1111

NativeScript/runtime/NativeScript.mm

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "NativeScript.h"
22
#include "Runtime.h"
33
#include "RuntimeConfig.h"
4+
#include "js_native_api.h"
5+
#include "jsr.h"
6+
#include "ffi/NativeScriptException.h"
47
#include "ffi/Tasks.h"
58

69
using namespace nativescript;
@@ -31,13 +34,93 @@ - (void)runScriptString:(NSString*)script runLoop:(BOOL)runLoop {
3134

3235
- (void)runMainApplication {
3336
std::string spec = "./app";
34-
runtime_->RunModule(spec);
37+
try {
38+
runtime_->RunModule(spec);
39+
} catch (const NativeScriptException& e) {
40+
std::string description = e.Description();
41+
NSLog(@"NativeScript runMainApplication failed: %s", description.c_str());
42+
@throw [NSException exceptionWithName:@"NativeScriptException"
43+
reason:@(description.c_str())
44+
userInfo:nil];
45+
} catch (const std::exception& e) {
46+
NSLog(@"NativeScript runMainApplication failed: %s", e.what());
47+
@throw [NSException exceptionWithName:@"NativeScriptException"
48+
reason:@(e.what())
49+
userInfo:nil];
50+
}
3551
runtime_->RunLoop();
3652
Tasks::Drain();
3753
}
3854

3955
- (bool)liveSync {
40-
return false;
56+
if (!runtime_) {
57+
return false;
58+
}
59+
60+
napi_env env = runtime_->GetEnv();
61+
if (env == nullptr) {
62+
return false;
63+
}
64+
65+
bool didInvokeCallback = false;
66+
67+
NapiScope scope(env);
68+
69+
napi_value global;
70+
if (napi_get_global(env, &global) != napi_ok) {
71+
return false;
72+
}
73+
74+
bool hasLiveSyncCallback = false;
75+
if (napi_has_named_property(env, global, "__onLiveSync",
76+
&hasLiveSyncCallback) != napi_ok ||
77+
!hasLiveSyncCallback) {
78+
return false;
79+
}
80+
81+
napi_value callback;
82+
if (napi_get_named_property(env, global, "__onLiveSync", &callback) != napi_ok) {
83+
return false;
84+
}
85+
86+
napi_valuetype callbackType;
87+
if (napi_typeof(env, callback, &callbackType) != napi_ok ||
88+
callbackType != napi_function) {
89+
return false;
90+
}
91+
92+
napi_value context;
93+
if (napi_create_object(env, &context) != napi_ok) {
94+
return false;
95+
}
96+
97+
napi_value result;
98+
napi_status status = napi_call_function(env, global, callback, 1, &context, &result);
99+
if (status != napi_ok) {
100+
bool hasPendingException = false;
101+
if (napi_is_exception_pending(env, &hasPendingException) == napi_ok &&
102+
hasPendingException) {
103+
napi_value error;
104+
napi_get_and_clear_last_exception(env, &error);
105+
}
106+
return false;
107+
}
108+
109+
didInvokeCallback = true;
110+
111+
if (result != nullptr) {
112+
napi_valuetype returnType;
113+
if (napi_typeof(env, result, &returnType) == napi_ok &&
114+
returnType == napi_boolean) {
115+
bool callbackResult = false;
116+
if (napi_get_value_bool(env, result, &callbackResult) == napi_ok) {
117+
didInvokeCallback = callbackResult;
118+
}
119+
}
120+
}
121+
122+
Tasks::Drain();
123+
return didInvokeCallback;
41124
}
42125

43126
- (void)shutdownRuntime {

0 commit comments

Comments
 (0)