From 3c81065a72aca4956dbb5e1650318c05b477321c Mon Sep 17 00:00:00 2001 From: jjrv Date: Mon, 5 Dec 2016 20:08:41 +0200 Subject: [PATCH] Fix passing objects without a toJS method by value on Emscripten target. --- src/em/BindClass.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/em/BindClass.ts b/src/em/BindClass.ts index 9ca22f2..d8b4aaa 100644 --- a/src/em/BindClass.ts +++ b/src/em/BindClass.ts @@ -206,7 +206,7 @@ export namespace _nbind { } wireRead = (arg: number) => popValue(arg, this.ptrType); - wireWrite = pushValue; + wireWrite = (arg: any) => pushPointer(arg, this.ptrType, true); // Optional type conversion code // makeWireWrite = (expr: string) => '_nbind.pushValue(' + expr + ')'; @@ -237,8 +237,12 @@ export namespace _nbind { return(ptr ? new type.proto(ptrMarker, type.flags, ptr) : null); } - export function pushPointer(obj: Wrapper, type: BindClassPtr) { - if(!(obj instanceof Wrapper)) throw(new Error('Type mismatch')); + export function pushPointer(obj: Wrapper, type: BindClassPtr, tryValue?: boolean) { + if(!(obj instanceof Wrapper)) { + if(tryValue) { + return(pushValue(obj)); + } else throw(new Error('Type mismatch')); + } let ptr = obj.__nbindPtr; let objType = (obj.__nbindType).classType;