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

Side by Side Diff: src/factory.cc

Issue 16549002: Add type field to AST expression nodes (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/jsregexp.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 669
670 Handle<JSObject> Factory::NewNeanderObject() { 670 Handle<JSObject> Factory::NewNeanderObject() {
671 CALL_HEAP_FUNCTION( 671 CALL_HEAP_FUNCTION(
672 isolate(), 672 isolate(),
673 isolate()->heap()->AllocateJSObjectFromMap( 673 isolate()->heap()->AllocateJSObjectFromMap(
674 isolate()->heap()->neander_map()), 674 isolate()->heap()->neander_map()),
675 JSObject); 675 JSObject);
676 } 676 }
677 677
678 678
679 Handle<Object> Factory::NewTypeError(const char* type, 679 Handle<Object> Factory::NewTypeError(const char* message,
680 Vector< Handle<Object> > args) { 680 Vector< Handle<Object> > args) {
681 return NewError("MakeTypeError", type, args); 681 return NewError("MakeTypeError", message, args);
682 } 682 }
683 683
684 684
685 Handle<Object> Factory::NewTypeError(Handle<String> message) { 685 Handle<Object> Factory::NewTypeError(Handle<String> message) {
686 return NewError("$TypeError", message); 686 return NewError("$TypeError", message);
687 } 687 }
688 688
689 689
690 Handle<Object> Factory::NewRangeError(const char* type, 690 Handle<Object> Factory::NewRangeError(const char* message,
691 Vector< Handle<Object> > args) { 691 Vector< Handle<Object> > args) {
692 return NewError("MakeRangeError", type, args); 692 return NewError("MakeRangeError", message, args);
693 } 693 }
694 694
695 695
696 Handle<Object> Factory::NewRangeError(Handle<String> message) { 696 Handle<Object> Factory::NewRangeError(Handle<String> message) {
697 return NewError("$RangeError", message); 697 return NewError("$RangeError", message);
698 } 698 }
699 699
700 700
701 Handle<Object> Factory::NewSyntaxError(const char* type, Handle<JSArray> args) { 701 Handle<Object> Factory::NewSyntaxError(const char* message,
702 return NewError("MakeSyntaxError", type, args); 702 Handle<JSArray> args) {
703 return NewError("MakeSyntaxError", message, args);
703 } 704 }
704 705
705 706
706 Handle<Object> Factory::NewSyntaxError(Handle<String> message) { 707 Handle<Object> Factory::NewSyntaxError(Handle<String> message) {
707 return NewError("$SyntaxError", message); 708 return NewError("$SyntaxError", message);
708 } 709 }
709 710
710 711
711 Handle<Object> Factory::NewReferenceError(const char* type, 712 Handle<Object> Factory::NewReferenceError(const char* message,
712 Vector< Handle<Object> > args) { 713 Vector< Handle<Object> > args) {
713 return NewError("MakeReferenceError", type, args); 714 return NewError("MakeReferenceError", message, args);
714 } 715 }
715 716
716 717
717 Handle<Object> Factory::NewReferenceError(Handle<String> message) { 718 Handle<Object> Factory::NewReferenceError(Handle<String> message) {
718 return NewError("$ReferenceError", message); 719 return NewError("$ReferenceError", message);
719 } 720 }
720 721
721 722
722 Handle<Object> Factory::NewError(const char* maker, 723 Handle<Object> Factory::NewError(const char* maker,
723 const char* type, 724 const char* message,
724 Vector< Handle<Object> > args) { 725 Vector< Handle<Object> > args) {
725 // Instantiate a closeable HandleScope for EscapeFrom. 726 // Instantiate a closeable HandleScope for EscapeFrom.
726 v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate())); 727 v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate()));
727 Handle<FixedArray> array = NewFixedArray(args.length()); 728 Handle<FixedArray> array = NewFixedArray(args.length());
728 for (int i = 0; i < args.length(); i++) { 729 for (int i = 0; i < args.length(); i++) {
729 array->set(i, *args[i]); 730 array->set(i, *args[i]);
730 } 731 }
731 Handle<JSArray> object = NewJSArrayWithElements(array); 732 Handle<JSArray> object = NewJSArrayWithElements(array);
732 Handle<Object> result = NewError(maker, type, object); 733 Handle<Object> result = NewError(maker, message, object);
733 return result.EscapeFrom(&scope); 734 return result.EscapeFrom(&scope);
734 } 735 }
735 736
736 737
737 Handle<Object> Factory::NewEvalError(const char* type, 738 Handle<Object> Factory::NewEvalError(const char* message,
738 Vector< Handle<Object> > args) { 739 Vector< Handle<Object> > args) {
739 return NewError("MakeEvalError", type, args); 740 return NewError("MakeEvalError", message, args);
740 } 741 }
741 742
742 743
743 Handle<Object> Factory::NewError(const char* type, 744 Handle<Object> Factory::NewError(const char* message,
744 Vector< Handle<Object> > args) { 745 Vector< Handle<Object> > args) {
745 return NewError("MakeError", type, args); 746 return NewError("MakeError", message, args);
746 } 747 }
747 748
748 749
749 Handle<String> Factory::EmergencyNewError(const char* type, 750 Handle<String> Factory::EmergencyNewError(const char* message,
750 Handle<JSArray> args) { 751 Handle<JSArray> args) {
751 const int kBufferSize = 1000; 752 const int kBufferSize = 1000;
752 char buffer[kBufferSize]; 753 char buffer[kBufferSize];
753 size_t space = kBufferSize; 754 size_t space = kBufferSize;
754 char* p = &buffer[0]; 755 char* p = &buffer[0];
755 756
756 Vector<char> v(buffer, kBufferSize); 757 Vector<char> v(buffer, kBufferSize);
757 OS::StrNCpy(v, type, space); 758 OS::StrNCpy(v, message, space);
758 space -= Min(space, strlen(type)); 759 space -= Min(space, strlen(message));
759 p = &buffer[kBufferSize] - space; 760 p = &buffer[kBufferSize] - space;
760 761
761 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { 762 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) {
762 if (space > 0) { 763 if (space > 0) {
763 *p++ = ' '; 764 *p++ = ' ';
764 space--; 765 space--;
765 if (space > 0) { 766 if (space > 0) {
766 MaybeObject* maybe_arg = args->GetElement(i); 767 MaybeObject* maybe_arg = args->GetElement(i);
767 Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg)); 768 Handle<String> arg_str(reinterpret_cast<String*>(maybe_arg));
768 const char* arg = *arg_str->ToCString(); 769 const char* arg = *arg_str->ToCString();
769 Vector<char> v2(p, static_cast<int>(space)); 770 Vector<char> v2(p, static_cast<int>(space));
770 OS::StrNCpy(v2, arg, space); 771 OS::StrNCpy(v2, arg, space);
771 space -= Min(space, strlen(arg)); 772 space -= Min(space, strlen(arg));
772 p = &buffer[kBufferSize] - space; 773 p = &buffer[kBufferSize] - space;
773 } 774 }
774 } 775 }
775 } 776 }
776 if (space > 0) { 777 if (space > 0) {
777 *p = '\0'; 778 *p = '\0';
778 } else { 779 } else {
779 buffer[kBufferSize - 1] = '\0'; 780 buffer[kBufferSize - 1] = '\0';
780 } 781 }
781 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED); 782 Handle<String> error_string = NewStringFromUtf8(CStrVector(buffer), TENURED);
782 return error_string; 783 return error_string;
783 } 784 }
784 785
785 786
786 Handle<Object> Factory::NewError(const char* maker, 787 Handle<Object> Factory::NewError(const char* maker,
787 const char* type, 788 const char* message,
788 Handle<JSArray> args) { 789 Handle<JSArray> args) {
789 Handle<String> make_str = InternalizeUtf8String(maker); 790 Handle<String> make_str = InternalizeUtf8String(maker);
790 Handle<Object> fun_obj( 791 Handle<Object> fun_obj(
791 isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str), 792 isolate()->js_builtins_object()->GetPropertyNoExceptionThrown(*make_str),
792 isolate()); 793 isolate());
793 // If the builtins haven't been properly configured yet this error 794 // If the builtins haven't been properly configured yet this error
794 // constructor may not have been defined. Bail out. 795 // constructor may not have been defined. Bail out.
795 if (!fun_obj->IsJSFunction()) { 796 if (!fun_obj->IsJSFunction()) {
796 return EmergencyNewError(type, args); 797 return EmergencyNewError(message, args);
797 } 798 }
798 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); 799 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
799 Handle<Object> type_obj = InternalizeUtf8String(type); 800 Handle<Object> message_obj = InternalizeUtf8String(message);
800 Handle<Object> argv[] = { type_obj, args }; 801 Handle<Object> argv[] = { message_obj, args };
801 802
802 // Invoke the JavaScript factory method. If an exception is thrown while 803 // Invoke the JavaScript factory method. If an exception is thrown while
803 // running the factory method, use the exception as the result. 804 // running the factory method, use the exception as the result.
804 bool caught_exception; 805 bool caught_exception;
805 Handle<Object> result = Execution::TryCall(fun, 806 Handle<Object> result = Execution::TryCall(fun,
806 isolate()->js_builtins_object(), 807 isolate()->js_builtins_object(),
807 ARRAY_SIZE(argv), 808 ARRAY_SIZE(argv),
808 argv, 809 argv,
809 &caught_exception); 810 &caught_exception);
810 return result; 811 return result;
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 return Handle<Object>::null(); 1556 return Handle<Object>::null();
1556 } 1557 }
1557 1558
1558 1559
1559 Handle<Object> Factory::ToBoolean(bool value) { 1560 Handle<Object> Factory::ToBoolean(bool value) {
1560 return value ? true_value() : false_value(); 1561 return value ? true_value() : false_value();
1561 } 1562 }
1562 1563
1563 1564
1564 } } // namespace v8::internal 1565 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/jsregexp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698