OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <memory> | 9 #include <memory> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 | 221 |
222 namespace { | 222 namespace { |
223 | 223 |
224 bool IsErrorObject(Isolate* isolate, Handle<Object> object) { | 224 bool IsErrorObject(Isolate* isolate, Handle<Object> object) { |
225 if (!object->IsJSReceiver()) return false; | 225 if (!object->IsJSReceiver()) return false; |
226 Handle<Symbol> symbol = isolate->factory()->stack_trace_symbol(); | 226 Handle<Symbol> symbol = isolate->factory()->stack_trace_symbol(); |
227 return JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(object), symbol) | 227 return JSReceiver::HasOwnProperty(Handle<JSReceiver>::cast(object), symbol) |
228 .FromMaybe(false); | 228 .FromMaybe(false); |
229 } | 229 } |
230 | 230 |
| 231 Handle<String> AsStringOrEmpty(Isolate* isolate, Handle<Object> object) { |
| 232 return object->IsString() ? Handle<String>::cast(object) |
| 233 : isolate->factory()->empty_string(); |
| 234 } |
| 235 |
231 Handle<String> NoSideEffectsErrorToString(Isolate* isolate, | 236 Handle<String> NoSideEffectsErrorToString(Isolate* isolate, |
232 Handle<Object> input) { | 237 Handle<Object> input) { |
233 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(input); | 238 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(input); |
234 | 239 |
235 Handle<Name> name_key = isolate->factory()->name_string(); | 240 Handle<Name> name_key = isolate->factory()->name_string(); |
236 Handle<Object> name = JSReceiver::GetDataProperty(receiver, name_key); | 241 Handle<Object> name = JSReceiver::GetDataProperty(receiver, name_key); |
237 Handle<String> name_str = (name->IsUndefined(isolate)) | 242 Handle<String> name_str = AsStringOrEmpty(isolate, name); |
238 ? isolate->factory()->Error_string() | |
239 : Object::NoSideEffectsToString(isolate, name); | |
240 | 243 |
241 Handle<Name> msg_key = isolate->factory()->message_string(); | 244 Handle<Name> msg_key = isolate->factory()->message_string(); |
242 Handle<Object> msg = JSReceiver::GetDataProperty(receiver, msg_key); | 245 Handle<Object> msg = JSReceiver::GetDataProperty(receiver, msg_key); |
243 Handle<String> msg_str = (msg->IsUndefined(isolate)) | 246 Handle<String> msg_str = AsStringOrEmpty(isolate, msg); |
244 ? isolate->factory()->empty_string() | |
245 : Object::NoSideEffectsToString(isolate, msg); | |
246 | 247 |
247 if (name_str->length() == 0) return msg_str; | 248 if (name_str->length() == 0) return msg_str; |
248 if (msg_str->length() == 0) return name_str; | 249 if (msg_str->length() == 0) return name_str; |
249 | 250 |
250 IncrementalStringBuilder builder(isolate); | 251 IncrementalStringBuilder builder(isolate); |
251 builder.AppendString(name_str); | 252 builder.AppendString(name_str); |
252 builder.AppendCString(": "); | 253 builder.AppendCString(": "); |
253 builder.AppendString(msg_str); | 254 builder.AppendString(msg_str); |
254 | 255 |
255 return builder.Finish().ToHandleChecked(); | 256 return builder.Finish().ToHandleChecked(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 receiver, isolate->factory()->constructor_string()); | 315 receiver, isolate->factory()->constructor_string()); |
315 if (ctor->IsFunction()) { | 316 if (ctor->IsFunction()) { |
316 Handle<String> ctor_name; | 317 Handle<String> ctor_name; |
317 if (ctor->IsJSBoundFunction()) { | 318 if (ctor->IsJSBoundFunction()) { |
318 ctor_name = JSBoundFunction::GetName( | 319 ctor_name = JSBoundFunction::GetName( |
319 isolate, Handle<JSBoundFunction>::cast(ctor)) | 320 isolate, Handle<JSBoundFunction>::cast(ctor)) |
320 .ToHandleChecked(); | 321 .ToHandleChecked(); |
321 } else if (ctor->IsJSFunction()) { | 322 } else if (ctor->IsJSFunction()) { |
322 Handle<Object> ctor_name_obj = | 323 Handle<Object> ctor_name_obj = |
323 JSFunction::GetName(isolate, Handle<JSFunction>::cast(ctor)); | 324 JSFunction::GetName(isolate, Handle<JSFunction>::cast(ctor)); |
324 ctor_name = NoSideEffectsToString(isolate, ctor_name_obj); | 325 ctor_name = AsStringOrEmpty(isolate, ctor_name_obj); |
325 } | 326 } |
326 | 327 |
327 if (ctor_name->length() != 0) { | 328 if (ctor_name->length() != 0) { |
328 IncrementalStringBuilder builder(isolate); | 329 IncrementalStringBuilder builder(isolate); |
329 builder.AppendCString("#<"); | 330 builder.AppendCString("#<"); |
330 builder.AppendString(ctor_name); | 331 builder.AppendString(ctor_name); |
331 builder.AppendCString(">"); | 332 builder.AppendCString(">"); |
332 | 333 |
333 return builder.Finish().ToHandleChecked(); | 334 return builder.Finish().ToHandleChecked(); |
334 } | 335 } |
(...skipping 18850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19185 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, | 19186 for (PrototypeIterator iter(isolate, this, kStartAtReceiver, |
19186 PrototypeIterator::END_AT_NULL); | 19187 PrototypeIterator::END_AT_NULL); |
19187 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { | 19188 !iter.IsAtEnd(); iter.AdvanceIgnoringProxies()) { |
19188 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; | 19189 if (iter.GetCurrent<Object>()->IsJSProxy()) return true; |
19189 } | 19190 } |
19190 return false; | 19191 return false; |
19191 } | 19192 } |
19192 | 19193 |
19193 } // namespace internal | 19194 } // namespace internal |
19194 } // namespace v8 | 19195 } // namespace v8 |
OLD | NEW |