[Streams API] Shield implementation from user mangling Promise.reject and resolve...
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 14:01:13 +0000 (14:01 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 14:01:13 +0000 (14:01 +0000)
commita55c1ff251744c9d9ceda141bd5d46f77df4b0d6
tree0e52835cd3e92efeb78f114e17e1bf07ce893efa
parentd0f6102c11027f63b3968b8d01eb268befe714b2
[Streams API] Shield implementation from user mangling Promise.reject and resolve methods
https://bugs.webkit.org/show_bug.cgi?id=150895

Reviewed by Youenn Fablet.

Source/JavaScriptCore:

Keep Promise.resolve and reject also as internal slots for the Promise constructor given that there is no way to
retrieve the former implementation if the user decides to replace it. This allows to safely create vended
promises even if the user changes the constructor methods.

* runtime/JSPromiseConstructor.h:
* runtime/JSPromiseConstructor.cpp:
(JSC::JSPromiseConstructor::addOwnInternalSlots): Added to include @reject and @resolve.
(JSC::JSPromiseConstructor::create): Call addOwnInternalSlots.

Source/WebCore:

Replace all calls to @Promise.resolve and @Promise.reject with their internal slot counterparts. This way we
ensure that if the user replaces those constructor methods, our implementation still works.

Test: streams/streams-promises.html.

* Modules/streams/ReadableStream.js:
(initializeReadableStream):
(cancel):
* Modules/streams/ReadableStreamInternals.js:
(privateInitializeReadableStreamReader):
(cancelReadableStream):
(readFromReadableStreamReader):
* Modules/streams/ReadableStreamReader.js:
(cancel):
(read):
(closed):
* Modules/streams/StreamInternals.js:
(promiseInvokeOrNoop):
(promiseInvokeOrFallbackOrNoop):
* Modules/streams/WritableStream.js:
(initializeWritableStream):
(abort):
(close):
(write):
(closed):
(ready):

LayoutTests:

* streams/streams-promises.html: Improved some style issues. Added tests about changing Promise.resolve and
reject.
* streams/streams-promises-expected.txt: Added expectations.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192057 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/streams/streams-promises-expected.txt
LayoutTests/streams/streams-promises.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
Source/JavaScriptCore/runtime/JSPromiseConstructor.h
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.js
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/ReadableStreamReader.js
Source/WebCore/Modules/streams/StreamInternals.js
Source/WebCore/Modules/streams/WritableStream.js