Ver código fonte

fix: if the native getOwnPropertyDescriptor proxy trap returns an empty PropertyDescriptor, return undefined.

Dmitry Panov 4 anos atrás
pai
commit
ee3cb2035c
2 arquivos alterados com 25 adições e 5 exclusões
  1. 3 0
      builtin_proxy.go
  2. 22 5
      builtin_proxy_test.go

+ 3 - 0
builtin_proxy.go

@@ -77,6 +77,9 @@ func (r *Runtime) proxyproto_nativehandler_getOwnPropertyDescriptor(native func(
 						return _undefined
 					default:
 						desc := native(t, p.String())
+						if desc.Empty() {
+							return _undefined
+						}
 						return desc.toValue(r)
 					}
 				}

+ 22 - 5
builtin_proxy_test.go

@@ -54,7 +54,7 @@ func TestProxy_Object_native_proxy_getPrototypeOf(t *testing.T) {
 
 	_, err := runtime.RunString(TESTLIB + SCRIPT)
 	if err != nil {
-		panic(err)
+		t.Fatal(err)
 	}
 }
 
@@ -138,7 +138,7 @@ func TestProxy_native_proxy_isExtensible(t *testing.T) {
 
 	val, err := runtime.RunString(SCRIPT)
 	if err != nil {
-		panic(err)
+		t.Fatal(err)
 	}
 	if val.ToBoolean() {
 		t.Fatal()
@@ -200,7 +200,7 @@ func TestProxy_native_proxy_preventExtensions(t *testing.T) {
 
 	val, err := runtime.RunString(SCRIPT)
 	if err != nil {
-		panic(err)
+		t.Fatal(err)
 	}
 	if val.ToBoolean() {
 		t.Fatal()
@@ -304,7 +304,7 @@ func TestProxy_native_proxy_getOwnPropertyDescriptor(t *testing.T) {
 
 	val, err := runtime.RunString(SCRIPT)
 	if err != nil {
-		panic(err)
+		t.Fatal(err)
 	}
 
 	if c, ok := val.(*Object).self.assertCallable(); ok {
@@ -320,6 +320,23 @@ func TestProxy_native_proxy_getOwnPropertyDescriptor(t *testing.T) {
 	}
 }
 
+func TestProxy_native_proxy_getOwnPropertyDescriptor_non_existing(t *testing.T) {
+	vm := New()
+	proxy := vm.NewProxy(vm.NewObject(), &ProxyTrapConfig{
+		GetOwnPropertyDescriptor: func(target *Object, prop string) (propertyDescriptor PropertyDescriptor) {
+			return // empty PropertyDescriptor
+		},
+	})
+	vm.Set("proxy", proxy)
+	res, err := vm.RunString(`Object.getOwnPropertyDescriptor(proxy, "foo") === undefined`)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if res != valueTrue {
+		t.Fatal(res)
+	}
+}
+
 func TestProxy_Object_target_defineProperty(t *testing.T) {
 	const SCRIPT = `
 	var obj = {};
@@ -373,7 +390,7 @@ func TestProxy_native_proxy_defineProperty(t *testing.T) {
 
 	val, err := runtime.RunString(SCRIPT)
 	if err != nil {
-		panic(err)
+		t.Fatal(err)
 	}
 	if s := val.String(); s != "321tset" {
 		t.Fatalf("val: %s", s)