Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: src/builtins/builtins-string.cc

Issue 2335553002: Revert of [builtins] Move StringNormalize to a cpp builtin. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins/builtins.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 assembler->Return(assembler->NaNConstant()); 470 assembler->Return(assembler->NaNConstant());
471 assembler->Bind(&if_positioninbounds); 471 assembler->Bind(&if_positioninbounds);
472 } 472 }
473 473
474 // Load the character at the {position} from the {receiver}. 474 // Load the character at the {position} from the {receiver}.
475 Node* value = assembler->StringCharCodeAt(receiver, position); 475 Node* value = assembler->StringCharCodeAt(receiver, position);
476 Node* result = assembler->SmiFromWord32(value); 476 Node* result = assembler->SmiFromWord32(value);
477 assembler->Return(result); 477 assembler->Return(result);
478 } 478 }
479 479
480 // ES6 section 21.1.3.12 String.prototype.normalize ( [form] )
481 //
482 // Simply checks the argument is valid and returns the string itself.
483 // If internationalization is enabled, then i18n.js will override this function
484 // and provide the proper functionality, so this is just a fallback.
485 BUILTIN(StringPrototypeNormalize) {
486 HandleScope handle_scope(isolate);
487 TO_THIS_STRING(string, "String.prototype.normalize");
488
489 Handle<Object> form_input = args.atOrUndefined(isolate, 1);
490 if (form_input->IsUndefined(isolate)) return *string;
491
492 Handle<String> form;
493 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, form,
494 Object::ToString(isolate, form));
495
496 if (!(String::Equals(form,
497 isolate->factory()->NewStringFromStaticChars("NFC")) ||
498 String::Equals(form,
499 isolate->factory()->NewStringFromStaticChars("NFD")) ||
500 String::Equals(form,
501 isolate->factory()->NewStringFromStaticChars("NFKC")) ||
502 String::Equals(form,
503 isolate->factory()->NewStringFromStaticChars("NFKD")))) {
504 Handle<String> valid_forms =
505 isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD");
506 THROW_NEW_ERROR_RETURN_FAILURE(
507 isolate,
508 NewRangeError(MessageTemplate::kNormalizationForm, valid_forms));
509 }
510
511 return *string;
512 }
513
514 // ES6 section 21.1.3.25 String.prototype.toString () 480 // ES6 section 21.1.3.25 String.prototype.toString ()
515 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { 481 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
516 typedef compiler::Node Node; 482 typedef compiler::Node Node;
517 483
518 Node* receiver = assembler->Parameter(0); 484 Node* receiver = assembler->Parameter(0);
519 Node* context = assembler->Parameter(3); 485 Node* context = assembler->Parameter(3);
520 486
521 Node* result = assembler->ToThisValue( 487 Node* result = assembler->ToThisValue(
522 context, receiver, PrimitiveType::kString, "String.prototype.toString"); 488 context, receiver, PrimitiveType::kString, "String.prototype.toString");
523 assembler->Return(result); 489 assembler->Return(result);
(...skipping 27 matching lines...) Expand all
551 Node* receiver = assembler->Parameter(0); 517 Node* receiver = assembler->Parameter(0);
552 Node* context = assembler->Parameter(3); 518 Node* context = assembler->Parameter(3);
553 519
554 Node* result = assembler->ToThisValue( 520 Node* result = assembler->ToThisValue(
555 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); 521 context, receiver, PrimitiveType::kString, "String.prototype.valueOf");
556 assembler->Return(result); 522 assembler->Return(result);
557 } 523 }
558 524
559 } // namespace internal 525 } // namespace internal
560 } // namespace v8 526 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins.h ('k') | src/js/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698