Skip to content

Commit

Permalink
fix(android)(9_0_X): obtain holder for module references (#11561)
Browse files Browse the repository at this point in the history
Fixes TIMOB-27777
  • Loading branch information
garymathews committed Apr 14, 2020
1 parent 802687f commit 764f024
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Expand Up @@ -755,8 +755,17 @@ beprovided to handle the result.
holder = holder->FindInstanceInPrototypeChain(getProxyTemplate(isolate));
}
if (holder.IsEmpty() || holder->IsNull()) {
LOGE(TAG, "Couldn't obtain argument holder");
args.GetReturnValue().Set(v8::Undefined(isolate));
return;
if (!moduleInstance.IsEmpty()) {
holder = moduleInstance.Get(isolate);
if (holder.IsEmpty() || holder->IsNull()) {
LOGE(TAG, "Couldn't obtain argument holder");
args.GetReturnValue().Set(v8::Undefined(isolate));
return;
}
} else {
LOGE(TAG, "Couldn't obtain argument holder");
args.GetReturnValue().Set(v8::Undefined(isolate));
return;
}
}
</#macro>
Expand Up @@ -37,6 +37,7 @@ using namespace v8;
<#assign className = Proxy.className(proxyClassName)>

Persistent<FunctionTemplate> ${className}::proxyTemplate;
Persistent<Object> ${className}::moduleInstance;
jclass ${className}::javaClass = NULL;

${className}::${className}() : titanium::Proxy()
Expand All @@ -60,12 +61,13 @@ void ${className}::bindProxy(Local<Object> exports, Local<Context> context)
Local<String> nameSymbol = NEW_SYMBOL(isolate, "${proxyAttrs.name}"); // use symbol over string for efficiency
<#if isModule>
MaybeLocal<Object> maybeInstance = constructor->NewInstance(context);
Local<Object> moduleInstance;
if (!maybeInstance.ToLocal(&moduleInstance)) {
Local<Object> instance;
if (!maybeInstance.ToLocal(&instance)) {
titanium::V8Util::fatalException(isolate, tryCatch);
return;
}
exports->Set(context, nameSymbol, moduleInstance);
exports->Set(context, nameSymbol, instance);
moduleInstance.Reset(isolate, instance);
<#else>
exports->Set(context, nameSymbol, constructor);
</#if>
Expand All @@ -77,6 +79,9 @@ void ${className}::dispose(Isolate* isolate)
if (!proxyTemplate.IsEmpty()) {
proxyTemplate.Reset();
}
if (!moduleInstance.IsEmpty()) {
moduleInstance.Reset();
}

<#if superProxyClassName??>
<@Proxy.superNamespace/>${superProxyClassName}::dispose(isolate);
Expand Down
Expand Up @@ -27,6 +27,7 @@ public:

private:
static v8::Persistent<v8::FunctionTemplate> proxyTemplate;
static v8::Persistent<v8::Object> moduleInstance;

// Methods -----------------------------------------------------------
<@Proxy.listMethods ; isFirst, name, method>
Expand Down
27 changes: 27 additions & 0 deletions tests/Resources/core.runtime.addontest.js
@@ -0,0 +1,27 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2020 by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */

'use strict';

const should = require('./utilities/assertions');

describe.windowsBroken('Core', () => {
describe('Runtime', () => {
describe('Static Method Reference', () => {

// Reference static method.
const createProxy = Ti.createProxy;
should(createProxy).be.a.Function;

// Attempt to call static method.
const result = createProxy({});
should(result).be.a.Object;
});
});
});

0 comments on commit 764f024

Please sign in to comment.