Skip to content

Commit 16c6049

Browse files
committed
Merge remote-tracking branch 'origin/main' into dev
2 parents 826a395 + 8329e87 commit 16c6049

File tree

6 files changed

+77
-16
lines changed

6 files changed

+77
-16
lines changed

NativeScript/runtime/Helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ inline bool IsNumber(const v8::Local<v8::Value>& value) {
158158
return !value.IsEmpty() && (value->IsNumber() || value->IsNumberObject());
159159
}
160160

161+
inline bool IsBigInt(const v8::Local<v8::Value>& value) {
162+
return !value.IsEmpty() && (value->IsBigInt() || value->IsBigIntObject());
163+
}
164+
161165
inline bool IsBool(const v8::Local<v8::Value>& value) {
162166
return !value.IsEmpty() && (value->IsBoolean() || value->IsBooleanObject());
163167
}

NativeScript/runtime/Pointer.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Local<Value> Pointer::NewInstance(Local<Context> context, void* handle) {
2020
Isolate* isolate = context->GetIsolate();
2121
intptr_t ptr = static_cast<intptr_t>(reinterpret_cast<size_t>(handle));
2222

23-
Local<Value> arg = Number::New(isolate, ptr);
23+
Local<Value> arg = BigInt::NewFromUnsigned(isolate, ptr);
2424
Local<Value> args[1] { arg };
2525
Local<Value> result;
2626
Local<v8::Function> ctorFunc = Pointer::GetPointerCtorFunc(context);
@@ -61,6 +61,7 @@ Local<v8::Function> Pointer::GetPointerCtorFunc(Local<Context> context) {
6161
Pointer::RegisterToHexStringMethod(context, prototype);
6262
Pointer::RegisterToDecimalStringMethod(context, prototype);
6363
Pointer::RegisterToNumberMethod(context, prototype);
64+
Pointer::RegisterToBigIntMethod(context, prototype);
6465

6566
cache->PointerCtorFunc = std::make_unique<Persistent<v8::Function>>(isolate, ctorFunc);
6667
cache->PointerCtorFunc->SetWrapperClassId(Constants::ClassTypes::DataWrapper);
@@ -75,12 +76,12 @@ void Pointer::PointerConstructorCallback(const FunctionCallbackInfo<Value>& info
7576
void* ptr = nullptr;
7677

7778
if (info.Length() == 1) {
78-
if (!tns::IsNumber(info[0])) {
79+
bool isBigInt = tns::IsBigInt(info[0]);
80+
bool isNumber = !isBigInt && tns::IsNumber(info[0]);
81+
if (!isBigInt && !isNumber) {
7982
throw NativeScriptException("Pointer constructor's first arg must be an integer.");
8083
}
8184

82-
Local<Number> arg = info[0].As<Number>();
83-
8485
#if __SIZEOF_POINTER__ == 8
8586
// JSC stores 64-bit integers as doubles in JSValue.
8687
// Caution: This means that pointers with more than 54 significant bits
@@ -89,12 +90,28 @@ void Pointer::PointerConstructorCallback(const FunctionCallbackInfo<Value>& info
8990
// so we're safe at the time being.
9091
// See https://en.wikipedia.org/wiki/X86-64#Virtual_address_space_details
9192
// and https://en.wikipedia.org/wiki/ARM_architecture#ARMv8-A
93+
94+
// The future is here, and turns out the OS is using more than 54 bits.
95+
// as a result,
9296
int64_t value;
93-
tns::Assert(arg->IntegerValue(context).To(&value), isolate);
97+
if (isBigInt) {
98+
value = info[0].As<BigInt>()->Int64Value();
99+
} else {
100+
// TODO: Maybe log this?
101+
//#ifdef DEBUG
102+
// syslog(LOG_WARNING, "Using JS Number to represent a pointer. Result might be wrong.");
103+
//#endif
104+
tns::Assert(info[0].As<Number>()->IntegerValue(context).To(&value), isolate);
105+
}
106+
94107
ptr = reinterpret_cast<void*>(value);
95108
#else
96109
int32_t value;
97-
tns::Assert(arg->Int32Value(context).To(&value), isolate);
110+
if (isBigInt) {
111+
value = (int32_t)info[0].As<BigInt>()->Int64Value();
112+
} else {
113+
tns::Assert(info[0].As<Number>()->Int32Value (context).To(&value), isolate);
114+
}
98115
ptr = reinterpret_cast<void*>(value);
99116
#endif
100117
}
@@ -255,4 +272,22 @@ void Pointer::RegisterToNumberMethod(Local<Context> context, Local<Object> proto
255272
tns::Assert(success, isolate);
256273
}
257274

275+
void Pointer::RegisterToBigIntMethod(Local<Context> context, Local<Object> prototype) {
276+
Isolate* isolate = context->GetIsolate();
277+
Local<FunctionTemplate> funcTemplate = FunctionTemplate::New(isolate, [](const FunctionCallbackInfo<Value>& info) {
278+
Isolate* isolate = info.GetIsolate();
279+
PointerWrapper* wrapper = static_cast<PointerWrapper*>(info.This()->GetInternalField(0).As<External>()->Value());
280+
const void* value = wrapper->Data();
281+
size_t number = reinterpret_cast<size_t>(value);
282+
Local<BigInt> result = BigInt::NewFromUnsigned(isolate, number);
283+
info.GetReturnValue().Set(result);
284+
});
285+
286+
Local<v8::Function> func;
287+
tns::Assert(funcTemplate->GetFunction(context).ToLocal(&func), isolate);
288+
289+
bool success = prototype->Set(context, tns::ToV8String(isolate, "toBigInt"), func).FromMaybe(false);
290+
tns::Assert(success, isolate);
291+
}
292+
258293
}

NativeScript/runtime/Pointer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Pointer {
1919
static void RegisterToHexStringMethod(v8::Local<v8::Context> context, v8::Local<v8::Object> prototype);
2020
static void RegisterToDecimalStringMethod(v8::Local<v8::Context> context, v8::Local<v8::Object> prototype);
2121
static void RegisterToNumberMethod(v8::Local<v8::Context> context, v8::Local<v8::Object> prototype);
22+
static void RegisterToBigIntMethod(v8::Local<v8::Context> context, v8::Local<v8::Object> prototype);
2223
};
2324

2425
}

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ brew install cmake
1010
sudo ln -s /usr/local/bin/cmake $(which cmake)
1111

1212
# Clone repo
13-
git clone https://github.com/NativeScript/ns-v8ios-runtime.git
13+
git clone https://github.com/NativeScript/ios.git
1414

1515
# Initialize and clone the submodules
16-
cd ns-v8ios-runtime
16+
cd ios
1717
git submodule update --init
1818

1919
# Ensure that you have the required llvm binaries for building the metadata generator
@@ -73,7 +73,7 @@ Add the `Nativescript.framework` from the v8ios workspace:
7373
If you encounter vague errors like this when building your app with the runtime included (This has been observed sometimes while Profiling apps in Xcode):
7474

7575
```
76-
/path/to/ns-v8ios-runtime/NativeScript/inspector/src/base/atomicops.h:311:11: No matching function for call to 'Relaxed_Load'
76+
/path/to/ios/NativeScript/inspector/src/base/atomicops.h:311:11: No matching function for call to 'Relaxed_Load'
7777
```
7878

7979
This is most likely related to `Build Active Architecture Only` setting in Xcode for various targets (your app and the included v8ios runtime). You should check to make sure your app `Build Settings` and the v8ios targets `NativeScript` and `TKLiveSync` Build Settings are set to YES for both Debug and Release. See this reference:
@@ -101,8 +101,8 @@ In order to build the V8 engine for iOS and produce the static libraries used in
101101
**Prerequisites:**
102102

103103
```
104-
git clone https://github.com/NativeScript/ns-v8ios-runtime.git
105-
cd ns-v8ios-runtime
104+
git clone https://github.com/NativeScript/ios.git
105+
cd ios
106106
```
107107

108108
You will need Google [depot_tools](https://www.chromium.org/developers/how-tos/install-depot-tools)
@@ -122,7 +122,7 @@ export PATH=`pwd`/depot_tools:"$PATH"
122122
123123
```
124124
// IMPORTANT: Make sure you are inside the clone of this repo...
125-
cd ns-v8ios-runtime
125+
cd ios
126126
127127
// Fetch v8 source:
128128
fetch v8
@@ -158,7 +158,7 @@ error: patch failed: BUILD.gn:538
158158
error: BUILD.gn: patch does not apply
159159
error: patch failed: src/inspector/inspector_protocol_config.json:21
160160
error: src/inspector/inspector_protocol_config.json: patch does not apply
161-
~/Documents/ns-v8ios-runtime/v8/build ~/Documents/ns-v8ios-runtime/v8 ~/Documents/ns-v8ios-runtime
161+
~/Documents/ios/v8/build ~/Documents/ios/v8 ~/Documents/ios
162162
error: patch failed: config/ios/ios_sdk.gni:32
163163
error: config/ios/ios_sdk.gni: patch does not apply
164164
```
@@ -176,12 +176,12 @@ npm run build-v8-source
176176
* Example failure 1:
177177

178178
```
179-
@Mac ns-v8ios-runtime % npm run build-v8-source
179+
@Mac ios % npm run build-v8-source
180180
181181
> @nativescript/[email protected] build-v8-source
182182
> ./build_v8_source.sh
183183
184-
~/Documents/ns-v8ios-runtime/v8 ~/Documents/ns-v8ios-runtime
184+
~/Documents/ios/v8 ~/Documents/ios
185185
Building for out.gn/x64-release (simulator)
186186
Done. Made 212 targets from 92 files in 4004ms
187187
ninja: Entering directory `out.gn/x64-release'

TestRunner/app/tests/Marshalling/PointerTests.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@ describe(module.id, function () {
1818
expect(pointer.toString()).toBe(`<Pointer: ${hexMinusOneForCurrentBitness}>`);
1919
});
2020

21+
it("Pointer from a BigInt", function () {
22+
const number = 0x12abcdef;
23+
var pointer = new interop.Pointer(BigInt(number));
24+
expect(pointer instanceof interop.Pointer).toBe(true);
25+
expect(pointer.toNumber()).toBe(number);
26+
expect(pointer.toString()).toBe(`<Pointer: 0x${number.toString(16)}>`);
27+
expect(pointer.toDecimalString()).toBe(number.toString());
28+
expect(pointer.toBigInt()).toBe(BigInt(number));
29+
});
30+
31+
it("Pointer from a really big BigInt", function () {
32+
const number = BigInt("0x1fffffffffffffff");
33+
var pointer = new interop.Pointer(number);
34+
expect(pointer instanceof interop.Pointer).toBe(true);
35+
// toNumber is no longer accurate
36+
expect(pointer.toNumber()).toBeGreaterThan(Number.MAX_SAFE_INTEGER);
37+
expect(pointer.toString()).toBe(`<Pointer: 0x${number.toString(16)}>`);
38+
expect(pointer.toDecimalString()).toBe(number.toString());
39+
expect(pointer.toBigInt()).toBe(BigInt(number));
40+
});
41+
2142
it("Pointer from a wrapped Number", function () {
2243
const number = 0x12abcdef;
2344
var pointer = new interop.Pointer(new Number(number));

metadata-generator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (NOT LIBXML2_FOUND)
1313
endif ()
1414

1515
get_filename_component(LLVM_ROOT "../../llvm/13.0.1" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
16-
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)
16+
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)
1717

1818
set(LLVM_SYSTEM_LIBS "-lz -lcurses -lm -lxml2")
1919
set(LLVM_PREPROCESSOR_FLAGS "-I${LLVM_ROOT}/include -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS")

0 commit comments

Comments
 (0)