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

Side by Side Diff: test/cctest/test-api.cc

Issue 546803003: Update ObjectToString to Harmony-draft algorithm (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add lots more tests, make it safer 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2003 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 2014
2015 void SymbolAccessorSetter(Local<Name> name, Local<Value> value, 2015 void SymbolAccessorSetter(Local<Name> name, Local<Value> value,
2016 const v8::PropertyCallbackInfo<void>& info) { 2016 const v8::PropertyCallbackInfo<void>& info) {
2017 CHECK(name->IsSymbol()); 2017 CHECK(name->IsSymbol());
2018 Local<Symbol> sym = Local<Symbol>::Cast(name); 2018 Local<Symbol> sym = Local<Symbol>::Cast(name);
2019 if (sym->Name()->IsUndefined()) 2019 if (sym->Name()->IsUndefined())
2020 return; 2020 return;
2021 SimpleAccessorSetter(Local<String>::Cast(sym->Name()), value, info); 2021 SimpleAccessorSetter(Local<String>::Cast(sym->Name()), value, info);
2022 } 2022 }
2023 2023
2024 void SymbolAccessorGetterReturnsDefault(Local<Name> name,
2025 const v8::PropertyCallbackInfo<v8::Value>& info) {
2026 CHECK(name->IsSymbol());
2027 Local<Symbol> sym = Local<Symbol>::Cast(name);
2028 if (sym->Name()->IsUndefined())
2029 return;
2030 info.GetReturnValue().Set(info.Data());
2031 }
2032
2033 static void ThrowingSymbolAccessorGetter(
2034 Local<Name> name,
2035 const v8::PropertyCallbackInfo<v8::Value>& info) {
2036 ApiTestFuzzer::Fuzz();
Dmitry Lomov (no reviews) 2014/10/18 21:24:19 Why this line?
2037 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(name));
2038 }
2039
2024 void EmptyInterceptorGetter(Local<String> name, 2040 void EmptyInterceptorGetter(Local<String> name,
2025 const v8::PropertyCallbackInfo<v8::Value>& info) { 2041 const v8::PropertyCallbackInfo<v8::Value>& info) {
2026 } 2042 }
2027 2043
2028 void EmptyInterceptorSetter(Local<String> name, 2044 void EmptyInterceptorSetter(Local<String> name,
2029 Local<Value> value, 2045 Local<Value> value,
2030 const v8::PropertyCallbackInfo<v8::Value>& info) { 2046 const v8::PropertyCallbackInfo<v8::Value>& info) {
2031 } 2047 }
2032 2048
2033 void InterceptorGetter(Local<String> name, 2049 void InterceptorGetter(Local<String> name,
(...skipping 11448 matching lines...) Expand 10 before | Expand all | Expand 10 after
13482 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); 13498 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]")));
13483 13499
13484 // Check global 13500 // Check global
13485 value = context->Global()->ObjectProtoToString(); 13501 value = context->Global()->ObjectProtoToString();
13486 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); 13502 CHECK(value->IsString() && value->Equals(v8_str("[object global]")));
13487 13503
13488 // Check ordinary object 13504 // Check ordinary object
13489 Local<Value> object = v8_compile("new Object()")->Run(); 13505 Local<Value> object = v8_compile("new Object()")->Run();
13490 value = object.As<v8::Object>()->ObjectProtoToString(); 13506 value = object.As<v8::Object>()->ObjectProtoToString();
13491 CHECK(value->IsString() && value->Equals(v8_str("[object Object]"))); 13507 CHECK(value->IsString() && value->Equals(v8_str("[object Object]")));
13508
13509 // Check that ES6 semantics using @@toStringTag work
13510 i::FLAG_harmony_tostring = true;
13511 Local<v8::Symbol> toStringTag = v8::Symbol::GetToStringTag(isolate);
13512
13513 #define TEST_TOSTRINGTAG(type, tag, expected) \
13514 do { \
13515 object = v8_compile("new " #type "()")->Run(); \
Dmitry Lomov (no reviews) 2014/10/18 21:24:19 Nit: use CompileRun here
13516 object.As<v8::Object>()->Set(toStringTag, v8_str(#tag)); \
13517 value = object.As<v8::Object>()->ObjectProtoToString(); \
13518 CHECK(value->IsString() && value->Equals( \
13519 v8_str("[object " #expected "]"))); \
13520 } while (0)
13521
13522 TEST_TOSTRINGTAG(Array, Object, Object);
13523 TEST_TOSTRINGTAG(Object, Arguments, ~Arguments);
13524 TEST_TOSTRINGTAG(Object, Array, ~Array);
13525 TEST_TOSTRINGTAG(Object, Boolean, ~Boolean);
13526 TEST_TOSTRINGTAG(Object, Date, ~Date);
13527 TEST_TOSTRINGTAG(Object, Error, ~Error);
13528 TEST_TOSTRINGTAG(Object, Function, ~Function);
13529 TEST_TOSTRINGTAG(Object, Number, ~Number);
13530 TEST_TOSTRINGTAG(Object, RegExp, ~RegExp);
13531 TEST_TOSTRINGTAG(Object, String, ~String);
13532 TEST_TOSTRINGTAG(Object, Foo, Foo);
13533
13534 #undef TEST_TOSTRINGTAG
13535
13536 // @@toStringTag getter throws
13537 Local<v8::Object> obj = v8::Object::New(isolate);
Dmitry Lomov (no reviews) 2014/10/18 21:24:19 Great test, add one more where the getter is actua
caitp (gmail) 2014/10/18 21:27:40 There's a problem with that --- the bootstrapper d
caitp (gmail) 2014/10/18 21:35:01 Er, I mean `Symbol.toStringTag` is not exposed ---
Dmitry Lomov (no reviews) 2014/10/18 21:45:00 Ah, I see. Extract the tests for toStringTag into
13538 obj->SetAccessor(toStringTag, ThrowingSymbolAccessorGetter);
13539 { TryCatch try_catch;
13540 value = obj->ObjectProtoToString();
13541 CHECK(value.IsEmpty());
13542 CHECK(try_catch.HasCaught());
13543 }
13544
13545 // @@toStringTag getter does not throw
13546 obj = v8::Object::New(isolate);
13547 obj->SetAccessor(toStringTag, SymbolAccessorGetterReturnsDefault,
13548 0, v8_str("Test"));
13549 { TryCatch try_catch;
13550 value = obj->ObjectProtoToString();
13551 CHECK(value->IsString() && value->Equals(v8_str("[object Test]")));
13552 CHECK(!try_catch.HasCaught());
13553 }
13492 } 13554 }
13493 13555
13494 13556
13495 THREADED_TEST(ObjectGetConstructorName) { 13557 THREADED_TEST(ObjectGetConstructorName) {
13496 LocalContext context; 13558 LocalContext context;
13497 v8::HandleScope scope(context->GetIsolate()); 13559 v8::HandleScope scope(context->GetIsolate());
13498 v8_compile("function Parent() {};" 13560 v8_compile("function Parent() {};"
13499 "function Child() {};" 13561 "function Child() {};"
13500 "Child.prototype = new Parent();" 13562 "Child.prototype = new Parent();"
13501 "var outer = { inner: function() { } };" 13563 "var outer = { inner: function() { } };"
(...skipping 10332 matching lines...) Expand 10 before | Expand all | Expand 10 after
23834 char chunk2[] = 23896 char chunk2[] =
23835 "XXr = 13;\n" 23897 "XXr = 13;\n"
23836 " return foob\xeb\x91\x80\xeb\x91\x80r;\n" 23898 " return foob\xeb\x91\x80\xeb\x91\x80r;\n"
23837 "}\n"; 23899 "}\n";
23838 chunk1[strlen(chunk1) - 1] = reference[0]; 23900 chunk1[strlen(chunk1) - 1] = reference[0];
23839 chunk2[0] = reference[1]; 23901 chunk2[0] = reference[1];
23840 chunk2[1] = reference[2]; 23902 chunk2[1] = reference[2];
23841 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 23903 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
23842 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 23904 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
23843 } 23905 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698