[Streams API] streams should not directly use Number and related methods
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2015 09:06:25 +0000 (09:06 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2015 09:06:25 +0000 (09:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151499

Reviewed by Darin Adler.

Source/JavaScriptCore:

* runtime/CommonIdentifiers.h: Adding isNaN as private symbol.
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init): Adding @isNaN function.

Source/WebCore:

Covered by updated test.

Using @Number, @isFinite and @isNaN in place of Number, Number.isFinite and Number.isNaN.

* Modules/streams/ReadableStreamInternals.js:
(enqueueInReadableStream):
* Modules/streams/StreamInternals.js:
(validateAndNormalizeQueuingStrategy):
(enqueueValueWithSize):

LayoutTests:

Added a non-regression test.

* streams/streams-promises-expected.txt:
* streams/streams-promises.html:

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

LayoutTests/ChangeLog
LayoutTests/streams/streams-promises-expected.txt
LayoutTests/streams/streams-promises.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/StreamInternals.js

index 4554ce2..419d7f8 100644 (file)
@@ -1,5 +1,17 @@
 2015-12-01  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
+        [Streams API] streams should not directly use Number and related methods
+        https://bugs.webkit.org/show_bug.cgi?id=151499
+
+        Reviewed by Darin Adler.
+
+        Added a non-regression test.
+
+        * streams/streams-promises-expected.txt:
+        * streams/streams-promises.html:
+
+2015-12-01  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
         [Streams API] Remove use of @catch for exposed promises
         https://bugs.webkit.org/show_bug.cgi?id=151625
 
index 4d61e4a..ba1ae22 100644 (file)
@@ -6,4 +6,5 @@ PASS Streams and promises: replace prototype of a promise object
 PASS Streams and promises: replace then method in Promise prototype 
 PASS Streams and promises: replace catch method in Promise prototype 
 PASS Streams and promises: replace then method in promise object 
+PASS Streams should not directly use Number and related methods 
 
index 8be8a65..ae0f4b6 100644 (file)
@@ -89,4 +89,30 @@ test(function() {
     new ReadableStream({ start: function() { return createMangledPromise(); } })
     new WritableStream({ start: function() { return createMangledPromise(); } })
 }, 'Streams and promises: replace then method in promise object');
+
+test(function() {
+    const NumberBackup = Number;
+    const NumberIsNaNBackup = Number.isNaN;
+    const NumberIsFiniteBackup = Number.isFinite;
+
+    try {
+        Number.isNaN = function() { assert_unreached("streams should not use this Number.isNaN method"); };
+        Number.isFinite = function() { assert_unreached("streams should not use this Number.isFinite method"); };
+        Number = null;
+
+        new ReadableStream({
+            start: function(controller) {
+                controller.enqueue("small potato");
+            }
+        }, {
+            size: function(chunk) { return 2; },
+            highWaterMark: 1
+        });
+
+    } finally {
+        Number = NumberBackup;
+        Number.isNaN = NumberIsNaNBackup;
+        Number.isFinite = NumberIsFiniteBackup;
+    }
+}, 'Streams should not directly use Number and related methods');
 </script>
index 214bcca..e080def 100644 (file)
@@ -1,3 +1,14 @@
+2015-12-01  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Streams API] streams should not directly use Number and related methods
+        https://bugs.webkit.org/show_bug.cgi?id=151499
+
+        Reviewed by Darin Adler.
+
+        * runtime/CommonIdentifiers.h: Adding isNaN as private symbol.
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init): Adding @isNaN function.
+
 2015-12-01  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Don't hide the argument name inside for block in AirIteratedRegisterCoalescing.cpp
index 4cf6590..495f235 100644 (file)
     macro(abs) \
     macro(floor) \
     macro(isFinite) \
+    macro(isNaN) \
     macro(getPrototypeOf) \
     macro(getOwnPropertyNames) \
     macro(RangeError) \
index a4007d3..bc08f96 100644 (file)
@@ -500,6 +500,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
     JSFunction* privateFuncAbs = JSFunction::create(vm, this, 0, String(), mathProtoFuncAbs, AbsIntrinsic);
     JSFunction* privateFuncFloor = JSFunction::create(vm, this, 0, String(), mathProtoFuncFloor, FloorIntrinsic);
     JSFunction* privateFuncIsFinite = JSFunction::create(vm, this, 0, String(), globalFuncIsFinite);
+    JSFunction* privateFuncIsNaN = JSFunction::create(vm, this, 0, String(), globalFuncIsNaN);
 
     JSFunction* privateFuncGetTemplateObject = JSFunction::create(vm, this, 0, String(), getTemplateObject);
     JSFunction* privateFuncToLength = JSFunction::createBuiltinFunction(vm, globalObjectToLengthCodeGenerator(vm), this);
@@ -527,6 +528,7 @@ putDirectWithoutTransition(vm, vm.propertyNames-> jsName, lowerName ## Construct
         GlobalPropertyInfo(vm.propertyNames->absPrivateName, privateFuncAbs, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->floorPrivateName, privateFuncFloor, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->isFinitePrivateName, privateFuncIsFinite, DontEnum | DontDelete | ReadOnly),
+        GlobalPropertyInfo(vm.propertyNames->isNaNPrivateName, privateFuncIsNaN, DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyPrivateName, jsNumber(ArrayIterateKey), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindValuePrivateName, jsNumber(ArrayIterateValue), DontEnum | DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->arrayIterationKindKeyValuePrivateName, jsNumber(ArrayIterateKeyValue), DontEnum | DontDelete | ReadOnly),
index 1652709..711e63c 100644 (file)
@@ -1,3 +1,20 @@
+2015-12-01  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Streams API] streams should not directly use Number and related methods
+        https://bugs.webkit.org/show_bug.cgi?id=151499
+
+        Reviewed by Darin Adler.
+
+        Covered by updated test.
+
+        Using @Number, @isFinite and @isNaN in place of Number, Number.isFinite and Number.isNaN.
+
+        * Modules/streams/ReadableStreamInternals.js:
+        (enqueueInReadableStream):
+        * Modules/streams/StreamInternals.js:
+        (validateAndNormalizeQueuingStrategy):
+        (enqueueValueWithSize):
+
 2015-12-01  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GTK+ build after r192849.
index a878a5c..36fd277 100644 (file)
@@ -322,8 +322,8 @@ function enqueueInReadableStream(stream, chunk)
     try {
         let size = 1;
         if (stream.@strategy.size) {
-            size = Number(stream.@strategy.size(chunk));
-            if (Number.isNaN(size) || size === +Infinity || size < 0)
+            size = @Number(stream.@strategy.size(chunk));
+            if (!@isFinite(size) || size < 0)
                 throw new @RangeError("Chunk size is not valid");
         }
         @enqueueValueWithSize(stream.@queue, chunk, size);
index fcd8c99..f60e4d0 100644 (file)
@@ -78,9 +78,9 @@ function validateAndNormalizeQueuingStrategy(size, highWaterMark)
     const normalizedStrategy = { };
 
     normalizedStrategy.size = size;
-    normalizedStrategy.highWaterMark = Number(highWaterMark);
+    normalizedStrategy.highWaterMark = @Number(highWaterMark);
 
-    if (Number.isNaN(normalizedStrategy.highWaterMark))
+    if (@isNaN(normalizedStrategy.highWaterMark))
         throw new @TypeError("highWaterMark parameter is not a number");
     if (normalizedStrategy.highWaterMark < 0)
         throw new @RangeError("highWaterMark is negative");
@@ -108,8 +108,8 @@ function enqueueValueWithSize(queue, value, size)
 {
     "use strict";
 
-    size = Number(size);
-    if (Number.isNaN(size) || !Number.isFinite(size) || size < 0)
+    size = @Number(size);
+    if (!@isFinite(size) || size < 0)
         throw new @RangeError("size has an incorrect value");
     queue.content.push({ value: value, size: size });
     queue.size += size;