loadSlice(sp + 16).set(str);
},
+ // func valueInstanceOf(v ref, t ref) bool
+ "syscall/js.valueInstanceOf": (sp) => {
+ mem().setUint8(sp + 16, loadValue(sp + 8) instanceof loadValue(sp + 12));
+ },
+
"debug": (value) => {
console.log(value);
},
syscall/js/js_js.s: [wasm] valueBool: RET without writing to 1-byte ret+8(FP)
syscall/js/js_js.s: [wasm] valueLength: RET without writing to 8-byte ret+8(FP)
syscall/js/js_js.s: [wasm] valuePrepareString: RET without writing to 4-byte ret+8(FP)
+syscall/js/js_js.s: [wasm] valueInstanceOf: RET without writing to 1-byte ret+8(FP)
func valuePrepareString(v ref) (ref, int)
func valueLoadString(v ref, b []byte)
+
+// InstanceOf reports whether v is an instance of type t according to JavaScript's instanceof operator.
+func (v Value) InstanceOf(t Value) bool {
+ return valueInstanceOf(v.ref, t.ref)
+}
+
+func valueInstanceOf(v ref, t ref) bool
TEXT ·valueLoadString(SB), NOSPLIT, $0
CallImport
RET
+
+TEXT ·valueInstanceOf(SB), NOSPLIT, $0
+ CallImport
+ RET
}
}
+func TestInstanceOf(t *testing.T) {
+ someArray := js.Global.Get("Array").New()
+ if got, want := someArray.InstanceOf(js.Global.Get("Array")), true; got != want {
+ t.Errorf("got %#v, want %#v", got, want)
+ }
+ if got, want := someArray.InstanceOf(js.Global.Get("Function")), false; got != want {
+ t.Errorf("got %#v, want %#v", got, want)
+ }
+}
+
func TestCallback(t *testing.T) {
c := make(chan struct{})
cb := js.NewCallback(func(args []js.Value) {