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

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

Issue 2315343002: [builtins] Move StringNormalize to a cpp builtin. (Closed)
Patch Set: take 2 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 // ECMA-262 v6, section 21.1.3.12 String.prototype.normalize ( [form] )
481 //
482 // For now we do nothing, as proper normalization requires big tables.
483 // If Intl is enabled, then i18n.js will override it and provide the the
484 // proper functionality.
485 BUILTIN(StringPrototypeNormalize) {
486 HandleScope handle_scope(isolate);
487 TO_THIS_STRING(string, "String.prototype.trim");
Franzi 2016/09/09 12:51:04 trim?
488
489 Handle<String> form;
490
491 if (args.atOrUndefined(isolate, 1)->IsUndefined(isolate)) {
492 return *string;
493 }
494 MaybeHandle<String> maybe_form(Object::ToString(isolate, args.at<Object>(1)));
Benedikt Meurer 2016/09/08 04:41:30 This is not correct, as the ToString can throw and
petermarshall 2016/09/09 11:41:07 Done.
495 maybe_form.ToHandle(&form);
496
497 if (!(form->Equals(*isolate->factory()->NewStringFromStaticChars("NFC")) ||
498 form->Equals(*isolate->factory()->NewStringFromStaticChars("NFD")) ||
499 form->Equals(*isolate->factory()->NewStringFromStaticChars("NFKC")) ||
500 form->Equals(*isolate->factory()->NewStringFromStaticChars("NFKD")))) {
501 Handle<String> validForms =
502 isolate->factory()->NewStringFromStaticChars("NFC, NFD, NFKC, NFKD");
503 THROW_NEW_ERROR_RETURN_FAILURE(
504 isolate,
505 NewRangeError(MessageTemplate::kNormalizationForm, validForms));
506 }
507
508 return *string;
509 }
510
480 // ES6 section 21.1.3.25 String.prototype.toString () 511 // ES6 section 21.1.3.25 String.prototype.toString ()
481 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) { 512 void Builtins::Generate_StringPrototypeToString(CodeStubAssembler* assembler) {
482 typedef compiler::Node Node; 513 typedef compiler::Node Node;
483 514
484 Node* receiver = assembler->Parameter(0); 515 Node* receiver = assembler->Parameter(0);
485 Node* context = assembler->Parameter(3); 516 Node* context = assembler->Parameter(3);
486 517
487 Node* result = assembler->ToThisValue( 518 Node* result = assembler->ToThisValue(
488 context, receiver, PrimitiveType::kString, "String.prototype.toString"); 519 context, receiver, PrimitiveType::kString, "String.prototype.toString");
489 assembler->Return(result); 520 assembler->Return(result);
(...skipping 27 matching lines...) Expand all
517 Node* receiver = assembler->Parameter(0); 548 Node* receiver = assembler->Parameter(0);
518 Node* context = assembler->Parameter(3); 549 Node* context = assembler->Parameter(3);
519 550
520 Node* result = assembler->ToThisValue( 551 Node* result = assembler->ToThisValue(
521 context, receiver, PrimitiveType::kString, "String.prototype.valueOf"); 552 context, receiver, PrimitiveType::kString, "String.prototype.valueOf");
522 assembler->Return(result); 553 assembler->Return(result);
523 } 554 }
524 555
525 } // namespace internal 556 } // namespace internal
526 } // namespace v8 557 } // 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