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

Unified Diff: src/objects.cc

Issue 1509533003: Rewrite Object.prototype.toString in C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase, add back experimental flag Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 440d38c9f8ffe157a7d9a612a3e4832ed3e11ccd..ce590c7e33ecf957b7682b102e62cfde460f3d03 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -16184,6 +16184,40 @@ int JSObject::GetOwnElementKeys(FixedArray* storage, PropertyFilter filter) {
}
+MaybeHandle<String> JSObject::ObjectProtoToString(Isolate* isolate,
+ Handle<Object> object) {
+ if (object->IsUndefined()) return isolate->factory()->undefined_to_string();
+ if (object->IsNull()) return isolate->factory()->null_to_string();
+
+ Handle<JSReceiver> receiver;
+ CHECK(Object::ToObject(isolate, object).ToHandle(&receiver));
+
+ Handle<String> tag;
+ if (FLAG_harmony_tostring) {
+ Handle<Object> to_string_tag;
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, to_string_tag,
+ GetProperty(receiver, isolate->factory()->to_string_tag_symbol()),
+ String);
+ if (to_string_tag->IsString()) {
+ tag = Handle<String>::cast(to_string_tag);
+ }
+ }
+
+ if (tag.is_null()) {
+ // TODO(adamk): class_name() is expensive, replace with instance type
+ // checks where possible.
+ tag = handle(receiver->class_name(), isolate);
+ }
+
+ IncrementalStringBuilder builder(isolate);
+ builder.AppendCString("[object ");
+ builder.AppendString(tag);
+ builder.AppendCharacter(']');
+ return builder.Finish();
+}
+
+
const char* Symbol::PrivateSymbolToName() const {
Heap* heap = GetIsolate()->heap();
#define SYMBOL_CHECK_AND_PRINT(name) \
« no previous file with comments | « src/objects.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698