[JSC] Offer @makeTypeError instead of exposing @TypeError
authorysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 18:56:22 +0000 (18:56 +0000)
committerysuzuki@apple.com <ysuzuki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 Mar 2019 18:56:22 +0000 (18:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193858

Reviewed by Mark Lam.

Source/JavaScriptCore:

Instead of exposing @TypeError, we expose @makeTypeError function.
And we make TypeError and Error lazily-allocated objects in non JIT environment.
In JIT environment, only TypeError becomes lazily-allocated since WebAssembly errors
touch Error prototype anyway. But we can make them lazy in a subsequent patch.

* builtins/AsyncFromSyncIteratorPrototype.js:
* builtins/AsyncGeneratorPrototype.js:
(globalPrivate.asyncGeneratorEnqueue):
* builtins/BuiltinNames.h:
* builtins/PromiseOperations.js:
(globalPrivate.createResolvingFunctions.resolve):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::initializeErrorConstructor):
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::errorPrototype const):
(JSC::JSGlobalObject::errorStructure const):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalFuncMakeTypeError):
* runtime/JSGlobalObjectFunctions.h:

Source/WebCore:

Use @makeTypeError instead.

* Modules/mediastream/RTCPeerConnection.js:
* Modules/mediastream/RTCPeerConnectionInternals.js:
* Modules/streams/ReadableByteStreamInternals.js:
(readableByteStreamControllerClose):
(readableByteStreamControllerPullInto):
* Modules/streams/ReadableStream.js:
(cancel):
(pipeTo):
* Modules/streams/ReadableStreamBYOBReader.js:
(cancel):
(read):
* Modules/streams/ReadableStreamDefaultReader.js:
(cancel):
(read):
* Modules/streams/ReadableStreamInternals.js:
(readableStreamReaderGenericRelease):
* Modules/streams/WritableStream.js:
(abort):
(close):
(write):
(getter.closed):
(getter.ready):

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

18 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/AsyncFromSyncIteratorPrototype.js
Source/JavaScriptCore/builtins/AsyncGeneratorPrototype.js
Source/JavaScriptCore/builtins/BuiltinNames.h
Source/JavaScriptCore/builtins/PromiseOperations.js
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.js
Source/WebCore/Modules/mediastream/RTCPeerConnectionInternals.js
Source/WebCore/Modules/streams/ReadableByteStreamInternals.js
Source/WebCore/Modules/streams/ReadableStream.js
Source/WebCore/Modules/streams/ReadableStreamBYOBReader.js
Source/WebCore/Modules/streams/ReadableStreamDefaultReader.js
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/WritableStream.js

index e169062..d019b92 100644 (file)
@@ -1,3 +1,32 @@
+2019-03-04  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Offer @makeTypeError instead of exposing @TypeError
+        https://bugs.webkit.org/show_bug.cgi?id=193858
+
+        Reviewed by Mark Lam.
+
+        Instead of exposing @TypeError, we expose @makeTypeError function.
+        And we make TypeError and Error lazily-allocated objects in non JIT environment.
+        In JIT environment, only TypeError becomes lazily-allocated since WebAssembly errors
+        touch Error prototype anyway. But we can make them lazy in a subsequent patch.
+
+        * builtins/AsyncFromSyncIteratorPrototype.js:
+        * builtins/AsyncGeneratorPrototype.js:
+        (globalPrivate.asyncGeneratorEnqueue):
+        * builtins/BuiltinNames.h:
+        * builtins/PromiseOperations.js:
+        (globalPrivate.createResolvingFunctions.resolve):
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::initializeErrorConstructor):
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::errorPrototype const):
+        (JSC::JSGlobalObject::errorStructure const):
+        * runtime/JSGlobalObjectFunctions.cpp:
+        (JSC::globalFuncMakeTypeError):
+        * runtime/JSGlobalObjectFunctions.h:
+
 2019-03-04  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GLib] Returning G_TYPE_OBJECT from a constructor does not work
index 26ae9e5..6ea1a7f 100644 (file)
@@ -30,7 +30,7 @@ function next(value)
     const promiseCapability = @newPromiseCapability(@Promise);
 
     if (!@isObject(this) || !@isObject(@getByIdDirectPrivate(this, "syncIterator"))) {
-        promiseCapability.@reject.@call(@undefined, new @TypeError('Iterator is not an object.'));
+        promiseCapability.@reject.@call(@undefined, @makeTypeError('Iterator is not an object.'));
         return promiseCapability.@promise;
     }
 
@@ -57,7 +57,7 @@ function return(value)
     const promiseCapability = @newPromiseCapability(@Promise);
 
     if (!@isObject(this) || !@isObject(@getByIdDirectPrivate(this, "syncIterator"))) {
-        promiseCapability.@reject.@call(@undefined, new @TypeError('Iterator is not an object.'));
+        promiseCapability.@reject.@call(@undefined, @makeTypeError('Iterator is not an object.'));
         return promiseCapability.@promise;
     }
 
@@ -81,7 +81,7 @@ function return(value)
         const returnResult = returnMethod.@call(syncIterator, value);
 
         if (!@isObject(returnResult)) {
-            promiseCapability.@reject.@call(@undefined, new @TypeError('Iterator result interface is not an object.'));
+            promiseCapability.@reject.@call(@undefined, @makeTypeError('Iterator result interface is not an object.'));
             return promiseCapability.@promise;
         }
 
@@ -106,7 +106,7 @@ function throw(exception)
     const promiseCapability = @newPromiseCapability(@Promise);
 
     if (!@isObject(this) || !@isObject(@getByIdDirectPrivate(this, "syncIterator"))) {
-        promiseCapability.@reject.@call(@undefined, new @TypeError('Iterator is not an object.'));
+        promiseCapability.@reject.@call(@undefined, @makeTypeError('Iterator is not an object.'));
         return promiseCapability.@promise;
     }
 
@@ -130,7 +130,7 @@ function throw(exception)
         const throwResult = throwMethod.@call(syncIterator, exception);
         
         if (!@isObject(throwResult)) {
-            promiseCapability.@reject.@call(@undefined, new @TypeError('Iterator result interface is not an object.'));
+            promiseCapability.@reject.@call(@undefined, @makeTypeError('Iterator result interface is not an object.'));
             return promiseCapability.@promise;
         }
         
index 4e78680..d9afd42 100644 (file)
@@ -265,7 +265,7 @@ function asyncGeneratorEnqueue(generator, value, resumeMode)
     
     const promiseCapability = @newPromiseCapability(@Promise);
     if (!@isObject(generator) || typeof @getByIdDirectPrivate(generator, "asyncGeneratorSuspendReason") !== 'number') {
-        promiseCapability.@reject.@call(@undefined, new @TypeError('|this| should be an async generator'));
+        promiseCapability.@reject.@call(@undefined, @makeTypeError('|this| should be an async generator'));
         return promiseCapability.@promise;
     }
 
index 1f8260b..5ad0c7b 100644 (file)
@@ -74,7 +74,6 @@ namespace JSC {
     macro(getOwnPropertyNames) \
     macro(ownKeys) \
     macro(Set) \
-    macro(TypeError) \
     macro(typedArrayLength) \
     macro(typedArraySort) \
     macro(typedArrayGetOriginalConstructor) \
@@ -143,6 +142,7 @@ namespace JSC {
     macro(regExpCreate) \
     macro(replaceUsingRegExp) \
     macro(replaceUsingStringSearch) \
+    macro(makeTypeError) \
     macro(mapBucket) \
     macro(mapBucketHead) \
     macro(mapBucketNext) \
index be85499..54d81bc 100644 (file)
@@ -148,7 +148,7 @@ function createResolvingFunctions(promise)
         alreadyResolved = true;
 
         if (resolution === promise)
-            return @rejectPromise(promise, new @TypeError("Resolve a promise with itself"));
+            return @rejectPromise(promise, @makeTypeError("Resolve a promise with itself"));
 
         if (!@isObject(resolution))
             return @fulfillPromise(promise, resolution);
index 490d8cd..1f97389 100644 (file)
@@ -335,6 +335,7 @@ const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = {
   Float64Array          JSGlobalObject::m_typedArrayFloat64          DontEnum|ClassStructure
   DataView              JSGlobalObject::m_typedArrayDataView         DontEnum|ClassStructure
   Date                  JSGlobalObject::m_dateStructure              DontEnum|ClassStructure
+  Error                 JSGlobalObject::m_errorStructure             DontEnum|ClassStructure
   Boolean               JSGlobalObject::m_booleanObjectStructure     DontEnum|ClassStructure
   Number                JSGlobalObject::m_numberObjectStructure      DontEnum|ClassStructure
   Symbol                JSGlobalObject::m_symbolObjectStructure      DontEnum|ClassStructure
@@ -409,9 +410,9 @@ static JSObject* getGetterById(ExecState* exec, JSObject* base, const Identifier
 template<ErrorType errorType>
 void JSGlobalObject::initializeErrorConstructor(LazyClassStructure::Initializer& init)
 {
-    init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorPrototype.get()), errorTypeName(errorType)));
+    init.setPrototype(NativeErrorPrototype::create(init.vm, NativeErrorPrototype::createStructure(init.vm, this, m_errorStructure.prototype(this)), errorTypeName(errorType)));
     init.setStructure(ErrorInstance::createStructure(init.vm, this, init.prototype));
-    init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorConstructor.get()), jsCast<NativeErrorPrototype*>(init.prototype)));
+    init.setConstructor(NativeErrorConstructor<errorType>::create(init.vm, NativeErrorConstructor<errorType>::createStructure(init.vm, this, m_errorStructure.constructor(this)), jsCast<NativeErrorPrototype*>(init.prototype)));
 }
 
 void JSGlobalObject::init(VM& vm)
@@ -726,7 +727,6 @@ m_ ## lowerName ## Prototype->putDirectWithoutTransition(vm, vm.propertyNames->c
     m_promiseConstructor.set(vm, this, promiseConstructor);
     m_internalPromiseConstructor.set(vm, this, internalPromiseConstructor);
     
-    m_errorConstructor.set(vm, this, errorConstructor);
     m_evalErrorStructure.initLater(
         [] (LazyClassStructure::Initializer& init) {
             init.global->initializeErrorConstructor<ErrorType::EvalError>(init);
@@ -854,6 +854,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
 
     JSFunction* privateFuncPropertyIsEnumerable = JSFunction::create(vm, this, 0, String(), globalFuncPropertyIsEnumerable);
     JSFunction* privateFuncImportModule = JSFunction::create(vm, this, 0, String(), globalFuncImportModule);
+    JSFunction* privateFuncMakeTypeError = JSFunction::create(vm, this, 0, String(), globalFuncMakeTypeError);
     JSFunction* privateFuncTypedArrayLength = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncLength);
     JSFunction* privateFuncTypedArrayGetOriginalConstructor = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncGetOriginalConstructor);
     JSFunction* privateFuncTypedArraySort = JSFunction::create(vm, this, 0, String(), typedArrayViewPrivateFuncSort);
@@ -925,9 +926,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         GlobalPropertyInfo(vm.propertyNames->builtinNames().propertyIsEnumerablePrivateName(), privateFuncPropertyIsEnumerable, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().importModulePrivateName(), privateFuncImportModule, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().enqueueJobPrivateName(), JSFunction::create(vm, this, 0, String(), enqueueJob), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
-        // FIXME: Offer @makeTypeError function instead of exposing @TypeError here.
-        // https://bugs.webkit.org/show_bug.cgi?id=193858
-        GlobalPropertyInfo(vm.propertyNames->builtinNames().TypeErrorPrivateName(), m_typeErrorStructure.constructor(this), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->builtinNames().makeTypeErrorPrivateName(), privateFuncMakeTypeError, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayLengthPrivateName(), privateFuncTypedArrayLength, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArrayGetOriginalConstructorPrivateName(), privateFuncTypedArrayGetOriginalConstructor, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->builtinNames().typedArraySortPrivateName(), privateFuncTypedArraySort, PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly),
@@ -1031,7 +1030,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         typedef capitalName ## Prototype Prototype; \
         typedef capitalName ## Constructor Constructor; \
         typedef JS ## capitalName JSObj; \
-        auto* base = m_ ## prototypeBase ## Prototype.get(); \
+        auto* base = prototypeBase ## Prototype(); \
         auto* prototype = Prototype::create(vm, this, Prototype::createStructure(vm, this, base)); \
         auto* structure = JSObj::createStructure(vm, this, prototype); \
         auto* constructor = Constructor::create(vm, Constructor::createStructure(vm, this, this->functionPrototype()), prototype); \
@@ -1587,7 +1586,6 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     visitor.append(thisObject->m_globalScopeExtension);
     visitor.append(thisObject->m_globalCallee);
     visitor.append(thisObject->m_stackOverflowFrameCallee);
-    visitor.append(thisObject->m_errorConstructor);
     thisObject->m_evalErrorStructure.visit(visitor);
     thisObject->m_rangeErrorStructure.visit(visitor);
     thisObject->m_referenceErrorStructure.visit(visitor);
@@ -1630,7 +1628,6 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     visitor.append(thisObject->m_objectPrototype);
     visitor.append(thisObject->m_functionPrototype);
     visitor.append(thisObject->m_arrayPrototype);
-    visitor.append(thisObject->m_errorPrototype);
     visitor.append(thisObject->m_iteratorPrototype);
     visitor.append(thisObject->m_generatorFunctionPrototype);
     visitor.append(thisObject->m_generatorPrototype);
@@ -1664,7 +1661,6 @@ void JSGlobalObject::visitChildren(JSCell* cell, SlotVisitor& visitor)
     thisObject->m_glibWrapperObjectStructure.visit(visitor);
 #endif
     visitor.append(thisObject->m_nullPrototypeObjectStructure);
-    visitor.append(thisObject->m_errorStructure);
     visitor.append(thisObject->m_calleeStructure);
 
     visitor.append(thisObject->m_hostFunctionStructure);
index fead79b..9e267b3 100644 (file)
@@ -128,7 +128,6 @@ template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint;
 
 #define FOR_EACH_SIMPLE_BUILTIN_TYPE_WITH_CONSTRUCTOR(macro) \
     macro(String, string, stringObject, StringObject, String, object) \
-    macro(Error, error, error, ErrorInstance, Error, object) \
     macro(Map, map, map, JSMap, Map, object) \
     macro(Set, set, set, JSSet, Set, object) \
     macro(JSPromise, promise, promise, JSPromise, Promise, object)
@@ -146,6 +145,7 @@ template<typename Watchpoint> class ObjectPropertyChangeAdaptiveWatchpoint;
 #define FOR_EACH_LAZY_BUILTIN_TYPE(macro) \
     macro(Boolean, boolean, booleanObject, BooleanObject, Boolean, object) \
     macro(Date, date, date, DateInstance, Date, object) \
+    macro(Error, error, error, ErrorInstance, Error, object) \
     macro(Number, number, numberObject, NumberObject, Number, object) \
     macro(Symbol, symbol, symbolObject, SymbolObject, Symbol, object) \
     DEFINE_STANDARD_BUILTIN(macro, WeakMap, weakMap) \
@@ -631,7 +631,7 @@ public:
     JSObject* datePrototype() const { return m_dateStructure.prototype(this); }
     JSObject* symbolPrototype() const { return m_symbolObjectStructure.prototypeInitializedOnMainThread(this); }
     RegExpPrototype* regExpPrototype() const { return m_regExpPrototype.get(); }
-    ErrorPrototype* errorPrototype() const { return m_errorPrototype.get(); }
+    JSObject* errorPrototype() const { return m_errorStructure.prototype(this); }
     IteratorPrototype* iteratorPrototype() const { return m_iteratorPrototype.get(); }
     AsyncIteratorPrototype* asyncIteratorPrototype() const { return m_asyncIteratorPrototype.get(); }
     GeneratorFunctionPrototype* generatorFunctionPrototype() const { return m_generatorFunctionPrototype.get(); }
@@ -692,7 +692,7 @@ public:
     Structure* dateStructure() const { return m_dateStructure.get(this); }
     Structure* symbolObjectStructure() const { return m_symbolObjectStructure.get(this); }
     Structure* nullPrototypeObjectStructure() const { return m_nullPrototypeObjectStructure.get(); }
-    Structure* errorStructure() const { return m_errorStructure.get(); }
+    Structure* errorStructure() const { return m_errorStructure.get(this); }
     Structure* errorStructure(ErrorType errorType) const
     {
         switch (errorType) {
index 1cb90da..e3877fb 100644 (file)
@@ -698,6 +698,13 @@ EncodedJSValue JSC_HOST_CALL globalFuncThrowTypeErrorArgumentsCalleeAndCaller(Ex
     return throwVMTypeError(exec, scope, "'arguments', 'callee', and 'caller' cannot be accessed in this context.");
 }
 
+EncodedJSValue JSC_HOST_CALL globalFuncMakeTypeError(ExecState* exec)
+{
+    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+    Structure* errorStructure = globalObject->errorStructure(ErrorType::TypeError);
+    return JSValue::encode(ErrorInstance::create(exec, errorStructure, exec->argument(0), nullptr, TypeNothing, false));
+}
+
 EncodedJSValue JSC_HOST_CALL globalFuncProtoGetter(ExecState* exec)
 {
     VM& vm = exec->vm();
index e775524..9f16aa1 100644 (file)
@@ -48,6 +48,7 @@ EncodedJSValue JSC_HOST_CALL globalFuncEscape(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncUnescape(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncThrowTypeError(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncThrowTypeErrorArgumentsCalleeAndCaller(ExecState*);
+EncodedJSValue JSC_HOST_CALL globalFuncMakeTypeError(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncProtoGetter(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncProtoSetter(ExecState*);
 EncodedJSValue JSC_HOST_CALL globalFuncHostPromiseRejectionTracker(ExecState*);
index 48a1c22..01b33e6 100644 (file)
@@ -1,3 +1,35 @@
+2019-03-04  Yusuke Suzuki  <ysuzuki@apple.com>
+
+        [JSC] Offer @makeTypeError instead of exposing @TypeError
+        https://bugs.webkit.org/show_bug.cgi?id=193858
+
+        Reviewed by Mark Lam.
+
+        Use @makeTypeError instead.
+
+        * Modules/mediastream/RTCPeerConnection.js:
+        * Modules/mediastream/RTCPeerConnectionInternals.js:
+        * Modules/streams/ReadableByteStreamInternals.js:
+        (readableByteStreamControllerClose):
+        (readableByteStreamControllerPullInto):
+        * Modules/streams/ReadableStream.js:
+        (cancel):
+        (pipeTo):
+        * Modules/streams/ReadableStreamBYOBReader.js:
+        (cancel):
+        (read):
+        * Modules/streams/ReadableStreamDefaultReader.js:
+        (cancel):
+        (read):
+        * Modules/streams/ReadableStreamInternals.js:
+        (readableStreamReaderGenericRelease):
+        * Modules/streams/WritableStream.js:
+        (abort):
+        (close):
+        (write):
+        (getter.closed):
+        (getter.ready):
+
 2019-03-04  Simon Fraser  <simon.fraser@apple.com>
 
         Share more code between overflow and frame scrolling nodes, fixing overflow scrollbar display
index ae80dad..79817e4 100644 (file)
@@ -79,7 +79,7 @@ function setLocalDescription(description)
         return @Promise.@reject(@makeThisTypeError("RTCPeerConnection", "setLocalDescription"));
 
     if (arguments.length < 1)
-        return @Promise.@reject(new @TypeError("Not enough arguments"));
+        return @Promise.@reject(@makeTypeError("Not enough arguments"));
 
     // FIXME 169644: According the spec, we should throw when receiving a RTCSessionDescription.
     const objectInfo = {
@@ -103,7 +103,7 @@ function setRemoteDescription(description)
         return @Promise.@reject(@makeThisTypeError("RTCPeerConnection", "setRemoteDescription"));
 
     if (arguments.length < 1)
-        return @Promise.@reject(new @TypeError("Not enough arguments"));
+        return @Promise.@reject(@makeTypeError("Not enough arguments"));
 
     // FIXME: According the spec, we should only expect RTCSessionDescriptionInit.
     const objectInfo = {
@@ -127,7 +127,7 @@ function addIceCandidate(candidate)
         return @Promise.@reject(@makeThisTypeError("RTCPeerConnection", "addIceCandidate"));
 
     if (arguments.length < 1)
-        return @Promise.@reject(new @TypeError("Not enough arguments"));
+        return @Promise.@reject(@makeTypeError("Not enough arguments"));
 
     const objectInfo = {
         "constructor": @RTCIceCandidate,
index f3ca443..2921df8 100644 (file)
@@ -76,7 +76,7 @@ function objectOverload(objectArg, functionName, objectInfo, promiseMode)
     }
 
     if (!objectArgOk)
-        return @Promise.@reject(new @TypeError(`Argument 1 ('${objectInfo.argName}') to RTCPeerConnection.${functionName} must be an instance of ${objectInfo.argType}`));
+        return @Promise.@reject(@makeTypeError(`Argument 1 ('${objectInfo.argName}') to RTCPeerConnection.${functionName} must be an instance of ${objectInfo.argType}`));
 
     return promiseMode(objectArg);
 }
index 77865f1..86364f0 100644 (file)
@@ -149,7 +149,7 @@ function readableByteStreamControllerClose(controller)
     var pendingPullIntos = @getByIdDirectPrivate(controller, "pendingPullIntos");
     if (pendingPullIntos.length > 0) {
         if (pendingPullIntos[0].bytesFilled > 0) {
-            const e = new @TypeError("Close requested while there remain pending bytes");
+            const e = @makeTypeError("Close requested while there remain pending bytes");
             @readableByteStreamControllerError(controller, e);
             throw e;
         }
@@ -648,7 +648,7 @@ function readableByteStreamControllerPullInto(controller, view)
             return @Promise.@resolve({ value: filledView, done: false });
         }
         if (@getByIdDirectPrivate(controller, "closeRequested")) {
-            const e = new @TypeError("Closing stream has been requested");
+            const e = @makeTypeError("Closing stream has been requested");
             @readableByteStreamControllerError(controller, e);
             return @Promise.@reject(e);
         }
index 068fe24..df31e67 100644 (file)
@@ -80,7 +80,7 @@ function cancel(reason)
         return @Promise.@reject(@makeThisTypeError("ReadableStream", "cancel"));
 
     if (@isReadableStreamLocked(this))
-        return @Promise.@reject(new @TypeError("ReadableStream is locked"));
+        return @Promise.@reject(@makeTypeError("ReadableStream is locked"));
 
     return @readableStreamCancel(this, reason);
 }
@@ -198,7 +198,7 @@ function pipeTo(destination)
     @Promise.prototype.@then.@call(destination.closed,
         function() {
             if (!closedPurposefully)
-                cancelSource(new @TypeError('destination is closing or closed and cannot be piped to anymore'));
+                cancelSource(@makeTypeError('destination is closing or closed and cannot be piped to anymore'));
         },
         cancelSource
     );
index e3b432d..3ac04a3 100644 (file)
@@ -49,7 +49,7 @@ function cancel(reason)
         return @Promise.@reject(@makeThisTypeError("ReadableStreamBYOBReader", "cancel"));
 
     if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
-        return @Promise.@reject(new @TypeError("cancel() called on a reader owned by no readable stream"));
+        return @Promise.@reject(@makeTypeError("cancel() called on a reader owned by no readable stream"));
 
     return @readableStreamReaderGenericCancel(this, reason);
 }
@@ -62,16 +62,16 @@ function read(view)
         return @Promise.@reject(@makeThisTypeError("ReadableStreamBYOBReader", "read"));
 
     if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
-        return @Promise.@reject(new @TypeError("read() called on a reader owned by no readable stream"));
+        return @Promise.@reject(@makeTypeError("read() called on a reader owned by no readable stream"));
 
     if (!@isObject(view))
-        return @Promise.@reject(new @TypeError("Provided view is not an object"));
+        return @Promise.@reject(@makeTypeError("Provided view is not an object"));
 
     if (!@ArrayBuffer.@isView(view))
-        return @Promise.@reject(new @TypeError("Provided view is not an ArrayBufferView"));
+        return @Promise.@reject(@makeTypeError("Provided view is not an ArrayBufferView"));
 
     if (view.byteLength === 0)
-        return @Promise.@reject(new @TypeError("Provided view cannot have a 0 byteLength"));
+        return @Promise.@reject(@makeTypeError("Provided view cannot have a 0 byteLength"));
 
     return @readableStreamBYOBReaderRead(this, view);
 }
index da75a3f..fbe229f 100644 (file)
@@ -48,7 +48,7 @@ function cancel(reason)
         return @Promise.@reject(@makeThisTypeError("ReadableStreamDefaultReader", "cancel"));
 
     if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
-        return @Promise.@reject(new @TypeError("cancel() called on a reader owned by no readable stream"));
+        return @Promise.@reject(@makeTypeError("cancel() called on a reader owned by no readable stream"));
 
     return @readableStreamReaderGenericCancel(this, reason);
 }
@@ -60,7 +60,7 @@ function read()
     if (!@isReadableStreamDefaultReader(this))
         return @Promise.@reject(@makeThisTypeError("ReadableStreamDefaultReader", "read"));
     if (!@getByIdDirectPrivate(this, "ownerReadableStream"))
-        return @Promise.@reject(new @TypeError("read() called on a reader owned by no readable stream"));
+        return @Promise.@reject(@makeTypeError("read() called on a reader owned by no readable stream"));
 
     return @readableStreamDefaultReaderRead(this);
 }
index 51f0198..3a32fe4 100644 (file)
@@ -514,9 +514,9 @@ function readableStreamReaderGenericRelease(reader)
     @assert(@getByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "reader") === reader);
 
     if (@getByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "state") === @streamReadable)
-        @getByIdDirectPrivate(reader, "closedPromiseCapability").@reject.@call(@undefined, new @TypeError("releasing lock of reader whose stream is still in readable state"));
+        @getByIdDirectPrivate(reader, "closedPromiseCapability").@reject.@call(@undefined, @makeTypeError("releasing lock of reader whose stream is still in readable state"));
     else
-        @putByIdDirectPrivate(reader, "closedPromiseCapability", { @promise: @newHandledRejectedPromise(new @TypeError("reader released lock")) });
+        @putByIdDirectPrivate(reader, "closedPromiseCapability", { @promise: @newHandledRejectedPromise(@makeTypeError("reader released lock")) });
 
     @putByIdDirectPrivate(@getByIdDirectPrivate(reader, "closedPromiseCapability").@promise, "promiseIsHandled", true);
     @putByIdDirectPrivate(@getByIdDirectPrivate(reader, "ownerReadableStream"), "reader", @undefined);
index 5da54d2..f68adfb 100644 (file)
@@ -70,7 +70,7 @@ function abort(reason)
     "use strict";
 
     if (!@isWritableStream(this))
-        return @Promise.@reject(new @TypeError("The WritableStream.abort method can only be used on instances of WritableStream"));
+        return @Promise.@reject(@makeTypeError("The WritableStream.abort method can only be used on instances of WritableStream"));
 
     const state = @getByIdDirectPrivate(this, "state");
     if (state === @streamClosed)
@@ -89,11 +89,11 @@ function close()
     "use strict";
 
     if (!@isWritableStream(this))
-        return @Promise.@reject(new @TypeError("The WritableStream.close method can only be used on instances of WritableStream"));
+        return @Promise.@reject(@makeTypeError("The WritableStream.close method can only be used on instances of WritableStream"));
 
     const state = @getByIdDirectPrivate(this, "state");
     if (state === @streamClosed || state === @streamClosing)
-        return @Promise.@reject(new @TypeError("Cannot close a WritableString that is closed or closing"));
+        return @Promise.@reject(@makeTypeError("Cannot close a WritableString that is closed or closing"));
 
     if (state === @streamErrored)
         return @Promise.@reject(@getByIdDirectPrivate(this, "storedError"));
@@ -113,11 +113,11 @@ function write(chunk)
     "use strict";
 
     if (!@isWritableStream(this))
-        return @Promise.@reject(new @TypeError("The WritableStream.write method can only be used on instances of WritableStream"));
+        return @Promise.@reject(@makeTypeError("The WritableStream.write method can only be used on instances of WritableStream"));
 
     const state = @getByIdDirectPrivate(this, "state");
     if (state === @streamClosed || state === @streamClosing)
-        return @Promise.@reject(new @TypeError("Cannot write on a WritableString that is closed or closing"));
+        return @Promise.@reject(@makeTypeError("Cannot write on a WritableString that is closed or closing"));
 
     if (state === @streamErrored)
         return @Promise.@reject(this.@storedError);
@@ -154,7 +154,7 @@ function closed()
     "use strict";
 
     if (!@isWritableStream(this))
-        return @Promise.@reject(new @TypeError("The WritableStream.closed getter can only be used on instances of WritableStream"));
+        return @Promise.@reject(@makeTypeError("The WritableStream.closed getter can only be used on instances of WritableStream"));
 
     return @getByIdDirectPrivate(this, "closedPromiseCapability").@promise;
 }
@@ -165,7 +165,7 @@ function ready()
     "use strict";
 
     if (!@isWritableStream(this))
-        return @Promise.@reject(new @TypeError("The WritableStream.ready getter can only be used on instances of WritableStream"));
+        return @Promise.@reject(@makeTypeError("The WritableStream.ready getter can only be used on instances of WritableStream"));
 
     return @getByIdDirectPrivate(this, "readyPromiseCapability").@promise;
 }