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

Side by Side Diff: src/factory.cc

Issue 1295093002: Do not use js builtins object when constructing an error. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix failures. Created 5 years, 4 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/factory.h ('k') | src/messages.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 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/base/bits.h" 8 #include "src/base/bits.h"
9 #include "src/bootstrapper.h" 9 #include "src/bootstrapper.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 } 1096 }
1097 1097
1098 1098
1099 Handle<Bool8x16> Factory::NewBool8x16(bool lanes[16], PretenureFlag pretenure) { 1099 Handle<Bool8x16> Factory::NewBool8x16(bool lanes[16], PretenureFlag pretenure) {
1100 CALL_HEAP_FUNCTION(isolate(), 1100 CALL_HEAP_FUNCTION(isolate(),
1101 isolate()->heap()->AllocateBool8x16(lanes, pretenure), 1101 isolate()->heap()->AllocateBool8x16(lanes, pretenure),
1102 Bool8x16); 1102 Bool8x16);
1103 } 1103 }
1104 1104
1105 1105
1106 Handle<Object> Factory::NewError(const char* maker, 1106 Handle<Object> Factory::NewError(Handle<JSFunction> constructor,
1107 MessageTemplate::Template template_index, 1107 MessageTemplate::Template template_index,
1108 Handle<Object> arg0, Handle<Object> arg1, 1108 Handle<Object> arg0, Handle<Object> arg1,
1109 Handle<Object> arg2) { 1109 Handle<Object> arg2) {
1110 HandleScope scope(isolate()); 1110 HandleScope scope(isolate());
1111 Handle<String> error_maker = InternalizeUtf8String(maker);
1112 if (isolate()->bootstrapper()->IsActive()) { 1111 if (isolate()->bootstrapper()->IsActive()) {
1113 // If this exception is being thrown during bootstrapping, 1112 // During bootstrapping we cannot construct error objects.
1114 // js_builtins_object is unavailable. We return the error maker 1113 return scope.CloseAndEscape(NewStringFromAsciiChecked(
1115 // name's string as the exception since we have nothing better 1114 MessageTemplate::TemplateString(template_index)));
1116 // to do.
1117 return scope.CloseAndEscape(error_maker);
1118 } 1115 }
1119 Handle<Object> fun_obj = Object::GetProperty(isolate()->js_builtins_object(),
1120 error_maker).ToHandleChecked();
1121 1116
1122 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); 1117 Handle<JSFunction> fun = isolate()->make_error_function();
1123 Handle<Object> message_type(Smi::FromInt(template_index), isolate()); 1118 Handle<Object> message_type(Smi::FromInt(template_index), isolate());
1124 if (arg0.is_null()) arg0 = undefined_value(); 1119 if (arg0.is_null()) arg0 = undefined_value();
1125 if (arg1.is_null()) arg1 = undefined_value(); 1120 if (arg1.is_null()) arg1 = undefined_value();
1126 if (arg2.is_null()) arg2 = undefined_value(); 1121 if (arg2.is_null()) arg2 = undefined_value();
1127 Handle<Object> argv[] = {message_type, arg0, arg1, arg2}; 1122 Handle<Object> argv[] = {constructor, message_type, arg0, arg1, arg2};
1128 1123
1129 // Invoke the JavaScript factory method. If an exception is thrown while 1124 // Invoke the JavaScript factory method. If an exception is thrown while
1130 // running the factory method, use the exception as the result. 1125 // running the factory method, use the exception as the result.
1131 Handle<Object> result; 1126 Handle<Object> result;
1132 MaybeHandle<Object> exception; 1127 MaybeHandle<Object> exception;
1133 if (!Execution::TryCall(fun, isolate()->js_builtins_object(), arraysize(argv), 1128 if (!Execution::TryCall(fun, undefined_value(), arraysize(argv), argv,
1134 argv, &exception).ToHandle(&result)) { 1129 &exception)
1130 .ToHandle(&result)) {
1135 Handle<Object> exception_obj; 1131 Handle<Object> exception_obj;
1136 if (exception.ToHandle(&exception_obj)) { 1132 if (exception.ToHandle(&exception_obj)) {
1137 result = exception_obj; 1133 result = exception_obj;
1138 } else { 1134 } else {
1139 result = undefined_value(); 1135 result = undefined_value();
1140 } 1136 }
1141 } 1137 }
1142 return scope.CloseAndEscape(result); 1138 return scope.CloseAndEscape(result);
1143 } 1139 }
1144 1140
1145 1141
1146 Handle<Object> Factory::NewError(MessageTemplate::Template template_index,
1147 Handle<Object> arg0, Handle<Object> arg1,
1148 Handle<Object> arg2) {
1149 return NewError("MakeError", template_index, arg0, arg1, arg2);
1150 }
1151
1152
1153 Handle<Object> Factory::NewTypeError(MessageTemplate::Template template_index,
1154 Handle<Object> arg0, Handle<Object> arg1,
1155 Handle<Object> arg2) {
1156 return NewError("MakeTypeError", template_index, arg0, arg1, arg2);
1157 }
1158
1159
1160 Handle<Object> Factory::NewSyntaxError(MessageTemplate::Template template_index,
1161 Handle<Object> arg0, Handle<Object> arg1,
1162 Handle<Object> arg2) {
1163 return NewError("MakeSyntaxError", template_index, arg0, arg1, arg2);
1164 }
1165
1166
1167 Handle<Object> Factory::NewReferenceError(
1168 MessageTemplate::Template template_index, Handle<Object> arg0,
1169 Handle<Object> arg1, Handle<Object> arg2) {
1170 return NewError("MakeReferenceError", template_index, arg0, arg1, arg2);
1171 }
1172
1173
1174 Handle<Object> Factory::NewRangeError(MessageTemplate::Template template_index,
1175 Handle<Object> arg0, Handle<Object> arg1,
1176 Handle<Object> arg2) {
1177 return NewError("MakeRangeError", template_index, arg0, arg1, arg2);
1178 }
1179
1180
1181 Handle<Object> Factory::NewEvalError(MessageTemplate::Template template_index,
1182 Handle<Object> arg0, Handle<Object> arg1,
1183 Handle<Object> arg2) {
1184 return NewError("MakeEvalError", template_index, arg0, arg1, arg2);
1185 }
1186
1187
1188 Handle<String> Factory::EmergencyNewError(const char* message,
1189 Handle<JSArray> args) {
1190 const int kBufferSize = 1000;
1191 char buffer[kBufferSize];
1192 size_t space = kBufferSize;
1193 char* p = &buffer[0];
1194
1195 Vector<char> v(buffer, kBufferSize);
1196 StrNCpy(v, message, space);
1197 space -= Min(space, strlen(message));
1198 p = &buffer[kBufferSize] - space;
1199
1200 for (int i = 0; i < Smi::cast(args->length())->value(); i++) {
1201 if (space > 0) {
1202 *p++ = ' ';
1203 space--;
1204 if (space > 0) {
1205 Handle<String> arg_str = Handle<String>::cast(
1206 Object::GetElement(isolate(), args, i).ToHandleChecked());
1207 base::SmartArrayPointer<char> arg = arg_str->ToCString();
1208 Vector<char> v2(p, static_cast<int>(space));
1209 StrNCpy(v2, arg.get(), space);
1210 space -= Min(space, strlen(arg.get()));
1211 p = &buffer[kBufferSize] - space;
1212 }
1213 }
1214 }
1215 if (space > 0) {
1216 *p = '\0';
1217 } else {
1218 buffer[kBufferSize - 1] = '\0';
1219 }
1220 return NewStringFromUtf8(CStrVector(buffer), TENURED).ToHandleChecked();
1221 }
1222
1223
1224 Handle<Object> Factory::NewError(const char* maker, const char* message,
1225 Handle<JSArray> args) {
1226 Handle<String> make_str = InternalizeUtf8String(maker);
1227 Handle<Object> fun_obj = Object::GetProperty(
1228 isolate()->js_builtins_object(), make_str).ToHandleChecked();
1229 // If the builtins haven't been properly configured yet this error
1230 // constructor may not have been defined. Bail out.
1231 if (!fun_obj->IsJSFunction()) {
1232 return EmergencyNewError(message, args);
1233 }
1234 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj);
1235 Handle<Object> message_obj = InternalizeUtf8String(message);
1236 Handle<Object> argv[] = { message_obj, args };
1237
1238 // Invoke the JavaScript factory method. If an exception is thrown while
1239 // running the factory method, use the exception as the result.
1240 Handle<Object> result;
1241 MaybeHandle<Object> exception;
1242 if (!Execution::TryCall(fun, undefined_value(), arraysize(argv), argv,
1243 &exception)
1244 .ToHandle(&result)) {
1245 Handle<Object> exception_obj;
1246 if (exception.ToHandle(&exception_obj)) return exception_obj;
1247 return undefined_value();
1248 }
1249 return result;
1250 }
1251
1252
1253 Handle<Object> Factory::NewError(Handle<JSFunction> constructor, 1142 Handle<Object> Factory::NewError(Handle<JSFunction> constructor,
1254 Handle<String> message) { 1143 Handle<String> message) {
1255 Handle<Object> argv[] = { message }; 1144 Handle<Object> argv[] = { message };
1256 1145
1257 // Invoke the JavaScript factory method. If an exception is thrown while 1146 // Invoke the JavaScript factory method. If an exception is thrown while
1258 // running the factory method, use the exception as the result. 1147 // running the factory method, use the exception as the result.
1259 Handle<Object> result; 1148 Handle<Object> result;
1260 MaybeHandle<Object> exception; 1149 MaybeHandle<Object> exception;
1261 if (!Execution::TryCall(constructor, undefined_value(), arraysize(argv), argv, 1150 if (!Execution::TryCall(constructor, undefined_value(), arraysize(argv), argv,
1262 &exception) 1151 &exception)
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 } 2354 }
2466 2355
2467 2356
2468 Handle<Object> Factory::ToBoolean(bool value) { 2357 Handle<Object> Factory::ToBoolean(bool value) {
2469 return value ? true_value() : false_value(); 2358 return value ? true_value() : false_value();
2470 } 2359 }
2471 2360
2472 2361
2473 } // namespace internal 2362 } // namespace internal
2474 } // namespace v8 2363 } // namespace v8
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698