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

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

Issue 1149863005: Move hash code from hidden string to a private symbol (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix merge Created 5 years, 7 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
« no previous file with comments | « src/x64/macro-assembler-x64.cc ('k') | test/cctest/test-hashing.cc » ('j') | 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 2241 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 CompileRun( 2252 CompileRun(
2253 "function cnst() { return 42; };\n" 2253 "function cnst() { return 42; };\n"
2254 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); 2254 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n");
2255 Local<v8::Object> o1 = v8::Object::New(isolate); 2255 Local<v8::Object> o1 = v8::Object::New(isolate);
2256 Local<v8::Object> o2 = v8::Object::New(isolate); 2256 Local<v8::Object> o2 = v8::Object::New(isolate);
2257 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2257 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2258 } 2258 }
2259 } 2259 }
2260 2260
2261 2261
2262 THREADED_TEST(GlobalProxyIdentityHash) { 2262 void GlobalProxyIdentityHash(bool set_in_js) {
2263 LocalContext env; 2263 LocalContext env;
2264 v8::Isolate* isolate = env->GetIsolate(); 2264 v8::Isolate* isolate = env->GetIsolate();
2265 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2265 v8::HandleScope scope(isolate); 2266 v8::HandleScope scope(isolate);
2266 Handle<Object> global_proxy = env->Global(); 2267 Handle<Object> global_proxy = env->Global();
2267 int hash1 = global_proxy->GetIdentityHash(); 2268 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy);
2269 env->Global()->Set(v8_str("global"), global_proxy);
2270 i::Handle<i::Object> original_hash;
2271 if (set_in_js) {
2272 CompileRun("var m = new Set(); m.add(global);");
2273 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate);
2274 } else {
2275 original_hash = i::Handle<i::Object>(
2276 i::Object::GetOrCreateHash(i_isolate, i_global_proxy));
2277 }
2278 CHECK(original_hash->IsSmi());
2279 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value();
2268 // Hash should be retained after being detached. 2280 // Hash should be retained after being detached.
2269 env->DetachGlobal(); 2281 env->DetachGlobal();
2270 int hash2 = global_proxy->GetIdentityHash(); 2282 int hash2 = global_proxy->GetIdentityHash();
2271 CHECK_EQ(hash1, hash2); 2283 CHECK_EQ(hash1, hash2);
2272 { 2284 {
2273 // Re-attach global proxy to a new context, hash should stay the same. 2285 // Re-attach global proxy to a new context, hash should stay the same.
2274 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy); 2286 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy);
2275 int hash3 = global_proxy->GetIdentityHash(); 2287 int hash3 = global_proxy->GetIdentityHash();
2276 CHECK_EQ(hash1, hash3); 2288 CHECK_EQ(hash1, hash3);
2277 } 2289 }
2278 } 2290 }
2279 2291
2280 2292
2293 THREADED_TEST(GlobalProxyIdentityHash) {
2294 GlobalProxyIdentityHash(true);
2295 GlobalProxyIdentityHash(false);
2296 }
2297
2298
2281 TEST(SymbolIdentityHash) { 2299 TEST(SymbolIdentityHash) {
2282 LocalContext env; 2300 LocalContext env;
2283 v8::Isolate* isolate = env->GetIsolate(); 2301 v8::Isolate* isolate = env->GetIsolate();
2284 v8::HandleScope scope(isolate); 2302 v8::HandleScope scope(isolate);
2285 2303
2286 { 2304 {
2287 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); 2305 Local<v8::Symbol> symbol = v8::Symbol::New(isolate);
2288 int hash = symbol->GetIdentityHash(); 2306 int hash = symbol->GetIdentityHash();
2289 int hash1 = symbol->GetIdentityHash(); 2307 int hash1 = symbol->GetIdentityHash();
2290 CHECK_EQ(hash, hash1); 2308 CHECK_EQ(hash, hash1);
(...skipping 18784 matching lines...) Expand 10 before | Expand all | Expand 10 after
21075 // add the testExtraShouldReturnFive export 21093 // add the testExtraShouldReturnFive export
21076 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); 21094 v8::Local<v8::Object> exports = env->GetExtrasExportsObject();
21077 21095
21078 auto func = 21096 auto func =
21079 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); 21097 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>();
21080 auto undefined = v8::Undefined(isolate); 21098 auto undefined = v8::Undefined(isolate);
21081 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); 21099 auto result = func->Call(undefined, 0, {}).As<v8::Number>();
21082 21100
21083 CHECK(result->Value() == 5.0); 21101 CHECK(result->Value() == 5.0);
21084 } 21102 }
OLDNEW
« no previous file with comments | « src/x64/macro-assembler-x64.cc ('k') | test/cctest/test-hashing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698