diff --git a/NativeScript/runtime/DictionaryAdapter.mm b/NativeScript/runtime/DictionaryAdapter.mm index 3d338d3d..12508695 100644 --- a/NativeScript/runtime/DictionaryAdapter.mm +++ b/NativeScript/runtime/DictionaryAdapter.mm @@ -34,6 +34,10 @@ - (instancetype)initWithMap:(std::shared_ptr>)map isolate:(Iso - (id)nextObject { Isolate* isolate = self->isolate_; + v8::Locker locker(isolate); + Isolate::Scope isolate_scope(isolate); + HandleScope handle_scope(isolate); + Local context = self->cache_->GetContext(); Local array = self->map_->Get(isolate).As()->AsArray(); @@ -82,15 +86,23 @@ - (instancetype)initWithProperties:(std::shared_ptr>)dictionar } - (Local)getProperties { + v8::Locker locker(self->isolate_); + Isolate::Scope isolate_scope(self->isolate_); + EscapableHandleScope handle_scope(self->isolate_); + Local context = self->cache_->GetContext(); Local properties; Local dictionary = self->dictionary_->Get(self->isolate_).As(); tns::Assert(dictionary->GetOwnPropertyNames(context).ToLocal(&properties), self->isolate_); - return properties; + return handle_scope.Escape(properties); } - (id)nextObject { Isolate* isolate = self->isolate_; + v8::Locker locker(isolate); + Isolate::Scope isolate_scope(isolate); + HandleScope handle_scope(isolate); + Local context = self->cache_->GetContext(); Local properties = [self getProperties]; if (self->index_ < properties->Length()) { @@ -107,6 +119,10 @@ - (id)nextObject { - (NSArray*)allObjects { Isolate* isolate = self->isolate_; + v8::Locker locker(isolate); + Isolate::Scope isolate_scope(isolate); + HandleScope handle_scope(isolate); + Local context = self->cache_->GetContext(); NSMutableArray* array = [NSMutableArray array]; Local properties = [self getProperties]; @@ -146,6 +162,10 @@ - (instancetype)initWithJSObject:(Local)jsObject isolate:(Isolate*)isola } - (NSUInteger)count { + v8::Locker locker(self->isolate_); + Isolate::Scope isolate_scope(self->isolate_); + HandleScope handle_scope(self->isolate_); + Local obj = self->object_->Get(self->isolate_).As(); if (obj->IsMap()) { @@ -163,6 +183,10 @@ - (NSUInteger)count { - (id)objectForKey:(id)aKey { Isolate* isolate = self->isolate_; + v8::Locker locker(isolate); + Isolate::Scope isolate_scope(isolate); + HandleScope handle_scope(isolate); + Local context = self->cache_->GetContext(); Local obj = self->object_->Get(self->isolate_).As(); @@ -194,6 +218,10 @@ - (id)objectForKey:(id)aKey { } - (NSEnumerator*)keyEnumerator { + v8::Locker locker(self->isolate_); + Isolate::Scope isolate_scope(self->isolate_); + HandleScope handle_scope(self->isolate_); + Local obj = self->object_->Get(self->isolate_); if (obj->IsMap()) { diff --git a/NativeScript/runtime/PromiseProxy.cpp b/NativeScript/runtime/PromiseProxy.cpp index 85952f11..64a89809 100644 --- a/NativeScript/runtime/PromiseProxy.cpp +++ b/NativeScript/runtime/PromiseProxy.cpp @@ -28,14 +28,14 @@ void PromiseProxy::Init(v8::Local context) { return new Proxy(promise, { get: function(target, name) { let orig = target[name]; - if (name === "then" || name === "catch") { + if (name === "then" || name === "catch" || name === "finally") { return orig.bind(target); } - return function(x) { + return typeof orig === 'function' ? function(x) { CFRunLoopPerformBlock(runloop, kCFRunLoopDefaultMode, orig.bind(target, x)); CFRunLoopWakeUp(runloop); return target; - }; + } : orig; } }); }