Title: [183006] trunk
Revision
183006
Author
commit-qu...@webkit.org
Date
2015-04-20 00:05:41 -0700 (Mon, 20 Apr 2015)

Log Message

Implement `Object.is`
https://bugs.webkit.org/show_bug.cgi?id=143865

Patch by Jordan Harband <ljh...@gmail.com> on 2015-04-20
Reviewed by Darin Adler.

Source/_javascript_Core:

Expose sameValue to JS, via Object.is
https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.is

* runtime/ObjectConstructor.cpp:
(JSC::objectConstructorIs):
* runtime/PropertyDescriptor.cpp:
(JSC::sameValue):

LayoutTests:

* js/Object-getOwnPropertyNames-expected.txt:
* js/Object-is-expected.txt: Added.
* js/Object-is.html: Added.
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/Object-is.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (183005 => 183006)


--- trunk/LayoutTests/ChangeLog	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/LayoutTests/ChangeLog	2015-04-20 07:05:41 UTC (rev 183006)
@@ -1,3 +1,16 @@
+2015-04-20  Jordan Harband  <ljh...@gmail.com>
+
+        Implement `Object.is`
+        https://bugs.webkit.org/show_bug.cgi?id=143865
+
+        Reviewed by Darin Adler.
+
+        * js/Object-getOwnPropertyNames-expected.txt:
+        * js/Object-is-expected.txt: Added.
+        * js/Object-is.html: Added.
+        * js/script-tests/Object-getOwnPropertyNames.js:
+        * js/script-tests/Object-is.js: Added.
+
 2015-04-19  Yusuke Suzuki  <utatane....@gmail.com>
 
         [ES6] Implement WeakSet

Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (183005 => 183006)


--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2015-04-20 07:05:41 UTC (rev 183006)
@@ -41,7 +41,7 @@
 PASS getSortedOwnPropertyNames(decodeURIComponent) is ['length', 'name']
 PASS getSortedOwnPropertyNames(encodeURI) is ['length', 'name']
 PASS getSortedOwnPropertyNames(encodeURIComponent) is ['length', 'name']
-PASS getSortedOwnPropertyNames(Object) is ['create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal']
+PASS getSortedOwnPropertyNames(Object) is ['create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal']
 PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']
 PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']

Added: trunk/LayoutTests/js/Object-is-expected.txt (0 => 183006)


--- trunk/LayoutTests/js/Object-is-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/Object-is-expected.txt	2015-04-20 07:05:41 UTC (rev 183006)
@@ -0,0 +1,26 @@
+Test to ensure correct behavior of Object.is
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Object.is.length is 2
+PASS Object.is.name is 'is'
+PASS Object.is(NaN, NaN) is true
+PASS Object.is(null, null) is true
+PASS Object.is(null) is false
+PASS Object.is(undefined, undefined) is true
+PASS Object.is(true, true) is true
+PASS Object.is(false, false) is true
+PASS Object.is('abc', 'abc') is true
+PASS Object.is(Infinity, Infinity) is true
+PASS Object.is(0, 0) is true
+PASS Object.is(-0, -0) is true
+PASS Object.is(0, -0) is false
+PASS Object.is(-0, 0) is false
+PASS var obj = {}; Object.is(obj, obj) is true
+PASS var arr = []; Object.is(arr, arr) is true
+PASS var sym = Symbol(); Object.is(sym, sym) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/js/Object-is.html (0 => 183006)


--- trunk/LayoutTests/js/Object-is.html	                        (rev 0)
+++ trunk/LayoutTests/js/Object-is.html	2015-04-20 07:05:41 UTC (rev 183006)
@@ -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/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (183005 => 183006)


--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2015-04-20 07:05:41 UTC (rev 183006)
@@ -50,7 +50,7 @@
     "encodeURI": "['length', 'name']",
     "encodeURIComponent": "['length', 'name']",
 // Built-in ECMA objects
-    "Object": "['create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal']",
+    "Object": "['create', 'defineProperties', 'defineProperty', 'freeze', 'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols', 'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys', 'length', 'name', 'preventExtensions', 'prototype', 'seal']",
     "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']",
     "Function": "['length', 'name', 'prototype']",
     "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",

Added: trunk/LayoutTests/js/script-tests/Object-is.js (0 => 183006)


--- trunk/LayoutTests/js/script-tests/Object-is.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/Object-is.js	2015-04-20 07:05:41 UTC (rev 183006)
@@ -0,0 +1,19 @@
+description("Test to ensure correct behavior of Object.is");
+
+shouldBe("Object.is.length", "2");
+shouldBe("Object.is.name", "'is'");
+shouldBe("Object.is(NaN, NaN)", "true");
+shouldBe("Object.is(null, null)", "true");
+shouldBe("Object.is(null)", "false");
+shouldBe("Object.is(undefined, undefined)", "true");
+shouldBe("Object.is(true, true)", "true");
+shouldBe("Object.is(false, false)", "true");
+shouldBe("Object.is('abc', 'abc')", "true");
+shouldBe("Object.is(Infinity, Infinity)", "true");
+shouldBe("Object.is(0, 0)", "true");
+shouldBe("Object.is(-0, -0)", "true");
+shouldBe("Object.is(0, -0)", "false");
+shouldBe("Object.is(-0, 0)", "false");
+shouldBe("var obj = {}; Object.is(obj, obj)", "true");
+shouldBe("var arr = []; Object.is(arr, arr)", "true");
+shouldBe("var sym = Symbol(); Object.is(sym, sym)", "true");

Modified: trunk/Source/_javascript_Core/ChangeLog (183005 => 183006)


--- trunk/Source/_javascript_Core/ChangeLog	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-04-20 07:05:41 UTC (rev 183006)
@@ -1,3 +1,18 @@
+2015-04-20  Jordan Harband  <ljh...@gmail.com>
+
+        Implement `Object.is`
+        https://bugs.webkit.org/show_bug.cgi?id=143865
+
+        Reviewed by Darin Adler.
+
+        Expose sameValue to JS, via Object.is
+        https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.is
+
+        * runtime/ObjectConstructor.cpp:
+        (JSC::objectConstructorIs):
+        * runtime/PropertyDescriptor.cpp:
+        (JSC::sameValue):
+
 2015-04-19  Darin Adler  <da...@apple.com>
 
         Remove all the remaining uses of OwnPtr and PassOwnPtr in _javascript_Core

Modified: trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp (183005 => 183006)


--- trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/Source/_javascript_Core/runtime/ObjectConstructor.cpp	2015-04-20 07:05:41 UTC (rev 183006)
@@ -52,6 +52,7 @@
 EncodedJSValue JSC_HOST_CALL objectConstructorIsSealed(ExecState*);
 EncodedJSValue JSC_HOST_CALL objectConstructorIsFrozen(ExecState*);
 EncodedJSValue JSC_HOST_CALL objectConstructorIsExtensible(ExecState*);
+EncodedJSValue JSC_HOST_CALL objectConstructorIs(ExecState*);
 
 }
 
@@ -78,6 +79,7 @@
   isSealed                  objectConstructorIsSealed                   DontEnum|Function 1
   isFrozen                  objectConstructorIsFrozen                   DontEnum|Function 1
   isExtensible              objectConstructorIsExtensible               DontEnum|Function 1
+  is                        objectConstructorIs                         DontEnum|Function 2
 @end
 */
 
@@ -579,4 +581,9 @@
     return JSValue::encode(jsBoolean(asObject(obj)->isExtensible()));
 }
 
+EncodedJSValue JSC_HOST_CALL objectConstructorIs(ExecState* exec)
+{
+    return JSValue::encode(jsBoolean(sameValue(exec, exec->argument(0), exec->argument(1))));
+}
+
 } // namespace JSC

Modified: trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp (183005 => 183006)


--- trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp	2015-04-20 06:05:26 UTC (rev 183005)
+++ trunk/Source/_javascript_Core/runtime/PropertyDescriptor.cpp	2015-04-20 07:05:41 UTC (rev 183006)
@@ -186,8 +186,10 @@
         return false;
     double x = a.asNumber();
     double y = b.asNumber();
-    if (std::isnan(x))
-        return std::isnan(y);
+    bool xIsNaN = std::isnan(x);
+    bool yIsNaN = std::isnan(y);
+    if (xIsNaN || yIsNaN)
+        return xIsNaN && yIsNaN;
     return bitwise_cast<uint64_t>(x) == bitwise_cast<uint64_t>(y);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to