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

Side by Side Diff: src/factory.cc

Issue 516913003: Do not expose termination exceptions to the Exception API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: address comment Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/ic/ic.cc » ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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/factory.h" 5 #include "src/factory.h"
6 6
7 #include "src/allocation-site-scopes.h" 7 #include "src/allocation-site-scopes.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/isolate-inl.h" 9 #include "src/isolate-inl.h"
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE: 359 case SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE:
360 return short_external_internalized_string_with_one_byte_data_map(); 360 return short_external_internalized_string_with_one_byte_data_map();
361 default: return MaybeHandle<Map>(); // No match found. 361 default: return MaybeHandle<Map>(); // No match found.
362 } 362 }
363 } 363 }
364 364
365 365
366 MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString( 366 MaybeHandle<SeqOneByteString> Factory::NewRawOneByteString(
367 int length, PretenureFlag pretenure) { 367 int length, PretenureFlag pretenure) {
368 if (length > String::kMaxLength || length < 0) { 368 if (length > String::kMaxLength || length < 0) {
369 return isolate()->Throw<SeqOneByteString>(NewInvalidStringLengthError()); 369 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqOneByteString);
370 } 370 }
371 CALL_HEAP_FUNCTION( 371 CALL_HEAP_FUNCTION(
372 isolate(), 372 isolate(),
373 isolate()->heap()->AllocateRawOneByteString(length, pretenure), 373 isolate()->heap()->AllocateRawOneByteString(length, pretenure),
374 SeqOneByteString); 374 SeqOneByteString);
375 } 375 }
376 376
377 377
378 MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString( 378 MaybeHandle<SeqTwoByteString> Factory::NewRawTwoByteString(
379 int length, PretenureFlag pretenure) { 379 int length, PretenureFlag pretenure) {
380 if (length > String::kMaxLength || length < 0) { 380 if (length > String::kMaxLength || length < 0) {
381 return isolate()->Throw<SeqTwoByteString>(NewInvalidStringLengthError()); 381 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), SeqTwoByteString);
382 } 382 }
383 CALL_HEAP_FUNCTION( 383 CALL_HEAP_FUNCTION(
384 isolate(), 384 isolate(),
385 isolate()->heap()->AllocateRawTwoByteString(length, pretenure), 385 isolate()->heap()->AllocateRawTwoByteString(length, pretenure),
386 SeqTwoByteString); 386 SeqTwoByteString);
387 } 387 }
388 388
389 389
390 Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t code) { 390 Handle<String> Factory::LookupSingleCharacterStringFromCode(uint32_t code) {
391 if (code <= String::kMaxOneByteCharCodeU) { 391 if (code <= String::kMaxOneByteCharCodeU) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 476
477 if (length == 2) { 477 if (length == 2) {
478 uint16_t c1 = left->Get(0); 478 uint16_t c1 = left->Get(0);
479 uint16_t c2 = right->Get(0); 479 uint16_t c2 = right->Get(0);
480 return MakeOrFindTwoCharacterString(isolate(), c1, c2); 480 return MakeOrFindTwoCharacterString(isolate(), c1, c2);
481 } 481 }
482 482
483 // Make sure that an out of memory exception is thrown if the length 483 // Make sure that an out of memory exception is thrown if the length
484 // of the new cons string is too large. 484 // of the new cons string is too large.
485 if (length > String::kMaxLength || length < 0) { 485 if (length > String::kMaxLength || length < 0) {
486 return isolate()->Throw<String>(NewInvalidStringLengthError()); 486 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
487 } 487 }
488 488
489 bool left_is_one_byte = left->IsOneByteRepresentation(); 489 bool left_is_one_byte = left->IsOneByteRepresentation();
490 bool right_is_one_byte = right->IsOneByteRepresentation(); 490 bool right_is_one_byte = right->IsOneByteRepresentation();
491 bool is_one_byte = left_is_one_byte && right_is_one_byte; 491 bool is_one_byte = left_is_one_byte && right_is_one_byte;
492 bool is_one_byte_data_in_two_byte_string = false; 492 bool is_one_byte_data_in_two_byte_string = false;
493 if (!is_one_byte) { 493 if (!is_one_byte) {
494 // At least one of the strings uses two-byte representation so we 494 // At least one of the strings uses two-byte representation so we
495 // can't use the fast case code for short ASCII strings below, but 495 // can't use the fast case code for short ASCII strings below, but
496 // we can try to save memory if all chars actually fit in ASCII. 496 // we can try to save memory if all chars actually fit in ASCII.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 slice->set_parent(*str); 609 slice->set_parent(*str);
610 slice->set_offset(offset); 610 slice->set_offset(offset);
611 return slice; 611 return slice;
612 } 612 }
613 613
614 614
615 MaybeHandle<String> Factory::NewExternalStringFromAscii( 615 MaybeHandle<String> Factory::NewExternalStringFromAscii(
616 const ExternalAsciiString::Resource* resource) { 616 const ExternalAsciiString::Resource* resource) {
617 size_t length = resource->length(); 617 size_t length = resource->length();
618 if (length > static_cast<size_t>(String::kMaxLength)) { 618 if (length > static_cast<size_t>(String::kMaxLength)) {
619 return isolate()->Throw<String>(NewInvalidStringLengthError()); 619 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
620 } 620 }
621 621
622 Handle<Map> map = external_ascii_string_map(); 622 Handle<Map> map = external_ascii_string_map();
623 Handle<ExternalAsciiString> external_string = 623 Handle<ExternalAsciiString> external_string =
624 New<ExternalAsciiString>(map, NEW_SPACE); 624 New<ExternalAsciiString>(map, NEW_SPACE);
625 external_string->set_length(static_cast<int>(length)); 625 external_string->set_length(static_cast<int>(length));
626 external_string->set_hash_field(String::kEmptyHashField); 626 external_string->set_hash_field(String::kEmptyHashField);
627 external_string->set_resource(resource); 627 external_string->set_resource(resource);
628 628
629 return external_string; 629 return external_string;
630 } 630 }
631 631
632 632
633 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( 633 MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
634 const ExternalTwoByteString::Resource* resource) { 634 const ExternalTwoByteString::Resource* resource) {
635 size_t length = resource->length(); 635 size_t length = resource->length();
636 if (length > static_cast<size_t>(String::kMaxLength)) { 636 if (length > static_cast<size_t>(String::kMaxLength)) {
637 return isolate()->Throw<String>(NewInvalidStringLengthError()); 637 THROW_NEW_ERROR(isolate(), NewInvalidStringLengthError(), String);
638 } 638 }
639 639
640 // For small strings we check whether the resource contains only 640 // For small strings we check whether the resource contains only
641 // one byte characters. If yes, we use a different string map. 641 // one byte characters. If yes, we use a different string map.
642 static const size_t kOneByteCheckLengthLimit = 32; 642 static const size_t kOneByteCheckLengthLimit = 32;
643 bool is_one_byte = length <= kOneByteCheckLengthLimit && 643 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
644 String::IsOneByte(resource->data(), static_cast<int>(length)); 644 String::IsOneByte(resource->data(), static_cast<int>(length));
645 Handle<Map> map = is_one_byte ? 645 Handle<Map> map = is_one_byte ?
646 external_string_with_one_byte_data_map() : external_string_map(); 646 external_string_with_one_byte_data_map() : external_string_map();
647 Handle<ExternalTwoByteString> external_string = 647 Handle<ExternalTwoByteString> external_string =
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 Handle<HeapNumber> Factory::NewHeapNumber(double value, 1043 Handle<HeapNumber> Factory::NewHeapNumber(double value,
1044 MutableMode mode, 1044 MutableMode mode,
1045 PretenureFlag pretenure) { 1045 PretenureFlag pretenure) {
1046 CALL_HEAP_FUNCTION( 1046 CALL_HEAP_FUNCTION(
1047 isolate(), 1047 isolate(),
1048 isolate()->heap()->AllocateHeapNumber(value, mode, pretenure), 1048 isolate()->heap()->AllocateHeapNumber(value, mode, pretenure),
1049 HeapNumber); 1049 HeapNumber);
1050 } 1050 }
1051 1051
1052 1052
1053 Handle<Object> Factory::NewTypeError(const char* message, 1053 MaybeHandle<Object> Factory::NewTypeError(const char* message,
1054 Vector< Handle<Object> > args) { 1054 Vector<Handle<Object> > args) {
1055 return NewError("MakeTypeError", message, args); 1055 return NewError("MakeTypeError", message, args);
1056 } 1056 }
1057 1057
1058 1058
1059 Handle<Object> Factory::NewTypeError(Handle<String> message) { 1059 MaybeHandle<Object> Factory::NewTypeError(Handle<String> message) {
1060 return NewError("$TypeError", message); 1060 return NewError("$TypeError", message);
1061 } 1061 }
1062 1062
1063 1063
1064 Handle<Object> Factory::NewRangeError(const char* message, 1064 MaybeHandle<Object> Factory::NewRangeError(const char* message,
1065 Vector< Handle<Object> > args) { 1065 Vector<Handle<Object> > args) {
1066 return NewError("MakeRangeError", message, args); 1066 return NewError("MakeRangeError", message, args);
1067 } 1067 }
1068 1068
1069 1069
1070 Handle<Object> Factory::NewRangeError(Handle<String> message) { 1070 MaybeHandle<Object> Factory::NewRangeError(Handle<String> message) {
1071 return NewError("$RangeError", message); 1071 return NewError("$RangeError", message);
1072 } 1072 }
1073 1073
1074 1074
1075 Handle<Object> Factory::NewSyntaxError(const char* message, 1075 MaybeHandle<Object> Factory::NewSyntaxError(const char* message,
1076 Handle<JSArray> args) { 1076 Handle<JSArray> args) {
1077 return NewError("MakeSyntaxError", message, args); 1077 return NewError("MakeSyntaxError", message, args);
1078 } 1078 }
1079 1079
1080 1080
1081 Handle<Object> Factory::NewSyntaxError(Handle<String> message) { 1081 MaybeHandle<Object> Factory::NewSyntaxError(Handle<String> message) {
1082 return NewError("$SyntaxError", message); 1082 return NewError("$SyntaxError", message);
1083 } 1083 }
1084 1084
1085 1085
1086 Handle<Object> Factory::NewReferenceError(const char* message, 1086 MaybeHandle<Object> Factory::NewReferenceError(const char* message,
1087 Vector< Handle<Object> > args) { 1087 Vector<Handle<Object> > args) {
1088 return NewError("MakeReferenceError", message, args); 1088 return NewError("MakeReferenceError", message, args);
1089 } 1089 }
1090 1090
1091 1091
1092 Handle<Object> Factory::NewReferenceError(const char* message, 1092 MaybeHandle<Object> Factory::NewReferenceError(const char* message,
1093 Handle<JSArray> args) { 1093 Handle<JSArray> args) {
1094 return NewError("MakeReferenceError", message, args); 1094 return NewError("MakeReferenceError", message, args);
1095 } 1095 }
1096 1096
1097 1097
1098 Handle<Object> Factory::NewReferenceError(Handle<String> message) { 1098 MaybeHandle<Object> Factory::NewReferenceError(Handle<String> message) {
1099 return NewError("$ReferenceError", message); 1099 return NewError("$ReferenceError", message);
1100 } 1100 }
1101 1101
1102 1102
1103 Handle<Object> Factory::NewError(const char* maker, 1103 MaybeHandle<Object> Factory::NewError(const char* maker, const char* message,
1104 const char* message, 1104 Vector<Handle<Object> > args) {
1105 Vector< Handle<Object> > args) {
1106 // Instantiate a closeable HandleScope for EscapeFrom. 1105 // Instantiate a closeable HandleScope for EscapeFrom.
1107 v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate())); 1106 v8::EscapableHandleScope scope(reinterpret_cast<v8::Isolate*>(isolate()));
1108 Handle<FixedArray> array = NewFixedArray(args.length()); 1107 Handle<FixedArray> array = NewFixedArray(args.length());
1109 for (int i = 0; i < args.length(); i++) { 1108 for (int i = 0; i < args.length(); i++) {
1110 array->set(i, *args[i]); 1109 array->set(i, *args[i]);
1111 } 1110 }
1112 Handle<JSArray> object = NewJSArrayWithElements(array); 1111 Handle<JSArray> object = NewJSArrayWithElements(array);
1113 Handle<Object> result = NewError(maker, message, object); 1112 Handle<Object> result;
1113 ASSIGN_RETURN_ON_EXCEPTION(isolate(), result,
1114 NewError(maker, message, object), Object);
1114 return result.EscapeFrom(&scope); 1115 return result.EscapeFrom(&scope);
1115 } 1116 }
1116 1117
1117 1118
1118 Handle<Object> Factory::NewEvalError(const char* message, 1119 MaybeHandle<Object> Factory::NewEvalError(const char* message,
1119 Vector< Handle<Object> > args) { 1120 Vector<Handle<Object> > args) {
1120 return NewError("MakeEvalError", message, args); 1121 return NewError("MakeEvalError", message, args);
1121 } 1122 }
1122 1123
1123 1124
1124 Handle<Object> Factory::NewError(const char* message, 1125 MaybeHandle<Object> Factory::NewError(const char* message,
1125 Vector< Handle<Object> > args) { 1126 Vector<Handle<Object> > args) {
1126 return NewError("MakeError", message, args); 1127 return NewError("MakeError", message, args);
1127 } 1128 }
1128 1129
1129 1130
1130 Handle<String> Factory::EmergencyNewError(const char* message, 1131 Handle<String> Factory::EmergencyNewError(const char* message,
1131 Handle<JSArray> args) { 1132 Handle<JSArray> args) {
1132 const int kBufferSize = 1000; 1133 const int kBufferSize = 1000;
1133 char buffer[kBufferSize]; 1134 char buffer[kBufferSize];
1134 size_t space = kBufferSize; 1135 size_t space = kBufferSize;
1135 char* p = &buffer[0]; 1136 char* p = &buffer[0];
(...skipping 20 matching lines...) Expand all
1156 } 1157 }
1157 if (space > 0) { 1158 if (space > 0) {
1158 *p = '\0'; 1159 *p = '\0';
1159 } else { 1160 } else {
1160 buffer[kBufferSize - 1] = '\0'; 1161 buffer[kBufferSize - 1] = '\0';
1161 } 1162 }
1162 return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked(); 1163 return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
1163 } 1164 }
1164 1165
1165 1166
1166 Handle<Object> Factory::NewError(const char* maker, 1167 MaybeHandle<Object> Factory::NewError(const char* maker, const char* message,
1167 const char* message, 1168 Handle<JSArray> args) {
1168 Handle<JSArray> args) {
1169 Handle<String> make_str = InternalizeUtf8String(maker); 1169 Handle<String> make_str = InternalizeUtf8String(maker);
1170 Handle<Object> fun_obj = Object::GetProperty( 1170 Handle<Object> fun_obj = Object::GetProperty(
1171 isolate()->js_builtins_object(), make_str).ToHandleChecked(); 1171 isolate()->js_builtins_object(), make_str).ToHandleChecked();
1172 // If the builtins haven't been properly configured yet this error 1172 // If the builtins haven't been properly configured yet this error
1173 // constructor may not have been defined. Bail out. 1173 // constructor may not have been defined. Bail out.
1174 if (!fun_obj->IsJSFunction()) { 1174 if (!fun_obj->IsJSFunction()) {
1175 return EmergencyNewError(message, args); 1175 return EmergencyNewError(message, args);
1176 } 1176 }
1177 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); 1177 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
1178 Handle<Object> message_obj = InternalizeUtf8String(message); 1178 Handle<Object> message_obj = InternalizeUtf8String(message);
1179 Handle<Object> argv[] = { message_obj, args }; 1179 Handle<Object> argv[] = { message_obj, args };
1180 1180
1181 // Invoke the JavaScript factory method. If an exception is thrown while 1181 // Invoke the JavaScript factory method. If an exception is thrown while
1182 // running the factory method, use the exception as the result. 1182 // running the factory method, use the exception as the result.
1183 Handle<Object> result; 1183 Handle<Object> result;
1184 Handle<Object> exception; 1184 MaybeHandle<Object> exception;
1185 if (!Execution::TryCall(fun, 1185 if (!Execution::TryCall(fun,
1186 isolate()->js_builtins_object(), 1186 isolate()->js_builtins_object(),
1187 arraysize(argv), 1187 arraysize(argv),
1188 argv, 1188 argv,
1189 &exception).ToHandle(&result)) { 1189 &exception).ToHandle(&result)) {
1190 return exception; 1190 return exception;
1191 } 1191 }
1192 return result; 1192 return result;
1193 } 1193 }
1194 1194
1195 1195
1196 Handle<Object> Factory::NewError(Handle<String> message) { 1196 MaybeHandle<Object> Factory::NewError(Handle<String> message) {
1197 return NewError("$Error", message); 1197 return NewError("$Error", message);
1198 } 1198 }
1199 1199
1200 1200
1201 Handle<Object> Factory::NewError(const char* constructor, 1201 MaybeHandle<Object> Factory::NewError(const char* constructor,
1202 Handle<String> message) { 1202 Handle<String> message) {
1203 Handle<String> constr = InternalizeUtf8String(constructor); 1203 Handle<String> constr = InternalizeUtf8String(constructor);
1204 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( 1204 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty(
1205 isolate()->js_builtins_object(), constr).ToHandleChecked()); 1205 isolate()->js_builtins_object(), constr).ToHandleChecked());
1206 Handle<Object> argv[] = { message }; 1206 Handle<Object> argv[] = { message };
1207 1207
1208 // Invoke the JavaScript factory method. If an exception is thrown while 1208 // Invoke the JavaScript factory method. If an exception is thrown while
1209 // running the factory method, use the exception as the result. 1209 // running the factory method, use the exception as the result.
1210 Handle<Object> result; 1210 Handle<Object> result;
1211 Handle<Object> exception; 1211 MaybeHandle<Object> exception;
1212 if (!Execution::TryCall(fun, 1212 if (!Execution::TryCall(fun,
1213 isolate()->js_builtins_object(), 1213 isolate()->js_builtins_object(),
1214 arraysize(argv), 1214 arraysize(argv),
1215 argv, 1215 argv,
1216 &exception).ToHandle(&result)) { 1216 &exception).ToHandle(&result)) {
1217 return exception; 1217 return exception;
1218 } 1218 }
1219 return result; 1219 return result;
1220 } 1220 }
1221 1221
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 return Handle<Object>::null(); 2385 return Handle<Object>::null();
2386 } 2386 }
2387 2387
2388 2388
2389 Handle<Object> Factory::ToBoolean(bool value) { 2389 Handle<Object> Factory::ToBoolean(bool value) {
2390 return value ? true_value() : false_value(); 2390 return value ? true_value() : false_value();
2391 } 2391 }
2392 2392
2393 2393
2394 } } // namespace v8::internal 2394 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/ic/ic.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698