aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2014-05-13 01:06:05 -0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-05-21 23:07:56 +0700
commit121cb8f58671140441eec21780f97fef4f8cb667 (patch)
tree8ceeb480041782a9af00b33893eb3f90bee639dc /src
parenta33f6e69daf7428ae03dc7a024644e0ba944f70a (diff)
Passing an argument from C++ into JavaScript has 'borrow' semantics rather than ownership semantics. That is, to keep a reference beyond the function call, you must call .clone(). This is necessary to avoid special-casing non-overridden virtual functions. (I don't know if this change will stick. It's possible it will have some problems.)
Diffstat (limited to 'src')
-rw-r--r--src/embind/embind.js9
-rw-r--r--src/embind/emval.js9
2 files changed, 17 insertions, 1 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 9f3e6eff..124ea569 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -590,6 +590,9 @@ function __embind_register_emval(rawType, name) {
'argPackAdvance': 8,
'readValueFromPointer': simpleReadValueFromPointer,
destructorFunction: null, // This type does not need a destructor
+
+ // TODO: do we need a deleteObject here? write a test where
+ // emval is passed into JS via an interface
});
}
@@ -1195,6 +1198,12 @@ RegisteredPointer.prototype.destructor = function destructor(ptr) {
RegisteredPointer.prototype['argPackAdvance'] = 8;
RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer;
+RegisteredPointer.prototype['deleteObject'] = function deleteObject(handle) {
+ if (handle !== null) {
+ handle['delete']();
+ }
+};
+
RegisteredPointer.prototype['fromWireType'] = function fromWireType(ptr) {
// ptr is a raw pointer (or a raw smartpointer)
diff --git a/src/embind/emval.js b/src/embind/emval.js
index 2b49fc83..1661bc02 100644
--- a/src/embind/emval.js
+++ b/src/embind/emval.js
@@ -265,7 +265,14 @@ function __emval_get_method_caller(argCount, argTypes) {
" args += argType" + i + ".argPackAdvance;\n";
}
functionBody +=
- " var rv = handle[name](" + argsList + ");\n" +
+ " var rv = handle[name](" + argsList + ");\n";
+ for (var i = 0; i < argCount - 1; ++i) {
+ if (types[i + 1]['deleteObject']) {
+ functionBody +=
+ " argType" + i + ".deleteObject(arg" + i + ");\n";
+ }
+ }
+ functionBody +=
" return retType.toWireType(destructors, rv);\n" +
"};\n";