- Revision
- 207347
- Author
- commit-qu...@webkit.org
- Date
- 2016-10-14 11:14:03 -0700 (Fri, 14 Oct 2016)
Log Message
test262: @isConstructor incorrectly thinks Math.cos is a constructor
https://bugs.webkit.org/show_bug.cgi?id=163437
Patch by Joseph Pecoraro <pecor...@apple.com> on 2016-10-14
Reviewed by Saam Barati.
JSTests:
* stress/is-constructor.js: Added.
(assert):
(prototype.assert):
New test to cover the @isConstructor builtin.
* test262.yaml:
Test now passes.
Source/_javascript_Core:
* runtime/JSFunction.cpp:
(JSC::JSFunction::getConstructData):
By default, Host JSFunctions are not constructable. They get
the default callHostFunctionAsConstructor native constructor.
When getting construct data we can return ConstructType::None
in these cases instead of indicating it might be constructable
and later throwing an exception when construction is attempted.
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (207346 => 207347)
--- trunk/JSTests/ChangeLog 2016-10-14 18:06:47 UTC (rev 207346)
+++ trunk/JSTests/ChangeLog 2016-10-14 18:14:03 UTC (rev 207347)
@@ -1,3 +1,18 @@
+2016-10-14 Joseph Pecoraro <pecor...@apple.com>
+
+ test262: @isConstructor incorrectly thinks Math.cos is a constructor
+ https://bugs.webkit.org/show_bug.cgi?id=163437
+
+ Reviewed by Saam Barati.
+
+ * stress/is-constructor.js: Added.
+ (assert):
+ (prototype.assert):
+ New test to cover the @isConstructor builtin.
+
+ * test262.yaml:
+ Test now passes.
+
2016-10-14 Ryan Haddad <ryanhad...@apple.com>
Unreviewed, rolling out r207322.
Added: trunk/JSTests/stress/is-constructor.js (0 => 207347)
--- trunk/JSTests/stress/is-constructor.js (rev 0)
+++ trunk/JSTests/stress/is-constructor.js 2016-10-14 18:14:03 UTC (rev 207347)
@@ -0,0 +1,99 @@
+function assert(x) {
+ if (!x)
+ throw Error("Bad");
+}
+
+let isConstructor = createBuiltin("(function(c) { return @isConstructor(c); })");
+
+// Functions.
+assert(isConstructor(assert));
+assert(isConstructor(class{}));
+assert(isConstructor(function(){}));
+
+// Proxy functions.
+assert(isConstructor(new Proxy(assert, {})));
+assert(isConstructor(new Proxy(class{}, {})));
+assert(isConstructor(new Proxy(function(){}, {})));
+
+// Bound functions.
+assert(isConstructor(assert.bind(null), {}));
+assert(isConstructor((class{}).bind(null), {}));
+assert(isConstructor(function(){}.bind(null), {}));
+
+// Builtin constructors.
+assert(isConstructor(Array));
+assert(isConstructor(ArrayBuffer));
+assert(isConstructor(Boolean));
+assert(isConstructor(Date));
+assert(isConstructor(Error));
+assert(isConstructor(Function));
+assert(isConstructor(Map));
+assert(isConstructor(Number));
+assert(isConstructor(Object));
+assert(isConstructor(Promise));
+assert(isConstructor(Proxy));
+assert(isConstructor(RegExp));
+assert(isConstructor(Set));
+assert(isConstructor(String));
+assert(isConstructor(WeakMap));
+assert(isConstructor(WeakSet));
+
+// Non-function values.
+assert(!isConstructor(undefined));
+assert(!isConstructor(null));
+assert(!isConstructor(true));
+assert(!isConstructor(false));
+assert(!isConstructor(0));
+assert(!isConstructor(1));
+assert(!isConstructor(1.1));
+assert(!isConstructor(-1));
+assert(!isConstructor(Date.now()));
+assert(!isConstructor(new Date));
+assert(!isConstructor(Infinity));
+assert(!isConstructor(NaN));
+assert(!isConstructor(""));
+assert(!isConstructor("test"));
+assert(!isConstructor([]));
+assert(!isConstructor({}));
+assert(!isConstructor(/regex/));
+assert(!isConstructor(Math));
+assert(!isConstructor(JSON));
+assert(!isConstructor(Symbol()));
+assert(!isConstructor(new Error));
+assert(!isConstructor(new Proxy({}, {})));
+assert(!isConstructor(Array.prototype));
+
+// Symbol is not a constructor.
+assert(!isConstructor(Symbol));
+
+// Getters / setters are not constructors.
+assert(!isConstructor(Object.getOwnPropertyDescriptor({get f(){}}, "f").get));
+assert(!isConstructor(Object.getOwnPropertyDescriptor({set f(x){}}, "f").set));
+
+// Arrow functions are not constructors.
+assert(!isConstructor(()=>{}));
+
+// Generators are not constructors.
+assert(!isConstructor(function*(){}));
+
+// Native builtins are not constructors.
+assert(!isConstructor(isConstructor));
+
+// https://tc39.github.io/ecma262/#sec-built-in-function-objects
+// Built-in function objects that are not identified as constructors do not
+// implement the [[Construct]] internal method unless otherwise specified in
+// the description of a particular function.
+assert(!isConstructor(Array.of));
+assert(!isConstructor(Object.getOwnPropertyDescriptor));
+assert(!isConstructor(Date.now));
+assert(!isConstructor(Math.cos));
+assert(!isConstructor(JSON.stringify));
+assert(!isConstructor(Promise.all));
+assert(!isConstructor(Symbol.for));
+assert(!isConstructor(Array.prototype.push));
+
+// Proxy and bound functions carry forward non-constructor-ness.
+assert(!isConstructor(new Proxy(Symbol, {})));
+assert(!isConstructor(new Proxy(Math.cos, {})));
+assert(!isConstructor(Symbol.bind(null)));
+assert(!isConstructor(Math.cos.bind(null)));
Modified: trunk/JSTests/test262.yaml (207346 => 207347)
--- trunk/JSTests/test262.yaml 2016-10-14 18:06:47 UTC (rev 207346)
+++ trunk/JSTests/test262.yaml 2016-10-14 18:14:03 UTC (rev 207347)
@@ -3054,9 +3054,9 @@
- path: test262/test/built-ins/Array/of/return-a-custom-instance.js
cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], [:strict]
- path: test262/test/built-ins/Array/of/return-a-new-array-object.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/Array/of/return-a-new-array-object.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/Array/of/return-abrupt-from-contructor.js
cmd: runTest262 :normal, "NoException", ["../../../../harness/assert.js", "../../../../harness/sta.js"], []
- path: test262/test/built-ins/Array/of/return-abrupt-from-contructor.js
Modified: trunk/Source/_javascript_Core/ChangeLog (207346 => 207347)
--- trunk/Source/_javascript_Core/ChangeLog 2016-10-14 18:06:47 UTC (rev 207346)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-10-14 18:14:03 UTC (rev 207347)
@@ -1,3 +1,18 @@
+2016-10-14 Joseph Pecoraro <pecor...@apple.com>
+
+ test262: @isConstructor incorrectly thinks Math.cos is a constructor
+ https://bugs.webkit.org/show_bug.cgi?id=163437
+
+ Reviewed by Saam Barati.
+
+ * runtime/JSFunction.cpp:
+ (JSC::JSFunction::getConstructData):
+ By default, Host JSFunctions are not constructable. They get
+ the default callHostFunctionAsConstructor native constructor.
+ When getting construct data we can return ConstructType::None
+ in these cases instead of indicating it might be constructable
+ and later throwing an exception when construction is attempted.
+
2016-10-14 Ryan Haddad <ryanhad...@apple.com>
Unreviewed, rolling out r207322.
Modified: trunk/Source/_javascript_Core/runtime/JSFunction.cpp (207346 => 207347)
--- trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2016-10-14 18:06:47 UTC (rev 207346)
+++ trunk/Source/_javascript_Core/runtime/JSFunction.cpp 2016-10-14 18:14:03 UTC (rev 207347)
@@ -573,6 +573,8 @@
JSFunction* thisObject = jsCast<JSFunction*>(cell);
if (thisObject->isHostFunction()) {
+ if (thisObject->nativeConstructor() == callHostFunctionAsConstructor)
+ return ConstructType::None;
constructData.native.function = thisObject->nativeConstructor();
return ConstructType::Host;
}