Title: [202631] trunk
Revision
202631
Author
[email protected]
Date
2016-06-29 11:16:33 -0700 (Wed, 29 Jun 2016)

Log Message

[JSC] Fix small issues of TypedArray prototype
https://bugs.webkit.org/show_bug.cgi?id=159248

Patch by Benjamin Poulain <[email protected]> on 2016-06-29
Reviewed by Saam Barati.

Source/_javascript_Core:

First, TypedArray's toString and Array's toString
should be the same function.
I moved the function to GlobalObject and each array type
gets it as needed.

Then TypedArray length was supposed to be configurable.
I removed the "DontDelete" flag accordingly.

* runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototype::finishCreation):
* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::arrayProtoToStringFunction):
* runtime/JSTypedArrayViewPrototype.cpp:
(JSC::JSTypedArrayViewPrototype::finishCreation):

LayoutTests:

* js/script-tests/typedarray-prototype.js: Added.
* js/typedarray-prototype-expected.txt: Added.
* js/typedarray-prototype.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (202630 => 202631)


--- trunk/LayoutTests/ChangeLog	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/LayoutTests/ChangeLog	2016-06-29 18:16:33 UTC (rev 202631)
@@ -1,3 +1,14 @@
+2016-06-29  Benjamin Poulain  <[email protected]>
+
+        [JSC] Fix small issues of TypedArray prototype
+        https://bugs.webkit.org/show_bug.cgi?id=159248
+
+        Reviewed by Saam Barati.
+
+        * js/script-tests/typedarray-prototype.js: Added.
+        * js/typedarray-prototype-expected.txt: Added.
+        * js/typedarray-prototype.html: Added.
+
 2016-06-29  Alejandro G. Castro  <[email protected]>
 
         WebRTC: ice-char can not contain '=' characters for credentials

Added: trunk/LayoutTests/js/script-tests/typedarray-prototype.js (0 => 202631)


--- trunk/LayoutTests/js/script-tests/typedarray-prototype.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/typedarray-prototype.js	2016-06-29 18:16:33 UTC (rev 202631)
@@ -0,0 +1,44 @@
+"use strict"
+
+description('This tests basic properties of the TypedArray prototype');
+
+let arrayTypes = [
+    Int8Array,
+    Int16Array,
+    Int32Array,
+    Uint8Array,
+    Uint16Array,
+    Uint32Array,
+    Float32Array,
+    Float64Array,
+];
+
+// The prototype should be the same for every type of view.
+for (let i = 0; i < arrayTypes.length; ++i) {
+    for (let j = i; j < arrayTypes.length; ++j) {
+        shouldBeTrue("Object.getPrototypeOf(" + arrayTypes[i].name + ") === Object.getPrototypeOf(" + arrayTypes[j].name + ")");
+    }
+}
+
+let TypedArray = Object.getPrototypeOf(Int8Array);
+
+// length.
+shouldBeFalse('"writable" in Object.getOwnPropertyDescriptor(TypedArray.prototype, "length")');
+shouldBeFalse('Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").enumerable');
+shouldBeTrue('Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").configurable');
+shouldBe('Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").get.length', '0');
+shouldBeEqualToString('typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").get', 'function');
+shouldBe('Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").set', 'undefined');
+
+// toString.
+shouldBe('TypedArray.prototype.toString', 'Array.prototype.toString');
+shouldBeTrue('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").writable');
+shouldBeFalse('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").enumerable');
+shouldBeTrue('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").configurable');
+shouldBeEqualToString('typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").value', 'function');
+
+// toLocaleString.
+shouldBeTrue('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").writable');
+shouldBeFalse('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").enumerable');
+shouldBeTrue('Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").configurable');
+shouldBeEqualToString('typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").value', 'function');

Added: trunk/LayoutTests/js/typedarray-prototype-expected.txt (0 => 202631)


--- trunk/LayoutTests/js/typedarray-prototype-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/typedarray-prototype-expected.txt	2016-06-29 18:16:33 UTC (rev 202631)
@@ -0,0 +1,60 @@
+This tests basic properties of the TypedArray prototype
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Int8Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Int16Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Int32Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Uint8Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Uint16Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Int8Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Int16Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Int32Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Uint8Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Uint16Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Int16Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Int32Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Uint8Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Uint16Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Int32Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Uint8Array) === Object.getPrototypeOf(Uint8Array) is true
+PASS Object.getPrototypeOf(Uint8Array) === Object.getPrototypeOf(Uint16Array) is true
+PASS Object.getPrototypeOf(Uint8Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Uint8Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Uint8Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Uint16Array) === Object.getPrototypeOf(Uint16Array) is true
+PASS Object.getPrototypeOf(Uint16Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Uint16Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Uint16Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Uint32Array) === Object.getPrototypeOf(Uint32Array) is true
+PASS Object.getPrototypeOf(Uint32Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Uint32Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Float32Array) === Object.getPrototypeOf(Float32Array) is true
+PASS Object.getPrototypeOf(Float32Array) === Object.getPrototypeOf(Float64Array) is true
+PASS Object.getPrototypeOf(Float64Array) === Object.getPrototypeOf(Float64Array) is true
+PASS "writable" in Object.getOwnPropertyDescriptor(TypedArray.prototype, "length") is false
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").enumerable is false
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").configurable is true
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").get.length is 0
+PASS typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").get is "function"
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "length").set is undefined
+PASS TypedArray.prototype.toString is Array.prototype.toString
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").writable is true
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").enumerable is false
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").configurable is true
+PASS typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").value is "function"
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").writable is true
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").enumerable is false
+PASS Object.getOwnPropertyDescriptor(TypedArray.prototype, "toLocaleString").configurable is true
+PASS typeof Object.getOwnPropertyDescriptor(TypedArray.prototype, "toString").value is "function"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/typedarray-prototype.html (0 => 202631)


--- trunk/LayoutTests/js/typedarray-prototype.html	                        (rev 0)
+++ trunk/LayoutTests/js/typedarray-prototype.html	2016-06-29 18:16:33 UTC (rev 202631)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Modified: trunk/Source/_javascript_Core/ChangeLog (202630 => 202631)


--- trunk/Source/_javascript_Core/ChangeLog	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-06-29 18:16:33 UTC (rev 202631)
@@ -1,3 +1,28 @@
+2016-06-29  Benjamin Poulain  <[email protected]>
+
+        [JSC] Fix small issues of TypedArray prototype
+        https://bugs.webkit.org/show_bug.cgi?id=159248
+
+        Reviewed by Saam Barati.
+
+        First, TypedArray's toString and Array's toString
+        should be the same function.
+        I moved the function to GlobalObject and each array type
+        gets it as needed.
+
+        Then TypedArray length was supposed to be configurable.
+        I removed the "DontDelete" flag accordingly.
+
+        * runtime/ArrayPrototype.cpp:
+        (JSC::ArrayPrototype::finishCreation):
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::init):
+        (JSC::JSGlobalObject::visitChildren):
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::arrayProtoToStringFunction):
+        * runtime/JSTypedArrayViewPrototype.cpp:
+        (JSC::JSTypedArrayViewPrototype::finishCreation):
+
 2016-06-29  Caio Lima  <[email protected]>
 
         LLInt should support other types of prototype GetById caching.

Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (202630 => 202631)


--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2016-06-29 18:16:33 UTC (rev 202631)
@@ -86,10 +86,10 @@
     ASSERT(inherits(info()));
     vm.prototypeMap.addPrototype(this);
 
+    putDirectWithoutTransition(vm, vm.propertyNames->toString, globalObject->arrayProtoToStringFunction(), DontEnum);
     putDirectWithoutTransition(vm, vm.propertyNames->builtinNames().valuesPublicName(), globalObject->arrayProtoValuesFunction(), DontEnum);
     putDirectWithoutTransition(vm, vm.propertyNames->iteratorSymbol, globalObject->arrayProtoValuesFunction(), DontEnum);
-    
-    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->toString, arrayProtoFuncToString, DontEnum, 0);
+
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->toLocaleString, arrayProtoFuncToLocaleString, DontEnum, 0);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("concat", arrayPrototypeConcatCodeGenerator, DontEnum);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("fill", arrayPrototypeFillCodeGenerator, DontEnum);

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp (202630 => 202631)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.cpp	2016-06-29 18:16:33 UTC (rev 202631)
@@ -365,6 +365,10 @@
     m_functionPrototype->addFunctionProperties(exec, this, &callFunction, &applyFunction, &hasInstanceSymbolFunction);
     m_callFunction.set(vm, this, callFunction);
     m_applyFunction.set(vm, this, applyFunction);
+    m_arrayProtoToStringFunction.initLater(
+        [] (const Initializer<JSFunction>& init) {
+            init.set(JSFunction::create(init.vm, init.owner, 0, init.vm.propertyNames->toString.string(), arrayProtoFuncToString, NoIntrinsic));
+        });
     m_arrayProtoValuesFunction.initLater(
         [] (const Initializer<JSFunction>& init) {
             init.set(JSFunction::createBuiltinFunction(init.vm, arrayPrototypeValuesCodeGenerator(init.vm), init.owner));
@@ -1036,6 +1040,7 @@
     visitor.append(&thisObject->m_callFunction);
     visitor.append(&thisObject->m_applyFunction);
     visitor.append(&thisObject->m_definePropertyFunction);
+    thisObject->m_arrayProtoToStringFunction.visit(visitor);
     thisObject->m_arrayProtoValuesFunction.visit(visitor);
     thisObject->m_initializePromiseFunction.visit(visitor);
     visitor.append(&thisObject->m_newPromiseCapabilityFunction);

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObject.h (202630 => 202631)


--- trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObject.h	2016-06-29 18:16:33 UTC (rev 202631)
@@ -240,6 +240,7 @@
     WriteBarrier<JSFunction> m_callFunction;
     WriteBarrier<JSFunction> m_applyFunction;
     WriteBarrier<JSFunction> m_definePropertyFunction;
+    LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoToStringFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_arrayProtoValuesFunction;
     LazyProperty<JSGlobalObject, JSFunction> m_initializePromiseFunction;
     WriteBarrier<JSFunction> m_newPromiseCapabilityFunction;
@@ -485,6 +486,7 @@
     JSFunction* callFunction() const { return m_callFunction.get(); }
     JSFunction* applyFunction() const { return m_applyFunction.get(); }
     JSFunction* definePropertyFunction() const { return m_definePropertyFunction.get(); }
+    JSFunction* arrayProtoToStringFunction() const { return m_arrayProtoToStringFunction.get(this); }
     JSFunction* arrayProtoValuesFunction() const { return m_arrayProtoValuesFunction.get(this); }
     JSFunction* initializePromiseFunction() const { return m_initializePromiseFunction.get(this); }
     JSFunction* newPromiseCapabilityFunction() const { return m_newPromiseCapabilityFunction.get(); }

Modified: trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp (202630 => 202631)


--- trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp	2016-06-29 18:11:35 UTC (rev 202630)
+++ trunk/Source/_javascript_Core/runtime/JSTypedArrayViewPrototype.cpp	2016-06-29 18:16:33 UTC (rev 202631)
@@ -246,6 +246,8 @@
 
     ASSERT(inherits(info()));
 
+    putDirectWithoutTransition(vm, vm.propertyNames->toString, globalObject->arrayProtoToStringFunction(), DontEnum);
+
     JSC_NATIVE_GETTER(vm.propertyNames->buffer, typedArrayViewProtoGetterFuncBuffer, DontEnum | ReadOnly | DontDelete);
     JSC_NATIVE_INTRINSIC_GETTER(vm.propertyNames->byteLength, typedArrayViewProtoGetterFuncByteLength, DontEnum | ReadOnly | DontDelete, TypedArrayByteLengthIntrinsic);
     JSC_NATIVE_INTRINSIC_GETTER(vm.propertyNames->byteOffset, typedArrayViewProtoGetterFuncByteOffset, DontEnum | ReadOnly | DontDelete, TypedArrayByteOffsetIntrinsic);
@@ -262,7 +264,7 @@
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->join, typedArrayViewProtoFuncJoin, DontEnum, 1);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().keysPublicName(), typedArrayPrototypeKeysCodeGenerator, DontEnum);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION("lastIndexOf", typedArrayViewProtoFuncLastIndexOf, DontEnum, 1);
-    JSC_NATIVE_INTRINSIC_GETTER(vm.propertyNames->length, typedArrayViewProtoGetterFuncLength, DontEnum | ReadOnly | DontDelete, TypedArrayLengthIntrinsic);
+    JSC_NATIVE_INTRINSIC_GETTER(vm.propertyNames->length, typedArrayViewProtoGetterFuncLength, DontEnum | ReadOnly, TypedArrayLengthIntrinsic);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("map", typedArrayPrototypeMapCodeGenerator, DontEnum);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("reduce", typedArrayPrototypeReduceCodeGenerator, DontEnum);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("reduceRight", typedArrayPrototypeReduceRightCodeGenerator, DontEnum);
@@ -272,7 +274,6 @@
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION("some", typedArrayPrototypeSomeCodeGenerator, DontEnum);
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->subarray, typedArrayViewProtoFuncSubarray, DontEnum, 2);
     JSC_BUILTIN_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->toLocaleString, typedArrayPrototypeToLocaleStringCodeGenerator, DontEnum);
-    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->toString, arrayProtoFuncToString, DontEnum, 0);
     JSC_NATIVE_GETTER(vm.propertyNames->toStringTagSymbol, typedArrayViewProtoGetterFuncToStringTag, DontEnum | ReadOnly);
 
     JSFunction* valuesFunction = JSFunction::createBuiltinFunction(vm, typedArrayPrototypeValuesCodeGenerator(vm), globalObject);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to