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

Unified Diff: src/api.cc

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use intern'd strings instead of creating vectors Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | src/arraybuffer.js » ('j') | src/generator.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 0c78b5f27058f923fc02ccd2b9b6dc6e53c8bca7..a0286cefc68bac78baac63c6219440d6e56d9b57 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3379,6 +3379,7 @@ Local<String> v8::Object::ObjectProtoToString() {
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
i::Handle<i::Object> name(self->class_name(), i_isolate);
+ i::Handle<i::Object> tag;
// Native implementation of Object.prototype.toString (v8natives.js):
// var c = %_ClassOf(this);
@@ -3393,6 +3394,53 @@ Local<String> v8::Object::ObjectProtoToString() {
i_isolate->factory()->Arguments_string())) {
return v8::String::NewFromUtf8(isolate, "[object Object]");
} else {
+ if (internal::FLAG_harmony_tostring) {
+ i::Handle<i::Symbol> toStringTag = Utils::OpenHandle(
+ *Symbol::GetToStringTag(isolate));
+ tag = i::Runtime::GetObjectProperty(
Dmitry Lomov (no reviews) 2014/10/18 15:16:48 This calls into Javascript, so needs EXCEPTION_PRE
+ i_isolate, self, toStringTag).ToHandleChecked();
+
+ if (!tag->IsUndefined()) {
+ if (!tag->IsString()) {
+ return v8::String::NewFromUtf8(isolate, "[object ???]");
+ } else {
+ i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag);
+ using namespace internal;
Dmitry Lomov (no reviews) 2014/10/18 15:16:48 Nit: remove 'using namespace internal' here, we us
+ if (!i::String::Equals(class_name, tag_name)) {
+ if (i::String::Equals(
+ tag_name, i_isolate->factory()->Arguments_string())) {
Dmitry Lomov (no reviews) 2014/10/18 15:16:48 Nit: introduce variable for i_isolate->factory()
+ return v8::String::NewFromUtf8(isolate, "[object ~Arguments]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Array_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Array]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Boolean_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Boolean]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Date_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Date]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Error_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Error]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Function_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Function]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->Number_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~Number]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->RegExp_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~RegExp]");
+ } else if (i::String::Equals(
+ tag_name, i_isolate->factory()->String_string())) {
+ return v8::String::NewFromUtf8(isolate, "[object ~String]");
+ } else {
+ class_name = tag_name;
+ }
+ }
+ }
+ }
+ }
const char* prefix = "[object ";
Local<String> str = Utils::ToLocal(class_name);
const char* postfix = "]";
@@ -6199,6 +6247,11 @@ Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) {
}
+Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) {
+ return GetWellKnownSymbol(isolate, "Symbol.toStringTag");
+}
+
+
Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
LOG_API(i_isolate, "Private::New()");
« no previous file with comments | « include/v8.h ('k') | src/arraybuffer.js » ('j') | src/generator.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698