| OLD | NEW |
| 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 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 CompileRun( | 2241 CompileRun( |
| 2242 "function cnst() { return 42; };\n" | 2242 "function cnst() { return 42; };\n" |
| 2243 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); | 2243 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); |
| 2244 Local<v8::Object> o1 = v8::Object::New(isolate); | 2244 Local<v8::Object> o1 = v8::Object::New(isolate); |
| 2245 Local<v8::Object> o2 = v8::Object::New(isolate); | 2245 Local<v8::Object> o2 = v8::Object::New(isolate); |
| 2246 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); | 2246 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); |
| 2247 } | 2247 } |
| 2248 } | 2248 } |
| 2249 | 2249 |
| 2250 | 2250 |
| 2251 THREADED_TEST(GlobalProxyIdentityHash) { | 2251 void GlobalProxyIdentityHash(bool set_in_js) { |
| 2252 LocalContext env; | 2252 LocalContext env; |
| 2253 v8::Isolate* isolate = env->GetIsolate(); | 2253 v8::Isolate* isolate = env->GetIsolate(); |
| 2254 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 2254 v8::HandleScope scope(isolate); | 2255 v8::HandleScope scope(isolate); |
| 2255 Handle<Object> global_proxy = env->Global(); | 2256 Handle<Object> global_proxy = env->Global(); |
| 2256 int hash1 = global_proxy->GetIdentityHash(); | 2257 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy); |
| 2258 env->Global()->Set(v8_str("global"), global_proxy); |
| 2259 i::Handle<i::Object> original_hash; |
| 2260 if (set_in_js) { |
| 2261 CompileRun("var m = new Set(); m.add(global);"); |
| 2262 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate); |
| 2263 } else { |
| 2264 original_hash = i::Handle<i::Object>( |
| 2265 i::Object::GetOrCreateHash(i_isolate, i_global_proxy)); |
| 2266 } |
| 2267 CHECK(original_hash->IsSmi()); |
| 2268 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value(); |
| 2257 // Hash should be retained after being detached. | 2269 // Hash should be retained after being detached. |
| 2258 env->DetachGlobal(); | 2270 env->DetachGlobal(); |
| 2259 int hash2 = global_proxy->GetIdentityHash(); | 2271 int hash2 = global_proxy->GetIdentityHash(); |
| 2260 CHECK_EQ(hash1, hash2); | 2272 CHECK_EQ(hash1, hash2); |
| 2261 { | 2273 { |
| 2262 // Re-attach global proxy to a new context, hash should stay the same. | 2274 // Re-attach global proxy to a new context, hash should stay the same. |
| 2263 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy); | 2275 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy); |
| 2264 int hash3 = global_proxy->GetIdentityHash(); | 2276 int hash3 = global_proxy->GetIdentityHash(); |
| 2265 CHECK_EQ(hash1, hash3); | 2277 CHECK_EQ(hash1, hash3); |
| 2266 } | 2278 } |
| 2267 } | 2279 } |
| 2268 | 2280 |
| 2269 | 2281 |
| 2282 THREADED_TEST(GlobalProxyIdentityHash) { |
| 2283 GlobalProxyIdentityHash(true); |
| 2284 GlobalProxyIdentityHash(false); |
| 2285 } |
| 2286 |
| 2287 |
| 2270 TEST(SymbolIdentityHash) { | 2288 TEST(SymbolIdentityHash) { |
| 2271 LocalContext env; | 2289 LocalContext env; |
| 2272 v8::Isolate* isolate = env->GetIsolate(); | 2290 v8::Isolate* isolate = env->GetIsolate(); |
| 2273 v8::HandleScope scope(isolate); | 2291 v8::HandleScope scope(isolate); |
| 2274 | 2292 |
| 2275 { | 2293 { |
| 2276 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); | 2294 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); |
| 2277 int hash = symbol->GetIdentityHash(); | 2295 int hash = symbol->GetIdentityHash(); |
| 2278 int hash1 = symbol->GetIdentityHash(); | 2296 int hash1 = symbol->GetIdentityHash(); |
| 2279 CHECK_EQ(hash, hash1); | 2297 CHECK_EQ(hash, hash1); |
| (...skipping 18837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21117 // add the testExtraShouldReturnFive export | 21135 // add the testExtraShouldReturnFive export |
| 21118 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); | 21136 v8::Local<v8::Object> exports = env->GetExtrasExportsObject(); |
| 21119 | 21137 |
| 21120 auto func = | 21138 auto func = |
| 21121 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); | 21139 exports->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); |
| 21122 auto undefined = v8::Undefined(isolate); | 21140 auto undefined = v8::Undefined(isolate); |
| 21123 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 21141 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); |
| 21124 | 21142 |
| 21125 CHECK(result->Value() == 5.0); | 21143 CHECK(result->Value() == 5.0); |
| 21126 } | 21144 } |
| OLD | NEW |