Title: [194394] trunk
Revision
194394
Author
[email protected]
Date
2015-12-23 12:02:37 -0800 (Wed, 23 Dec 2015)

Log Message

[INTL] Implement String.prototype.localeCompare in ECMA-402
https://bugs.webkit.org/show_bug.cgi?id=147607

Patch by Andy VanWagoner <[email protected]> on 2015-12-23
Reviewed by Benjamin Poulain.

Source/_javascript_Core:

Add localeCompare in builtin _javascript_ that delegates comparing to Intl.Collator.
Keep existing native implementation for use if INTL flag is disabled.
For the common case where no locale or options are specified, avoid creating
a new collator and just use the prototype which is initialized with the defaults.

* CMakeLists.txt:
* DerivedSources.make:
* _javascript_Core.xcodeproj/project.pbxproj:
* builtins/StringPrototype.js: Added.
(localeCompare):
* runtime/StringPrototype.cpp:
(JSC::StringPrototype::finishCreation):

LayoutTests:

* js/script-tests/string-localeCompare.js:
* js/script-tests/string-prototype-properties.js: Update error message.
* js/string-localeCompare-expected.txt:
* js/string-prototype-properties-expected.txt: Update error message.
* js/string-localeCompare.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (194393 => 194394)


--- trunk/LayoutTests/ChangeLog	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/ChangeLog	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1,3 +1,16 @@
+2015-12-23  Andy VanWagoner  <[email protected]>
+
+        [INTL] Implement String.prototype.localeCompare in ECMA-402
+        https://bugs.webkit.org/show_bug.cgi?id=147607
+
+        Reviewed by Benjamin Poulain.
+
+        * js/script-tests/string-localeCompare.js:
+        * js/script-tests/string-prototype-properties.js: Update error message.
+        * js/string-localeCompare-expected.txt:
+        * js/string-prototype-properties-expected.txt: Update error message.
+        * js/string-localeCompare.html:
+
 2015-12-23  Ryan Haddad  <[email protected]>
 
         Rebaselining fast/text/emoji.html for Windows

Modified: trunk/LayoutTests/js/dom/script-tests/string-prototype-properties.js (194393 => 194394)


--- trunk/LayoutTests/js/dom/script-tests/string-prototype-properties.js	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/js/dom/script-tests/string-prototype-properties.js	2015-12-23 20:02:37 UTC (rev 194394)
@@ -20,7 +20,7 @@
 shouldThrow("String.prototype.substring.call(undefined, 1, 3)");
 shouldThrow("String.prototype.toLowerCase.call(undefined)");
 shouldThrow("String.prototype.toUpperCase.call(undefined)");
-shouldThrow("String.prototype.localeCompare.call(undefined, '1224')");
+shouldThrow("String.prototype.localeCompare.call(undefined, '1224')", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
 shouldThrow("String.prototype.toLocaleLowerCase.call(undefined)");
 shouldThrow("String.prototype.toLocaleUpperCase.call(undefined)");
 shouldThrow("String.prototype.trim.call(undefined)");

Modified: trunk/LayoutTests/js/dom/string-prototype-properties-expected.txt (194393 => 194394)


--- trunk/LayoutTests/js/dom/string-prototype-properties-expected.txt	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/js/dom/string-prototype-properties-expected.txt	2015-12-23 20:02:37 UTC (rev 194394)
@@ -20,7 +20,7 @@
 PASS String.prototype.substring.call(undefined, 1, 3) threw exception TypeError: Type error.
 PASS String.prototype.toLowerCase.call(undefined) threw exception TypeError: Type error.
 PASS String.prototype.toUpperCase.call(undefined) threw exception TypeError: Type error.
-PASS String.prototype.localeCompare.call(undefined, '1224') threw exception TypeError: Type error.
+PASS String.prototype.localeCompare.call(undefined, '1224') threw exception TypeError: String.prototype.localeCompare requires that |this| not be undefined.
 PASS String.prototype.toLocaleLowerCase.call(undefined) threw exception TypeError: Type error.
 PASS String.prototype.toLocaleUpperCase.call(undefined) threw exception TypeError: Type error.
 PASS String.prototype.trim.call(undefined) threw exception TypeError: Type error.

Modified: trunk/LayoutTests/js/script-tests/string-localeCompare.js (194393 => 194394)


--- trunk/LayoutTests/js/script-tests/string-localeCompare.js	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/js/script-tests/string-localeCompare.js	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1,5 +1,28 @@
-description("This test checks String.localeCompare().");
+description("This test checks the behavior of String.prototype.localeCompare as described in the ECMAScript Internationalization API Specification (ECMA-402 2.0).");
 
+shouldBe("String.prototype.localeCompare.length", "1");
+shouldBeFalse("Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').enumerable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').configurable");
+shouldBeTrue("Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').writable");
+
+// Test RequireObjectCoercible.
+shouldThrow("String.prototype.localeCompare.call()", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
+shouldThrow("String.prototype.localeCompare.call(undefined)", "'TypeError: String.prototype.localeCompare requires that |this| not be undefined'");
+shouldThrow("String.prototype.localeCompare.call(null)", "'TypeError: String.prototype.localeCompare requires that |this| not be null'");
+shouldNotThrow("String.prototype.localeCompare.call({}, '')");
+shouldNotThrow("String.prototype.localeCompare.call([], '')");
+shouldNotThrow("String.prototype.localeCompare.call(NaN, '')");
+shouldNotThrow("String.prototype.localeCompare.call(5, '')");
+shouldNotThrow("String.prototype.localeCompare.call('', '')");
+shouldNotThrow("String.prototype.localeCompare.call(() => {}, '')");
+
+// Test toString fails.
+shouldThrow("''.localeCompare.call({ toString() { throw 'thisFail' } }, '')", "'thisFail'");
+shouldThrow("''.localeCompare({ toString() { throw 'thatFail' } })", "'thatFail'");
+shouldNotThrow("''.localeCompare()");
+shouldNotThrow("''.localeCompare(null)");
+
+// Basic support.
 shouldBeTrue('"a".localeCompare("aa") < 0');
 shouldBeTrue('"a".localeCompare("b") < 0');
 
@@ -8,3 +31,45 @@
 
 shouldBeTrue('"aa".localeCompare("a") > 0');
 shouldBeTrue('"b".localeCompare("a") > 0');
+
+// Uses Intl.Collator.
+shouldThrow("'a'.localeCompare('b', '$')", "'RangeError: invalid language tag: $'");
+shouldThrow("'a'.localeCompare('b', 'en', {usage: 'Sort'})", '\'RangeError: usage must be either "sort" or "search"\'');
+
+shouldBe("'ä'.localeCompare('z', 'en')", "-1");
+shouldBe("'ä'.localeCompare('z', 'sv')", "1");
+
+shouldBe("'a'.localeCompare('b', 'en', { sensitivity:'base' })", "-1");
+shouldBe("'a'.localeCompare('ä', 'en', { sensitivity:'base' })", "0");
+shouldBe("'a'.localeCompare('A', 'en', { sensitivity:'base' })", "0");
+shouldBe("'a'.localeCompare('ⓐ', 'en', { sensitivity:'base' })", "0");
+
+shouldBe("'a'.localeCompare('b', 'en', { sensitivity:'accent' })", "-1");
+shouldBe("'a'.localeCompare('ä', 'en', { sensitivity:'accent' })", "-1");
+shouldBe("'a'.localeCompare('A', 'en', { sensitivity:'accent' })", "0");
+shouldBe("'a'.localeCompare('ⓐ', 'en', { sensitivity:'accent' })", "0");
+
+shouldBe("'a'.localeCompare('b', 'en', { sensitivity:'case' })", "-1");
+shouldBe("'a'.localeCompare('ä', 'en', { sensitivity:'case' })", "0");
+shouldBe("'a'.localeCompare('A', 'en', { sensitivity:'case' })", "-1");
+shouldBe("'a'.localeCompare('ⓐ', 'en', { sensitivity:'case' })", "0");
+
+shouldBe("'a'.localeCompare('b', 'en', { sensitivity:'variant' })", "-1");
+shouldBe("'a'.localeCompare('ä', 'en', { sensitivity:'variant' })", "-1");
+shouldBe("'a'.localeCompare('A', 'en', { sensitivity:'variant' })", "-1");
+shouldBe("'a'.localeCompare('ⓐ', 'en', { sensitivity:'variant' })", "-1");
+
+shouldBe("'1'.localeCompare('2', 'en', { numeric:false })", "-1");
+shouldBe("'2'.localeCompare('10', 'en', { numeric:false })", "1");
+shouldBe("'01'.localeCompare('1', 'en', { numeric:false })", "-1");
+shouldBe("'๑'.localeCompare('๒', 'en', { numeric:false })", "-1");
+shouldBe("'๒'.localeCompare('๑๐', 'en', { numeric:false })", "1");
+shouldBe("'๐๑'.localeCompare('๑', 'en', { numeric:false })", "-1");
+
+shouldBe("'1'.localeCompare('2', 'en', { numeric:true })", "-1");
+shouldBe("'2'.localeCompare('10', 'en', { numeric:true })", "-1");
+shouldBe("'01'.localeCompare('1', 'en', { numeric:true })", "0");
+shouldBe("'๑'.localeCompare('๒', 'en', { numeric:true })", "-1");
+shouldBe("'๒'.localeCompare('๑๐', 'en', { numeric:true })", "-1");
+shouldBe("'๐๑'.localeCompare('๑', 'en', { numeric:true })", "0");
+

Modified: trunk/LayoutTests/js/string-localeCompare-expected.txt (194393 => 194394)


--- trunk/LayoutTests/js/string-localeCompare-expected.txt	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/js/string-localeCompare-expected.txt	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1,14 +1,63 @@
-This test checks String.localeCompare().
+This test checks the behavior of String.prototype.localeCompare as described in the ECMAScript Internationalization API Specification (ECMA-402 2.0).
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
+PASS String.prototype.localeCompare.length is 1
+PASS Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').enumerable is false
+PASS Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').configurable is true
+PASS Object.getOwnPropertyDescriptor(String.prototype, 'localeCompare').writable is true
+PASS String.prototype.localeCompare.call() threw exception TypeError: String.prototype.localeCompare requires that |this| not be undefined.
+PASS String.prototype.localeCompare.call(undefined) threw exception TypeError: String.prototype.localeCompare requires that |this| not be undefined.
+PASS String.prototype.localeCompare.call(null) threw exception TypeError: String.prototype.localeCompare requires that |this| not be null.
+PASS String.prototype.localeCompare.call({}, '') did not throw exception.
+PASS String.prototype.localeCompare.call([], '') did not throw exception.
+PASS String.prototype.localeCompare.call(NaN, '') did not throw exception.
+PASS String.prototype.localeCompare.call(5, '') did not throw exception.
+PASS String.prototype.localeCompare.call('', '') did not throw exception.
+PASS String.prototype.localeCompare.call(() => {}, '') did not throw exception.
+PASS ''.localeCompare.call({ toString() { throw 'thisFail' } }, '') threw exception thisFail.
+PASS ''.localeCompare({ toString() { throw 'thatFail' } }) threw exception thatFail.
+PASS ''.localeCompare() did not throw exception.
+PASS ''.localeCompare(null) did not throw exception.
 PASS "a".localeCompare("aa") < 0 is true
 PASS "a".localeCompare("b") < 0 is true
 PASS "a".localeCompare("a") === 0 is true
 PASS "ạ̈".localeCompare("ạ̈") === 0 is true
 PASS "aa".localeCompare("a") > 0 is true
 PASS "b".localeCompare("a") > 0 is true
+PASS 'a'.localeCompare('b', '$') threw exception RangeError: invalid language tag: $.
+PASS 'a'.localeCompare('b', 'en', {usage: 'Sort'}) threw exception RangeError: usage must be either "sort" or "search".
+PASS 'ä'.localeCompare('z', 'en') is -1
+PASS 'ä'.localeCompare('z', 'sv') is 1
+PASS 'a'.localeCompare('b', 'en', { sensitivity:'base' }) is -1
+PASS 'a'.localeCompare('ä', 'en', { sensitivity:'base' }) is 0
+PASS 'a'.localeCompare('A', 'en', { sensitivity:'base' }) is 0
+PASS 'a'.localeCompare('ⓐ', 'en', { sensitivity:'base' }) is 0
+PASS 'a'.localeCompare('b', 'en', { sensitivity:'accent' }) is -1
+PASS 'a'.localeCompare('ä', 'en', { sensitivity:'accent' }) is -1
+PASS 'a'.localeCompare('A', 'en', { sensitivity:'accent' }) is 0
+PASS 'a'.localeCompare('ⓐ', 'en', { sensitivity:'accent' }) is 0
+PASS 'a'.localeCompare('b', 'en', { sensitivity:'case' }) is -1
+PASS 'a'.localeCompare('ä', 'en', { sensitivity:'case' }) is 0
+PASS 'a'.localeCompare('A', 'en', { sensitivity:'case' }) is -1
+PASS 'a'.localeCompare('ⓐ', 'en', { sensitivity:'case' }) is 0
+PASS 'a'.localeCompare('b', 'en', { sensitivity:'variant' }) is -1
+PASS 'a'.localeCompare('ä', 'en', { sensitivity:'variant' }) is -1
+PASS 'a'.localeCompare('A', 'en', { sensitivity:'variant' }) is -1
+PASS 'a'.localeCompare('ⓐ', 'en', { sensitivity:'variant' }) is -1
+PASS '1'.localeCompare('2', 'en', { numeric:false }) is -1
+PASS '2'.localeCompare('10', 'en', { numeric:false }) is 1
+PASS '01'.localeCompare('1', 'en', { numeric:false }) is -1
+PASS '๑'.localeCompare('๒', 'en', { numeric:false }) is -1
+PASS '๒'.localeCompare('๑๐', 'en', { numeric:false }) is 1
+PASS '๐๑'.localeCompare('๑', 'en', { numeric:false }) is -1
+PASS '1'.localeCompare('2', 'en', { numeric:true }) is -1
+PASS '2'.localeCompare('10', 'en', { numeric:true }) is -1
+PASS '01'.localeCompare('1', 'en', { numeric:true }) is 0
+PASS '๑'.localeCompare('๒', 'en', { numeric:true }) is -1
+PASS '๒'.localeCompare('๑๐', 'en', { numeric:true }) is -1
+PASS '๐๑'.localeCompare('๑', 'en', { numeric:true }) is 0
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/string-localeCompare.html (194393 => 194394)


--- trunk/LayoutTests/js/string-localeCompare.html	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/LayoutTests/js/string-localeCompare.html	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1,6 +1,7 @@
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
 <html>
 <head>
+<meta charset="utf-8">
 <script src=""
 </head>
 <body>

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (194393 => 194394)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1251,6 +1251,7 @@
     ${_javascript_CORE_DIR}/builtins/ReflectObject.js
     ${_javascript_CORE_DIR}/builtins/StringConstructor.js
     ${_javascript_CORE_DIR}/builtins/StringIteratorPrototype.js
+    ${_javascript_CORE_DIR}/builtins/StringPrototype.js
     ${_javascript_CORE_DIR}/builtins/TypedArrayConstructor.js
     ${_javascript_CORE_DIR}/builtins/TypedArrayPrototype.js
 )

Modified: trunk/Source/_javascript_Core/ChangeLog (194393 => 194394)


--- trunk/Source/_javascript_Core/ChangeLog	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-12-23 20:02:37 UTC (rev 194394)
@@ -1,3 +1,23 @@
+2015-12-23  Andy VanWagoner  <[email protected]>
+
+        [INTL] Implement String.prototype.localeCompare in ECMA-402
+        https://bugs.webkit.org/show_bug.cgi?id=147607
+
+        Reviewed by Benjamin Poulain.
+
+        Add localeCompare in builtin _javascript_ that delegates comparing to Intl.Collator.
+        Keep existing native implementation for use if INTL flag is disabled.
+        For the common case where no locale or options are specified, avoid creating
+        a new collator and just use the prototype which is initialized with the defaults.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * builtins/StringPrototype.js: Added.
+        (localeCompare):
+        * runtime/StringPrototype.cpp:
+        (JSC::StringPrototype::finishCreation):
+
 2015-12-23  Benjamin Poulain  <[email protected]>
 
         Fix x86_64 after r194388

Modified: trunk/Source/_javascript_Core/DerivedSources.make (194393 => 194394)


--- trunk/Source/_javascript_Core/DerivedSources.make	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/Source/_javascript_Core/DerivedSources.make	2015-12-23 20:02:37 UTC (rev 194394)
@@ -98,6 +98,7 @@
     $(_javascript_Core)/builtins/ReflectObject.js \
     $(_javascript_Core)/builtins/StringConstructor.js \
     $(_javascript_Core)/builtins/StringIteratorPrototype.js \
+    $(_javascript_Core)/builtins/StringPrototype.js \
     $(_javascript_Core)/builtins/TypedArrayConstructor.js \
     $(_javascript_Core)/builtins/TypedArrayPrototype.js \
 #

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (194393 => 194394)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2015-12-23 20:02:37 UTC (rev 194394)
@@ -2059,7 +2059,7 @@
 		FE99B24A1C24C3D700C82159 /* JITNegGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE99B2471C24B6D300C82159 /* JITNegGenerator.cpp */; settings = {ASSET_TAGS = (); }; };
 		FEA08620182B7A0400F6D851 /* Breakpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = FEA0861E182B7A0400F6D851 /* Breakpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */ = {isa = PBXBuildFile; fileRef = FEA0861F182B7A0400F6D851 /* DebuggerPrimitives.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		FEA1E4391C213A2B00277A16 /* ValueProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEA1E4381C213A2600277A16 /* ValueProfile.cpp */; settings = {ASSET_TAGS = (); }; };
+		FEA1E4391C213A2B00277A16 /* ValueProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEA1E4381C213A2600277A16 /* ValueProfile.cpp */; };
 		FEB137571BB11EF900CD5100 /* MacroAssemblerARM64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEB137561BB11EEE00CD5100 /* MacroAssemblerARM64.cpp */; };
 		FEB51F6C1A97B688001F921C /* Regress141809.mm in Sources */ = {isa = PBXBuildFile; fileRef = FEB51F6B1A97B688001F921C /* Regress141809.mm */; };
 		FEB58C14187B8B160098EF0B /* ErrorHandlingScope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEB58C12187B8B160098EF0B /* ErrorHandlingScope.cpp */; };
@@ -3681,6 +3681,7 @@
 		A1D792F91B43864B004516F5 /* IntlNumberFormatConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlNumberFormatConstructor.h; sourceTree = "<group>"; };
 		A1D792FA1B43864B004516F5 /* IntlNumberFormatPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntlNumberFormatPrototype.cpp; sourceTree = "<group>"; };
 		A1D792FB1B43864B004516F5 /* IntlNumberFormatPrototype.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntlNumberFormatPrototype.h; sourceTree = "<group>"; };
+		A1E0451B1C25B4B100BB663C /* StringPrototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; path = StringPrototype.js; sourceTree = "<group>"; };
 		A503FA13188E0FAF00110F14 /* _javascript_CallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = _javascript_CallFrame.cpp; sourceTree = "<group>"; };
 		A503FA14188E0FAF00110F14 /* _javascript_CallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _javascript_CallFrame.h; sourceTree = "<group>"; };
 		A503FA15188E0FB000110F14 /* JSJavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrame.cpp; sourceTree = "<group>"; };
@@ -6781,6 +6782,7 @@
 				7CF9BC5F1B65D9B1009DB1EF /* ReflectObject.js */,
 				7CF9BC601B65D9B1009DB1EF /* StringConstructor.js */,
 				7CF9BC611B65D9B1009DB1EF /* StringIteratorPrototype.js */,
+				A1E0451B1C25B4B100BB663C /* StringPrototype.js */,
 				53917E831B791CB8000EBD33 /* TypedArrayPrototype.js */,
 				534C457A1BC703DC007476A7 /* TypedArrayConstructor.js */,
 			);

Added: trunk/Source/_javascript_Core/builtins/StringPrototype.js (0 => 194394)


--- trunk/Source/_javascript_Core/builtins/StringPrototype.js	                        (rev 0)
+++ trunk/Source/_javascript_Core/builtins/StringPrototype.js	2015-12-23 20:02:37 UTC (rev 194394)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2015 Andy VanWagoner <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// @conditional=ENABLE(INTL)
+
+function localeCompare(that/*, locales, options */)
+{
+    "use strict";
+
+    // 13.1.1 String.prototype.localeCompare (that [, locales [, options ]]) (ECMA-402 2.0)
+    // http://ecma-international.org/publications/standards/Ecma-402.htm
+
+    // 1. Let O be RequireObjectCoercible(this value).
+    if (this === null)
+        throw new @TypeError("String.prototype.localeCompare requires that |this| not be null");
+    
+    if (this === undefined)
+        throw new @TypeError("String.prototype.localeCompare requires that |this| not be undefined");
+
+    // 2. Let S be ToString(O).
+    // 3. ReturnIfAbrupt(S).
+    var thisString = @toString(this);
+
+    // 4. Let That be ToString(that).
+    // 5. ReturnIfAbrupt(That).
+    var thatString = @toString(that);
+
+    // Avoid creating a collator for defaults.
+    if (arguments[1] === undefined && arguments[2] === undefined)
+        return @Collator.prototype.compare(thisString, thatString);
+
+    // 6. Let collator be Construct(%Collator%, «locales, options»).
+    // 7. ReturnIfAbrupt(collator).
+    var collator = new @Collator(arguments[1], arguments[2]);
+
+    // 8. Return CompareStrings(collator, S, That).
+    return collator.compare(thisString, thatString);
+}

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (194393 => 194394)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2015-12-23 19:15:13 UTC (rev 194393)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2015-12-23 20:02:37 UTC (rev 194394)
@@ -29,6 +29,7 @@
 #include "Error.h"
 #include "Executable.h"
 #include "IntlObject.h"
+#include "JSCBuiltins.h"
 #include "JSCInlines.h"
 #include "JSGlobalObjectFunctions.h"
 #include "JSArray.h"
@@ -130,11 +131,12 @@
     JSC_NATIVE_FUNCTION("substring", stringProtoFuncSubstring, DontEnum, 2);
     JSC_NATIVE_FUNCTION("toLowerCase", stringProtoFuncToLowerCase, DontEnum, 0);
     JSC_NATIVE_FUNCTION("toUpperCase", stringProtoFuncToUpperCase, DontEnum, 0);
-    JSC_NATIVE_FUNCTION("localeCompare", stringProtoFuncLocaleCompare, DontEnum, 1);
 #if ENABLE(INTL)
+    JSC_BUILTIN_FUNCTION("localeCompare", stringPrototypeLocaleCompareCodeGenerator, DontEnum);
     JSC_NATIVE_FUNCTION("toLocaleLowerCase", stringProtoFuncToLocaleLowerCase, DontEnum, 0);
     JSC_NATIVE_FUNCTION("toLocaleUpperCase", stringProtoFuncToLocaleUpperCase, DontEnum, 0);
 #else
+    JSC_NATIVE_FUNCTION("localeCompare", stringProtoFuncLocaleCompare, DontEnum, 1);
     JSC_NATIVE_FUNCTION("toLocaleLowerCase", stringProtoFuncToLowerCase, DontEnum, 0);
     JSC_NATIVE_FUNCTION("toLocaleUpperCase", stringProtoFuncToUpperCase, DontEnum, 0);
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to