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 16272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16283 if (constructor->shared()->IsApiFunction()) { | 16283 if (constructor->shared()->IsApiFunction()) { |
16284 DCHECK(is_api_object); | 16284 DCHECK(is_api_object); |
16285 } else { | 16285 } else { |
16286 DCHECK(!is_api_object); | 16286 DCHECK(!is_api_object); |
16287 } | 16287 } |
16288 } | 16288 } |
16289 #endif | 16289 #endif |
16290 return is_api_object; | 16290 return is_api_object; |
16291 } | 16291 } |
16292 | 16292 |
16293 MaybeHandle<String> Object::ObjectProtoToString(Isolate* isolate, | |
16294 Handle<Object> object) { | |
16295 if (*object == isolate->heap()->undefined_value()) { | |
16296 return isolate->factory()->undefined_to_string(); | |
16297 } | |
16298 if (*object == isolate->heap()->null_value()) { | |
16299 return isolate->factory()->null_to_string(); | |
16300 } | |
16301 | |
16302 Handle<JSReceiver> receiver = | |
16303 Object::ToObject(isolate, object).ToHandleChecked(); | |
16304 | |
16305 // For proxies, we must check IsArray() before get(toStringTag) to comply | |
16306 // with the specification | |
16307 Maybe<bool> is_array = Nothing<bool>(); | |
16308 InstanceType instance_type = receiver->map()->instance_type(); | |
16309 if (instance_type == JS_PROXY_TYPE) { | |
16310 is_array = Object::IsArray(receiver); | |
16311 MAYBE_RETURN(is_array, MaybeHandle<String>()); | |
16312 } | |
16313 | |
16314 Handle<String> tag; | |
16315 Handle<Object> to_string_tag; | |
16316 ASSIGN_RETURN_ON_EXCEPTION( | |
16317 isolate, to_string_tag, | |
16318 JSReceiver::GetProperty(receiver, | |
16319 isolate->factory()->to_string_tag_symbol()), | |
16320 String); | |
16321 if (to_string_tag->IsString()) { | |
16322 tag = Handle<String>::cast(to_string_tag); | |
16323 } else { | |
16324 switch (instance_type) { | |
16325 case JS_API_OBJECT_TYPE: | |
16326 case JS_SPECIAL_API_OBJECT_TYPE: | |
16327 tag = handle(receiver->class_name(), isolate); | |
16328 break; | |
16329 case JS_ARGUMENTS_TYPE: | |
16330 return isolate->factory()->arguments_to_string(); | |
16331 case JS_ARRAY_TYPE: | |
16332 return isolate->factory()->array_to_string(); | |
16333 case JS_BOUND_FUNCTION_TYPE: | |
16334 case JS_FUNCTION_TYPE: | |
16335 return isolate->factory()->function_to_string(); | |
16336 case JS_ERROR_TYPE: | |
16337 return isolate->factory()->error_to_string(); | |
16338 case JS_DATE_TYPE: | |
16339 return isolate->factory()->date_to_string(); | |
16340 case JS_REGEXP_TYPE: | |
16341 return isolate->factory()->regexp_to_string(); | |
16342 case JS_PROXY_TYPE: { | |
16343 if (is_array.FromJust()) { | |
16344 return isolate->factory()->array_to_string(); | |
16345 } | |
16346 if (receiver->IsCallable()) { | |
16347 return isolate->factory()->function_to_string(); | |
16348 } | |
16349 return isolate->factory()->object_to_string(); | |
16350 } | |
16351 case JS_VALUE_TYPE: { | |
16352 Object* value = JSValue::cast(*receiver)->value(); | |
16353 if (value->IsString()) { | |
16354 return isolate->factory()->string_to_string(); | |
16355 } | |
16356 if (value->IsNumber()) { | |
16357 return isolate->factory()->number_to_string(); | |
16358 } | |
16359 if (value->IsBoolean()) { | |
16360 return isolate->factory()->boolean_to_string(); | |
16361 } | |
16362 if (value->IsSymbol()) { | |
16363 return isolate->factory()->object_to_string(); | |
16364 } | |
16365 UNREACHABLE(); | |
16366 tag = handle(receiver->class_name(), isolate); | |
16367 break; | |
16368 } | |
16369 default: | |
16370 return isolate->factory()->object_to_string(); | |
16371 } | |
16372 } | |
16373 | |
16374 IncrementalStringBuilder builder(isolate); | |
16375 builder.AppendCString("[object "); | |
16376 builder.AppendString(tag); | |
16377 builder.AppendCharacter(']'); | |
16378 return builder.Finish(); | |
16379 } | |
16380 | |
16381 const char* Symbol::PrivateSymbolToName() const { | 16293 const char* Symbol::PrivateSymbolToName() const { |
16382 Heap* heap = GetIsolate()->heap(); | 16294 Heap* heap = GetIsolate()->heap(); |
16383 #define SYMBOL_CHECK_AND_PRINT(name) \ | 16295 #define SYMBOL_CHECK_AND_PRINT(name) \ |
16384 if (this == heap->name()) return #name; | 16296 if (this == heap->name()) return #name; |
16385 PRIVATE_SYMBOL_LIST(SYMBOL_CHECK_AND_PRINT) | 16297 PRIVATE_SYMBOL_LIST(SYMBOL_CHECK_AND_PRINT) |
16386 #undef SYMBOL_CHECK_AND_PRINT | 16298 #undef SYMBOL_CHECK_AND_PRINT |
16387 return "UNKNOWN"; | 16299 return "UNKNOWN"; |
16388 } | 16300 } |
16389 | 16301 |
16390 | 16302 |
(...skipping 4059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20450 // depend on this. | 20362 // depend on this. |
20451 return DICTIONARY_ELEMENTS; | 20363 return DICTIONARY_ELEMENTS; |
20452 } | 20364 } |
20453 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20365 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
20454 return kind; | 20366 return kind; |
20455 } | 20367 } |
20456 } | 20368 } |
20457 | 20369 |
20458 } // namespace internal | 20370 } // namespace internal |
20459 } // namespace v8 | 20371 } // namespace v8 |
OLD | NEW |