aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2014-05-02 14:56:45 -0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-05-21 22:55:45 +0700
commita30b438d002a389a523350e2bb0f66b0cf92711d (patch)
treef3f41012eca9acb1cfa32584e3609381b8c38799
parenta2487b69b6d5e0fc81ef67f062f61764fad5af00 (diff)
properties set in constructor persist to methods
-rw-r--r--src/embind/embind.js9
-rw-r--r--system/include/emscripten/bind.h6
-rw-r--r--system/include/emscripten/val.h5
-rw-r--r--tests/embind/embind.test.js6
4 files changed, 20 insertions, 6 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index fe784001..8947c76f 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -1730,17 +1730,24 @@ function __embind_register_class_class_function(
});
}
-function __embind_create_inheriting_constructor(constructorName, wrapperType) {
+function __embind_create_inheriting_constructor(constructorName, wrapperType, properties) {
constructorName = readLatin1String(constructorName);
wrapperType = requireRegisteredType(wrapperType, 'wrapper');
+ properties = requireHandle(properties);
+
var registeredClass = wrapperType.registeredClass;
var wrapperPrototype = registeredClass.instancePrototype;
var baseConstructor = registeredClass.baseClass.constructor;
var ctor = createNamedFunction(constructorName, function() {
var inner = baseConstructor.implement(this);
this.$$ = inner.$$;
+ this.initialize.apply(this, Array.prototype.slice.call(arguments));
});
ctor.prototype = Object.create(wrapperPrototype);
+ ctor.prototype.initialize = function initialize() {};
+ for (var p in properties) {
+ ctor.prototype[p] = properties[p];
+ }
return __emval_register(ctor);
}
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index a0545f3f..3c2d7097 100644
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -174,7 +174,8 @@ namespace emscripten {
EM_VAL _embind_create_inheriting_constructor(
const char* constructorName,
- TYPEID wrapperType);
+ TYPEID wrapperType,
+ EM_VAL properties);
void _embind_register_enum(
TYPEID enumType,
@@ -996,7 +997,8 @@ namespace emscripten {
val wrapped_extend(const std::string& name, const val& properties) {
return val::take_ownership(_embind_create_inheriting_constructor(
name.c_str(),
- TypeID<WrapperType>::get()));
+ TypeID<WrapperType>::get(),
+ properties.__get_handle()));
}
};
diff --git a/system/include/emscripten/val.h b/system/include/emscripten/val.h
index bfd8610a..8bcc30c4 100644
--- a/system/include/emscripten/val.h
+++ b/system/include/emscripten/val.h
@@ -411,6 +411,11 @@ namespace emscripten {
return fromGenericWireType<T>(result);
}
+ // private: TODO: use a friend?
+ internal::EM_VAL __get_handle() const {
+ return handle;
+ }
+
val typeof() const {
return val(_emval_typeof(handle));
}
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 17abccbf..49c70c6d 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1648,8 +1648,6 @@ module({
instance.delete();
});
-/* ENABLE THESE AS THEY PASS
-
test("properties set in constructor are externally visible", function() {
var HasProperty = cm.AbstractClass.extend("AbstractClass", {
initialize: function(x) {
@@ -1657,10 +1655,12 @@ module({
}
});
var instance = new HasProperty(10);
- assert.equal(10, instance.set_property);
+ assert.equal(10, instance.property);
instance.delete();
});
+/* ENABLE THESE AS THEY PASS
+
test("pass derived object to c++", function() {
var Implementation = cm.AbstractClass.extend("AbstractClass", {
abstractMethod: function() {