diff --git a/.gitignore b/.gitignore index aa6017ed..8e3a4c6f 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,8 @@ v8 .npmrc llvm/ + +# v8 build files... +.gclient_entries +.gclient +.cipd/ diff --git a/NativeScript/NativeScript-Prefix.pch b/NativeScript/NativeScript-Prefix.pch index 2d5e9175..a7fc6edd 100644 --- a/NativeScript/NativeScript-Prefix.pch +++ b/NativeScript/NativeScript-Prefix.pch @@ -1,7 +1,7 @@ #ifndef NativeScript_Prefix_pch #define NativeScript_Prefix_pch -#define NATIVESCRIPT_VERSION "8.3.1-alpha.0" +#define NATIVESCRIPT_VERSION "8.3.1-alpha.1" #ifdef DEBUG #define SIZEOF_OFF_T 8 diff --git a/NativeScript/runtime/Helpers.h b/NativeScript/runtime/Helpers.h index 1cec7b59..a2f43c4d 100644 --- a/NativeScript/runtime/Helpers.h +++ b/NativeScript/runtime/Helpers.h @@ -37,11 +37,21 @@ BaseDataWrapper* GetValue(v8::Isolate* isolate, const v8::Local& val) void DeleteValue(v8::Isolate* isolate, const v8::Local& val); std::vector> ArgsToVector(const v8::FunctionCallbackInfo& info); -bool IsString(v8::Local value); -bool IsNumber(v8::Local value); -bool IsBool(v8::Local value); -bool IsArrayOrArrayLike(v8::Isolate* isolate, v8::Local value); -void* TryGetBufferFromArrayBuffer(v8::Local value, bool& isArrayBuffer); +inline bool IsString(const v8::Local& value) { + return !value.IsEmpty() && (value->IsString() || value->IsStringObject()); +} + +inline bool IsNumber(const v8::Local& value) { + return !value.IsEmpty() && (value->IsNumber() || value->IsNumberObject()); +} + +inline bool IsBool(const v8::Local& value) { + return !value.IsEmpty() && (value->IsBoolean() || value->IsBooleanObject()); +} + + +bool IsArrayOrArrayLike(v8::Isolate* isolate, const v8::Local& value); +void* TryGetBufferFromArrayBuffer(const v8::Local& value, bool& isArrayBuffer); void ExecuteOnMainThread(std::function func, bool async = true); diff --git a/NativeScript/runtime/Helpers.mm b/NativeScript/runtime/Helpers.mm index b7d05375..7d12af9c 100644 --- a/NativeScript/runtime/Helpers.mm +++ b/NativeScript/runtime/Helpers.mm @@ -337,19 +337,7 @@ return args; } -bool tns::IsString(Local value) { - return !value.IsEmpty() && (value->IsString() || value->IsStringObject()); -} - -bool tns::IsNumber(Local value) { - return !value.IsEmpty() && (value->IsNumber() || value->IsNumberObject()); -} - -bool tns::IsBool(Local value) { - return !value.IsEmpty() && (value->IsBoolean() || value->IsBooleanObject()); -} - -bool tns::IsArrayOrArrayLike(Isolate* isolate, Local value) { +bool tns::IsArrayOrArrayLike(Isolate* isolate, const Local& value) { if (value->IsArray()) { return true; } @@ -365,7 +353,7 @@ return obj->Has(context, ToV8String(isolate, "length")).FromMaybe(false); } -void* tns::TryGetBufferFromArrayBuffer(v8::Local value, bool& isArrayBuffer) { +void* tns::TryGetBufferFromArrayBuffer(const v8::Local& value, bool& isArrayBuffer) { isArrayBuffer = false; if (value.IsEmpty() || (!value->IsArrayBuffer() && !value->IsArrayBufferView())) { diff --git a/NativeScript/runtime/Interop.h b/NativeScript/runtime/Interop.h index b5057163..78bc31c1 100644 --- a/NativeScript/runtime/Interop.h +++ b/NativeScript/runtime/Interop.h @@ -148,6 +148,7 @@ class Interop { static bool IsNumbericType(BinaryTypeEncodingType type); static v8::Local GetInteropType(v8::Local context, BinaryTypeEncodingType type); static std::vector GetAdditionalProtocols(const TypeEncoding* typeEncoding); + static SEL GetSwizzledMethodSelector(SEL selector); template static inline void SetValue(void* dest, T value) { @@ -192,6 +193,7 @@ class Interop { static JSBlockDescriptor kJSBlockDescriptor; } JSBlock; + }; } diff --git a/NativeScript/runtime/Interop.mm b/NativeScript/runtime/Interop.mm index de86059c..53bb1adc 100644 --- a/NativeScript/runtime/Interop.mm +++ b/NativeScript/runtime/Interop.mm @@ -18,6 +18,7 @@ #include "SymbolIterator.h" #include "UnmanagedType.h" #include "OneByteStringResource.h" +#include "robin_hood.h" using namespace v8; @@ -1366,6 +1367,26 @@ return result.As(); } +SEL Interop::GetSwizzledMethodSelector(SEL selector) { + static robin_hood::unordered_map *swizzledMethodSelectorCache = new robin_hood::unordered_map(); + + SEL swizzledMethodSelector = NULL; + + try { + swizzledMethodSelector = swizzledMethodSelectorCache->at(selector); + } catch(const std::out_of_range&) { + // ignore... + } + + if(!swizzledMethodSelector) { + swizzledMethodSelector = sel_registerName((Constants::SwizzledPrefix + std::string(sel_getName(selector))).c_str()); + // save to cache + swizzledMethodSelectorCache->emplace(selector, swizzledMethodSelector); + } + + return swizzledMethodSelector; +} + Local Interop::CallFunctionInternal(MethodCall& methodCall) { int initialParameterIndex = methodCall.isPrimitiveFunction_ ? 0 : 2; @@ -1401,9 +1422,7 @@ SEL selector = methodCall.selector_; if (isInstanceMethod) { - NSString* selectorStr = NSStringFromSelector(selector); - NSString* swizzledMethodSelectorStr = [NSString stringWithFormat:@"%s%@", Constants::SwizzledPrefix.c_str(), selectorStr]; - SEL swizzledMethodSelector = NSSelectorFromString(swizzledMethodSelectorStr); + SEL swizzledMethodSelector = Interop::GetSwizzledMethodSelector(selector); if ([methodCall.target_ respondsToSelector:swizzledMethodSelector]) { selector = swizzledMethodSelector; } diff --git a/package.json b/package.json index 80e7586d..f64a5e7c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@nativescript/ios", "description": "NativeScript Runtime for iOS", - "version": "8.3.1-alpha.0", + "version": "8.3.1-alpha.1", "keywords": [ "NativeScript", "iOS",