Object.getOwnPropertyNames includes "arguments" and "caller" for bound functions
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Jan 2018 00:15:21 +0000 (00:15 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 7 Jan 2018 00:15:21 +0000 (00:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181321

Reviewed by Saam Barati.

JSTests:

* stress/bound-function-does-not-have-caller-and-arguments.js: Added.
(shouldBe):
(testFunction):
* test262.yaml:

Source/JavaScriptCore:

According to ECMA262 16.2[1], functions created using the bind method must not have
"caller" and "arguments" own properties.

[1]: https://tc39.github.io/ecma262/#sec-forbidden-extensions

* runtime/JSBoundFunction.cpp:
(JSC::JSBoundFunction::finishCreation):

LayoutTests:

* inspector/model/remote-object-get-properties-expected.txt:
* inspector/runtime/getProperties-expected.txt:
* js/script-tests/strict-throw-type-error.js:
* js/strict-throw-type-error-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226489 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/stress/bound-function-does-not-have-caller-and-arguments.js [new file with mode: 0644]
JSTests/test262.yaml
LayoutTests/ChangeLog
LayoutTests/inspector/model/remote-object-get-properties-expected.txt
LayoutTests/inspector/runtime/getProperties-expected.txt
LayoutTests/js/script-tests/strict-throw-type-error.js
LayoutTests/js/strict-throw-type-error-expected.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSBoundFunction.cpp

index 32e07e2..7ec7c6e 100644 (file)
@@ -1,3 +1,15 @@
+2018-01-06  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Object.getOwnPropertyNames includes "arguments" and "caller" for bound functions
+        https://bugs.webkit.org/show_bug.cgi?id=181321
+
+        Reviewed by Saam Barati.
+
+        * stress/bound-function-does-not-have-caller-and-arguments.js: Added.
+        (shouldBe):
+        (testFunction):
+        * test262.yaml:
+
 2018-01-05  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, attempt to fix test262 after r226386.
diff --git a/JSTests/stress/bound-function-does-not-have-caller-and-arguments.js b/JSTests/stress/bound-function-does-not-have-caller-and-arguments.js
new file mode 100644 (file)
index 0000000..97cc76f
--- /dev/null
@@ -0,0 +1,15 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+function testFunction(func) {
+    var array = Object.getOwnPropertyNames(func);
+    shouldBe(array.indexOf("arguments"), -1);
+    shouldBe(array.indexOf("caller"), -1);
+}
+
+testFunction((() => { }).bind());
+testFunction((() => { "use strict"; }).bind());
+testFunction((function () { }).bind());
+testFunction((function () { "use strict"; }).bind());
index f930ddc..87c7d19 100644 (file)
 - path: test262/test/built-ins/Function/prototype/bind/15.3.4.5.2-4-9.js
   cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Function/prototype/bind/BoundFunction_restricted-properties.js
-  cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Function/prototype/bind/BoundFunction_restricted-properties.js
-  cmd: runTest262 :fail, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], [:strict]
 - path: test262/test/built-ins/Function/prototype/bind/S15.3.4.5_A1.js
   cmd: runTest262 :normal, "NoException", ["../../../../../harness/assert.js", "../../../../../harness/sta.js"], []
 - path: test262/test/built-ins/Function/prototype/bind/S15.3.4.5_A1.js
 - path: test262/test/language/statements/function/13.2-3-s.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/function/13.2-30-s.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
 - path: test262/test/language/statements/function/13.2-30-s.js
-  cmd: runTest262 :fail, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
+  cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/function/13.2-4-s.js
   cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
 - path: test262/test/language/statements/function/13.2-5-s.js
index 9c30f5b..b1ce252 100644 (file)
@@ -1,3 +1,15 @@
+2018-01-06  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Object.getOwnPropertyNames includes "arguments" and "caller" for bound functions
+        https://bugs.webkit.org/show_bug.cgi?id=181321
+
+        Reviewed by Saam Barati.
+
+        * inspector/model/remote-object-get-properties-expected.txt:
+        * inspector/runtime/getProperties-expected.txt:
+        * js/script-tests/strict-throw-type-error.js:
+        * js/strict-throw-type-error-expected.txt:
+
 2018-01-05  Youenn Fablet  <youenn@apple.com>
 
         Implement Cache API partitioning based on ClientOrigin
index e5d7960..8ee1a90 100644 (file)
@@ -401,8 +401,6 @@ description: function unboundFunction() {
 OWN PROPERTIES:
     name
     length
-    arguments
-    caller
     __proto__
     targetFunction
     boundThis
@@ -410,9 +408,9 @@ OWN PROPERTIES:
 
 DISPLAYABLE PROPERTIES:
     length
-    arguments
-    caller
     name
+    caller
+    arguments
     __proto__
     targetFunction
     boundThis
@@ -420,13 +418,13 @@ DISPLAYABLE PROPERTIES:
 
 ALL PROPERTIES:
     length
-    arguments
-    caller
     name
     toString
     apply
     call
     bind
+    caller
+    arguments
     constructor
     Symbol(Symbol.hasInstance)
     toLocaleString
index 84d4db5..3090752 100644 (file)
@@ -20,8 +20,6 @@ Properties:
   __proto__ function function () {
     [native code]
 }
-  arguments getter setter
-  caller getter setter
   length number 0
   name string bound Number
 Internal properties:
@@ -37,8 +35,6 @@ Properties:
   __proto__ function function () {
     [native code]
 }
-  arguments getter setter
-  caller getter setter
   length number 0
   name string bound 
 Internal properties:
index cccbb7a..a057350 100644 (file)
@@ -16,8 +16,8 @@ var functionCaller1 = getter(strictArgumentsFunction1.__proto__, "caller");
 var functionArguments1 = getter(strictArgumentsFunction1.__proto__, "arguments");
 var argumentsCaller1 = Object.getOwnPropertyDescriptor(strictArguments1, "caller");
 var argumentsCallee1 = getter(strictArguments1, "callee");
-var boundCaller1 = getter(boundFunction1, "caller");
-var boundArguments1 = getter(boundFunction1, "arguments");
+var boundCaller1 = Object.getOwnPropertyDescriptor(boundFunction1, "caller");
+var boundArguments1 = Object.getOwnPropertyDescriptor(boundFunction1, "arguments");
 
 function strictArgumentsFunction2()
 {
@@ -30,21 +30,21 @@ var functionCaller2 = getter(strictArgumentsFunction2.__proto__, "caller");
 var functionArguments2 = getter(strictArgumentsFunction2.__proto__, "arguments");
 var argumentsCaller2 = Object.getOwnPropertyDescriptor(strictArguments2, "caller");
 var argumentsCallee2 = getter(strictArguments2, "callee");
-var boundCaller2 = getter(boundFunction2, "caller");
-var boundArguments2 = getter(boundFunction2, "arguments");
+var boundCaller2 = Object.getOwnPropertyDescriptor(boundFunction2, "caller");
+var boundArguments2 = Object.getOwnPropertyDescriptor(boundFunction2, "arguments");
 
 shouldBeTrue('functionCaller1 === functionCaller2');
 
 shouldBeTrue('functionCaller1 === functionArguments1');
 shouldBe('argumentsCaller1', 'undefined');
 shouldBeTrue('functionCaller1 === argumentsCallee1');
-shouldBeTrue('functionCaller1 === boundCaller1');
-shouldBeTrue('functionCaller1 === boundArguments1');
+shouldBe('boundCaller1', 'undefined');
+shouldBe('boundArguments1', 'undefined');
 
 shouldBeTrue('functionCaller2 === functionArguments2');
 shouldBe('argumentsCaller2', 'undefined');
 shouldBeTrue('functionCaller2 === argumentsCallee2');
-shouldBeTrue('functionCaller2 === boundCaller2');
-shouldBeTrue('functionCaller2 === boundArguments2');
+shouldBe('boundCaller2', 'undefined');
+shouldBe('boundArguments2', 'undefined');
 
 successfullyParsed = true;
index 304ca3a..9eb1e4f 100644 (file)
@@ -7,13 +7,13 @@ PASS functionCaller1 === functionCaller2 is true
 PASS functionCaller1 === functionArguments1 is true
 PASS argumentsCaller1 is undefined
 PASS functionCaller1 === argumentsCallee1 is true
-PASS functionCaller1 === boundCaller1 is true
-PASS functionCaller1 === boundArguments1 is true
+PASS boundCaller1 is undefined
+PASS boundArguments1 is undefined
 PASS functionCaller2 === functionArguments2 is true
 PASS argumentsCaller2 is undefined
 PASS functionCaller2 === argumentsCallee2 is true
-PASS functionCaller2 === boundCaller2 is true
-PASS functionCaller2 === boundArguments2 is true
+PASS boundCaller2 is undefined
+PASS boundArguments2 is undefined
 PASS successfullyParsed is true
 
 TEST COMPLETE
index d57a57e..078dc85 100644 (file)
@@ -1,3 +1,18 @@
+2018-01-06  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        Object.getOwnPropertyNames includes "arguments" and "caller" for bound functions
+        https://bugs.webkit.org/show_bug.cgi?id=181321
+
+        Reviewed by Saam Barati.
+
+        According to ECMA262 16.2[1], functions created using the bind method must not have
+        "caller" and "arguments" own properties.
+
+        [1]: https://tc39.github.io/ecma262/#sec-forbidden-extensions
+
+        * runtime/JSBoundFunction.cpp:
+        (JSC::JSBoundFunction::finishCreation):
+
 2018-01-05  JF Bastien  <jfbastien@apple.com>
 
         WebAssembly: poison JS object's secrets
index d2a0d26..ea6e0ab 100644 (file)
@@ -225,9 +225,6 @@ void JSBoundFunction::finishCreation(VM& vm, NativeExecutable* executable, int l
     String name; // We lazily create our 'name' string property.
     Base::finishCreation(vm, executable, length, name);
     ASSERT(inherits(vm, info()));
-
-    putDirectNonIndexAccessor(vm, vm.propertyNames->arguments, globalObject()->throwTypeErrorArgumentsCalleeAndCallerGetterSetter(), PropertyAttribute::DontDelete | PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
-    putDirectNonIndexAccessor(vm, vm.propertyNames->caller, globalObject()->throwTypeErrorArgumentsCalleeAndCallerGetterSetter(), PropertyAttribute::DontDelete | PropertyAttribute::DontEnum | PropertyAttribute::Accessor);
 }
 
 void JSBoundFunction::visitChildren(JSCell* cell, SlotVisitor& visitor)