aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Austin <caustin@gmail.com>2014-05-03 23:13:29 -0700
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-05-21 22:58:10 +0700
commit6e7397193370ebad6be01438ab1e65223820e909 (patch)
tree651a95b66dba3f2bfefee1e802a43f97b816cf6a
parent54b4bc160a2d86082b48074a86d1b05268044a02 (diff)
Remove .implement from the public API
-rw-r--r--src/embind/embind.js2
-rw-r--r--system/include/emscripten/bind.h5
-rw-r--r--tests/embind/embind.test.js163
3 files changed, 69 insertions, 101 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 37f9e432..3274a0e1 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -1740,7 +1740,7 @@ function __embind_create_inheriting_constructor(constructorName, wrapperType, pr
var wrapperPrototype = registeredClass.instancePrototype;
var baseConstructor = registeredClass.baseClass.constructor;
var ctor = createNamedFunction(constructorName, function() {
- var inner = baseConstructor.implement(this);
+ var inner = baseConstructor.__$implement(this);
this.$$ = inner.$$;
this.initialize.apply(this, Array.prototype.slice.call(arguments));
});
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h
index e03523c0..d5187ed9 100644
--- a/system/include/emscripten/bind.h
+++ b/system/include/emscripten/bind.h
@@ -1117,8 +1117,11 @@ namespace emscripten {
SmartPtrIfNeeded<PointerType> _(cls, pointerName);
return
+ // rather than use an internal-yet-accessible
+ // constructor function, we could call something like
+ // _embind_register_wrapper_constructor
class_function(
- "implement",
+ "__$implement",
&wrapped_new<PointerType, WrapperType, val>,
allow_raw_pointer<ret_val>())
.class_function(
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 6b9be675..fbcaf93d 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1554,92 +1554,6 @@ module({
assert.equal("from concrete", obj.abstractMethod());
obj.delete();
});
-
- test("can implement abstract methods in JavaScript", function() {
- var expected = "my JS string";
- function MyImplementation() {
- this.rv = expected;
- }
- MyImplementation.prototype.abstractMethod = function() {
- return this.rv;
- };
-
- var impl = cm.AbstractClass.implement(new MyImplementation);
- assert.equal(expected, impl.abstractMethod());
- assert.equal(expected, cm.callAbstractMethod(impl));
- impl.delete();
- });
-
- test("can implement optional methods in JavaScript", function() {
- var expected = "my JS string";
- function MyImplementation() {
- this.rv = expected;
- }
- MyImplementation.prototype.optionalMethod = function() {
- return this.rv;
- };
-
- var impl = cm.AbstractClass.implement(new MyImplementation);
- // TODO: remove .implement() as a public API. It interacts poorly with Class.extend.
- //assert.equal(expected, impl.optionalMethod(expected));
- assert.equal(expected, cm.callOptionalMethod(impl, expected));
- impl.delete();
- });
-
- test("if not implemented then optional method runs default", function() {
- var impl = cm.AbstractClass.implement({});
- assert.equal("optionalfoo", impl.optionalMethod("foo"));
- // TODO: remove .implement() as a public API. It interacts poorly with Class.extend.
- //assert.equal("optionalfoo", cm.callOptionalMethod(impl, "foo"));
- impl.delete();
- });
-
- test("returning null shared pointer from interfaces implemented in JS code does not leak", function() {
- var impl = cm.AbstractClass.implement({
- returnsSharedPtr: function() {
- return null;
- }
- });
- cm.callReturnsSharedPtrMethod(impl);
- impl.delete();
- // Let the memory leak test superfixture check that no leaks occurred.
- });
-
- test("returning a new shared pointer from interfaces implemented in JS code does not leak", function() {
- var impl = cm.AbstractClass.implement({
- returnsSharedPtr: function() {
- return cm.embind_test_return_smart_derived_ptr().deleteLater();
- }
- });
- cm.callReturnsSharedPtrMethod(impl);
- impl.delete();
- // Let the memory leak test superfixture check that no leaks occurred.
- });
-
- test("void methods work", function() {
- var saved = {};
- var impl = cm.AbstractClass.implement({
- differentArguments: function(i, d, f, q, s) {
- saved.i = i;
- saved.d = d;
- saved.f = f;
- saved.q = q;
- saved.s = s;
- }
- });
-
- cm.callDifferentArguments(impl, 1, 2, 3, 4, "foo");
-
- assert.deepEqual(saved, {
- i: 1,
- d: 2,
- f: 3,
- q: 4,
- s: "foo",
- });
-
- impl.delete();
- });
});
BaseFixture.extend("new-style class inheritance", function() {
@@ -1746,6 +1660,70 @@ module({
assert.instanceof(instance, cm.AbstractClass);
instance.delete();
});
+
+ test("returning null shared pointer from interfaces implemented in JS code does not leak", function() {
+ var C = cm.AbstractClass.extend("C", {
+ returnsSharedPtr: function() {
+ return null;
+ }
+ });
+ var impl = new C;
+ cm.callReturnsSharedPtrMethod(impl);
+ impl.delete();
+ // Let the memory leak test superfixture check that no leaks occurred.
+ });
+
+ test("returning a new shared pointer from interfaces implemented in JS code does not leak", function() {
+ var C = cm.AbstractClass.extend("C", {
+ returnsSharedPtr: function() {
+ return cm.embind_test_return_smart_derived_ptr().deleteLater();
+ }
+ });
+ var impl = new C;
+ cm.callReturnsSharedPtrMethod(impl);
+ impl.delete();
+ // Let the memory leak test superfixture check that no leaks occurred.
+ });
+
+ test("void methods work", function() {
+ var saved = {};
+ var C = cm.AbstractClass.extend("C", {
+ differentArguments: function(i, d, f, q, s) {
+ saved.i = i;
+ saved.d = d;
+ saved.f = f;
+ saved.q = q;
+ saved.s = s;
+ }
+ });
+ var impl = new C;
+
+ cm.callDifferentArguments(impl, 1, 2, 3, 4, "foo");
+
+ assert.deepEqual(saved, {
+ i: 1,
+ d: 2,
+ f: 3,
+ q: 4,
+ s: "foo",
+ });
+
+ impl.delete();
+ });
+
+ test("returning a cached new shared pointer from interfaces implemented in JS code does not leak", function() {
+ var derived = cm.embind_test_return_smart_derived_ptr();
+ var C = cm.AbstractClass.extend("C", {
+ returnsSharedPtr: function() {
+ return derived;
+ }
+ });
+ var impl = new C;
+ cm.callReturnsSharedPtrMethod(impl);
+ impl.delete();
+ derived.delete();
+ // Let the memory leak test superfixture check that no leaks occurred.
+ });
});
BaseFixture.extend("registration order", function() {
@@ -2053,19 +2031,6 @@ module({
});
});
- test("returning a cached new shared pointer from interfaces implemented in JS code does not leak", function() {
- var derived = cm.embind_test_return_smart_derived_ptr();
- var impl = cm.AbstractClass.implement({
- returnsSharedPtr: function() {
- return derived;
- }
- });
- cm.callReturnsSharedPtrMethod(impl);
- impl.delete();
- derived.delete();
- // Let the memory leak test superfixture check that no leaks occurred.
- });
-
BaseFixture.extend("val::as", function() {
test("built-ins", function() {
assert.equal(true, cm.val_as_bool(true));