aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-05-28 18:05:37 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-05-28 18:05:37 -0700
commit975882c00450475dc9102c65f5ac6fcb88b9125b (patch)
tree4f766f49fd9eb15024b09d8de87085b6d7aab0de
parent504b62384aba8da8258ed6f8ba0a455a1db7736a (diff)
parent34599322eea3c9d2240c1c09d0f148f95612ed5a (diff)
Merge pull request #2388 from waywardmonkeys/upstream-from-imvu
Upstream from imvu
-rw-r--r--src/embind/embind.js15
-rw-r--r--tests/embind/embind.test.js1
2 files changed, 13 insertions, 3 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js
index 124ea569..8c8d73ad 100644
--- a/src/embind/embind.js
+++ b/src/embind/embind.js
@@ -1216,9 +1216,18 @@ RegisteredPointer.prototype['fromWireType'] = function fromWireType(ptr) {
var registeredInstance = getInheritedInstance(this.registeredClass, rawPointer);
if (undefined !== registeredInstance) {
- var rv = registeredInstance['clone']();
- this.destructor(ptr);
- return rv;
+ // JS object has been neutered, time to repopulate it
+ if (0 === registeredInstance.$$.count.value) {
+ registeredInstance.$$.ptr = rawPointer;
+ registeredInstance.$$.smartPtr = ptr;
+ return registeredInstance['clone']();
+ } else {
+ // else, just increment reference count on existing object
+ // it already has a reference to the smart pointer
+ var rv = registeredInstance['clone']();
+ this.destructor(ptr);
+ return rv;
+ }
}
function makeDefaultHandle() {
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index a6b2e98c..432202ff 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -2410,6 +2410,7 @@ module({
var back = holder.get();
assert.equal(back, instance);
holder.delete();
+ back.delete();
});
});