Commit ae71fbc3 authored by petermarshall's avatar petermarshall Committed by Commit bot

Revert of [builtins] Move StringNormalize to a cpp builtin. (patchset #10...

Revert of [builtins] Move StringNormalize to a cpp builtin. (patchset #10 id:180001 of https://codereview.chromium.org/2315343002/ )

Reason for revert:
Tests fail when i18n is switched off, trybots do not run this configuration

Original issue's description:
> [builtins] Move StringNormalize to a cpp builtin.
>
> BUG=v8:5364
>
> Committed: https://crrev.com/7f84a6a2e7000bebba49354b4648346ff606ca34
> Cr-Commit-Position: refs/heads/master@{#39331}

TBR=bmeurer@chromium.org,franzih@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5364

Review-Url: https://codereview.chromium.org/2335553002
Cr-Commit-Position: refs/heads/master@{#39332}
parent 7f84a6a2
......@@ -1395,8 +1395,6 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
1, true);
SimpleInstallFunction(prototype, "charCodeAt",
Builtins::kStringPrototypeCharCodeAt, 1, true);
SimpleInstallFunction(prototype, "normalize",
Builtins::kStringPrototypeNormalize, 0, false);
SimpleInstallFunction(prototype, "toString",
Builtins::kStringPrototypeToString, 0, true);
SimpleInstallFunction(prototype, "trim", Builtins::kStringPrototypeTrim, 0,
......
......@@ -477,40 +477,6 @@ void Builtins::Generate_StringPrototypeCharCodeAt(
assembler->Return(result);
}
// ES6 section 21.1.3.12 String.prototype.normalize ( [form] )
//
// Simply checks the argument is valid and returns the string itself.
// If internationalization is enabled, then i18n.js will override this function
// and provide the proper functionality, so this is just a fallback.
BUILTIN(StringPrototypeNormalize) {
HandleScope handle_scope(isolate);
TO_THIS_STRING(string, "String.prototype.normalize");
Handle<Object> form_input = args.atOrUndefined(isolate, 1);
if (form_input->IsUndefined(isolate)) return *string;
Handle<String> form;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, form,
Object::ToString(isolate, form));
if (!(String::Equals(form,
isolate->factory()->NewStringFromStaticChars("NFC")) ||
String::Equals(form,
isolate->factory()->NewStringFromStaticChars("NFD")) ||
String::Equals(form,
isolate->factory()->NewStringFromStaticChars("NFKC")) ||
String::Equals(form,
isolate->factory()->NewStringFromStaticChars("NFKD")))) {
Handle<String> valid_forms =
isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD");
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewRangeError(MessageTemplate::kNormalizationForm, valid_forms));
}
return *string;
}
// ES6 section 21.1.3.25 String.prototype.toString ()
void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
typedef compiler::Node Node;
......
......@@ -535,8 +535,6 @@ namespace internal {
TFJ(StringPrototypeCharAt, 2) \
/* ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) */ \
TFJ(StringPrototypeCharCodeAt, 2) \
/* ES6 section 21.1.3.12 String.prototype.normalize ( [form] ) */ \
CPP(StringPrototypeNormalize) \
/* ES6 section 21.1.3.25 String.prototype.toString () */ \
TFJ(StringPrototypeToString, 1) \
CPP(StringPrototypeTrim) \
......
......@@ -118,6 +118,30 @@ function StringMatchJS(pattern) {
}
// ECMA-262 v6, section 21.1.3.12
//
// For now we do nothing, as proper normalization requires big tables.
// If Intl is enabled, then i18n.js will override it and provide the the
// proper functionality.
function StringNormalize(formArg) { // length == 0
CHECK_OBJECT_COERCIBLE(this, "String.prototype.normalize");
var s = TO_STRING(this);
var form = IS_UNDEFINED(formArg) ? 'NFC' : TO_STRING(formArg);
var NORMALIZATION_FORMS = ['NFC', 'NFD', 'NFKC', 'NFKD'];
var normalizationForm = %ArrayIndexOf(NORMALIZATION_FORMS, form, 0);
if (normalizationForm === -1) {
throw %make_range_error(kNormalizationForm,
%_Call(ArrayJoin, NORMALIZATION_FORMS, ', '));
}
return s;
}
%FunctionSetLength(StringNormalize, 0);
// This has the same size as the RegExpLastMatchInfo array, and can be used
// for functions that expect that structure to be returned. It is used when
// the needle is a string rather than a regexp. In this case we can't update
......@@ -716,6 +740,7 @@ utils.InstallFunctions(GlobalString.prototype, DONT_ENUM, [
"lastIndexOf", StringLastIndexOf,
"localeCompare", StringLocaleCompareJS,
"match", StringMatchJS,
"normalize", StringNormalize,
"repeat", StringRepeat,
"replace", StringReplace,
"search", StringSearch,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment