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

Side by Side 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: Teach NoSideEffectToString() that ObjectToString was extended 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/v8.h ('k') | src/arraybuffer.js » ('j') | src/messages.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 3352 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 // Because we use caching to speed up enumeration it is important 3363 // Because we use caching to speed up enumeration it is important
3364 // to never change the result of the basic enumeration function so 3364 // to never change the result of the basic enumeration function so
3365 // we clone the result. 3365 // we clone the result.
3366 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value); 3366 i::Handle<i::FixedArray> elms = isolate->factory()->CopyFixedArray(value);
3367 i::Handle<i::JSArray> result = 3367 i::Handle<i::JSArray> result =
3368 isolate->factory()->NewJSArrayWithElements(elms); 3368 isolate->factory()->NewJSArrayWithElements(elms);
3369 return Utils::ToLocal(scope.CloseAndEscape(result)); 3369 return Utils::ToLocal(scope.CloseAndEscape(result));
3370 } 3370 }
3371 3371
3372 3372
3373 static bool GetPredefinedToString(
3374 i::Handle<i::String> tag, Local<String>* result) {
3375 i::Isolate* i_isolate = tag->GetIsolate();
3376 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
3377 i::Factory* factory = i_isolate->factory();
3378
3379 if (i::String::Equals(tag, factory->Arguments_string())) {
3380 *result = v8::String::NewFromUtf8(isolate, "[object ~Arguments]");
3381 } else if (i::String::Equals(tag, factory->Array_string())) {
3382 *result = v8::String::NewFromUtf8(isolate, "[object ~Array]");
3383 } else if (i::String::Equals(tag, factory->Boolean_string())) {
3384 *result = v8::String::NewFromUtf8(isolate, "[object ~Boolean]");
3385 } else if (i::String::Equals(tag, factory->Date_string())) {
3386 *result = v8::String::NewFromUtf8(isolate, "[object ~Date]");
3387 } else if (i::String::Equals(tag, factory->Error_string())) {
3388 *result = v8::String::NewFromUtf8(isolate, "[object ~Error]");
3389 } else if (i::String::Equals(tag, factory->Function_string())) {
3390 *result = v8::String::NewFromUtf8(isolate, "[object ~Function]");
3391 } else if (i::String::Equals(tag, factory->Number_string())) {
3392 *result = v8::String::NewFromUtf8(isolate, "[object ~Number]");
3393 } else if (i::String::Equals(tag, factory->RegExp_string())) {
3394 *result = v8::String::NewFromUtf8(isolate, "[object ~RegExp]");
3395 } else if (i::String::Equals(tag, factory->String_string())) {
3396 *result = v8::String::NewFromUtf8(isolate, "[object ~String]");
3397 } else {
3398 return false;
3399 }
3400 return true;
3401 }
3402
3403
3373 Local<String> v8::Object::ObjectProtoToString() { 3404 Local<String> v8::Object::ObjectProtoToString() {
3374 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate(); 3405 i::Isolate* i_isolate = Utils::OpenHandle(this)->GetIsolate();
3375 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate); 3406 Isolate* isolate = reinterpret_cast<Isolate*>(i_isolate);
3376 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()", 3407 ON_BAILOUT(i_isolate, "v8::Object::ObjectProtoToString()",
3377 return Local<v8::String>()); 3408 return Local<v8::String>());
3378 ENTER_V8(i_isolate); 3409 ENTER_V8(i_isolate);
3379 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3410 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3380 3411
3381 i::Handle<i::Object> name(self->class_name(), i_isolate); 3412 i::Handle<i::Object> name(self->class_name(), i_isolate);
3413 i::Handle<i::Object> tag;
3382 3414
3383 // Native implementation of Object.prototype.toString (v8natives.js): 3415 // Native implementation of Object.prototype.toString (v8natives.js):
3384 // var c = %_ClassOf(this); 3416 // var c = %_ClassOf(this);
3385 // if (c === 'Arguments') c = 'Object'; 3417 // if (c === 'Arguments') c = 'Object';
3386 // return "[object " + c + "]"; 3418 // return "[object " + c + "]";
3387 3419
3388 if (!name->IsString()) { 3420 if (!name->IsString()) {
3389 return v8::String::NewFromUtf8(isolate, "[object ]"); 3421 return v8::String::NewFromUtf8(isolate, "[object ]");
3390 } else { 3422 } else {
3391 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name); 3423 i::Handle<i::String> class_name = i::Handle<i::String>::cast(name);
3392 if (i::String::Equals(class_name, 3424 if (i::String::Equals(class_name,
3393 i_isolate->factory()->Arguments_string())) { 3425 i_isolate->factory()->Arguments_string())) {
3394 return v8::String::NewFromUtf8(isolate, "[object Object]"); 3426 return v8::String::NewFromUtf8(isolate, "[object Object]");
3395 } else { 3427 } else {
3428 if (internal::FLAG_harmony_tostring) {
3429 i::Handle<i::Symbol> toStringTag = Utils::OpenHandle(
3430 *Symbol::GetToStringTag(isolate));
3431 EXCEPTION_PREAMBLE(i_isolate);
3432 has_pending_exception = !i::Runtime::GetObjectProperty(
3433 i_isolate, self, toStringTag).ToHandle(&tag);
3434 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::String>());
3435
3436 if (!tag->IsUndefined()) {
3437 if (!tag->IsString())
3438 return v8::String::NewFromUtf8(isolate, "[object ???]");
3439 i::Handle<i::String> tag_name = i::Handle<i::String>::cast(tag);
3440 if (!i::String::Equals(class_name, tag_name)) {
3441 Local<String> result;
3442 if (GetPredefinedToString(tag_name, &result))
3443 return result;
3444
3445 class_name = tag_name;
3446 }
3447 }
3448 }
3396 const char* prefix = "[object "; 3449 const char* prefix = "[object ";
3397 Local<String> str = Utils::ToLocal(class_name); 3450 Local<String> str = Utils::ToLocal(class_name);
3398 const char* postfix = "]"; 3451 const char* postfix = "]";
3399 3452
3400 int prefix_len = i::StrLength(prefix); 3453 int prefix_len = i::StrLength(prefix);
3401 int str_len = str->Utf8Length(); 3454 int str_len = str->Utf8Length();
3402 int postfix_len = i::StrLength(postfix); 3455 int postfix_len = i::StrLength(postfix);
3403 3456
3404 int buf_len = prefix_len + str_len + postfix_len; 3457 int buf_len = prefix_len + str_len + postfix_len;
3405 i::ScopedVector<char> buf(buf_len); 3458 i::ScopedVector<char> buf(buf_len);
(...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after
6192 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) { 6245 Local<Symbol> v8::Symbol::GetIterator(Isolate* isolate) {
6193 return GetWellKnownSymbol(isolate, "Symbol.iterator"); 6246 return GetWellKnownSymbol(isolate, "Symbol.iterator");
6194 } 6247 }
6195 6248
6196 6249
6197 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) { 6250 Local<Symbol> v8::Symbol::GetUnscopables(Isolate* isolate) {
6198 return GetWellKnownSymbol(isolate, "Symbol.unscopables"); 6251 return GetWellKnownSymbol(isolate, "Symbol.unscopables");
6199 } 6252 }
6200 6253
6201 6254
6255 Local<Symbol> v8::Symbol::GetToStringTag(Isolate* isolate) {
6256 return GetWellKnownSymbol(isolate, "Symbol.toStringTag");
6257 }
6258
6259
6202 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) { 6260 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
6203 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6261 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6204 LOG_API(i_isolate, "Private::New()"); 6262 LOG_API(i_isolate, "Private::New()");
6205 ENTER_V8(i_isolate); 6263 ENTER_V8(i_isolate);
6206 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); 6264 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
6207 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); 6265 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
6208 Local<Symbol> result = Utils::ToLocal(symbol); 6266 Local<Symbol> result = Utils::ToLocal(symbol);
6209 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); 6267 return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6210 } 6268 }
6211 6269
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
7661 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7719 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7662 Address callback_address = 7720 Address callback_address =
7663 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7721 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7664 VMState<EXTERNAL> state(isolate); 7722 VMState<EXTERNAL> state(isolate);
7665 ExternalCallbackScope call_scope(isolate, callback_address); 7723 ExternalCallbackScope call_scope(isolate, callback_address);
7666 callback(info); 7724 callback(info);
7667 } 7725 }
7668 7726
7669 7727
7670 } } // namespace v8::internal 7728 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/arraybuffer.js » ('j') | src/messages.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698