Debug assertion failure while loading http://kangax.github.io/compat-table/es6/.
https://bugs.webkit.org/show_bug.cgi?id=154542
Reviewed by Saam Barati.
Source/JavaScriptCore:
According to the spec, the constructors of the following types "are not intended
to be called as a function and will throw an exception". These types are:
TypedArrays - https://tc39.github.io/ecma262/#sec-typedarray-constructors
Map - https://tc39.github.io/ecma262/#sec-map-constructor
Set - https://tc39.github.io/ecma262/#sec-set-constructor
WeakMap - https://tc39.github.io/ecma262/#sec-weakmap-constructor
WeakSet - https://tc39.github.io/ecma262/#sec-weakset-constructor
ArrayBuffer - https://tc39.github.io/ecma262/#sec-arraybuffer-constructor
DataView - https://tc39.github.io/ecma262/#sec-dataview-constructor
Promise - https://tc39.github.io/ecma262/#sec-promise-constructor
Proxy - https://tc39.github.io/ecma262/#sec-proxy-constructor
This patch does the foillowing:
1. Ensures that these constructors can be called but will throw a TypeError
when called.
2. Makes all these objects use throwConstructorCannotBeCalledAsFunctionTypeError()
in their implementation to be consistent.
3. Change the error message to "calling XXX constructor without new is invalid".
This is clearer because the error is likely due to the user forgetting to use
the new operator on these constructors.
* runtime/Error.h:
* runtime/Error.cpp:
(JSC::throwConstructorCannotBeCalledAsFunctionTypeError):
- Added a convenience function to throw the TypeError.
* runtime/JSArrayBufferConstructor.cpp:
(JSC::constructArrayBuffer):
(JSC::callArrayBuffer):
(JSC::JSArrayBufferConstructor::getCallData):
* runtime/JSGenericTypedArrayViewConstructorInlines.h:
(JSC::callGenericTypedArrayView):
(JSC::JSGenericTypedArrayViewConstructor<ViewClass>::getCallData):
* runtime/JSPromiseConstructor.cpp:
(JSC::callPromise):
* runtime/MapConstructor.cpp:
(JSC::callMap):
* runtime/ProxyConstructor.cpp:
(JSC::callProxy):
(JSC::ProxyConstructor::getCallData):
* runtime/SetConstructor.cpp:
(JSC::callSet):
* runtime/WeakMapConstructor.cpp:
(JSC::callWeakMap):
* runtime/WeakSetConstructor.cpp:
(JSC::callWeakSet):
* tests/es6.yaml:
- The typed_arrays_%TypedArray%[Symbol.species].js test now passes.
* tests/stress/call-non-calleable-constructors-as-function.js: Added.
(test):
* tests/stress/map-constructor.js:
(testCallTypeError):
* tests/stress/promise-cannot-be-called.js:
(shouldThrow):
* tests/stress/proxy-basic.js:
* tests/stress/set-constructor.js:
* tests/stress/throw-from-ftl-call-ic-slow-path-cells.js:
(i.catch):
* tests/stress/throw-from-ftl-call-ic-slow-path-undefined.js:
(i.catch):
* tests/stress/throw-from-ftl-call-ic-slow-path.js:
(i.catch):
* tests/stress/weak-map-constructor.js:
(testCallTypeError):
* tests/stress/weak-set-constructor.js:
- Updated error message string.
LayoutTests:
* js/Promise-types-expected.txt:
* js/basic-map-expected.txt:
* js/basic-set-expected.txt:
* js/dom/basic-weakmap-expected.txt:
* js/dom/basic-weakset-expected.txt:
* js/script-tests/Promise-types.js:
* js/typedarray-constructors-expected.txt:
- Updated error message string.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@196986 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/tests/stress/call-non-calleable-constructors-as-function.js b/Source/JavaScriptCore/tests/stress/call-non-calleable-constructors-as-function.js
new file mode 100644
index 0000000..e921b7e
--- /dev/null
+++ b/Source/JavaScriptCore/tests/stress/call-non-calleable-constructors-as-function.js
@@ -0,0 +1,59 @@
+var errors = "";
+var numTests = 0;
+
+function test(type) {
+ var didThrow = false;
+ try {
+ var bad = type(10);
+ } catch(e) {
+ didThrow = true;
+ }
+
+ if (!didThrow) {
+ errors += ("bad result: calling " + type.name + " as a function did not throw\n");
+ }
+ numTests++;
+
+ if (typeof type !== "function")
+ errors += ("bad result: typeof " + type.name + " is not function. Was " + (typeof type) + "\n");
+ numTests++;
+}
+
+// According to the spec, the constructors of the following types "are not intended to be
+// called as a function and will throw an exception". However, as constructors, their
+// type should be "function".
+
+// https://tc39.github.io/ecma262/#sec-typedarray-constructors
+test(Int8Array);
+test(Uint8Array);
+test(Uint8ClampedArray);
+test(Int16Array);
+test(Uint16Array);
+test(Int32Array);
+test(Uint32Array);
+test(Float32Array);
+test(Float64Array);
+
+// https://tc39.github.io/ecma262/#sec-map-constructor
+test(Map);
+// https://tc39.github.io/ecma262/#sec-set-constructor
+test(Set);
+// https://tc39.github.io/ecma262/#sec-weakmap-constructor
+test(WeakMap);
+// https://tc39.github.io/ecma262/#sec-weakset-constructor
+test(WeakSet);
+// https://tc39.github.io/ecma262/#sec-arraybuffer-constructor
+test(ArrayBuffer);
+// https://tc39.github.io/ecma262/#sec-dataview-constructor
+test(DataView);
+// https://tc39.github.io/ecma262/#sec-promise-constructor
+test(Promise);
+// https://tc39.github.io/ecma262/#sec-proxy-constructor
+test(Proxy);
+
+let expectedNumTests = 34;
+if (numTests != expectedNumTests) {
+ errors += "Not all tests were run: ran " + numTests + " out of " + expectedNumTests + " \n";
+}
+if (errors.length)
+ throw new Error(errors);