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

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

Powered by Google App Engine
This is Rietveld 408576698