Browse Source

Fix Proxy creation panicing on target not callable

fixes #306
Mihail Stoykov 4 years ago
parent
commit
6e2dd7d16c
2 changed files with 14 additions and 1 deletions
  1. 13 0
      builtin_proxy_test.go
  2. 1 1
      proxy.go

+ 13 - 0
builtin_proxy_test.go

@@ -1229,3 +1229,16 @@ func TestProxyExport(t *testing.T) {
 		t.Fatalf("Export returned unexpected type: %T", v1)
 		t.Fatalf("Export returned unexpected type: %T", v1)
 	}
 	}
 }
 }
+
+func TestProxy_proxy_createTargetNotCallable(t *testing.T) {
+	// from https://github.com/tc39/test262/blob/main/test/built-ins/Proxy/create-target-is-not-callable.js
+	const SCRIPT = `
+	var p = new Proxy({}, {});
+
+	assert.throws(TypeError, function() {
+		  p();
+	});
+	`
+
+	testScript1(TESTLIB+SCRIPT, _undefined, t)
+}

+ 1 - 1
proxy.go

@@ -848,7 +848,7 @@ func (p *proxyObject) assertConstructor() func(args []Value, newTarget *Object)
 
 
 func (p *proxyObject) apply(call FunctionCall) Value {
 func (p *proxyObject) apply(call FunctionCall) Value {
 	if p.call == nil {
 	if p.call == nil {
-		p.val.runtime.NewTypeError("proxy target is not a function")
+		panic(p.val.runtime.NewTypeError("proxy target is not a function"))
 	}
 	}
 	if v, ok := p.checkHandler().apply(p.target, nilSafe(call.This), call.Arguments); ok {
 	if v, ok := p.checkHandler().apply(p.target, nilSafe(call.This), call.Arguments); ok {
 		return v
 		return v