aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <caustin@gmail.com>2014-03-23 14:03:07 -0700
committerChad Austin <chad@chadaustin.me>2014-03-28 23:56:41 -0700
commitb9abf3c50ff469a0a7c2824138210ecd6f0dd708 (patch)
tree033ced914aefa103d0fb2c0ad977678b3c1e7119 /src
parentbb34f6aaa0043e39d43b684f78099712b79026c2 (diff)
Some minor emval simplifications
Diffstat (limited to 'src')
-rw-r--r--src/embind/emval.js58
1 files changed, 23 insertions, 35 deletions
diff --git a/src/embind/emval.js b/src/embind/emval.js
index f0ca9b9b..f6f0f343 100644
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -55,6 +55,7 @@ function requireHandle(handle) {
if (!handle) {
throwBindingError('Cannot use deleted val. handle = ' + handle);
}
+ return _emval_handle_array[handle].value;
}
function __emval_register(value) {
@@ -116,14 +117,13 @@ var __newers = {}; // arity -> function
function craftEmvalAllocator(argCount) {
/*This function returns a new function that looks like this:
- function emval_allocator_3(handle, argTypes, args) {
+ function emval_allocator_3(constructor, argTypes, args) {
var argType0 = requireRegisteredType(HEAP32[(argTypes >> 2)], "parameter 0");
var arg0 = argType0.readValueFromPointer(args);
var argType1 = requireRegisteredType(HEAP32[(argTypes >> 2) + 1], "parameter 1");
var arg1 = argType1.readValueFromPointer(args + 8);
var argType2 = requireRegisteredType(HEAP32[(argTypes >> 2) + 2], "parameter 2");
var arg2 = argType2.readValueFromPointer(args + 16);
- var constructor = _emval_handle_array[handle].value;
var obj = new constructor(arg0, arg1, arg2);
return __emval_register(obj);
} */
@@ -134,7 +134,7 @@ function craftEmvalAllocator(argCount) {
}
var functionBody =
- "return function emval_allocator_"+argCount+"(handle, argTypes, args) {\n";
+ "return function emval_allocator_"+argCount+"(constructor, argTypes, args) {\n";
for(var i = 0; i < argCount; ++i) {
functionBody +=
@@ -142,18 +142,17 @@ function craftEmvalAllocator(argCount) {
"var arg"+i+" = argType"+i+".readValueFromPointer(args + " + i * 8 + ");\n";
}
functionBody +=
- "var constructor = _emval_handle_array[handle].value;\n" +
"var obj = new constructor("+argsList+");\n" +
"return __emval_register(obj);\n" +
"}\n";
/*jshint evil:true*/
- return (new Function("requireRegisteredType", "HEAP32", "_emval_handle_array", "__emval_register", functionBody))(
- requireRegisteredType, HEAP32, _emval_handle_array, __emval_register);
+ return (new Function("requireRegisteredType", "HEAP32", "__emval_register", functionBody))(
+ requireRegisteredType, HEAP32, __emval_register);
}
function __emval_new(handle, argCount, argTypes, args) {
- requireHandle(handle);
+ handle = requireHandle(handle);
var newer = __newers[argCount];
if (!newer) {
@@ -178,39 +177,29 @@ function __emval_get_module_property(name) {
}
function __emval_get_property(handle, key) {
- requireHandle(handle);
- return __emval_register(_emval_handle_array[handle].value[_emval_handle_array[key].value]);
+ handle = requireHandle(handle);
+ key = requireHandle(key);
+ return __emval_register(handle[key]);
}
function __emval_set_property(handle, key, value) {
- requireHandle(handle);
- _emval_handle_array[handle].value[_emval_handle_array[key].value] = _emval_handle_array[value].value;
+ handle = requireHandle(handle);
+ key = requireHandle(key);
+ value = requireHandle(value);
+ handle[key] = value;
}
function __emval_as(handle, returnType, destructorsRef) {
- requireHandle(handle);
+ handle = requireHandle(handle);
returnType = requireRegisteredType(returnType, 'emval::as');
var destructors = [];
var rd = __emval_register(destructors);
HEAP32[destructorsRef >> 2] = rd;
- return returnType['toWireType'](
- destructors,
- _emval_handle_array[handle].value);
-}
-
-function parseParameters(argCount, argTypes, argWireTypes) {
- var a = new Array(argCount);
- for (var i = 0; i < argCount; ++i) {
- var argType = requireRegisteredType(
- HEAP32[(argTypes >> 2) + i],
- "parameter " + i);
- a[i] = argType['fromWireType'](argWireTypes[i]);
- }
- return a;
+ return returnType['toWireType'](destructors, handle);
}
function __emval_call(handle, argCount, argTypes) {
- requireHandle(handle);
+ handle = requireHandle(handle);
var types = lookupTypes(argCount, argTypes);
var args = new Array(argCount);
@@ -218,8 +207,7 @@ function __emval_call(handle, argCount, argTypes) {
args[i] = types[i]['fromWireType'](arguments[3 + i]);
}
- var fn = _emval_handle_array[handle].value;
- var rv = fn.apply(undefined, args);
+ var rv = handle.apply(undefined, args);
return __emval_register(rv);
}
@@ -245,8 +233,8 @@ function __emval_get_method_caller(argCount, argTypes) {
var retType = types[0];
var signatureName = retType.name + "_$" + types.slice(1).map(function (t) { return t.name; }).join("_") + "$";
- var args1 = ["addFunction", "createNamedFunction", "requireHandle", "getStringOrSymbol", "_emval_handle_array", "retType", "allocateDestructors"];
- var args2 = [Runtime.addFunction, createNamedFunction, requireHandle, getStringOrSymbol, _emval_handle_array, retType, allocateDestructors];
+ var args1 = ["addFunction", "createNamedFunction", "requireHandle", "getStringOrSymbol", "retType", "allocateDestructors"];
+ var args2 = [Runtime.addFunction, createNamedFunction, requireHandle, getStringOrSymbol, retType, allocateDestructors];
var argsList = ""; // 'arg0, arg1, arg2, ... , argN'
var argsListWired = ""; // 'arg0Wired, ..., argNWired'
@@ -259,15 +247,14 @@ function __emval_get_method_caller(argCount, argTypes) {
var invokerFnBody =
"return addFunction(createNamedFunction('" + signatureName + "', function (handle, name, destructorsRef" + argsListWired + ") {\n" +
- " requireHandle(handle);\n" +
+ " var handle = requireHandle(handle);\n" +
" name = getStringOrSymbol(name);\n";
for (var i = 0; i < argCount - 1; ++i) {
invokerFnBody += " var arg" + i + " = argType" + i + ".fromWireType(arg" + i + "Wired);\n";
}
invokerFnBody +=
- " var obj = _emval_handle_array[handle].value;\n" +
- " var rv = obj[name](" + argsList + ");\n" +
+ " var rv = handle[name](" + argsList + ");\n" +
" return retType.toWireType(allocateDestructors(destructorsRef), rv);\n" +
"}));\n";
@@ -277,6 +264,7 @@ function __emval_get_method_caller(argCount, argTypes) {
}
function __emval_has_function(handle, name) {
+ handle = requireHandle(handle);
name = getStringOrSymbol(name);
- return _emval_handle_array[handle].value[name] instanceof Function;
+ return handle[name] instanceof Function;
}