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

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

Issue 13626002: ES6 symbols: extend V8 API to support symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added TODO Created 7 years, 8 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 | « src/runtime.cc ('k') | no next file » | no next file with comments »
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 // 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 2160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2171 CompileRun( 2171 CompileRun(
2172 "function cnst() { return 42; };\n" 2172 "function cnst() { return 42; };\n"
2173 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); 2173 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2174 Local<v8::Object> o1 = v8::Object::New(); 2174 Local<v8::Object> o1 = v8::Object::New();
2175 Local<v8::Object> o2 = v8::Object::New(); 2175 Local<v8::Object> o2 = v8::Object::New();
2176 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2176 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2177 } 2177 }
2178 } 2178 }
2179 2179
2180 2180
2181 THREADED_TEST(SymbolProperties) {
2182 i::FLAG_harmony_symbols = true;
2183
2184 LocalContext env;
2185 v8::Isolate* isolate = env->GetIsolate();
2186 v8::HandleScope scope(isolate);
2187
2188 v8::Local<v8::Object> obj = v8::Object::New();
2189 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
2190 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, "my-symbol");
2191
2192 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2193
2194 // Check basic symbol functionality.
2195 CHECK(sym1->IsSymbol());
2196 CHECK(sym2->IsSymbol());
2197 CHECK(!obj->IsSymbol());
2198
2199 CHECK(sym1->Equals(sym1));
2200 CHECK(sym2->Equals(sym2));
2201 CHECK(!sym1->Equals(sym2));
2202 CHECK(!sym2->Equals(sym1));
2203 CHECK(sym1->StrictEquals(sym1));
2204 CHECK(sym2->StrictEquals(sym2));
2205 CHECK(!sym1->StrictEquals(sym2));
2206 CHECK(!sym2->StrictEquals(sym1));
2207
2208 CHECK(sym2->Name()->Equals(v8::String::New("my-symbol")));
2209
2210 v8::Local<v8::Value> sym_val = sym2;
2211 CHECK(sym_val->IsSymbol());
2212 CHECK(sym_val->Equals(sym2));
2213 CHECK(sym_val->StrictEquals(sym2));
2214 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2));
2215
2216 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2);
2217 CHECK(sym_obj->IsSymbolObject());
2218 CHECK(!sym2->IsSymbolObject());
2219 CHECK(!obj->IsSymbolObject());
2220 CHECK(sym_obj->Equals(sym2));
2221 CHECK(!sym_obj->StrictEquals(sym2));
2222 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj));
2223 CHECK(v8::SymbolObject::Cast(*sym_obj)->SymbolValue()->Equals(sym2));
2224
2225 // Make sure delete of a non-existent symbol property works.
2226 CHECK(obj->Delete(sym1));
2227 CHECK(!obj->Has(sym1));
2228
2229 CHECK(obj->Set(sym1, v8::Integer::New(1503)));
2230 CHECK(obj->Has(sym1));
2231 CHECK_EQ(1503, obj->Get(sym1)->Int32Value());
2232 CHECK(obj->Set(sym1, v8::Integer::New(2002)));
2233 CHECK(obj->Has(sym1));
2234 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2235 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1));
2236
2237 CHECK_EQ(0, obj->GetOwnPropertyNames()->Length());
2238 int num_props = obj->GetPropertyNames()->Length();
2239 CHECK(obj->Set(v8::String::New("bla"), v8::Integer::New(20)));
2240 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2241 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2242
2243 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2244
2245 // Add another property and delete it afterwards to force the object in
2246 // slow case.
2247 CHECK(obj->Set(sym2, v8::Integer::New(2008)));
2248 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2249 CHECK_EQ(2008, obj->Get(sym2)->Int32Value());
2250 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2251 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2252
2253 CHECK(obj->Has(sym1));
2254 CHECK(obj->Has(sym2));
2255 CHECK(obj->Delete(sym2));
2256 CHECK(obj->Has(sym1));
2257 CHECK(!obj->Has(sym2));
2258 CHECK_EQ(2002, obj->Get(sym1)->Int32Value());
2259 CHECK_EQ(1, obj->GetOwnPropertyNames()->Length());
2260 }
2261
2262
2181 THREADED_TEST(HiddenProperties) { 2263 THREADED_TEST(HiddenProperties) {
2182 LocalContext env; 2264 LocalContext env;
2183 v8::HandleScope scope(env->GetIsolate()); 2265 v8::HandleScope scope(env->GetIsolate());
2184 2266
2185 v8::Local<v8::Object> obj = v8::Object::New(); 2267 v8::Local<v8::Object> obj = v8::Object::New();
2186 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2268 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2187 v8::Local<v8::String> empty = v8_str(""); 2269 v8::Local<v8::String> empty = v8_str("");
2188 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2270 v8::Local<v8::String> prop_name = v8_str("prop_name");
2189 2271
2190 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2272 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
(...skipping 16128 matching lines...) Expand 10 before | Expand all | Expand 10 after
18319 i::Semaphore* sem_; 18401 i::Semaphore* sem_;
18320 volatile int sem_value_; 18402 volatile int sem_value_;
18321 }; 18403 };
18322 18404
18323 18405
18324 THREADED_TEST(SemaphoreInterruption) { 18406 THREADED_TEST(SemaphoreInterruption) {
18325 ThreadInterruptTest().RunTest(); 18407 ThreadInterruptTest().RunTest();
18326 } 18408 }
18327 18409
18328 #endif // WIN32 18410 #endif // WIN32
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698