Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@8bbe7b2e82] [1.6>1.7] [MERGE #3323 @dil…
Browse files Browse the repository at this point in the history
…ijev] Fix #3203, Fix #3204: Intl.getCanonicalLocales: name, toString, cannot call with new

Merge pull request #3323 from dilijev:intl-gcl-fix

Fixes #3203
Fixes #3204
  • Loading branch information
chakrabot authored and kfarnung committed Jul 21, 2017
1 parent 3346716 commit 8dbdd50
Show file tree
Hide file tree
Showing 9 changed files with 16,386 additions and 15,849 deletions.
31 changes: 31 additions & 0 deletions deps/chakrashim/core/RegenAllByteCodeNoBuild.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
::-------------------------------------------------------------------------------------------------------
:: Copyright (C) Microsoft. All rights reserved.
:: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
::-------------------------------------------------------------------------------------------------------

:: WARNING: be careful when using this script as it assumes that
:: you already have bytecode-format-compatible builds for all required flavors.
:: This script helps speed things up when you are only making changes to scripts,
:: e.g. Intl.js, without making any changes to bytecode format, since rebuilding
:: every flavor of ChakraCore.dll when there are no relevant changes is a waste of time.
:: Please ensure that you use buddy builds to validate the results.

:: Regenerate all bytecode (without rebuilding each flavor of ch.exe)
:: ch.exe is used to generate Intl bytecodes.
:: ch.exe (NoJIT variety) is used to generate NoJIT Intl bytecodes.
:: Each set of bytecode requires an x86_debug and x64_debug binary.
::
:: Thus we need to already have compatible builds of the following:
:: [Core] ch.exe x64_debug
:: [Core] ch.exe x86_debug
:: [Core] ch.exe x64_debug (NoJIT)
:: [Core] ch.exe x86_debug (NoJIT)

@echo off
setlocal
set _reporoot=%~dp0
pushd %_reporoot%\lib\Runtime\Library\InJavascript
call GenByteCode.cmd
call GenByteCode.cmd -nojit
popd
endlocal
45 changes: 34 additions & 11 deletions deps/chakrashim/core/lib/Runtime/Library/InJavascript/Intl.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,26 @@
}

var hiddenObj = platform.getHiddenObject(that);
if (hiddenObj === undefined || hiddenObj.isValid !== "Valid") {
if (!hiddenObj || hiddenObj.isValid !== "Valid") {
platform.raiseNotAConstructor(functionName);
}

return supportedLocalesOf(locales, options);
}

var canonicalizeLocaleListWrapper = function (that, functionName, locales) {
if (that === null || that === undefined) {
platform.raiseNotAConstructor(functionName);
}

var hiddenObj = platform.getHiddenObject(that);
if (!hiddenObj || hiddenObj.isValid !== "Valid") {
platform.raiseNotAConstructor(functionName);
}

return CanonicalizeLocaleList(locales);
}

// Shared among all the constructors
var supportedLocalesOf = function (locales, options) {
var matcher;
Expand All @@ -401,36 +414,46 @@
}
};

const supportedLocalesOfThisArg = setPrototype({}, null);
platform.setHiddenObject(supportedLocalesOfThisArg, setPrototype({ isValid: "Valid" }, null));
const intlStaticMethodThisArg = setPrototype({}, null);
platform.setHiddenObject(intlStaticMethodThisArg, setPrototype({ isValid: "Valid" }, null));

// We wrap these functions so that we can define the correct name for this function for each Intl constructor,
// which allows us to display the correct error message for each Intl type.
const collator_supportedLocalesOf_name = "Intl.Collator.supportedLocalesOf";
const collator_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(collator_supportedLocalesOf_name, function (locales) {
const collator_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(collator_supportedLocalesOf_name,
function collator_supportedLocalesOf_dummyName(locales) {
const options = arguments.length < 2 ? undefined : arguments[1];
return supportedLocalesOfWrapper(this, collator_supportedLocalesOf_name, locales, options);
}), supportedLocalesOfThisArg);
}), intlStaticMethodThisArg);

const numberFormat_supportedLocalesOf_name = "Intl.NumberFormat.supportedLocalesOf";
const numberFormat_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(numberFormat_supportedLocalesOf_name, function (locales) {
const numberFormat_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(numberFormat_supportedLocalesOf_name,
function numberFormat_supportedLocalesOf_dummyName(locales) {
const options = arguments.length < 2 ? undefined : arguments[1];
return supportedLocalesOfWrapper(this, numberFormat_supportedLocalesOf_name, locales, options);
}), supportedLocalesOfThisArg);
}), intlStaticMethodThisArg);

const dateTimeFormat_supportedLocalesOf_name = "Intl.DateTimeFormat.supportedLocalesOf";
const dateTimeFormat_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(dateTimeFormat_supportedLocalesOf_name, function (locales) {
const dateTimeFormat_supportedLocalesOf = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(dateTimeFormat_supportedLocalesOf_name,
function dateTimeFormat_supportedLocalesOf_dummyName(locales) {
const options = arguments.length < 2 ? undefined : arguments[1];
return supportedLocalesOfWrapper(this, dateTimeFormat_supportedLocalesOf_name, locales, options);
}), supportedLocalesOfThisArg);
}), intlStaticMethodThisArg);

const getCanonicalLocales_name = "Intl.getCanonicalLocales";
const getCanonicalLocales = callInstanceFunc(FunctionInstanceBind, tagPublicFunction(getCanonicalLocales_name,
function getCanonicalLocales_dummyName(locales) {
return canonicalizeLocaleListWrapper(this, getCanonicalLocales_name, locales);
}), intlStaticMethodThisArg);

// TODO: Bound functions get the "bound" prefix by default, so we need to remove it.
// When https://github.com/Microsoft/ChakraCore/issues/637 is fixed and we have a way
// to make built-in functions non-constructible, we can remove the call to
// Function.prototype.bind and just rely on tagging instead of setting the "name" manually.
// Function.prototype.bind (i.e. FunctionInstanceBind) and just rely on tagging instead of setting the "name" manually.
ObjectDefineProperty(collator_supportedLocalesOf, 'name', { value: 'supportedLocalesOf' });
ObjectDefineProperty(numberFormat_supportedLocalesOf, 'name', { value: 'supportedLocalesOf' });
ObjectDefineProperty(dateTimeFormat_supportedLocalesOf, 'name', { value: 'supportedLocalesOf' });
ObjectDefineProperty(getCanonicalLocales, 'name', { value: 'getCanonicalLocales' });

// If an empty string is encountered for the value of the property; that means that is by default.
// So in the case of zh-TW; "default" and "stroke" are the same.
Expand Down Expand Up @@ -1467,6 +1490,6 @@
ObjectDefineProperty(Intl, "Collator", { value: Collator, writable: true, enumerable: false, configurable: true });
ObjectDefineProperty(Intl, "NumberFormat", { value: NumberFormat, writable: true, enumerable: false, configurable: true });
ObjectDefineProperty(Intl, "DateTimeFormat", { value: DateTimeFormat, writable: true, enumerable: false, configurable: true });
ObjectDefineProperty(Intl, "getCanonicalLocales", { value: CanonicalizeLocaleList, writeable: true, enumerable: false, configurable: true });
ObjectDefineProperty(Intl, "getCanonicalLocales", { value: getCanonicalLocales, writable: true, enumerable: false, configurable: true });
}
});
Loading

0 comments on commit 8dbdd50

Please sign in to comment.