Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

fix: vue prototype and JSStringRef memory leak! #1977

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion ios/sdk/WeexSDK/Sources/Bridge/WXBridgeContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,30 @@ - (NSInteger)invokeNative:(NSString *)instanceId tasks:(NSArray *)tasks callback
return 1;
}

- (JSValueRef)getFunctionPrototype:(JSContextRef)ctx{
WXAssertParam(ctx);

JSStringRef funcstr = JSStringCreateWithUTF8CString("Function");
JSObjectRef global = JSContextGetGlobalObject(ctx);
JSValueRef exc = NULL;

JSValueRef value = JSObjectGetProperty(ctx, global, funcstr, &exc);
if (!value) {
WXLogError(@"%@",exc);
JSStringRelease(funcstr);
return NULL;
}
JSObjectRef funcCtor = JSValueToObject(ctx, value, &exc);
if (!funcCtor) {
WXLogError(@"%@",exc);
JSStringRelease(funcstr);
return NULL;
}
JSValueRef funcProto = JSObjectGetPrototype(ctx, funcCtor);
JSStringRelease(funcstr);
return funcProto;
}

- (void)createInstance:(NSString *)instanceIdString
template:(NSString *)jsBundleString
options:(NSDictionary *)options
Expand Down Expand Up @@ -489,9 +513,12 @@ - (void)createInstance:(NSString *)instanceIdString
for (NSString * key in allKeys) {
JSStringRef propertyName = JSStringCreateWithUTF8CString([key cStringUsingEncoding:NSUTF8StringEncoding]);
if ([key isEqualToString:@"Vue"]) {
JSObjectSetPrototype(instanceContextRef, JSValueToObject(instanceContextRef, [instanceContextEnvironment valueForProperty:key].JSValueRef, NULL), JSObjectGetPrototype(instanceContextRef, instanceGlobalObject));
JSValueRef funcProto = [self getFunctionPrototype:instanceContextRef];
WXAssert(funcProto,@"failed to get function prototype! ");
JSObjectSetPrototype(instanceContextRef, JSValueToObject(instanceContextRef, [instanceContextEnvironment valueForProperty:key].JSValueRef, NULL), funcProto);
}
JSObjectSetProperty(instanceContextRef, instanceGlobalObject, propertyName, [instanceContextEnvironment valueForProperty:key].JSValueRef, 0, NULL);
JSStringRelease(propertyName);
}

if (WX_SYS_VERSION_LESS_THAN(@"10.2")) {
Expand Down