Changeset 206870 in webkit
- Timestamp:
- Oct 6, 2016 10:59:33 AM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r206853 r206870 1 2016-10-06 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [WebCore][JSC] Use new @throwTypeError and @throwRangeError intrinsics 4 https://bugs.webkit.org/show_bug.cgi?id=163001 5 6 Reviewed by Keith Miller. 7 8 Previously, the argument of @throwXXXError intrinsics must be string literal. 9 But it is error-prone restriction. This patch relaxes the restriction to accept 10 arbitrary values. To keep emitted bytecode small, if the argument is string literal, 11 we generate the same bytecode as before. If the argument is not string literal, 12 we evaluate it and perform to_string before passing to throw_static_error. 13 14 * bytecompiler/BytecodeGenerator.cpp: 15 (JSC::BytecodeGenerator::emitThrowStaticError): 16 * bytecompiler/BytecodeGenerator.h: 17 * bytecompiler/NodesCodegen.cpp: 18 (JSC::BytecodeIntrinsicNode::emit_intrinsic_throwTypeError): 19 (JSC::BytecodeIntrinsicNode::emit_intrinsic_throwRangeError): 20 * dfg/DFGByteCodeParser.cpp: 21 (JSC::DFG::ByteCodeParser::parseBlock): 22 1 23 2016-10-05 Yusuke Suzuki <utatane.tea@gmail.com> 2 24 -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
r206853 r206870 3906 3906 } 3907 3907 3908 void BytecodeGenerator::emitThrowStaticError(ErrorType errorType, RegisterID* raw) 3909 { 3910 RefPtr<RegisterID> message = newTemporary(); 3911 emitToString(message.get(), raw); 3912 emitOpcode(op_throw_static_error); 3913 instructions().append(message->index()); 3914 instructions().append(static_cast<unsigned>(errorType)); 3915 } 3916 3908 3917 void BytecodeGenerator::emitThrowStaticError(ErrorType errorType, const Identifier& message) 3909 3918 { -
trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.h
r206853 r206870 663 663 } 664 664 665 void emitThrowStaticError(ErrorType, RegisterID*); 665 666 void emitThrowStaticError(ErrorType, const Identifier& message); 666 667 void emitThrowReferenceError(const String& message); -
trunk/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
r206853 r206870 902 902 { 903 903 ArgumentListNode* node = m_args->m_listNode; 904 ASSERT(node->m_expr->isString());905 const Identifier& ident = static_cast<StringNode*>(node->m_expr)->value();906 904 ASSERT(!node->m_next); 907 908 generator.emitThrowTypeError(ident); 905 if (node->m_expr->isString()) { 906 const Identifier& ident = static_cast<StringNode*>(node->m_expr)->value(); 907 generator.emitThrowTypeError(ident); 908 } else { 909 RefPtr<RegisterID> message = generator.emitNode(node); 910 generator.emitThrowStaticError(ErrorType::TypeError, message.get()); 911 } 909 912 return dst; 910 913 } … … 913 916 { 914 917 ArgumentListNode* node = m_args->m_listNode; 915 ASSERT(node->m_expr->isString());916 const Identifier& ident = static_cast<StringNode*>(node->m_expr)->value();917 918 ASSERT(!node->m_next); 918 919 generator.emitThrowRangeError(ident); 919 if (node->m_expr->isString()) { 920 const Identifier& ident = static_cast<StringNode*>(node->m_expr)->value(); 921 generator.emitThrowRangeError(ident); 922 } else { 923 RefPtr<RegisterID> message = generator.emitNode(node); 924 generator.emitThrowStaticError(ErrorType::RangeError, message.get()); 925 } 926 920 927 return dst; 921 928 } -
trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
r206853 r206870 4661 4661 4662 4662 case op_throw_static_error: 4663 addToGraph(Phantom, get(VirtualRegister(currentInstruction[1].u.operand))); // Keep argument live. 4663 4664 addToGraph(ThrowStaticError); 4664 4665 flushForTerminal(); -
trunk/Source/WebCore/ChangeLog
r206869 r206870 1 2016-10-06 Yusuke Suzuki <utatane.tea@gmail.com> 2 3 [WebCore][JSC] Use new @throwTypeError and @throwRangeError intrinsics 4 https://bugs.webkit.org/show_bug.cgi?id=163001 5 6 Reviewed by Keith Miller. 7 8 Replace `throw new @XXXError(...)` to @throwXXXError intrinsic. 9 It reduces the size of bytecode sequence and facilitate inlining. 10 11 No behavior change. 12 13 * Modules/fetch/FetchHeaders.js: 14 (initializeFetchHeaders): 15 * Modules/fetch/FetchInternals.js: 16 (fillFetchHeaders): 17 * Modules/fetch/FetchRequest.js: 18 (initializeFetchRequest): 19 * Modules/fetch/FetchResponse.js: 20 (initializeFetchResponse): 21 (clone): 22 * Modules/mediastream/NavigatorUserMedia.js: 23 (webkitGetUserMedia): 24 * Modules/mediastream/RTCPeerConnection.js: 25 (initializeRTCPeerConnection): 26 (getLocalStreams): 27 (getStreamById): 28 (addStream): 29 * Modules/streams/ReadableStream.js: 30 (initializeReadableStream): 31 (getReader): 32 * Modules/streams/ReadableStreamDefaultController.js: 33 (enqueue): 34 (error): 35 (close): 36 * Modules/streams/ReadableStreamDefaultReader.js: 37 (releaseLock): 38 * Modules/streams/ReadableStreamInternals.js: 39 (privateInitializeReadableStreamDefaultReader): 40 (privateInitializeReadableStreamDefaultController): 41 (doStructuredClone): 42 (readableStreamError): 43 * Modules/streams/StreamInternals.js: 44 (validateAndNormalizeQueuingStrategy): 45 (enqueueValueWithSize): 46 * Modules/streams/WritableStream.js: 47 (initializeWritableStream): 48 (state): 49 * xml/XMLHttpRequest.js: 50 (response): 51 1 52 2016-10-06 John Wilander <wilander@apple.com> 2 53 -
trunk/Source/WebCore/Modules/fetch/FetchHeaders.js
r203445 r206870 34 34 35 35 if (!@isObject(headersInit)) 36 throw new @TypeError("headersInit must be an object");36 @throwTypeError("headersInit must be an object"); 37 37 38 38 @fillFetchHeaders(this, headersInit); -
trunk/Source/WebCore/Modules/fetch/FetchInternals.js
r206814 r206870 40 40 let header = headersInit[i]; 41 41 if (header.length !== 2) 42 throw new @TypeError("headersInit sequence items should contain two values");42 @throwTypeError("headersInit sequence items should contain two values"); 43 43 @Headers.prototype.@appendFromJS.@call(headers, header[0], header[1]); 44 44 } -
trunk/Source/WebCore/Modules/fetch/FetchRequest.js
r203675 r206870 33 33 init = { }; 34 34 else if (!@isObject(init)) 35 throw new @TypeError("Request init must be an object");35 @throwTypeError("Request init must be an object"); 36 36 37 37 let headers = this.@initializeWith(input, init); -
trunk/Source/WebCore/Modules/fetch/FetchResponse.js
r206814 r206870 33 33 init = { }; 34 34 else if (!@isObject(init)) 35 throw new @TypeError("Response init must be an object");35 @throwTypeError("Response init must be an object"); 36 36 37 37 let status = (init.status !== @undefined) ? @toNumber(init.status) : 200; 38 38 if (status < 200 || status > 599) 39 throw new @RangeError("Status must be between 200 and 599");39 @throwRangeError("Status must be between 200 and 599"); 40 40 41 41 let statusText = (init.statusText !== @undefined) ? init.statusText : "OK"; … … 48 48 if (body !== @undefined && body !== null) { 49 49 if (status == 101 || status == 204 || status == 205 || status == 304) 50 throw new @TypeError("Response cannot have a body with the given status");50 @throwTypeError("Response cannot have a body with the given status"); 51 51 52 52 // FIXME: Use @isReadableStream once it is no longer guarded by READABLE_STREAM_API guard. … … 96 96 97 97 if (@Response.prototype.@isDisturbed.@call(this) || (this.@body && @isReadableStreamLocked(this.@body))) 98 throw new @TypeError("Cannot clone a disturbed Response");98 @throwTypeError("Cannot clone a disturbed Response"); 99 99 100 100 var cloned = @Response.prototype.@cloneForJS.@call(this); -
trunk/Source/WebCore/Modules/mediastream/NavigatorUserMedia.js
r206011 r206870 35 35 36 36 if (arguments.length < 3) 37 throw new @TypeError("Not enough arguments");37 @throwTypeError("Not enough arguments"); 38 38 39 39 if (options !== @Object(options)) 40 throw new @TypeError("Argument 1 (options) to Navigator.webkitGetUserMedia must be an object");40 @throwTypeError("Argument 1 (options) to Navigator.webkitGetUserMedia must be an object"); 41 41 42 42 if (typeof successCallback !== "function") 43 throw new @TypeError("Argument 2 ('successCallback') to Navigator.webkitGetUserMedia must be a function");43 @throwTypeError("Argument 2 ('successCallback') to Navigator.webkitGetUserMedia must be a function"); 44 44 if (typeof errorCallback !== "function") 45 throw new @TypeError("Argument 3 ('errorCallback') to Navigator.webkitGetUserMedia must be a function");45 @throwTypeError("Argument 3 ('errorCallback') to Navigator.webkitGetUserMedia must be a function"); 46 46 47 47 this.mediaDevices.@getUserMedia(options).@then(successCallback, errorCallback); -
trunk/Source/WebCore/Modules/mediastream/RTCPeerConnection.js
r202810 r206870 36 36 37 37 if (arguments.length < 1) 38 throw new @TypeError("Not enough arguments");38 @throwTypeError("Not enough arguments"); 39 39 40 40 if (!@isObject(configuration)) 41 throw new @TypeError("RTCPeerConnection argument must be a valid Dictionary");41 @throwTypeError("RTCPeerConnection argument must be a valid Dictionary"); 42 42 43 43 // FIXME: Handle errors in a better way than catching and re-throwing (http://webkit.org/b/158936) … … 47 47 const message = e.name === "TypeMismatchError" ? "Invalid RTCPeerConnection constructor arguments" 48 48 : "Error creating RTCPeerConnection"; 49 throw new @TypeError(message);49 @throwTypeError(message); 50 50 } 51 51 … … 61 61 62 62 if (!@isRTCPeerConnection(this)) 63 throw new @TypeError("Function should be called on an RTCPeerConnection");63 @throwTypeError("Function should be called on an RTCPeerConnection"); 64 64 65 65 return this.@localStreams.slice(); … … 71 71 72 72 if (!@isRTCPeerConnection(this)) 73 throw new @TypeError("Function should be called on an RTCPeerConnection");74 75 if (arguments.length < 1) 76 throw new @TypeError("Not enough arguments");73 @throwTypeError("Function should be called on an RTCPeerConnection"); 74 75 if (arguments.length < 1) 76 @throwTypeError("Not enough arguments"); 77 77 78 78 const streamId = @String(streamIdArg); … … 88 88 89 89 if (!@isRTCPeerConnection(this)) 90 throw new @TypeError("Function should be called on an RTCPeerConnection");91 92 if (arguments.length < 1) 93 throw new @TypeError("Not enough arguments");90 @throwTypeError("Function should be called on an RTCPeerConnection"); 91 92 if (arguments.length < 1) 93 @throwTypeError("Not enough arguments"); 94 94 95 95 if (!(stream instanceof @MediaStream)) 96 throw new @TypeError("Argument 1 ('stream') to RTCPeerConnection.addStream must be an instance of MediaStream");96 @throwTypeError("Argument 1 ('stream') to RTCPeerConnection.addStream must be an instance of MediaStream"); 97 97 98 98 if (this.@localStreams.find(localStream => localStream.id === stream.id)) … … 108 108 109 109 if (!@isRTCPeerConnection(this)) 110 throw new @TypeError("Function should be called on an RTCPeerConnection");111 112 if (arguments.length < 1) 113 throw new @TypeError("Not enough arguments");110 @throwTypeError("Function should be called on an RTCPeerConnection"); 111 112 if (arguments.length < 1) 113 @throwTypeError("Not enough arguments"); 114 114 115 115 if (!(stream instanceof @MediaStream)) 116 throw new @TypeError("Argument 1 ('stream') to RTCPeerConnection.removeStream must be an instance of MediaStream");116 @throwTypeError("Argument 1 ('stream') to RTCPeerConnection.removeStream must be an instance of MediaStream"); 117 117 118 118 const indexOfStreamToRemove = this.@localStreams.findIndex(localStream => localStream.id === stream.id); -
trunk/Source/WebCore/Modules/streams/ReadableStream.js
r206814 r206870 37 37 38 38 if (!@isObject(underlyingSource)) 39 throw new @TypeError("ReadableStream constructor takes an object as first argument");39 @throwTypeError("ReadableStream constructor takes an object as first argument"); 40 40 41 41 if (strategy !== @undefined && !@isObject(strategy)) 42 throw new @TypeError("ReadableStream constructor takes an object as second argument, if any");42 @throwTypeError("ReadableStream constructor takes an object as second argument, if any"); 43 43 44 44 this.@state = @streamReadable; … … 54 54 if (typeString === "bytes") { 55 55 // FIXME: Implement support of ReadableByteStreamController. 56 throw new @TypeError("ReadableByteStreamController is not implemented");56 @throwTypeError("ReadableByteStreamController is not implemented"); 57 57 } else if (type === @undefined) { 58 58 if (strategy.highWaterMark === @undefined) … … 60 60 this.@readableStreamController = new @ReadableStreamDefaultController(this, underlyingSource, strategy.size, strategy.highWaterMark); 61 61 } else 62 throw new @RangeError("Invalid type for underlying source");62 @throwRangeError("Invalid type for underlying source"); 63 63 64 64 return this; … … 90 90 if (options.mode === 'byob') { 91 91 // FIXME: Update once ReadableByteStreamContoller and ReadableStreamBYOBReader are implemented. 92 throw new @TypeError("ReadableStreamBYOBReader is not implemented");92 @throwTypeError("ReadableStreamBYOBReader is not implemented"); 93 93 } 94 94 … … 96 96 return new @ReadableStreamDefaultReader(this); 97 97 98 throw new @RangeError("Invalid mode is specified");98 @throwRangeError("Invalid mode is specified"); 99 99 } 100 100 -
trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultController.js
r206814 r206870 34 34 35 35 if (this.@closeRequested) 36 throw new @TypeError("ReadableStreamDefaultController is requested to close");36 @throwTypeError("ReadableStreamDefaultController is requested to close"); 37 37 38 38 if (this.@controlledReadableStream.@state !== @streamReadable) 39 throw new @TypeError("ReadableStream is not readable");39 @throwTypeError("ReadableStream is not readable"); 40 40 41 41 return @readableStreamDefaultControllerEnqueue(this, chunk); … … 51 51 const stream = this.@controlledReadableStream; 52 52 if (stream.@state !== @streamReadable) 53 throw new @TypeError("ReadableStream is not readable");53 @throwTypeError("ReadableStream is not readable"); 54 54 55 55 @readableStreamError(stream, error); … … 64 64 65 65 if (this.@closeRequested) 66 throw new @TypeError("ReadableStreamDefaultController is already requested to close");66 @throwTypeError("ReadableStreamDefaultController is already requested to close"); 67 67 68 68 if (this.@controlledReadableStream.@state !== @streamReadable) 69 throw new @TypeError("ReadableStream is not readable");69 @throwTypeError("ReadableStream is not readable"); 70 70 71 71 @readableStreamDefaultControllerClose(this); -
trunk/Source/WebCore/Modules/streams/ReadableStreamDefaultReader.js
r206814 r206870 63 63 64 64 if (this.@readRequests.length) 65 throw new @TypeError("There are still pending read requests, cannot release the lock");65 @throwTypeError("There are still pending read requests, cannot release the lock"); 66 66 67 67 if (stream.@state === @streamReadable) -
trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js
r206814 r206870 33 33 34 34 if (!@isReadableStream(stream)) 35 throw new @TypeError("ReadableStreamDefaultReader needs a ReadableStream");35 @throwTypeError("ReadableStreamDefaultReader needs a ReadableStream"); 36 36 if (@isReadableStreamLocked(stream)) 37 throw new @TypeError("ReadableStream is locked");37 @throwTypeError("ReadableStream is locked"); 38 38 39 39 this.@readRequests = []; … … 59 59 60 60 if (!@isReadableStream(stream)) 61 throw new @TypeError("ReadableStreamDefaultController needs a ReadableStream");61 @throwTypeError("ReadableStreamDefaultController needs a ReadableStream"); 62 62 63 63 // readableStreamController is initialized with null value. 64 64 if (stream.@readableStreamController !== null) 65 throw new @TypeError("ReadableStream already has a controller");65 @throwTypeError("ReadableStream already has a controller"); 66 66 67 67 this.@controlledReadableStream = stream; … … 158 158 return @structuredCloneArrayBufferView(object); 159 159 160 throw new @TypeError("structuredClone not implemented for: " + object);160 @throwTypeError("structuredClone not implemented for: " + object); 161 161 } 162 162 … … 270 270 } else 271 271 // FIXME: Implement ReadableStreamBYOBReader. 272 throw new @TypeError("Only ReadableStreamDefaultReader is currently supported");272 @throwTypeError("Only ReadableStreamDefaultReader is currently supported"); 273 273 274 274 reader.@closedPromiseCapability.@reject.@call(@undefined, error); -
trunk/Source/WebCore/Modules/streams/StreamInternals.js
r205549 r206870 80 80 81 81 if (size !== @undefined && typeof size !== "function") 82 throw new @TypeError("size parameter must be a function");82 @throwTypeError("size parameter must be a function"); 83 83 84 84 const normalizedStrategy = { }; … … 88 88 89 89 if (@isNaN(normalizedStrategy.highWaterMark) || normalizedStrategy.highWaterMark < 0) 90 throw new @RangeError("highWaterMark value is negative or not a number");90 @throwRangeError("highWaterMark value is negative or not a number"); 91 91 92 92 return normalizedStrategy; … … 115 115 size = @Number(size); 116 116 if (!@isFinite(size) || size < 0) 117 throw new @RangeError("size has an incorrect value");117 @throwRangeError("size has an incorrect value"); 118 118 queue.content.@push({ value: value, size: size }); 119 119 queue.size += size; -
trunk/Source/WebCore/Modules/streams/WritableStream.js
r205549 r206870 37 37 38 38 if (!@isObject(underlyingSink)) 39 throw new @TypeError("WritableStream constructor takes an object as first argument");39 @throwTypeError("WritableStream constructor takes an object as first argument"); 40 40 41 41 if (!@isObject(strategy)) 42 throw new @TypeError("WritableStream constructor takes an object as second argument, if any");42 @throwTypeError("WritableStream constructor takes an object as second argument, if any"); 43 43 44 44 this.@underlyingSink = underlyingSink; … … 171 171 172 172 if (!@isWritableStream(this)) 173 throw new @TypeError("The WritableStream.state getter can only be used on instances of WritableStream");173 @throwTypeError("The WritableStream.state getter can only be used on instances of WritableStream"); 174 174 175 175 switch(this.@state) { -
trunk/Source/WebCore/xml/XMLHttpRequest.js
r203494 r206870 30 30 // FIXME: Add a helper routine for that kind of checks. 31 31 if (!(this instanceof @XMLHttpRequest)) 32 throw new @TypeError("The XMLHttpRequest.response getter can only be used on instances of XMLHttpRequest");32 @throwTypeError("The XMLHttpRequest.response getter can only be used on instances of XMLHttpRequest"); 33 33 34 34 if (@XMLHttpRequest.prototype.@responseCacheIsValid.@call(this))
Note: See TracChangeset
for help on using the changeset viewer.