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

[TIMOB-24021] [TIMOB-24022] Fixes for Android hyperloop #86

Merged
merged 2 commits into from
Oct 12, 2016
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -24,13 +24,13 @@ if (isInnerClass) {
// it's a nested class. Load up the parent, then just hang our class off of that.
parent = classDefinition.name.slice(0, classDefinition.name.indexOf('$'));
-%>
var EnclosingClass = require('<%= parent %>');
var EnclosingClass = require('./<%= parent %>');
<%
} else if (parts.length > 1) {
// hang off the package
parent = parts.slice(0, parts.length - 1).join('.');
-%>
var parentPackage = require('<%= parent %>');
var parentPackage = require('./<%= parent %>');
<% } -%>

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ global.<%= baseName %> = <%= sanitizedName %>;
<% if (classDefinition.superClass) {
// This is a subclass, let's extend the superclass!
-%>
var SuperClass = require('<%- classDefinition.superClass %>');
var SuperClass = require('./<%- classDefinition.superClass %>');
<%= sanitizedName %>.prototype = Object.create(SuperClass.prototype);
<%= sanitizedName %>.prototype.constructor = <%= sanitizedName %>;

Expand Down Expand Up @@ -124,7 +124,7 @@ if (classDefinition.attributes.indexOf('final') == -1 &&

function _wrapArg(arg) {
if (arg.apiName && arg.isNativeProxy && arg.isInstanceProxy) { // Assume hyperloop proxy, wrap in JS wrapper
var other = require(arg.apiName);
var other = require('./' + arg.apiName);
return new other(arg);
}
return arg;
Expand Down Expand Up @@ -197,7 +197,7 @@ if (classDefinition.innerClasses) {
-%>
Object.defineProperty(<%= sanitizedName %>, '<%= baseInnerClassName %>', {
get: function() {
return require('<%= innerClassName %>');
return require('./<%= innerClassName %>');
},
enumerable: true
});
Expand Down Expand Up @@ -227,7 +227,7 @@ Object.defineProperty(<%= sanitizedName %>, '<%= propertyName %>', {
if (result.apiName === '<%= classDefinition.name %>') {
return new <%= sanitizedName %>(result);
} else {
var ctor = require(result.apiName);
var ctor = require('./' + result.apiName);
return new ctor(result);
}
}
Expand Down Expand Up @@ -271,7 +271,7 @@ Object.defineProperty(<%= sanitizedName %>.prototype, '<%= propertyName %>', {
if (result.apiName === '<%= classDefinition.name %>') {
return new <%= sanitizedName %>(result);
} else {
var ctor = require(result.apiName);
var ctor = require('./' + result.apiName);
return new ctor(result);
}
}
Expand Down Expand Up @@ -342,7 +342,7 @@ for (var methodName in classDefinition.methods) {
if (result.apiName === '<%= classDefinition.name %>') {
return new <%= sanitizedName %>(result);
} else {
var ctor = require(result.apiName);
var ctor = require('./' + result.apiName);
return new ctor(result);
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ for (var methodName in classDefinition.methods) {
if (result.apiName === '<%= classDefinition.name %>') {
return new <%= sanitizedName %>(result);
} else {
var ctor = require(result.apiName);
var ctor = require('./' + result.apiName);
return new ctor(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ if (isInnerClass) {
// it's a nested class. Load up the parent, then just hang our class off of that.
parent = classDefinition.name.slice(0, classDefinition.name.indexOf('$'));
-%>
var EnclosingClass = require('<%= parent %>');
var EnclosingClass = require('./<%= parent %>');
<%
} else if (parts.length > 1) {
// hang off the package
parent = parts.slice(0, parts.length - 1).join('.');
-%>
var parentPackage = require('<%= parent %>');
var parentPackage = require('./<%= parent %>');
<% } -%>

/**
Expand All @@ -52,7 +52,7 @@ var <%= sanitizedName %> = function() {

function _wrapArg(arg) {
if (arg.apiName && arg.isNativeProxy && arg.isInstanceProxy) { // Assume hyperloop proxy, wrap in JS wrapper
var other = require(arg.apiName);
var other = require('./' + arg.apiName);
return new other(arg);
}
return arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var sanitizedName = packageDefinition.safeName,
* @module <%= packageDefinition.name %>
*/
<% if (parts.length > 1) { -%>
var parent = require('<%= parent %>') || {};
var parent = require('./<%= parent %>') || {};
<% } else { -%>
var parent = global;
<% } -%>
Expand All @@ -39,7 +39,7 @@ if (packageDefinition.classes) {
-%>
Object.defineProperty(<%= sanitizedName %>, '<%= baseClassName %>', {
get: function() {
return require('<%= className %>');
return require('./<%= className %>');
},
enumerable: true
});
Expand Down
17 changes: 9 additions & 8 deletions android/src/hyperloop/ClassProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public InstanceProxy newInstance(Object[] initArgs) {
} else {
// Handle converting JS arguments object from HashMap to Object[]
if (initArgs != null && initArgs.length == 1 && initArgs[0] instanceof Map) {
initArgs = convertArgumentsMapToArray((Map<Integer, Object>) initArgs[0]);
initArgs = convertArgumentsMapToArray((Map<String, Object>) initArgs[0]);
}
}

Expand Down Expand Up @@ -109,26 +109,27 @@ public InstanceProxy newInstance(Object[] initArgs) {
}

/**
* When we receive a JS arguments object, it comes in as a Map<Integer,
* Object>. This converts that to an Object[]. If no entry exists for an
* When we receive a JS arguments object, it comes in as a Map<String,
* Object> (where the String key is an integer). This converts that to an Object[]. If no entry exists for an
* index, we place null in the array.
*
* @param object
* @return
*/
private Object[] convertArgumentsMapToArray(Map<Integer, Object> arguments) {
private Object[] convertArgumentsMapToArray(Map<String, Object> arguments) {
if (arguments == null || arguments.size() == 0) {
return new Object[0];
}
// find the highest index
int highest = 0;
for (Integer current : arguments.keySet()) {
highest = Math.max(highest, current);
for (String current : arguments.keySet()) {
Integer currentInt = Integer.valueOf(current);
highest = Math.max(highest, currentInt);
}
// create an array to hold proper amount of elements
Object[] array = new Object[highest + 1];
for (Map.Entry<Integer, Object> entry : arguments.entrySet()) {
array[entry.getKey()] = entry.getValue();
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
array[Integer.valueOf(entry.getKey())] = entry.getValue();
}
return array;
}
Expand Down