aboutsummaryrefslogtreecommitdiff
path: root/src/embind/embind.js
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-03-23 02:07:45 -0700
committerJukka Jylänki <jujjyl@gmail.com>2013-04-12 14:26:36 +0300
commitb7936b0a61a37b451b2e4f01cb02986d26640d35 (patch)
treecbfd7e6a04e81420193c532e962a38ad53a0cf50 /src/embind/embind.js
parent0b8597a8dbf36b26dfb76df8d11fa7377bd810f1 (diff)
Unify 'this' handling in class functions. 'this' is just the first argument to the method. This removes several special cases and will remove even more soon.
Diffstat (limited to 'src/embind/embind.js')
-rwxr-xr-xsrc/embind/embind.js23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index ddfc4d43..d5e8659d 100755
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -958,7 +958,8 @@ function validateThis(this_, classType, humanName) {
if (!this_.$$.ptr) {
throwBindingError('cannot call emscripten binding method ' + humanName + ' on deleted object');
}
-
+
+ // todo: kill this
return upcastPointer(
this_.$$.ptr,
this_.$$.ptrType.registeredClass,
@@ -969,8 +970,7 @@ function __embind_register_class_function(
rawClassType,
methodName,
argCount,
- rawArgTypesAddr,
- isConst,
+ rawArgTypesAddr, // [ReturnType, ThisType, Args...]
rawInvoker,
memberFunctionSize,
memberFunction
@@ -990,21 +990,18 @@ function __embind_register_class_function(
whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
classType.registeredClass.instancePrototype[methodName] = function() {
- if (arguments.length !== argCount - 1) {
- throwBindingError('emscripten binding method ' + humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
+ if (arguments.length !== argCount - 2) {
+ throwBindingError(humanName + ' called with ' + arguments.length + ' arguments, expected ' + (argCount-1));
}
- var ptr = validateThis(this, classType, humanName);
- if (!isConst && this.$$.ptrType.isConst) {
- throwBindingError('Cannot call non-const method ' + humanName + ' on const reference');
- }
+ validateThis(this, classType, humanName);
var destructors = [];
var args = new Array(argCount + 1);
- args[0] = ptr;
- args[1] = memberFunction;
- for (var i = 1; i < argCount; ++i) {
- args[i + 1] = argTypes[i].toWireType(destructors, arguments[i - 1]);
+ args[0] = memberFunction;
+ args[1] = argTypes[1].toWireType(destructors, this);
+ for (var i = 2; i < argCount; ++i) {
+ args[i] = argTypes[i].toWireType(destructors, arguments[i - 2]);
}
var rv = rawInvoker.apply(null, args);
rv = argTypes[0].fromWireType(rv);