Title: [214259] trunk
Revision
214259
Author
[email protected]
Date
2017-03-22 10:52:55 -0700 (Wed, 22 Mar 2017)

Log Message

WebAssembly: constructors without new don't throw
https://bugs.webkit.org/show_bug.cgi?id=165995

Reviewed by Saam Barati.

JSTests:

* wasm/js-api/test_basic_api.js:
(const.c.in.constructorProperties.switch):

Source/_javascript_Core:

* wasm/js/WebAssemblyCompileErrorConstructor.cpp:
(JSC::constructJSWebAssemblyCompileError):
(JSC::callJSWebAssemblyCompileError):
* wasm/js/WebAssemblyLinkErrorConstructor.cpp:
(JSC::constructJSWebAssemblyLinkError):
(JSC::callJSWebAssemblyLinkError):
* wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
(JSC::constructJSWebAssemblyRuntimeError):
(JSC::callJSWebAssemblyRuntimeError):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (214258 => 214259)


--- trunk/JSTests/ChangeLog	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/JSTests/ChangeLog	2017-03-22 17:52:55 UTC (rev 214259)
@@ -1,3 +1,13 @@
+2017-03-22  JF Bastien  <[email protected]>
+
+        WebAssembly: constructors without new don't throw
+        https://bugs.webkit.org/show_bug.cgi?id=165995
+
+        Reviewed by Saam Barati.
+
+        * wasm/js-api/test_basic_api.js:
+        (const.c.in.constructorProperties.switch):
+
 2017-03-21  Yusuke Suzuki  <[email protected]>
 
         [JSC] Optimize Number.prototype.toString on Int32 / Int52 / Double

Modified: trunk/JSTests/wasm/js-api/test_basic_api.js (214258 => 214259)


--- trunk/JSTests/wasm/js-api/test_basic_api.js	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/JSTests/wasm/js-api/test_basic_api.js	2017-03-22 17:52:55 UTC (rev 214259)
@@ -49,7 +49,10 @@
     assert.eq(WebAssembly[c].length, constructorProperties[c].length);
     checkOwnPropertyDescriptor(WebAssembly, c, constructorProperties[c]);
     checkOwnPropertyDescriptor(WebAssembly[c], "prototype", { typeofvalue: "object", writable: false, configurable: false, enumerable: false });
-    assert.throws(() => WebAssembly[c](), TypeError, `calling WebAssembly.${c} constructor without new is invalid`);
+    if (["CompileError", "LinkError", "RuntimeError"].indexOf(c) >= 0)
+        WebAssembly[c](); // Per spec, the WebAssembly.*Error types match ye olden _javascript_ NativeError behavior: they can be constructed without `new`.
+    else
+        assert.throws(() => WebAssembly[c](), TypeError, `calling WebAssembly.${c} constructor without new is invalid`);
     switch (c) {
     case "Module":
         for (const invalid of invalidConstructorInputs)
@@ -86,15 +89,28 @@
     case "CompileError":
     case "LinkError":
     case "RuntimeError": {
-        const e = new WebAssembly[c];
-        assert.eq(e instanceof WebAssembly[c], true);
-        assert.eq(e instanceof Error, true);
-        assert.eq(e instanceof TypeError, false);
-        assert.eq(e.message, "");
-        assert.eq(typeof e.stack, "string");
-        const sillyString = "uh-oh!";
-        const e2 = new WebAssembly[c](sillyString);
-        // FIXME fix Compile / Runtime errors for this: assert.eq(e2.message, sillyString + " (evaluating 'new WebAssembly[c](sillyString)')");
+        {
+            const e = new WebAssembly[c];
+            assert.eq(e instanceof WebAssembly[c], true);
+            assert.eq(e instanceof Error, true);
+            assert.eq(e instanceof TypeError, false);
+            assert.eq(e.message, "");
+            assert.eq(typeof e.stack, "string");
+            const sillyString = "uh-oh!";
+            const e2 = new WebAssembly[c](sillyString);
+            assert.eq(e2.message, sillyString + " (evaluating 'new WebAssembly[c](sillyString)')");
+        }
+        {
+            const e = WebAssembly[c]();
+            assert.eq(e instanceof WebAssembly[c], true);
+            assert.eq(e instanceof Error, true);
+            assert.eq(e instanceof TypeError, false);
+            assert.eq(e.message, "");
+            assert.eq(typeof e.stack, "string");
+            const sillyString = "uh-oh!";
+            const e2 = WebAssembly[c](sillyString);
+            assert.eq(e2.message, sillyString);
+        }
     } break;
     default: throw new Error(`Implementation error: unexpected constructor property "${c}"`);
     }

Modified: trunk/Source/_javascript_Core/ChangeLog (214258 => 214259)


--- trunk/Source/_javascript_Core/ChangeLog	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/Source/_javascript_Core/ChangeLog	2017-03-22 17:52:55 UTC (rev 214259)
@@ -1,3 +1,20 @@
+2017-03-22  JF Bastien  <[email protected]>
+
+        WebAssembly: constructors without new don't throw
+        https://bugs.webkit.org/show_bug.cgi?id=165995
+
+        Reviewed by Saam Barati.
+
+        * wasm/js/WebAssemblyCompileErrorConstructor.cpp:
+        (JSC::constructJSWebAssemblyCompileError):
+        (JSC::callJSWebAssemblyCompileError):
+        * wasm/js/WebAssemblyLinkErrorConstructor.cpp:
+        (JSC::constructJSWebAssemblyLinkError):
+        (JSC::callJSWebAssemblyLinkError):
+        * wasm/js/WebAssemblyRuntimeErrorConstructor.cpp:
+        (JSC::constructJSWebAssemblyRuntimeError):
+        (JSC::callJSWebAssemblyRuntimeError):
+
 2017-03-22  Guillaume Emont  <[email protected]>
 
         [DFG] Don't use ArraySlice intrinsic on MIPS

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyCompileErrorConstructor.cpp (214258 => 214259)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyCompileErrorConstructor.cpp	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyCompileErrorConstructor.cpp	2017-03-22 17:52:55 UTC (rev 214259)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -44,21 +44,21 @@
  @end
  */
 
-static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyCompileError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyCompileError(ExecState* exec)
 {
-    auto& vm = state->vm();
+    auto& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue message = state->argument(0);
-    auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyCompileErrorStructure());
+    JSValue message = exec->argument(0);
+    auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyCompileErrorStructure());
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    return JSValue::encode(JSWebAssemblyCompileError::create(state, vm, structure, message));
+    return JSValue::encode(JSWebAssemblyCompileError::create(exec, vm, structure, message));
 }
 
-static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyCompileError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyCompileError(ExecState* exec)
 {
-    VM& vm = state->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.CompileError"));
+    JSValue message = exec->argument(0);
+    Structure* errorStructure = asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyCompileErrorStructure();
+    return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
 }
 
 WebAssemblyCompileErrorConstructor* WebAssemblyCompileErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyCompileErrorPrototype* thisPrototype)

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyLinkErrorConstructor.cpp (214258 => 214259)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyLinkErrorConstructor.cpp	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyLinkErrorConstructor.cpp	2017-03-22 17:52:55 UTC (rev 214259)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -44,21 +44,21 @@
  @end
  */
 
-static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyLinkError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyLinkError(ExecState* exec)
 {
-    auto& vm = state->vm();
+    auto& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue message = state->argument(0);
-    auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyLinkErrorStructure());
+    JSValue message = exec->argument(0);
+    auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyLinkErrorStructure());
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    return JSValue::encode(JSWebAssemblyLinkError::create(state, vm, structure, message));
+    return JSValue::encode(JSWebAssemblyLinkError::create(exec, vm, structure, message));
 }
 
-static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyLinkError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyLinkError(ExecState* exec)
 {
-    VM& vm = state->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.LinkError"));
+    JSValue message = exec->argument(0);
+    Structure* errorStructure = asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyLinkErrorStructure();
+    return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
 }
 
 WebAssemblyLinkErrorConstructor* WebAssemblyLinkErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyLinkErrorPrototype* thisPrototype)

Modified: trunk/Source/_javascript_Core/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp (214258 => 214259)


--- trunk/Source/_javascript_Core/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp	2017-03-22 17:51:10 UTC (rev 214258)
+++ trunk/Source/_javascript_Core/wasm/js/WebAssemblyRuntimeErrorConstructor.cpp	2017-03-22 17:52:55 UTC (rev 214259)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -44,21 +44,21 @@
  @end
  */
 
-static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyRuntimeError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL constructJSWebAssemblyRuntimeError(ExecState* exec)
 {
-    auto& vm = state->vm();
+    auto& vm = exec->vm();
     auto scope = DECLARE_THROW_SCOPE(vm);
-    JSValue message = state->argument(0);
-    auto* structure = InternalFunction::createSubclassStructure(state, state->newTarget(), asInternalFunction(state->jsCallee())->globalObject()->WebAssemblyRuntimeErrorStructure());
+    JSValue message = exec->argument(0);
+    auto* structure = InternalFunction::createSubclassStructure(exec, exec->newTarget(), asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyRuntimeErrorStructure());
     RETURN_IF_EXCEPTION(scope, encodedJSValue());
-    return JSValue::encode(JSWebAssemblyRuntimeError::create(state, vm, structure, message));
+    return JSValue::encode(JSWebAssemblyRuntimeError::create(exec, vm, structure, message));
 }
 
-static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyRuntimeError(ExecState* state)
+static EncodedJSValue JSC_HOST_CALL callJSWebAssemblyRuntimeError(ExecState* exec)
 {
-    VM& vm = state->vm();
-    auto scope = DECLARE_THROW_SCOPE(vm);
-    return JSValue::encode(throwConstructorCannotBeCalledAsFunctionTypeError(state, scope, "WebAssembly.RuntimeError"));
+    JSValue message = exec->argument(0);
+    Structure* errorStructure = asInternalFunction(exec->jsCallee())->globalObject()->WebAssemblyRuntimeErrorStructure();
+    return JSValue::encode(ErrorInstance::create(exec, errorStructure, message, nullptr, TypeNothing, false));
 }
 
 WebAssemblyRuntimeErrorConstructor* WebAssemblyRuntimeErrorConstructor::create(VM& vm, Structure* structure, WebAssemblyRuntimeErrorPrototype* thisPrototype)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to