Changeset 287560 in webkit
- Timestamp:
- Jan 3, 2022 9:12:15 PM (7 months ago)
- Location:
- trunk
- Files:
-
- 4 added
- 6 edited
-
JSTests/ChakraCore/test/Array/toLocaleString.baseline-jsc (modified) (2 diffs)
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/stress/array-tolocalestring-delete-tolocalestring.js (added)
-
JSTests/stress/array-tolocalestring-empty-separator.js (added)
-
JSTests/stress/array-tolocalestring-options.js (added)
-
JSTests/stress/array-tolocalestring-undefined-null.js (added)
-
LayoutTests/js/dom/script-tests/toString-overrides.js (modified) (1 diff)
-
LayoutTests/js/dom/toString-overrides-expected.txt (modified) (1 diff)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/runtime/ArrayPrototype.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChakraCore/test/Array/toLocaleString.baseline-jsc
r205387 r287560 19 19 20 20 3. Array: element toLocaleString not callable 21 0,[object Object] 21 TypeError : toLocaleString is not callable 22 22 23 23 … … 31 31 32 32 6. Object: element toLocaleString not callable 33 0,[object Object] 33 TypeError : toLocaleString is not callable 34 34 35 35 -
trunk/JSTests/ChangeLog
r287546 r287560 1 2022-01-03 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Array.prototype.toLocaleString does not respect deletion of Object.prototype.toLocaleString 4 https://bugs.webkit.org/show_bug.cgi?id=232723 5 6 Reviewed by Alexey Shvayka. 7 8 * ChakraCore/test/Array/toLocaleString.baseline-jsc: 9 * stress/array-tolocalestring-delete-tolocalestring.js: Added. 10 (shouldThrow): 11 * stress/array-tolocalestring-empty-separator.js: Added. 12 (shouldBe): 13 * stress/array-tolocalestring-options.js: Added. 14 (shouldBe): 15 * stress/array-tolocalestring-undefined-null.js: Added. 16 (shouldBe): 17 (shouldBe.toLocaleString): 18 1 19 2022-01-03 Yusuke Suzuki <ysuzuki@apple.com> 2 20 -
trunk/LayoutTests/js/dom/script-tests/toString-overrides.js
r156066 r287560 22 22 shouldBe("[1].toLocaleString()", "'toLocaleString'"); 23 23 Number.prototype.toLocaleString = "invalid"; 24 should Be("[1].toLocaleString()", "'1'");24 shouldThrow("[1].toLocaleString()"); 25 25 shouldBe("[/r/].toString()", "'toString2'"); 26 26 shouldBe("[/r/].toLocaleString()", "'toLocaleString2'"); 27 27 RegExp.prototype.toLocaleString = "invalid"; 28 should Be("[/r/].toLocaleString()", "'toString2'");28 shouldThrow("[/r/].toLocaleString()", "'toString2'"); 29 29 30 30 var caught = false; -
trunk/LayoutTests/js/dom/toString-overrides-expected.txt
r156066 r287560 6 6 PASS [1].toString() is '1' 7 7 PASS [1].toLocaleString() is 'toLocaleString' 8 PASS [1].toLocaleString() is '1'8 PASS [1].toLocaleString() threw exception TypeError: toLocaleString is not callable. 9 9 PASS [/r/].toString() is 'toString2' 10 10 PASS [/r/].toLocaleString() is 'toLocaleString2' 11 PASS [/r/].toLocaleString() is 'toString2' 11 FAIL [/r/].toLocaleString() should throw toString2. Threw exception TypeError: toLocaleString is not callable. 12 12 PASS caught is true 13 13 PASS successfullyParsed is true -
trunk/Source/JavaScriptCore/ChangeLog
r287546 r287560 1 2022-01-03 Yusuke Suzuki <ysuzuki@apple.com> 2 3 Array.prototype.toLocaleString does not respect deletion of Object.prototype.toLocaleString 4 https://bugs.webkit.org/show_bug.cgi?id=232723 5 6 Reviewed by Alexey Shvayka. 7 8 This patch implements ECMA402 Array.prototype.toLocaleString[1]. The new implementation invokes "toLocaleString" 9 method for each elements. 10 11 [1]: https://tc39.es/ecma402/#sup-array.prototype.tolocalestring 12 13 * runtime/ArrayPrototype.cpp: 14 (JSC::toLocaleString): 15 (JSC::JSC_DEFINE_HOST_FUNCTION): 16 (JSC::slowJoin): 17 1 18 2022-01-03 Yusuke Suzuki <ysuzuki@apple.com> 2 19 -
trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp
r287136 r287560 677 677 } 678 678 679 static JSString* toLocaleString(JSGlobalObject* globalObject, JSValue value, JSValue locales, JSValue options) 680 { 681 VM& vm = globalObject->vm(); 682 auto scope = DECLARE_THROW_SCOPE(vm); 683 684 JSValue toLocaleStringMethod = value.get(globalObject, vm.propertyNames->toLocaleString); 685 RETURN_IF_EXCEPTION(scope, { }); 686 687 auto callData = getCallData(vm, toLocaleStringMethod); 688 if (callData.type == CallData::Type::None) { 689 throwTypeError(globalObject, scope, "toLocaleString is not callable"_s); 690 return { }; 691 } 692 693 MarkedArgumentBufferWithSize<2> arguments; 694 arguments.append(locales); 695 arguments.append(options); 696 ASSERT(!arguments.hasOverflowed()); 697 698 JSValue result = call(globalObject, toLocaleStringMethod, callData, value, arguments); 699 RETURN_IF_EXCEPTION(scope, { }); 700 701 RELEASE_AND_RETURN(scope, result.toString(globalObject)); 702 } 703 704 // https://tc39.es/ecma402/#sup-array.prototype.tolocalestring 679 705 JSC_DEFINE_HOST_FUNCTION(arrayProtoFuncToLocaleString, (JSGlobalObject* globalObject, CallFrame* callFrame)) 680 706 { … … 683 709 JSValue thisValue = callFrame->thisValue().toThis(globalObject, ECMAMode::strict()); 684 710 711 JSValue locales = callFrame->argument(0); 712 JSValue options = callFrame->argument(1); 713 714 // 1. Let array be ? ToObject(this value). 685 715 JSObject* thisObject = thisValue.toObject(globalObject); 686 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 687 uint64_t length = static_cast<uint64_t>(toLength(globalObject, thisObject)); 688 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 689 if (length > std::numeric_limits<unsigned>::max()) { 690 throwOutOfMemoryError(globalObject, scope); 691 return encodedJSValue(); 692 } 716 RETURN_IF_EXCEPTION(scope, { }); 693 717 694 718 StringRecursionChecker checker(globalObject, thisObject); … … 697 721 return JSValue::encode(earlyReturnValue); 698 722 699 JSStringJoiner stringJoiner(globalObject, ',', static_cast<uint32_t>(length)); 700 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 701 702 ArgList arguments(callFrame); 703 for (unsigned i = 0; i < length; ++i) { 704 JSValue element = thisObject->getIndex(globalObject, i); 705 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 723 // 2. Let len be ? ToLength(? Get(array, "length")). 724 uint64_t length = static_cast<uint64_t>(toLength(globalObject, thisObject)); 725 RETURN_IF_EXCEPTION(scope, { }); 726 727 // 3. Let separator be the String value for the list-separator String appropriate for 728 // the host environment's current locale (this is derived in an implementation-defined way). 729 const LChar comma = ','; 730 JSString* separator = jsSingleCharacterString(vm, comma); 731 732 // 4. Let R be the empty String. 733 if (!length) 734 return JSValue::encode(jsEmptyString(vm)); 735 736 // 5. Let k be 0. 737 JSValue element0 = thisObject->getIndex(globalObject, 0); 738 RETURN_IF_EXCEPTION(scope, { }); 739 740 // 6. Repeat, while k < len, 741 // 6.a. If k > 0, then 742 // 6.a.i. Set R to the string-concatenation of R and separator. 743 744 JSString* r = nullptr; 745 if (element0.isUndefinedOrNull()) 746 r = jsEmptyString(vm); 747 else { 748 r = toLocaleString(globalObject, element0, locales, options); 749 RETURN_IF_EXCEPTION(scope, { }); 750 } 751 752 // 8. Let k be 1. 753 // 9. Repeat, while k < len 754 // 9.e Increase k by 1.. 755 for (uint64_t k = 1; k < length; ++k) { 756 // 6.b. Let nextElement be ? Get(array, ! ToString(k)). 757 JSValue element = thisObject->getIndex(globalObject, k); 758 RETURN_IF_EXCEPTION(scope, { }); 759 760 // c. If nextElement is not undefined or null, then 761 JSString* next = nullptr; 706 762 if (element.isUndefinedOrNull()) 707 element = jsEmptyString(vm);763 next = jsEmptyString(vm); 708 764 else { 709 JSValue conversionFunction = element.get(globalObject, vm.propertyNames->toLocaleString);710 RETURN_IF_EXCEPTION(scope, encodedJSValue());711 auto callData = getCallData(vm, conversionFunction);712 if (callData.type != CallData::Type::None) {713 element = call(globalObject, conversionFunction, callData, element, arguments);714 RETURN_IF_EXCEPTION(scope, encodedJSValue()); 715 }716 }717 stringJoiner.append(globalObject, element);718 RETURN_IF_EXCEPTION(scope, encodedJSValue());719 } 720 721 RELEASE_AND_RETURN(scope, JSValue::encode(stringJoiner.join(globalObject)));765 // i. Let S be ? ToString(? Invoke(nextElement, "toLocaleString", « locales, options »)). 766 // ii. Set R to the string-concatenation of R and S. 767 next = toLocaleString(globalObject, element, locales, options); 768 RETURN_IF_EXCEPTION(scope, { }); 769 } 770 771 // d. Increase k by 1. 772 r = jsString(globalObject, r, separator, next); 773 RETURN_IF_EXCEPTION(scope, { }); 774 } 775 776 // 7. Return R. 777 return JSValue::encode(r); 722 778 } 723 779 … … 748 804 for (uint64_t k = 1; k < length; ++k) { 749 805 // b. Let element be ? Get(O, ! ToString(k)). 750 JSValue element = thisObject->get (globalObject, Identifier::fromString(vm, AtomString::number(k)));806 JSValue element = thisObject->getIndex(globalObject, k); 751 807 RETURN_IF_EXCEPTION(scope, { }); 752 808
Note: See TracChangeset
for help on using the changeset viewer.