Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): obtain holder for module references #11498

Merged
merged 7 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,12 @@ 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);
garymathews marked this conversation as resolved.
Show resolved Hide resolved
} else {
LOGE(TAG, "Couldn't obtain argument holder");
args.GetReturnValue().Set(v8::Undefined(isolate));
return;
}
}
</#macro>
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
});
});
});