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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ApiTestFuzzer::Fuzz(); 137 ApiTestFuzzer::Fuzz();
138 v8::Handle<v8::Array> result = v8::Array::New(args.Length()); 138 v8::Handle<v8::Array> result = v8::Array::New(args.Length());
139 for (int i = 0; i < args.Length(); i++) { 139 for (int i = 0; i < args.Length(); i++) {
140 result->Set(v8::Integer::New(i), args[i]); 140 result->Set(v8::Integer::New(i), args[i]);
141 } 141 }
142 return result; 142 return result;
143 } 143 }
144 144
145 145
146 THREADED_TEST(Handles) { 146 THREADED_TEST(Handles) {
147 v8::HandleScope scope; 147 v8::HandleScope scope(v8::Isolate::GetCurrent());
148 Local<Context> local_env; 148 Local<Context> local_env;
149 { 149 {
150 LocalContext env; 150 LocalContext env;
151 local_env = env.local(); 151 local_env = env.local();
152 } 152 }
153 153
154 // Local context should still be live. 154 // Local context should still be live.
155 CHECK(!local_env.IsEmpty()); 155 CHECK(!local_env.IsEmpty());
156 local_env->Enter(); 156 local_env->Enter();
157 157
158 v8::Handle<v8::Primitive> undef = v8::Undefined(); 158 v8::Handle<v8::Primitive> undef = v8::Undefined();
159 CHECK(!undef.IsEmpty()); 159 CHECK(!undef.IsEmpty());
160 CHECK(undef->IsUndefined()); 160 CHECK(undef->IsUndefined());
161 161
162 const char* c_source = "1 + 2 + 3"; 162 const char* c_source = "1 + 2 + 3";
163 Local<String> source = String::New(c_source); 163 Local<String> source = String::New(c_source);
164 Local<Script> script = Script::Compile(source); 164 Local<Script> script = Script::Compile(source);
165 CHECK_EQ(6, script->Run()->Int32Value()); 165 CHECK_EQ(6, script->Run()->Int32Value());
166 166
167 local_env->Exit(); 167 local_env->Exit();
168 } 168 }
169 169
170 170
171 THREADED_TEST(IsolateOfContext) { 171 THREADED_TEST(IsolateOfContext) {
172 v8::HandleScope scope;
173 v8::Persistent<Context> env = Context::New(); 172 v8::Persistent<Context> env = Context::New();
173 v8::HandleScope scope(env->GetIsolate());
174 174
175 CHECK(!env->InContext()); 175 CHECK(!env->InContext());
176 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 176 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
177 env->Enter(); 177 env->Enter();
178 CHECK(env->InContext()); 178 CHECK(env->InContext());
179 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 179 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
180 env->Exit(); 180 env->Exit();
181 CHECK(!env->InContext()); 181 CHECK(!env->InContext());
182 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent()); 182 CHECK(env->GetIsolate() == v8::Isolate::GetCurrent());
183 183
184 env.Dispose(env->GetIsolate()); 184 env.Dispose(env->GetIsolate());
185 } 185 }
186 186
187 187
188 THREADED_TEST(ReceiverSignature) { 188 THREADED_TEST(ReceiverSignature) {
189 v8::HandleScope scope;
190 LocalContext env; 189 LocalContext env;
190 v8::HandleScope scope(env->GetIsolate());
191 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 191 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
192 v8::Handle<v8::Signature> sig = v8::Signature::New(fun); 192 v8::Handle<v8::Signature> sig = v8::Signature::New(fun);
193 fun->PrototypeTemplate()->Set( 193 fun->PrototypeTemplate()->Set(
194 v8_str("m"), 194 v8_str("m"),
195 v8::FunctionTemplate::New(IncrementingSignatureCallback, 195 v8::FunctionTemplate::New(IncrementingSignatureCallback,
196 v8::Handle<Value>(), 196 v8::Handle<Value>(),
197 sig)); 197 sig));
198 env->Global()->Set(v8_str("Fun"), fun->GetFunction()); 198 env->Global()->Set(v8_str("Fun"), fun->GetFunction());
199 signature_callback_count = 0; 199 signature_callback_count = 0;
200 CompileRun( 200 CompileRun(
(...skipping 22 matching lines...) Expand all
223 CompileRun( 223 CompileRun(
224 "var o = new UnrelFun();" 224 "var o = new UnrelFun();"
225 "o.m = Fun.prototype.m;" 225 "o.m = Fun.prototype.m;"
226 "o.m();"); 226 "o.m();");
227 CHECK_EQ(2, signature_callback_count); 227 CHECK_EQ(2, signature_callback_count);
228 CHECK(try_catch.HasCaught()); 228 CHECK(try_catch.HasCaught());
229 } 229 }
230 230
231 231
232 THREADED_TEST(ArgumentSignature) { 232 THREADED_TEST(ArgumentSignature) {
233 v8::HandleScope scope;
234 LocalContext env; 233 LocalContext env;
234 v8::HandleScope scope(env->GetIsolate());
235 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); 235 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New();
236 cons->SetClassName(v8_str("Cons")); 236 cons->SetClassName(v8_str("Cons"));
237 v8::Handle<v8::Signature> sig = 237 v8::Handle<v8::Signature> sig =
238 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons); 238 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(), 1, &cons);
239 v8::Handle<v8::FunctionTemplate> fun = 239 v8::Handle<v8::FunctionTemplate> fun =
240 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); 240 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig);
241 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); 241 env->Global()->Set(v8_str("Cons"), cons->GetFunction());
242 env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); 242 env->Global()->Set(v8_str("Fun1"), fun->GetFunction());
243 243
244 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';"); 244 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 "'[object Cons1],[object Cons2],[object Cons3],d';"); 285 "'[object Cons1],[object Cons2],[object Cons3],d';");
286 CHECK(value7->IsTrue()); 286 CHECK(value7->IsTrue());
287 287
288 v8::Handle<Value> value8 = CompileRun( 288 v8::Handle<Value> value8 = CompileRun(
289 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'"); 289 "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'");
290 CHECK(value8->IsTrue()); 290 CHECK(value8->IsTrue());
291 } 291 }
292 292
293 293
294 THREADED_TEST(HulIgennem) { 294 THREADED_TEST(HulIgennem) {
295 v8::HandleScope scope;
296 LocalContext env; 295 LocalContext env;
296 v8::HandleScope scope(env->GetIsolate());
297 v8::Handle<v8::Primitive> undef = v8::Undefined(); 297 v8::Handle<v8::Primitive> undef = v8::Undefined();
298 Local<String> undef_str = undef->ToString(); 298 Local<String> undef_str = undef->ToString();
299 char* value = i::NewArray<char>(undef_str->Length() + 1); 299 char* value = i::NewArray<char>(undef_str->Length() + 1);
300 undef_str->WriteAscii(value); 300 undef_str->WriteAscii(value);
301 CHECK_EQ(0, strcmp(value, "undefined")); 301 CHECK_EQ(0, strcmp(value, "undefined"));
302 i::DeleteArray(value); 302 i::DeleteArray(value);
303 } 303 }
304 304
305 305
306 THREADED_TEST(Access) { 306 THREADED_TEST(Access) {
307 v8::HandleScope scope;
308 LocalContext env; 307 LocalContext env;
308 v8::HandleScope scope(env->GetIsolate());
309 Local<v8::Object> obj = v8::Object::New(); 309 Local<v8::Object> obj = v8::Object::New();
310 Local<Value> foo_before = obj->Get(v8_str("foo")); 310 Local<Value> foo_before = obj->Get(v8_str("foo"));
311 CHECK(foo_before->IsUndefined()); 311 CHECK(foo_before->IsUndefined());
312 Local<String> bar_str = v8_str("bar"); 312 Local<String> bar_str = v8_str("bar");
313 obj->Set(v8_str("foo"), bar_str); 313 obj->Set(v8_str("foo"), bar_str);
314 Local<Value> foo_after = obj->Get(v8_str("foo")); 314 Local<Value> foo_after = obj->Get(v8_str("foo"));
315 CHECK(!foo_after->IsUndefined()); 315 CHECK(!foo_after->IsUndefined());
316 CHECK(foo_after->IsString()); 316 CHECK(foo_after->IsString());
317 CHECK_EQ(bar_str, foo_after); 317 CHECK_EQ(bar_str, foo_after);
318 } 318 }
319 319
320 320
321 THREADED_TEST(AccessElement) { 321 THREADED_TEST(AccessElement) {
322 v8::HandleScope scope;
323 LocalContext env; 322 LocalContext env;
323 v8::HandleScope scope(env->GetIsolate());
324 Local<v8::Object> obj = v8::Object::New(); 324 Local<v8::Object> obj = v8::Object::New();
325 Local<Value> before = obj->Get(1); 325 Local<Value> before = obj->Get(1);
326 CHECK(before->IsUndefined()); 326 CHECK(before->IsUndefined());
327 Local<String> bar_str = v8_str("bar"); 327 Local<String> bar_str = v8_str("bar");
328 obj->Set(1, bar_str); 328 obj->Set(1, bar_str);
329 Local<Value> after = obj->Get(1); 329 Local<Value> after = obj->Get(1);
330 CHECK(!after->IsUndefined()); 330 CHECK(!after->IsUndefined());
331 CHECK(after->IsString()); 331 CHECK(after->IsString());
332 CHECK_EQ(bar_str, after); 332 CHECK_EQ(bar_str, after);
333 333
334 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); 334 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>();
335 CHECK_EQ(v8_str("a"), value->Get(0)); 335 CHECK_EQ(v8_str("a"), value->Get(0));
336 CHECK_EQ(v8_str("b"), value->Get(1)); 336 CHECK_EQ(v8_str("b"), value->Get(1));
337 } 337 }
338 338
339 339
340 THREADED_TEST(Script) { 340 THREADED_TEST(Script) {
341 v8::HandleScope scope;
342 LocalContext env; 341 LocalContext env;
342 v8::HandleScope scope(env->GetIsolate());
343 const char* c_source = "1 + 2 + 3"; 343 const char* c_source = "1 + 2 + 3";
344 Local<String> source = String::New(c_source); 344 Local<String> source = String::New(c_source);
345 Local<Script> script = Script::Compile(source); 345 Local<Script> script = Script::Compile(source);
346 CHECK_EQ(6, script->Run()->Int32Value()); 346 CHECK_EQ(6, script->Run()->Int32Value());
347 } 347 }
348 348
349 349
350 static uint16_t* AsciiToTwoByteString(const char* source) { 350 static uint16_t* AsciiToTwoByteString(const char* source) {
351 int array_length = i::StrLength(source) + 1; 351 int array_length = i::StrLength(source) + 1;
352 uint16_t* converted = i::NewArray<uint16_t>(array_length); 352 uint16_t* converted = i::NewArray<uint16_t>(array_length);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 size_t length_; 403 size_t length_;
404 int* counter_; 404 int* counter_;
405 }; 405 };
406 406
407 407
408 THREADED_TEST(ScriptUsingStringResource) { 408 THREADED_TEST(ScriptUsingStringResource) {
409 int dispose_count = 0; 409 int dispose_count = 0;
410 const char* c_source = "1 + 2 * 3"; 410 const char* c_source = "1 + 2 * 3";
411 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 411 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
412 { 412 {
413 v8::HandleScope scope;
414 LocalContext env; 413 LocalContext env;
414 v8::HandleScope scope(env->GetIsolate());
415 TestResource* resource = new TestResource(two_byte_source, &dispose_count); 415 TestResource* resource = new TestResource(two_byte_source, &dispose_count);
416 Local<String> source = String::NewExternal(resource); 416 Local<String> source = String::NewExternal(resource);
417 Local<Script> script = Script::Compile(source); 417 Local<Script> script = Script::Compile(source);
418 Local<Value> value = script->Run(); 418 Local<Value> value = script->Run();
419 CHECK(value->IsNumber()); 419 CHECK(value->IsNumber());
420 CHECK_EQ(7, value->Int32Value()); 420 CHECK_EQ(7, value->Int32Value());
421 CHECK(source->IsExternal()); 421 CHECK(source->IsExternal());
422 CHECK_EQ(resource, 422 CHECK_EQ(resource,
423 static_cast<TestResource*>(source->GetExternalStringResource())); 423 static_cast<TestResource*>(source->GetExternalStringResource()));
424 String::Encoding encoding = String::UNKNOWN_ENCODING; 424 String::Encoding encoding = String::UNKNOWN_ENCODING;
425 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 425 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
426 source->GetExternalStringResourceBase(&encoding)); 426 source->GetExternalStringResourceBase(&encoding));
427 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); 427 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
428 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 428 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
429 CHECK_EQ(0, dispose_count); 429 CHECK_EQ(0, dispose_count);
430 } 430 }
431 v8::internal::Isolate::Current()->compilation_cache()->Clear(); 431 v8::internal::Isolate::Current()->compilation_cache()->Clear();
432 HEAP->CollectAllAvailableGarbage(); 432 HEAP->CollectAllAvailableGarbage();
433 CHECK_EQ(1, dispose_count); 433 CHECK_EQ(1, dispose_count);
434 } 434 }
435 435
436 436
437 THREADED_TEST(ScriptUsingAsciiStringResource) { 437 THREADED_TEST(ScriptUsingAsciiStringResource) {
438 int dispose_count = 0; 438 int dispose_count = 0;
439 const char* c_source = "1 + 2 * 3"; 439 const char* c_source = "1 + 2 * 3";
440 { 440 {
441 v8::HandleScope scope;
442 LocalContext env; 441 LocalContext env;
442 v8::HandleScope scope(env->GetIsolate());
443 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source), 443 TestAsciiResource* resource = new TestAsciiResource(i::StrDup(c_source),
444 &dispose_count); 444 &dispose_count);
445 Local<String> source = String::NewExternal(resource); 445 Local<String> source = String::NewExternal(resource);
446 CHECK(source->IsExternalAscii()); 446 CHECK(source->IsExternalAscii());
447 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 447 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
448 source->GetExternalAsciiStringResource()); 448 source->GetExternalAsciiStringResource());
449 String::Encoding encoding = String::UNKNOWN_ENCODING; 449 String::Encoding encoding = String::UNKNOWN_ENCODING;
450 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 450 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
451 source->GetExternalStringResourceBase(&encoding)); 451 source->GetExternalStringResourceBase(&encoding));
452 CHECK_EQ(String::ASCII_ENCODING, encoding); 452 CHECK_EQ(String::ASCII_ENCODING, encoding);
453 Local<Script> script = Script::Compile(source); 453 Local<Script> script = Script::Compile(source);
454 Local<Value> value = script->Run(); 454 Local<Value> value = script->Run();
455 CHECK(value->IsNumber()); 455 CHECK(value->IsNumber());
456 CHECK_EQ(7, value->Int32Value()); 456 CHECK_EQ(7, value->Int32Value());
457 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 457 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
458 CHECK_EQ(0, dispose_count); 458 CHECK_EQ(0, dispose_count);
459 } 459 }
460 i::Isolate::Current()->compilation_cache()->Clear(); 460 i::Isolate::Current()->compilation_cache()->Clear();
461 HEAP->CollectAllAvailableGarbage(); 461 HEAP->CollectAllAvailableGarbage();
462 CHECK_EQ(1, dispose_count); 462 CHECK_EQ(1, dispose_count);
463 } 463 }
464 464
465 465
466 THREADED_TEST(ScriptMakingExternalString) { 466 THREADED_TEST(ScriptMakingExternalString) {
467 int dispose_count = 0; 467 int dispose_count = 0;
468 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 468 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
469 { 469 {
470 v8::HandleScope scope;
471 LocalContext env; 470 LocalContext env;
471 v8::HandleScope scope(env->GetIsolate());
472 Local<String> source = String::New(two_byte_source); 472 Local<String> source = String::New(two_byte_source);
473 // Trigger GCs so that the newly allocated string moves to old gen. 473 // Trigger GCs so that the newly allocated string moves to old gen.
474 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 474 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
475 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 475 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
476 CHECK_EQ(source->IsExternal(), false); 476 CHECK_EQ(source->IsExternal(), false);
477 CHECK_EQ(source->IsExternalAscii(), false); 477 CHECK_EQ(source->IsExternalAscii(), false);
478 String::Encoding encoding = String::UNKNOWN_ENCODING; 478 String::Encoding encoding = String::UNKNOWN_ENCODING;
479 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding)); 479 CHECK_EQ(NULL, source->GetExternalStringResourceBase(&encoding));
480 CHECK_EQ(String::ASCII_ENCODING, encoding); 480 CHECK_EQ(String::ASCII_ENCODING, encoding);
481 bool success = source->MakeExternal(new TestResource(two_byte_source, 481 bool success = source->MakeExternal(new TestResource(two_byte_source,
482 &dispose_count)); 482 &dispose_count));
483 CHECK(success); 483 CHECK(success);
484 Local<Script> script = Script::Compile(source); 484 Local<Script> script = Script::Compile(source);
485 Local<Value> value = script->Run(); 485 Local<Value> value = script->Run();
486 CHECK(value->IsNumber()); 486 CHECK(value->IsNumber());
487 CHECK_EQ(7, value->Int32Value()); 487 CHECK_EQ(7, value->Int32Value());
488 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 488 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
489 CHECK_EQ(0, dispose_count); 489 CHECK_EQ(0, dispose_count);
490 } 490 }
491 i::Isolate::Current()->compilation_cache()->Clear(); 491 i::Isolate::Current()->compilation_cache()->Clear();
492 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 492 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
493 CHECK_EQ(1, dispose_count); 493 CHECK_EQ(1, dispose_count);
494 } 494 }
495 495
496 496
497 THREADED_TEST(ScriptMakingExternalAsciiString) { 497 THREADED_TEST(ScriptMakingExternalAsciiString) {
498 int dispose_count = 0; 498 int dispose_count = 0;
499 const char* c_source = "1 + 2 * 3"; 499 const char* c_source = "1 + 2 * 3";
500 { 500 {
501 v8::HandleScope scope;
502 LocalContext env; 501 LocalContext env;
502 v8::HandleScope scope(env->GetIsolate());
503 Local<String> source = v8_str(c_source); 503 Local<String> source = v8_str(c_source);
504 // Trigger GCs so that the newly allocated string moves to old gen. 504 // Trigger GCs so that the newly allocated string moves to old gen.
505 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 505 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
506 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 506 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
507 bool success = source->MakeExternal( 507 bool success = source->MakeExternal(
508 new TestAsciiResource(i::StrDup(c_source), &dispose_count)); 508 new TestAsciiResource(i::StrDup(c_source), &dispose_count));
509 CHECK(success); 509 CHECK(success);
510 Local<Script> script = Script::Compile(source); 510 Local<Script> script = Script::Compile(source);
511 Local<Value> value = script->Run(); 511 Local<Value> value = script->Run();
512 CHECK(value->IsNumber()); 512 CHECK(value->IsNumber());
513 CHECK_EQ(7, value->Int32Value()); 513 CHECK_EQ(7, value->Int32Value());
514 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 514 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
515 CHECK_EQ(0, dispose_count); 515 CHECK_EQ(0, dispose_count);
516 } 516 }
517 i::Isolate::Current()->compilation_cache()->Clear(); 517 i::Isolate::Current()->compilation_cache()->Clear();
518 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 518 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
519 CHECK_EQ(1, dispose_count); 519 CHECK_EQ(1, dispose_count);
520 } 520 }
521 521
522 522
523 TEST(MakingExternalStringConditions) { 523 TEST(MakingExternalStringConditions) {
524 v8::HandleScope scope;
525 LocalContext env; 524 LocalContext env;
525 v8::HandleScope scope(env->GetIsolate());
526 526
527 // Free some space in the new space so that we can check freshness. 527 // Free some space in the new space so that we can check freshness.
528 HEAP->CollectGarbage(i::NEW_SPACE); 528 HEAP->CollectGarbage(i::NEW_SPACE);
529 HEAP->CollectGarbage(i::NEW_SPACE); 529 HEAP->CollectGarbage(i::NEW_SPACE);
530 530
531 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); 531 uint16_t* two_byte_string = AsciiToTwoByteString("s1");
532 Local<String> small_string = String::New(two_byte_string); 532 Local<String> small_string = String::New(two_byte_string);
533 i::DeleteArray(two_byte_string); 533 i::DeleteArray(two_byte_string);
534 534
535 // We should refuse to externalize newly created small string. 535 // We should refuse to externalize newly created small string.
(...skipping 24 matching lines...) Expand all
560 two_byte_string = AsciiToTwoByteString(buf); 560 two_byte_string = AsciiToTwoByteString(buf);
561 Local<String> large_string = String::New(two_byte_string); 561 Local<String> large_string = String::New(two_byte_string);
562 i::DeleteArray(buf); 562 i::DeleteArray(buf);
563 i::DeleteArray(two_byte_string); 563 i::DeleteArray(two_byte_string);
564 // Large strings should be immediately accepted. 564 // Large strings should be immediately accepted.
565 CHECK(large_string->CanMakeExternal()); 565 CHECK(large_string->CanMakeExternal());
566 } 566 }
567 567
568 568
569 TEST(MakingExternalAsciiStringConditions) { 569 TEST(MakingExternalAsciiStringConditions) {
570 v8::HandleScope scope;
571 LocalContext env; 570 LocalContext env;
571 v8::HandleScope scope(env->GetIsolate());
572 572
573 // Free some space in the new space so that we can check freshness. 573 // Free some space in the new space so that we can check freshness.
574 HEAP->CollectGarbage(i::NEW_SPACE); 574 HEAP->CollectGarbage(i::NEW_SPACE);
575 HEAP->CollectGarbage(i::NEW_SPACE); 575 HEAP->CollectGarbage(i::NEW_SPACE);
576 576
577 Local<String> small_string = String::New("s1"); 577 Local<String> small_string = String::New("s1");
578 // We should refuse to externalize newly created small string. 578 // We should refuse to externalize newly created small string.
579 CHECK(!small_string->CanMakeExternal()); 579 CHECK(!small_string->CanMakeExternal());
580 // Trigger GCs so that the newly allocated string moves to old gen. 580 // Trigger GCs so that the newly allocated string moves to old gen.
581 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 581 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
(...skipping 16 matching lines...) Expand all
598 buf[buf_size - 1] = '\0'; 598 buf[buf_size - 1] = '\0';
599 Local<String> large_string = String::New(buf); 599 Local<String> large_string = String::New(buf);
600 i::DeleteArray(buf); 600 i::DeleteArray(buf);
601 // Large strings should be immediately accepted. 601 // Large strings should be immediately accepted.
602 CHECK(large_string->CanMakeExternal()); 602 CHECK(large_string->CanMakeExternal());
603 } 603 }
604 604
605 605
606 THREADED_TEST(UsingExternalString) { 606 THREADED_TEST(UsingExternalString) {
607 { 607 {
608 v8::HandleScope scope; 608 v8::HandleScope scope(v8::Isolate::GetCurrent());
609 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 609 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
610 Local<String> string = 610 Local<String> string =
611 String::NewExternal(new TestResource(two_byte_string)); 611 String::NewExternal(new TestResource(two_byte_string));
612 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 612 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
613 // Trigger GCs so that the newly allocated string moves to old gen. 613 // Trigger GCs so that the newly allocated string moves to old gen.
614 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 614 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
615 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 615 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
616 i::Handle<i::String> isymbol = 616 i::Handle<i::String> isymbol =
617 FACTORY->InternalizedStringFromString(istring); 617 FACTORY->InternalizedStringFromString(istring);
618 CHECK(isymbol->IsInternalizedString()); 618 CHECK(isymbol->IsInternalizedString());
619 } 619 }
620 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 620 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
621 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 621 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
622 } 622 }
623 623
624 624
625 THREADED_TEST(UsingExternalAsciiString) { 625 THREADED_TEST(UsingExternalAsciiString) {
626 { 626 {
627 v8::HandleScope scope; 627 v8::HandleScope scope(v8::Isolate::GetCurrent());
628 const char* one_byte_string = "test string"; 628 const char* one_byte_string = "test string";
629 Local<String> string = String::NewExternal( 629 Local<String> string = String::NewExternal(
630 new TestAsciiResource(i::StrDup(one_byte_string))); 630 new TestAsciiResource(i::StrDup(one_byte_string)));
631 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 631 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
632 // Trigger GCs so that the newly allocated string moves to old gen. 632 // Trigger GCs so that the newly allocated string moves to old gen.
633 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now 633 HEAP->CollectGarbage(i::NEW_SPACE); // in survivor space now
634 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now 634 HEAP->CollectGarbage(i::NEW_SPACE); // in old gen now
635 i::Handle<i::String> isymbol = 635 i::Handle<i::String> isymbol =
636 FACTORY->InternalizedStringFromString(istring); 636 FACTORY->InternalizedStringFromString(istring);
637 CHECK(isymbol->IsInternalizedString()); 637 CHECK(isymbol->IsInternalizedString());
638 } 638 }
639 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 639 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
640 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 640 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
641 } 641 }
642 642
643 643
644 THREADED_TEST(ScavengeExternalString) { 644 THREADED_TEST(ScavengeExternalString) {
645 i::FLAG_stress_compaction = false; 645 i::FLAG_stress_compaction = false;
646 i::FLAG_gc_global = false; 646 i::FLAG_gc_global = false;
647 int dispose_count = 0; 647 int dispose_count = 0;
648 bool in_new_space = false; 648 bool in_new_space = false;
649 { 649 {
650 v8::HandleScope scope; 650 v8::HandleScope scope(v8::Isolate::GetCurrent());
651 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 651 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
652 Local<String> string = 652 Local<String> string =
653 String::NewExternal(new TestResource(two_byte_string, 653 String::NewExternal(new TestResource(two_byte_string,
654 &dispose_count)); 654 &dispose_count));
655 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 655 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
656 HEAP->CollectGarbage(i::NEW_SPACE); 656 HEAP->CollectGarbage(i::NEW_SPACE);
657 in_new_space = HEAP->InNewSpace(*istring); 657 in_new_space = HEAP->InNewSpace(*istring);
658 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring)); 658 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring));
659 CHECK_EQ(0, dispose_count); 659 CHECK_EQ(0, dispose_count);
660 } 660 }
661 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 661 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
662 CHECK_EQ(1, dispose_count); 662 CHECK_EQ(1, dispose_count);
663 } 663 }
664 664
665 665
666 THREADED_TEST(ScavengeExternalAsciiString) { 666 THREADED_TEST(ScavengeExternalAsciiString) {
667 i::FLAG_stress_compaction = false; 667 i::FLAG_stress_compaction = false;
668 i::FLAG_gc_global = false; 668 i::FLAG_gc_global = false;
669 int dispose_count = 0; 669 int dispose_count = 0;
670 bool in_new_space = false; 670 bool in_new_space = false;
671 { 671 {
672 v8::HandleScope scope; 672 v8::HandleScope scope(v8::Isolate::GetCurrent());
673 const char* one_byte_string = "test string"; 673 const char* one_byte_string = "test string";
674 Local<String> string = String::NewExternal( 674 Local<String> string = String::NewExternal(
675 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count)); 675 new TestAsciiResource(i::StrDup(one_byte_string), &dispose_count));
676 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 676 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
677 HEAP->CollectGarbage(i::NEW_SPACE); 677 HEAP->CollectGarbage(i::NEW_SPACE);
678 in_new_space = HEAP->InNewSpace(*istring); 678 in_new_space = HEAP->InNewSpace(*istring);
679 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring)); 679 CHECK(in_new_space || HEAP->old_data_space()->Contains(*istring));
680 CHECK_EQ(0, dispose_count); 680 CHECK_EQ(0, dispose_count);
681 } 681 }
682 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE); 682 HEAP->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_DATA_SPACE);
(...skipping 25 matching lines...) Expand all
708 708
709 709
710 TEST(ExternalStringWithDisposeHandling) { 710 TEST(ExternalStringWithDisposeHandling) {
711 const char* c_source = "1 + 2 * 3"; 711 const char* c_source = "1 + 2 * 3";
712 712
713 // Use a stack allocated external string resource allocated object. 713 // Use a stack allocated external string resource allocated object.
714 TestAsciiResourceWithDisposeControl::dispose_count = 0; 714 TestAsciiResourceWithDisposeControl::dispose_count = 0;
715 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 715 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
716 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false); 716 TestAsciiResourceWithDisposeControl res_stack(i::StrDup(c_source), false);
717 { 717 {
718 v8::HandleScope scope;
719 LocalContext env; 718 LocalContext env;
719 v8::HandleScope scope(env->GetIsolate());
720 Local<String> source = String::NewExternal(&res_stack); 720 Local<String> source = String::NewExternal(&res_stack);
721 Local<Script> script = Script::Compile(source); 721 Local<Script> script = Script::Compile(source);
722 Local<Value> value = script->Run(); 722 Local<Value> value = script->Run();
723 CHECK(value->IsNumber()); 723 CHECK(value->IsNumber());
724 CHECK_EQ(7, value->Int32Value()); 724 CHECK_EQ(7, value->Int32Value());
725 HEAP->CollectAllAvailableGarbage(); 725 HEAP->CollectAllAvailableGarbage();
726 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 726 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
727 } 727 }
728 i::Isolate::Current()->compilation_cache()->Clear(); 728 i::Isolate::Current()->compilation_cache()->Clear();
729 HEAP->CollectAllAvailableGarbage(); 729 HEAP->CollectAllAvailableGarbage();
730 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 730 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
731 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 731 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
732 732
733 // Use a heap allocated external string resource allocated object. 733 // Use a heap allocated external string resource allocated object.
734 TestAsciiResourceWithDisposeControl::dispose_count = 0; 734 TestAsciiResourceWithDisposeControl::dispose_count = 0;
735 TestAsciiResourceWithDisposeControl::dispose_calls = 0; 735 TestAsciiResourceWithDisposeControl::dispose_calls = 0;
736 TestAsciiResource* res_heap = 736 TestAsciiResource* res_heap =
737 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true); 737 new TestAsciiResourceWithDisposeControl(i::StrDup(c_source), true);
738 { 738 {
739 v8::HandleScope scope;
740 LocalContext env; 739 LocalContext env;
740 v8::HandleScope scope(env->GetIsolate());
741 Local<String> source = String::NewExternal(res_heap); 741 Local<String> source = String::NewExternal(res_heap);
742 Local<Script> script = Script::Compile(source); 742 Local<Script> script = Script::Compile(source);
743 Local<Value> value = script->Run(); 743 Local<Value> value = script->Run();
744 CHECK(value->IsNumber()); 744 CHECK(value->IsNumber());
745 CHECK_EQ(7, value->Int32Value()); 745 CHECK_EQ(7, value->Int32Value());
746 HEAP->CollectAllAvailableGarbage(); 746 HEAP->CollectAllAvailableGarbage();
747 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count); 747 CHECK_EQ(0, TestAsciiResourceWithDisposeControl::dispose_count);
748 } 748 }
749 i::Isolate::Current()->compilation_cache()->Clear(); 749 i::Isolate::Current()->compilation_cache()->Clear();
750 HEAP->CollectAllAvailableGarbage(); 750 HEAP->CollectAllAvailableGarbage();
751 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls); 751 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_calls);
752 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count); 752 CHECK_EQ(1, TestAsciiResourceWithDisposeControl::dispose_count);
753 } 753 }
754 754
755 755
756 THREADED_TEST(StringConcat) { 756 THREADED_TEST(StringConcat) {
757 { 757 {
758 v8::HandleScope scope;
759 LocalContext env; 758 LocalContext env;
759 v8::HandleScope scope(env->GetIsolate());
760 const char* one_byte_string_1 = "function a_times_t"; 760 const char* one_byte_string_1 = "function a_times_t";
761 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; 761 const char* two_byte_string_1 = "wo_plus_b(a, b) {return ";
762 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; 762 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + ";
763 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; 763 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + ";
764 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; 764 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
765 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; 765 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + ";
766 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; 766 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);";
767 Local<String> left = v8_str(one_byte_string_1); 767 Local<String> left = v8_str(one_byte_string_1);
768 768
769 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); 769 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
(...skipping 23 matching lines...) Expand all
793 CHECK(value->IsNumber()); 793 CHECK(value->IsNumber());
794 CHECK_EQ(68, value->Int32Value()); 794 CHECK_EQ(68, value->Int32Value());
795 } 795 }
796 i::Isolate::Current()->compilation_cache()->Clear(); 796 i::Isolate::Current()->compilation_cache()->Clear();
797 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 797 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
798 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 798 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
799 } 799 }
800 800
801 801
802 THREADED_TEST(GlobalProperties) { 802 THREADED_TEST(GlobalProperties) {
803 v8::HandleScope scope;
804 LocalContext env; 803 LocalContext env;
804 v8::HandleScope scope(env->GetIsolate());
805 v8::Handle<v8::Object> global = env->Global(); 805 v8::Handle<v8::Object> global = env->Global();
806 global->Set(v8_str("pi"), v8_num(3.1415926)); 806 global->Set(v8_str("pi"), v8_num(3.1415926));
807 Local<Value> pi = global->Get(v8_str("pi")); 807 Local<Value> pi = global->Get(v8_str("pi"));
808 CHECK_EQ(3.1415926, pi->NumberValue()); 808 CHECK_EQ(3.1415926, pi->NumberValue());
809 } 809 }
810 810
811 811
812 static v8::Handle<Value> handle_call(const v8::Arguments& args) { 812 static v8::Handle<Value> handle_call(const v8::Arguments& args) {
813 ApiTestFuzzer::Fuzz(); 813 ApiTestFuzzer::Fuzz();
814 return v8_num(102); 814 return v8_num(102);
815 } 815 }
816 816
817 817
818 static v8::Handle<Value> construct_call(const v8::Arguments& args) { 818 static v8::Handle<Value> construct_call(const v8::Arguments& args) {
819 ApiTestFuzzer::Fuzz(); 819 ApiTestFuzzer::Fuzz();
820 args.This()->Set(v8_str("x"), v8_num(1)); 820 args.This()->Set(v8_str("x"), v8_num(1));
821 args.This()->Set(v8_str("y"), v8_num(2)); 821 args.This()->Set(v8_str("y"), v8_num(2));
822 return args.This(); 822 return args.This();
823 } 823 }
824 824
825 static v8::Handle<Value> Return239(Local<String> name, const AccessorInfo&) { 825 static v8::Handle<Value> Return239(Local<String> name, const AccessorInfo&) {
826 ApiTestFuzzer::Fuzz(); 826 ApiTestFuzzer::Fuzz();
827 return v8_num(239); 827 return v8_num(239);
828 } 828 }
829 829
830 830
831 THREADED_TEST(FunctionTemplate) { 831 THREADED_TEST(FunctionTemplate) {
832 v8::HandleScope scope;
833 LocalContext env; 832 LocalContext env;
833 v8::HandleScope scope(env->GetIsolate());
834 { 834 {
835 Local<v8::FunctionTemplate> fun_templ = 835 Local<v8::FunctionTemplate> fun_templ =
836 v8::FunctionTemplate::New(handle_call); 836 v8::FunctionTemplate::New(handle_call);
837 Local<Function> fun = fun_templ->GetFunction(); 837 Local<Function> fun = fun_templ->GetFunction();
838 env->Global()->Set(v8_str("obj"), fun); 838 env->Global()->Set(v8_str("obj"), fun);
839 Local<Script> script = v8_compile("obj()"); 839 Local<Script> script = v8_compile("obj()");
840 CHECK_EQ(102, script->Run()->Int32Value()); 840 CHECK_EQ(102, script->Run()->Int32Value());
841 } 841 }
842 // Use SetCallHandler to initialize a function template, should work like the 842 // Use SetCallHandler to initialize a function template, should work like the
843 // previous one. 843 // previous one.
(...skipping 19 matching lines...) Expand all
863 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 863 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
864 CHECK_EQ(v8_str("[object funky]"), result); 864 CHECK_EQ(v8_str("[object funky]"), result);
865 865
866 result = v8_compile("(new obj()).m")->Run(); 866 result = v8_compile("(new obj()).m")->Run();
867 CHECK_EQ(239, result->Int32Value()); 867 CHECK_EQ(239, result->Int32Value());
868 } 868 }
869 } 869 }
870 870
871 871
872 THREADED_TEST(FunctionTemplateSetLength) { 872 THREADED_TEST(FunctionTemplateSetLength) {
873 v8::HandleScope scope;
874 LocalContext env; 873 LocalContext env;
874 v8::HandleScope scope(env->GetIsolate());
875 { 875 {
876 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( 876 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(
877 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23); 877 handle_call, Handle<v8::Value>(), Handle<v8::Signature>(), 23);
878 Local<Function> fun = fun_templ->GetFunction(); 878 Local<Function> fun = fun_templ->GetFunction();
879 env->Global()->Set(v8_str("obj"), fun); 879 env->Global()->Set(v8_str("obj"), fun);
880 Local<Script> script = v8_compile("obj.length"); 880 Local<Script> script = v8_compile("obj.length");
881 CHECK_EQ(23, script->Run()->Int32Value()); 881 CHECK_EQ(23, script->Run()->Int32Value());
882 } 882 }
883 { 883 {
884 Local<v8::FunctionTemplate> fun_templ = 884 Local<v8::FunctionTemplate> fun_templ =
(...skipping 18 matching lines...) Expand all
903 903
904 static void* expected_ptr; 904 static void* expected_ptr;
905 static v8::Handle<v8::Value> callback(const v8::Arguments& args) { 905 static v8::Handle<v8::Value> callback(const v8::Arguments& args) {
906 void* ptr = v8::External::Cast(*args.Data())->Value(); 906 void* ptr = v8::External::Cast(*args.Data())->Value();
907 CHECK_EQ(expected_ptr, ptr); 907 CHECK_EQ(expected_ptr, ptr);
908 return v8::True(); 908 return v8::True();
909 } 909 }
910 910
911 911
912 static void TestExternalPointerWrapping() { 912 static void TestExternalPointerWrapping() {
913 v8::HandleScope scope;
914 LocalContext env; 913 LocalContext env;
914 v8::HandleScope scope(env->GetIsolate());
915 915
916 v8::Handle<v8::Value> data = v8::External::New(expected_ptr); 916 v8::Handle<v8::Value> data = v8::External::New(expected_ptr);
917 917
918 v8::Handle<v8::Object> obj = v8::Object::New(); 918 v8::Handle<v8::Object> obj = v8::Object::New();
919 obj->Set(v8_str("func"), 919 obj->Set(v8_str("func"),
920 v8::FunctionTemplate::New(callback, data)->GetFunction()); 920 v8::FunctionTemplate::New(callback, data)->GetFunction());
921 env->Global()->Set(v8_str("obj"), obj); 921 env->Global()->Set(v8_str("obj"), obj);
922 922
923 CHECK(CompileRun( 923 CHECK(CompileRun(
924 "function foo() {\n" 924 "function foo() {\n"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef); 968 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef);
969 TestExternalPointerWrapping(); 969 TestExternalPointerWrapping();
970 970
971 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1); 971 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
972 TestExternalPointerWrapping(); 972 TestExternalPointerWrapping();
973 #endif 973 #endif
974 } 974 }
975 975
976 976
977 THREADED_TEST(FindInstanceInPrototypeChain) { 977 THREADED_TEST(FindInstanceInPrototypeChain) {
978 v8::HandleScope scope;
979 LocalContext env; 978 LocalContext env;
979 v8::HandleScope scope(env->GetIsolate());
980 980
981 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); 981 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New();
982 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); 982 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New();
983 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); 983 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New();
984 derived->Inherit(base); 984 derived->Inherit(base);
985 985
986 Local<v8::Function> base_function = base->GetFunction(); 986 Local<v8::Function> base_function = base->GetFunction();
987 Local<v8::Function> derived_function = derived->GetFunction(); 987 Local<v8::Function> derived_function = derived->GetFunction();
988 Local<v8::Function> other_function = other->GetFunction(); 988 Local<v8::Function> other_function = other->GetFunction();
989 989
(...skipping 25 matching lines...) Expand all
1015 CHECK_EQ(derived_instance2, 1015 CHECK_EQ(derived_instance2,
1016 other_instance->FindInstanceInPrototypeChain(base)); 1016 other_instance->FindInstanceInPrototypeChain(base));
1017 CHECK_EQ(derived_instance2, 1017 CHECK_EQ(derived_instance2,
1018 other_instance->FindInstanceInPrototypeChain(derived)); 1018 other_instance->FindInstanceInPrototypeChain(derived));
1019 CHECK_EQ(other_instance, 1019 CHECK_EQ(other_instance,
1020 other_instance->FindInstanceInPrototypeChain(other)); 1020 other_instance->FindInstanceInPrototypeChain(other));
1021 } 1021 }
1022 1022
1023 1023
1024 THREADED_TEST(TinyInteger) { 1024 THREADED_TEST(TinyInteger) {
1025 v8::HandleScope scope;
1026 LocalContext env; 1025 LocalContext env;
1026 v8::HandleScope scope(env->GetIsolate());
1027 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1027 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1028 1028
1029 int32_t value = 239; 1029 int32_t value = 239;
1030 Local<v8::Integer> value_obj = v8::Integer::New(value); 1030 Local<v8::Integer> value_obj = v8::Integer::New(value);
1031 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1031 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1032 1032
1033 value_obj = v8::Integer::New(value, isolate); 1033 value_obj = v8::Integer::New(value, isolate);
1034 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1034 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1035 } 1035 }
1036 1036
1037 1037
1038 THREADED_TEST(BigSmiInteger) { 1038 THREADED_TEST(BigSmiInteger) {
1039 v8::HandleScope scope;
1040 LocalContext env; 1039 LocalContext env;
1040 v8::HandleScope scope(env->GetIsolate());
1041 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1041 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1042 1042
1043 int32_t value = i::Smi::kMaxValue; 1043 int32_t value = i::Smi::kMaxValue;
1044 // We cannot add one to a Smi::kMaxValue without wrapping. 1044 // We cannot add one to a Smi::kMaxValue without wrapping.
1045 if (i::kSmiValueSize < 32) { 1045 if (i::kSmiValueSize < 32) {
1046 CHECK(i::Smi::IsValid(value)); 1046 CHECK(i::Smi::IsValid(value));
1047 CHECK(!i::Smi::IsValid(value + 1)); 1047 CHECK(!i::Smi::IsValid(value + 1));
1048 1048
1049 Local<v8::Integer> value_obj = v8::Integer::New(value); 1049 Local<v8::Integer> value_obj = v8::Integer::New(value);
1050 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1050 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1051 1051
1052 value_obj = v8::Integer::New(value, isolate); 1052 value_obj = v8::Integer::New(value, isolate);
1053 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1053 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1054 } 1054 }
1055 } 1055 }
1056 1056
1057 1057
1058 THREADED_TEST(BigInteger) { 1058 THREADED_TEST(BigInteger) {
1059 v8::HandleScope scope;
1060 LocalContext env; 1059 LocalContext env;
1060 v8::HandleScope scope(env->GetIsolate());
1061 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1061 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1062 1062
1063 // We cannot add one to a Smi::kMaxValue without wrapping. 1063 // We cannot add one to a Smi::kMaxValue without wrapping.
1064 if (i::kSmiValueSize < 32) { 1064 if (i::kSmiValueSize < 32) {
1065 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1. 1065 // The casts allow this to compile, even if Smi::kMaxValue is 2^31-1.
1066 // The code will not be run in that case, due to the "if" guard. 1066 // The code will not be run in that case, due to the "if" guard.
1067 int32_t value = 1067 int32_t value =
1068 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1); 1068 static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1);
1069 CHECK(value > i::Smi::kMaxValue); 1069 CHECK(value > i::Smi::kMaxValue);
1070 CHECK(!i::Smi::IsValid(value)); 1070 CHECK(!i::Smi::IsValid(value));
1071 1071
1072 Local<v8::Integer> value_obj = v8::Integer::New(value); 1072 Local<v8::Integer> value_obj = v8::Integer::New(value);
1073 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1073 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1074 1074
1075 value_obj = v8::Integer::New(value, isolate); 1075 value_obj = v8::Integer::New(value, isolate);
1076 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1076 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1077 } 1077 }
1078 } 1078 }
1079 1079
1080 1080
1081 THREADED_TEST(TinyUnsignedInteger) { 1081 THREADED_TEST(TinyUnsignedInteger) {
1082 v8::HandleScope scope;
1083 LocalContext env; 1082 LocalContext env;
1083 v8::HandleScope scope(env->GetIsolate());
1084 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1084 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1085 1085
1086 uint32_t value = 239; 1086 uint32_t value = 239;
1087 1087
1088 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1088 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1089 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1089 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1090 1090
1091 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1091 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1092 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1092 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1093 } 1093 }
1094 1094
1095 1095
1096 THREADED_TEST(BigUnsignedSmiInteger) { 1096 THREADED_TEST(BigUnsignedSmiInteger) {
1097 v8::HandleScope scope;
1098 LocalContext env; 1097 LocalContext env;
1098 v8::HandleScope scope(env->GetIsolate());
1099 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1099 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1100 1100
1101 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue); 1101 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue);
1102 CHECK(i::Smi::IsValid(value)); 1102 CHECK(i::Smi::IsValid(value));
1103 CHECK(!i::Smi::IsValid(value + 1)); 1103 CHECK(!i::Smi::IsValid(value + 1));
1104 1104
1105 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1105 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1106 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1106 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1107 1107
1108 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1108 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1109 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1109 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1110 } 1110 }
1111 1111
1112 1112
1113 THREADED_TEST(BigUnsignedInteger) { 1113 THREADED_TEST(BigUnsignedInteger) {
1114 v8::HandleScope scope;
1115 LocalContext env; 1114 LocalContext env;
1115 v8::HandleScope scope(env->GetIsolate());
1116 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1116 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1117 1117
1118 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1; 1118 uint32_t value = static_cast<uint32_t>(i::Smi::kMaxValue) + 1;
1119 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue)); 1119 CHECK(value > static_cast<uint32_t>(i::Smi::kMaxValue));
1120 CHECK(!i::Smi::IsValid(value)); 1120 CHECK(!i::Smi::IsValid(value));
1121 1121
1122 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1122 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1123 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1123 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1124 1124
1125 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1125 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1126 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1126 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1127 } 1127 }
1128 1128
1129 1129
1130 THREADED_TEST(OutOfSignedRangeUnsignedInteger) { 1130 THREADED_TEST(OutOfSignedRangeUnsignedInteger) {
1131 v8::HandleScope scope;
1132 LocalContext env; 1131 LocalContext env;
1132 v8::HandleScope scope(env->GetIsolate());
1133 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 1133 v8::Isolate* isolate = v8::Isolate::GetCurrent();
1134 1134
1135 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; 1135 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1;
1136 uint32_t value = INT32_MAX_AS_UINT + 1; 1136 uint32_t value = INT32_MAX_AS_UINT + 1;
1137 CHECK(value > INT32_MAX_AS_UINT); // No overflow. 1137 CHECK(value > INT32_MAX_AS_UINT); // No overflow.
1138 1138
1139 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); 1139 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value);
1140 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1140 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1141 1141
1142 value_obj = v8::Integer::NewFromUnsigned(value, isolate); 1142 value_obj = v8::Integer::NewFromUnsigned(value, isolate);
1143 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1143 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1144 } 1144 }
1145 1145
1146 1146
1147 THREADED_TEST(IsNativeError) { 1147 THREADED_TEST(IsNativeError) {
1148 v8::HandleScope scope;
1149 LocalContext env; 1148 LocalContext env;
1149 v8::HandleScope scope(env->GetIsolate());
1150 v8::Handle<Value> syntax_error = CompileRun( 1150 v8::Handle<Value> syntax_error = CompileRun(
1151 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); 1151 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1152 CHECK(syntax_error->IsNativeError()); 1152 CHECK(syntax_error->IsNativeError());
1153 v8::Handle<Value> not_error = CompileRun("{a:42}"); 1153 v8::Handle<Value> not_error = CompileRun("{a:42}");
1154 CHECK(!not_error->IsNativeError()); 1154 CHECK(!not_error->IsNativeError());
1155 v8::Handle<Value> not_object = CompileRun("42"); 1155 v8::Handle<Value> not_object = CompileRun("42");
1156 CHECK(!not_object->IsNativeError()); 1156 CHECK(!not_object->IsNativeError());
1157 } 1157 }
1158 1158
1159 1159
1160 THREADED_TEST(StringObject) { 1160 THREADED_TEST(StringObject) {
1161 v8::HandleScope scope;
1162 LocalContext env; 1161 LocalContext env;
1162 v8::HandleScope scope(env->GetIsolate());
1163 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); 1163 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")");
1164 CHECK(boxed_string->IsStringObject()); 1164 CHECK(boxed_string->IsStringObject());
1165 v8::Handle<Value> unboxed_string = CompileRun("\"test\""); 1165 v8::Handle<Value> unboxed_string = CompileRun("\"test\"");
1166 CHECK(!unboxed_string->IsStringObject()); 1166 CHECK(!unboxed_string->IsStringObject());
1167 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)"); 1167 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)");
1168 CHECK(!boxed_not_string->IsStringObject()); 1168 CHECK(!boxed_not_string->IsStringObject());
1169 v8::Handle<Value> not_object = CompileRun("0"); 1169 v8::Handle<Value> not_object = CompileRun("0");
1170 CHECK(!not_object->IsStringObject()); 1170 CHECK(!not_object->IsStringObject());
1171 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>(); 1171 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>();
1172 CHECK(!as_boxed.IsEmpty()); 1172 CHECK(!as_boxed.IsEmpty());
1173 Local<v8::String> the_string = as_boxed->StringValue(); 1173 Local<v8::String> the_string = as_boxed->StringValue();
1174 CHECK(!the_string.IsEmpty()); 1174 CHECK(!the_string.IsEmpty());
1175 ExpectObject("\"test\"", the_string); 1175 ExpectObject("\"test\"", the_string);
1176 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string); 1176 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string);
1177 CHECK(new_boxed_string->IsStringObject()); 1177 CHECK(new_boxed_string->IsStringObject());
1178 as_boxed = new_boxed_string.As<v8::StringObject>(); 1178 as_boxed = new_boxed_string.As<v8::StringObject>();
1179 the_string = as_boxed->StringValue(); 1179 the_string = as_boxed->StringValue();
1180 CHECK(!the_string.IsEmpty()); 1180 CHECK(!the_string.IsEmpty());
1181 ExpectObject("\"test\"", the_string); 1181 ExpectObject("\"test\"", the_string);
1182 } 1182 }
1183 1183
1184 1184
1185 THREADED_TEST(NumberObject) { 1185 THREADED_TEST(NumberObject) {
1186 v8::HandleScope scope;
1187 LocalContext env; 1186 LocalContext env;
1187 v8::HandleScope scope(env->GetIsolate());
1188 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); 1188 v8::Handle<Value> boxed_number = CompileRun("new Number(42)");
1189 CHECK(boxed_number->IsNumberObject()); 1189 CHECK(boxed_number->IsNumberObject());
1190 v8::Handle<Value> unboxed_number = CompileRun("42"); 1190 v8::Handle<Value> unboxed_number = CompileRun("42");
1191 CHECK(!unboxed_number->IsNumberObject()); 1191 CHECK(!unboxed_number->IsNumberObject());
1192 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); 1192 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)");
1193 CHECK(!boxed_not_number->IsNumberObject()); 1193 CHECK(!boxed_not_number->IsNumberObject());
1194 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); 1194 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>();
1195 CHECK(!as_boxed.IsEmpty()); 1195 CHECK(!as_boxed.IsEmpty());
1196 double the_number = as_boxed->NumberValue(); 1196 double the_number = as_boxed->NumberValue();
1197 CHECK_EQ(42.0, the_number); 1197 CHECK_EQ(42.0, the_number);
1198 v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43); 1198 v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43);
1199 CHECK(new_boxed_number->IsNumberObject()); 1199 CHECK(new_boxed_number->IsNumberObject());
1200 as_boxed = new_boxed_number.As<v8::NumberObject>(); 1200 as_boxed = new_boxed_number.As<v8::NumberObject>();
1201 the_number = as_boxed->NumberValue(); 1201 the_number = as_boxed->NumberValue();
1202 CHECK_EQ(43.0, the_number); 1202 CHECK_EQ(43.0, the_number);
1203 } 1203 }
1204 1204
1205 1205
1206 THREADED_TEST(BooleanObject) { 1206 THREADED_TEST(BooleanObject) {
1207 v8::HandleScope scope;
1208 LocalContext env; 1207 LocalContext env;
1208 v8::HandleScope scope(env->GetIsolate());
1209 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)"); 1209 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)");
1210 CHECK(boxed_boolean->IsBooleanObject()); 1210 CHECK(boxed_boolean->IsBooleanObject());
1211 v8::Handle<Value> unboxed_boolean = CompileRun("true"); 1211 v8::Handle<Value> unboxed_boolean = CompileRun("true");
1212 CHECK(!unboxed_boolean->IsBooleanObject()); 1212 CHECK(!unboxed_boolean->IsBooleanObject());
1213 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)"); 1213 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)");
1214 CHECK(!boxed_not_boolean->IsBooleanObject()); 1214 CHECK(!boxed_not_boolean->IsBooleanObject());
1215 v8::Handle<v8::BooleanObject> as_boxed = 1215 v8::Handle<v8::BooleanObject> as_boxed =
1216 boxed_boolean.As<v8::BooleanObject>(); 1216 boxed_boolean.As<v8::BooleanObject>();
1217 CHECK(!as_boxed.IsEmpty()); 1217 CHECK(!as_boxed.IsEmpty());
1218 bool the_boolean = as_boxed->BooleanValue(); 1218 bool the_boolean = as_boxed->BooleanValue();
1219 CHECK_EQ(true, the_boolean); 1219 CHECK_EQ(true, the_boolean);
1220 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true); 1220 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true);
1221 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false); 1221 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false);
1222 CHECK(boxed_true->IsBooleanObject()); 1222 CHECK(boxed_true->IsBooleanObject());
1223 CHECK(boxed_false->IsBooleanObject()); 1223 CHECK(boxed_false->IsBooleanObject());
1224 as_boxed = boxed_true.As<v8::BooleanObject>(); 1224 as_boxed = boxed_true.As<v8::BooleanObject>();
1225 CHECK_EQ(true, as_boxed->BooleanValue()); 1225 CHECK_EQ(true, as_boxed->BooleanValue());
1226 as_boxed = boxed_false.As<v8::BooleanObject>(); 1226 as_boxed = boxed_false.As<v8::BooleanObject>();
1227 CHECK_EQ(false, as_boxed->BooleanValue()); 1227 CHECK_EQ(false, as_boxed->BooleanValue());
1228 } 1228 }
1229 1229
1230 1230
1231 THREADED_TEST(Number) { 1231 THREADED_TEST(Number) {
1232 v8::HandleScope scope;
1233 LocalContext env; 1232 LocalContext env;
1233 v8::HandleScope scope(env->GetIsolate());
1234 double PI = 3.1415926; 1234 double PI = 3.1415926;
1235 Local<v8::Number> pi_obj = v8::Number::New(PI); 1235 Local<v8::Number> pi_obj = v8::Number::New(PI);
1236 CHECK_EQ(PI, pi_obj->NumberValue()); 1236 CHECK_EQ(PI, pi_obj->NumberValue());
1237 } 1237 }
1238 1238
1239 1239
1240 THREADED_TEST(ToNumber) { 1240 THREADED_TEST(ToNumber) {
1241 v8::HandleScope scope;
1242 LocalContext env; 1241 LocalContext env;
1242 v8::HandleScope scope(env->GetIsolate());
1243 Local<String> str = v8_str("3.1415926"); 1243 Local<String> str = v8_str("3.1415926");
1244 CHECK_EQ(3.1415926, str->NumberValue()); 1244 CHECK_EQ(3.1415926, str->NumberValue());
1245 v8::Handle<v8::Boolean> t = v8::True(); 1245 v8::Handle<v8::Boolean> t = v8::True();
1246 CHECK_EQ(1.0, t->NumberValue()); 1246 CHECK_EQ(1.0, t->NumberValue());
1247 v8::Handle<v8::Boolean> f = v8::False(); 1247 v8::Handle<v8::Boolean> f = v8::False();
1248 CHECK_EQ(0.0, f->NumberValue()); 1248 CHECK_EQ(0.0, f->NumberValue());
1249 } 1249 }
1250 1250
1251 1251
1252 THREADED_TEST(Date) { 1252 THREADED_TEST(Date) {
1253 v8::HandleScope scope;
1254 LocalContext env; 1253 LocalContext env;
1254 v8::HandleScope scope(env->GetIsolate());
1255 double PI = 3.1415926; 1255 double PI = 3.1415926;
1256 Local<Value> date = v8::Date::New(PI); 1256 Local<Value> date = v8::Date::New(PI);
1257 CHECK_EQ(3.0, date->NumberValue()); 1257 CHECK_EQ(3.0, date->NumberValue());
1258 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42)); 1258 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42));
1259 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); 1259 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value());
1260 } 1260 }
1261 1261
1262 1262
1263 THREADED_TEST(Boolean) { 1263 THREADED_TEST(Boolean) {
1264 v8::HandleScope scope;
1265 LocalContext env; 1264 LocalContext env;
1265 v8::HandleScope scope(env->GetIsolate());
1266 v8::Handle<v8::Boolean> t = v8::True(); 1266 v8::Handle<v8::Boolean> t = v8::True();
1267 CHECK(t->Value()); 1267 CHECK(t->Value());
1268 v8::Handle<v8::Boolean> f = v8::False(); 1268 v8::Handle<v8::Boolean> f = v8::False();
1269 CHECK(!f->Value()); 1269 CHECK(!f->Value());
1270 v8::Handle<v8::Primitive> u = v8::Undefined(); 1270 v8::Handle<v8::Primitive> u = v8::Undefined();
1271 CHECK(!u->BooleanValue()); 1271 CHECK(!u->BooleanValue());
1272 v8::Handle<v8::Primitive> n = v8::Null(); 1272 v8::Handle<v8::Primitive> n = v8::Null();
1273 CHECK(!n->BooleanValue()); 1273 CHECK(!n->BooleanValue());
1274 v8::Handle<String> str1 = v8_str(""); 1274 v8::Handle<String> str1 = v8_str("");
1275 CHECK(!str1->BooleanValue()); 1275 CHECK(!str1->BooleanValue());
(...skipping 13 matching lines...) Expand all
1289 } 1289 }
1290 1290
1291 1291
1292 static v8::Handle<Value> GetM(Local<String> name, const AccessorInfo&) { 1292 static v8::Handle<Value> GetM(Local<String> name, const AccessorInfo&) {
1293 ApiTestFuzzer::Fuzz(); 1293 ApiTestFuzzer::Fuzz();
1294 return v8_num(876); 1294 return v8_num(876);
1295 } 1295 }
1296 1296
1297 1297
1298 THREADED_TEST(GlobalPrototype) { 1298 THREADED_TEST(GlobalPrototype) {
1299 v8::HandleScope scope; 1299 v8::HandleScope scope(v8::Isolate::GetCurrent());
1300 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 1300 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
1301 func_templ->PrototypeTemplate()->Set( 1301 func_templ->PrototypeTemplate()->Set(
1302 "dummy", 1302 "dummy",
1303 v8::FunctionTemplate::New(DummyCallHandler)); 1303 v8::FunctionTemplate::New(DummyCallHandler));
1304 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1304 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate();
1305 templ->Set("x", v8_num(200)); 1305 templ->Set("x", v8_num(200));
1306 templ->SetAccessor(v8_str("m"), GetM); 1306 templ->SetAccessor(v8_str("m"), GetM);
1307 LocalContext env(0, templ); 1307 LocalContext env(0, templ);
1308 v8::Handle<Script> script(v8_compile("dummy()")); 1308 v8::Handle<Script> script(v8_compile("dummy()"));
1309 v8::Handle<Value> result(script->Run()); 1309 v8::Handle<Value> result(script->Run());
1310 CHECK_EQ(13.4, result->NumberValue()); 1310 CHECK_EQ(13.4, result->NumberValue());
1311 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1311 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value());
1312 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1312 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value());
1313 } 1313 }
1314 1314
1315 1315
1316 THREADED_TEST(ObjectTemplate) { 1316 THREADED_TEST(ObjectTemplate) {
1317 v8::HandleScope scope; 1317 v8::HandleScope scope(v8::Isolate::GetCurrent());
1318 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); 1318 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1319 templ1->Set("x", v8_num(10)); 1319 templ1->Set("x", v8_num(10));
1320 templ1->Set("y", v8_num(13)); 1320 templ1->Set("y", v8_num(13));
1321 LocalContext env; 1321 LocalContext env;
1322 Local<v8::Object> instance1 = templ1->NewInstance(); 1322 Local<v8::Object> instance1 = templ1->NewInstance();
1323 env->Global()->Set(v8_str("p"), instance1); 1323 env->Global()->Set(v8_str("p"), instance1);
1324 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1324 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
1325 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1325 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
1326 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 1326 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New();
1327 fun->PrototypeTemplate()->Set("nirk", v8_num(123)); 1327 fun->PrototypeTemplate()->Set("nirk", v8_num(123));
(...skipping 15 matching lines...) Expand all
1343 } 1343 }
1344 1344
1345 1345
1346 static v8::Handle<Value> GetKnurd(Local<String> property, const AccessorInfo&) { 1346 static v8::Handle<Value> GetKnurd(Local<String> property, const AccessorInfo&) {
1347 ApiTestFuzzer::Fuzz(); 1347 ApiTestFuzzer::Fuzz();
1348 return v8_num(15.2); 1348 return v8_num(15.2);
1349 } 1349 }
1350 1350
1351 1351
1352 THREADED_TEST(DescriptorInheritance) { 1352 THREADED_TEST(DescriptorInheritance) {
1353 v8::HandleScope scope; 1353 v8::HandleScope scope(v8::Isolate::GetCurrent());
1354 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); 1354 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New();
1355 super->PrototypeTemplate()->Set("flabby", 1355 super->PrototypeTemplate()->Set("flabby",
1356 v8::FunctionTemplate::New(GetFlabby)); 1356 v8::FunctionTemplate::New(GetFlabby));
1357 super->PrototypeTemplate()->Set("PI", v8_num(3.14)); 1357 super->PrototypeTemplate()->Set("PI", v8_num(3.14));
1358 1358
1359 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); 1359 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd);
1360 1360
1361 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(); 1361 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New();
1362 base1->Inherit(super); 1362 base1->Inherit(super);
1363 base1->PrototypeTemplate()->Set("v1", v8_num(20.1)); 1363 base1->PrototypeTemplate()->Set("v1", v8_num(20.1));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 templ->PrototypeTemplate()->SetAccessor(name, getter, setter); 1474 templ->PrototypeTemplate()->SetAccessor(name, getter, setter);
1475 } 1475 }
1476 1476
1477 void AddInterceptor(Handle<FunctionTemplate> templ, 1477 void AddInterceptor(Handle<FunctionTemplate> templ,
1478 v8::NamedPropertyGetter getter, 1478 v8::NamedPropertyGetter getter,
1479 v8::NamedPropertySetter setter) { 1479 v8::NamedPropertySetter setter) {
1480 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); 1480 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1481 } 1481 }
1482 1482
1483 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { 1483 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) {
1484 v8::HandleScope scope; 1484 v8::HandleScope scope(v8::Isolate::GetCurrent());
1485 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1485 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1486 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1486 Handle<FunctionTemplate> child = FunctionTemplate::New();
1487 child->Inherit(parent); 1487 child->Inherit(parent);
1488 AddAccessor(parent, v8_str("age"), 1488 AddAccessor(parent, v8_str("age"),
1489 SimpleAccessorGetter, SimpleAccessorSetter); 1489 SimpleAccessorGetter, SimpleAccessorSetter);
1490 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1490 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1491 LocalContext env; 1491 LocalContext env;
1492 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1492 env->Global()->Set(v8_str("Child"), child->GetFunction());
1493 CompileRun("var child = new Child;" 1493 CompileRun("var child = new Child;"
1494 "child.age = 10;"); 1494 "child.age = 10;");
1495 ExpectBoolean("child.hasOwnProperty('age')", false); 1495 ExpectBoolean("child.hasOwnProperty('age')", false);
1496 ExpectInt32("child.age", 10); 1496 ExpectInt32("child.age", 10);
1497 ExpectInt32("child.accessor_age", 10); 1497 ExpectInt32("child.accessor_age", 10);
1498 } 1498 }
1499 1499
1500 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) { 1500 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) {
1501 v8::HandleScope scope; 1501 v8::HandleScope scope(v8::Isolate::GetCurrent());
1502 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1502 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1503 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1503 Handle<FunctionTemplate> child = FunctionTemplate::New();
1504 child->Inherit(parent); 1504 child->Inherit(parent);
1505 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1505 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1506 LocalContext env; 1506 LocalContext env;
1507 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1507 env->Global()->Set(v8_str("Child"), child->GetFunction());
1508 CompileRun("var child = new Child;" 1508 CompileRun("var child = new Child;"
1509 "var parent = child.__proto__;" 1509 "var parent = child.__proto__;"
1510 "Object.defineProperty(parent, 'age', " 1510 "Object.defineProperty(parent, 'age', "
1511 " {get: function(){ return this.accessor_age; }, " 1511 " {get: function(){ return this.accessor_age; }, "
1512 " set: function(v){ this.accessor_age = v; }, " 1512 " set: function(v){ this.accessor_age = v; }, "
1513 " enumerable: true, configurable: true});" 1513 " enumerable: true, configurable: true});"
1514 "child.age = 10;"); 1514 "child.age = 10;");
1515 ExpectBoolean("child.hasOwnProperty('age')", false); 1515 ExpectBoolean("child.hasOwnProperty('age')", false);
1516 ExpectInt32("child.age", 10); 1516 ExpectInt32("child.age", 10);
1517 ExpectInt32("child.accessor_age", 10); 1517 ExpectInt32("child.accessor_age", 10);
1518 } 1518 }
1519 1519
1520 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) { 1520 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) {
1521 v8::HandleScope scope; 1521 v8::HandleScope scope(v8::Isolate::GetCurrent());
1522 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1522 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1523 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1523 Handle<FunctionTemplate> child = FunctionTemplate::New();
1524 child->Inherit(parent); 1524 child->Inherit(parent);
1525 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1525 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1526 LocalContext env; 1526 LocalContext env;
1527 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1527 env->Global()->Set(v8_str("Child"), child->GetFunction());
1528 CompileRun("var child = new Child;" 1528 CompileRun("var child = new Child;"
1529 "var parent = child.__proto__;" 1529 "var parent = child.__proto__;"
1530 "parent.name = 'Alice';"); 1530 "parent.name = 'Alice';");
1531 ExpectBoolean("child.hasOwnProperty('name')", false); 1531 ExpectBoolean("child.hasOwnProperty('name')", false);
1532 ExpectString("child.name", "Alice"); 1532 ExpectString("child.name", "Alice");
1533 CompileRun("child.name = 'Bob';"); 1533 CompileRun("child.name = 'Bob';");
1534 ExpectString("child.name", "Bob"); 1534 ExpectString("child.name", "Bob");
1535 ExpectBoolean("child.hasOwnProperty('name')", true); 1535 ExpectBoolean("child.hasOwnProperty('name')", true);
1536 ExpectString("parent.name", "Alice"); 1536 ExpectString("parent.name", "Alice");
1537 } 1537 }
1538 1538
1539 THREADED_TEST(SwitchFromInterceptorToAccessor) { 1539 THREADED_TEST(SwitchFromInterceptorToAccessor) {
1540 v8::HandleScope scope; 1540 v8::HandleScope scope(v8::Isolate::GetCurrent());
1541 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 1541 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1542 AddAccessor(templ, v8_str("age"), 1542 AddAccessor(templ, v8_str("age"),
1543 SimpleAccessorGetter, SimpleAccessorSetter); 1543 SimpleAccessorGetter, SimpleAccessorSetter);
1544 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 1544 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
1545 LocalContext env; 1545 LocalContext env;
1546 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 1546 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
1547 CompileRun("var obj = new Obj;" 1547 CompileRun("var obj = new Obj;"
1548 "function setAge(i){ obj.age = i; };" 1548 "function setAge(i){ obj.age = i; };"
1549 "for(var i = 0; i <= 10000; i++) setAge(i);"); 1549 "for(var i = 0; i <= 10000; i++) setAge(i);");
1550 // All i < 10000 go to the interceptor. 1550 // All i < 10000 go to the interceptor.
1551 ExpectInt32("obj.interceptor_age", 9999); 1551 ExpectInt32("obj.interceptor_age", 9999);
1552 // The last i goes to the accessor. 1552 // The last i goes to the accessor.
1553 ExpectInt32("obj.accessor_age", 10000); 1553 ExpectInt32("obj.accessor_age", 10000);
1554 } 1554 }
1555 1555
1556 THREADED_TEST(SwitchFromAccessorToInterceptor) { 1556 THREADED_TEST(SwitchFromAccessorToInterceptor) {
1557 v8::HandleScope scope; 1557 v8::HandleScope scope(v8::Isolate::GetCurrent());
1558 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 1558 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1559 AddAccessor(templ, v8_str("age"), 1559 AddAccessor(templ, v8_str("age"),
1560 SimpleAccessorGetter, SimpleAccessorSetter); 1560 SimpleAccessorGetter, SimpleAccessorSetter);
1561 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 1561 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
1562 LocalContext env; 1562 LocalContext env;
1563 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 1563 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
1564 CompileRun("var obj = new Obj;" 1564 CompileRun("var obj = new Obj;"
1565 "function setAge(i){ obj.age = i; };" 1565 "function setAge(i){ obj.age = i; };"
1566 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 1566 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1567 // All i >= 10000 go to the accessor. 1567 // All i >= 10000 go to the accessor.
1568 ExpectInt32("obj.accessor_age", 10000); 1568 ExpectInt32("obj.accessor_age", 10000);
1569 // The last i goes to the interceptor. 1569 // The last i goes to the interceptor.
1570 ExpectInt32("obj.interceptor_age", 9999); 1570 ExpectInt32("obj.interceptor_age", 9999);
1571 } 1571 }
1572 1572
1573 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { 1573 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) {
1574 v8::HandleScope scope; 1574 v8::HandleScope scope(v8::Isolate::GetCurrent());
1575 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1575 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1576 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1576 Handle<FunctionTemplate> child = FunctionTemplate::New();
1577 child->Inherit(parent); 1577 child->Inherit(parent);
1578 AddAccessor(parent, v8_str("age"), 1578 AddAccessor(parent, v8_str("age"),
1579 SimpleAccessorGetter, SimpleAccessorSetter); 1579 SimpleAccessorGetter, SimpleAccessorSetter);
1580 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 1580 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
1581 LocalContext env; 1581 LocalContext env;
1582 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1582 env->Global()->Set(v8_str("Child"), child->GetFunction());
1583 CompileRun("var child = new Child;" 1583 CompileRun("var child = new Child;"
1584 "function setAge(i){ child.age = i; };" 1584 "function setAge(i){ child.age = i; };"
1585 "for(var i = 0; i <= 10000; i++) setAge(i);"); 1585 "for(var i = 0; i <= 10000; i++) setAge(i);");
1586 // All i < 10000 go to the interceptor. 1586 // All i < 10000 go to the interceptor.
1587 ExpectInt32("child.interceptor_age", 9999); 1587 ExpectInt32("child.interceptor_age", 9999);
1588 // The last i goes to the accessor. 1588 // The last i goes to the accessor.
1589 ExpectInt32("child.accessor_age", 10000); 1589 ExpectInt32("child.accessor_age", 10000);
1590 } 1590 }
1591 1591
1592 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { 1592 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) {
1593 v8::HandleScope scope; 1593 v8::HandleScope scope(v8::Isolate::GetCurrent());
1594 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1594 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1595 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1595 Handle<FunctionTemplate> child = FunctionTemplate::New();
1596 child->Inherit(parent); 1596 child->Inherit(parent);
1597 AddAccessor(parent, v8_str("age"), 1597 AddAccessor(parent, v8_str("age"),
1598 SimpleAccessorGetter, SimpleAccessorSetter); 1598 SimpleAccessorGetter, SimpleAccessorSetter);
1599 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 1599 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
1600 LocalContext env; 1600 LocalContext env;
1601 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1601 env->Global()->Set(v8_str("Child"), child->GetFunction());
1602 CompileRun("var child = new Child;" 1602 CompileRun("var child = new Child;"
1603 "function setAge(i){ child.age = i; };" 1603 "function setAge(i){ child.age = i; };"
1604 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 1604 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1605 // All i >= 10000 go to the accessor. 1605 // All i >= 10000 go to the accessor.
1606 ExpectInt32("child.accessor_age", 10000); 1606 ExpectInt32("child.accessor_age", 10000);
1607 // The last i goes to the interceptor. 1607 // The last i goes to the interceptor.
1608 ExpectInt32("child.interceptor_age", 9999); 1608 ExpectInt32("child.interceptor_age", 9999);
1609 } 1609 }
1610 1610
1611 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { 1611 THREADED_TEST(SwitchFromInterceptorToJSAccessor) {
1612 v8::HandleScope scope; 1612 v8::HandleScope scope(v8::Isolate::GetCurrent());
1613 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 1613 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1614 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 1614 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
1615 LocalContext env; 1615 LocalContext env;
1616 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 1616 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
1617 CompileRun("var obj = new Obj;" 1617 CompileRun("var obj = new Obj;"
1618 "function setter(i) { this.accessor_age = i; };" 1618 "function setter(i) { this.accessor_age = i; };"
1619 "function getter() { return this.accessor_age; };" 1619 "function getter() { return this.accessor_age; };"
1620 "function setAge(i) { obj.age = i; };" 1620 "function setAge(i) { obj.age = i; };"
1621 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 1621 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1622 "for(var i = 0; i <= 10000; i++) setAge(i);"); 1622 "for(var i = 0; i <= 10000; i++) setAge(i);");
1623 // All i < 10000 go to the interceptor. 1623 // All i < 10000 go to the interceptor.
1624 ExpectInt32("obj.interceptor_age", 9999); 1624 ExpectInt32("obj.interceptor_age", 9999);
1625 // The last i goes to the JavaScript accessor. 1625 // The last i goes to the JavaScript accessor.
1626 ExpectInt32("obj.accessor_age", 10000); 1626 ExpectInt32("obj.accessor_age", 10000);
1627 // The installed JavaScript getter is still intact. 1627 // The installed JavaScript getter is still intact.
1628 // This last part is a regression test for issue 1651 and relies on the fact 1628 // This last part is a regression test for issue 1651 and relies on the fact
1629 // that both interceptor and accessor are being installed on the same object. 1629 // that both interceptor and accessor are being installed on the same object.
1630 ExpectInt32("obj.age", 10000); 1630 ExpectInt32("obj.age", 10000);
1631 ExpectBoolean("obj.hasOwnProperty('age')", true); 1631 ExpectBoolean("obj.hasOwnProperty('age')", true);
1632 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 1632 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
1633 } 1633 }
1634 1634
1635 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { 1635 THREADED_TEST(SwitchFromJSAccessorToInterceptor) {
1636 v8::HandleScope scope; 1636 v8::HandleScope scope(v8::Isolate::GetCurrent());
1637 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 1637 Handle<FunctionTemplate> templ = FunctionTemplate::New();
1638 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 1638 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
1639 LocalContext env; 1639 LocalContext env;
1640 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 1640 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
1641 CompileRun("var obj = new Obj;" 1641 CompileRun("var obj = new Obj;"
1642 "function setter(i) { this.accessor_age = i; };" 1642 "function setter(i) { this.accessor_age = i; };"
1643 "function getter() { return this.accessor_age; };" 1643 "function getter() { return this.accessor_age; };"
1644 "function setAge(i) { obj.age = i; };" 1644 "function setAge(i) { obj.age = i; };"
1645 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 1645 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
1646 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 1646 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1647 // All i >= 10000 go to the accessor. 1647 // All i >= 10000 go to the accessor.
1648 ExpectInt32("obj.accessor_age", 10000); 1648 ExpectInt32("obj.accessor_age", 10000);
1649 // The last i goes to the interceptor. 1649 // The last i goes to the interceptor.
1650 ExpectInt32("obj.interceptor_age", 9999); 1650 ExpectInt32("obj.interceptor_age", 9999);
1651 // The installed JavaScript getter is still intact. 1651 // The installed JavaScript getter is still intact.
1652 // This last part is a regression test for issue 1651 and relies on the fact 1652 // This last part is a regression test for issue 1651 and relies on the fact
1653 // that both interceptor and accessor are being installed on the same object. 1653 // that both interceptor and accessor are being installed on the same object.
1654 ExpectInt32("obj.age", 10000); 1654 ExpectInt32("obj.age", 10000);
1655 ExpectBoolean("obj.hasOwnProperty('age')", true); 1655 ExpectBoolean("obj.hasOwnProperty('age')", true);
1656 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 1656 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
1657 } 1657 }
1658 1658
1659 THREADED_TEST(SwitchFromInterceptorToProperty) { 1659 THREADED_TEST(SwitchFromInterceptorToProperty) {
1660 v8::HandleScope scope; 1660 v8::HandleScope scope(v8::Isolate::GetCurrent());
1661 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1661 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1662 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1662 Handle<FunctionTemplate> child = FunctionTemplate::New();
1663 child->Inherit(parent); 1663 child->Inherit(parent);
1664 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 1664 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
1665 LocalContext env; 1665 LocalContext env;
1666 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1666 env->Global()->Set(v8_str("Child"), child->GetFunction());
1667 CompileRun("var child = new Child;" 1667 CompileRun("var child = new Child;"
1668 "function setAge(i){ child.age = i; };" 1668 "function setAge(i){ child.age = i; };"
1669 "for(var i = 0; i <= 10000; i++) setAge(i);"); 1669 "for(var i = 0; i <= 10000; i++) setAge(i);");
1670 // All i < 10000 go to the interceptor. 1670 // All i < 10000 go to the interceptor.
1671 ExpectInt32("child.interceptor_age", 9999); 1671 ExpectInt32("child.interceptor_age", 9999);
1672 // The last i goes to child's own property. 1672 // The last i goes to child's own property.
1673 ExpectInt32("child.age", 10000); 1673 ExpectInt32("child.age", 10000);
1674 } 1674 }
1675 1675
1676 THREADED_TEST(SwitchFromPropertyToInterceptor) { 1676 THREADED_TEST(SwitchFromPropertyToInterceptor) {
1677 v8::HandleScope scope; 1677 v8::HandleScope scope(v8::Isolate::GetCurrent());
1678 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1678 Handle<FunctionTemplate> parent = FunctionTemplate::New();
1679 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1679 Handle<FunctionTemplate> child = FunctionTemplate::New();
1680 child->Inherit(parent); 1680 child->Inherit(parent);
1681 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 1681 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
1682 LocalContext env; 1682 LocalContext env;
1683 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1683 env->Global()->Set(v8_str("Child"), child->GetFunction());
1684 CompileRun("var child = new Child;" 1684 CompileRun("var child = new Child;"
1685 "function setAge(i){ child.age = i; };" 1685 "function setAge(i){ child.age = i; };"
1686 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 1686 "for(var i = 20000; i >= 9999; i--) setAge(i);");
1687 // All i >= 10000 go to child's own property. 1687 // All i >= 10000 go to child's own property.
1688 ExpectInt32("child.age", 10000); 1688 ExpectInt32("child.age", 10000);
1689 // The last i goes to the interceptor. 1689 // The last i goes to the interceptor.
1690 ExpectInt32("child.interceptor_age", 9999); 1690 ExpectInt32("child.interceptor_age", 9999);
1691 } 1691 }
1692 1692
1693 THREADED_TEST(NamedPropertyHandlerGetter) { 1693 THREADED_TEST(NamedPropertyHandlerGetter) {
1694 echo_named_call_count = 0; 1694 echo_named_call_count = 0;
1695 v8::HandleScope scope; 1695 v8::HandleScope scope(v8::Isolate::GetCurrent());
1696 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 1696 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
1697 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, 1697 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty,
1698 0, 0, 0, 0, 1698 0, 0, 0, 0,
1699 v8_str("data")); 1699 v8_str("data"));
1700 LocalContext env; 1700 LocalContext env;
1701 env->Global()->Set(v8_str("obj"), 1701 env->Global()->Set(v8_str("obj"),
1702 templ->GetFunction()->NewInstance()); 1702 templ->GetFunction()->NewInstance());
1703 CHECK_EQ(echo_named_call_count, 0); 1703 CHECK_EQ(echo_named_call_count, 0);
1704 v8_compile("obj.x")->Run(); 1704 v8_compile("obj.x")->Run();
1705 CHECK_EQ(echo_named_call_count, 1); 1705 CHECK_EQ(echo_named_call_count, 1);
(...skipping 14 matching lines...) Expand all
1720 static v8::Handle<Value> EchoIndexedProperty(uint32_t index, 1720 static v8::Handle<Value> EchoIndexedProperty(uint32_t index,
1721 const AccessorInfo& info) { 1721 const AccessorInfo& info) {
1722 ApiTestFuzzer::Fuzz(); 1722 ApiTestFuzzer::Fuzz();
1723 CHECK_EQ(v8_num(637), info.Data()); 1723 CHECK_EQ(v8_num(637), info.Data());
1724 echo_indexed_call_count++; 1724 echo_indexed_call_count++;
1725 return v8_num(index); 1725 return v8_num(index);
1726 } 1726 }
1727 1727
1728 1728
1729 THREADED_TEST(IndexedPropertyHandlerGetter) { 1729 THREADED_TEST(IndexedPropertyHandlerGetter) {
1730 v8::HandleScope scope; 1730 v8::HandleScope scope(v8::Isolate::GetCurrent());
1731 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 1731 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
1732 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, 1732 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty,
1733 0, 0, 0, 0, 1733 0, 0, 0, 0,
1734 v8_num(637)); 1734 v8_num(637));
1735 LocalContext env; 1735 LocalContext env;
1736 env->Global()->Set(v8_str("obj"), 1736 env->Global()->Set(v8_str("obj"),
1737 templ->GetFunction()->NewInstance()); 1737 templ->GetFunction()->NewInstance());
1738 Local<Script> script = v8_compile("obj[900]"); 1738 Local<Script> script = v8_compile("obj[900]");
1739 CHECK_EQ(script->Run()->Int32Value(), 900); 1739 CHECK_EQ(script->Run()->Int32Value(), 900);
1740 } 1740 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 1821
1822 v8::Handle<v8::Array> CheckThisNamedPropertyEnumerator( 1822 v8::Handle<v8::Array> CheckThisNamedPropertyEnumerator(
1823 const AccessorInfo& info) { 1823 const AccessorInfo& info) {
1824 ApiTestFuzzer::Fuzz(); 1824 ApiTestFuzzer::Fuzz();
1825 CHECK(info.This()->Equals(bottom)); 1825 CHECK(info.This()->Equals(bottom));
1826 return v8::Handle<v8::Array>(); 1826 return v8::Handle<v8::Array>();
1827 } 1827 }
1828 1828
1829 1829
1830 THREADED_TEST(PropertyHandlerInPrototype) { 1830 THREADED_TEST(PropertyHandlerInPrototype) {
1831 v8::HandleScope scope;
1832 LocalContext env; 1831 LocalContext env;
1832 v8::HandleScope scope(env->GetIsolate());
1833 1833
1834 // Set up a prototype chain with three interceptors. 1834 // Set up a prototype chain with three interceptors.
1835 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 1835 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
1836 templ->InstanceTemplate()->SetIndexedPropertyHandler( 1836 templ->InstanceTemplate()->SetIndexedPropertyHandler(
1837 CheckThisIndexedPropertyHandler, 1837 CheckThisIndexedPropertyHandler,
1838 CheckThisIndexedPropertySetter, 1838 CheckThisIndexedPropertySetter,
1839 CheckThisIndexedPropertyQuery, 1839 CheckThisIndexedPropertyQuery,
1840 CheckThisIndexedPropertyDeleter, 1840 CheckThisIndexedPropertyDeleter,
1841 CheckThisIndexedPropertyEnumerator); 1841 CheckThisIndexedPropertyEnumerator);
1842 1842
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 const AccessorInfo&) { 1890 const AccessorInfo&) {
1891 if (v8_str("pre")->Equals(key)) { 1891 if (v8_str("pre")->Equals(key)) {
1892 return v8::Integer::New(v8::None); 1892 return v8::Integer::New(v8::None);
1893 } 1893 }
1894 1894
1895 return v8::Handle<v8::Integer>(); // do not intercept the call 1895 return v8::Handle<v8::Integer>(); // do not intercept the call
1896 } 1896 }
1897 1897
1898 1898
1899 THREADED_TEST(PrePropertyHandler) { 1899 THREADED_TEST(PrePropertyHandler) {
1900 v8::HandleScope scope; 1900 v8::HandleScope scope(v8::Isolate::GetCurrent());
1901 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 1901 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New();
1902 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, 1902 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet,
1903 0, 1903 0,
1904 PrePropertyHandlerQuery); 1904 PrePropertyHandlerQuery);
1905 LocalContext env(NULL, desc->InstanceTemplate()); 1905 LocalContext env(NULL, desc->InstanceTemplate());
1906 Script::Compile(v8_str( 1906 Script::Compile(v8_str(
1907 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); 1907 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run();
1908 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run(); 1908 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run();
1909 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); 1909 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre);
1910 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); 1910 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run();
1911 CHECK_EQ(v8_str("Object: on"), result_on); 1911 CHECK_EQ(v8_str("Object: on"), result_on);
1912 v8::Handle<Value> result_post = Script::Compile(v8_str("post"))->Run(); 1912 v8::Handle<Value> result_post = Script::Compile(v8_str("post"))->Run();
1913 CHECK(result_post.IsEmpty()); 1913 CHECK(result_post.IsEmpty());
1914 } 1914 }
1915 1915
1916 1916
1917 THREADED_TEST(UndefinedIsNotEnumerable) { 1917 THREADED_TEST(UndefinedIsNotEnumerable) {
1918 v8::HandleScope scope;
1919 LocalContext env; 1918 LocalContext env;
1919 v8::HandleScope scope(env->GetIsolate());
1920 v8::Handle<Value> result = Script::Compile(v8_str( 1920 v8::Handle<Value> result = Script::Compile(v8_str(
1921 "this.propertyIsEnumerable(undefined)"))->Run(); 1921 "this.propertyIsEnumerable(undefined)"))->Run();
1922 CHECK(result->IsFalse()); 1922 CHECK(result->IsFalse());
1923 } 1923 }
1924 1924
1925 1925
1926 v8::Handle<Script> call_recursively_script; 1926 v8::Handle<Script> call_recursively_script;
1927 static const int kTargetRecursionDepth = 200; // near maximum 1927 static const int kTargetRecursionDepth = 200; // near maximum
1928 1928
1929 1929
(...skipping 15 matching lines...) Expand all
1945 return v8::Undefined(); 1945 return v8::Undefined();
1946 } 1946 }
1947 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 1947 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
1948 v8::Handle<Value> function = 1948 v8::Handle<Value> function =
1949 args.This()->Get(v8_str("callFunctionRecursively")); 1949 args.This()->Get(v8_str("callFunctionRecursively"));
1950 return function.As<Function>()->Call(args.This(), 0, NULL); 1950 return function.As<Function>()->Call(args.This(), 0, NULL);
1951 } 1951 }
1952 1952
1953 1953
1954 THREADED_TEST(DeepCrossLanguageRecursion) { 1954 THREADED_TEST(DeepCrossLanguageRecursion) {
1955 v8::HandleScope scope; 1955 v8::HandleScope scope(v8::Isolate::GetCurrent());
1956 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 1956 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
1957 global->Set(v8_str("callScriptRecursively"), 1957 global->Set(v8_str("callScriptRecursively"),
1958 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); 1958 v8::FunctionTemplate::New(CallScriptRecursivelyCall));
1959 global->Set(v8_str("callFunctionRecursively"), 1959 global->Set(v8_str("callFunctionRecursively"),
1960 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); 1960 v8::FunctionTemplate::New(CallFunctionRecursivelyCall));
1961 LocalContext env(NULL, global); 1961 LocalContext env(NULL, global);
1962 1962
1963 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 1963 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
1964 call_recursively_script = v8_compile("callScriptRecursively()"); 1964 call_recursively_script = v8_compile("callScriptRecursively()");
1965 call_recursively_script->Run(); 1965 call_recursively_script->Run();
(...skipping 13 matching lines...) Expand all
1979 1979
1980 static v8::Handle<Value> ThrowingPropertyHandlerSet(Local<String> key, 1980 static v8::Handle<Value> ThrowingPropertyHandlerSet(Local<String> key,
1981 Local<Value>, 1981 Local<Value>,
1982 const AccessorInfo&) { 1982 const AccessorInfo&) {
1983 v8::ThrowException(key); 1983 v8::ThrowException(key);
1984 return v8::Undefined(); // not the same as v8::Handle<v8::Value>() 1984 return v8::Undefined(); // not the same as v8::Handle<v8::Value>()
1985 } 1985 }
1986 1986
1987 1987
1988 THREADED_TEST(CallbackExceptionRegression) { 1988 THREADED_TEST(CallbackExceptionRegression) {
1989 v8::HandleScope scope; 1989 v8::HandleScope scope(v8::Isolate::GetCurrent());
1990 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 1990 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
1991 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet, 1991 obj->SetNamedPropertyHandler(ThrowingPropertyHandlerGet,
1992 ThrowingPropertyHandlerSet); 1992 ThrowingPropertyHandlerSet);
1993 LocalContext env; 1993 LocalContext env;
1994 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 1994 env->Global()->Set(v8_str("obj"), obj->NewInstance());
1995 v8::Handle<Value> otto = Script::Compile(v8_str( 1995 v8::Handle<Value> otto = Script::Compile(v8_str(
1996 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); 1996 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
1997 CHECK_EQ(v8_str("otto"), otto); 1997 CHECK_EQ(v8_str("otto"), otto);
1998 v8::Handle<Value> netto = Script::Compile(v8_str( 1998 v8::Handle<Value> netto = Script::Compile(v8_str(
1999 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); 1999 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
2000 CHECK_EQ(v8_str("netto"), netto); 2000 CHECK_EQ(v8_str("netto"), netto);
2001 } 2001 }
2002 2002
2003 2003
2004 THREADED_TEST(FunctionPrototype) { 2004 THREADED_TEST(FunctionPrototype) {
2005 v8::HandleScope scope; 2005 v8::HandleScope scope(v8::Isolate::GetCurrent());
2006 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(); 2006 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New();
2007 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); 2007 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321));
2008 LocalContext env; 2008 LocalContext env;
2009 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); 2009 env->Global()->Set(v8_str("Foo"), Foo->GetFunction());
2010 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); 2010 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak"));
2011 CHECK_EQ(script->Run()->Int32Value(), 321); 2011 CHECK_EQ(script->Run()->Int32Value(), 321);
2012 } 2012 }
2013 2013
2014 2014
2015 THREADED_TEST(InternalFields) { 2015 THREADED_TEST(InternalFields) {
2016 v8::HandleScope scope;
2017 LocalContext env; 2016 LocalContext env;
2017 v8::HandleScope scope(env->GetIsolate());
2018 2018
2019 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2019 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2020 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2020 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2021 instance_templ->SetInternalFieldCount(1); 2021 instance_templ->SetInternalFieldCount(1);
2022 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2022 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2023 CHECK_EQ(1, obj->InternalFieldCount()); 2023 CHECK_EQ(1, obj->InternalFieldCount());
2024 CHECK(obj->GetInternalField(0)->IsUndefined()); 2024 CHECK(obj->GetInternalField(0)->IsUndefined());
2025 obj->SetInternalField(0, v8_num(17)); 2025 obj->SetInternalField(0, v8_num(17));
2026 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 2026 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
2027 } 2027 }
2028 2028
2029 2029
2030 THREADED_TEST(GlobalObjectInternalFields) { 2030 THREADED_TEST(GlobalObjectInternalFields) {
2031 v8::HandleScope scope; 2031 v8::HandleScope scope(v8::Isolate::GetCurrent());
2032 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 2032 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
2033 global_template->SetInternalFieldCount(1); 2033 global_template->SetInternalFieldCount(1);
2034 LocalContext env(NULL, global_template); 2034 LocalContext env(NULL, global_template);
2035 v8::Handle<v8::Object> global_proxy = env->Global(); 2035 v8::Handle<v8::Object> global_proxy = env->Global();
2036 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2036 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2037 CHECK_EQ(1, global->InternalFieldCount()); 2037 CHECK_EQ(1, global->InternalFieldCount());
2038 CHECK(global->GetInternalField(0)->IsUndefined()); 2038 CHECK(global->GetInternalField(0)->IsUndefined());
2039 global->SetInternalField(0, v8_num(17)); 2039 global->SetInternalField(0, v8_num(17));
2040 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); 2040 CHECK_EQ(17, global->GetInternalField(0)->Int32Value());
2041 } 2041 }
2042 2042
2043 2043
2044 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, 2044 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj,
2045 void* value) { 2045 void* value) {
2046 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2046 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2047 obj->SetAlignedPointerInInternalField(0, value); 2047 obj->SetAlignedPointerInInternalField(0, value);
2048 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2048 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2049 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); 2049 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
2050 } 2050 }
2051 2051
2052 2052
2053 THREADED_TEST(InternalFieldsAlignedPointers) { 2053 THREADED_TEST(InternalFieldsAlignedPointers) {
2054 v8::HandleScope scope;
2055 LocalContext env; 2054 LocalContext env;
2055 v8::HandleScope scope(env->GetIsolate());
2056 2056
2057 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2057 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
2058 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2058 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2059 instance_templ->SetInternalFieldCount(1); 2059 instance_templ->SetInternalFieldCount(1);
2060 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2060 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2061 CHECK_EQ(1, obj->InternalFieldCount()); 2061 CHECK_EQ(1, obj->InternalFieldCount());
2062 2062
2063 CheckAlignedPointerInInternalField(obj, NULL); 2063 CheckAlignedPointerInInternalField(obj, NULL);
2064 2064
2065 int* heap_allocated = new int[100]; 2065 int* heap_allocated = new int[100];
(...skipping 17 matching lines...) Expand all
2083 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index)); 2083 CHECK_EQ(value, (*env)->GetAlignedPointerFromEmbedderData(index));
2084 } 2084 }
2085 2085
2086 2086
2087 static void* AlignedTestPointer(int i) { 2087 static void* AlignedTestPointer(int i) {
2088 return reinterpret_cast<void*>(i * 1234); 2088 return reinterpret_cast<void*>(i * 1234);
2089 } 2089 }
2090 2090
2091 2091
2092 THREADED_TEST(EmbedderDataAlignedPointers) { 2092 THREADED_TEST(EmbedderDataAlignedPointers) {
2093 v8::HandleScope scope;
2094 LocalContext env; 2093 LocalContext env;
2094 v8::HandleScope scope(env->GetIsolate());
2095 2095
2096 CheckAlignedPointerInEmbedderData(&env, 0, NULL); 2096 CheckAlignedPointerInEmbedderData(&env, 0, NULL);
2097 2097
2098 int* heap_allocated = new int[100]; 2098 int* heap_allocated = new int[100];
2099 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated); 2099 CheckAlignedPointerInEmbedderData(&env, 1, heap_allocated);
2100 delete[] heap_allocated; 2100 delete[] heap_allocated;
2101 2101
2102 int stack_allocated[100]; 2102 int stack_allocated[100];
2103 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated); 2103 CheckAlignedPointerInEmbedderData(&env, 2, stack_allocated);
2104 2104
(...skipping 12 matching lines...) Expand all
2117 2117
2118 2118
2119 static void CheckEmbedderData(LocalContext* env, 2119 static void CheckEmbedderData(LocalContext* env,
2120 int index, 2120 int index,
2121 v8::Handle<Value> data) { 2121 v8::Handle<Value> data) {
2122 (*env)->SetEmbedderData(index, data); 2122 (*env)->SetEmbedderData(index, data);
2123 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); 2123 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2124 } 2124 }
2125 2125
2126 THREADED_TEST(EmbedderData) { 2126 THREADED_TEST(EmbedderData) {
2127 v8::HandleScope scope;
2128 LocalContext env; 2127 LocalContext env;
2128 v8::HandleScope scope(env->GetIsolate());
2129 2129
2130 CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps")); 2130 CheckEmbedderData(&env, 3, v8::String::New("The quick brown fox jumps"));
2131 CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog.")); 2131 CheckEmbedderData(&env, 2, v8::String::New("over the lazy dog."));
2132 CheckEmbedderData(&env, 1, v8::Number::New(1.2345)); 2132 CheckEmbedderData(&env, 1, v8::Number::New(1.2345));
2133 CheckEmbedderData(&env, 0, v8::Boolean::New(true)); 2133 CheckEmbedderData(&env, 0, v8::Boolean::New(true));
2134 } 2134 }
2135 2135
2136 2136
2137 THREADED_TEST(IdentityHash) { 2137 THREADED_TEST(IdentityHash) {
2138 v8::HandleScope scope;
2139 LocalContext env; 2138 LocalContext env;
2139 v8::HandleScope scope(env->GetIsolate());
2140 2140
2141 // Ensure that the test starts with an fresh heap to test whether the hash 2141 // Ensure that the test starts with an fresh heap to test whether the hash
2142 // code is based on the address. 2142 // code is based on the address.
2143 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2143 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2144 Local<v8::Object> obj = v8::Object::New(); 2144 Local<v8::Object> obj = v8::Object::New();
2145 int hash = obj->GetIdentityHash(); 2145 int hash = obj->GetIdentityHash();
2146 int hash1 = obj->GetIdentityHash(); 2146 int hash1 = obj->GetIdentityHash();
2147 CHECK_EQ(hash, hash1); 2147 CHECK_EQ(hash, hash1);
2148 int hash2 = v8::Object::New()->GetIdentityHash(); 2148 int hash2 = v8::Object::New()->GetIdentityHash();
2149 // Since the identity hash is essentially a random number two consecutive 2149 // Since the identity hash is essentially a random number two consecutive
(...skipping 22 matching lines...) Expand all
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(HiddenProperties) { 2181 THREADED_TEST(HiddenProperties) {
2182 v8::HandleScope scope;
2183 LocalContext env; 2182 LocalContext env;
2183 v8::HandleScope scope(env->GetIsolate());
2184 2184
2185 v8::Local<v8::Object> obj = v8::Object::New(); 2185 v8::Local<v8::Object> obj = v8::Object::New();
2186 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2186 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2187 v8::Local<v8::String> empty = v8_str(""); 2187 v8::Local<v8::String> empty = v8_str("");
2188 v8::Local<v8::String> prop_name = v8_str("prop_name"); 2188 v8::Local<v8::String> prop_name = v8_str("prop_name");
2189 2189
2190 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 2190 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
2191 2191
2192 // Make sure delete of a non-existent hidden value works 2192 // Make sure delete of a non-existent hidden value works
2193 CHECK(obj->DeleteHiddenValue(key)); 2193 CHECK(obj->DeleteHiddenValue(key));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002))); 2227 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2002)));
2228 CHECK(obj->DeleteHiddenValue(key)); 2228 CHECK(obj->DeleteHiddenValue(key));
2229 CHECK(obj->GetHiddenValue(key).IsEmpty()); 2229 CHECK(obj->GetHiddenValue(key).IsEmpty());
2230 } 2230 }
2231 2231
2232 2232
2233 THREADED_TEST(Regress97784) { 2233 THREADED_TEST(Regress97784) {
2234 // Regression test for crbug.com/97784 2234 // Regression test for crbug.com/97784
2235 // Messing with the Object.prototype should not have effect on 2235 // Messing with the Object.prototype should not have effect on
2236 // hidden properties. 2236 // hidden properties.
2237 v8::HandleScope scope;
2238 LocalContext env; 2237 LocalContext env;
2238 v8::HandleScope scope(env->GetIsolate());
2239 2239
2240 v8::Local<v8::Object> obj = v8::Object::New(); 2240 v8::Local<v8::Object> obj = v8::Object::New();
2241 v8::Local<v8::String> key = v8_str("hidden"); 2241 v8::Local<v8::String> key = v8_str("hidden");
2242 2242
2243 CompileRun( 2243 CompileRun(
2244 "set_called = false;" 2244 "set_called = false;"
2245 "Object.defineProperty(" 2245 "Object.defineProperty("
2246 " Object.prototype," 2246 " Object.prototype,"
2247 " 'hidden'," 2247 " 'hidden',"
2248 " {get: function() { return 45; }," 2248 " {get: function() { return 45; },"
(...skipping 11 matching lines...) Expand all
2260 2260
2261 static bool interceptor_for_hidden_properties_called; 2261 static bool interceptor_for_hidden_properties_called;
2262 static v8::Handle<Value> InterceptorForHiddenProperties( 2262 static v8::Handle<Value> InterceptorForHiddenProperties(
2263 Local<String> name, const AccessorInfo& info) { 2263 Local<String> name, const AccessorInfo& info) {
2264 interceptor_for_hidden_properties_called = true; 2264 interceptor_for_hidden_properties_called = true;
2265 return v8::Handle<Value>(); 2265 return v8::Handle<Value>();
2266 } 2266 }
2267 2267
2268 2268
2269 THREADED_TEST(HiddenPropertiesWithInterceptors) { 2269 THREADED_TEST(HiddenPropertiesWithInterceptors) {
2270 v8::HandleScope scope;
2271 LocalContext context; 2270 LocalContext context;
2271 v8::HandleScope scope(context->GetIsolate());
2272 2272
2273 interceptor_for_hidden_properties_called = false; 2273 interceptor_for_hidden_properties_called = false;
2274 2274
2275 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 2275 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
2276 2276
2277 // Associate an interceptor with an object and start setting hidden values. 2277 // Associate an interceptor with an object and start setting hidden values.
2278 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 2278 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
2279 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 2279 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
2280 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); 2280 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
2281 Local<v8::Function> function = fun_templ->GetFunction(); 2281 Local<v8::Function> function = fun_templ->GetFunction();
2282 Local<v8::Object> obj = function->NewInstance(); 2282 Local<v8::Object> obj = function->NewInstance();
2283 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); 2283 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302)));
2284 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); 2284 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
2285 CHECK(!interceptor_for_hidden_properties_called); 2285 CHECK(!interceptor_for_hidden_properties_called);
2286 } 2286 }
2287 2287
2288 2288
2289 THREADED_TEST(External) { 2289 THREADED_TEST(External) {
2290 v8::HandleScope scope; 2290 v8::HandleScope scope(v8::Isolate::GetCurrent());
2291 int x = 3; 2291 int x = 3;
2292 Local<v8::External> ext = v8::External::New(&x); 2292 Local<v8::External> ext = v8::External::New(&x);
2293 LocalContext env; 2293 LocalContext env;
2294 env->Global()->Set(v8_str("ext"), ext); 2294 env->Global()->Set(v8_str("ext"), ext);
2295 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run(); 2295 Local<Value> reext_obj = Script::Compile(v8_str("this.ext"))->Run();
2296 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); 2296 v8::Handle<v8::External> reext = reext_obj.As<v8::External>();
2297 int* ptr = static_cast<int*>(reext->Value()); 2297 int* ptr = static_cast<int*>(reext->Value());
2298 CHECK_EQ(x, 3); 2298 CHECK_EQ(x, 3);
2299 *ptr = 10; 2299 *ptr = 10;
2300 CHECK_EQ(x, 10); 2300 CHECK_EQ(x, 10);
(...skipping 14 matching lines...) Expand all
2315 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value()); 2315 char_ptr = reinterpret_cast<char*>(v8::External::Cast(*three)->Value());
2316 CHECK_EQ('3', *char_ptr); 2316 CHECK_EQ('3', *char_ptr);
2317 i::DeleteArray(data); 2317 i::DeleteArray(data);
2318 } 2318 }
2319 2319
2320 2320
2321 THREADED_TEST(GlobalHandle) { 2321 THREADED_TEST(GlobalHandle) {
2322 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 2322 v8::Isolate* isolate = v8::Isolate::GetCurrent();
2323 v8::Persistent<String> global; 2323 v8::Persistent<String> global;
2324 { 2324 {
2325 v8::HandleScope scope; 2325 v8::HandleScope scope(isolate);
2326 Local<String> str = v8_str("str"); 2326 Local<String> str = v8_str("str");
2327 global = v8::Persistent<String>::New(isolate, str); 2327 global = v8::Persistent<String>::New(isolate, str);
2328 } 2328 }
2329 CHECK_EQ(global->Length(), 3); 2329 CHECK_EQ(global->Length(), 3);
2330 global.Dispose(isolate); 2330 global.Dispose(isolate);
2331 2331
2332 { 2332 {
2333 v8::HandleScope scope; 2333 v8::HandleScope scope(isolate);
2334 Local<String> str = v8_str("str"); 2334 Local<String> str = v8_str("str");
2335 global = v8::Persistent<String>::New(isolate, str); 2335 global = v8::Persistent<String>::New(isolate, str);
2336 } 2336 }
2337 CHECK_EQ(global->Length(), 3); 2337 CHECK_EQ(global->Length(), 3);
2338 global.Dispose(isolate); 2338 global.Dispose(isolate);
2339 } 2339 }
2340 2340
2341 2341
2342 THREADED_TEST(LocalHandle) { 2342 THREADED_TEST(LocalHandle) {
2343 v8::HandleScope scope; 2343 v8::HandleScope scope(v8::Isolate::GetCurrent());
2344 v8::Local<String> local = v8::Local<String>::New(v8_str("str")); 2344 v8::Local<String> local = v8::Local<String>::New(v8_str("str"));
2345 CHECK_EQ(local->Length(), 3); 2345 CHECK_EQ(local->Length(), 3);
2346 2346
2347 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str")); 2347 local = v8::Local<String>::New(v8::Isolate::GetCurrent(), v8_str("str"));
2348 CHECK_EQ(local->Length(), 3); 2348 CHECK_EQ(local->Length(), 3);
2349 } 2349 }
2350 2350
2351 2351
2352 class WeakCallCounter { 2352 class WeakCallCounter {
2353 public: 2353 public:
(...skipping 11 matching lines...) Expand all
2365 Persistent<Value> handle, 2365 Persistent<Value> handle,
2366 void* id) { 2366 void* id) {
2367 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id); 2367 WeakCallCounter* counter = reinterpret_cast<WeakCallCounter*>(id);
2368 CHECK_EQ(1234, counter->id()); 2368 CHECK_EQ(1234, counter->id());
2369 counter->increment(); 2369 counter->increment();
2370 handle.Dispose(isolate); 2370 handle.Dispose(isolate);
2371 } 2371 }
2372 2372
2373 2373
2374 THREADED_TEST(ApiObjectGroups) { 2374 THREADED_TEST(ApiObjectGroups) {
2375 HandleScope scope;
2376 LocalContext env; 2375 LocalContext env;
2377 v8::Isolate* iso = env->GetIsolate(); 2376 v8::Isolate* iso = env->GetIsolate();
2377 HandleScope scope(iso);
2378 2378
2379 Persistent<Object> g1s1; 2379 Persistent<Object> g1s1;
2380 Persistent<Object> g1s2; 2380 Persistent<Object> g1s2;
2381 Persistent<Object> g1c1; 2381 Persistent<Object> g1c1;
2382 Persistent<Object> g2s1; 2382 Persistent<Object> g2s1;
2383 Persistent<Object> g2s2; 2383 Persistent<Object> g2s2;
2384 Persistent<Object> g2c1; 2384 Persistent<Object> g2c1;
2385 2385
2386 WeakCallCounter counter(1234); 2386 WeakCallCounter counter(1234);
2387 2387
2388 { 2388 {
2389 HandleScope scope; 2389 HandleScope scope(iso);
2390 g1s1 = Persistent<Object>::New(iso, Object::New()); 2390 g1s1 = Persistent<Object>::New(iso, Object::New());
2391 g1s2 = Persistent<Object>::New(iso, Object::New()); 2391 g1s2 = Persistent<Object>::New(iso, Object::New());
2392 g1c1 = Persistent<Object>::New(iso, Object::New()); 2392 g1c1 = Persistent<Object>::New(iso, Object::New());
2393 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2393 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2394 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2394 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2395 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2395 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2396 2396
2397 g2s1 = Persistent<Object>::New(iso, Object::New()); 2397 g2s1 = Persistent<Object>::New(iso, Object::New());
2398 g2s2 = Persistent<Object>::New(iso, Object::New()); 2398 g2s2 = Persistent<Object>::New(iso, Object::New());
2399 g2c1 = Persistent<Object>::New(iso, Object::New()); 2399 g2c1 = Persistent<Object>::New(iso, Object::New());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 // And now make children weak again and collect them. 2451 // And now make children weak again and collect them.
2452 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2452 g1c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2453 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2453 g2c1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2454 2454
2455 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 2455 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
2456 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2456 CHECK_EQ(7, counter.NumberOfWeakCalls());
2457 } 2457 }
2458 2458
2459 2459
2460 THREADED_TEST(ApiObjectGroupsCycle) { 2460 THREADED_TEST(ApiObjectGroupsCycle) {
2461 HandleScope scope;
2462 LocalContext env; 2461 LocalContext env;
2463 v8::Isolate* iso = env->GetIsolate(); 2462 v8::Isolate* iso = env->GetIsolate();
2463 HandleScope scope(iso);
2464 2464
2465 WeakCallCounter counter(1234); 2465 WeakCallCounter counter(1234);
2466 2466
2467 Persistent<Object> g1s1; 2467 Persistent<Object> g1s1;
2468 Persistent<Object> g1s2; 2468 Persistent<Object> g1s2;
2469 Persistent<Object> g2s1; 2469 Persistent<Object> g2s1;
2470 Persistent<Object> g2s2; 2470 Persistent<Object> g2s2;
2471 Persistent<Object> g3s1; 2471 Persistent<Object> g3s1;
2472 Persistent<Object> g3s2; 2472 Persistent<Object> g3s2;
2473 Persistent<Object> g4s1; 2473 Persistent<Object> g4s1;
2474 Persistent<Object> g4s2; 2474 Persistent<Object> g4s2;
2475 2475
2476 { 2476 {
2477 HandleScope scope; 2477 HandleScope scope(iso);
2478 g1s1 = Persistent<Object>::New(iso, Object::New()); 2478 g1s1 = Persistent<Object>::New(iso, Object::New());
2479 g1s2 = Persistent<Object>::New(iso, Object::New()); 2479 g1s2 = Persistent<Object>::New(iso, Object::New());
2480 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2480 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2481 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2481 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2482 CHECK(g1s1.IsWeak(iso)); 2482 CHECK(g1s1.IsWeak(iso));
2483 CHECK(g1s2.IsWeak(iso)); 2483 CHECK(g1s2.IsWeak(iso));
2484 2484
2485 g2s1 = Persistent<Object>::New(iso, Object::New()); 2485 g2s1 = Persistent<Object>::New(iso, Object::New());
2486 g2s2 = Persistent<Object>::New(iso, Object::New()); 2486 g2s2 = Persistent<Object>::New(iso, Object::New());
2487 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2487 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2561 // All objects should be gone. 9 global handles in total. 2561 // All objects should be gone. 9 global handles in total.
2562 CHECK_EQ(9, counter.NumberOfWeakCalls()); 2562 CHECK_EQ(9, counter.NumberOfWeakCalls());
2563 } 2563 }
2564 2564
2565 2565
2566 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures 2566 // TODO(mstarzinger): This should be a THREADED_TEST but causes failures
2567 // on the buildbots, so was made non-threaded for the time being. 2567 // on the buildbots, so was made non-threaded for the time being.
2568 TEST(ApiObjectGroupsCycleForScavenger) { 2568 TEST(ApiObjectGroupsCycleForScavenger) {
2569 i::FLAG_stress_compaction = false; 2569 i::FLAG_stress_compaction = false;
2570 i::FLAG_gc_global = false; 2570 i::FLAG_gc_global = false;
2571 HandleScope scope;
2572 LocalContext env; 2571 LocalContext env;
2573 v8::Isolate* iso = env->GetIsolate(); 2572 v8::Isolate* iso = env->GetIsolate();
2573 HandleScope scope(iso);
2574 2574
2575 WeakCallCounter counter(1234); 2575 WeakCallCounter counter(1234);
2576 2576
2577 Persistent<Object> g1s1; 2577 Persistent<Object> g1s1;
2578 Persistent<Object> g1s2; 2578 Persistent<Object> g1s2;
2579 Persistent<Object> g2s1; 2579 Persistent<Object> g2s1;
2580 Persistent<Object> g2s2; 2580 Persistent<Object> g2s2;
2581 Persistent<Object> g3s1; 2581 Persistent<Object> g3s1;
2582 Persistent<Object> g3s2; 2582 Persistent<Object> g3s2;
2583 2583
2584 { 2584 {
2585 HandleScope scope; 2585 HandleScope scope(iso);
2586 g1s1 = Persistent<Object>::New(iso, Object::New()); 2586 g1s1 = Persistent<Object>::New(iso, Object::New());
2587 g1s2 = Persistent<Object>::New(iso, Object::New()); 2587 g1s2 = Persistent<Object>::New(iso, Object::New());
2588 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2588 g1s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2589 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2589 g1s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2590 2590
2591 g2s1 = Persistent<Object>::New(iso, Object::New()); 2591 g2s1 = Persistent<Object>::New(iso, Object::New());
2592 g2s2 = Persistent<Object>::New(iso, Object::New()); 2592 g2s2 = Persistent<Object>::New(iso, Object::New());
2593 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2593 g2s1.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2594 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback); 2594 g2s2.MakeWeak(iso, reinterpret_cast<void*>(&counter), &WeakPointerCallback);
2595 2595
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 } 2654 }
2655 2655
2656 HEAP->CollectGarbage(i::NEW_SPACE); 2656 HEAP->CollectGarbage(i::NEW_SPACE);
2657 2657
2658 // All objects should be gone. 7 global handles in total. 2658 // All objects should be gone. 7 global handles in total.
2659 CHECK_EQ(7, counter.NumberOfWeakCalls()); 2659 CHECK_EQ(7, counter.NumberOfWeakCalls());
2660 } 2660 }
2661 2661
2662 2662
2663 THREADED_TEST(ScriptException) { 2663 THREADED_TEST(ScriptException) {
2664 v8::HandleScope scope;
2665 LocalContext env; 2664 LocalContext env;
2665 v8::HandleScope scope(env->GetIsolate());
2666 Local<Script> script = Script::Compile(v8_str("throw 'panama!';")); 2666 Local<Script> script = Script::Compile(v8_str("throw 'panama!';"));
2667 v8::TryCatch try_catch; 2667 v8::TryCatch try_catch;
2668 Local<Value> result = script->Run(); 2668 Local<Value> result = script->Run();
2669 CHECK(result.IsEmpty()); 2669 CHECK(result.IsEmpty());
2670 CHECK(try_catch.HasCaught()); 2670 CHECK(try_catch.HasCaught());
2671 String::AsciiValue exception_value(try_catch.Exception()); 2671 String::AsciiValue exception_value(try_catch.Exception());
2672 CHECK_EQ(*exception_value, "panama!"); 2672 CHECK_EQ(*exception_value, "panama!");
2673 } 2673 }
2674 2674
2675 2675
2676 TEST(TryCatchCustomException) { 2676 TEST(TryCatchCustomException) {
2677 v8::HandleScope scope;
2678 LocalContext env; 2677 LocalContext env;
2678 v8::HandleScope scope(env->GetIsolate());
2679 v8::TryCatch try_catch; 2679 v8::TryCatch try_catch;
2680 CompileRun("function CustomError() { this.a = 'b'; }" 2680 CompileRun("function CustomError() { this.a = 'b'; }"
2681 "(function f() { throw new CustomError(); })();"); 2681 "(function f() { throw new CustomError(); })();");
2682 CHECK(try_catch.HasCaught()); 2682 CHECK(try_catch.HasCaught());
2683 CHECK(try_catch.Exception()->ToObject()-> 2683 CHECK(try_catch.Exception()->ToObject()->
2684 Get(v8_str("a"))->Equals(v8_str("b"))); 2684 Get(v8_str("a"))->Equals(v8_str("b")));
2685 } 2685 }
2686 2686
2687 2687
2688 bool message_received; 2688 bool message_received;
2689 2689
2690 2690
2691 static void check_message_0(v8::Handle<v8::Message> message, 2691 static void check_message_0(v8::Handle<v8::Message> message,
2692 v8::Handle<Value> data) { 2692 v8::Handle<Value> data) {
2693 CHECK_EQ(5.76, data->NumberValue()); 2693 CHECK_EQ(5.76, data->NumberValue());
2694 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue()); 2694 CHECK_EQ(6.75, message->GetScriptResourceName()->NumberValue());
2695 CHECK_EQ(7.56, message->GetScriptData()->NumberValue()); 2695 CHECK_EQ(7.56, message->GetScriptData()->NumberValue());
2696 message_received = true; 2696 message_received = true;
2697 } 2697 }
2698 2698
2699 2699
2700 THREADED_TEST(MessageHandler0) { 2700 THREADED_TEST(MessageHandler0) {
2701 message_received = false; 2701 message_received = false;
2702 v8::HandleScope scope; 2702 v8::HandleScope scope(v8::Isolate::GetCurrent());
2703 CHECK(!message_received); 2703 CHECK(!message_received);
2704 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 2704 v8::V8::AddMessageListener(check_message_0, v8_num(5.76));
2705 LocalContext context; 2705 LocalContext context;
2706 v8::ScriptOrigin origin = 2706 v8::ScriptOrigin origin =
2707 v8::ScriptOrigin(v8_str("6.75")); 2707 v8::ScriptOrigin(v8_str("6.75"));
2708 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"), 2708 v8::Handle<v8::Script> script = Script::Compile(v8_str("throw 'error'"),
2709 &origin); 2709 &origin);
2710 script->SetData(v8_str("7.56")); 2710 script->SetData(v8_str("7.56"));
2711 script->Run(); 2711 script->Run();
2712 CHECK(message_received); 2712 CHECK(message_received);
2713 // clear out the message listener 2713 // clear out the message listener
2714 v8::V8::RemoveMessageListeners(check_message_0); 2714 v8::V8::RemoveMessageListeners(check_message_0);
2715 } 2715 }
2716 2716
2717 2717
2718 static void check_message_1(v8::Handle<v8::Message> message, 2718 static void check_message_1(v8::Handle<v8::Message> message,
2719 v8::Handle<Value> data) { 2719 v8::Handle<Value> data) {
2720 CHECK(data->IsNumber()); 2720 CHECK(data->IsNumber());
2721 CHECK_EQ(1337, data->Int32Value()); 2721 CHECK_EQ(1337, data->Int32Value());
2722 message_received = true; 2722 message_received = true;
2723 } 2723 }
2724 2724
2725 2725
2726 TEST(MessageHandler1) { 2726 TEST(MessageHandler1) {
2727 message_received = false; 2727 message_received = false;
2728 v8::HandleScope scope; 2728 v8::HandleScope scope(v8::Isolate::GetCurrent());
2729 CHECK(!message_received); 2729 CHECK(!message_received);
2730 v8::V8::AddMessageListener(check_message_1); 2730 v8::V8::AddMessageListener(check_message_1);
2731 LocalContext context; 2731 LocalContext context;
2732 CompileRun("throw 1337;"); 2732 CompileRun("throw 1337;");
2733 CHECK(message_received); 2733 CHECK(message_received);
2734 // clear out the message listener 2734 // clear out the message listener
2735 v8::V8::RemoveMessageListeners(check_message_1); 2735 v8::V8::RemoveMessageListeners(check_message_1);
2736 } 2736 }
2737 2737
2738 2738
2739 static void check_message_2(v8::Handle<v8::Message> message, 2739 static void check_message_2(v8::Handle<v8::Message> message,
2740 v8::Handle<Value> data) { 2740 v8::Handle<Value> data) {
2741 LocalContext context; 2741 LocalContext context;
2742 CHECK(data->IsObject()); 2742 CHECK(data->IsObject());
2743 v8::Local<v8::Value> hidden_property = 2743 v8::Local<v8::Value> hidden_property =
2744 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); 2744 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key"));
2745 CHECK(v8_str("hidden value")->Equals(hidden_property)); 2745 CHECK(v8_str("hidden value")->Equals(hidden_property));
2746 message_received = true; 2746 message_received = true;
2747 } 2747 }
2748 2748
2749 2749
2750 TEST(MessageHandler2) { 2750 TEST(MessageHandler2) {
2751 message_received = false; 2751 message_received = false;
2752 v8::HandleScope scope; 2752 v8::HandleScope scope(v8::Isolate::GetCurrent());
2753 CHECK(!message_received); 2753 CHECK(!message_received);
2754 v8::V8::AddMessageListener(check_message_2); 2754 v8::V8::AddMessageListener(check_message_2);
2755 LocalContext context; 2755 LocalContext context;
2756 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); 2756 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
2757 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"), 2757 v8::Object::Cast(*error)->SetHiddenValue(v8_str("hidden key"),
2758 v8_str("hidden value")); 2758 v8_str("hidden value"));
2759 context->Global()->Set(v8_str("error"), error); 2759 context->Global()->Set(v8_str("error"), error);
2760 CompileRun("throw error;"); 2760 CompileRun("throw error;");
2761 CHECK(message_received); 2761 CHECK(message_received);
2762 // clear out the message listener 2762 // clear out the message listener
2763 v8::V8::RemoveMessageListeners(check_message_2); 2763 v8::V8::RemoveMessageListeners(check_message_2);
2764 } 2764 }
2765 2765
2766 2766
2767 THREADED_TEST(GetSetProperty) { 2767 THREADED_TEST(GetSetProperty) {
2768 v8::HandleScope scope;
2769 LocalContext context; 2768 LocalContext context;
2769 v8::HandleScope scope(context->GetIsolate());
2770 context->Global()->Set(v8_str("foo"), v8_num(14)); 2770 context->Global()->Set(v8_str("foo"), v8_num(14));
2771 context->Global()->Set(v8_str("12"), v8_num(92)); 2771 context->Global()->Set(v8_str("12"), v8_num(92));
2772 context->Global()->Set(v8::Integer::New(16), v8_num(32)); 2772 context->Global()->Set(v8::Integer::New(16), v8_num(32));
2773 context->Global()->Set(v8_num(13), v8_num(56)); 2773 context->Global()->Set(v8_num(13), v8_num(56));
2774 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run(); 2774 Local<Value> foo = Script::Compile(v8_str("this.foo"))->Run();
2775 CHECK_EQ(14, foo->Int32Value()); 2775 CHECK_EQ(14, foo->Int32Value());
2776 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run(); 2776 Local<Value> twelve = Script::Compile(v8_str("this[12]"))->Run();
2777 CHECK_EQ(92, twelve->Int32Value()); 2777 CHECK_EQ(92, twelve->Int32Value());
2778 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run(); 2778 Local<Value> sixteen = Script::Compile(v8_str("this[16]"))->Run();
2779 CHECK_EQ(32, sixteen->Int32Value()); 2779 CHECK_EQ(32, sixteen->Int32Value());
2780 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run(); 2780 Local<Value> thirteen = Script::Compile(v8_str("this[13]"))->Run();
2781 CHECK_EQ(56, thirteen->Int32Value()); 2781 CHECK_EQ(56, thirteen->Int32Value());
2782 CHECK_EQ(92, context->Global()->Get(v8::Integer::New(12))->Int32Value()); 2782 CHECK_EQ(92, context->Global()->Get(v8::Integer::New(12))->Int32Value());
2783 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); 2783 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value());
2784 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); 2784 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value());
2785 CHECK_EQ(32, context->Global()->Get(v8::Integer::New(16))->Int32Value()); 2785 CHECK_EQ(32, context->Global()->Get(v8::Integer::New(16))->Int32Value());
2786 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); 2786 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value());
2787 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); 2787 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value());
2788 CHECK_EQ(56, context->Global()->Get(v8::Integer::New(13))->Int32Value()); 2788 CHECK_EQ(56, context->Global()->Get(v8::Integer::New(13))->Int32Value());
2789 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); 2789 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value());
2790 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); 2790 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value());
2791 } 2791 }
2792 2792
2793 2793
2794 THREADED_TEST(PropertyAttributes) { 2794 THREADED_TEST(PropertyAttributes) {
2795 v8::HandleScope scope;
2796 LocalContext context; 2795 LocalContext context;
2796 v8::HandleScope scope(context->GetIsolate());
2797 // none 2797 // none
2798 Local<String> prop = v8_str("none"); 2798 Local<String> prop = v8_str("none");
2799 context->Global()->Set(prop, v8_num(7)); 2799 context->Global()->Set(prop, v8_num(7));
2800 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 2800 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop));
2801 // read-only 2801 // read-only
2802 prop = v8_str("read_only"); 2802 prop = v8_str("read_only");
2803 context->Global()->Set(prop, v8_num(7), v8::ReadOnly); 2803 context->Global()->Set(prop, v8_num(7), v8::ReadOnly);
2804 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 2804 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value());
2805 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); 2805 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop));
2806 Script::Compile(v8_str("read_only = 9"))->Run(); 2806 Script::Compile(v8_str("read_only = 9"))->Run();
(...skipping 22 matching lines...) Expand all
2829 CompileRun("({ toString: function() { throw 'exception';} })"); 2829 CompileRun("({ toString: function() { throw 'exception';} })");
2830 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(exception)); 2830 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(exception));
2831 CHECK(try_catch.HasCaught()); 2831 CHECK(try_catch.HasCaught());
2832 String::AsciiValue exception_value(try_catch.Exception()); 2832 String::AsciiValue exception_value(try_catch.Exception());
2833 CHECK_EQ("exception", *exception_value); 2833 CHECK_EQ("exception", *exception_value);
2834 try_catch.Reset(); 2834 try_catch.Reset();
2835 } 2835 }
2836 2836
2837 2837
2838 THREADED_TEST(Array) { 2838 THREADED_TEST(Array) {
2839 v8::HandleScope scope;
2840 LocalContext context; 2839 LocalContext context;
2840 v8::HandleScope scope(context->GetIsolate());
2841 Local<v8::Array> array = v8::Array::New(); 2841 Local<v8::Array> array = v8::Array::New();
2842 CHECK_EQ(0, array->Length()); 2842 CHECK_EQ(0, array->Length());
2843 CHECK(array->Get(0)->IsUndefined()); 2843 CHECK(array->Get(0)->IsUndefined());
2844 CHECK(!array->Has(0)); 2844 CHECK(!array->Has(0));
2845 CHECK(array->Get(100)->IsUndefined()); 2845 CHECK(array->Get(100)->IsUndefined());
2846 CHECK(!array->Has(100)); 2846 CHECK(!array->Has(100));
2847 array->Set(2, v8_num(7)); 2847 array->Set(2, v8_num(7));
2848 CHECK_EQ(3, array->Length()); 2848 CHECK_EQ(3, array->Length());
2849 CHECK(!array->Has(0)); 2849 CHECK(!array->Has(0));
2850 CHECK(!array->Has(1)); 2850 CHECK(!array->Has(1));
2851 CHECK(array->Has(2)); 2851 CHECK(array->Has(2));
2852 CHECK_EQ(7, array->Get(2)->Int32Value()); 2852 CHECK_EQ(7, array->Get(2)->Int32Value());
2853 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run(); 2853 Local<Value> obj = Script::Compile(v8_str("[1, 2, 3]"))->Run();
2854 Local<v8::Array> arr = obj.As<v8::Array>(); 2854 Local<v8::Array> arr = obj.As<v8::Array>();
2855 CHECK_EQ(3, arr->Length()); 2855 CHECK_EQ(3, arr->Length());
2856 CHECK_EQ(1, arr->Get(0)->Int32Value()); 2856 CHECK_EQ(1, arr->Get(0)->Int32Value());
2857 CHECK_EQ(2, arr->Get(1)->Int32Value()); 2857 CHECK_EQ(2, arr->Get(1)->Int32Value());
2858 CHECK_EQ(3, arr->Get(2)->Int32Value()); 2858 CHECK_EQ(3, arr->Get(2)->Int32Value());
2859 array = v8::Array::New(27); 2859 array = v8::Array::New(27);
2860 CHECK_EQ(27, array->Length()); 2860 CHECK_EQ(27, array->Length());
2861 array = v8::Array::New(-27); 2861 array = v8::Array::New(-27);
2862 CHECK_EQ(0, array->Length()); 2862 CHECK_EQ(0, array->Length());
2863 } 2863 }
2864 2864
2865 2865
2866 v8::Handle<Value> HandleF(const v8::Arguments& args) { 2866 v8::Handle<Value> HandleF(const v8::Arguments& args) {
2867 v8::HandleScope scope; 2867 v8::HandleScope scope(args.GetIsolate());
2868 ApiTestFuzzer::Fuzz(); 2868 ApiTestFuzzer::Fuzz();
2869 Local<v8::Array> result = v8::Array::New(args.Length()); 2869 Local<v8::Array> result = v8::Array::New(args.Length());
2870 for (int i = 0; i < args.Length(); i++) 2870 for (int i = 0; i < args.Length(); i++)
2871 result->Set(i, args[i]); 2871 result->Set(i, args[i]);
2872 return scope.Close(result); 2872 return scope.Close(result);
2873 } 2873 }
2874 2874
2875 2875
2876 THREADED_TEST(Vector) { 2876 THREADED_TEST(Vector) {
2877 v8::HandleScope scope; 2877 v8::HandleScope scope(v8::Isolate::GetCurrent());
2878 Local<ObjectTemplate> global = ObjectTemplate::New(); 2878 Local<ObjectTemplate> global = ObjectTemplate::New();
2879 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); 2879 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF));
2880 LocalContext context(0, global); 2880 LocalContext context(0, global);
2881 2881
2882 const char* fun = "f()"; 2882 const char* fun = "f()";
2883 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); 2883 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>();
2884 CHECK_EQ(0, a0->Length()); 2884 CHECK_EQ(0, a0->Length());
2885 2885
2886 const char* fun2 = "f(11)"; 2886 const char* fun2 = "f(11)";
2887 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); 2887 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>();
(...skipping 17 matching lines...) Expand all
2905 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>(); 2905 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>();
2906 CHECK_EQ(4, a4->Length()); 2906 CHECK_EQ(4, a4->Length());
2907 CHECK_EQ(17, a4->Get(0)->Int32Value()); 2907 CHECK_EQ(17, a4->Get(0)->Int32Value());
2908 CHECK_EQ(18, a4->Get(1)->Int32Value()); 2908 CHECK_EQ(18, a4->Get(1)->Int32Value());
2909 CHECK_EQ(19, a4->Get(2)->Int32Value()); 2909 CHECK_EQ(19, a4->Get(2)->Int32Value());
2910 CHECK_EQ(20, a4->Get(3)->Int32Value()); 2910 CHECK_EQ(20, a4->Get(3)->Int32Value());
2911 } 2911 }
2912 2912
2913 2913
2914 THREADED_TEST(FunctionCall) { 2914 THREADED_TEST(FunctionCall) {
2915 v8::HandleScope scope;
2916 LocalContext context; 2915 LocalContext context;
2916 v8::HandleScope scope(context->GetIsolate());
2917 CompileRun( 2917 CompileRun(
2918 "function Foo() {" 2918 "function Foo() {"
2919 " var result = [];" 2919 " var result = [];"
2920 " for (var i = 0; i < arguments.length; i++) {" 2920 " for (var i = 0; i < arguments.length; i++) {"
2921 " result.push(arguments[i]);" 2921 " result.push(arguments[i]);"
2922 " }" 2922 " }"
2923 " return result;" 2923 " return result;"
2924 "}"); 2924 "}");
2925 Local<Function> Foo = 2925 Local<Function> Foo =
2926 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 2926 Local<Function>::Cast(context->Global()->Get(v8_str("Foo")));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 // It's not possible to read a snapshot into a heap with different dimensions. 2973 // It's not possible to read a snapshot into a heap with different dimensions.
2974 if (i::Snapshot::IsEnabled()) return; 2974 if (i::Snapshot::IsEnabled()) return;
2975 // Set heap limits. 2975 // Set heap limits.
2976 static const int K = 1024; 2976 static const int K = 1024;
2977 v8::ResourceConstraints constraints; 2977 v8::ResourceConstraints constraints;
2978 constraints.set_max_young_space_size(256 * K); 2978 constraints.set_max_young_space_size(256 * K);
2979 constraints.set_max_old_space_size(4 * K * K); 2979 constraints.set_max_old_space_size(4 * K * K);
2980 v8::SetResourceConstraints(&constraints); 2980 v8::SetResourceConstraints(&constraints);
2981 2981
2982 // Execute a script that causes out of memory. 2982 // Execute a script that causes out of memory.
2983 v8::HandleScope scope;
2984 LocalContext context; 2983 LocalContext context;
2984 v8::HandleScope scope(context->GetIsolate());
2985 v8::V8::IgnoreOutOfMemoryException(); 2985 v8::V8::IgnoreOutOfMemoryException();
2986 Local<Script> script = 2986 Local<Script> script =
2987 Script::Compile(String::New(js_code_causing_out_of_memory)); 2987 Script::Compile(String::New(js_code_causing_out_of_memory));
2988 Local<Value> result = script->Run(); 2988 Local<Value> result = script->Run();
2989 2989
2990 // Check for out of memory state. 2990 // Check for out of memory state.
2991 CHECK(result.IsEmpty()); 2991 CHECK(result.IsEmpty());
2992 CHECK(context->HasOutOfMemoryException()); 2992 CHECK(context->HasOutOfMemoryException());
2993 } 2993 }
2994 2994
2995 2995
2996 v8::Handle<Value> ProvokeOutOfMemory(const v8::Arguments& args) { 2996 v8::Handle<Value> ProvokeOutOfMemory(const v8::Arguments& args) {
2997 ApiTestFuzzer::Fuzz(); 2997 ApiTestFuzzer::Fuzz();
2998 2998
2999 v8::HandleScope scope;
3000 LocalContext context; 2999 LocalContext context;
3000 v8::HandleScope scope(context->GetIsolate());
3001 Local<Script> script = 3001 Local<Script> script =
3002 Script::Compile(String::New(js_code_causing_out_of_memory)); 3002 Script::Compile(String::New(js_code_causing_out_of_memory));
3003 Local<Value> result = script->Run(); 3003 Local<Value> result = script->Run();
3004 3004
3005 // Check for out of memory state. 3005 // Check for out of memory state.
3006 CHECK(result.IsEmpty()); 3006 CHECK(result.IsEmpty());
3007 CHECK(context->HasOutOfMemoryException()); 3007 CHECK(context->HasOutOfMemoryException());
3008 3008
3009 return result; 3009 return result;
3010 } 3010 }
3011 3011
3012 3012
3013 TEST(OutOfMemoryNested) { 3013 TEST(OutOfMemoryNested) {
3014 // It's not possible to read a snapshot into a heap with different dimensions. 3014 // It's not possible to read a snapshot into a heap with different dimensions.
3015 if (i::Snapshot::IsEnabled()) return; 3015 if (i::Snapshot::IsEnabled()) return;
3016 // Set heap limits. 3016 // Set heap limits.
3017 static const int K = 1024; 3017 static const int K = 1024;
3018 v8::ResourceConstraints constraints; 3018 v8::ResourceConstraints constraints;
3019 constraints.set_max_young_space_size(256 * K); 3019 constraints.set_max_young_space_size(256 * K);
3020 constraints.set_max_old_space_size(4 * K * K); 3020 constraints.set_max_old_space_size(4 * K * K);
3021 v8::SetResourceConstraints(&constraints); 3021 v8::SetResourceConstraints(&constraints);
3022 3022
3023 v8::HandleScope scope; 3023 v8::HandleScope scope(v8::Isolate::GetCurrent());
3024 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3024 Local<ObjectTemplate> templ = ObjectTemplate::New();
3025 templ->Set(v8_str("ProvokeOutOfMemory"), 3025 templ->Set(v8_str("ProvokeOutOfMemory"),
3026 v8::FunctionTemplate::New(ProvokeOutOfMemory)); 3026 v8::FunctionTemplate::New(ProvokeOutOfMemory));
3027 LocalContext context(0, templ); 3027 LocalContext context(0, templ);
3028 v8::V8::IgnoreOutOfMemoryException(); 3028 v8::V8::IgnoreOutOfMemoryException();
3029 Local<Value> result = CompileRun( 3029 Local<Value> result = CompileRun(
3030 "var thrown = false;" 3030 "var thrown = false;"
3031 "try {" 3031 "try {"
3032 " ProvokeOutOfMemory();" 3032 " ProvokeOutOfMemory();"
3033 "} catch (e) {" 3033 "} catch (e) {"
(...skipping 11 matching lines...) Expand all
3045 // Set heap limits. 3045 // Set heap limits.
3046 static const int K = 1024; 3046 static const int K = 1024;
3047 v8::ResourceConstraints constraints; 3047 v8::ResourceConstraints constraints;
3048 constraints.set_max_young_space_size(256 * K); 3048 constraints.set_max_young_space_size(256 * K);
3049 constraints.set_max_old_space_size(3 * K * K); 3049 constraints.set_max_old_space_size(3 * K * K);
3050 v8::SetResourceConstraints(&constraints); 3050 v8::SetResourceConstraints(&constraints);
3051 3051
3052 // Execute a script that causes out of memory. 3052 // Execute a script that causes out of memory.
3053 v8::V8::IgnoreOutOfMemoryException(); 3053 v8::V8::IgnoreOutOfMemoryException();
3054 3054
3055 v8::HandleScope scope;
3056 LocalContext context; 3055 LocalContext context;
3056 v8::HandleScope scope(context->GetIsolate());
3057 3057
3058 // Build huge string. This should fail with out of memory exception. 3058 // Build huge string. This should fail with out of memory exception.
3059 Local<Value> result = CompileRun( 3059 Local<Value> result = CompileRun(
3060 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" 3060 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();"
3061 "for (var i = 0; i < 22; i++) { str = str + str; }"); 3061 "for (var i = 0; i < 22; i++) { str = str + str; }");
3062 3062
3063 // Check for out of memory state. 3063 // Check for out of memory state.
3064 CHECK(result.IsEmpty()); 3064 CHECK(result.IsEmpty());
3065 CHECK(context->HasOutOfMemoryException()); 3065 CHECK(context->HasOutOfMemoryException());
3066 } 3066 }
3067 3067
3068 3068
3069 THREADED_TEST(ConstructCall) { 3069 THREADED_TEST(ConstructCall) {
3070 v8::HandleScope scope;
3071 LocalContext context; 3070 LocalContext context;
3071 v8::HandleScope scope(context->GetIsolate());
3072 CompileRun( 3072 CompileRun(
3073 "function Foo() {" 3073 "function Foo() {"
3074 " var result = [];" 3074 " var result = [];"
3075 " for (var i = 0; i < arguments.length; i++) {" 3075 " for (var i = 0; i < arguments.length; i++) {"
3076 " result.push(arguments[i]);" 3076 " result.push(arguments[i]);"
3077 " }" 3077 " }"
3078 " return result;" 3078 " return result;"
3079 "}"); 3079 "}");
3080 Local<Function> Foo = 3080 Local<Function> Foo =
3081 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 3081 Local<Function>::Cast(context->Global()->Get(v8_str("Foo")));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3120 3120
3121 static void CheckUncle(v8::TryCatch* try_catch) { 3121 static void CheckUncle(v8::TryCatch* try_catch) {
3122 CHECK(try_catch->HasCaught()); 3122 CHECK(try_catch->HasCaught());
3123 String::AsciiValue str_value(try_catch->Exception()); 3123 String::AsciiValue str_value(try_catch->Exception());
3124 CHECK_EQ(*str_value, "uncle?"); 3124 CHECK_EQ(*str_value, "uncle?");
3125 try_catch->Reset(); 3125 try_catch->Reset();
3126 } 3126 }
3127 3127
3128 3128
3129 THREADED_TEST(ConversionNumber) { 3129 THREADED_TEST(ConversionNumber) {
3130 v8::HandleScope scope;
3131 LocalContext env; 3130 LocalContext env;
3131 v8::HandleScope scope(env->GetIsolate());
3132 // Very large number. 3132 // Very large number.
3133 CompileRun("var obj = Math.pow(2,32) * 1237;"); 3133 CompileRun("var obj = Math.pow(2,32) * 1237;");
3134 Local<Value> obj = env->Global()->Get(v8_str("obj")); 3134 Local<Value> obj = env->Global()->Get(v8_str("obj"));
3135 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value()); 3135 CHECK_EQ(5312874545152.0, obj->ToNumber()->Value());
3136 CHECK_EQ(0, obj->ToInt32()->Value()); 3136 CHECK_EQ(0, obj->ToInt32()->Value());
3137 CHECK(0u == obj->ToUint32()->Value()); // NOLINT - no CHECK_EQ for unsigned. 3137 CHECK(0u == obj->ToUint32()->Value()); // NOLINT - no CHECK_EQ for unsigned.
3138 // Large number. 3138 // Large number.
3139 CompileRun("var obj = -1234567890123;"); 3139 CompileRun("var obj = -1234567890123;");
3140 obj = env->Global()->Get(v8_str("obj")); 3140 obj = env->Global()->Get(v8_str("obj"));
3141 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value()); 3141 CHECK_EQ(-1234567890123.0, obj->ToNumber()->Value());
(...skipping 26 matching lines...) Expand all
3168 // Large negative fraction. 3168 // Large negative fraction.
3169 CompileRun("var obj = -5726623061.75;"); 3169 CompileRun("var obj = -5726623061.75;");
3170 obj = env->Global()->Get(v8_str("obj")); 3170 obj = env->Global()->Get(v8_str("obj"));
3171 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value()); 3171 CHECK_EQ(-5726623061.75, obj->ToNumber()->Value());
3172 CHECK_EQ(-1431655765, obj->ToInt32()->Value()); 3172 CHECK_EQ(-1431655765, obj->ToInt32()->Value());
3173 CHECK(2863311531u == obj->ToUint32()->Value()); // NOLINT 3173 CHECK(2863311531u == obj->ToUint32()->Value()); // NOLINT
3174 } 3174 }
3175 3175
3176 3176
3177 THREADED_TEST(isNumberType) { 3177 THREADED_TEST(isNumberType) {
3178 v8::HandleScope scope;
3179 LocalContext env; 3178 LocalContext env;
3179 v8::HandleScope scope(env->GetIsolate());
3180 // Very large number. 3180 // Very large number.
3181 CompileRun("var obj = Math.pow(2,32) * 1237;"); 3181 CompileRun("var obj = Math.pow(2,32) * 1237;");
3182 Local<Value> obj = env->Global()->Get(v8_str("obj")); 3182 Local<Value> obj = env->Global()->Get(v8_str("obj"));
3183 CHECK(!obj->IsInt32()); 3183 CHECK(!obj->IsInt32());
3184 CHECK(!obj->IsUint32()); 3184 CHECK(!obj->IsUint32());
3185 // Large negative number. 3185 // Large negative number.
3186 CompileRun("var obj = -1234567890123;"); 3186 CompileRun("var obj = -1234567890123;");
3187 obj = env->Global()->Get(v8_str("obj")); 3187 obj = env->Global()->Get(v8_str("obj"));
3188 CHECK(!obj->IsInt32()); 3188 CHECK(!obj->IsInt32());
3189 CHECK(!obj->IsUint32()); 3189 CHECK(!obj->IsUint32());
(...skipping 29 matching lines...) Expand all
3219 CHECK(obj->IsUint32()); 3219 CHECK(obj->IsUint32());
3220 // Positive zero 3220 // Positive zero
3221 CompileRun("var obj = -0.0;"); 3221 CompileRun("var obj = -0.0;");
3222 obj = env->Global()->Get(v8_str("obj")); 3222 obj = env->Global()->Get(v8_str("obj"));
3223 CHECK(!obj->IsInt32()); 3223 CHECK(!obj->IsInt32());
3224 CHECK(!obj->IsUint32()); 3224 CHECK(!obj->IsUint32());
3225 } 3225 }
3226 3226
3227 3227
3228 THREADED_TEST(ConversionException) { 3228 THREADED_TEST(ConversionException) {
3229 v8::HandleScope scope;
3230 LocalContext env; 3229 LocalContext env;
3230 v8::HandleScope scope(env->GetIsolate());
3231 CompileRun( 3231 CompileRun(
3232 "function TestClass() { };" 3232 "function TestClass() { };"
3233 "TestClass.prototype.toString = function () { throw 'uncle?'; };" 3233 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
3234 "var obj = new TestClass();"); 3234 "var obj = new TestClass();");
3235 Local<Value> obj = env->Global()->Get(v8_str("obj")); 3235 Local<Value> obj = env->Global()->Get(v8_str("obj"));
3236 3236
3237 v8::TryCatch try_catch; 3237 v8::TryCatch try_catch;
3238 3238
3239 Local<Value> to_string_result = obj->ToString(); 3239 Local<Value> to_string_result = obj->ToString();
3240 CHECK(to_string_result.IsEmpty()); 3240 CHECK(to_string_result.IsEmpty());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3280 3280
3281 3281
3282 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) { 3282 v8::Handle<Value> ThrowFromC(const v8::Arguments& args) {
3283 ApiTestFuzzer::Fuzz(); 3283 ApiTestFuzzer::Fuzz();
3284 return v8::ThrowException(v8_str("konto")); 3284 return v8::ThrowException(v8_str("konto"));
3285 } 3285 }
3286 3286
3287 3287
3288 v8::Handle<Value> CCatcher(const v8::Arguments& args) { 3288 v8::Handle<Value> CCatcher(const v8::Arguments& args) {
3289 if (args.Length() < 1) return v8::False(); 3289 if (args.Length() < 1) return v8::False();
3290 v8::HandleScope scope; 3290 v8::HandleScope scope(args.GetIsolate());
3291 v8::TryCatch try_catch; 3291 v8::TryCatch try_catch;
3292 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 3292 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run();
3293 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 3293 CHECK(!try_catch.HasCaught() || result.IsEmpty());
3294 return v8::Boolean::New(try_catch.HasCaught()); 3294 return v8::Boolean::New(try_catch.HasCaught());
3295 } 3295 }
3296 3296
3297 3297
3298 THREADED_TEST(APICatch) { 3298 THREADED_TEST(APICatch) {
3299 v8::HandleScope scope; 3299 v8::HandleScope scope(v8::Isolate::GetCurrent());
3300 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3300 Local<ObjectTemplate> templ = ObjectTemplate::New();
3301 templ->Set(v8_str("ThrowFromC"), 3301 templ->Set(v8_str("ThrowFromC"),
3302 v8::FunctionTemplate::New(ThrowFromC)); 3302 v8::FunctionTemplate::New(ThrowFromC));
3303 LocalContext context(0, templ); 3303 LocalContext context(0, templ);
3304 CompileRun( 3304 CompileRun(
3305 "var thrown = false;" 3305 "var thrown = false;"
3306 "try {" 3306 "try {"
3307 " ThrowFromC();" 3307 " ThrowFromC();"
3308 "} catch (e) {" 3308 "} catch (e) {"
3309 " thrown = true;" 3309 " thrown = true;"
3310 "}"); 3310 "}");
3311 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); 3311 Local<Value> thrown = context->Global()->Get(v8_str("thrown"));
3312 CHECK(thrown->BooleanValue()); 3312 CHECK(thrown->BooleanValue());
3313 } 3313 }
3314 3314
3315 3315
3316 THREADED_TEST(APIThrowTryCatch) { 3316 THREADED_TEST(APIThrowTryCatch) {
3317 v8::HandleScope scope; 3317 v8::HandleScope scope(v8::Isolate::GetCurrent());
3318 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3318 Local<ObjectTemplate> templ = ObjectTemplate::New();
3319 templ->Set(v8_str("ThrowFromC"), 3319 templ->Set(v8_str("ThrowFromC"),
3320 v8::FunctionTemplate::New(ThrowFromC)); 3320 v8::FunctionTemplate::New(ThrowFromC));
3321 LocalContext context(0, templ); 3321 LocalContext context(0, templ);
3322 v8::TryCatch try_catch; 3322 v8::TryCatch try_catch;
3323 CompileRun("ThrowFromC();"); 3323 CompileRun("ThrowFromC();");
3324 CHECK(try_catch.HasCaught()); 3324 CHECK(try_catch.HasCaught());
3325 } 3325 }
3326 3326
3327 3327
3328 // Test that a try-finally block doesn't shadow a try-catch block 3328 // Test that a try-finally block doesn't shadow a try-catch block
3329 // when setting up an external handler. 3329 // when setting up an external handler.
3330 // 3330 //
3331 // BUG(271): Some of the exception propagation does not work on the 3331 // BUG(271): Some of the exception propagation does not work on the
3332 // ARM simulator because the simulator separates the C++ stack and the 3332 // ARM simulator because the simulator separates the C++ stack and the
3333 // JS stack. This test therefore fails on the simulator. The test is 3333 // JS stack. This test therefore fails on the simulator. The test is
3334 // not threaded to allow the threading tests to run on the simulator. 3334 // not threaded to allow the threading tests to run on the simulator.
3335 TEST(TryCatchInTryFinally) { 3335 TEST(TryCatchInTryFinally) {
3336 v8::HandleScope scope; 3336 v8::HandleScope scope(v8::Isolate::GetCurrent());
3337 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3337 Local<ObjectTemplate> templ = ObjectTemplate::New();
3338 templ->Set(v8_str("CCatcher"), 3338 templ->Set(v8_str("CCatcher"),
3339 v8::FunctionTemplate::New(CCatcher)); 3339 v8::FunctionTemplate::New(CCatcher));
3340 LocalContext context(0, templ); 3340 LocalContext context(0, templ);
3341 Local<Value> result = CompileRun("try {" 3341 Local<Value> result = CompileRun("try {"
3342 " try {" 3342 " try {"
3343 " CCatcher('throw 7;');" 3343 " CCatcher('throw 7;');"
3344 " } finally {" 3344 " } finally {"
3345 " }" 3345 " }"
3346 "} catch (e) {" 3346 "} catch (e) {"
(...skipping 14 matching lines...) Expand all
3361 ApiTestFuzzer::Fuzz(); 3361 ApiTestFuzzer::Fuzz();
3362 CHECK(false); 3362 CHECK(false);
3363 return v8::Undefined(); 3363 return v8::Undefined();
3364 } 3364 }
3365 3365
3366 3366
3367 // Test that overwritten methods are not invoked on uncaught exception 3367 // Test that overwritten methods are not invoked on uncaught exception
3368 // formatting. However, they are invoked when performing normal error 3368 // formatting. However, they are invoked when performing normal error
3369 // string conversions. 3369 // string conversions.
3370 TEST(APIThrowMessageOverwrittenToString) { 3370 TEST(APIThrowMessageOverwrittenToString) {
3371 v8::HandleScope scope; 3371 v8::HandleScope scope(v8::Isolate::GetCurrent());
3372 v8::V8::AddMessageListener(check_reference_error_message); 3372 v8::V8::AddMessageListener(check_reference_error_message);
3373 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3373 Local<ObjectTemplate> templ = ObjectTemplate::New();
3374 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail)); 3374 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail));
3375 LocalContext context(NULL, templ); 3375 LocalContext context(NULL, templ);
3376 CompileRun("asdf;"); 3376 CompileRun("asdf;");
3377 CompileRun("var limit = {};" 3377 CompileRun("var limit = {};"
3378 "limit.valueOf = fail;" 3378 "limit.valueOf = fail;"
3379 "Error.stackTraceLimit = limit;"); 3379 "Error.stackTraceLimit = limit;");
3380 CompileRun("asdf"); 3380 CompileRun("asdf");
3381 CompileRun("Array.prototype.pop = fail;"); 3381 CompileRun("Array.prototype.pop = fail;");
(...skipping 25 matching lines...) Expand all
3407 3407
3408 static void check_custom_error_message( 3408 static void check_custom_error_message(
3409 v8::Handle<v8::Message> message, 3409 v8::Handle<v8::Message> message,
3410 v8::Handle<v8::Value> data) { 3410 v8::Handle<v8::Value> data) {
3411 const char* uncaught_error = "Uncaught MyError toString"; 3411 const char* uncaught_error = "Uncaught MyError toString";
3412 CHECK(message->Get()->Equals(v8_str(uncaught_error))); 3412 CHECK(message->Get()->Equals(v8_str(uncaught_error)));
3413 } 3413 }
3414 3414
3415 3415
3416 TEST(CustomErrorToString) { 3416 TEST(CustomErrorToString) {
3417 v8::HandleScope scope; 3417 LocalContext context;
3418 v8::HandleScope scope(context->GetIsolate());
3418 v8::V8::AddMessageListener(check_custom_error_message); 3419 v8::V8::AddMessageListener(check_custom_error_message);
3419 LocalContext context;
3420 CompileRun( 3420 CompileRun(
3421 "function MyError(name, message) { " 3421 "function MyError(name, message) { "
3422 " this.name = name; " 3422 " this.name = name; "
3423 " this.message = message; " 3423 " this.message = message; "
3424 "} " 3424 "} "
3425 "MyError.prototype = Object.create(Error.prototype); " 3425 "MyError.prototype = Object.create(Error.prototype); "
3426 "MyError.prototype.toString = function() { " 3426 "MyError.prototype.toString = function() { "
3427 " return 'MyError toString'; " 3427 " return 'MyError toString'; "
3428 "}; " 3428 "}; "
3429 "throw new MyError('my name', 'my message'); "); 3429 "throw new MyError('my name', 'my message'); ");
3430 v8::V8::RemoveMessageListeners(check_custom_error_message); 3430 v8::V8::RemoveMessageListeners(check_custom_error_message);
3431 } 3431 }
3432 3432
3433 3433
3434 static void receive_message(v8::Handle<v8::Message> message, 3434 static void receive_message(v8::Handle<v8::Message> message,
3435 v8::Handle<v8::Value> data) { 3435 v8::Handle<v8::Value> data) {
3436 message->Get(); 3436 message->Get();
3437 message_received = true; 3437 message_received = true;
3438 } 3438 }
3439 3439
3440 3440
3441 TEST(APIThrowMessage) { 3441 TEST(APIThrowMessage) {
3442 message_received = false; 3442 message_received = false;
3443 v8::HandleScope scope; 3443 v8::HandleScope scope(v8::Isolate::GetCurrent());
3444 v8::V8::AddMessageListener(receive_message); 3444 v8::V8::AddMessageListener(receive_message);
3445 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3445 Local<ObjectTemplate> templ = ObjectTemplate::New();
3446 templ->Set(v8_str("ThrowFromC"), 3446 templ->Set(v8_str("ThrowFromC"),
3447 v8::FunctionTemplate::New(ThrowFromC)); 3447 v8::FunctionTemplate::New(ThrowFromC));
3448 LocalContext context(0, templ); 3448 LocalContext context(0, templ);
3449 CompileRun("ThrowFromC();"); 3449 CompileRun("ThrowFromC();");
3450 CHECK(message_received); 3450 CHECK(message_received);
3451 v8::V8::RemoveMessageListeners(receive_message); 3451 v8::V8::RemoveMessageListeners(receive_message);
3452 } 3452 }
3453 3453
3454 3454
3455 TEST(APIThrowMessageAndVerboseTryCatch) { 3455 TEST(APIThrowMessageAndVerboseTryCatch) {
3456 message_received = false; 3456 message_received = false;
3457 v8::HandleScope scope; 3457 v8::HandleScope scope(v8::Isolate::GetCurrent());
3458 v8::V8::AddMessageListener(receive_message); 3458 v8::V8::AddMessageListener(receive_message);
3459 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3459 Local<ObjectTemplate> templ = ObjectTemplate::New();
3460 templ->Set(v8_str("ThrowFromC"), 3460 templ->Set(v8_str("ThrowFromC"),
3461 v8::FunctionTemplate::New(ThrowFromC)); 3461 v8::FunctionTemplate::New(ThrowFromC));
3462 LocalContext context(0, templ); 3462 LocalContext context(0, templ);
3463 v8::TryCatch try_catch; 3463 v8::TryCatch try_catch;
3464 try_catch.SetVerbose(true); 3464 try_catch.SetVerbose(true);
3465 Local<Value> result = CompileRun("ThrowFromC();"); 3465 Local<Value> result = CompileRun("ThrowFromC();");
3466 CHECK(try_catch.HasCaught()); 3466 CHECK(try_catch.HasCaught());
3467 CHECK(result.IsEmpty()); 3467 CHECK(result.IsEmpty());
3468 CHECK(message_received); 3468 CHECK(message_received);
3469 v8::V8::RemoveMessageListeners(receive_message); 3469 v8::V8::RemoveMessageListeners(receive_message);
3470 } 3470 }
3471 3471
3472 3472
3473 TEST(APIStackOverflowAndVerboseTryCatch) { 3473 TEST(APIStackOverflowAndVerboseTryCatch) {
3474 message_received = false; 3474 message_received = false;
3475 v8::HandleScope scope; 3475 v8::HandleScope scope(v8::Isolate::GetCurrent());
3476 v8::V8::AddMessageListener(receive_message); 3476 v8::V8::AddMessageListener(receive_message);
3477 LocalContext context; 3477 LocalContext context;
Michael Starzinger 2013/03/14 19:10:26 Here the LocalContext is available, move it up and
Sven Panne 2013/03/15 07:59:09 Done.
3478 v8::TryCatch try_catch; 3478 v8::TryCatch try_catch;
3479 try_catch.SetVerbose(true); 3479 try_catch.SetVerbose(true);
3480 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); 3480 Local<Value> result = CompileRun("function foo() { foo(); } foo();");
3481 CHECK(try_catch.HasCaught()); 3481 CHECK(try_catch.HasCaught());
3482 CHECK(result.IsEmpty()); 3482 CHECK(result.IsEmpty());
3483 CHECK(message_received); 3483 CHECK(message_received);
3484 v8::V8::RemoveMessageListeners(receive_message); 3484 v8::V8::RemoveMessageListeners(receive_message);
3485 } 3485 }
3486 3486
3487 3487
3488 THREADED_TEST(ExternalScriptException) { 3488 THREADED_TEST(ExternalScriptException) {
3489 v8::HandleScope scope; 3489 v8::HandleScope scope(v8::Isolate::GetCurrent());
3490 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3490 Local<ObjectTemplate> templ = ObjectTemplate::New();
3491 templ->Set(v8_str("ThrowFromC"), 3491 templ->Set(v8_str("ThrowFromC"),
3492 v8::FunctionTemplate::New(ThrowFromC)); 3492 v8::FunctionTemplate::New(ThrowFromC));
3493 LocalContext context(0, templ); 3493 LocalContext context(0, templ);
3494 3494
3495 v8::TryCatch try_catch; 3495 v8::TryCatch try_catch;
3496 Local<Script> script 3496 Local<Script> script
3497 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); 3497 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
3498 Local<Value> result = script->Run(); 3498 Local<Value> result = script->Run();
3499 CHECK(result.IsEmpty()); 3499 CHECK(result.IsEmpty());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 if (equality) { 3546 if (equality) {
3547 CHECK_EQ(count, expected); 3547 CHECK_EQ(count, expected);
3548 } else { 3548 } else {
3549 CHECK_NE(count, expected); 3549 CHECK_NE(count, expected);
3550 } 3550 }
3551 return v8::Undefined(); 3551 return v8::Undefined();
3552 } 3552 }
3553 3553
3554 3554
3555 THREADED_TEST(EvalInTryFinally) { 3555 THREADED_TEST(EvalInTryFinally) {
3556 v8::HandleScope scope;
3557 LocalContext context; 3556 LocalContext context;
3557 v8::HandleScope scope(context->GetIsolate());
3558 v8::TryCatch try_catch; 3558 v8::TryCatch try_catch;
3559 CompileRun("(function() {" 3559 CompileRun("(function() {"
3560 " try {" 3560 " try {"
3561 " eval('asldkf (*&^&*^');" 3561 " eval('asldkf (*&^&*^');"
3562 " } finally {" 3562 " } finally {"
3563 " return;" 3563 " return;"
3564 " }" 3564 " }"
3565 "})()"); 3565 "})()");
3566 CHECK(!try_catch.HasCaught()); 3566 CHECK(!try_catch.HasCaught());
3567 } 3567 }
(...skipping 13 matching lines...) Expand all
3581 // 3581 //
3582 // Each entry is an activation, either JS or C. The index is the count at that 3582 // Each entry is an activation, either JS or C. The index is the count at that
3583 // level. Stars identify activations with exception handlers, the @ identifies 3583 // level. Stars identify activations with exception handlers, the @ identifies
3584 // the exception handler that should catch the exception. 3584 // the exception handler that should catch the exception.
3585 // 3585 //
3586 // BUG(271): Some of the exception propagation does not work on the 3586 // BUG(271): Some of the exception propagation does not work on the
3587 // ARM simulator because the simulator separates the C++ stack and the 3587 // ARM simulator because the simulator separates the C++ stack and the
3588 // JS stack. This test therefore fails on the simulator. The test is 3588 // JS stack. This test therefore fails on the simulator. The test is
3589 // not threaded to allow the threading tests to run on the simulator. 3589 // not threaded to allow the threading tests to run on the simulator.
3590 TEST(ExceptionOrder) { 3590 TEST(ExceptionOrder) {
3591 v8::HandleScope scope; 3591 v8::HandleScope scope(v8::Isolate::GetCurrent());
3592 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3592 Local<ObjectTemplate> templ = ObjectTemplate::New();
3593 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); 3593 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck));
3594 templ->Set(v8_str("CThrowCountDown"), 3594 templ->Set(v8_str("CThrowCountDown"),
3595 v8::FunctionTemplate::New(CThrowCountDown)); 3595 v8::FunctionTemplate::New(CThrowCountDown));
3596 LocalContext context(0, templ); 3596 LocalContext context(0, templ);
3597 CompileRun( 3597 CompileRun(
3598 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" 3598 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
3599 " if (count == 0) throw 'FromJS';" 3599 " if (count == 0) throw 'FromJS';"
3600 " if (count % jsInterval == 0) {" 3600 " if (count % jsInterval == 0) {"
3601 " try {" 3601 " try {"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3645 3645
3646 3646
3647 v8::Handle<Value> ThrowValue(const v8::Arguments& args) { 3647 v8::Handle<Value> ThrowValue(const v8::Arguments& args) {
3648 ApiTestFuzzer::Fuzz(); 3648 ApiTestFuzzer::Fuzz();
3649 CHECK_EQ(1, args.Length()); 3649 CHECK_EQ(1, args.Length());
3650 return v8::ThrowException(args[0]); 3650 return v8::ThrowException(args[0]);
3651 } 3651 }
3652 3652
3653 3653
3654 THREADED_TEST(ThrowValues) { 3654 THREADED_TEST(ThrowValues) {
3655 v8::HandleScope scope; 3655 v8::HandleScope scope(v8::Isolate::GetCurrent());
3656 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3656 Local<ObjectTemplate> templ = ObjectTemplate::New();
3657 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue)); 3657 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue));
3658 LocalContext context(0, templ); 3658 LocalContext context(0, templ);
3659 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 3659 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
3660 "function Run(obj) {" 3660 "function Run(obj) {"
3661 " try {" 3661 " try {"
3662 " Throw(obj);" 3662 " Throw(obj);"
3663 " } catch (e) {" 3663 " } catch (e) {"
3664 " return e;" 3664 " return e;"
3665 " }" 3665 " }"
3666 " return 'no exception';" 3666 " return 'no exception';"
3667 "}" 3667 "}"
3668 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); 3668 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
3669 CHECK_EQ(5, result->Length()); 3669 CHECK_EQ(5, result->Length());
3670 CHECK(result->Get(v8::Integer::New(0))->IsString()); 3670 CHECK(result->Get(v8::Integer::New(0))->IsString());
3671 CHECK(result->Get(v8::Integer::New(1))->IsNumber()); 3671 CHECK(result->Get(v8::Integer::New(1))->IsNumber());
3672 CHECK_EQ(1, result->Get(v8::Integer::New(1))->Int32Value()); 3672 CHECK_EQ(1, result->Get(v8::Integer::New(1))->Int32Value());
3673 CHECK(result->Get(v8::Integer::New(2))->IsNumber()); 3673 CHECK(result->Get(v8::Integer::New(2))->IsNumber());
3674 CHECK_EQ(0, result->Get(v8::Integer::New(2))->Int32Value()); 3674 CHECK_EQ(0, result->Get(v8::Integer::New(2))->Int32Value());
3675 CHECK(result->Get(v8::Integer::New(3))->IsNull()); 3675 CHECK(result->Get(v8::Integer::New(3))->IsNull());
3676 CHECK(result->Get(v8::Integer::New(4))->IsUndefined()); 3676 CHECK(result->Get(v8::Integer::New(4))->IsUndefined());
3677 } 3677 }
3678 3678
3679 3679
3680 THREADED_TEST(CatchZero) { 3680 THREADED_TEST(CatchZero) {
3681 v8::HandleScope scope;
3682 LocalContext context; 3681 LocalContext context;
3682 v8::HandleScope scope(context->GetIsolate());
3683 v8::TryCatch try_catch; 3683 v8::TryCatch try_catch;
3684 CHECK(!try_catch.HasCaught()); 3684 CHECK(!try_catch.HasCaught());
3685 Script::Compile(v8_str("throw 10"))->Run(); 3685 Script::Compile(v8_str("throw 10"))->Run();
3686 CHECK(try_catch.HasCaught()); 3686 CHECK(try_catch.HasCaught());
3687 CHECK_EQ(10, try_catch.Exception()->Int32Value()); 3687 CHECK_EQ(10, try_catch.Exception()->Int32Value());
3688 try_catch.Reset(); 3688 try_catch.Reset();
3689 CHECK(!try_catch.HasCaught()); 3689 CHECK(!try_catch.HasCaught());
3690 Script::Compile(v8_str("throw 0"))->Run(); 3690 Script::Compile(v8_str("throw 0"))->Run();
3691 CHECK(try_catch.HasCaught()); 3691 CHECK(try_catch.HasCaught());
3692 CHECK_EQ(0, try_catch.Exception()->Int32Value()); 3692 CHECK_EQ(0, try_catch.Exception()->Int32Value());
3693 } 3693 }
3694 3694
3695 3695
3696 THREADED_TEST(CatchExceptionFromWith) { 3696 THREADED_TEST(CatchExceptionFromWith) {
3697 v8::HandleScope scope;
3698 LocalContext context; 3697 LocalContext context;
3698 v8::HandleScope scope(context->GetIsolate());
3699 v8::TryCatch try_catch; 3699 v8::TryCatch try_catch;
3700 CHECK(!try_catch.HasCaught()); 3700 CHECK(!try_catch.HasCaught());
3701 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); 3701 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run();
3702 CHECK(try_catch.HasCaught()); 3702 CHECK(try_catch.HasCaught());
3703 } 3703 }
3704 3704
3705 3705
3706 THREADED_TEST(TryCatchAndFinallyHidingException) { 3706 THREADED_TEST(TryCatchAndFinallyHidingException) {
3707 v8::HandleScope scope;
3708 LocalContext context; 3707 LocalContext context;
3708 v8::HandleScope scope(context->GetIsolate());
3709 v8::TryCatch try_catch; 3709 v8::TryCatch try_catch;
3710 CHECK(!try_catch.HasCaught()); 3710 CHECK(!try_catch.HasCaught());
3711 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); 3711 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };");
3712 CompileRun("f({toString: function() { throw 42; }});"); 3712 CompileRun("f({toString: function() { throw 42; }});");
3713 CHECK(!try_catch.HasCaught()); 3713 CHECK(!try_catch.HasCaught());
3714 } 3714 }
3715 3715
3716 3716
3717 v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) { 3717 v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) {
3718 v8::TryCatch try_catch; 3718 v8::TryCatch try_catch;
3719 return v8::Undefined(); 3719 return v8::Undefined();
3720 } 3720 }
3721 3721
3722 3722
3723 THREADED_TEST(TryCatchAndFinally) { 3723 THREADED_TEST(TryCatchAndFinally) {
3724 v8::HandleScope scope;
3725 LocalContext context; 3724 LocalContext context;
3725 v8::HandleScope scope(context->GetIsolate());
3726 context->Global()->Set( 3726 context->Global()->Set(
3727 v8_str("native_with_try_catch"), 3727 v8_str("native_with_try_catch"),
3728 v8::FunctionTemplate::New(WithTryCatch)->GetFunction()); 3728 v8::FunctionTemplate::New(WithTryCatch)->GetFunction());
3729 v8::TryCatch try_catch; 3729 v8::TryCatch try_catch;
3730 CHECK(!try_catch.HasCaught()); 3730 CHECK(!try_catch.HasCaught());
3731 CompileRun( 3731 CompileRun(
3732 "try {\n" 3732 "try {\n"
3733 " throw new Error('a');\n" 3733 " throw new Error('a');\n"
3734 "} finally {\n" 3734 "} finally {\n"
3735 " native_with_try_catch();\n" 3735 " native_with_try_catch();\n"
(...skipping 10 matching lines...) Expand all
3746 CHECK(try_catch.HasCaught()); 3746 CHECK(try_catch.HasCaught());
3747 try_catch.ReThrow(); 3747 try_catch.ReThrow();
3748 } else { 3748 } else {
3749 v8::ThrowException(v8_str("back")); 3749 v8::ThrowException(v8_str("back"));
3750 } 3750 }
3751 } 3751 }
3752 3752
3753 3753
3754 TEST(TryCatchNested) { 3754 TEST(TryCatchNested) {
3755 v8::V8::Initialize(); 3755 v8::V8::Initialize();
3756 v8::HandleScope scope;
3757 LocalContext context; 3756 LocalContext context;
3757 v8::HandleScope scope(context->GetIsolate());
3758 v8::TryCatch try_catch; 3758 v8::TryCatch try_catch;
3759 TryCatchNestedHelper(5); 3759 TryCatchNestedHelper(5);
3760 CHECK(try_catch.HasCaught()); 3760 CHECK(try_catch.HasCaught());
3761 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back")); 3761 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back"));
3762 } 3762 }
3763 3763
3764 3764
3765 THREADED_TEST(Equality) { 3765 THREADED_TEST(Equality) {
3766 v8::HandleScope scope;
3767 LocalContext context; 3766 LocalContext context;
3768 v8::Isolate* isolate = context->GetIsolate(); 3767 v8::Isolate* isolate = context->GetIsolate();
3768 v8::HandleScope scope(context->GetIsolate());
3769 // Check that equality works at all before relying on CHECK_EQ 3769 // Check that equality works at all before relying on CHECK_EQ
3770 CHECK(v8_str("a")->Equals(v8_str("a"))); 3770 CHECK(v8_str("a")->Equals(v8_str("a")));
3771 CHECK(!v8_str("a")->Equals(v8_str("b"))); 3771 CHECK(!v8_str("a")->Equals(v8_str("b")));
3772 3772
3773 CHECK_EQ(v8_str("a"), v8_str("a")); 3773 CHECK_EQ(v8_str("a"), v8_str("a"));
3774 CHECK_NE(v8_str("a"), v8_str("b")); 3774 CHECK_NE(v8_str("a"), v8_str("b"));
3775 CHECK_EQ(v8_num(1), v8_num(1)); 3775 CHECK_EQ(v8_num(1), v8_num(1));
3776 CHECK_EQ(v8_num(1.00), v8_num(1)); 3776 CHECK_EQ(v8_num(1.00), v8_num(1));
3777 CHECK_NE(v8_num(1), v8_num(2)); 3777 CHECK_NE(v8_num(1), v8_num(2));
3778 3778
(...skipping 11 matching lines...) Expand all
3790 3790
3791 v8::Handle<v8::Object> obj = v8::Object::New(); 3791 v8::Handle<v8::Object> obj = v8::Object::New();
3792 v8::Persistent<v8::Object> alias = 3792 v8::Persistent<v8::Object> alias =
3793 v8::Persistent<v8::Object>::New(isolate, obj); 3793 v8::Persistent<v8::Object>::New(isolate, obj);
3794 CHECK(alias->StrictEquals(obj)); 3794 CHECK(alias->StrictEquals(obj));
3795 alias.Dispose(isolate); 3795 alias.Dispose(isolate);
3796 } 3796 }
3797 3797
3798 3798
3799 THREADED_TEST(MultiRun) { 3799 THREADED_TEST(MultiRun) {
3800 v8::HandleScope scope;
3801 LocalContext context; 3800 LocalContext context;
3801 v8::HandleScope scope(context->GetIsolate());
3802 Local<Script> script = Script::Compile(v8_str("x")); 3802 Local<Script> script = Script::Compile(v8_str("x"));
3803 for (int i = 0; i < 10; i++) 3803 for (int i = 0; i < 10; i++)
3804 script->Run(); 3804 script->Run();
3805 } 3805 }
3806 3806
3807 3807
3808 static v8::Handle<Value> GetXValue(Local<String> name, 3808 static v8::Handle<Value> GetXValue(Local<String> name,
3809 const AccessorInfo& info) { 3809 const AccessorInfo& info) {
3810 ApiTestFuzzer::Fuzz(); 3810 ApiTestFuzzer::Fuzz();
3811 CHECK_EQ(info.Data(), v8_str("donut")); 3811 CHECK_EQ(info.Data(), v8_str("donut"));
3812 CHECK_EQ(name, v8_str("x")); 3812 CHECK_EQ(name, v8_str("x"));
3813 return name; 3813 return name;
3814 } 3814 }
3815 3815
3816 3816
3817 THREADED_TEST(SimplePropertyRead) { 3817 THREADED_TEST(SimplePropertyRead) {
3818 v8::HandleScope scope; 3818 v8::HandleScope scope(v8::Isolate::GetCurrent());
3819 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3819 Local<ObjectTemplate> templ = ObjectTemplate::New();
3820 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 3820 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
3821 LocalContext context; 3821 LocalContext context;
Michael Starzinger 2013/03/14 19:10:26 Likewise.
Sven Panne 2013/03/15 07:59:09 Done.
3822 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 3822 context->Global()->Set(v8_str("obj"), templ->NewInstance());
3823 Local<Script> script = Script::Compile(v8_str("obj.x")); 3823 Local<Script> script = Script::Compile(v8_str("obj.x"));
3824 for (int i = 0; i < 10; i++) { 3824 for (int i = 0; i < 10; i++) {
3825 Local<Value> result = script->Run(); 3825 Local<Value> result = script->Run();
3826 CHECK_EQ(result, v8_str("x")); 3826 CHECK_EQ(result, v8_str("x"));
3827 } 3827 }
3828 } 3828 }
3829 3829
3830 THREADED_TEST(DefinePropertyOnAPIAccessor) { 3830 THREADED_TEST(DefinePropertyOnAPIAccessor) {
3831 v8::HandleScope scope; 3831 v8::HandleScope scope(v8::Isolate::GetCurrent());
3832 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3832 Local<ObjectTemplate> templ = ObjectTemplate::New();
3833 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 3833 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
3834 LocalContext context; 3834 LocalContext context;
Michael Starzinger 2013/03/14 19:10:26 Likewise, and several occurrences below.
Sven Panne 2013/03/15 07:59:09 Done.
3835 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 3835 context->Global()->Set(v8_str("obj"), templ->NewInstance());
3836 3836
3837 // Uses getOwnPropertyDescriptor to check the configurable status 3837 // Uses getOwnPropertyDescriptor to check the configurable status
3838 Local<Script> script_desc 3838 Local<Script> script_desc
3839 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( " 3839 = Script::Compile(v8_str("var prop = Object.getOwnPropertyDescriptor( "
3840 "obj, 'x');" 3840 "obj, 'x');"
3841 "prop.configurable;")); 3841 "prop.configurable;"));
3842 Local<Value> result = script_desc->Run(); 3842 Local<Value> result = script_desc->Run();
3843 CHECK_EQ(result->BooleanValue(), true); 3843 CHECK_EQ(result->BooleanValue(), true);
3844 3844
(...skipping 23 matching lines...) Expand all
3868 3868
3869 // Make sure that it is not possible to redefine again 3869 // Make sure that it is not possible to redefine again
3870 v8::TryCatch try_catch; 3870 v8::TryCatch try_catch;
3871 result = script_define->Run(); 3871 result = script_define->Run();
3872 CHECK(try_catch.HasCaught()); 3872 CHECK(try_catch.HasCaught());
3873 String::AsciiValue exception_value(try_catch.Exception()); 3873 String::AsciiValue exception_value(try_catch.Exception());
3874 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x"); 3874 CHECK_EQ(*exception_value, "TypeError: Cannot redefine property: x");
3875 } 3875 }
3876 3876
3877 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { 3877 THREADED_TEST(DefinePropertyOnDefineGetterSetter) {
3878 v8::HandleScope scope; 3878 v8::HandleScope scope(v8::Isolate::GetCurrent());
3879 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3879 Local<ObjectTemplate> templ = ObjectTemplate::New();
3880 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 3880 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
3881 LocalContext context; 3881 LocalContext context;
3882 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 3882 context->Global()->Set(v8_str("obj"), templ->NewInstance());
3883 3883
3884 Local<Script> script_desc = Script::Compile(v8_str("var prop =" 3884 Local<Script> script_desc = Script::Compile(v8_str("var prop ="
3885 "Object.getOwnPropertyDescriptor( " 3885 "Object.getOwnPropertyDescriptor( "
3886 "obj, 'x');" 3886 "obj, 'x');"
3887 "prop.configurable;")); 3887 "prop.configurable;"));
3888 Local<Value> result = script_desc->Run(); 3888 Local<Value> result = script_desc->Run();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3920 } 3920 }
3921 3921
3922 3922
3923 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, 3923 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context,
3924 char const* name) { 3924 char const* name) {
3925 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); 3925 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name)));
3926 } 3926 }
3927 3927
3928 3928
3929 THREADED_TEST(DefineAPIAccessorOnObject) { 3929 THREADED_TEST(DefineAPIAccessorOnObject) {
3930 v8::HandleScope scope; 3930 v8::HandleScope scope(v8::Isolate::GetCurrent());
3931 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3931 Local<ObjectTemplate> templ = ObjectTemplate::New();
3932 LocalContext context; 3932 LocalContext context;
3933 3933
3934 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 3934 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
3935 CompileRun("var obj2 = {};"); 3935 CompileRun("var obj2 = {};");
3936 3936
3937 CHECK(CompileRun("obj1.x")->IsUndefined()); 3937 CHECK(CompileRun("obj1.x")->IsUndefined());
3938 CHECK(CompileRun("obj2.x")->IsUndefined()); 3938 CHECK(CompileRun("obj2.x")->IsUndefined());
3939 3939
3940 CHECK(GetGlobalProperty(&context, "obj1")-> 3940 CHECK(GetGlobalProperty(&context, "obj1")->
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3994 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 3994 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
3995 CHECK(!GetGlobalProperty(&context, "obj2")-> 3995 CHECK(!GetGlobalProperty(&context, "obj2")->
3996 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 3996 SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")));
3997 3997
3998 ExpectString("obj1.x", "z"); 3998 ExpectString("obj1.x", "z");
3999 ExpectString("obj2.x", "z"); 3999 ExpectString("obj2.x", "z");
4000 } 4000 }
4001 4001
4002 4002
4003 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { 4003 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) {
4004 v8::HandleScope scope; 4004 v8::HandleScope scope(v8::Isolate::GetCurrent());
4005 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4005 Local<ObjectTemplate> templ = ObjectTemplate::New();
4006 LocalContext context; 4006 LocalContext context;
4007 4007
4008 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 4008 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
4009 CompileRun("var obj2 = {};"); 4009 CompileRun("var obj2 = {};");
4010 4010
4011 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 4011 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
4012 v8_str("x"), 4012 v8_str("x"),
4013 GetXValue, NULL, 4013 GetXValue, NULL,
4014 v8_str("donut"), v8::DEFAULT, v8::DontDelete)); 4014 v8_str("donut"), v8::DEFAULT, v8::DontDelete));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4050 static v8::Handle<Value> Get239Value(Local<String> name, 4050 static v8::Handle<Value> Get239Value(Local<String> name,
4051 const AccessorInfo& info) { 4051 const AccessorInfo& info) {
4052 ApiTestFuzzer::Fuzz(); 4052 ApiTestFuzzer::Fuzz();
4053 CHECK_EQ(info.Data(), v8_str("donut")); 4053 CHECK_EQ(info.Data(), v8_str("donut"));
4054 CHECK_EQ(name, v8_str("239")); 4054 CHECK_EQ(name, v8_str("239"));
4055 return name; 4055 return name;
4056 } 4056 }
4057 4057
4058 4058
4059 THREADED_TEST(ElementAPIAccessor) { 4059 THREADED_TEST(ElementAPIAccessor) {
4060 v8::HandleScope scope; 4060 v8::HandleScope scope(v8::Isolate::GetCurrent());
4061 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4061 Local<ObjectTemplate> templ = ObjectTemplate::New();
4062 LocalContext context; 4062 LocalContext context;
4063 4063
4064 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 4064 context->Global()->Set(v8_str("obj1"), templ->NewInstance());
4065 CompileRun("var obj2 = {};"); 4065 CompileRun("var obj2 = {};");
4066 4066
4067 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor( 4067 CHECK(GetGlobalProperty(&context, "obj1")->SetAccessor(
4068 v8_str("239"), 4068 v8_str("239"),
4069 Get239Value, NULL, 4069 Get239Value, NULL,
4070 v8_str("donut"))); 4070 v8_str("donut")));
(...skipping 17 matching lines...) Expand all
4088 const AccessorInfo& info) { 4088 const AccessorInfo& info) {
4089 CHECK_EQ(value, v8_num(4)); 4089 CHECK_EQ(value, v8_num(4));
4090 CHECK_EQ(info.Data(), v8_str("donut")); 4090 CHECK_EQ(info.Data(), v8_str("donut"));
4091 CHECK_EQ(name, v8_str("x")); 4091 CHECK_EQ(name, v8_str("x"));
4092 CHECK(xValue.IsEmpty()); 4092 CHECK(xValue.IsEmpty());
4093 xValue = v8::Persistent<Value>::New(info.GetIsolate(), value); 4093 xValue = v8::Persistent<Value>::New(info.GetIsolate(), value);
4094 } 4094 }
4095 4095
4096 4096
4097 THREADED_TEST(SimplePropertyWrite) { 4097 THREADED_TEST(SimplePropertyWrite) {
4098 v8::HandleScope scope; 4098 v8::HandleScope scope(v8::Isolate::GetCurrent());
4099 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4099 Local<ObjectTemplate> templ = ObjectTemplate::New();
4100 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 4100 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
4101 LocalContext context; 4101 LocalContext context;
4102 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4102 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4103 Local<Script> script = Script::Compile(v8_str("obj.x = 4")); 4103 Local<Script> script = Script::Compile(v8_str("obj.x = 4"));
4104 for (int i = 0; i < 10; i++) { 4104 for (int i = 0; i < 10; i++) {
4105 CHECK(xValue.IsEmpty()); 4105 CHECK(xValue.IsEmpty());
4106 script->Run(); 4106 script->Run();
4107 CHECK_EQ(v8_num(4), xValue); 4107 CHECK_EQ(v8_num(4), xValue);
4108 xValue.Dispose(context->GetIsolate()); 4108 xValue.Dispose(context->GetIsolate());
4109 xValue = v8::Persistent<Value>(); 4109 xValue = v8::Persistent<Value>();
4110 } 4110 }
4111 } 4111 }
4112 4112
4113 4113
4114 THREADED_TEST(SetterOnly) { 4114 THREADED_TEST(SetterOnly) {
4115 v8::HandleScope scope; 4115 v8::HandleScope scope(v8::Isolate::GetCurrent());
4116 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4116 Local<ObjectTemplate> templ = ObjectTemplate::New();
4117 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 4117 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
4118 LocalContext context; 4118 LocalContext context;
4119 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4119 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4120 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 4120 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
4121 for (int i = 0; i < 10; i++) { 4121 for (int i = 0; i < 10; i++) {
4122 CHECK(xValue.IsEmpty()); 4122 CHECK(xValue.IsEmpty());
4123 script->Run(); 4123 script->Run();
4124 CHECK_EQ(v8_num(4), xValue); 4124 CHECK_EQ(v8_num(4), xValue);
4125 xValue.Dispose(context->GetIsolate()); 4125 xValue.Dispose(context->GetIsolate());
4126 xValue = v8::Persistent<Value>(); 4126 xValue = v8::Persistent<Value>();
4127 } 4127 }
4128 } 4128 }
4129 4129
4130 4130
4131 THREADED_TEST(NoAccessors) { 4131 THREADED_TEST(NoAccessors) {
4132 v8::HandleScope scope; 4132 v8::HandleScope scope(v8::Isolate::GetCurrent());
4133 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4133 Local<ObjectTemplate> templ = ObjectTemplate::New();
4134 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut")); 4134 templ->SetAccessor(v8_str("x"), NULL, NULL, v8_str("donut"));
4135 LocalContext context; 4135 LocalContext context;
4136 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4136 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4137 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x")); 4137 Local<Script> script = Script::Compile(v8_str("obj.x = 4; obj.x"));
4138 for (int i = 0; i < 10; i++) { 4138 for (int i = 0; i < 10; i++) {
4139 script->Run(); 4139 script->Run();
4140 } 4140 }
4141 } 4141 }
4142 4142
4143 4143
4144 static v8::Handle<Value> XPropertyGetter(Local<String> property, 4144 static v8::Handle<Value> XPropertyGetter(Local<String> property,
4145 const AccessorInfo& info) { 4145 const AccessorInfo& info) {
4146 ApiTestFuzzer::Fuzz(); 4146 ApiTestFuzzer::Fuzz();
4147 CHECK(info.Data()->IsUndefined()); 4147 CHECK(info.Data()->IsUndefined());
4148 return property; 4148 return property;
4149 } 4149 }
4150 4150
4151 4151
4152 THREADED_TEST(NamedInterceptorPropertyRead) { 4152 THREADED_TEST(NamedInterceptorPropertyRead) {
4153 v8::HandleScope scope; 4153 v8::HandleScope scope(v8::Isolate::GetCurrent());
4154 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4154 Local<ObjectTemplate> templ = ObjectTemplate::New();
4155 templ->SetNamedPropertyHandler(XPropertyGetter); 4155 templ->SetNamedPropertyHandler(XPropertyGetter);
4156 LocalContext context; 4156 LocalContext context;
4157 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4157 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4158 Local<Script> script = Script::Compile(v8_str("obj.x")); 4158 Local<Script> script = Script::Compile(v8_str("obj.x"));
4159 for (int i = 0; i < 10; i++) { 4159 for (int i = 0; i < 10; i++) {
4160 Local<Value> result = script->Run(); 4160 Local<Value> result = script->Run();
4161 CHECK_EQ(result, v8_str("x")); 4161 CHECK_EQ(result, v8_str("x"));
4162 } 4162 }
4163 } 4163 }
4164 4164
4165 4165
4166 THREADED_TEST(NamedInterceptorDictionaryIC) { 4166 THREADED_TEST(NamedInterceptorDictionaryIC) {
4167 v8::HandleScope scope; 4167 v8::HandleScope scope(v8::Isolate::GetCurrent());
4168 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4168 Local<ObjectTemplate> templ = ObjectTemplate::New();
4169 templ->SetNamedPropertyHandler(XPropertyGetter); 4169 templ->SetNamedPropertyHandler(XPropertyGetter);
4170 LocalContext context; 4170 LocalContext context;
4171 // Create an object with a named interceptor. 4171 // Create an object with a named interceptor.
4172 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance()); 4172 context->Global()->Set(v8_str("interceptor_obj"), templ->NewInstance());
4173 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x")); 4173 Local<Script> script = Script::Compile(v8_str("interceptor_obj.x"));
4174 for (int i = 0; i < 10; i++) { 4174 for (int i = 0; i < 10; i++) {
4175 Local<Value> result = script->Run(); 4175 Local<Value> result = script->Run();
4176 CHECK_EQ(result, v8_str("x")); 4176 CHECK_EQ(result, v8_str("x"));
4177 } 4177 }
4178 // Create a slow case object and a function accessing a property in 4178 // Create a slow case object and a function accessing a property in
4179 // that slow case object (with dictionary probing in generated 4179 // that slow case object (with dictionary probing in generated
4180 // code). Then force object with a named interceptor into slow-case, 4180 // code). Then force object with a named interceptor into slow-case,
4181 // pass it to the function, and check that the interceptor is called 4181 // pass it to the function, and check that the interceptor is called
4182 // instead of accessing the local property. 4182 // instead of accessing the local property.
4183 Local<Value> result = 4183 Local<Value> result =
4184 CompileRun("function get_x(o) { return o.x; };" 4184 CompileRun("function get_x(o) { return o.x; };"
4185 "var obj = { x : 42, y : 0 };" 4185 "var obj = { x : 42, y : 0 };"
4186 "delete obj.y;" 4186 "delete obj.y;"
4187 "for (var i = 0; i < 10; i++) get_x(obj);" 4187 "for (var i = 0; i < 10; i++) get_x(obj);"
4188 "interceptor_obj.x = 42;" 4188 "interceptor_obj.x = 42;"
4189 "interceptor_obj.y = 10;" 4189 "interceptor_obj.y = 10;"
4190 "delete interceptor_obj.y;" 4190 "delete interceptor_obj.y;"
4191 "get_x(interceptor_obj)"); 4191 "get_x(interceptor_obj)");
4192 CHECK_EQ(result, v8_str("x")); 4192 CHECK_EQ(result, v8_str("x"));
4193 } 4193 }
4194 4194
4195 4195
4196 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) { 4196 THREADED_TEST(NamedInterceptorDictionaryICMultipleContext) {
4197 v8::HandleScope scope; 4197 v8::HandleScope scope(v8::Isolate::GetCurrent());
4198 4198
4199 v8::Persistent<Context> context1 = Context::New(); 4199 v8::Persistent<Context> context1 = Context::New();
4200 4200
4201 context1->Enter(); 4201 context1->Enter();
4202 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4202 Local<ObjectTemplate> templ = ObjectTemplate::New();
4203 templ->SetNamedPropertyHandler(XPropertyGetter); 4203 templ->SetNamedPropertyHandler(XPropertyGetter);
4204 // Create an object with a named interceptor. 4204 // Create an object with a named interceptor.
4205 v8::Local<v8::Object> object = templ->NewInstance(); 4205 v8::Local<v8::Object> object = templ->NewInstance();
4206 context1->Global()->Set(v8_str("interceptor_obj"), object); 4206 context1->Global()->Set(v8_str("interceptor_obj"), object);
4207 4207
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4241 // Set x on the prototype object and do not handle the get request. 4241 // Set x on the prototype object and do not handle the get request.
4242 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 4242 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
4243 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 4243 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
4244 return v8::Handle<Value>(); 4244 return v8::Handle<Value>();
4245 } 4245 }
4246 4246
4247 4247
4248 // This is a regression test for http://crbug.com/20104. Map 4248 // This is a regression test for http://crbug.com/20104. Map
4249 // transitions should not interfere with post interceptor lookup. 4249 // transitions should not interfere with post interceptor lookup.
4250 THREADED_TEST(NamedInterceptorMapTransitionRead) { 4250 THREADED_TEST(NamedInterceptorMapTransitionRead) {
4251 v8::HandleScope scope; 4251 v8::HandleScope scope(v8::Isolate::GetCurrent());
4252 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); 4252 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New();
4253 Local<v8::ObjectTemplate> instance_template 4253 Local<v8::ObjectTemplate> instance_template
4254 = function_template->InstanceTemplate(); 4254 = function_template->InstanceTemplate();
4255 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); 4255 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
4256 LocalContext context; 4256 LocalContext context;
4257 context->Global()->Set(v8_str("F"), function_template->GetFunction()); 4257 context->Global()->Set(v8_str("F"), function_template->GetFunction());
4258 // Create an instance of F and introduce a map transition for x. 4258 // Create an instance of F and introduce a map transition for x.
4259 CompileRun("var o = new F(); o.x = 23;"); 4259 CompileRun("var o = new F(); o.x = 23;");
4260 // Create an instance of F and invoke the getter. The result should be 23. 4260 // Create an instance of F and invoke the getter. The result should be 23.
4261 Local<Value> result = CompileRun("o = new F(); o.x"); 4261 Local<Value> result = CompileRun("o = new F(); o.x");
(...skipping 16 matching lines...) Expand all
4278 const AccessorInfo& info) { 4278 const AccessorInfo& info) {
4279 ApiTestFuzzer::Fuzz(); 4279 ApiTestFuzzer::Fuzz();
4280 if (index == 39) { 4280 if (index == 39) {
4281 return value; 4281 return value;
4282 } 4282 }
4283 return v8::Handle<Value>(); 4283 return v8::Handle<Value>();
4284 } 4284 }
4285 4285
4286 4286
4287 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) { 4287 THREADED_TEST(IndexedInterceptorWithIndexedAccessor) {
4288 v8::HandleScope scope; 4288 v8::HandleScope scope(v8::Isolate::GetCurrent());
4289 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4289 Local<ObjectTemplate> templ = ObjectTemplate::New();
4290 templ->SetIndexedPropertyHandler(IndexedPropertyGetter, 4290 templ->SetIndexedPropertyHandler(IndexedPropertyGetter,
4291 IndexedPropertySetter); 4291 IndexedPropertySetter);
4292 LocalContext context; 4292 LocalContext context;
4293 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4293 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4294 Local<Script> getter_script = Script::Compile(v8_str( 4294 Local<Script> getter_script = Script::Compile(v8_str(
4295 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];")); 4295 "obj.__defineGetter__(\"3\", function(){return 5;});obj[3];"));
4296 Local<Script> setter_script = Script::Compile(v8_str( 4296 Local<Script> setter_script = Script::Compile(v8_str(
4297 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});" 4297 "obj.__defineSetter__(\"17\", function(val){this.foo = val;});"
4298 "obj[17] = 23;" 4298 "obj[17] = 23;"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4345 "for(i = 0; i < 80000; i++) { keys[i] = i; };" 4345 "for(i = 0; i < 80000; i++) { keys[i] = i; };"
4346 "keys.length = 25; keys;")); 4346 "keys.length = 25; keys;"));
4347 Local<Value> result = indexed_property_names_script->Run(); 4347 Local<Value> result = indexed_property_names_script->Run();
4348 return Local<v8::Array>(::v8::Array::Cast(*result)); 4348 return Local<v8::Array>(::v8::Array::Cast(*result));
4349 } 4349 }
4350 4350
4351 4351
4352 // Make sure that the the interceptor code in the runtime properly handles 4352 // Make sure that the the interceptor code in the runtime properly handles
4353 // merging property name lists for double-array-backed arrays. 4353 // merging property name lists for double-array-backed arrays.
4354 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) { 4354 THREADED_TEST(IndexedInterceptorUnboxedDoubleWithIndexedAccessor) {
4355 v8::HandleScope scope; 4355 v8::HandleScope scope(v8::Isolate::GetCurrent());
4356 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4356 Local<ObjectTemplate> templ = ObjectTemplate::New();
4357 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter, 4357 templ->SetIndexedPropertyHandler(UnboxedDoubleIndexedPropertyGetter,
4358 UnboxedDoubleIndexedPropertySetter, 4358 UnboxedDoubleIndexedPropertySetter,
4359 0, 4359 0,
4360 0, 4360 0,
4361 UnboxedDoubleIndexedPropertyEnumerator); 4361 UnboxedDoubleIndexedPropertyEnumerator);
4362 LocalContext context; 4362 LocalContext context;
4363 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4363 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4364 // When obj is created, force it to be Stored in a FastDoubleArray. 4364 // When obj is created, force it to be Stored in a FastDoubleArray.
4365 Local<Script> create_unboxed_double_script = Script::Compile(v8_str( 4365 Local<Script> create_unboxed_double_script = Script::Compile(v8_str(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 if (index < 4) { 4397 if (index < 4) {
4398 return v8::Handle<Value>(v8_num(index)); 4398 return v8::Handle<Value>(v8_num(index));
4399 } 4399 }
4400 return v8::Handle<Value>(); 4400 return v8::Handle<Value>();
4401 } 4401 }
4402 4402
4403 4403
4404 // Make sure that the the interceptor code in the runtime properly handles 4404 // Make sure that the the interceptor code in the runtime properly handles
4405 // merging property name lists for non-string arguments arrays. 4405 // merging property name lists for non-string arguments arrays.
4406 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) { 4406 THREADED_TEST(IndexedInterceptorNonStrictArgsWithIndexedAccessor) {
4407 v8::HandleScope scope; 4407 v8::HandleScope scope(v8::Isolate::GetCurrent());
4408 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4408 Local<ObjectTemplate> templ = ObjectTemplate::New();
4409 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter, 4409 templ->SetIndexedPropertyHandler(NonStrictIndexedPropertyGetter,
4410 0, 4410 0,
4411 0, 4411 0,
4412 0, 4412 0,
4413 NonStrictArgsIndexedPropertyEnumerator); 4413 NonStrictArgsIndexedPropertyEnumerator);
4414 LocalContext context; 4414 LocalContext context;
4415 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4415 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4416 Local<Script> create_args_script = 4416 Local<Script> create_args_script =
4417 Script::Compile(v8_str( 4417 Script::Compile(v8_str(
4418 "var key_count = 0;" 4418 "var key_count = 0;"
4419 "for (x in obj) {key_count++;} key_count;")); 4419 "for (x in obj) {key_count++;} key_count;"));
4420 Local<Value> result = create_args_script->Run(); 4420 Local<Value> result = create_args_script->Run();
4421 CHECK_EQ(v8_num(4), result); 4421 CHECK_EQ(v8_num(4), result);
4422 } 4422 }
4423 4423
4424 4424
4425 static v8::Handle<Value> IdentityIndexedPropertyGetter( 4425 static v8::Handle<Value> IdentityIndexedPropertyGetter(
4426 uint32_t index, 4426 uint32_t index,
4427 const AccessorInfo& info) { 4427 const AccessorInfo& info) {
4428 return v8::Integer::NewFromUnsigned(index); 4428 return v8::Integer::NewFromUnsigned(index);
4429 } 4429 }
4430 4430
4431 4431
4432 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) { 4432 THREADED_TEST(IndexedInterceptorWithGetOwnPropertyDescriptor) {
4433 v8::HandleScope scope; 4433 v8::HandleScope scope(v8::Isolate::GetCurrent());
4434 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4434 Local<ObjectTemplate> templ = ObjectTemplate::New();
4435 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4435 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4436 4436
4437 LocalContext context; 4437 LocalContext context;
4438 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4438 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4439 4439
4440 // Check fast object case. 4440 // Check fast object case.
4441 const char* fast_case_code = 4441 const char* fast_case_code =
4442 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()"; 4442 "Object.getOwnPropertyDescriptor(obj, 0).value.toString()";
4443 ExpectString(fast_case_code, "0"); 4443 ExpectString(fast_case_code, "0");
4444 4444
4445 // Check slow case. 4445 // Check slow case.
4446 const char* slow_case_code = 4446 const char* slow_case_code =
4447 "obj.x = 1; delete obj.x;" 4447 "obj.x = 1; delete obj.x;"
4448 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()"; 4448 "Object.getOwnPropertyDescriptor(obj, 1).value.toString()";
4449 ExpectString(slow_case_code, "1"); 4449 ExpectString(slow_case_code, "1");
4450 } 4450 }
4451 4451
4452 4452
4453 THREADED_TEST(IndexedInterceptorWithNoSetter) { 4453 THREADED_TEST(IndexedInterceptorWithNoSetter) {
4454 v8::HandleScope scope; 4454 v8::HandleScope scope(v8::Isolate::GetCurrent());
4455 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4455 Local<ObjectTemplate> templ = ObjectTemplate::New();
4456 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4456 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4457 4457
4458 LocalContext context; 4458 LocalContext context;
4459 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 4459 context->Global()->Set(v8_str("obj"), templ->NewInstance());
4460 4460
4461 const char* code = 4461 const char* code =
4462 "try {" 4462 "try {"
4463 " obj[0] = 239;" 4463 " obj[0] = 239;"
4464 " for (var i = 0; i < 100; i++) {" 4464 " for (var i = 0; i < 100; i++) {"
4465 " var v = obj[0];" 4465 " var v = obj[0];"
4466 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;" 4466 " if (v != 0) throw 'Wrong value ' + v + ' at iteration ' + i;"
4467 " }" 4467 " }"
4468 " 'PASSED'" 4468 " 'PASSED'"
4469 "} catch(e) {" 4469 "} catch(e) {"
4470 " e" 4470 " e"
4471 "}"; 4471 "}";
4472 ExpectString(code, "PASSED"); 4472 ExpectString(code, "PASSED");
4473 } 4473 }
4474 4474
4475 4475
4476 THREADED_TEST(IndexedInterceptorWithAccessorCheck) { 4476 THREADED_TEST(IndexedInterceptorWithAccessorCheck) {
4477 v8::HandleScope scope; 4477 v8::HandleScope scope(v8::Isolate::GetCurrent());
4478 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4478 Local<ObjectTemplate> templ = ObjectTemplate::New();
4479 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4479 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4480 4480
4481 LocalContext context; 4481 LocalContext context;
4482 Local<v8::Object> obj = templ->NewInstance(); 4482 Local<v8::Object> obj = templ->NewInstance();
4483 obj->TurnOnAccessCheck(); 4483 obj->TurnOnAccessCheck();
4484 context->Global()->Set(v8_str("obj"), obj); 4484 context->Global()->Set(v8_str("obj"), obj);
4485 4485
4486 const char* code = 4486 const char* code =
4487 "try {" 4487 "try {"
4488 " for (var i = 0; i < 100; i++) {" 4488 " for (var i = 0; i < 100; i++) {"
4489 " var v = obj[0];" 4489 " var v = obj[0];"
4490 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;" 4490 " if (v != undefined) throw 'Wrong value ' + v + ' at iteration ' + i;"
4491 " }" 4491 " }"
4492 " 'PASSED'" 4492 " 'PASSED'"
4493 "} catch(e) {" 4493 "} catch(e) {"
4494 " e" 4494 " e"
4495 "}"; 4495 "}";
4496 ExpectString(code, "PASSED"); 4496 ExpectString(code, "PASSED");
4497 } 4497 }
4498 4498
4499 4499
4500 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) { 4500 THREADED_TEST(IndexedInterceptorWithAccessorCheckSwitchedOn) {
4501 i::FLAG_allow_natives_syntax = true; 4501 i::FLAG_allow_natives_syntax = true;
4502 v8::HandleScope scope; 4502 v8::HandleScope scope(v8::Isolate::GetCurrent());
4503 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4503 Local<ObjectTemplate> templ = ObjectTemplate::New();
4504 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4504 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4505 4505
4506 LocalContext context; 4506 LocalContext context;
4507 Local<v8::Object> obj = templ->NewInstance(); 4507 Local<v8::Object> obj = templ->NewInstance();
4508 context->Global()->Set(v8_str("obj"), obj); 4508 context->Global()->Set(v8_str("obj"), obj);
4509 4509
4510 const char* code = 4510 const char* code =
4511 "try {" 4511 "try {"
4512 " for (var i = 0; i < 100; i++) {" 4512 " for (var i = 0; i < 100; i++) {"
4513 " var expected = i;" 4513 " var expected = i;"
4514 " if (i == 5) {" 4514 " if (i == 5) {"
4515 " %EnableAccessChecks(obj);" 4515 " %EnableAccessChecks(obj);"
4516 " expected = undefined;" 4516 " expected = undefined;"
4517 " }" 4517 " }"
4518 " var v = obj[i];" 4518 " var v = obj[i];"
4519 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 4519 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4520 " if (i == 5) %DisableAccessChecks(obj);" 4520 " if (i == 5) %DisableAccessChecks(obj);"
4521 " }" 4521 " }"
4522 " 'PASSED'" 4522 " 'PASSED'"
4523 "} catch(e) {" 4523 "} catch(e) {"
4524 " e" 4524 " e"
4525 "}"; 4525 "}";
4526 ExpectString(code, "PASSED"); 4526 ExpectString(code, "PASSED");
4527 } 4527 }
4528 4528
4529 4529
4530 THREADED_TEST(IndexedInterceptorWithDifferentIndices) { 4530 THREADED_TEST(IndexedInterceptorWithDifferentIndices) {
4531 v8::HandleScope scope; 4531 v8::HandleScope scope(v8::Isolate::GetCurrent());
4532 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4532 Local<ObjectTemplate> templ = ObjectTemplate::New();
4533 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4533 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4534 4534
4535 LocalContext context; 4535 LocalContext context;
4536 Local<v8::Object> obj = templ->NewInstance(); 4536 Local<v8::Object> obj = templ->NewInstance();
4537 context->Global()->Set(v8_str("obj"), obj); 4537 context->Global()->Set(v8_str("obj"), obj);
4538 4538
4539 const char* code = 4539 const char* code =
4540 "try {" 4540 "try {"
4541 " for (var i = 0; i < 100; i++) {" 4541 " for (var i = 0; i < 100; i++) {"
4542 " var v = obj[i];" 4542 " var v = obj[i];"
4543 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 4543 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4544 " }" 4544 " }"
4545 " 'PASSED'" 4545 " 'PASSED'"
4546 "} catch(e) {" 4546 "} catch(e) {"
4547 " e" 4547 " e"
4548 "}"; 4548 "}";
4549 ExpectString(code, "PASSED"); 4549 ExpectString(code, "PASSED");
4550 } 4550 }
4551 4551
4552 4552
4553 THREADED_TEST(IndexedInterceptorWithNegativeIndices) { 4553 THREADED_TEST(IndexedInterceptorWithNegativeIndices) {
4554 v8::HandleScope scope; 4554 v8::HandleScope scope(v8::Isolate::GetCurrent());
4555 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4555 Local<ObjectTemplate> templ = ObjectTemplate::New();
4556 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4556 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4557 4557
4558 LocalContext context; 4558 LocalContext context;
4559 Local<v8::Object> obj = templ->NewInstance(); 4559 Local<v8::Object> obj = templ->NewInstance();
4560 context->Global()->Set(v8_str("obj"), obj); 4560 context->Global()->Set(v8_str("obj"), obj);
4561 4561
4562 const char* code = 4562 const char* code =
4563 "try {" 4563 "try {"
4564 " for (var i = 0; i < 100; i++) {" 4564 " for (var i = 0; i < 100; i++) {"
(...skipping 18 matching lines...) Expand all
4583 " }" 4583 " }"
4584 " 'PASSED'" 4584 " 'PASSED'"
4585 "} catch(e) {" 4585 "} catch(e) {"
4586 " e" 4586 " e"
4587 "}"; 4587 "}";
4588 ExpectString(code, "PASSED"); 4588 ExpectString(code, "PASSED");
4589 } 4589 }
4590 4590
4591 4591
4592 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) { 4592 THREADED_TEST(IndexedInterceptorWithNotSmiLookup) {
4593 v8::HandleScope scope; 4593 v8::HandleScope scope(v8::Isolate::GetCurrent());
4594 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4594 Local<ObjectTemplate> templ = ObjectTemplate::New();
4595 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4595 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4596 4596
4597 LocalContext context; 4597 LocalContext context;
4598 Local<v8::Object> obj = templ->NewInstance(); 4598 Local<v8::Object> obj = templ->NewInstance();
4599 context->Global()->Set(v8_str("obj"), obj); 4599 context->Global()->Set(v8_str("obj"), obj);
4600 4600
4601 const char* code = 4601 const char* code =
4602 "try {" 4602 "try {"
4603 " for (var i = 0; i < 100; i++) {" 4603 " for (var i = 0; i < 100; i++) {"
4604 " var expected = i;" 4604 " var expected = i;"
4605 " var key = i;" 4605 " var key = i;"
4606 " if (i == 50) {" 4606 " if (i == 50) {"
4607 " key = 'foobar';" 4607 " key = 'foobar';"
4608 " expected = undefined;" 4608 " expected = undefined;"
4609 " }" 4609 " }"
4610 " var v = obj[key];" 4610 " var v = obj[key];"
4611 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 4611 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4612 " }" 4612 " }"
4613 " 'PASSED'" 4613 " 'PASSED'"
4614 "} catch(e) {" 4614 "} catch(e) {"
4615 " e" 4615 " e"
4616 "}"; 4616 "}";
4617 ExpectString(code, "PASSED"); 4617 ExpectString(code, "PASSED");
4618 } 4618 }
4619 4619
4620 4620
4621 THREADED_TEST(IndexedInterceptorGoingMegamorphic) { 4621 THREADED_TEST(IndexedInterceptorGoingMegamorphic) {
4622 v8::HandleScope scope; 4622 v8::HandleScope scope(v8::Isolate::GetCurrent());
4623 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4623 Local<ObjectTemplate> templ = ObjectTemplate::New();
4624 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4624 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4625 4625
4626 LocalContext context; 4626 LocalContext context;
4627 Local<v8::Object> obj = templ->NewInstance(); 4627 Local<v8::Object> obj = templ->NewInstance();
4628 context->Global()->Set(v8_str("obj"), obj); 4628 context->Global()->Set(v8_str("obj"), obj);
4629 4629
4630 const char* code = 4630 const char* code =
4631 "var original = obj;" 4631 "var original = obj;"
4632 "try {" 4632 "try {"
4633 " for (var i = 0; i < 100; i++) {" 4633 " for (var i = 0; i < 100; i++) {"
4634 " var expected = i;" 4634 " var expected = i;"
4635 " if (i == 50) {" 4635 " if (i == 50) {"
4636 " obj = {50: 'foobar'};" 4636 " obj = {50: 'foobar'};"
4637 " expected = 'foobar';" 4637 " expected = 'foobar';"
4638 " }" 4638 " }"
4639 " var v = obj[i];" 4639 " var v = obj[i];"
4640 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 4640 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4641 " if (i == 50) obj = original;" 4641 " if (i == 50) obj = original;"
4642 " }" 4642 " }"
4643 " 'PASSED'" 4643 " 'PASSED'"
4644 "} catch(e) {" 4644 "} catch(e) {"
4645 " e" 4645 " e"
4646 "}"; 4646 "}";
4647 ExpectString(code, "PASSED"); 4647 ExpectString(code, "PASSED");
4648 } 4648 }
4649 4649
4650 4650
4651 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) { 4651 THREADED_TEST(IndexedInterceptorReceiverTurningSmi) {
4652 v8::HandleScope scope; 4652 v8::HandleScope scope(v8::Isolate::GetCurrent());
4653 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4653 Local<ObjectTemplate> templ = ObjectTemplate::New();
4654 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4654 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4655 4655
4656 LocalContext context; 4656 LocalContext context;
4657 Local<v8::Object> obj = templ->NewInstance(); 4657 Local<v8::Object> obj = templ->NewInstance();
4658 context->Global()->Set(v8_str("obj"), obj); 4658 context->Global()->Set(v8_str("obj"), obj);
4659 4659
4660 const char* code = 4660 const char* code =
4661 "var original = obj;" 4661 "var original = obj;"
4662 "try {" 4662 "try {"
4663 " for (var i = 0; i < 100; i++) {" 4663 " for (var i = 0; i < 100; i++) {"
4664 " var expected = i;" 4664 " var expected = i;"
4665 " if (i == 5) {" 4665 " if (i == 5) {"
4666 " obj = 239;" 4666 " obj = 239;"
4667 " expected = undefined;" 4667 " expected = undefined;"
4668 " }" 4668 " }"
4669 " var v = obj[i];" 4669 " var v = obj[i];"
4670 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;" 4670 " if (v != expected) throw 'Wrong value ' + v + ' at iteration ' + i;"
4671 " if (i == 5) obj = original;" 4671 " if (i == 5) obj = original;"
4672 " }" 4672 " }"
4673 " 'PASSED'" 4673 " 'PASSED'"
4674 "} catch(e) {" 4674 "} catch(e) {"
4675 " e" 4675 " e"
4676 "}"; 4676 "}";
4677 ExpectString(code, "PASSED"); 4677 ExpectString(code, "PASSED");
4678 } 4678 }
4679 4679
4680 4680
4681 THREADED_TEST(IndexedInterceptorOnProto) { 4681 THREADED_TEST(IndexedInterceptorOnProto) {
4682 v8::HandleScope scope; 4682 v8::HandleScope scope(v8::Isolate::GetCurrent());
4683 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4683 Local<ObjectTemplate> templ = ObjectTemplate::New();
4684 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter); 4684 templ->SetIndexedPropertyHandler(IdentityIndexedPropertyGetter);
4685 4685
4686 LocalContext context; 4686 LocalContext context;
4687 Local<v8::Object> obj = templ->NewInstance(); 4687 Local<v8::Object> obj = templ->NewInstance();
4688 context->Global()->Set(v8_str("obj"), obj); 4688 context->Global()->Set(v8_str("obj"), obj);
4689 4689
4690 const char* code = 4690 const char* code =
4691 "var o = {__proto__: obj};" 4691 "var o = {__proto__: obj};"
4692 "try {" 4692 "try {"
4693 " for (var i = 0; i < 100; i++) {" 4693 " for (var i = 0; i < 100; i++) {"
4694 " var v = o[i];" 4694 " var v = o[i];"
4695 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;" 4695 " if (v != i) throw 'Wrong value ' + v + ' at iteration ' + i;"
4696 " }" 4696 " }"
4697 " 'PASSED'" 4697 " 'PASSED'"
4698 "} catch(e) {" 4698 "} catch(e) {"
4699 " e" 4699 " e"
4700 "}"; 4700 "}";
4701 ExpectString(code, "PASSED"); 4701 ExpectString(code, "PASSED");
4702 } 4702 }
4703 4703
4704 4704
4705 THREADED_TEST(MultiContexts) { 4705 THREADED_TEST(MultiContexts) {
4706 v8::HandleScope scope; 4706 v8::HandleScope scope(v8::Isolate::GetCurrent());
4707 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); 4707 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New();
4708 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); 4708 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler));
4709 4709
4710 Local<String> password = v8_str("Password"); 4710 Local<String> password = v8_str("Password");
4711 4711
4712 // Create an environment 4712 // Create an environment
4713 LocalContext context0(0, templ); 4713 LocalContext context0(0, templ);
4714 context0->SetSecurityToken(password); 4714 context0->SetSecurityToken(password);
4715 v8::Handle<v8::Object> global0 = context0->Global(); 4715 v8::Handle<v8::Object> global0 = context0->Global();
4716 global0->Set(v8_str("custom"), v8_num(1234)); 4716 global0->Set(v8_str("custom"), v8_num(1234));
(...skipping 15 matching lines...) Expand all
4732 CHECK_EQ(global1, global2); 4732 CHECK_EQ(global1, global2);
4733 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value()); 4733 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value());
4734 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value()); 4734 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value());
4735 } 4735 }
4736 4736
4737 4737
4738 THREADED_TEST(FunctionPrototypeAcrossContexts) { 4738 THREADED_TEST(FunctionPrototypeAcrossContexts) {
4739 // Make sure that functions created by cloning boilerplates cannot 4739 // Make sure that functions created by cloning boilerplates cannot
4740 // communicate through their __proto__ field. 4740 // communicate through their __proto__ field.
4741 4741
4742 v8::HandleScope scope; 4742 v8::HandleScope scope(v8::Isolate::GetCurrent());
4743 4743
4744 LocalContext env0; 4744 LocalContext env0;
4745 v8::Handle<v8::Object> global0 = 4745 v8::Handle<v8::Object> global0 =
4746 env0->Global(); 4746 env0->Global();
4747 v8::Handle<v8::Object> object0 = 4747 v8::Handle<v8::Object> object0 =
4748 global0->Get(v8_str("Object")).As<v8::Object>(); 4748 global0->Get(v8_str("Object")).As<v8::Object>();
4749 v8::Handle<v8::Object> tostring0 = 4749 v8::Handle<v8::Object> tostring0 =
4750 object0->Get(v8_str("toString")).As<v8::Object>(); 4750 object0->Get(v8_str("toString")).As<v8::Object>();
4751 v8::Handle<v8::Object> proto0 = 4751 v8::Handle<v8::Object> proto0 =
4752 tostring0->Get(v8_str("__proto__")).As<v8::Object>(); 4752 tostring0->Get(v8_str("__proto__")).As<v8::Object>();
(...skipping 12 matching lines...) Expand all
4765 } 4765 }
4766 4766
4767 4767
4768 THREADED_TEST(Regress892105) { 4768 THREADED_TEST(Regress892105) {
4769 // Make sure that object and array literals created by cloning 4769 // Make sure that object and array literals created by cloning
4770 // boilerplates cannot communicate through their __proto__ 4770 // boilerplates cannot communicate through their __proto__
4771 // field. This is rather difficult to check, but we try to add stuff 4771 // field. This is rather difficult to check, but we try to add stuff
4772 // to Object.prototype and Array.prototype and create a new 4772 // to Object.prototype and Array.prototype and create a new
4773 // environment. This should succeed. 4773 // environment. This should succeed.
4774 4774
4775 v8::HandleScope scope; 4775 v8::HandleScope scope(v8::Isolate::GetCurrent());
4776 4776
4777 Local<String> source = v8_str("Object.prototype.obj = 1234;" 4777 Local<String> source = v8_str("Object.prototype.obj = 1234;"
4778 "Array.prototype.arr = 4567;" 4778 "Array.prototype.arr = 4567;"
4779 "8901"); 4779 "8901");
4780 4780
4781 LocalContext env0; 4781 LocalContext env0;
4782 Local<Script> script0 = Script::Compile(source); 4782 Local<Script> script0 = Script::Compile(source);
4783 CHECK_EQ(8901.0, script0->Run()->NumberValue()); 4783 CHECK_EQ(8901.0, script0->Run()->NumberValue());
4784 4784
4785 LocalContext env1; 4785 LocalContext env1;
4786 Local<Script> script1 = Script::Compile(source); 4786 Local<Script> script1 = Script::Compile(source);
4787 CHECK_EQ(8901.0, script1->Run()->NumberValue()); 4787 CHECK_EQ(8901.0, script1->Run()->NumberValue());
4788 } 4788 }
4789 4789
4790 4790
4791 THREADED_TEST(UndetectableObject) { 4791 THREADED_TEST(UndetectableObject) {
4792 v8::HandleScope scope;
4793 LocalContext env; 4792 LocalContext env;
4793 v8::HandleScope scope(env->GetIsolate());
4794 4794
4795 Local<v8::FunctionTemplate> desc = 4795 Local<v8::FunctionTemplate> desc =
4796 v8::FunctionTemplate::New(0, v8::Handle<Value>()); 4796 v8::FunctionTemplate::New(0, v8::Handle<Value>());
4797 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 4797 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
4798 4798
4799 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 4799 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4800 env->Global()->Set(v8_str("undetectable"), obj); 4800 env->Global()->Set(v8_str("undetectable"), obj);
4801 4801
4802 ExpectString("undetectable.toString()", "[object Object]"); 4802 ExpectString("undetectable.toString()", "[object Object]");
4803 ExpectString("typeof undetectable", "undefined"); 4803 ExpectString("typeof undetectable", "undefined");
(...skipping 22 matching lines...) Expand all
4826 4826
4827 ExpectBoolean("undetectable===null", false); 4827 ExpectBoolean("undetectable===null", false);
4828 ExpectBoolean("null===undetectable", false); 4828 ExpectBoolean("null===undetectable", false);
4829 ExpectBoolean("undetectable===undefined", false); 4829 ExpectBoolean("undetectable===undefined", false);
4830 ExpectBoolean("undefined===undetectable", false); 4830 ExpectBoolean("undefined===undetectable", false);
4831 ExpectBoolean("undetectable===undetectable", true); 4831 ExpectBoolean("undetectable===undetectable", true);
4832 } 4832 }
4833 4833
4834 4834
4835 THREADED_TEST(VoidLiteral) { 4835 THREADED_TEST(VoidLiteral) {
4836 v8::HandleScope scope;
4837 LocalContext env; 4836 LocalContext env;
4837 v8::HandleScope scope(env->GetIsolate());
4838 4838
4839 Local<v8::FunctionTemplate> desc = 4839 Local<v8::FunctionTemplate> desc =
4840 v8::FunctionTemplate::New(0, v8::Handle<Value>()); 4840 v8::FunctionTemplate::New(0, v8::Handle<Value>());
4841 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 4841 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
4842 4842
4843 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 4843 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4844 env->Global()->Set(v8_str("undetectable"), obj); 4844 env->Global()->Set(v8_str("undetectable"), obj);
4845 4845
4846 ExpectBoolean("undefined == void 0", true); 4846 ExpectBoolean("undefined == void 0", true);
4847 ExpectBoolean("undetectable == void 0", true); 4847 ExpectBoolean("undetectable == void 0", true);
(...skipping 22 matching lines...) Expand all
4870 " return void 0 === x;" 4870 " return void 0 === x;"
4871 " } catch(e) {" 4871 " } catch(e) {"
4872 " return e.toString();" 4872 " return e.toString();"
4873 " }" 4873 " }"
4874 "})()", 4874 "})()",
4875 "ReferenceError: x is not defined"); 4875 "ReferenceError: x is not defined");
4876 } 4876 }
4877 4877
4878 4878
4879 THREADED_TEST(ExtensibleOnUndetectable) { 4879 THREADED_TEST(ExtensibleOnUndetectable) {
4880 v8::HandleScope scope;
4881 LocalContext env; 4880 LocalContext env;
4881 v8::HandleScope scope(env->GetIsolate());
4882 4882
4883 Local<v8::FunctionTemplate> desc = 4883 Local<v8::FunctionTemplate> desc =
4884 v8::FunctionTemplate::New(0, v8::Handle<Value>()); 4884 v8::FunctionTemplate::New(0, v8::Handle<Value>());
4885 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 4885 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
4886 4886
4887 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 4887 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
4888 env->Global()->Set(v8_str("undetectable"), obj); 4888 env->Global()->Set(v8_str("undetectable"), obj);
4889 4889
4890 Local<String> source = v8_str("undetectable.x = 42;" 4890 Local<String> source = v8_str("undetectable.x = 42;"
4891 "undetectable.x"); 4891 "undetectable.x");
(...skipping 11 matching lines...) Expand all
4903 4903
4904 source = v8_str("undetectable.y = 2000;"); 4904 source = v8_str("undetectable.y = 2000;");
4905 script = Script::Compile(source); 4905 script = Script::Compile(source);
4906 script->Run(); 4906 script->Run();
4907 ExpectBoolean("undetectable.y == undefined", true); 4907 ExpectBoolean("undetectable.y == undefined", true);
4908 } 4908 }
4909 4909
4910 4910
4911 4911
4912 THREADED_TEST(UndetectableString) { 4912 THREADED_TEST(UndetectableString) {
4913 v8::HandleScope scope;
4914 LocalContext env; 4913 LocalContext env;
4914 v8::HandleScope scope(env->GetIsolate());
4915 4915
4916 Local<String> obj = String::NewUndetectable("foo"); 4916 Local<String> obj = String::NewUndetectable("foo");
4917 env->Global()->Set(v8_str("undetectable"), obj); 4917 env->Global()->Set(v8_str("undetectable"), obj);
4918 4918
4919 ExpectString("undetectable", "foo"); 4919 ExpectString("undetectable", "foo");
4920 ExpectString("typeof undetectable", "undefined"); 4920 ExpectString("typeof undetectable", "undefined");
4921 ExpectString("typeof(undetectable)", "undefined"); 4921 ExpectString("typeof(undetectable)", "undefined");
4922 ExpectBoolean("typeof undetectable == 'undefined'", true); 4922 ExpectBoolean("typeof undetectable == 'undefined'", true);
4923 ExpectBoolean("typeof undetectable == 'string'", false); 4923 ExpectBoolean("typeof undetectable == 'string'", false);
4924 ExpectBoolean("if (undetectable) { true; } else { false; }", false); 4924 ExpectBoolean("if (undetectable) { true; } else { false; }", false);
(...skipping 19 matching lines...) Expand all
4944 ExpectBoolean("undetectable===null", false); 4944 ExpectBoolean("undetectable===null", false);
4945 ExpectBoolean("null===undetectable", false); 4945 ExpectBoolean("null===undetectable", false);
4946 ExpectBoolean("undetectable===undefined", false); 4946 ExpectBoolean("undetectable===undefined", false);
4947 ExpectBoolean("undefined===undetectable", false); 4947 ExpectBoolean("undefined===undetectable", false);
4948 ExpectBoolean("undetectable===undetectable", true); 4948 ExpectBoolean("undetectable===undetectable", true);
4949 } 4949 }
4950 4950
4951 4951
4952 TEST(UndetectableOptimized) { 4952 TEST(UndetectableOptimized) {
4953 i::FLAG_allow_natives_syntax = true; 4953 i::FLAG_allow_natives_syntax = true;
4954 v8::HandleScope scope;
4955 LocalContext env; 4954 LocalContext env;
4955 v8::HandleScope scope(env->GetIsolate());
4956 4956
4957 Local<String> obj = String::NewUndetectable("foo"); 4957 Local<String> obj = String::NewUndetectable("foo");
4958 env->Global()->Set(v8_str("undetectable"), obj); 4958 env->Global()->Set(v8_str("undetectable"), obj);
4959 env->Global()->Set(v8_str("detectable"), v8_str("bar")); 4959 env->Global()->Set(v8_str("detectable"), v8_str("bar"));
4960 4960
4961 ExpectString( 4961 ExpectString(
4962 "function testBranch() {" 4962 "function testBranch() {"
4963 " if (!%_IsUndetectableObject(undetectable)) throw 1;" 4963 " if (!%_IsUndetectableObject(undetectable)) throw 1;"
4964 " if (%_IsUndetectableObject(detectable)) throw 2;" 4964 " if (%_IsUndetectableObject(detectable)) throw 2;"
4965 "}\n" 4965 "}\n"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5000 } 5000 }
5001 5001
5002 5002
5003 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) { 5003 static v8::Handle<Value> HandleLogDelegator(const v8::Arguments& args) {
5004 ApiTestFuzzer::Fuzz(); 5004 ApiTestFuzzer::Fuzz();
5005 return v8::Undefined(); 5005 return v8::Undefined();
5006 } 5006 }
5007 5007
5008 5008
5009 THREADED_TEST(GlobalObjectTemplate) { 5009 THREADED_TEST(GlobalObjectTemplate) {
5010 v8::HandleScope handle_scope; 5010 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5011 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 5011 Local<ObjectTemplate> global_template = ObjectTemplate::New();
5012 global_template->Set(v8_str("JSNI_Log"), 5012 global_template->Set(v8_str("JSNI_Log"),
5013 v8::FunctionTemplate::New(HandleLogDelegator)); 5013 v8::FunctionTemplate::New(HandleLogDelegator));
5014 v8::Persistent<Context> context = Context::New(0, global_template); 5014 v8::Persistent<Context> context = Context::New(0, global_template);
5015 Context::Scope context_scope(context); 5015 Context::Scope context_scope(context);
5016 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 5016 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
5017 context.Dispose(context->GetIsolate()); 5017 context.Dispose(context->GetIsolate());
5018 } 5018 }
5019 5019
5020 5020
5021 static const char* kSimpleExtensionSource = 5021 static const char* kSimpleExtensionSource =
5022 "function Foo() {" 5022 "function Foo() {"
5023 " return 4;" 5023 " return 4;"
5024 "}"; 5024 "}";
5025 5025
5026 5026
5027 THREADED_TEST(SimpleExtensions) { 5027 THREADED_TEST(SimpleExtensions) {
5028 v8::HandleScope handle_scope; 5028 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5029 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 5029 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
5030 const char* extension_names[] = { "simpletest" }; 5030 const char* extension_names[] = { "simpletest" };
5031 v8::ExtensionConfiguration extensions(1, extension_names); 5031 v8::ExtensionConfiguration extensions(1, extension_names);
5032 v8::Handle<Context> context = Context::New(&extensions); 5032 v8::Handle<Context> context = Context::New(&extensions);
5033 Context::Scope lock(context); 5033 Context::Scope lock(context);
5034 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 5034 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
5035 CHECK_EQ(result, v8::Integer::New(4)); 5035 CHECK_EQ(result, v8::Integer::New(4));
5036 } 5036 }
5037 5037
5038 5038
5039 THREADED_TEST(NullExtensions) { 5039 THREADED_TEST(NullExtensions) {
5040 v8::HandleScope handle_scope; 5040 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5041 v8::RegisterExtension(new Extension("nulltest", NULL)); 5041 v8::RegisterExtension(new Extension("nulltest", NULL));
5042 const char* extension_names[] = { "nulltest" }; 5042 const char* extension_names[] = { "nulltest" };
5043 v8::ExtensionConfiguration extensions(1, extension_names); 5043 v8::ExtensionConfiguration extensions(1, extension_names);
5044 v8::Handle<Context> context = Context::New(&extensions); 5044 v8::Handle<Context> context = Context::New(&extensions);
5045 Context::Scope lock(context); 5045 Context::Scope lock(context);
5046 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run(); 5046 v8::Handle<Value> result = Script::Compile(v8_str("1+3"))->Run();
5047 CHECK_EQ(result, v8::Integer::New(4)); 5047 CHECK_EQ(result, v8::Integer::New(4));
5048 } 5048 }
5049 5049
5050 5050
5051 static const char* kEmbeddedExtensionSource = 5051 static const char* kEmbeddedExtensionSource =
5052 "function Ret54321(){return 54321;}~~@@$" 5052 "function Ret54321(){return 54321;}~~@@$"
5053 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 5053 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
5054 static const int kEmbeddedExtensionSourceValidLen = 34; 5054 static const int kEmbeddedExtensionSourceValidLen = 34;
5055 5055
5056 5056
5057 THREADED_TEST(ExtensionMissingSourceLength) { 5057 THREADED_TEST(ExtensionMissingSourceLength) {
5058 v8::HandleScope handle_scope; 5058 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5059 v8::RegisterExtension(new Extension("srclentest_fail", 5059 v8::RegisterExtension(new Extension("srclentest_fail",
5060 kEmbeddedExtensionSource)); 5060 kEmbeddedExtensionSource));
5061 const char* extension_names[] = { "srclentest_fail" }; 5061 const char* extension_names[] = { "srclentest_fail" };
5062 v8::ExtensionConfiguration extensions(1, extension_names); 5062 v8::ExtensionConfiguration extensions(1, extension_names);
5063 v8::Handle<Context> context = Context::New(&extensions); 5063 v8::Handle<Context> context = Context::New(&extensions);
5064 CHECK_EQ(0, *context); 5064 CHECK_EQ(0, *context);
5065 } 5065 }
5066 5066
5067 5067
5068 THREADED_TEST(ExtensionWithSourceLength) { 5068 THREADED_TEST(ExtensionWithSourceLength) {
5069 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; 5069 for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
5070 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { 5070 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
5071 v8::HandleScope handle_scope; 5071 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5072 i::ScopedVector<char> extension_name(32); 5072 i::ScopedVector<char> extension_name(32);
5073 i::OS::SNPrintF(extension_name, "ext #%d", source_len); 5073 i::OS::SNPrintF(extension_name, "ext #%d", source_len);
5074 v8::RegisterExtension(new Extension(extension_name.start(), 5074 v8::RegisterExtension(new Extension(extension_name.start(),
5075 kEmbeddedExtensionSource, 0, 0, 5075 kEmbeddedExtensionSource, 0, 0,
5076 source_len)); 5076 source_len));
5077 const char* extension_names[1] = { extension_name.start() }; 5077 const char* extension_names[1] = { extension_name.start() };
5078 v8::ExtensionConfiguration extensions(1, extension_names); 5078 v8::ExtensionConfiguration extensions(1, extension_names);
5079 v8::Handle<Context> context = Context::New(&extensions); 5079 v8::Handle<Context> context = Context::New(&extensions);
5080 if (source_len == kEmbeddedExtensionSourceValidLen) { 5080 if (source_len == kEmbeddedExtensionSourceValidLen) {
5081 Context::Scope lock(context); 5081 Context::Scope lock(context);
(...skipping 18 matching lines...) Expand all
5100 "(function() {" 5100 "(function() {"
5101 " var x = 42;" 5101 " var x = 42;"
5102 " function e() {" 5102 " function e() {"
5103 " return eval('x');" 5103 " return eval('x');"
5104 " }" 5104 " }"
5105 " this.UseEval2 = e;" 5105 " this.UseEval2 = e;"
5106 "})()"; 5106 "})()";
5107 5107
5108 5108
5109 THREADED_TEST(UseEvalFromExtension) { 5109 THREADED_TEST(UseEvalFromExtension) {
5110 v8::HandleScope handle_scope; 5110 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5111 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 5111 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
5112 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 5112 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
5113 const char* extension_names[] = { "evaltest1", "evaltest2" }; 5113 const char* extension_names[] = { "evaltest1", "evaltest2" };
5114 v8::ExtensionConfiguration extensions(2, extension_names); 5114 v8::ExtensionConfiguration extensions(2, extension_names);
5115 v8::Handle<Context> context = Context::New(&extensions); 5115 v8::Handle<Context> context = Context::New(&extensions);
5116 Context::Scope lock(context); 5116 Context::Scope lock(context);
5117 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run(); 5117 v8::Handle<Value> result = Script::Compile(v8_str("UseEval1()"))->Run();
5118 CHECK_EQ(result, v8::Integer::New(42)); 5118 CHECK_EQ(result, v8::Integer::New(42));
5119 result = Script::Compile(v8_str("UseEval2()"))->Run(); 5119 result = Script::Compile(v8_str("UseEval2()"))->Run();
5120 CHECK_EQ(result, v8::Integer::New(42)); 5120 CHECK_EQ(result, v8::Integer::New(42));
(...skipping 12 matching lines...) Expand all
5133 "(function() {" 5133 "(function() {"
5134 " var x = 42;" 5134 " var x = 42;"
5135 " function e() {" 5135 " function e() {"
5136 " with ({x:87}) { return x; }" 5136 " with ({x:87}) { return x; }"
5137 " }" 5137 " }"
5138 " this.UseWith2 = e;" 5138 " this.UseWith2 = e;"
5139 "})()"; 5139 "})()";
5140 5140
5141 5141
5142 THREADED_TEST(UseWithFromExtension) { 5142 THREADED_TEST(UseWithFromExtension) {
5143 v8::HandleScope handle_scope; 5143 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5144 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 5144 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
5145 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 5145 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
5146 const char* extension_names[] = { "withtest1", "withtest2" }; 5146 const char* extension_names[] = { "withtest1", "withtest2" };
5147 v8::ExtensionConfiguration extensions(2, extension_names); 5147 v8::ExtensionConfiguration extensions(2, extension_names);
5148 v8::Handle<Context> context = Context::New(&extensions); 5148 v8::Handle<Context> context = Context::New(&extensions);
5149 Context::Scope lock(context); 5149 Context::Scope lock(context);
5150 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run(); 5150 v8::Handle<Value> result = Script::Compile(v8_str("UseWith1()"))->Run();
5151 CHECK_EQ(result, v8::Integer::New(87)); 5151 CHECK_EQ(result, v8::Integer::New(87));
5152 result = Script::Compile(v8_str("UseWith2()"))->Run(); 5152 result = Script::Compile(v8_str("UseWith2()"))->Run();
5153 CHECK_EQ(result, v8::Integer::New(87)); 5153 CHECK_EQ(result, v8::Integer::New(87));
5154 } 5154 }
5155 5155
5156 5156
5157 THREADED_TEST(AutoExtensions) { 5157 THREADED_TEST(AutoExtensions) {
5158 v8::HandleScope handle_scope; 5158 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5159 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 5159 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
5160 extension->set_auto_enable(true); 5160 extension->set_auto_enable(true);
5161 v8::RegisterExtension(extension); 5161 v8::RegisterExtension(extension);
5162 v8::Handle<Context> context = Context::New(); 5162 v8::Handle<Context> context = Context::New();
5163 Context::Scope lock(context); 5163 Context::Scope lock(context);
5164 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); 5164 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run();
5165 CHECK_EQ(result, v8::Integer::New(4)); 5165 CHECK_EQ(result, v8::Integer::New(4));
5166 } 5166 }
5167 5167
5168 5168
5169 static const char* kSyntaxErrorInExtensionSource = 5169 static const char* kSyntaxErrorInExtensionSource =
5170 "["; 5170 "[";
5171 5171
5172 5172
5173 // Test that a syntax error in an extension does not cause a fatal 5173 // Test that a syntax error in an extension does not cause a fatal
5174 // error but results in an empty context. 5174 // error but results in an empty context.
5175 THREADED_TEST(SyntaxErrorExtensions) { 5175 THREADED_TEST(SyntaxErrorExtensions) {
5176 v8::HandleScope handle_scope; 5176 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5177 v8::RegisterExtension(new Extension("syntaxerror", 5177 v8::RegisterExtension(new Extension("syntaxerror",
5178 kSyntaxErrorInExtensionSource)); 5178 kSyntaxErrorInExtensionSource));
5179 const char* extension_names[] = { "syntaxerror" }; 5179 const char* extension_names[] = { "syntaxerror" };
5180 v8::ExtensionConfiguration extensions(1, extension_names); 5180 v8::ExtensionConfiguration extensions(1, extension_names);
5181 v8::Handle<Context> context = Context::New(&extensions); 5181 v8::Handle<Context> context = Context::New(&extensions);
5182 CHECK(context.IsEmpty()); 5182 CHECK(context.IsEmpty());
5183 } 5183 }
5184 5184
5185 5185
5186 static const char* kExceptionInExtensionSource = 5186 static const char* kExceptionInExtensionSource =
5187 "throw 42"; 5187 "throw 42";
5188 5188
5189 5189
5190 // Test that an exception when installing an extension does not cause 5190 // Test that an exception when installing an extension does not cause
5191 // a fatal error but results in an empty context. 5191 // a fatal error but results in an empty context.
5192 THREADED_TEST(ExceptionExtensions) { 5192 THREADED_TEST(ExceptionExtensions) {
5193 v8::HandleScope handle_scope; 5193 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5194 v8::RegisterExtension(new Extension("exception", 5194 v8::RegisterExtension(new Extension("exception",
5195 kExceptionInExtensionSource)); 5195 kExceptionInExtensionSource));
5196 const char* extension_names[] = { "exception" }; 5196 const char* extension_names[] = { "exception" };
5197 v8::ExtensionConfiguration extensions(1, extension_names); 5197 v8::ExtensionConfiguration extensions(1, extension_names);
5198 v8::Handle<Context> context = Context::New(&extensions); 5198 v8::Handle<Context> context = Context::New(&extensions);
5199 CHECK(context.IsEmpty()); 5199 CHECK(context.IsEmpty());
5200 } 5200 }
5201 5201
5202 5202
5203 static const char* kNativeCallInExtensionSource = 5203 static const char* kNativeCallInExtensionSource =
5204 "function call_runtime_last_index_of(x) {" 5204 "function call_runtime_last_index_of(x) {"
5205 " return %StringLastIndexOf(x, 'bob', 10);" 5205 " return %StringLastIndexOf(x, 'bob', 10);"
5206 "}"; 5206 "}";
5207 5207
5208 5208
5209 static const char* kNativeCallTest = 5209 static const char* kNativeCallTest =
5210 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; 5210 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
5211 5211
5212 // Test that a native runtime calls are supported in extensions. 5212 // Test that a native runtime calls are supported in extensions.
5213 THREADED_TEST(NativeCallInExtensions) { 5213 THREADED_TEST(NativeCallInExtensions) {
5214 v8::HandleScope handle_scope; 5214 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5215 v8::RegisterExtension(new Extension("nativecall", 5215 v8::RegisterExtension(new Extension("nativecall",
5216 kNativeCallInExtensionSource)); 5216 kNativeCallInExtensionSource));
5217 const char* extension_names[] = { "nativecall" }; 5217 const char* extension_names[] = { "nativecall" };
5218 v8::ExtensionConfiguration extensions(1, extension_names); 5218 v8::ExtensionConfiguration extensions(1, extension_names);
5219 v8::Handle<Context> context = Context::New(&extensions); 5219 v8::Handle<Context> context = Context::New(&extensions);
5220 Context::Scope lock(context); 5220 Context::Scope lock(context);
5221 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run(); 5221 v8::Handle<Value> result = Script::Compile(v8_str(kNativeCallTest))->Run();
5222 CHECK_EQ(result, v8::Integer::New(3)); 5222 CHECK_EQ(result, v8::Integer::New(3));
5223 } 5223 }
5224 5224
(...skipping 14 matching lines...) Expand all
5239 static v8::Handle<v8::Value> Echo(const v8::Arguments& args) { 5239 static v8::Handle<v8::Value> Echo(const v8::Arguments& args) {
5240 if (args.Length() >= 1) return (args[0]); 5240 if (args.Length() >= 1) return (args[0]);
5241 return v8::Undefined(); 5241 return v8::Undefined();
5242 } 5242 }
5243 private: 5243 private:
5244 v8::InvocationCallback function_; 5244 v8::InvocationCallback function_;
5245 }; 5245 };
5246 5246
5247 5247
5248 THREADED_TEST(NativeFunctionDeclaration) { 5248 THREADED_TEST(NativeFunctionDeclaration) {
5249 v8::HandleScope handle_scope; 5249 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5250 const char* name = "nativedecl"; 5250 const char* name = "nativedecl";
5251 v8::RegisterExtension(new NativeFunctionExtension(name, 5251 v8::RegisterExtension(new NativeFunctionExtension(name,
5252 "native function foo();")); 5252 "native function foo();"));
5253 const char* extension_names[] = { name }; 5253 const char* extension_names[] = { name };
5254 v8::ExtensionConfiguration extensions(1, extension_names); 5254 v8::ExtensionConfiguration extensions(1, extension_names);
5255 v8::Handle<Context> context = Context::New(&extensions); 5255 v8::Handle<Context> context = Context::New(&extensions);
5256 Context::Scope lock(context); 5256 Context::Scope lock(context);
5257 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run(); 5257 v8::Handle<Value> result = Script::Compile(v8_str("foo(42);"))->Run();
5258 CHECK_EQ(result, v8::Integer::New(42)); 5258 CHECK_EQ(result, v8::Integer::New(42));
5259 } 5259 }
5260 5260
5261 5261
5262 THREADED_TEST(NativeFunctionDeclarationError) { 5262 THREADED_TEST(NativeFunctionDeclarationError) {
5263 v8::HandleScope handle_scope; 5263 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5264 const char* name = "nativedeclerr"; 5264 const char* name = "nativedeclerr";
5265 // Syntax error in extension code. 5265 // Syntax error in extension code.
5266 v8::RegisterExtension(new NativeFunctionExtension(name, 5266 v8::RegisterExtension(new NativeFunctionExtension(name,
5267 "native\nfunction foo();")); 5267 "native\nfunction foo();"));
5268 const char* extension_names[] = { name }; 5268 const char* extension_names[] = { name };
5269 v8::ExtensionConfiguration extensions(1, extension_names); 5269 v8::ExtensionConfiguration extensions(1, extension_names);
5270 v8::Handle<Context> context(Context::New(&extensions)); 5270 v8::Handle<Context> context(Context::New(&extensions));
5271 CHECK(context.IsEmpty()); 5271 CHECK(context.IsEmpty());
5272 } 5272 }
5273 5273
5274 5274
5275 THREADED_TEST(NativeFunctionDeclarationErrorEscape) { 5275 THREADED_TEST(NativeFunctionDeclarationErrorEscape) {
5276 v8::HandleScope handle_scope; 5276 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5277 const char* name = "nativedeclerresc"; 5277 const char* name = "nativedeclerresc";
5278 // Syntax error in extension code - escape code in "native" means that 5278 // Syntax error in extension code - escape code in "native" means that
5279 // it's not treated as a keyword. 5279 // it's not treated as a keyword.
5280 v8::RegisterExtension(new NativeFunctionExtension( 5280 v8::RegisterExtension(new NativeFunctionExtension(
5281 name, 5281 name,
5282 "nativ\\u0065 function foo();")); 5282 "nativ\\u0065 function foo();"));
5283 const char* extension_names[] = { name }; 5283 const char* extension_names[] = { name };
5284 v8::ExtensionConfiguration extensions(1, extension_names); 5284 v8::ExtensionConfiguration extensions(1, extension_names);
5285 v8::Handle<Context> context(Context::New(&extensions)); 5285 v8::Handle<Context> context(Context::New(&extensions));
5286 CHECK(context.IsEmpty()); 5286 CHECK(context.IsEmpty());
5287 } 5287 }
5288 5288
5289 5289
5290 static void CheckDependencies(const char* name, const char* expected) { 5290 static void CheckDependencies(const char* name, const char* expected) {
5291 v8::HandleScope handle_scope; 5291 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5292 v8::ExtensionConfiguration config(1, &name); 5292 v8::ExtensionConfiguration config(1, &name);
5293 LocalContext context(&config); 5293 LocalContext context(&config);
5294 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); 5294 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded")));
5295 } 5295 }
5296 5296
5297 5297
5298 /* 5298 /*
5299 * Configuration: 5299 * Configuration:
5300 * 5300 *
5301 * /-- B <--\ 5301 * /-- B <--\
5302 * A <- -- D <-- E 5302 * A <- -- D <-- E
5303 * \-- C <--/ 5303 * \-- C <--/
5304 */ 5304 */
5305 THREADED_TEST(ExtensionDependency) { 5305 THREADED_TEST(ExtensionDependency) {
5306 static const char* kEDeps[] = { "D" }; 5306 static const char* kEDeps[] = { "D" };
5307 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps)); 5307 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps));
5308 static const char* kDDeps[] = { "B", "C" }; 5308 static const char* kDDeps[] = { "B", "C" };
5309 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps)); 5309 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps));
5310 static const char* kBCDeps[] = { "A" }; 5310 static const char* kBCDeps[] = { "A" };
5311 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps)); 5311 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps));
5312 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps)); 5312 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps));
5313 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';")); 5313 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';"));
5314 CheckDependencies("A", "undefinedA"); 5314 CheckDependencies("A", "undefinedA");
5315 CheckDependencies("B", "undefinedAB"); 5315 CheckDependencies("B", "undefinedAB");
5316 CheckDependencies("C", "undefinedAC"); 5316 CheckDependencies("C", "undefinedAC");
5317 CheckDependencies("D", "undefinedABCD"); 5317 CheckDependencies("D", "undefinedABCD");
5318 CheckDependencies("E", "undefinedABCDE"); 5318 CheckDependencies("E", "undefinedABCDE");
5319 v8::HandleScope handle_scope; 5319 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5320 static const char* exts[2] = { "C", "E" }; 5320 static const char* exts[2] = { "C", "E" };
5321 v8::ExtensionConfiguration config(2, exts); 5321 v8::ExtensionConfiguration config(2, exts);
5322 LocalContext context(&config); 5322 LocalContext context(&config);
5323 CHECK_EQ(v8_str("undefinedACBDE"), context->Global()->Get(v8_str("loaded"))); 5323 CHECK_EQ(v8_str("undefinedACBDE"), context->Global()->Get(v8_str("loaded")));
5324 } 5324 }
5325 5325
5326 5326
5327 static const char* kExtensionTestScript = 5327 static const char* kExtensionTestScript =
5328 "native function A();" 5328 "native function A();"
5329 "native function B();" 5329 "native function B();"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
5364 } else if (name->Equals(v8_str("C"))) { 5364 } else if (name->Equals(v8_str("C"))) {
5365 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6)); 5365 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6));
5366 } else { 5366 } else {
5367 return v8::Handle<v8::FunctionTemplate>(); 5367 return v8::Handle<v8::FunctionTemplate>();
5368 } 5368 }
5369 } 5369 }
5370 5370
5371 5371
5372 THREADED_TEST(FunctionLookup) { 5372 THREADED_TEST(FunctionLookup) {
5373 v8::RegisterExtension(new FunctionExtension()); 5373 v8::RegisterExtension(new FunctionExtension());
5374 v8::HandleScope handle_scope; 5374 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5375 static const char* exts[1] = { "functiontest" }; 5375 static const char* exts[1] = { "functiontest" };
5376 v8::ExtensionConfiguration config(1, exts); 5376 v8::ExtensionConfiguration config(1, exts);
5377 LocalContext context(&config); 5377 LocalContext context(&config);
5378 CHECK_EQ(3, lookup_count); 5378 CHECK_EQ(3, lookup_count);
5379 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run()); 5379 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run());
5380 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run()); 5380 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run());
5381 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run()); 5381 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run());
5382 } 5382 }
5383 5383
5384 5384
5385 THREADED_TEST(NativeFunctionConstructCall) { 5385 THREADED_TEST(NativeFunctionConstructCall) {
5386 v8::RegisterExtension(new FunctionExtension()); 5386 v8::RegisterExtension(new FunctionExtension());
5387 v8::HandleScope handle_scope; 5387 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5388 static const char* exts[1] = { "functiontest" }; 5388 static const char* exts[1] = { "functiontest" };
5389 v8::ExtensionConfiguration config(1, exts); 5389 v8::ExtensionConfiguration config(1, exts);
5390 LocalContext context(&config); 5390 LocalContext context(&config);
5391 for (int i = 0; i < 10; i++) { 5391 for (int i = 0; i < 10; i++) {
5392 // Run a few times to ensure that allocation of objects doesn't 5392 // Run a few times to ensure that allocation of objects doesn't
5393 // change behavior of a constructor function. 5393 // change behavior of a constructor function.
5394 CHECK_EQ(v8::Integer::New(8), 5394 CHECK_EQ(v8::Integer::New(8),
5395 Script::Compile(v8_str("(new A()).data"))->Run()); 5395 Script::Compile(v8_str("(new A()).data"))->Run());
5396 CHECK_EQ(v8::Integer::New(7), 5396 CHECK_EQ(v8::Integer::New(7),
5397 Script::Compile(v8_str("(new B()).data"))->Run()); 5397 Script::Compile(v8_str("(new B()).data"))->Run());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5436 "str.match(/X/);"; 5436 "str.match(/X/);";
5437 5437
5438 5438
5439 void OOMCallback(const char* location, const char* message) { 5439 void OOMCallback(const char* location, const char* message) {
5440 exit(0); 5440 exit(0);
5441 } 5441 }
5442 5442
5443 5443
5444 TEST(RegexpOutOfMemory) { 5444 TEST(RegexpOutOfMemory) {
5445 // Execute a script that causes out of memory when flattening a string. 5445 // Execute a script that causes out of memory when flattening a string.
5446 v8::HandleScope scope; 5446 v8::HandleScope scope(v8::Isolate::GetCurrent());
5447 v8::V8::SetFatalErrorHandler(OOMCallback); 5447 v8::V8::SetFatalErrorHandler(OOMCallback);
5448 LocalContext context; 5448 LocalContext context;
5449 Local<Script> script = 5449 Local<Script> script =
5450 Script::Compile(String::New(js_code_causing_huge_string_flattening)); 5450 Script::Compile(String::New(js_code_causing_huge_string_flattening));
5451 last_location = NULL; 5451 last_location = NULL;
5452 script->Run(); 5452 script->Run();
5453 5453
5454 CHECK(false); // Should not return. 5454 CHECK(false); // Should not return.
5455 } 5455 }
5456 5456
5457 5457
5458 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, 5458 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message,
5459 v8::Handle<Value> data) { 5459 v8::Handle<Value> data) {
5460 CHECK(message->GetScriptResourceName()->IsUndefined()); 5460 CHECK(message->GetScriptResourceName()->IsUndefined());
5461 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName()); 5461 CHECK_EQ(v8::Undefined(), message->GetScriptResourceName());
5462 message->GetLineNumber(); 5462 message->GetLineNumber();
5463 message->GetSourceLine(); 5463 message->GetSourceLine();
5464 } 5464 }
5465 5465
5466 5466
5467 THREADED_TEST(ErrorWithMissingScriptInfo) { 5467 THREADED_TEST(ErrorWithMissingScriptInfo) {
5468 v8::HandleScope scope;
5469 LocalContext context; 5468 LocalContext context;
5469 v8::HandleScope scope(context->GetIsolate());
5470 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); 5470 v8::V8::AddMessageListener(MissingScriptInfoMessageListener);
5471 Script::Compile(v8_str("throw Error()"))->Run(); 5471 Script::Compile(v8_str("throw Error()"))->Run();
5472 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); 5472 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener);
5473 } 5473 }
5474 5474
5475 5475
5476 int global_index = 0; 5476 int global_index = 0;
5477 5477
5478 class Snorkel { 5478 class Snorkel {
5479 public: 5479 public:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5523 prev->Set(v8_str("next"), obj); 5523 prev->Set(v8_str("next"), obj);
5524 prev.MakeWeak(info.GetIsolate(), new Snorkel(), &HandleWeakReference); 5524 prev.MakeWeak(info.GetIsolate(), new Snorkel(), &HandleWeakReference);
5525 whammy->objects_[whammy->cursor_].Clear(); 5525 whammy->objects_[whammy->cursor_].Clear();
5526 } 5526 }
5527 whammy->objects_[whammy->cursor_] = global; 5527 whammy->objects_[whammy->cursor_] = global;
5528 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; 5528 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount;
5529 return whammy->getScript()->Run(); 5529 return whammy->getScript()->Run();
5530 } 5530 }
5531 5531
5532 THREADED_TEST(WeakReference) { 5532 THREADED_TEST(WeakReference) {
5533 v8::HandleScope handle_scope; 5533 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
5534 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); 5534 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New();
5535 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent()); 5535 Whammy* whammy = new Whammy(v8::Isolate::GetCurrent());
5536 templ->SetNamedPropertyHandler(WhammyPropertyGetter, 5536 templ->SetNamedPropertyHandler(WhammyPropertyGetter,
5537 0, 0, 0, 0, 5537 0, 0, 0, 0,
5538 v8::External::New(whammy)); 5538 v8::External::New(whammy));
5539 const char* extension_list[] = { "v8/gc" }; 5539 const char* extension_list[] = { "v8/gc" };
5540 v8::ExtensionConfiguration extensions(1, extension_list); 5540 v8::ExtensionConfiguration extensions(1, extension_list);
5541 v8::Persistent<Context> context = Context::New(&extensions); 5541 v8::Persistent<Context> context = Context::New(&extensions);
5542 Context::Scope context_scope(context); 5542 Context::Scope context_scope(context);
5543 5543
(...skipping 25 matching lines...) Expand all
5569 5569
5570 5570
5571 THREADED_TEST(IndependentWeakHandle) { 5571 THREADED_TEST(IndependentWeakHandle) {
5572 v8::Persistent<Context> context = Context::New(); 5572 v8::Persistent<Context> context = Context::New();
5573 v8::Isolate* iso = context->GetIsolate(); 5573 v8::Isolate* iso = context->GetIsolate();
5574 Context::Scope context_scope(context); 5574 Context::Scope context_scope(context);
5575 5575
5576 v8::Persistent<v8::Object> object_a, object_b; 5576 v8::Persistent<v8::Object> object_a, object_b;
5577 5577
5578 { 5578 {
5579 v8::HandleScope handle_scope; 5579 v8::HandleScope handle_scope(iso);
5580 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); 5580 object_a = v8::Persistent<v8::Object>::New(iso, v8::Object::New());
5581 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New()); 5581 object_b = v8::Persistent<v8::Object>::New(iso, v8::Object::New());
5582 } 5582 }
5583 5583
5584 bool object_a_disposed = false; 5584 bool object_a_disposed = false;
5585 bool object_b_disposed = false; 5585 bool object_b_disposed = false;
5586 object_a.MakeWeak(iso, &object_a_disposed, &DisposeAndSetFlag); 5586 object_a.MakeWeak(iso, &object_a_disposed, &DisposeAndSetFlag);
5587 object_b.MakeWeak(iso, &object_b_disposed, &DisposeAndSetFlag); 5587 object_b.MakeWeak(iso, &object_b_disposed, &DisposeAndSetFlag);
5588 CHECK(!object_b.IsIndependent(iso)); 5588 CHECK(!object_b.IsIndependent(iso));
5589 object_a.MarkIndependent(iso); 5589 object_a.MarkIndependent(iso);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5634 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] = 5634 v8::NearDeathCallback gc_forcing_callback[kNumberOfGCTypes] =
5635 {&ForceScavenge, &ForceMarkSweep}; 5635 {&ForceScavenge, &ForceMarkSweep};
5636 5636
5637 typedef void (*GCInvoker)(); 5637 typedef void (*GCInvoker)();
5638 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 5638 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
5639 5639
5640 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 5640 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
5641 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 5641 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
5642 v8::Persistent<v8::Object> object; 5642 v8::Persistent<v8::Object> object;
5643 { 5643 {
5644 v8::HandleScope handle_scope; 5644 v8::HandleScope handle_scope(isolate);
5645 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 5645 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
5646 } 5646 }
5647 bool disposed = false; 5647 bool disposed = false;
5648 object.MakeWeak(isolate, &disposed, gc_forcing_callback[inner_gc]); 5648 object.MakeWeak(isolate, &disposed, gc_forcing_callback[inner_gc]);
5649 object.MarkIndependent(isolate); 5649 object.MarkIndependent(isolate);
5650 invoke_gc[outer_gc](); 5650 invoke_gc[outer_gc]();
5651 CHECK(disposed); 5651 CHECK(disposed);
5652 } 5652 }
5653 } 5653 }
5654 } 5654 }
5655 5655
5656 5656
5657 static void RevivingCallback(v8::Isolate* isolate, 5657 static void RevivingCallback(v8::Isolate* isolate,
5658 v8::Persistent<v8::Value> obj, 5658 v8::Persistent<v8::Value> obj,
5659 void* data) { 5659 void* data) {
5660 obj.ClearWeak(isolate); 5660 obj.ClearWeak(isolate);
5661 *(reinterpret_cast<bool*>(data)) = true; 5661 *(reinterpret_cast<bool*>(data)) = true;
5662 } 5662 }
5663 5663
5664 5664
5665 THREADED_TEST(IndependentHandleRevival) { 5665 THREADED_TEST(IndependentHandleRevival) {
5666 v8::Persistent<Context> context = Context::New(); 5666 v8::Persistent<Context> context = Context::New();
5667 Context::Scope context_scope(context); 5667 Context::Scope context_scope(context);
5668 v8::Isolate* isolate = context->GetIsolate(); 5668 v8::Isolate* isolate = context->GetIsolate();
5669 5669
5670 v8::Persistent<v8::Object> object; 5670 v8::Persistent<v8::Object> object;
5671 { 5671 {
5672 v8::HandleScope handle_scope; 5672 v8::HandleScope handle_scope(isolate);
5673 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 5673 object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
5674 object->Set(v8_str("x"), v8::Integer::New(1)); 5674 object->Set(v8_str("x"), v8::Integer::New(1));
5675 v8::Local<String> y_str = v8_str("y"); 5675 v8::Local<String> y_str = v8_str("y");
5676 object->Set(y_str, y_str); 5676 object->Set(y_str, y_str);
5677 } 5677 }
5678 bool revived = false; 5678 bool revived = false;
5679 object.MakeWeak(isolate, &revived, &RevivingCallback); 5679 object.MakeWeak(isolate, &revived, &RevivingCallback);
5680 object.MarkIndependent(isolate); 5680 object.MarkIndependent(isolate);
5681 HEAP->PerformScavenge(); 5681 HEAP->PerformScavenge();
5682 CHECK(revived); 5682 CHECK(revived);
5683 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 5683 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
5684 { 5684 {
5685 v8::HandleScope handle_scope; 5685 v8::HandleScope handle_scope(isolate);
5686 v8::Local<String> y_str = v8_str("y"); 5686 v8::Local<String> y_str = v8_str("y");
5687 CHECK_EQ(v8::Integer::New(1), object->Get(v8_str("x"))); 5687 CHECK_EQ(v8::Integer::New(1), object->Get(v8_str("x")));
5688 CHECK(object->Get(y_str)->Equals(y_str)); 5688 CHECK(object->Get(y_str)->Equals(y_str));
5689 } 5689 }
5690 } 5690 }
5691 5691
5692 5692
5693 v8::Handle<Function> args_fun; 5693 v8::Handle<Function> args_fun;
5694 5694
5695 5695
5696 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) { 5696 static v8::Handle<Value> ArgumentsTestCallback(const v8::Arguments& args) {
5697 ApiTestFuzzer::Fuzz(); 5697 ApiTestFuzzer::Fuzz();
5698 CHECK_EQ(args_fun, args.Callee()); 5698 CHECK_EQ(args_fun, args.Callee());
5699 CHECK_EQ(3, args.Length()); 5699 CHECK_EQ(3, args.Length());
5700 CHECK_EQ(v8::Integer::New(1), args[0]); 5700 CHECK_EQ(v8::Integer::New(1), args[0]);
5701 CHECK_EQ(v8::Integer::New(2), args[1]); 5701 CHECK_EQ(v8::Integer::New(2), args[1]);
5702 CHECK_EQ(v8::Integer::New(3), args[2]); 5702 CHECK_EQ(v8::Integer::New(3), args[2]);
5703 CHECK_EQ(v8::Undefined(), args[3]); 5703 CHECK_EQ(v8::Undefined(), args[3]);
5704 v8::HandleScope scope; 5704 v8::HandleScope scope(args.GetIsolate());
5705 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 5705 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
5706 return v8::Undefined(); 5706 return v8::Undefined();
5707 } 5707 }
5708 5708
5709 5709
5710 THREADED_TEST(Arguments) { 5710 THREADED_TEST(Arguments) {
5711 v8::HandleScope scope; 5711 v8::HandleScope scope(v8::Isolate::GetCurrent());
5712 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 5712 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
5713 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); 5713 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback));
5714 LocalContext context(NULL, global); 5714 LocalContext context(NULL, global);
5715 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 5715 args_fun = context->Global()->Get(v8_str("f")).As<Function>();
5716 v8_compile("f(1, 2, 3)")->Run(); 5716 v8_compile("f(1, 2, 3)")->Run();
5717 } 5717 }
5718 5718
5719 5719
5720 static v8::Handle<Value> NoBlockGetterX(Local<String> name, 5720 static v8::Handle<Value> NoBlockGetterX(Local<String> name,
5721 const AccessorInfo&) { 5721 const AccessorInfo&) {
(...skipping 20 matching lines...) Expand all
5742 static v8::Handle<v8::Boolean> IDeleter(uint32_t index, const AccessorInfo&) { 5742 static v8::Handle<v8::Boolean> IDeleter(uint32_t index, const AccessorInfo&) {
5743 if (index != 2) { 5743 if (index != 2) {
5744 return v8::Handle<v8::Boolean>(); // not intercepted 5744 return v8::Handle<v8::Boolean>(); // not intercepted
5745 } 5745 }
5746 5746
5747 return v8::False(); // intercepted, and don't delete the property 5747 return v8::False(); // intercepted, and don't delete the property
5748 } 5748 }
5749 5749
5750 5750
5751 THREADED_TEST(Deleter) { 5751 THREADED_TEST(Deleter) {
5752 v8::HandleScope scope; 5752 v8::HandleScope scope(v8::Isolate::GetCurrent());
5753 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 5753 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
5754 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL); 5754 obj->SetNamedPropertyHandler(NoBlockGetterX, NULL, NULL, PDeleter, NULL);
5755 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL); 5755 obj->SetIndexedPropertyHandler(NoBlockGetterI, NULL, NULL, IDeleter, NULL);
5756 LocalContext context; 5756 LocalContext context;
5757 context->Global()->Set(v8_str("k"), obj->NewInstance()); 5757 context->Global()->Set(v8_str("k"), obj->NewInstance());
5758 CompileRun( 5758 CompileRun(
5759 "k.foo = 'foo';" 5759 "k.foo = 'foo';"
5760 "k.bar = 'bar';" 5760 "k.bar = 'bar';"
5761 "k[2] = 2;" 5761 "k[2] = 2;"
5762 "k[4] = 4;"); 5762 "k[4] = 4;");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5805 static v8::Handle<v8::Array> IndexedEnum(const AccessorInfo&) { 5805 static v8::Handle<v8::Array> IndexedEnum(const AccessorInfo&) {
5806 ApiTestFuzzer::Fuzz(); 5806 ApiTestFuzzer::Fuzz();
5807 v8::Handle<v8::Array> result = v8::Array::New(2); 5807 v8::Handle<v8::Array> result = v8::Array::New(2);
5808 result->Set(v8::Integer::New(0), v8_str("0")); 5808 result->Set(v8::Integer::New(0), v8_str("0"));
5809 result->Set(v8::Integer::New(1), v8_str("1")); 5809 result->Set(v8::Integer::New(1), v8_str("1"));
5810 return result; 5810 return result;
5811 } 5811 }
5812 5812
5813 5813
5814 THREADED_TEST(Enumerators) { 5814 THREADED_TEST(Enumerators) {
5815 v8::HandleScope scope; 5815 v8::HandleScope scope(v8::Isolate::GetCurrent());
5816 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 5816 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
5817 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum); 5817 obj->SetNamedPropertyHandler(GetK, NULL, NULL, NULL, NamedEnum);
5818 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum); 5818 obj->SetIndexedPropertyHandler(IndexedGetK, NULL, NULL, NULL, IndexedEnum);
5819 LocalContext context; 5819 LocalContext context;
5820 context->Global()->Set(v8_str("k"), obj->NewInstance()); 5820 context->Global()->Set(v8_str("k"), obj->NewInstance());
5821 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 5821 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
5822 "k[10] = 0;" 5822 "k[10] = 0;"
5823 "k.a = 0;" 5823 "k.a = 0;"
5824 "k[5] = 0;" 5824 "k[5] = 0;"
5825 "k.b = 0;" 5825 "k.b = 0;"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
5919 } else if (name->Equals(v8_str("p3"))) { 5919 } else if (name->Equals(v8_str("p3"))) {
5920 CHECK_EQ(info.This(), global->Get(v8_str("o3"))); 5920 CHECK_EQ(info.This(), global->Get(v8_str("o3")));
5921 } else if (name->Equals(v8_str("p4"))) { 5921 } else if (name->Equals(v8_str("p4"))) {
5922 CHECK_EQ(info.This(), global->Get(v8_str("o4"))); 5922 CHECK_EQ(info.This(), global->Get(v8_str("o4")));
5923 } 5923 }
5924 return v8::Undefined(); 5924 return v8::Undefined();
5925 } 5925 }
5926 5926
5927 5927
5928 THREADED_TEST(GetterHolders) { 5928 THREADED_TEST(GetterHolders) {
5929 v8::HandleScope scope; 5929 v8::HandleScope scope(v8::Isolate::GetCurrent());
5930 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 5930 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
5931 obj->SetAccessor(v8_str("p1"), PGetter); 5931 obj->SetAccessor(v8_str("p1"), PGetter);
5932 obj->SetAccessor(v8_str("p2"), PGetter); 5932 obj->SetAccessor(v8_str("p2"), PGetter);
5933 obj->SetAccessor(v8_str("p3"), PGetter); 5933 obj->SetAccessor(v8_str("p3"), PGetter);
5934 obj->SetAccessor(v8_str("p4"), PGetter); 5934 obj->SetAccessor(v8_str("p4"), PGetter);
5935 p_getter_count = 0; 5935 p_getter_count = 0;
5936 RunHolderTest(obj); 5936 RunHolderTest(obj);
5937 CHECK_EQ(40, p_getter_count); 5937 CHECK_EQ(40, p_getter_count);
5938 } 5938 }
5939 5939
5940 5940
5941 THREADED_TEST(PreInterceptorHolders) { 5941 THREADED_TEST(PreInterceptorHolders) {
5942 v8::HandleScope scope; 5942 v8::HandleScope scope(v8::Isolate::GetCurrent());
5943 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 5943 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
5944 obj->SetNamedPropertyHandler(PGetter2); 5944 obj->SetNamedPropertyHandler(PGetter2);
5945 p_getter_count2 = 0; 5945 p_getter_count2 = 0;
5946 RunHolderTest(obj); 5946 RunHolderTest(obj);
5947 CHECK_EQ(40, p_getter_count2); 5947 CHECK_EQ(40, p_getter_count2);
5948 } 5948 }
5949 5949
5950 5950
5951 THREADED_TEST(ObjectInstantiation) { 5951 THREADED_TEST(ObjectInstantiation) {
5952 v8::HandleScope scope; 5952 v8::HandleScope scope(v8::Isolate::GetCurrent());
5953 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 5953 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
5954 templ->SetAccessor(v8_str("t"), PGetter2); 5954 templ->SetAccessor(v8_str("t"), PGetter2);
5955 LocalContext context; 5955 LocalContext context;
5956 context->Global()->Set(v8_str("o"), templ->NewInstance()); 5956 context->Global()->Set(v8_str("o"), templ->NewInstance());
5957 for (int i = 0; i < 100; i++) { 5957 for (int i = 0; i < 100; i++) {
5958 v8::HandleScope inner_scope; 5958 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
5959 v8::Handle<v8::Object> obj = templ->NewInstance(); 5959 v8::Handle<v8::Object> obj = templ->NewInstance();
5960 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); 5960 CHECK_NE(obj, context->Global()->Get(v8_str("o")));
5961 context->Global()->Set(v8_str("o2"), obj); 5961 context->Global()->Set(v8_str("o2"), obj);
5962 v8::Handle<Value> value = 5962 v8::Handle<Value> value =
5963 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); 5963 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run();
5964 CHECK_EQ(v8::True(), value); 5964 CHECK_EQ(v8::True(), value);
5965 context->Global()->Set(v8_str("o"), obj); 5965 context->Global()->Set(v8_str("o"), obj);
5966 } 5966 }
5967 } 5967 }
5968 5968
(...skipping 25 matching lines...) Expand all
5994 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str)); 5994 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str));
5995 i::FlattenString(istr); 5995 i::FlattenString(istr);
5996 len = str->Utf8Length(); 5996 len = str->Utf8Length();
5997 } 5997 }
5998 return len; 5998 return len;
5999 } 5999 }
6000 6000
6001 6001
6002 THREADED_TEST(StringWrite) { 6002 THREADED_TEST(StringWrite) {
6003 LocalContext context; 6003 LocalContext context;
6004 v8::HandleScope scope; 6004 v8::HandleScope scope(context->GetIsolate());
6005 v8::Handle<String> str = v8_str("abcde"); 6005 v8::Handle<String> str = v8_str("abcde");
6006 // abc<Icelandic eth><Unicode snowman>. 6006 // abc<Icelandic eth><Unicode snowman>.
6007 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); 6007 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203");
6008 v8::Handle<String> str3 = v8::String::New("abc\0def", 7); 6008 v8::Handle<String> str3 = v8::String::New("abc\0def", 7);
6009 const int kStride = 4; // Must match stride in for loops in JS below. 6009 const int kStride = 4; // Must match stride in for loops in JS below.
6010 CompileRun( 6010 CompileRun(
6011 "var left = '';" 6011 "var left = '';"
6012 "for (var i = 0; i < 0xd800; i += 4) {" 6012 "for (var i = 0; i < 0xd800; i += 4) {"
6013 " left = left + String.fromCharCode(i);" 6013 " left = left + String.fromCharCode(i);"
6014 "}"); 6014 "}");
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
6342 CHECK_EQ((u1 & 0x3), c >> 18); 6342 CHECK_EQ((u1 & 0x3), c >> 18);
6343 } 6343 }
6344 } 6344 }
6345 } 6345 }
6346 } 6346 }
6347 } 6347 }
6348 6348
6349 6349
6350 THREADED_TEST(Utf16) { 6350 THREADED_TEST(Utf16) {
6351 LocalContext context; 6351 LocalContext context;
6352 v8::HandleScope scope; 6352 v8::HandleScope scope(context->GetIsolate());
6353 CompileRun( 6353 CompileRun(
6354 "var pad = '01234567890123456789';" 6354 "var pad = '01234567890123456789';"
6355 "var p = [];" 6355 "var p = [];"
6356 "var plens = [20, 3, 3];" 6356 "var plens = [20, 3, 3];"
6357 "p.push('01234567890123456789');" 6357 "p.push('01234567890123456789');"
6358 "var lead = 0xd800;" 6358 "var lead = 0xd800;"
6359 "var trail = 0xdc00;" 6359 "var trail = 0xdc00;"
6360 "p.push(String.fromCharCode(0xd800));" 6360 "p.push(String.fromCharCode(0xd800));"
6361 "p.push(String.fromCharCode(0xdc00));" 6361 "p.push(String.fromCharCode(0xdc00));"
6362 "var a = [];" 6362 "var a = [];"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6408 6408
6409 static void SameSymbolHelper(const char* a, const char* b) { 6409 static void SameSymbolHelper(const char* a, const char* b) {
6410 Handle<String> symbol1 = v8::String::NewSymbol(a); 6410 Handle<String> symbol1 = v8::String::NewSymbol(a);
6411 Handle<String> symbol2 = v8::String::NewSymbol(b); 6411 Handle<String> symbol2 = v8::String::NewSymbol(b);
6412 CHECK(SameSymbol(symbol1, symbol2)); 6412 CHECK(SameSymbol(symbol1, symbol2));
6413 } 6413 }
6414 6414
6415 6415
6416 THREADED_TEST(Utf16Symbol) { 6416 THREADED_TEST(Utf16Symbol) {
6417 LocalContext context; 6417 LocalContext context;
6418 v8::HandleScope scope; 6418 v8::HandleScope scope(context->GetIsolate());
6419 6419
6420 Handle<String> symbol1 = v8::String::NewSymbol("abc"); 6420 Handle<String> symbol1 = v8::String::NewSymbol("abc");
6421 Handle<String> symbol2 = v8::String::NewSymbol("abc"); 6421 Handle<String> symbol2 = v8::String::NewSymbol("abc");
6422 CHECK(SameSymbol(symbol1, symbol2)); 6422 CHECK(SameSymbol(symbol1, symbol2));
6423 6423
6424 SameSymbolHelper("\360\220\220\205", // 4 byte encoding. 6424 SameSymbolHelper("\360\220\220\205", // 4 byte encoding.
6425 "\355\240\201\355\260\205"); // 2 3-byte surrogates. 6425 "\355\240\201\355\260\205"); // 2 3-byte surrogates.
6426 SameSymbolHelper("\355\240\201\355\260\206", // 2 3-byte surrogates. 6426 SameSymbolHelper("\355\240\201\355\260\206", // 2 3-byte surrogates.
6427 "\360\220\220\206"); // 4 byte encoding. 6427 "\360\220\220\206"); // 4 byte encoding.
6428 SameSymbolHelper("x\360\220\220\205", // 4 byte encoding. 6428 SameSymbolHelper("x\360\220\220\205", // 4 byte encoding.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6460 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0)))); 6460 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0))));
6461 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b)))); 6461 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b))));
6462 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1)))); 6462 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1))));
6463 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2)))); 6463 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2))));
6464 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3)))); 6464 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3))));
6465 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4)))); 6465 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4))));
6466 } 6466 }
6467 6467
6468 6468
6469 THREADED_TEST(ToArrayIndex) { 6469 THREADED_TEST(ToArrayIndex) {
6470 v8::HandleScope scope;
6471 LocalContext context; 6470 LocalContext context;
6471 v8::HandleScope scope(context->GetIsolate());
6472 6472
6473 v8::Handle<String> str = v8_str("42"); 6473 v8::Handle<String> str = v8_str("42");
6474 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 6474 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
6475 CHECK(!index.IsEmpty()); 6475 CHECK(!index.IsEmpty());
6476 CHECK_EQ(42.0, index->Uint32Value()); 6476 CHECK_EQ(42.0, index->Uint32Value());
6477 str = v8_str("42asdf"); 6477 str = v8_str("42asdf");
6478 index = str->ToArrayIndex(); 6478 index = str->ToArrayIndex();
6479 CHECK(index.IsEmpty()); 6479 CHECK(index.IsEmpty());
6480 str = v8_str("-42"); 6480 str = v8_str("-42");
6481 index = str->ToArrayIndex(); 6481 index = str->ToArrayIndex();
6482 CHECK(index.IsEmpty()); 6482 CHECK(index.IsEmpty());
6483 str = v8_str("4294967295"); 6483 str = v8_str("4294967295");
6484 index = str->ToArrayIndex(); 6484 index = str->ToArrayIndex();
6485 CHECK(!index.IsEmpty()); 6485 CHECK(!index.IsEmpty());
6486 CHECK_EQ(4294967295.0, index->Uint32Value()); 6486 CHECK_EQ(4294967295.0, index->Uint32Value());
6487 v8::Handle<v8::Number> num = v8::Number::New(1); 6487 v8::Handle<v8::Number> num = v8::Number::New(1);
6488 index = num->ToArrayIndex(); 6488 index = num->ToArrayIndex();
6489 CHECK(!index.IsEmpty()); 6489 CHECK(!index.IsEmpty());
6490 CHECK_EQ(1.0, index->Uint32Value()); 6490 CHECK_EQ(1.0, index->Uint32Value());
6491 num = v8::Number::New(-1); 6491 num = v8::Number::New(-1);
6492 index = num->ToArrayIndex(); 6492 index = num->ToArrayIndex();
6493 CHECK(index.IsEmpty()); 6493 CHECK(index.IsEmpty());
6494 v8::Handle<v8::Object> obj = v8::Object::New(); 6494 v8::Handle<v8::Object> obj = v8::Object::New();
6495 index = obj->ToArrayIndex(); 6495 index = obj->ToArrayIndex();
6496 CHECK(index.IsEmpty()); 6496 CHECK(index.IsEmpty());
6497 } 6497 }
6498 6498
6499 6499
6500 THREADED_TEST(ErrorConstruction) { 6500 THREADED_TEST(ErrorConstruction) {
6501 v8::HandleScope scope;
6502 LocalContext context; 6501 LocalContext context;
6502 v8::HandleScope scope(context->GetIsolate());
6503 6503
6504 v8::Handle<String> foo = v8_str("foo"); 6504 v8::Handle<String> foo = v8_str("foo");
6505 v8::Handle<String> message = v8_str("message"); 6505 v8::Handle<String> message = v8_str("message");
6506 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); 6506 v8::Handle<Value> range_error = v8::Exception::RangeError(foo);
6507 CHECK(range_error->IsObject()); 6507 CHECK(range_error->IsObject());
6508 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); 6508 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo));
6509 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); 6509 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo);
6510 CHECK(reference_error->IsObject()); 6510 CHECK(reference_error->IsObject());
6511 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); 6511 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo));
6512 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); 6512 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo);
(...skipping 18 matching lines...) Expand all
6531 Local<Value> value, 6531 Local<Value> value,
6532 const AccessorInfo& info) { 6532 const AccessorInfo& info) {
6533 if (info.This()->Has(name)) { 6533 if (info.This()->Has(name)) {
6534 info.This()->Delete(name); 6534 info.This()->Delete(name);
6535 } 6535 }
6536 info.This()->Set(name, value); 6536 info.This()->Set(name, value);
6537 } 6537 }
6538 6538
6539 6539
6540 THREADED_TEST(DeleteAccessor) { 6540 THREADED_TEST(DeleteAccessor) {
6541 v8::HandleScope scope; 6541 v8::HandleScope scope(v8::Isolate::GetCurrent());
6542 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6542 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6543 obj->SetAccessor(v8_str("y"), YGetter, YSetter); 6543 obj->SetAccessor(v8_str("y"), YGetter, YSetter);
6544 LocalContext context; 6544 LocalContext context;
6545 v8::Handle<v8::Object> holder = obj->NewInstance(); 6545 v8::Handle<v8::Object> holder = obj->NewInstance();
6546 context->Global()->Set(v8_str("holder"), holder); 6546 context->Global()->Set(v8_str("holder"), holder);
6547 v8::Handle<Value> result = CompileRun( 6547 v8::Handle<Value> result = CompileRun(
6548 "holder.y = 11; holder.y = 12; holder.y"); 6548 "holder.y = 11; holder.y = 12; holder.y");
6549 CHECK_EQ(12, result->Uint32Value()); 6549 CHECK_EQ(12, result->Uint32Value());
6550 } 6550 }
6551 6551
6552 6552
6553 THREADED_TEST(TypeSwitch) { 6553 THREADED_TEST(TypeSwitch) {
6554 v8::HandleScope scope; 6554 v8::HandleScope scope(v8::Isolate::GetCurrent());
6555 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(); 6555 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New();
6556 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(); 6556 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New();
6557 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(); 6557 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New();
6558 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 6558 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
6559 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 6559 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
6560 LocalContext context; 6560 LocalContext context;
6561 v8::Handle<v8::Object> obj0 = v8::Object::New(); 6561 v8::Handle<v8::Object> obj0 = v8::Object::New();
6562 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 6562 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
6563 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 6563 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
6564 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 6564 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6622 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, 6622 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>,
6623 v8::Handle<Value>) { 6623 v8::Handle<Value>) {
6624 report_count++; 6624 report_count++;
6625 } 6625 }
6626 6626
6627 6627
6628 // Counts uncaught exceptions, but other tests running in parallel 6628 // Counts uncaught exceptions, but other tests running in parallel
6629 // also have uncaught exceptions. 6629 // also have uncaught exceptions.
6630 TEST(ApiUncaughtException) { 6630 TEST(ApiUncaughtException) {
6631 report_count = 0; 6631 report_count = 0;
6632 v8::HandleScope scope;
6633 LocalContext env; 6632 LocalContext env;
6633 v8::HandleScope scope(env->GetIsolate());
6634 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 6634 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener);
6635 6635
6636 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 6636 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback);
6637 v8::Local<v8::Object> global = env->Global(); 6637 v8::Local<v8::Object> global = env->Global();
6638 global->Set(v8_str("trouble"), fun->GetFunction()); 6638 global->Set(v8_str("trouble"), fun->GetFunction());
6639 6639
6640 Script::Compile(v8_str("function trouble_callee() {" 6640 Script::Compile(v8_str("function trouble_callee() {"
6641 " var x = null;" 6641 " var x = null;"
6642 " return x.foo;" 6642 " return x.foo;"
6643 "};" 6643 "};"
(...skipping 17 matching lines...) Expand all
6661 v8::Handle<v8::Value> name_val = message->GetScriptResourceName(); 6661 v8::Handle<v8::Value> name_val = message->GetScriptResourceName();
6662 CHECK(!name_val.IsEmpty() && name_val->IsString()); 6662 CHECK(!name_val.IsEmpty() && name_val->IsString());
6663 v8::String::AsciiValue name(message->GetScriptResourceName()); 6663 v8::String::AsciiValue name(message->GetScriptResourceName());
6664 CHECK_EQ(script_resource_name, *name); 6664 CHECK_EQ(script_resource_name, *name);
6665 CHECK_EQ(3, message->GetLineNumber()); 6665 CHECK_EQ(3, message->GetLineNumber());
6666 v8::String::AsciiValue source_line(message->GetSourceLine()); 6666 v8::String::AsciiValue source_line(message->GetSourceLine());
6667 CHECK_EQ(" new o.foo();", *source_line); 6667 CHECK_EQ(" new o.foo();", *source_line);
6668 } 6668 }
6669 6669
6670 TEST(ExceptionInNativeScript) { 6670 TEST(ExceptionInNativeScript) {
6671 v8::HandleScope scope;
6672 LocalContext env; 6671 LocalContext env;
6672 v8::HandleScope scope(env->GetIsolate());
6673 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 6673 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
6674 6674
6675 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 6675 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback);
6676 v8::Local<v8::Object> global = env->Global(); 6676 v8::Local<v8::Object> global = env->Global();
6677 global->Set(v8_str("trouble"), fun->GetFunction()); 6677 global->Set(v8_str("trouble"), fun->GetFunction());
6678 6678
6679 Script::Compile(v8_str("function trouble() {\n" 6679 Script::Compile(v8_str("function trouble() {\n"
6680 " var o = {};\n" 6680 " var o = {};\n"
6681 " new o.foo();\n" 6681 " new o.foo();\n"
6682 "};"), v8::String::New(script_resource_name))->Run(); 6682 "};"), v8::String::New(script_resource_name))->Run();
6683 Local<Value> trouble = global->Get(v8_str("trouble")); 6683 Local<Value> trouble = global->Get(v8_str("trouble"));
6684 CHECK(trouble->IsFunction()); 6684 CHECK(trouble->IsFunction());
6685 Function::Cast(*trouble)->Call(global, 0, NULL); 6685 Function::Cast(*trouble)->Call(global, 0, NULL);
6686 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 6686 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
6687 } 6687 }
6688 6688
6689 6689
6690 TEST(CompilationErrorUsingTryCatchHandler) { 6690 TEST(CompilationErrorUsingTryCatchHandler) {
6691 v8::HandleScope scope;
6692 LocalContext env; 6691 LocalContext env;
6692 v8::HandleScope scope(env->GetIsolate());
6693 v8::TryCatch try_catch; 6693 v8::TryCatch try_catch;
6694 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); 6694 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile."));
6695 CHECK_NE(NULL, *try_catch.Exception()); 6695 CHECK_NE(NULL, *try_catch.Exception());
6696 CHECK(try_catch.HasCaught()); 6696 CHECK(try_catch.HasCaught());
6697 } 6697 }
6698 6698
6699 6699
6700 TEST(TryCatchFinallyUsingTryCatchHandler) { 6700 TEST(TryCatchFinallyUsingTryCatchHandler) {
6701 v8::HandleScope scope;
6702 LocalContext env; 6701 LocalContext env;
6702 v8::HandleScope scope(env->GetIsolate());
6703 v8::TryCatch try_catch; 6703 v8::TryCatch try_catch;
6704 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); 6704 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run();
6705 CHECK(!try_catch.HasCaught()); 6705 CHECK(!try_catch.HasCaught());
6706 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); 6706 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run();
6707 CHECK(try_catch.HasCaught()); 6707 CHECK(try_catch.HasCaught());
6708 try_catch.Reset(); 6708 try_catch.Reset();
6709 Script::Compile(v8_str("(function() {" 6709 Script::Compile(v8_str("(function() {"
6710 "try { throw ''; } finally { return; }" 6710 "try { throw ''; } finally { return; }"
6711 "})()"))->Run(); 6711 "})()"))->Run();
6712 CHECK(!try_catch.HasCaught()); 6712 CHECK(!try_catch.HasCaught());
6713 Script::Compile(v8_str("(function()" 6713 Script::Compile(v8_str("(function()"
6714 " { try { throw ''; } finally { throw 0; }" 6714 " { try { throw ''; } finally { throw 0; }"
6715 "})()"))->Run(); 6715 "})()"))->Run();
6716 CHECK(try_catch.HasCaught()); 6716 CHECK(try_catch.HasCaught());
6717 } 6717 }
6718 6718
6719 6719
6720 // SecurityHandler can't be run twice 6720 // SecurityHandler can't be run twice
6721 TEST(SecurityHandler) { 6721 TEST(SecurityHandler) {
6722 v8::HandleScope scope0; 6722 v8::HandleScope scope0(v8::Isolate::GetCurrent());
6723 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 6723 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
6724 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, 6724 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback,
6725 IndexedSecurityTestCallback); 6725 IndexedSecurityTestCallback);
6726 // Create an environment 6726 // Create an environment
6727 v8::Persistent<Context> context0 = 6727 v8::Persistent<Context> context0 =
6728 Context::New(NULL, global_template); 6728 Context::New(NULL, global_template);
6729 context0->Enter(); 6729 context0->Enter();
6730 6730
6731 v8::Handle<v8::Object> global0 = context0->Global(); 6731 v8::Handle<v8::Object> global0 = context0->Global();
6732 v8::Handle<Script> script0 = v8_compile("foo = 111"); 6732 v8::Handle<Script> script0 = v8_compile("foo = 111");
6733 script0->Run(); 6733 script0->Run();
6734 global0->Set(v8_str("0"), v8_num(999)); 6734 global0->Set(v8_str("0"), v8_num(999));
6735 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); 6735 v8::Handle<Value> foo0 = global0->Get(v8_str("foo"));
6736 CHECK_EQ(111, foo0->Int32Value()); 6736 CHECK_EQ(111, foo0->Int32Value());
6737 v8::Handle<Value> z0 = global0->Get(v8_str("0")); 6737 v8::Handle<Value> z0 = global0->Get(v8_str("0"));
6738 CHECK_EQ(999, z0->Int32Value()); 6738 CHECK_EQ(999, z0->Int32Value());
6739 6739
6740 // Create another environment, should fail security checks. 6740 // Create another environment, should fail security checks.
6741 v8::HandleScope scope1; 6741 v8::HandleScope scope1(v8::Isolate::GetCurrent());
6742 6742
6743 v8::Persistent<Context> context1 = 6743 v8::Persistent<Context> context1 =
6744 Context::New(NULL, global_template); 6744 Context::New(NULL, global_template);
6745 context1->Enter(); 6745 context1->Enter();
6746 6746
6747 v8::Handle<v8::Object> global1 = context1->Global(); 6747 v8::Handle<v8::Object> global1 = context1->Global();
6748 global1->Set(v8_str("othercontext"), global0); 6748 global1->Set(v8_str("othercontext"), global0);
6749 // This set will fail the security check. 6749 // This set will fail the security check.
6750 v8::Handle<Script> script1 = 6750 v8::Handle<Script> script1 =
6751 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); 6751 v8_compile("othercontext.foo = 222; othercontext[0] = 888;");
6752 script1->Run(); 6752 script1->Run();
6753 // This read will pass the security check. 6753 // This read will pass the security check.
6754 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); 6754 v8::Handle<Value> foo1 = global0->Get(v8_str("foo"));
6755 CHECK_EQ(111, foo1->Int32Value()); 6755 CHECK_EQ(111, foo1->Int32Value());
6756 // This read will pass the security check. 6756 // This read will pass the security check.
6757 v8::Handle<Value> z1 = global0->Get(v8_str("0")); 6757 v8::Handle<Value> z1 = global0->Get(v8_str("0"));
6758 CHECK_EQ(999, z1->Int32Value()); 6758 CHECK_EQ(999, z1->Int32Value());
6759 6759
6760 // Create another environment, should pass security checks. 6760 // Create another environment, should pass security checks.
6761 { g_security_callback_result = true; // allow security handler to pass. 6761 { g_security_callback_result = true; // allow security handler to pass.
6762 v8::HandleScope scope2; 6762 v8::HandleScope scope2(v8::Isolate::GetCurrent());
6763 LocalContext context2; 6763 LocalContext context2;
6764 v8::Handle<v8::Object> global2 = context2->Global(); 6764 v8::Handle<v8::Object> global2 = context2->Global();
6765 global2->Set(v8_str("othercontext"), global0); 6765 global2->Set(v8_str("othercontext"), global0);
6766 v8::Handle<Script> script2 = 6766 v8::Handle<Script> script2 =
6767 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 6767 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
6768 script2->Run(); 6768 script2->Run();
6769 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 6769 v8::Handle<Value> foo2 = global0->Get(v8_str("foo"));
6770 CHECK_EQ(333, foo2->Int32Value()); 6770 CHECK_EQ(333, foo2->Int32Value());
6771 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 6771 v8::Handle<Value> z2 = global0->Get(v8_str("0"));
6772 CHECK_EQ(888, z2->Int32Value()); 6772 CHECK_EQ(888, z2->Int32Value());
6773 } 6773 }
6774 6774
6775 context1->Exit(); 6775 context1->Exit();
6776 context1.Dispose(context1->GetIsolate()); 6776 context1.Dispose(context1->GetIsolate());
6777 6777
6778 context0->Exit(); 6778 context0->Exit();
6779 context0.Dispose(context0->GetIsolate()); 6779 context0.Dispose(context0->GetIsolate());
6780 } 6780 }
6781 6781
6782 6782
6783 THREADED_TEST(SecurityChecks) { 6783 THREADED_TEST(SecurityChecks) {
6784 v8::HandleScope handle_scope;
6785 LocalContext env1; 6784 LocalContext env1;
6785 v8::HandleScope handle_scope(env1->GetIsolate());
6786 v8::Persistent<Context> env2 = Context::New(); 6786 v8::Persistent<Context> env2 = Context::New();
6787 6787
6788 Local<Value> foo = v8_str("foo"); 6788 Local<Value> foo = v8_str("foo");
6789 Local<Value> bar = v8_str("bar"); 6789 Local<Value> bar = v8_str("bar");
6790 6790
6791 // Set to the same domain. 6791 // Set to the same domain.
6792 env1->SetSecurityToken(foo); 6792 env1->SetSecurityToken(foo);
6793 6793
6794 // Create a function in env1. 6794 // Create a function in env1.
6795 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); 6795 Script::Compile(v8_str("spy=function(){return spy;}"))->Run();
(...skipping 23 matching lines...) Expand all
6819 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); 6819 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL);
6820 CHECK(try_catch.HasCaught()); 6820 CHECK(try_catch.HasCaught());
6821 } 6821 }
6822 6822
6823 env2.Dispose(env2->GetIsolate()); 6823 env2.Dispose(env2->GetIsolate());
6824 } 6824 }
6825 6825
6826 6826
6827 // Regression test case for issue 1183439. 6827 // Regression test case for issue 1183439.
6828 THREADED_TEST(SecurityChecksForPrototypeChain) { 6828 THREADED_TEST(SecurityChecksForPrototypeChain) {
6829 v8::HandleScope scope;
6830 LocalContext current; 6829 LocalContext current;
6830 v8::HandleScope scope(current->GetIsolate());
6831 v8::Persistent<Context> other = Context::New(); 6831 v8::Persistent<Context> other = Context::New();
6832 6832
6833 // Change context to be able to get to the Object function in the 6833 // Change context to be able to get to the Object function in the
6834 // other context without hitting the security checks. 6834 // other context without hitting the security checks.
6835 v8::Local<Value> other_object; 6835 v8::Local<Value> other_object;
6836 { Context::Scope scope(other); 6836 { Context::Scope scope(other);
6837 other_object = other->Global()->Get(v8_str("Object")); 6837 other_object = other->Global()->Get(v8_str("Object"));
6838 other->Global()->Set(v8_num(42), v8_num(87)); 6838 other->Global()->Set(v8_num(42), v8_num(87));
6839 } 6839 }
6840 6840
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6887 CHECK(!access_f2->Run()->Equals(v8_num(100))); 6887 CHECK(!access_f2->Run()->Equals(v8_num(100)));
6888 CHECK(access_f2->Run()->IsUndefined()); 6888 CHECK(access_f2->Run()->IsUndefined());
6889 CHECK(!access_f3->Run()->Equals(v8_num(101))); 6889 CHECK(!access_f3->Run()->Equals(v8_num(101)));
6890 CHECK(access_f3->Run()->IsUndefined()); 6890 CHECK(access_f3->Run()->IsUndefined());
6891 } 6891 }
6892 other.Dispose(other->GetIsolate()); 6892 other.Dispose(other->GetIsolate());
6893 } 6893 }
6894 6894
6895 6895
6896 THREADED_TEST(CrossDomainDelete) { 6896 THREADED_TEST(CrossDomainDelete) {
6897 v8::HandleScope handle_scope;
6898 LocalContext env1; 6897 LocalContext env1;
6898 v8::HandleScope handle_scope(env1->GetIsolate());
6899 v8::Persistent<Context> env2 = Context::New(); 6899 v8::Persistent<Context> env2 = Context::New();
6900 6900
6901 Local<Value> foo = v8_str("foo"); 6901 Local<Value> foo = v8_str("foo");
6902 Local<Value> bar = v8_str("bar"); 6902 Local<Value> bar = v8_str("bar");
6903 6903
6904 // Set to the same domain. 6904 // Set to the same domain.
6905 env1->SetSecurityToken(foo); 6905 env1->SetSecurityToken(foo);
6906 env2->SetSecurityToken(foo); 6906 env2->SetSecurityToken(foo);
6907 6907
6908 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6908 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 11 matching lines...) Expand all
6920 // Check that env1.prop still exists. 6920 // Check that env1.prop still exists.
6921 Local<Value> v = env1->Global()->Get(v8_str("prop")); 6921 Local<Value> v = env1->Global()->Get(v8_str("prop"));
6922 CHECK(v->IsNumber()); 6922 CHECK(v->IsNumber());
6923 CHECK_EQ(3, v->Int32Value()); 6923 CHECK_EQ(3, v->Int32Value());
6924 6924
6925 env2.Dispose(env2->GetIsolate()); 6925 env2.Dispose(env2->GetIsolate());
6926 } 6926 }
6927 6927
6928 6928
6929 THREADED_TEST(CrossDomainIsPropertyEnumerable) { 6929 THREADED_TEST(CrossDomainIsPropertyEnumerable) {
6930 v8::HandleScope handle_scope;
6931 LocalContext env1; 6930 LocalContext env1;
6931 v8::HandleScope handle_scope(env1->GetIsolate());
6932 v8::Persistent<Context> env2 = Context::New(); 6932 v8::Persistent<Context> env2 = Context::New();
6933 6933
6934 Local<Value> foo = v8_str("foo"); 6934 Local<Value> foo = v8_str("foo");
6935 Local<Value> bar = v8_str("bar"); 6935 Local<Value> bar = v8_str("bar");
6936 6936
6937 // Set to the same domain. 6937 // Set to the same domain.
6938 env1->SetSecurityToken(foo); 6938 env1->SetSecurityToken(foo);
6939 env2->SetSecurityToken(foo); 6939 env2->SetSecurityToken(foo);
6940 6940
6941 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6941 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 13 matching lines...) Expand all
6955 Context::Scope scope_env2(env2); 6955 Context::Scope scope_env2(env2);
6956 Local<Value> result = Script::Compile(test)->Run(); 6956 Local<Value> result = Script::Compile(test)->Run();
6957 CHECK(result->IsFalse()); 6957 CHECK(result->IsFalse());
6958 } 6958 }
6959 6959
6960 env2.Dispose(env2->GetIsolate()); 6960 env2.Dispose(env2->GetIsolate());
6961 } 6961 }
6962 6962
6963 6963
6964 THREADED_TEST(CrossDomainForIn) { 6964 THREADED_TEST(CrossDomainForIn) {
6965 v8::HandleScope handle_scope;
6966 LocalContext env1; 6965 LocalContext env1;
6966 v8::HandleScope handle_scope(env1->GetIsolate());
6967 v8::Persistent<Context> env2 = Context::New(); 6967 v8::Persistent<Context> env2 = Context::New();
6968 6968
6969 Local<Value> foo = v8_str("foo"); 6969 Local<Value> foo = v8_str("foo");
6970 Local<Value> bar = v8_str("bar"); 6970 Local<Value> bar = v8_str("bar");
6971 6971
6972 // Set to the same domain. 6972 // Set to the same domain.
6973 env1->SetSecurityToken(foo); 6973 env1->SetSecurityToken(foo);
6974 env2->SetSecurityToken(foo); 6974 env2->SetSecurityToken(foo);
6975 6975
6976 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6976 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 11 matching lines...) Expand all
6988 "for (var p in obj)" 6988 "for (var p in obj)"
6989 " if (p == 'prop') return false;" 6989 " if (p == 'prop') return false;"
6990 "return true;})()"); 6990 "return true;})()");
6991 CHECK(result->IsTrue()); 6991 CHECK(result->IsTrue());
6992 } 6992 }
6993 env2.Dispose(env2->GetIsolate()); 6993 env2.Dispose(env2->GetIsolate());
6994 } 6994 }
6995 6995
6996 6996
6997 TEST(ContextDetachGlobal) { 6997 TEST(ContextDetachGlobal) {
6998 v8::HandleScope handle_scope;
6999 LocalContext env1; 6998 LocalContext env1;
6999 v8::HandleScope handle_scope(env1->GetIsolate());
7000 v8::Persistent<Context> env2 = Context::New(); 7000 v8::Persistent<Context> env2 = Context::New();
7001 7001
7002 Local<v8::Object> global1 = env1->Global(); 7002 Local<v8::Object> global1 = env1->Global();
7003 7003
7004 Local<Value> foo = v8_str("foo"); 7004 Local<Value> foo = v8_str("foo");
7005 7005
7006 // Set to the same domain. 7006 // Set to the same domain.
7007 env1->SetSecurityToken(foo); 7007 env1->SetSecurityToken(foo);
7008 env2->SetSecurityToken(foo); 7008 env2->SetSecurityToken(foo);
7009 7009
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7052 Local<Value> r = global3->Get(v8_str("prop2")); 7052 Local<Value> r = global3->Get(v8_str("prop2"));
7053 CHECK(r->IsUndefined()); 7053 CHECK(r->IsUndefined());
7054 } 7054 }
7055 7055
7056 env2.Dispose(env2->GetIsolate()); 7056 env2.Dispose(env2->GetIsolate());
7057 env3.Dispose(env3->GetIsolate()); 7057 env3.Dispose(env3->GetIsolate());
7058 } 7058 }
7059 7059
7060 7060
7061 TEST(DetachAndReattachGlobal) { 7061 TEST(DetachAndReattachGlobal) {
7062 v8::HandleScope scope;
7063 LocalContext env1; 7062 LocalContext env1;
7063 v8::HandleScope scope(env1->GetIsolate());
7064 7064
7065 // Create second environment. 7065 // Create second environment.
7066 v8::Persistent<Context> env2 = Context::New(); 7066 v8::Persistent<Context> env2 = Context::New();
7067 7067
7068 Local<Value> foo = v8_str("foo"); 7068 Local<Value> foo = v8_str("foo");
7069 7069
7070 // Set same security token for env1 and env2. 7070 // Set same security token for env1 and env2.
7071 env1->SetSecurityToken(foo); 7071 env1->SetSecurityToken(foo);
7072 env2->SetSecurityToken(foo); 7072 env2->SetSecurityToken(foo);
7073 7073
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
7178 } 7178 }
7179 7179
7180 7180
7181 static void UnreachableSetter(Local<String>, Local<Value>, 7181 static void UnreachableSetter(Local<String>, Local<Value>,
7182 const AccessorInfo&) { 7182 const AccessorInfo&) {
7183 CHECK(false); // This function should nto be called. 7183 CHECK(false); // This function should nto be called.
7184 } 7184 }
7185 7185
7186 7186
7187 TEST(AccessControl) { 7187 TEST(AccessControl) {
7188 v8::HandleScope handle_scope; 7188 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7189 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7189 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7190 7190
7191 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7191 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7192 IndexedAccessBlocker); 7192 IndexedAccessBlocker);
7193 7193
7194 // Add an accessor accessible by cross-domain JS code. 7194 // Add an accessor accessible by cross-domain JS code.
7195 global_template->SetAccessor( 7195 global_template->SetAccessor(
7196 v8_str("accessible_prop"), 7196 v8_str("accessible_prop"),
7197 EchoGetter, EchoSetter, 7197 EchoGetter, EchoSetter,
7198 v8::Handle<Value>(), 7198 v8::Handle<Value>(),
(...skipping 25 matching lines...) Expand all
7224 7224
7225 // Define an element with JS getter and setter. 7225 // Define an element with JS getter and setter.
7226 CompileRun( 7226 CompileRun(
7227 "function el_getter() { return 'el_getter'; };\n" 7227 "function el_getter() { return 'el_getter'; };\n"
7228 "function el_setter() { return 'el_setter'; };\n" 7228 "function el_setter() { return 'el_setter'; };\n"
7229 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); 7229 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
7230 7230
7231 Local<Value> el_getter = global0->Get(v8_str("el_getter")); 7231 Local<Value> el_getter = global0->Get(v8_str("el_getter"));
7232 Local<Value> el_setter = global0->Get(v8_str("el_setter")); 7232 Local<Value> el_setter = global0->Get(v8_str("el_setter"));
7233 7233
7234 v8::HandleScope scope1; 7234 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7235 7235
7236 v8::Persistent<Context> context1 = Context::New(); 7236 v8::Persistent<Context> context1 = Context::New();
7237 context1->Enter(); 7237 context1->Enter();
7238 7238
7239 v8::Handle<v8::Object> global1 = context1->Global(); 7239 v8::Handle<v8::Object> global1 = context1->Global();
7240 global1->Set(v8_str("other"), global0); 7240 global1->Set(v8_str("other"), global0);
7241 7241
7242 // Access blocked property. 7242 // Access blocked property.
7243 CompileRun("other.blocked_prop = 1"); 7243 CompileRun("other.blocked_prop = 1");
7244 7244
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
7422 CHECK(value->IsTrue()); 7422 CHECK(value->IsTrue());
7423 7423
7424 context1->Exit(); 7424 context1->Exit();
7425 context0->Exit(); 7425 context0->Exit();
7426 context1.Dispose(context1->GetIsolate()); 7426 context1.Dispose(context1->GetIsolate());
7427 context0.Dispose(context0->GetIsolate()); 7427 context0.Dispose(context0->GetIsolate());
7428 } 7428 }
7429 7429
7430 7430
7431 TEST(AccessControlES5) { 7431 TEST(AccessControlES5) {
7432 v8::HandleScope handle_scope; 7432 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7433 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7433 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7434 7434
7435 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7435 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7436 IndexedAccessBlocker); 7436 IndexedAccessBlocker);
7437 7437
7438 // Add accessible accessor. 7438 // Add accessible accessor.
7439 global_template->SetAccessor( 7439 global_template->SetAccessor(
7440 v8_str("accessible_prop"), 7440 v8_str("accessible_prop"),
7441 EchoGetter, EchoSetter, 7441 EchoGetter, EchoSetter,
7442 v8::Handle<Value>(), 7442 v8::Handle<Value>(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7508 7508
7509 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, 7509 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
7510 uint32_t key, 7510 uint32_t key,
7511 v8::AccessType type, 7511 v8::AccessType type,
7512 Local<Value> data) { 7512 Local<Value> data) {
7513 return false; 7513 return false;
7514 } 7514 }
7515 7515
7516 7516
7517 THREADED_TEST(AccessControlGetOwnPropertyNames) { 7517 THREADED_TEST(AccessControlGetOwnPropertyNames) {
7518 v8::HandleScope handle_scope; 7518 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7519 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 7519 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
7520 7520
7521 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 7521 obj_template->Set(v8_str("x"), v8::Integer::New(42));
7522 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 7522 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
7523 GetOwnPropertyNamesIndexedBlocker); 7523 GetOwnPropertyNamesIndexedBlocker);
7524 7524
7525 // Create an environment 7525 // Create an environment
7526 v8::Persistent<Context> context0 = Context::New(NULL, obj_template); 7526 v8::Persistent<Context> context0 = Context::New(NULL, obj_template);
7527 context0->Enter(); 7527 context0->Enter();
7528 7528
7529 v8::Handle<v8::Object> global0 = context0->Global(); 7529 v8::Handle<v8::Object> global0 = context0->Global();
7530 7530
7531 v8::HandleScope scope1; 7531 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7532 7532
7533 v8::Persistent<Context> context1 = Context::New(); 7533 v8::Persistent<Context> context1 = Context::New();
7534 context1->Enter(); 7534 context1->Enter();
7535 7535
7536 v8::Handle<v8::Object> global1 = context1->Global(); 7536 v8::Handle<v8::Object> global1 = context1->Global();
7537 global1->Set(v8_str("other"), global0); 7537 global1->Set(v8_str("other"), global0);
7538 global1->Set(v8_str("object"), obj_template->NewInstance()); 7538 global1->Set(v8_str("object"), obj_template->NewInstance());
7539 7539
7540 v8::Handle<Value> value; 7540 v8::Handle<Value> value;
7541 7541
(...skipping 25 matching lines...) Expand all
7567 7567
7568 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) { 7568 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) {
7569 v8::Handle<v8::Array> result = v8::Array::New(2); 7569 v8::Handle<v8::Array> result = v8::Array::New(2);
7570 result->Set(0, v8_str("x")); 7570 result->Set(0, v8_str("x"));
7571 result->Set(1, v8::Object::New()); 7571 result->Set(1, v8::Object::New());
7572 return result; 7572 return result;
7573 } 7573 }
7574 7574
7575 7575
7576 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 7576 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
7577 v8::HandleScope handle_scope; 7577 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7578 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 7578 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
7579 7579
7580 obj_template->Set(v8_str("7"), v8::Integer::New(7)); 7580 obj_template->Set(v8_str("7"), v8::Integer::New(7));
7581 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 7581 obj_template->Set(v8_str("x"), v8::Integer::New(42));
7582 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 7582 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
7583 IndexedPropertyEnumerator); 7583 IndexedPropertyEnumerator);
7584 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, 7584 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
7585 NamedPropertyEnumerator); 7585 NamedPropertyEnumerator);
7586 7586
7587 LocalContext context; 7587 LocalContext context;
(...skipping 14 matching lines...) Expand all
7602 } 7602 }
7603 7603
7604 7604
7605 static v8::Handle<Value> ConstTenGetter(Local<String> name, 7605 static v8::Handle<Value> ConstTenGetter(Local<String> name,
7606 const AccessorInfo& info) { 7606 const AccessorInfo& info) {
7607 return v8_num(10); 7607 return v8_num(10);
7608 } 7608 }
7609 7609
7610 7610
7611 THREADED_TEST(CrossDomainAccessors) { 7611 THREADED_TEST(CrossDomainAccessors) {
7612 v8::HandleScope handle_scope; 7612 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7613 7613
7614 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 7614 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
7615 7615
7616 v8::Handle<v8::ObjectTemplate> global_template = 7616 v8::Handle<v8::ObjectTemplate> global_template =
7617 func_template->InstanceTemplate(); 7617 func_template->InstanceTemplate();
7618 7618
7619 v8::Handle<v8::ObjectTemplate> proto_template = 7619 v8::Handle<v8::ObjectTemplate> proto_template =
7620 func_template->PrototypeTemplate(); 7620 func_template->PrototypeTemplate();
7621 7621
7622 // Add an accessor to proto that's accessible by cross-domain JS code. 7622 // Add an accessor to proto that's accessible by cross-domain JS code.
7623 proto_template->SetAccessor(v8_str("accessible"), 7623 proto_template->SetAccessor(v8_str("accessible"),
7624 ConstTenGetter, 0, 7624 ConstTenGetter, 0,
7625 v8::Handle<Value>(), 7625 v8::Handle<Value>(),
7626 v8::ALL_CAN_READ); 7626 v8::ALL_CAN_READ);
7627 7627
7628 // Add an accessor that is not accessible by cross-domain JS code. 7628 // Add an accessor that is not accessible by cross-domain JS code.
7629 global_template->SetAccessor(v8_str("unreachable"), 7629 global_template->SetAccessor(v8_str("unreachable"),
7630 UnreachableGetter, 0, 7630 UnreachableGetter, 0,
7631 v8::Handle<Value>(), 7631 v8::Handle<Value>(),
7632 v8::DEFAULT); 7632 v8::DEFAULT);
7633 7633
7634 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 7634 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
7635 context0->Enter(); 7635 context0->Enter();
7636 7636
7637 Local<v8::Object> global = context0->Global(); 7637 Local<v8::Object> global = context0->Global();
7638 // Add a normal property that shadows 'accessible' 7638 // Add a normal property that shadows 'accessible'
7639 global->Set(v8_str("accessible"), v8_num(11)); 7639 global->Set(v8_str("accessible"), v8_num(11));
7640 7640
7641 // Enter a new context. 7641 // Enter a new context.
7642 v8::HandleScope scope1; 7642 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7643 v8::Persistent<Context> context1 = Context::New(); 7643 v8::Persistent<Context> context1 = Context::New();
7644 context1->Enter(); 7644 context1->Enter();
7645 7645
7646 v8::Handle<v8::Object> global1 = context1->Global(); 7646 v8::Handle<v8::Object> global1 = context1->Global();
7647 global1->Set(v8_str("other"), global); 7647 global1->Set(v8_str("other"), global);
7648 7648
7649 // Should return 10, instead of 11 7649 // Should return 10, instead of 11
7650 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 7650 v8::Handle<Value> value = v8_compile("other.accessible")->Run();
7651 CHECK(value->IsNumber()); 7651 CHECK(value->IsNumber());
7652 CHECK_EQ(10, value->Int32Value()); 7652 CHECK_EQ(10, value->Int32Value());
(...skipping 27 matching lines...) Expand all
7680 indexed_access_count++; 7680 indexed_access_count++;
7681 return true; 7681 return true;
7682 } 7682 }
7683 7683
7684 7684
7685 // This one is too easily disturbed by other tests. 7685 // This one is too easily disturbed by other tests.
7686 TEST(AccessControlIC) { 7686 TEST(AccessControlIC) {
7687 named_access_count = 0; 7687 named_access_count = 0;
7688 indexed_access_count = 0; 7688 indexed_access_count = 0;
7689 7689
7690 v8::HandleScope handle_scope; 7690 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7691 7691
7692 // Create an environment. 7692 // Create an environment.
7693 v8::Persistent<Context> context0 = Context::New(); 7693 v8::Persistent<Context> context0 = Context::New();
7694 context0->Enter(); 7694 context0->Enter();
7695 7695
7696 // Create an object that requires access-check functions to be 7696 // Create an object that requires access-check functions to be
7697 // called for cross-domain access. 7697 // called for cross-domain access.
7698 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7698 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7699 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 7699 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
7700 IndexedAccessCounter); 7700 IndexedAccessCounter);
7701 Local<v8::Object> object = object_template->NewInstance(); 7701 Local<v8::Object> object = object_template->NewInstance();
7702 7702
7703 v8::HandleScope scope1; 7703 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7704 7704
7705 // Create another environment. 7705 // Create another environment.
7706 v8::Persistent<Context> context1 = Context::New(); 7706 v8::Persistent<Context> context1 = Context::New();
7707 context1->Enter(); 7707 context1->Enter();
7708 7708
7709 // Make easy access to the object from the other environment. 7709 // Make easy access to the object from the other environment.
7710 v8::Handle<v8::Object> global1 = context1->Global(); 7710 v8::Handle<v8::Object> global1 = context1->Global();
7711 global1->Set(v8_str("obj"), object); 7711 global1->Set(v8_str("obj"), object);
7712 7712
7713 v8::Handle<Value> value; 7713 v8::Handle<Value> value;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
7829 7829
7830 // Regression test. In access checks, operations that may cause 7830 // Regression test. In access checks, operations that may cause
7831 // garbage collection are not allowed. It used to be the case that 7831 // garbage collection are not allowed. It used to be the case that
7832 // using the Write operation on a string could cause a garbage 7832 // using the Write operation on a string could cause a garbage
7833 // collection due to flattening of the string. This is no longer the 7833 // collection due to flattening of the string. This is no longer the
7834 // case. 7834 // case.
7835 THREADED_TEST(AccessControlFlatten) { 7835 THREADED_TEST(AccessControlFlatten) {
7836 named_access_count = 0; 7836 named_access_count = 0;
7837 indexed_access_count = 0; 7837 indexed_access_count = 0;
7838 7838
7839 v8::HandleScope handle_scope; 7839 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7840 7840
7841 // Create an environment. 7841 // Create an environment.
7842 v8::Persistent<Context> context0 = Context::New(); 7842 v8::Persistent<Context> context0 = Context::New();
7843 context0->Enter(); 7843 context0->Enter();
7844 7844
7845 // Create an object that requires access-check functions to be 7845 // Create an object that requires access-check functions to be
7846 // called for cross-domain access. 7846 // called for cross-domain access.
7847 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7847 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7848 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, 7848 object_template->SetAccessCheckCallbacks(NamedAccessFlatten,
7849 IndexedAccessFlatten); 7849 IndexedAccessFlatten);
7850 Local<v8::Object> object = object_template->NewInstance(); 7850 Local<v8::Object> object = object_template->NewInstance();
7851 7851
7852 v8::HandleScope scope1; 7852 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7853 7853
7854 // Create another environment. 7854 // Create another environment.
7855 v8::Persistent<Context> context1 = Context::New(); 7855 v8::Persistent<Context> context1 = Context::New();
7856 context1->Enter(); 7856 context1->Enter();
7857 7857
7858 // Make easy access to the object from the other environment. 7858 // Make easy access to the object from the other environment.
7859 v8::Handle<v8::Object> global1 = context1->Global(); 7859 v8::Handle<v8::Object> global1 = context1->Global();
7860 global1->Set(v8_str("obj"), object); 7860 global1->Set(v8_str("obj"), object);
7861 7861
7862 v8::Handle<Value> value; 7862 v8::Handle<Value> value;
(...skipping 30 matching lines...) Expand all
7893 static v8::Handle<Value> AccessControlIndexedSetter( 7893 static v8::Handle<Value> AccessControlIndexedSetter(
7894 uint32_t, Local<Value> value, const AccessorInfo&) { 7894 uint32_t, Local<Value> value, const AccessorInfo&) {
7895 return value; 7895 return value;
7896 } 7896 }
7897 7897
7898 7898
7899 THREADED_TEST(AccessControlInterceptorIC) { 7899 THREADED_TEST(AccessControlInterceptorIC) {
7900 named_access_count = 0; 7900 named_access_count = 0;
7901 indexed_access_count = 0; 7901 indexed_access_count = 0;
7902 7902
7903 v8::HandleScope handle_scope; 7903 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7904 7904
7905 // Create an environment. 7905 // Create an environment.
7906 v8::Persistent<Context> context0 = Context::New(); 7906 v8::Persistent<Context> context0 = Context::New();
7907 context0->Enter(); 7907 context0->Enter();
7908 7908
7909 // Create an object that requires access-check functions to be 7909 // Create an object that requires access-check functions to be
7910 // called for cross-domain access. The object also has interceptors 7910 // called for cross-domain access. The object also has interceptors
7911 // interceptor. 7911 // interceptor.
7912 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7912 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7913 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 7913 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
7914 IndexedAccessCounter); 7914 IndexedAccessCounter);
7915 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, 7915 object_template->SetNamedPropertyHandler(AccessControlNamedGetter,
7916 AccessControlNamedSetter); 7916 AccessControlNamedSetter);
7917 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, 7917 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter,
7918 AccessControlIndexedSetter); 7918 AccessControlIndexedSetter);
7919 Local<v8::Object> object = object_template->NewInstance(); 7919 Local<v8::Object> object = object_template->NewInstance();
7920 7920
7921 v8::HandleScope scope1; 7921 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7922 7922
7923 // Create another environment. 7923 // Create another environment.
7924 v8::Persistent<Context> context1 = Context::New(); 7924 v8::Persistent<Context> context1 = Context::New();
7925 context1->Enter(); 7925 context1->Enter();
7926 7926
7927 // Make easy access to the object from the other environment. 7927 // Make easy access to the object from the other environment.
7928 v8::Handle<v8::Object> global1 = context1->Global(); 7928 v8::Handle<v8::Object> global1 = context1->Global();
7929 global1->Set(v8_str("obj"), object); 7929 global1->Set(v8_str("obj"), object);
7930 7930
7931 v8::Handle<Value> value; 7931 v8::Handle<Value> value;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7968 } 7968 }
7969 7969
7970 7970
7971 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) { 7971 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) {
7972 ApiTestFuzzer::Fuzz(); 7972 ApiTestFuzzer::Fuzz();
7973 return v8_num(12); 7973 return v8_num(12);
7974 } 7974 }
7975 7975
7976 7976
7977 THREADED_TEST(InstanceProperties) { 7977 THREADED_TEST(InstanceProperties) {
7978 v8::HandleScope handle_scope;
7979 LocalContext context; 7978 LocalContext context;
7979 v8::HandleScope handle_scope(context->GetIsolate());
7980 7980
7981 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 7981 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
7982 Local<ObjectTemplate> instance = t->InstanceTemplate(); 7982 Local<ObjectTemplate> instance = t->InstanceTemplate();
7983 7983
7984 instance->Set(v8_str("x"), v8_num(42)); 7984 instance->Set(v8_str("x"), v8_num(42));
7985 instance->Set(v8_str("f"), 7985 instance->Set(v8_str("f"),
7986 v8::FunctionTemplate::New(InstanceFunctionCallback)); 7986 v8::FunctionTemplate::New(InstanceFunctionCallback));
7987 7987
7988 Local<Value> o = t->GetFunction()->NewInstance(); 7988 Local<Value> o = t->GetFunction()->NewInstance();
7989 7989
7990 context->Global()->Set(v8_str("i"), o); 7990 context->Global()->Set(v8_str("i"), o);
7991 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); 7991 Local<Value> value = Script::Compile(v8_str("i.x"))->Run();
7992 CHECK_EQ(42, value->Int32Value()); 7992 CHECK_EQ(42, value->Int32Value());
7993 7993
7994 value = Script::Compile(v8_str("i.f()"))->Run(); 7994 value = Script::Compile(v8_str("i.f()"))->Run();
7995 CHECK_EQ(12, value->Int32Value()); 7995 CHECK_EQ(12, value->Int32Value());
7996 } 7996 }
7997 7997
7998 7998
7999 static v8::Handle<Value> 7999 static v8::Handle<Value>
8000 GlobalObjectInstancePropertiesGet(Local<String> key, const AccessorInfo&) { 8000 GlobalObjectInstancePropertiesGet(Local<String> key, const AccessorInfo&) {
8001 ApiTestFuzzer::Fuzz(); 8001 ApiTestFuzzer::Fuzz();
8002 return v8::Handle<Value>(); 8002 return v8::Handle<Value>();
8003 } 8003 }
8004 8004
8005 8005
8006 THREADED_TEST(GlobalObjectInstanceProperties) { 8006 THREADED_TEST(GlobalObjectInstanceProperties) {
8007 v8::HandleScope handle_scope; 8007 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8008 8008
8009 Local<Value> global_object; 8009 Local<Value> global_object;
8010 8010
8011 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8011 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8012 t->InstanceTemplate()->SetNamedPropertyHandler( 8012 t->InstanceTemplate()->SetNamedPropertyHandler(
8013 GlobalObjectInstancePropertiesGet); 8013 GlobalObjectInstancePropertiesGet);
8014 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8014 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8015 instance_template->Set(v8_str("x"), v8_num(42)); 8015 instance_template->Set(v8_str("x"), v8_num(42));
8016 instance_template->Set(v8_str("f"), 8016 instance_template->Set(v8_str("f"),
8017 v8::FunctionTemplate::New(InstanceFunctionCallback)); 8017 v8::FunctionTemplate::New(InstanceFunctionCallback));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8053 CHECK_EQ(42, value->Int32Value()); 8053 CHECK_EQ(42, value->Int32Value());
8054 value = Script::Compile(v8_str("f()"))->Run(); 8054 value = Script::Compile(v8_str("f()"))->Run();
8055 CHECK_EQ(12, value->Int32Value()); 8055 CHECK_EQ(12, value->Int32Value());
8056 value = Script::Compile(v8_str(script))->Run(); 8056 value = Script::Compile(v8_str(script))->Run();
8057 CHECK_EQ(1, value->Int32Value()); 8057 CHECK_EQ(1, value->Int32Value());
8058 } 8058 }
8059 } 8059 }
8060 8060
8061 8061
8062 THREADED_TEST(CallKnownGlobalReceiver) { 8062 THREADED_TEST(CallKnownGlobalReceiver) {
8063 v8::HandleScope handle_scope; 8063 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8064 8064
8065 Local<Value> global_object; 8065 Local<Value> global_object;
8066 8066
8067 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8067 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8068 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8068 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8069 8069
8070 // The script to check that we leave global object not 8070 // The script to check that we leave global object not
8071 // global object proxy on stack when we deoptimize from inside 8071 // global object proxy on stack when we deoptimize from inside
8072 // arguments evaluation. 8072 // arguments evaluation.
8073 // To provoke error we need to both force deoptimization 8073 // To provoke error we need to both force deoptimization
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8131 8131
8132 8132
8133 static v8::Handle<Value> ShadowNamedGet(Local<String> key, 8133 static v8::Handle<Value> ShadowNamedGet(Local<String> key,
8134 const AccessorInfo&) { 8134 const AccessorInfo&) {
8135 return v8::Handle<Value>(); 8135 return v8::Handle<Value>();
8136 } 8136 }
8137 8137
8138 8138
8139 THREADED_TEST(ShadowObject) { 8139 THREADED_TEST(ShadowObject) {
8140 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 8140 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
8141 v8::HandleScope handle_scope; 8141 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8142 8142
8143 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8143 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New();
8144 LocalContext context(NULL, global_template); 8144 LocalContext context(NULL, global_template);
8145 8145
8146 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8146 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8147 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); 8147 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
8148 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); 8148 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
8149 Local<ObjectTemplate> proto = t->PrototypeTemplate(); 8149 Local<ObjectTemplate> proto = t->PrototypeTemplate();
8150 Local<ObjectTemplate> instance = t->InstanceTemplate(); 8150 Local<ObjectTemplate> instance = t->InstanceTemplate();
8151 8151
(...skipping 19 matching lines...) Expand all
8171 8171
8172 Script::Compile(v8_str("y = 43"))->Run(); 8172 Script::Compile(v8_str("y = 43"))->Run();
8173 CHECK_EQ(1, shadow_y_setter_call_count); 8173 CHECK_EQ(1, shadow_y_setter_call_count);
8174 value = Script::Compile(v8_str("y"))->Run(); 8174 value = Script::Compile(v8_str("y"))->Run();
8175 CHECK_EQ(1, shadow_y_getter_call_count); 8175 CHECK_EQ(1, shadow_y_getter_call_count);
8176 CHECK_EQ(42, value->Int32Value()); 8176 CHECK_EQ(42, value->Int32Value());
8177 } 8177 }
8178 8178
8179 8179
8180 THREADED_TEST(HiddenPrototype) { 8180 THREADED_TEST(HiddenPrototype) {
8181 v8::HandleScope handle_scope;
8182 LocalContext context; 8181 LocalContext context;
8182 v8::HandleScope handle_scope(context->GetIsolate());
8183 8183
8184 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 8184 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
8185 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8185 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8186 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8186 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8187 t1->SetHiddenPrototype(true); 8187 t1->SetHiddenPrototype(true);
8188 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 8188 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
8189 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8189 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8190 t2->SetHiddenPrototype(true); 8190 t2->SetHiddenPrototype(true);
8191 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 8191 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
8192 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8192 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 22 matching lines...) Expand all
8215 // Getting the prototype of o0 should get the first visible one 8215 // Getting the prototype of o0 should get the first visible one
8216 // which is o3. Therefore, z should not be defined on the prototype 8216 // which is o3. Therefore, z should not be defined on the prototype
8217 // object. 8217 // object.
8218 Local<Value> proto = o0->Get(v8_str("__proto__")); 8218 Local<Value> proto = o0->Get(v8_str("__proto__"));
8219 CHECK(proto->IsObject()); 8219 CHECK(proto->IsObject());
8220 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); 8220 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined());
8221 } 8221 }
8222 8222
8223 8223
8224 THREADED_TEST(HiddenPrototypeSet) { 8224 THREADED_TEST(HiddenPrototypeSet) {
8225 v8::HandleScope handle_scope;
8226 LocalContext context; 8225 LocalContext context;
8226 v8::HandleScope handle_scope(context->GetIsolate());
8227 8227
8228 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(); 8228 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New();
8229 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(); 8229 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New();
8230 ht->SetHiddenPrototype(true); 8230 ht->SetHiddenPrototype(true);
8231 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(); 8231 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New();
8232 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8232 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8233 8233
8234 Local<v8::Object> o = ot->GetFunction()->NewInstance(); 8234 Local<v8::Object> o = ot->GetFunction()->NewInstance();
8235 Local<v8::Object> h = ht->GetFunction()->NewInstance(); 8235 Local<v8::Object> h = ht->GetFunction()->NewInstance();
8236 Local<v8::Object> p = pt->GetFunction()->NewInstance(); 8236 Local<v8::Object> p = pt->GetFunction()->NewInstance();
(...skipping 20 matching lines...) Expand all
8257 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 8257 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
8258 o->Set(v8_str("z"), v8_num(9)); 8258 o->Set(v8_str("z"), v8_num(9));
8259 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value()); 8259 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value());
8260 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); 8260 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value());
8261 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 8261 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
8262 } 8262 }
8263 8263
8264 8264
8265 // Regression test for issue 2457. 8265 // Regression test for issue 2457.
8266 THREADED_TEST(HiddenPrototypeIdentityHash) { 8266 THREADED_TEST(HiddenPrototypeIdentityHash) {
8267 v8::HandleScope handle_scope;
8268 LocalContext context; 8267 LocalContext context;
8268 v8::HandleScope handle_scope(context->GetIsolate());
8269 8269
8270 Handle<FunctionTemplate> t = FunctionTemplate::New(); 8270 Handle<FunctionTemplate> t = FunctionTemplate::New();
8271 t->SetHiddenPrototype(true); 8271 t->SetHiddenPrototype(true);
8272 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 8272 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
8273 Handle<Object> p = t->GetFunction()->NewInstance(); 8273 Handle<Object> p = t->GetFunction()->NewInstance();
8274 Handle<Object> o = Object::New(); 8274 Handle<Object> o = Object::New();
8275 o->SetPrototype(p); 8275 o->SetPrototype(p);
8276 8276
8277 int hash = o->GetIdentityHash(); 8277 int hash = o->GetIdentityHash();
8278 USE(hash); 8278 USE(hash);
8279 o->Set(v8_str("foo"), v8_num(42)); 8279 o->Set(v8_str("foo"), v8_num(42));
8280 ASSERT_EQ(hash, o->GetIdentityHash()); 8280 ASSERT_EQ(hash, o->GetIdentityHash());
8281 } 8281 }
8282 8282
8283 8283
8284 THREADED_TEST(SetPrototype) { 8284 THREADED_TEST(SetPrototype) {
8285 v8::HandleScope handle_scope;
8286 LocalContext context; 8285 LocalContext context;
8286 v8::HandleScope handle_scope(context->GetIsolate());
8287 8287
8288 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 8288 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
8289 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8289 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8290 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8290 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8291 t1->SetHiddenPrototype(true); 8291 t1->SetHiddenPrototype(true);
8292 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 8292 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
8293 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8293 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8294 t2->SetHiddenPrototype(true); 8294 t2->SetHiddenPrototype(true);
8295 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 8295 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
8296 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8296 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
8336 CHECK(proto2->IsObject()); 8336 CHECK(proto2->IsObject());
8337 CHECK_EQ(proto2.As<v8::Object>(), o3); 8337 CHECK_EQ(proto2.As<v8::Object>(), o3);
8338 } 8338 }
8339 8339
8340 8340
8341 // Getting property names of an object with a prototype chain that 8341 // Getting property names of an object with a prototype chain that
8342 // triggers dictionary elements in GetLocalPropertyNames() shouldn't 8342 // triggers dictionary elements in GetLocalPropertyNames() shouldn't
8343 // crash the runtime. 8343 // crash the runtime.
8344 THREADED_TEST(Regress91517) { 8344 THREADED_TEST(Regress91517) {
8345 i::FLAG_allow_natives_syntax = true; 8345 i::FLAG_allow_natives_syntax = true;
8346 v8::HandleScope handle_scope;
8347 LocalContext context; 8346 LocalContext context;
8347 v8::HandleScope handle_scope(context->GetIsolate());
8348 8348
8349 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8349 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8350 t1->SetHiddenPrototype(true); 8350 t1->SetHiddenPrototype(true);
8351 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 8351 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
8352 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8352 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8353 t2->SetHiddenPrototype(true); 8353 t2->SetHiddenPrototype(true);
8354 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 8354 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
8355 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); 8355 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New());
8356 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 8356 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
8357 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8357 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 28 matching lines...) Expand all
8386 ExpectTrue("names.indexOf(\"baz\") >= 0"); 8386 ExpectTrue("names.indexOf(\"baz\") >= 0");
8387 ExpectTrue("names.indexOf(\"boo\") >= 0"); 8387 ExpectTrue("names.indexOf(\"boo\") >= 0");
8388 ExpectTrue("names.indexOf(\"foo\") >= 0"); 8388 ExpectTrue("names.indexOf(\"foo\") >= 0");
8389 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 8389 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
8390 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 8390 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
8391 ExpectFalse("names[1005] == undefined"); 8391 ExpectFalse("names[1005] == undefined");
8392 } 8392 }
8393 8393
8394 8394
8395 THREADED_TEST(FunctionReadOnlyPrototype) { 8395 THREADED_TEST(FunctionReadOnlyPrototype) {
8396 v8::HandleScope handle_scope;
8397 LocalContext context; 8396 LocalContext context;
8397 v8::HandleScope handle_scope(context->GetIsolate());
8398 8398
8399 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8399 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8400 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 8400 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
8401 t1->ReadOnlyPrototype(); 8401 t1->ReadOnlyPrototype();
8402 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 8402 context->Global()->Set(v8_str("func1"), t1->GetFunction());
8403 // Configured value of ReadOnly flag. 8403 // Configured value of ReadOnly flag.
8404 CHECK(CompileRun( 8404 CHECK(CompileRun(
8405 "(function() {" 8405 "(function() {"
8406 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 8406 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
8407 " return (descriptor['writable'] == false);" 8407 " return (descriptor['writable'] == false);"
8408 "})()")->BooleanValue()); 8408 "})()")->BooleanValue());
8409 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 8409 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
8410 CHECK_EQ(42, 8410 CHECK_EQ(42,
8411 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 8411 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
8412 8412
8413 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8413 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8414 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 8414 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
8415 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 8415 context->Global()->Set(v8_str("func2"), t2->GetFunction());
8416 // Default value of ReadOnly flag. 8416 // Default value of ReadOnly flag.
8417 CHECK(CompileRun( 8417 CHECK(CompileRun(
8418 "(function() {" 8418 "(function() {"
8419 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 8419 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
8420 " return (descriptor['writable'] == true);" 8420 " return (descriptor['writable'] == true);"
8421 "})()")->BooleanValue()); 8421 "})()")->BooleanValue());
8422 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 8422 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
8423 } 8423 }
8424 8424
8425 8425
8426 THREADED_TEST(SetPrototypeThrows) { 8426 THREADED_TEST(SetPrototypeThrows) {
8427 v8::HandleScope handle_scope;
8428 LocalContext context; 8427 LocalContext context;
8428 v8::HandleScope handle_scope(context->GetIsolate());
8429 8429
8430 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8430 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8431 8431
8432 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 8432 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
8433 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 8433 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
8434 8434
8435 CHECK(o0->SetPrototype(o1)); 8435 CHECK(o0->SetPrototype(o1));
8436 // If setting the prototype leads to the cycle, SetPrototype should 8436 // If setting the prototype leads to the cycle, SetPrototype should
8437 // return false and keep VM in sane state. 8437 // return false and keep VM in sane state.
8438 v8::TryCatch try_catch; 8438 v8::TryCatch try_catch;
8439 CHECK(!o1->SetPrototype(o0)); 8439 CHECK(!o1->SetPrototype(o0));
8440 CHECK(!try_catch.HasCaught()); 8440 CHECK(!try_catch.HasCaught());
8441 ASSERT(!i::Isolate::Current()->has_pending_exception()); 8441 ASSERT(!i::Isolate::Current()->has_pending_exception());
8442 8442
8443 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 8443 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value());
8444 } 8444 }
8445 8445
8446 8446
8447 THREADED_TEST(GetterSetterExceptions) { 8447 THREADED_TEST(GetterSetterExceptions) {
8448 v8::HandleScope handle_scope;
8449 LocalContext context; 8448 LocalContext context;
8449 v8::HandleScope handle_scope(context->GetIsolate());
8450 CompileRun( 8450 CompileRun(
8451 "function Foo() { };" 8451 "function Foo() { };"
8452 "function Throw() { throw 5; };" 8452 "function Throw() { throw 5; };"
8453 "var x = { };" 8453 "var x = { };"
8454 "x.__defineSetter__('set', Throw);" 8454 "x.__defineSetter__('set', Throw);"
8455 "x.__defineGetter__('get', Throw);"); 8455 "x.__defineGetter__('get', Throw);");
8456 Local<v8::Object> x = 8456 Local<v8::Object> x =
8457 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); 8457 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x")));
8458 v8::TryCatch try_catch; 8458 v8::TryCatch try_catch;
8459 x->Set(v8_str("set"), v8::Integer::New(8)); 8459 x->Set(v8_str("set"), v8::Integer::New(8));
8460 x->Get(v8_str("get")); 8460 x->Get(v8_str("get"));
8461 x->Set(v8_str("set"), v8::Integer::New(8)); 8461 x->Set(v8_str("set"), v8::Integer::New(8));
8462 x->Get(v8_str("get")); 8462 x->Get(v8_str("get"));
8463 x->Set(v8_str("set"), v8::Integer::New(8)); 8463 x->Set(v8_str("set"), v8::Integer::New(8));
8464 x->Get(v8_str("get")); 8464 x->Get(v8_str("get"));
8465 x->Set(v8_str("set"), v8::Integer::New(8)); 8465 x->Set(v8_str("set"), v8::Integer::New(8));
8466 x->Get(v8_str("get")); 8466 x->Get(v8_str("get"));
8467 } 8467 }
8468 8468
8469 8469
8470 THREADED_TEST(Constructor) { 8470 THREADED_TEST(Constructor) {
8471 v8::HandleScope handle_scope;
8472 LocalContext context; 8471 LocalContext context;
8472 v8::HandleScope handle_scope(context->GetIsolate());
8473 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 8473 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
8474 templ->SetClassName(v8_str("Fun")); 8474 templ->SetClassName(v8_str("Fun"));
8475 Local<Function> cons = templ->GetFunction(); 8475 Local<Function> cons = templ->GetFunction();
8476 context->Global()->Set(v8_str("Fun"), cons); 8476 context->Global()->Set(v8_str("Fun"), cons);
8477 Local<v8::Object> inst = cons->NewInstance(); 8477 Local<v8::Object> inst = cons->NewInstance();
8478 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 8478 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
8479 CHECK(obj->IsJSObject()); 8479 CHECK(obj->IsJSObject());
8480 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 8480 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
8481 CHECK(value->BooleanValue()); 8481 CHECK(value->BooleanValue());
8482 } 8482 }
(...skipping 19 matching lines...) Expand all
8502 } 8502 }
8503 8503
8504 8504
8505 static Handle<Value> FakeConstructorCallback(const Arguments& args) { 8505 static Handle<Value> FakeConstructorCallback(const Arguments& args) {
8506 ApiTestFuzzer::Fuzz(); 8506 ApiTestFuzzer::Fuzz();
8507 return args[0]; 8507 return args[0];
8508 } 8508 }
8509 8509
8510 8510
8511 THREADED_TEST(ConstructorForObject) { 8511 THREADED_TEST(ConstructorForObject) {
8512 v8::HandleScope handle_scope;
8513 LocalContext context; 8512 LocalContext context;
8513 v8::HandleScope handle_scope(context->GetIsolate());
8514 8514
8515 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 8515 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
8516 instance_template->SetCallAsFunctionHandler(ConstructorCallback); 8516 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
8517 Local<Object> instance = instance_template->NewInstance(); 8517 Local<Object> instance = instance_template->NewInstance();
8518 context->Global()->Set(v8_str("obj"), instance); 8518 context->Global()->Set(v8_str("obj"), instance);
8519 v8::TryCatch try_catch; 8519 v8::TryCatch try_catch;
8520 Local<Value> value; 8520 Local<Value> value;
8521 CHECK(!try_catch.HasCaught()); 8521 CHECK(!try_catch.HasCaught());
8522 8522
8523 // Call the Object's constructor with a 32-bit signed integer. 8523 // Call the Object's constructor with a 32-bit signed integer.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
8669 8669
8670 Local<Value> args2[] = { v8_num(28) }; 8670 Local<Value> args2[] = { v8_num(28) };
8671 value = instance2->CallAsConstructor(1, args2); 8671 value = instance2->CallAsConstructor(1, args2);
8672 CHECK(!try_catch.HasCaught()); 8672 CHECK(!try_catch.HasCaught());
8673 CHECK(!value->IsObject()); 8673 CHECK(!value->IsObject());
8674 } 8674 }
8675 } 8675 }
8676 8676
8677 8677
8678 THREADED_TEST(FunctionDescriptorException) { 8678 THREADED_TEST(FunctionDescriptorException) {
8679 v8::HandleScope handle_scope;
8680 LocalContext context; 8679 LocalContext context;
8680 v8::HandleScope handle_scope(context->GetIsolate());
8681 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 8681 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
8682 templ->SetClassName(v8_str("Fun")); 8682 templ->SetClassName(v8_str("Fun"));
8683 Local<Function> cons = templ->GetFunction(); 8683 Local<Function> cons = templ->GetFunction();
8684 context->Global()->Set(v8_str("Fun"), cons); 8684 context->Global()->Set(v8_str("Fun"), cons);
8685 Local<Value> value = CompileRun( 8685 Local<Value> value = CompileRun(
8686 "function test() {" 8686 "function test() {"
8687 " try {" 8687 " try {"
8688 " (new Fun()).blah()" 8688 " (new Fun()).blah()"
8689 " } catch (e) {" 8689 " } catch (e) {"
8690 " var str = String(e);" 8690 " var str = String(e);"
8691 " if (str.indexOf('TypeError') == -1) return 1;" 8691 " if (str.indexOf('TypeError') == -1) return 1;"
8692 " if (str.indexOf('[object Fun]') != -1) return 2;" 8692 " if (str.indexOf('[object Fun]') != -1) return 2;"
8693 " if (str.indexOf('#<Fun>') == -1) return 3;" 8693 " if (str.indexOf('#<Fun>') == -1) return 3;"
8694 " return 0;" 8694 " return 0;"
8695 " }" 8695 " }"
8696 " return 4;" 8696 " return 4;"
8697 "}" 8697 "}"
8698 "test();"); 8698 "test();");
8699 CHECK_EQ(0, value->Int32Value()); 8699 CHECK_EQ(0, value->Int32Value());
8700 } 8700 }
8701 8701
8702 8702
8703 THREADED_TEST(EvalAliasedDynamic) { 8703 THREADED_TEST(EvalAliasedDynamic) {
8704 v8::HandleScope scope;
8705 LocalContext current; 8704 LocalContext current;
8705 v8::HandleScope scope(current->GetIsolate());
8706 8706
8707 // Tests where aliased eval can only be resolved dynamically. 8707 // Tests where aliased eval can only be resolved dynamically.
8708 Local<Script> script = 8708 Local<Script> script =
8709 Script::Compile(v8_str("function f(x) { " 8709 Script::Compile(v8_str("function f(x) { "
8710 " var foo = 2;" 8710 " var foo = 2;"
8711 " with (x) { return eval('foo'); }" 8711 " with (x) { return eval('foo'); }"
8712 "}" 8712 "}"
8713 "foo = 0;" 8713 "foo = 0;"
8714 "result1 = f(new Object());" 8714 "result1 = f(new Object());"
8715 "result2 = f(this);" 8715 "result2 = f(this);"
(...skipping 14 matching lines...) Expand all
8730 "result4 = f(this)")); 8730 "result4 = f(this)"));
8731 script->Run(); 8731 script->Run();
8732 CHECK(!try_catch.HasCaught()); 8732 CHECK(!try_catch.HasCaught());
8733 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); 8733 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value());
8734 8734
8735 try_catch.Reset(); 8735 try_catch.Reset();
8736 } 8736 }
8737 8737
8738 8738
8739 THREADED_TEST(CrossEval) { 8739 THREADED_TEST(CrossEval) {
8740 v8::HandleScope scope; 8740 v8::HandleScope scope(v8::Isolate::GetCurrent());
8741 LocalContext other; 8741 LocalContext other;
8742 LocalContext current; 8742 LocalContext current;
8743 8743
8744 Local<String> token = v8_str("<security token>"); 8744 Local<String> token = v8_str("<security token>");
8745 other->SetSecurityToken(token); 8745 other->SetSecurityToken(token);
8746 current->SetSecurityToken(token); 8746 current->SetSecurityToken(token);
8747 8747
8748 // Set up reference from current to other. 8748 // Set up reference from current to other.
8749 current->Global()->Set(v8_str("other"), other->Global()); 8749 current->Global()->Set(v8_str("other"), other->Global());
8750 8750
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
8813 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); 8813 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
8814 result = script->Run(); 8814 result = script->Run();
8815 CHECK(try_catch.HasCaught()); 8815 CHECK(try_catch.HasCaught());
8816 } 8816 }
8817 8817
8818 8818
8819 // Test that calling eval in a context which has been detached from 8819 // Test that calling eval in a context which has been detached from
8820 // its global throws an exception. This behavior is consistent with 8820 // its global throws an exception. This behavior is consistent with
8821 // other JavaScript implementations. 8821 // other JavaScript implementations.
8822 THREADED_TEST(EvalInDetachedGlobal) { 8822 THREADED_TEST(EvalInDetachedGlobal) {
8823 v8::HandleScope scope; 8823 v8::HandleScope scope(v8::Isolate::GetCurrent());
8824 8824
8825 v8::Persistent<Context> context0 = Context::New(); 8825 v8::Persistent<Context> context0 = Context::New();
8826 v8::Persistent<Context> context1 = Context::New(); 8826 v8::Persistent<Context> context1 = Context::New();
8827 8827
8828 // Set up function in context0 that uses eval from context0. 8828 // Set up function in context0 that uses eval from context0.
8829 context0->Enter(); 8829 context0->Enter();
8830 v8::Handle<v8::Value> fun = 8830 v8::Handle<v8::Value> fun =
8831 CompileRun("var x = 42;" 8831 CompileRun("var x = 42;"
8832 "(function() {" 8832 "(function() {"
8833 " var e = eval;" 8833 " var e = eval;"
(...skipping 14 matching lines...) Expand all
8848 CHECK(x_value.IsEmpty()); 8848 CHECK(x_value.IsEmpty());
8849 CHECK(catcher.HasCaught()); 8849 CHECK(catcher.HasCaught());
8850 context1->Exit(); 8850 context1->Exit();
8851 8851
8852 context1.Dispose(context1->GetIsolate()); 8852 context1.Dispose(context1->GetIsolate());
8853 context0.Dispose(context0->GetIsolate()); 8853 context0.Dispose(context0->GetIsolate());
8854 } 8854 }
8855 8855
8856 8856
8857 THREADED_TEST(CrossLazyLoad) { 8857 THREADED_TEST(CrossLazyLoad) {
8858 v8::HandleScope scope; 8858 v8::HandleScope scope(v8::Isolate::GetCurrent());
8859 LocalContext other; 8859 LocalContext other;
8860 LocalContext current; 8860 LocalContext current;
8861 8861
8862 Local<String> token = v8_str("<security token>"); 8862 Local<String> token = v8_str("<security token>");
8863 other->SetSecurityToken(token); 8863 other->SetSecurityToken(token);
8864 current->SetSecurityToken(token); 8864 current->SetSecurityToken(token);
8865 8865
8866 // Set up reference from current to other. 8866 // Set up reference from current to other.
8867 current->Global()->Set(v8_str("other"), other->Global()); 8867 current->Global()->Set(v8_str("other"), other->Global());
8868 8868
(...skipping 14 matching lines...) Expand all
8883 } 8883 }
8884 8884
8885 return args[0]; 8885 return args[0];
8886 } 8886 }
8887 8887
8888 8888
8889 // Test that a call handler can be set for objects which will allow 8889 // Test that a call handler can be set for objects which will allow
8890 // non-function objects created through the API to be called as 8890 // non-function objects created through the API to be called as
8891 // functions. 8891 // functions.
8892 THREADED_TEST(CallAsFunction) { 8892 THREADED_TEST(CallAsFunction) {
8893 v8::HandleScope scope;
8894 LocalContext context; 8893 LocalContext context;
8894 v8::HandleScope scope(context->GetIsolate());
8895 8895
8896 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8896 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8897 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8897 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8898 instance_template->SetCallAsFunctionHandler(call_as_function); 8898 instance_template->SetCallAsFunctionHandler(call_as_function);
8899 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 8899 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8900 context->Global()->Set(v8_str("obj"), instance); 8900 context->Global()->Set(v8_str("obj"), instance);
8901 v8::TryCatch try_catch; 8901 v8::TryCatch try_catch;
8902 Local<Value> value; 8902 Local<Value> value;
8903 CHECK(!try_catch.HasCaught()); 8903 CHECK(!try_catch.HasCaught());
8904 8904
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
8996 CHECK(try_catch.HasCaught()); 8996 CHECK(try_catch.HasCaught());
8997 String::AsciiValue exception_value2(try_catch.Exception()); 8997 String::AsciiValue exception_value2(try_catch.Exception());
8998 CHECK_EQ("23", *exception_value2); 8998 CHECK_EQ("23", *exception_value2);
8999 try_catch.Reset(); 8999 try_catch.Reset();
9000 } 9000 }
9001 } 9001 }
9002 9002
9003 9003
9004 // Check whether a non-function object is callable. 9004 // Check whether a non-function object is callable.
9005 THREADED_TEST(CallableObject) { 9005 THREADED_TEST(CallableObject) {
9006 v8::HandleScope scope;
9007 LocalContext context; 9006 LocalContext context;
9007 v8::HandleScope scope(context->GetIsolate());
9008 9008
9009 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 9009 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
9010 instance_template->SetCallAsFunctionHandler(call_as_function); 9010 instance_template->SetCallAsFunctionHandler(call_as_function);
9011 Local<Object> instance = instance_template->NewInstance(); 9011 Local<Object> instance = instance_template->NewInstance();
9012 v8::TryCatch try_catch; 9012 v8::TryCatch try_catch;
9013 9013
9014 CHECK(instance->IsCallable()); 9014 CHECK(instance->IsCallable());
9015 CHECK(!try_catch.HasCaught()); 9015 CHECK(!try_catch.HasCaught());
9016 } 9016 }
9017 9017
(...skipping 25 matching lines...) Expand all
9043 } 9043 }
9044 } 9044 }
9045 9045
9046 9046
9047 static int CountHandles() { 9047 static int CountHandles() {
9048 return v8::HandleScope::NumberOfHandles(); 9048 return v8::HandleScope::NumberOfHandles();
9049 } 9049 }
9050 9050
9051 9051
9052 static int Recurse(int depth, int iterations) { 9052 static int Recurse(int depth, int iterations) {
9053 v8::HandleScope scope; 9053 v8::HandleScope scope(v8::Isolate::GetCurrent());
9054 if (depth == 0) return CountHandles(); 9054 if (depth == 0) return CountHandles();
9055 for (int i = 0; i < iterations; i++) { 9055 for (int i = 0; i < iterations; i++) {
9056 Local<v8::Number> n(v8::Integer::New(42)); 9056 Local<v8::Number> n(v8::Integer::New(42));
9057 } 9057 }
9058 return Recurse(depth - 1, iterations); 9058 return Recurse(depth - 1, iterations);
9059 } 9059 }
9060 9060
9061 9061
9062 THREADED_TEST(HandleIteration) { 9062 THREADED_TEST(HandleIteration) {
9063 static const int kIterations = 500; 9063 static const int kIterations = 500;
9064 static const int kNesting = 200; 9064 static const int kNesting = 200;
9065 CHECK_EQ(0, CountHandles()); 9065 CHECK_EQ(0, CountHandles());
9066 { 9066 {
9067 v8::HandleScope scope1; 9067 v8::HandleScope scope1(v8::Isolate::GetCurrent());
9068 CHECK_EQ(0, CountHandles()); 9068 CHECK_EQ(0, CountHandles());
9069 for (int i = 0; i < kIterations; i++) { 9069 for (int i = 0; i < kIterations; i++) {
9070 Local<v8::Number> n(v8::Integer::New(42)); 9070 Local<v8::Number> n(v8::Integer::New(42));
9071 CHECK_EQ(i + 1, CountHandles()); 9071 CHECK_EQ(i + 1, CountHandles());
9072 } 9072 }
9073 9073
9074 CHECK_EQ(kIterations, CountHandles()); 9074 CHECK_EQ(kIterations, CountHandles());
9075 { 9075 {
9076 v8::HandleScope scope2; 9076 v8::HandleScope scope2(v8::Isolate::GetCurrent());
9077 for (int j = 0; j < kIterations; j++) { 9077 for (int j = 0; j < kIterations; j++) {
9078 Local<v8::Number> n(v8::Integer::New(42)); 9078 Local<v8::Number> n(v8::Integer::New(42));
9079 CHECK_EQ(j + 1 + kIterations, CountHandles()); 9079 CHECK_EQ(j + 1 + kIterations, CountHandles());
9080 } 9080 }
9081 } 9081 }
9082 CHECK_EQ(kIterations, CountHandles()); 9082 CHECK_EQ(kIterations, CountHandles());
9083 } 9083 }
9084 CHECK_EQ(0, CountHandles()); 9084 CHECK_EQ(0, CountHandles());
9085 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 9085 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
9086 } 9086 }
9087 9087
9088 9088
9089 static v8::Handle<Value> InterceptorHasOwnPropertyGetter( 9089 static v8::Handle<Value> InterceptorHasOwnPropertyGetter(
9090 Local<String> name, 9090 Local<String> name,
9091 const AccessorInfo& info) { 9091 const AccessorInfo& info) {
9092 ApiTestFuzzer::Fuzz(); 9092 ApiTestFuzzer::Fuzz();
9093 return v8::Handle<Value>(); 9093 return v8::Handle<Value>();
9094 } 9094 }
9095 9095
9096 9096
9097 THREADED_TEST(InterceptorHasOwnProperty) { 9097 THREADED_TEST(InterceptorHasOwnProperty) {
9098 v8::HandleScope scope;
9099 LocalContext context; 9098 LocalContext context;
9099 v8::HandleScope scope(context->GetIsolate());
9100 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9100 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9101 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9101 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9102 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); 9102 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
9103 Local<Function> function = fun_templ->GetFunction(); 9103 Local<Function> function = fun_templ->GetFunction();
9104 context->Global()->Set(v8_str("constructor"), function); 9104 context->Global()->Set(v8_str("constructor"), function);
9105 v8::Handle<Value> value = CompileRun( 9105 v8::Handle<Value> value = CompileRun(
9106 "var o = new constructor();" 9106 "var o = new constructor();"
9107 "o.hasOwnProperty('ostehaps');"); 9107 "o.hasOwnProperty('ostehaps');");
9108 CHECK_EQ(false, value->BooleanValue()); 9108 CHECK_EQ(false, value->BooleanValue());
9109 value = CompileRun( 9109 value = CompileRun(
(...skipping 10 matching lines...) Expand all
9120 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC( 9120 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC(
9121 Local<String> name, 9121 Local<String> name,
9122 const AccessorInfo& info) { 9122 const AccessorInfo& info) {
9123 ApiTestFuzzer::Fuzz(); 9123 ApiTestFuzzer::Fuzz();
9124 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 9124 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
9125 return v8::Handle<Value>(); 9125 return v8::Handle<Value>();
9126 } 9126 }
9127 9127
9128 9128
9129 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 9129 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
9130 v8::HandleScope scope;
9131 LocalContext context; 9130 LocalContext context;
9131 v8::HandleScope scope(context->GetIsolate());
9132 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9132 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9133 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9133 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9134 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); 9134 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
9135 Local<Function> function = fun_templ->GetFunction(); 9135 Local<Function> function = fun_templ->GetFunction();
9136 context->Global()->Set(v8_str("constructor"), function); 9136 context->Global()->Set(v8_str("constructor"), function);
9137 // Let's first make some stuff so we can be sure to get a good GC. 9137 // Let's first make some stuff so we can be sure to get a good GC.
9138 CompileRun( 9138 CompileRun(
9139 "function makestr(size) {" 9139 "function makestr(size) {"
9140 " switch (size) {" 9140 " switch (size) {"
9141 " case 1: return 'f';" 9141 " case 1: return 'f';"
(...skipping 13 matching lines...) Expand all
9155 } 9155 }
9156 9156
9157 9157
9158 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property, 9158 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property,
9159 const AccessorInfo& info); 9159 const AccessorInfo& info);
9160 9160
9161 9161
9162 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, 9162 static void CheckInterceptorLoadIC(NamedPropertyGetter getter,
9163 const char* source, 9163 const char* source,
9164 int expected) { 9164 int expected) {
9165 v8::HandleScope scope; 9165 v8::HandleScope scope(v8::Isolate::GetCurrent());
9166 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9166 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9167 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); 9167 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data"));
9168 LocalContext context; 9168 LocalContext context;
9169 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9169 context->Global()->Set(v8_str("o"), templ->NewInstance());
9170 v8::Handle<Value> value = CompileRun(source); 9170 v8::Handle<Value> value = CompileRun(source);
9171 CHECK_EQ(expected, value->Int32Value()); 9171 CHECK_EQ(expected, value->Int32Value());
9172 } 9172 }
9173 9173
9174 9174
9175 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, 9175 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
9364 9364
9365 9365
9366 static void SetOnThis(Local<String> name, 9366 static void SetOnThis(Local<String> name,
9367 Local<Value> value, 9367 Local<Value> value,
9368 const AccessorInfo& info) { 9368 const AccessorInfo& info) {
9369 info.This()->ForceSet(name, value); 9369 info.This()->ForceSet(name, value);
9370 } 9370 }
9371 9371
9372 9372
9373 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { 9373 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) {
9374 v8::HandleScope scope; 9374 v8::HandleScope scope(v8::Isolate::GetCurrent());
9375 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9375 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9376 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9376 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9377 templ->SetAccessor(v8_str("y"), Return239); 9377 templ->SetAccessor(v8_str("y"), Return239);
9378 LocalContext context; 9378 LocalContext context;
9379 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9379 context->Global()->Set(v8_str("o"), templ->NewInstance());
9380 9380
9381 // Check the case when receiver and interceptor's holder 9381 // Check the case when receiver and interceptor's holder
9382 // are the same objects. 9382 // are the same objects.
9383 v8::Handle<Value> value = CompileRun( 9383 v8::Handle<Value> value = CompileRun(
9384 "var result = 0;" 9384 "var result = 0;"
9385 "for (var i = 0; i < 7; i++) {" 9385 "for (var i = 0; i < 7; i++) {"
9386 " result = o.y;" 9386 " result = o.y;"
9387 "}"); 9387 "}");
9388 CHECK_EQ(239, value->Int32Value()); 9388 CHECK_EQ(239, value->Int32Value());
9389 9389
9390 // Check the case when interceptor's holder is in proto chain 9390 // Check the case when interceptor's holder is in proto chain
9391 // of receiver. 9391 // of receiver.
9392 value = CompileRun( 9392 value = CompileRun(
9393 "r = { __proto__: o };" 9393 "r = { __proto__: o };"
9394 "var result = 0;" 9394 "var result = 0;"
9395 "for (var i = 0; i < 7; i++) {" 9395 "for (var i = 0; i < 7; i++) {"
9396 " result = r.y;" 9396 " result = r.y;"
9397 "}"); 9397 "}");
9398 CHECK_EQ(239, value->Int32Value()); 9398 CHECK_EQ(239, value->Int32Value());
9399 } 9399 }
9400 9400
9401 9401
9402 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { 9402 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) {
9403 v8::HandleScope scope; 9403 v8::HandleScope scope(v8::Isolate::GetCurrent());
9404 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9404 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9405 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9405 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9406 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9406 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9407 templ_p->SetAccessor(v8_str("y"), Return239); 9407 templ_p->SetAccessor(v8_str("y"), Return239);
9408 9408
9409 LocalContext context; 9409 LocalContext context;
9410 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9410 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9411 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9411 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9412 9412
9413 // Check the case when receiver and interceptor's holder 9413 // Check the case when receiver and interceptor's holder
(...skipping 12 matching lines...) Expand all
9426 "r = { __proto__: o };" 9426 "r = { __proto__: o };"
9427 "var result = 0;" 9427 "var result = 0;"
9428 "for (var i = 0; i < 7; i++) {" 9428 "for (var i = 0; i < 7; i++) {"
9429 " result = r.x + r.y;" 9429 " result = r.x + r.y;"
9430 "}"); 9430 "}");
9431 CHECK_EQ(239 + 42, value->Int32Value()); 9431 CHECK_EQ(239 + 42, value->Int32Value());
9432 } 9432 }
9433 9433
9434 9434
9435 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { 9435 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) {
9436 v8::HandleScope scope; 9436 v8::HandleScope scope(v8::Isolate::GetCurrent());
9437 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9437 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9438 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9438 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9439 templ->SetAccessor(v8_str("y"), Return239); 9439 templ->SetAccessor(v8_str("y"), Return239);
9440 9440
9441 LocalContext context; 9441 LocalContext context;
9442 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9442 context->Global()->Set(v8_str("o"), templ->NewInstance());
9443 9443
9444 v8::Handle<Value> value = CompileRun( 9444 v8::Handle<Value> value = CompileRun(
9445 "fst = new Object(); fst.__proto__ = o;" 9445 "fst = new Object(); fst.__proto__ = o;"
9446 "snd = new Object(); snd.__proto__ = fst;" 9446 "snd = new Object(); snd.__proto__ = fst;"
9447 "var result1 = 0;" 9447 "var result1 = 0;"
9448 "for (var i = 0; i < 7; i++) {" 9448 "for (var i = 0; i < 7; i++) {"
9449 " result1 = snd.x;" 9449 " result1 = snd.x;"
9450 "}" 9450 "}"
9451 "fst.x = 239;" 9451 "fst.x = 239;"
9452 "var result = 0;" 9452 "var result = 0;"
9453 "for (var i = 0; i < 7; i++) {" 9453 "for (var i = 0; i < 7; i++) {"
9454 " result = snd.x;" 9454 " result = snd.x;"
9455 "}" 9455 "}"
9456 "result + result1"); 9456 "result + result1");
9457 CHECK_EQ(239 + 42, value->Int32Value()); 9457 CHECK_EQ(239 + 42, value->Int32Value());
9458 } 9458 }
9459 9459
9460 9460
9461 // Test the case when we stored callback into 9461 // Test the case when we stored callback into
9462 // a stub, but interceptor produced value on its own. 9462 // a stub, but interceptor produced value on its own.
9463 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { 9463 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) {
9464 v8::HandleScope scope; 9464 v8::HandleScope scope(v8::Isolate::GetCurrent());
9465 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9465 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9466 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9466 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9467 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9467 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9468 templ_p->SetAccessor(v8_str("y"), Return239); 9468 templ_p->SetAccessor(v8_str("y"), Return239);
9469 9469
9470 LocalContext context; 9470 LocalContext context;
9471 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9471 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9472 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9472 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9473 9473
9474 v8::Handle<Value> value = CompileRun( 9474 v8::Handle<Value> value = CompileRun(
9475 "o.__proto__ = p;" 9475 "o.__proto__ = p;"
9476 "for (var i = 0; i < 7; i++) {" 9476 "for (var i = 0; i < 7; i++) {"
9477 " o.x;" 9477 " o.x;"
9478 // Now it should be ICed and keep a reference to x defined on p 9478 // Now it should be ICed and keep a reference to x defined on p
9479 "}" 9479 "}"
9480 "var result = 0;" 9480 "var result = 0;"
9481 "for (var i = 0; i < 7; i++) {" 9481 "for (var i = 0; i < 7; i++) {"
9482 " result += o.x;" 9482 " result += o.x;"
9483 "}" 9483 "}"
9484 "result"); 9484 "result");
9485 CHECK_EQ(42 * 7, value->Int32Value()); 9485 CHECK_EQ(42 * 7, value->Int32Value());
9486 } 9486 }
9487 9487
9488 9488
9489 // Test the case when we stored callback into 9489 // Test the case when we stored callback into
9490 // a stub, but it got invalidated later on. 9490 // a stub, but it got invalidated later on.
9491 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { 9491 THREADED_TEST(InterceptorLoadICInvalidatedCallback) {
9492 v8::HandleScope scope; 9492 v8::HandleScope scope(v8::Isolate::GetCurrent());
9493 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9493 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9494 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9494 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9495 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9495 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9496 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 9496 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis);
9497 9497
9498 LocalContext context; 9498 LocalContext context;
9499 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9499 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9500 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9500 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9501 9501
9502 v8::Handle<Value> value = CompileRun( 9502 v8::Handle<Value> value = CompileRun(
(...skipping 11 matching lines...) Expand all
9514 "}" 9514 "}"
9515 "result"); 9515 "result");
9516 CHECK_EQ(42 * 10, value->Int32Value()); 9516 CHECK_EQ(42 * 10, value->Int32Value());
9517 } 9517 }
9518 9518
9519 9519
9520 // Test the case when we stored callback into 9520 // Test the case when we stored callback into
9521 // a stub, but it got invalidated later on due to override on 9521 // a stub, but it got invalidated later on due to override on
9522 // global object which is between interceptor and callbacks' holders. 9522 // global object which is between interceptor and callbacks' holders.
9523 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { 9523 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) {
9524 v8::HandleScope scope; 9524 v8::HandleScope scope(v8::Isolate::GetCurrent());
9525 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9525 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9526 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9526 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9527 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9527 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9528 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 9528 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis);
9529 9529
9530 LocalContext context; 9530 LocalContext context;
9531 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9531 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9532 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9532 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9533 9533
9534 v8::Handle<Value> value = CompileRun( 9534 v8::Handle<Value> value = CompileRun(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9566 static v8::Handle<Value> InterceptorStoreICSetter( 9566 static v8::Handle<Value> InterceptorStoreICSetter(
9567 Local<String> key, Local<Value> value, const AccessorInfo&) { 9567 Local<String> key, Local<Value> value, const AccessorInfo&) {
9568 CHECK(v8_str("x")->Equals(key)); 9568 CHECK(v8_str("x")->Equals(key));
9569 CHECK_EQ(42, value->Int32Value()); 9569 CHECK_EQ(42, value->Int32Value());
9570 return value; 9570 return value;
9571 } 9571 }
9572 9572
9573 9573
9574 // This test should hit the store IC for the interceptor case. 9574 // This test should hit the store IC for the interceptor case.
9575 THREADED_TEST(InterceptorStoreIC) { 9575 THREADED_TEST(InterceptorStoreIC) {
9576 v8::HandleScope scope; 9576 v8::HandleScope scope(v8::Isolate::GetCurrent());
9577 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9577 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9578 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, 9578 templ->SetNamedPropertyHandler(InterceptorLoadICGetter,
9579 InterceptorStoreICSetter, 9579 InterceptorStoreICSetter,
9580 0, 0, 0, v8_str("data")); 9580 0, 0, 0, v8_str("data"));
9581 LocalContext context; 9581 LocalContext context;
9582 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9582 context->Global()->Set(v8_str("o"), templ->NewInstance());
9583 CompileRun( 9583 CompileRun(
9584 "for (var i = 0; i < 1000; i++) {" 9584 "for (var i = 0; i < 1000; i++) {"
9585 " o.x = 42;" 9585 " o.x = 42;"
9586 "}"); 9586 "}");
9587 } 9587 }
9588 9588
9589 9589
9590 THREADED_TEST(InterceptorStoreICWithNoSetter) { 9590 THREADED_TEST(InterceptorStoreICWithNoSetter) {
9591 v8::HandleScope scope; 9591 v8::HandleScope scope(v8::Isolate::GetCurrent());
9592 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9592 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9593 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9593 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9594 LocalContext context; 9594 LocalContext context;
9595 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9595 context->Global()->Set(v8_str("o"), templ->NewInstance());
9596 v8::Handle<Value> value = CompileRun( 9596 v8::Handle<Value> value = CompileRun(
9597 "for (var i = 0; i < 1000; i++) {" 9597 "for (var i = 0; i < 1000; i++) {"
9598 " o.y = 239;" 9598 " o.y = 239;"
9599 "}" 9599 "}"
9600 "42 + o.y"); 9600 "42 + o.y");
9601 CHECK_EQ(239 + 42, value->Int32Value()); 9601 CHECK_EQ(239 + 42, value->Int32Value());
9602 } 9602 }
9603 9603
9604 9604
9605 9605
9606 9606
9607 v8::Handle<Value> call_ic_function; 9607 v8::Handle<Value> call_ic_function;
9608 v8::Handle<Value> call_ic_function2; 9608 v8::Handle<Value> call_ic_function2;
9609 v8::Handle<Value> call_ic_function3; 9609 v8::Handle<Value> call_ic_function3;
9610 9610
9611 static v8::Handle<Value> InterceptorCallICGetter(Local<String> name, 9611 static v8::Handle<Value> InterceptorCallICGetter(Local<String> name,
9612 const AccessorInfo& info) { 9612 const AccessorInfo& info) {
9613 ApiTestFuzzer::Fuzz(); 9613 ApiTestFuzzer::Fuzz();
9614 CHECK(v8_str("x")->Equals(name)); 9614 CHECK(v8_str("x")->Equals(name));
9615 return call_ic_function; 9615 return call_ic_function;
9616 } 9616 }
9617 9617
9618 9618
9619 // This test should hit the call IC for the interceptor case. 9619 // This test should hit the call IC for the interceptor case.
9620 THREADED_TEST(InterceptorCallIC) { 9620 THREADED_TEST(InterceptorCallIC) {
9621 v8::HandleScope scope; 9621 v8::HandleScope scope(v8::Isolate::GetCurrent());
9622 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9622 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9623 templ->SetNamedPropertyHandler(InterceptorCallICGetter); 9623 templ->SetNamedPropertyHandler(InterceptorCallICGetter);
9624 LocalContext context; 9624 LocalContext context;
9625 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9625 context->Global()->Set(v8_str("o"), templ->NewInstance());
9626 call_ic_function = 9626 call_ic_function =
9627 v8_compile("function f(x) { return x + 1; }; f")->Run(); 9627 v8_compile("function f(x) { return x + 1; }; f")->Run();
9628 v8::Handle<Value> value = CompileRun( 9628 v8::Handle<Value> value = CompileRun(
9629 "var result = 0;" 9629 "var result = 0;"
9630 "for (var i = 0; i < 1000; i++) {" 9630 "for (var i = 0; i < 1000; i++) {"
9631 " result = o.x(41);" 9631 " result = o.x(41);"
9632 "}"); 9632 "}");
9633 CHECK_EQ(42, value->Int32Value()); 9633 CHECK_EQ(42, value->Int32Value());
9634 } 9634 }
9635 9635
9636 9636
9637 // This test checks that if interceptor doesn't provide 9637 // This test checks that if interceptor doesn't provide
9638 // a value, we can fetch regular value. 9638 // a value, we can fetch regular value.
9639 THREADED_TEST(InterceptorCallICSeesOthers) { 9639 THREADED_TEST(InterceptorCallICSeesOthers) {
9640 v8::HandleScope scope; 9640 v8::HandleScope scope(v8::Isolate::GetCurrent());
9641 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9641 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9642 templ->SetNamedPropertyHandler(NoBlockGetterX); 9642 templ->SetNamedPropertyHandler(NoBlockGetterX);
9643 LocalContext context; 9643 LocalContext context;
9644 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9644 context->Global()->Set(v8_str("o"), templ->NewInstance());
9645 v8::Handle<Value> value = CompileRun( 9645 v8::Handle<Value> value = CompileRun(
9646 "o.x = function f(x) { return x + 1; };" 9646 "o.x = function f(x) { return x + 1; };"
9647 "var result = 0;" 9647 "var result = 0;"
9648 "for (var i = 0; i < 7; i++) {" 9648 "for (var i = 0; i < 7; i++) {"
9649 " result = o.x(41);" 9649 " result = o.x(41);"
9650 "}"); 9650 "}");
9651 CHECK_EQ(42, value->Int32Value()); 9651 CHECK_EQ(42, value->Int32Value());
9652 } 9652 }
9653 9653
9654 9654
9655 static v8::Handle<Value> call_ic_function4; 9655 static v8::Handle<Value> call_ic_function4;
9656 static v8::Handle<Value> InterceptorCallICGetter4(Local<String> name, 9656 static v8::Handle<Value> InterceptorCallICGetter4(Local<String> name,
9657 const AccessorInfo& info) { 9657 const AccessorInfo& info) {
9658 ApiTestFuzzer::Fuzz(); 9658 ApiTestFuzzer::Fuzz();
9659 CHECK(v8_str("x")->Equals(name)); 9659 CHECK(v8_str("x")->Equals(name));
9660 return call_ic_function4; 9660 return call_ic_function4;
9661 } 9661 }
9662 9662
9663 9663
9664 // This test checks that if interceptor provides a function, 9664 // This test checks that if interceptor provides a function,
9665 // even if we cached shadowed variant, interceptor's function 9665 // even if we cached shadowed variant, interceptor's function
9666 // is invoked 9666 // is invoked
9667 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { 9667 THREADED_TEST(InterceptorCallICCacheableNotNeeded) {
9668 v8::HandleScope scope; 9668 v8::HandleScope scope(v8::Isolate::GetCurrent());
9669 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9669 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9670 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); 9670 templ->SetNamedPropertyHandler(InterceptorCallICGetter4);
9671 LocalContext context; 9671 LocalContext context;
9672 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9672 context->Global()->Set(v8_str("o"), templ->NewInstance());
9673 call_ic_function4 = 9673 call_ic_function4 =
9674 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9674 v8_compile("function f(x) { return x - 1; }; f")->Run();
9675 v8::Handle<Value> value = CompileRun( 9675 v8::Handle<Value> value = CompileRun(
9676 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" 9676 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };"
9677 "var result = 0;" 9677 "var result = 0;"
9678 "for (var i = 0; i < 1000; i++) {" 9678 "for (var i = 0; i < 1000; i++) {"
9679 " result = o.x(42);" 9679 " result = o.x(42);"
9680 "}"); 9680 "}");
9681 CHECK_EQ(41, value->Int32Value()); 9681 CHECK_EQ(41, value->Int32Value());
9682 } 9682 }
9683 9683
9684 9684
9685 // Test the case when we stored cacheable lookup into 9685 // Test the case when we stored cacheable lookup into
9686 // a stub, but it got invalidated later on 9686 // a stub, but it got invalidated later on
9687 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { 9687 THREADED_TEST(InterceptorCallICInvalidatedCacheable) {
9688 v8::HandleScope scope; 9688 v8::HandleScope scope(v8::Isolate::GetCurrent());
9689 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9689 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9690 templ->SetNamedPropertyHandler(NoBlockGetterX); 9690 templ->SetNamedPropertyHandler(NoBlockGetterX);
9691 LocalContext context; 9691 LocalContext context;
9692 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9692 context->Global()->Set(v8_str("o"), templ->NewInstance());
9693 v8::Handle<Value> value = CompileRun( 9693 v8::Handle<Value> value = CompileRun(
9694 "proto1 = new Object();" 9694 "proto1 = new Object();"
9695 "proto2 = new Object();" 9695 "proto2 = new Object();"
9696 "o.__proto__ = proto1;" 9696 "o.__proto__ = proto1;"
9697 "proto1.__proto__ = proto2;" 9697 "proto1.__proto__ = proto2;"
9698 "proto2.y = function(x) { return x + 1; };" 9698 "proto2.y = function(x) { return x + 1; };"
9699 // Invoke it many times to compile a stub 9699 // Invoke it many times to compile a stub
9700 "for (var i = 0; i < 7; i++) {" 9700 "for (var i = 0; i < 7; i++) {"
9701 " o.y(42);" 9701 " o.y(42);"
9702 "}" 9702 "}"
9703 "proto1.y = function(x) { return x - 1; };" 9703 "proto1.y = function(x) { return x - 1; };"
9704 "var result = 0;" 9704 "var result = 0;"
9705 "for (var i = 0; i < 7; i++) {" 9705 "for (var i = 0; i < 7; i++) {"
9706 " result += o.y(42);" 9706 " result += o.y(42);"
9707 "}"); 9707 "}");
9708 CHECK_EQ(41 * 7, value->Int32Value()); 9708 CHECK_EQ(41 * 7, value->Int32Value());
9709 } 9709 }
9710 9710
9711 9711
9712 // This test checks that if interceptor doesn't provide a function, 9712 // This test checks that if interceptor doesn't provide a function,
9713 // cached constant function is used 9713 // cached constant function is used
9714 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { 9714 THREADED_TEST(InterceptorCallICConstantFunctionUsed) {
9715 v8::HandleScope scope; 9715 v8::HandleScope scope(v8::Isolate::GetCurrent());
9716 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9716 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9717 templ->SetNamedPropertyHandler(NoBlockGetterX); 9717 templ->SetNamedPropertyHandler(NoBlockGetterX);
9718 LocalContext context; 9718 LocalContext context;
9719 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9719 context->Global()->Set(v8_str("o"), templ->NewInstance());
9720 v8::Handle<Value> value = CompileRun( 9720 v8::Handle<Value> value = CompileRun(
9721 "function inc(x) { return x + 1; };" 9721 "function inc(x) { return x + 1; };"
9722 "inc(1);" 9722 "inc(1);"
9723 "o.x = inc;" 9723 "o.x = inc;"
9724 "var result = 0;" 9724 "var result = 0;"
9725 "for (var i = 0; i < 1000; i++) {" 9725 "for (var i = 0; i < 1000; i++) {"
(...skipping 11 matching lines...) Expand all
9737 return call_ic_function5; 9737 return call_ic_function5;
9738 else 9738 else
9739 return Local<Value>(); 9739 return Local<Value>();
9740 } 9740 }
9741 9741
9742 9742
9743 // This test checks that if interceptor provides a function, 9743 // This test checks that if interceptor provides a function,
9744 // even if we cached constant function, interceptor's function 9744 // even if we cached constant function, interceptor's function
9745 // is invoked 9745 // is invoked
9746 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 9746 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
9747 v8::HandleScope scope; 9747 v8::HandleScope scope(v8::Isolate::GetCurrent());
9748 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9748 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9749 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 9749 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
9750 LocalContext context; 9750 LocalContext context;
9751 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9751 context->Global()->Set(v8_str("o"), templ->NewInstance());
9752 call_ic_function5 = 9752 call_ic_function5 =
9753 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9753 v8_compile("function f(x) { return x - 1; }; f")->Run();
9754 v8::Handle<Value> value = CompileRun( 9754 v8::Handle<Value> value = CompileRun(
9755 "function inc(x) { return x + 1; };" 9755 "function inc(x) { return x + 1; };"
9756 "inc(1);" 9756 "inc(1);"
9757 "o.x = inc;" 9757 "o.x = inc;"
(...skipping 13 matching lines...) Expand all
9771 return call_ic_function6; 9771 return call_ic_function6;
9772 else 9772 else
9773 return Local<Value>(); 9773 return Local<Value>();
9774 } 9774 }
9775 9775
9776 9776
9777 // Same test as above, except the code is wrapped in a function 9777 // Same test as above, except the code is wrapped in a function
9778 // to test the optimized compiler. 9778 // to test the optimized compiler.
9779 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { 9779 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
9780 i::FLAG_allow_natives_syntax = true; 9780 i::FLAG_allow_natives_syntax = true;
9781 v8::HandleScope scope; 9781 v8::HandleScope scope(v8::Isolate::GetCurrent());
9782 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9782 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9783 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); 9783 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
9784 LocalContext context; 9784 LocalContext context;
9785 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9785 context->Global()->Set(v8_str("o"), templ->NewInstance());
9786 call_ic_function6 = 9786 call_ic_function6 =
9787 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9787 v8_compile("function f(x) { return x - 1; }; f")->Run();
9788 v8::Handle<Value> value = CompileRun( 9788 v8::Handle<Value> value = CompileRun(
9789 "function inc(x) { return x + 1; };" 9789 "function inc(x) { return x + 1; };"
9790 "inc(1);" 9790 "inc(1);"
9791 "o.x = inc;" 9791 "o.x = inc;"
9792 "function test() {" 9792 "function test() {"
9793 " var result = 0;" 9793 " var result = 0;"
9794 " for (var i = 0; i < 1000; i++) {" 9794 " for (var i = 0; i < 1000; i++) {"
9795 " result = o.x(42);" 9795 " result = o.x(42);"
9796 " }" 9796 " }"
9797 " return result;" 9797 " return result;"
9798 "};" 9798 "};"
9799 "test();" 9799 "test();"
9800 "test();" 9800 "test();"
9801 "test();" 9801 "test();"
9802 "%OptimizeFunctionOnNextCall(test);" 9802 "%OptimizeFunctionOnNextCall(test);"
9803 "test()"); 9803 "test()");
9804 CHECK_EQ(41, value->Int32Value()); 9804 CHECK_EQ(41, value->Int32Value());
9805 } 9805 }
9806 9806
9807 9807
9808 // Test the case when we stored constant function into 9808 // Test the case when we stored constant function into
9809 // a stub, but it got invalidated later on 9809 // a stub, but it got invalidated later on
9810 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { 9810 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {
9811 v8::HandleScope scope; 9811 v8::HandleScope scope(v8::Isolate::GetCurrent());
9812 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9812 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9813 templ->SetNamedPropertyHandler(NoBlockGetterX); 9813 templ->SetNamedPropertyHandler(NoBlockGetterX);
9814 LocalContext context; 9814 LocalContext context;
9815 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9815 context->Global()->Set(v8_str("o"), templ->NewInstance());
9816 v8::Handle<Value> value = CompileRun( 9816 v8::Handle<Value> value = CompileRun(
9817 "function inc(x) { return x + 1; };" 9817 "function inc(x) { return x + 1; };"
9818 "inc(1);" 9818 "inc(1);"
9819 "proto1 = new Object();" 9819 "proto1 = new Object();"
9820 "proto2 = new Object();" 9820 "proto2 = new Object();"
9821 "o.__proto__ = proto1;" 9821 "o.__proto__ = proto1;"
9822 "proto1.__proto__ = proto2;" 9822 "proto1.__proto__ = proto2;"
9823 "proto2.y = inc;" 9823 "proto2.y = inc;"
9824 // Invoke it many times to compile a stub 9824 // Invoke it many times to compile a stub
9825 "for (var i = 0; i < 7; i++) {" 9825 "for (var i = 0; i < 7; i++) {"
9826 " o.y(42);" 9826 " o.y(42);"
9827 "}" 9827 "}"
9828 "proto1.y = function(x) { return x - 1; };" 9828 "proto1.y = function(x) { return x - 1; };"
9829 "var result = 0;" 9829 "var result = 0;"
9830 "for (var i = 0; i < 7; i++) {" 9830 "for (var i = 0; i < 7; i++) {"
9831 " result += o.y(42);" 9831 " result += o.y(42);"
9832 "}"); 9832 "}");
9833 CHECK_EQ(41 * 7, value->Int32Value()); 9833 CHECK_EQ(41 * 7, value->Int32Value());
9834 } 9834 }
9835 9835
9836 9836
9837 // Test the case when we stored constant function into 9837 // Test the case when we stored constant function into
9838 // a stub, but it got invalidated later on due to override on 9838 // a stub, but it got invalidated later on due to override on
9839 // global object which is between interceptor and constant function' holders. 9839 // global object which is between interceptor and constant function' holders.
9840 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { 9840 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) {
9841 v8::HandleScope scope; 9841 v8::HandleScope scope(v8::Isolate::GetCurrent());
9842 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9842 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9843 templ->SetNamedPropertyHandler(NoBlockGetterX); 9843 templ->SetNamedPropertyHandler(NoBlockGetterX);
9844 LocalContext context; 9844 LocalContext context;
9845 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9845 context->Global()->Set(v8_str("o"), templ->NewInstance());
9846 v8::Handle<Value> value = CompileRun( 9846 v8::Handle<Value> value = CompileRun(
9847 "function inc(x) { return x + 1; };" 9847 "function inc(x) { return x + 1; };"
9848 "inc(1);" 9848 "inc(1);"
9849 "o.__proto__ = this;" 9849 "o.__proto__ = this;"
9850 "this.__proto__.y = inc;" 9850 "this.__proto__.y = inc;"
9851 // Invoke it many times to compile a stub 9851 // Invoke it many times to compile a stub
9852 "for (var i = 0; i < 7; i++) {" 9852 "for (var i = 0; i < 7; i++) {"
9853 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" 9853 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
9854 "}" 9854 "}"
9855 "this.y = function(x) { return x - 1; };" 9855 "this.y = function(x) { return x - 1; };"
9856 "var result = 0;" 9856 "var result = 0;"
9857 "for (var i = 0; i < 7; i++) {" 9857 "for (var i = 0; i < 7; i++) {"
9858 " result += o.y(42);" 9858 " result += o.y(42);"
9859 "}"); 9859 "}");
9860 CHECK_EQ(41 * 7, value->Int32Value()); 9860 CHECK_EQ(41 * 7, value->Int32Value());
9861 } 9861 }
9862 9862
9863 9863
9864 // Test the case when actual function to call sits on global object. 9864 // Test the case when actual function to call sits on global object.
9865 THREADED_TEST(InterceptorCallICCachedFromGlobal) { 9865 THREADED_TEST(InterceptorCallICCachedFromGlobal) {
9866 v8::HandleScope scope; 9866 v8::HandleScope scope(v8::Isolate::GetCurrent());
9867 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9867 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9868 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 9868 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
9869 9869
9870 LocalContext context; 9870 LocalContext context;
9871 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9871 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9872 9872
9873 v8::Handle<Value> value = CompileRun( 9873 v8::Handle<Value> value = CompileRun(
9874 "try {" 9874 "try {"
9875 " o.__proto__ = this;" 9875 " o.__proto__ = this;"
9876 " for (var i = 0; i < 10; i++) {" 9876 " for (var i = 0; i < 10; i++) {"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
9940 if (count++ % 3 == 0) { 9940 if (count++ % 3 == 0) {
9941 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 9941 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
9942 // This should move the stub 9942 // This should move the stub
9943 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 9943 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
9944 } 9944 }
9945 return v8::Handle<v8::Value>(); 9945 return v8::Handle<v8::Value>();
9946 } 9946 }
9947 9947
9948 9948
9949 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 9949 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
9950 v8::HandleScope scope;
9951 LocalContext context; 9950 LocalContext context;
9951 v8::HandleScope scope(context->GetIsolate());
9952 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 9952 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
9953 nativeobject_templ->Set("callback", 9953 nativeobject_templ->Set("callback",
9954 v8::FunctionTemplate::New(DirectApiCallback)); 9954 v8::FunctionTemplate::New(DirectApiCallback));
9955 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 9955 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
9956 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 9956 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
9957 // call the api function multiple times to ensure direct call stub creation. 9957 // call the api function multiple times to ensure direct call stub creation.
9958 CompileRun( 9958 CompileRun(
9959 "function f() {" 9959 "function f() {"
9960 " for (var i = 1; i <= 30; i++) {" 9960 " for (var i = 1; i <= 30; i++) {"
9961 " nativeobject.callback();" 9961 " nativeobject.callback();"
9962 " }" 9962 " }"
9963 "}" 9963 "}"
9964 "f();"); 9964 "f();");
9965 } 9965 }
9966 9966
9967 9967
9968 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { 9968 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) {
9969 return v8::ThrowException(v8_str("g")); 9969 return v8::ThrowException(v8_str("g"));
9970 } 9970 }
9971 9971
9972 9972
9973 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 9973 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
9974 v8::HandleScope scope;
9975 LocalContext context; 9974 LocalContext context;
9975 v8::HandleScope scope(context->GetIsolate());
9976 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 9976 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
9977 nativeobject_templ->Set("callback", 9977 nativeobject_templ->Set("callback",
9978 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); 9978 v8::FunctionTemplate::New(ThrowingDirectApiCallback));
9979 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 9979 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
9980 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 9980 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
9981 // call the api function multiple times to ensure direct call stub creation. 9981 // call the api function multiple times to ensure direct call stub creation.
9982 v8::Handle<Value> result = CompileRun( 9982 v8::Handle<Value> result = CompileRun(
9983 "var result = '';" 9983 "var result = '';"
9984 "function f() {" 9984 "function f() {"
9985 " for (var i = 1; i <= 5; i++) {" 9985 " for (var i = 1; i <= 5; i++) {"
9986 " try { nativeobject.callback(); } catch (e) { result += e; }" 9986 " try { nativeobject.callback(); } catch (e) { result += e; }"
9987 " }" 9987 " }"
9988 "}" 9988 "}"
9989 "f(); result;"); 9989 "f(); result;");
9990 CHECK_EQ(v8_str("ggggg"), result); 9990 CHECK_EQ(v8_str("ggggg"), result);
9991 } 9991 }
9992 9992
9993 9993
9994 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name, 9994 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name,
9995 const v8::AccessorInfo& info) { 9995 const v8::AccessorInfo& info) {
9996 if (++p_getter_count % 3 == 0) { 9996 if (++p_getter_count % 3 == 0) {
9997 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 9997 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
9998 GenerateSomeGarbage(); 9998 GenerateSomeGarbage();
9999 } 9999 }
10000 return v8::Handle<v8::Value>(); 10000 return v8::Handle<v8::Value>();
10001 } 10001 }
10002 10002
10003 10003
10004 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 10004 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
10005 v8::HandleScope scope;
10006 LocalContext context; 10005 LocalContext context;
10006 v8::HandleScope scope(context->GetIsolate());
10007 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10007 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10008 obj->SetAccessor(v8_str("p1"), DirectGetterCallback); 10008 obj->SetAccessor(v8_str("p1"), DirectGetterCallback);
10009 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10009 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10010 p_getter_count = 0; 10010 p_getter_count = 0;
10011 CompileRun( 10011 CompileRun(
10012 "function f() {" 10012 "function f() {"
10013 " for (var i = 0; i < 30; i++) o1.p1;" 10013 " for (var i = 0; i < 30; i++) o1.p1;"
10014 "}" 10014 "}"
10015 "f();"); 10015 "f();");
10016 CHECK_EQ(30, p_getter_count); 10016 CHECK_EQ(30, p_getter_count);
10017 } 10017 }
10018 10018
10019 10019
10020 v8::Handle<v8::Value> ThrowingDirectGetterCallback( 10020 v8::Handle<v8::Value> ThrowingDirectGetterCallback(
10021 Local<String> name, const v8::AccessorInfo& info) { 10021 Local<String> name, const v8::AccessorInfo& info) {
10022 return v8::ThrowException(v8_str("g")); 10022 return v8::ThrowException(v8_str("g"));
10023 } 10023 }
10024 10024
10025 10025
10026 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 10026 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
10027 v8::HandleScope scope;
10028 LocalContext context; 10027 LocalContext context;
10028 v8::HandleScope scope(context->GetIsolate());
10029 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10029 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10030 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); 10030 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
10031 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10031 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10032 v8::Handle<Value> result = CompileRun( 10032 v8::Handle<Value> result = CompileRun(
10033 "var result = '';" 10033 "var result = '';"
10034 "for (var i = 0; i < 5; i++) {" 10034 "for (var i = 0; i < 5; i++) {"
10035 " try { o1.p1; } catch (e) { result += e; }" 10035 " try { o1.p1; } catch (e) { result += e; }"
10036 "}" 10036 "}"
10037 "result;"); 10037 "result;");
10038 CHECK_EQ(v8_str("ggggg"), result); 10038 CHECK_EQ(v8_str("ggggg"), result);
10039 } 10039 }
10040 10040
10041 10041
10042 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { 10042 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
10043 int interceptor_call_count = 0; 10043 int interceptor_call_count = 0;
10044 v8::HandleScope scope; 10044 v8::HandleScope scope(v8::Isolate::GetCurrent());
10045 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10045 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10046 v8::Handle<v8::FunctionTemplate> method_templ = 10046 v8::Handle<v8::FunctionTemplate> method_templ =
10047 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 10047 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
10048 v8_str("method_data"), 10048 v8_str("method_data"),
10049 v8::Handle<v8::Signature>()); 10049 v8::Handle<v8::Signature>());
10050 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10050 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10051 proto_templ->Set(v8_str("method"), method_templ); 10051 proto_templ->Set(v8_str("method"), method_templ);
10052 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10052 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10053 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10053 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
10054 NULL, NULL, NULL, NULL, 10054 NULL, NULL, NULL, NULL,
10055 v8::External::New(&interceptor_call_count)); 10055 v8::External::New(&interceptor_call_count));
10056 LocalContext context; 10056 LocalContext context;
10057 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10057 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10058 GenerateSomeGarbage(); 10058 GenerateSomeGarbage();
10059 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10059 context->Global()->Set(v8_str("o"), fun->NewInstance());
10060 CompileRun( 10060 CompileRun(
10061 "var result = 0;" 10061 "var result = 0;"
10062 "for (var i = 0; i < 100; i++) {" 10062 "for (var i = 0; i < 100; i++) {"
10063 " result = o.method(41);" 10063 " result = o.method(41);"
10064 "}"); 10064 "}");
10065 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10065 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10066 CHECK_EQ(100, interceptor_call_count); 10066 CHECK_EQ(100, interceptor_call_count);
10067 } 10067 }
10068 10068
10069 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { 10069 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) {
10070 int interceptor_call_count = 0; 10070 int interceptor_call_count = 0;
10071 v8::HandleScope scope; 10071 v8::HandleScope scope(v8::Isolate::GetCurrent());
10072 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10072 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10073 v8::Handle<v8::FunctionTemplate> method_templ = 10073 v8::Handle<v8::FunctionTemplate> method_templ =
10074 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10074 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10075 v8_str("method_data"), 10075 v8_str("method_data"),
10076 v8::Signature::New(fun_templ)); 10076 v8::Signature::New(fun_templ));
10077 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10077 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10078 proto_templ->Set(v8_str("method"), method_templ); 10078 proto_templ->Set(v8_str("method"), method_templ);
10079 fun_templ->SetHiddenPrototype(true); 10079 fun_templ->SetHiddenPrototype(true);
10080 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10080 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10081 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10081 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 10 matching lines...) Expand all
10092 "var result = 0;" 10092 "var result = 0;"
10093 "for (var i = 0; i < 100; i++) {" 10093 "for (var i = 0; i < 100; i++) {"
10094 " result = receiver.method(41);" 10094 " result = receiver.method(41);"
10095 "}"); 10095 "}");
10096 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10096 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10097 CHECK_EQ(100, interceptor_call_count); 10097 CHECK_EQ(100, interceptor_call_count);
10098 } 10098 }
10099 10099
10100 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 10100 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
10101 int interceptor_call_count = 0; 10101 int interceptor_call_count = 0;
10102 v8::HandleScope scope; 10102 v8::HandleScope scope(v8::Isolate::GetCurrent());
10103 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10103 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10104 v8::Handle<v8::FunctionTemplate> method_templ = 10104 v8::Handle<v8::FunctionTemplate> method_templ =
10105 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10105 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10106 v8_str("method_data"), 10106 v8_str("method_data"),
10107 v8::Signature::New(fun_templ)); 10107 v8::Signature::New(fun_templ));
10108 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10108 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10109 proto_templ->Set(v8_str("method"), method_templ); 10109 proto_templ->Set(v8_str("method"), method_templ);
10110 fun_templ->SetHiddenPrototype(true); 10110 fun_templ->SetHiddenPrototype(true);
10111 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10111 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10112 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10112 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 16 matching lines...) Expand all
10129 " receiver = {method: function(x) { return x - 1 }};" 10129 " receiver = {method: function(x) { return x - 1 }};"
10130 " }" 10130 " }"
10131 "}"); 10131 "}");
10132 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10132 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10133 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10133 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10134 CHECK_GE(interceptor_call_count, 50); 10134 CHECK_GE(interceptor_call_count, 50);
10135 } 10135 }
10136 10136
10137 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 10137 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
10138 int interceptor_call_count = 0; 10138 int interceptor_call_count = 0;
10139 v8::HandleScope scope; 10139 v8::HandleScope scope(v8::Isolate::GetCurrent());
10140 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10140 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10141 v8::Handle<v8::FunctionTemplate> method_templ = 10141 v8::Handle<v8::FunctionTemplate> method_templ =
10142 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10142 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10143 v8_str("method_data"), 10143 v8_str("method_data"),
10144 v8::Signature::New(fun_templ)); 10144 v8::Signature::New(fun_templ));
10145 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10145 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10146 proto_templ->Set(v8_str("method"), method_templ); 10146 proto_templ->Set(v8_str("method"), method_templ);
10147 fun_templ->SetHiddenPrototype(true); 10147 fun_templ->SetHiddenPrototype(true);
10148 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10148 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10149 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10149 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 16 matching lines...) Expand all
10166 " o.method = function(x) { return x - 1 };" 10166 " o.method = function(x) { return x - 1 };"
10167 " }" 10167 " }"
10168 "}"); 10168 "}");
10169 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10169 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10170 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10170 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10171 CHECK_GE(interceptor_call_count, 50); 10171 CHECK_GE(interceptor_call_count, 50);
10172 } 10172 }
10173 10173
10174 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 10174 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
10175 int interceptor_call_count = 0; 10175 int interceptor_call_count = 0;
10176 v8::HandleScope scope; 10176 v8::HandleScope scope(v8::Isolate::GetCurrent());
10177 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10177 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10178 v8::Handle<v8::FunctionTemplate> method_templ = 10178 v8::Handle<v8::FunctionTemplate> method_templ =
10179 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10179 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10180 v8_str("method_data"), 10180 v8_str("method_data"),
10181 v8::Signature::New(fun_templ)); 10181 v8::Signature::New(fun_templ));
10182 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10182 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10183 proto_templ->Set(v8_str("method"), method_templ); 10183 proto_templ->Set(v8_str("method"), method_templ);
10184 fun_templ->SetHiddenPrototype(true); 10184 fun_templ->SetHiddenPrototype(true);
10185 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10185 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10186 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10186 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 19 matching lines...) Expand all
10206 "}"); 10206 "}");
10207 CHECK(try_catch.HasCaught()); 10207 CHECK(try_catch.HasCaught());
10208 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 10208 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
10209 try_catch.Exception()->ToString()); 10209 try_catch.Exception()->ToString());
10210 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10210 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10211 CHECK_GE(interceptor_call_count, 50); 10211 CHECK_GE(interceptor_call_count, 50);
10212 } 10212 }
10213 10213
10214 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 10214 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
10215 int interceptor_call_count = 0; 10215 int interceptor_call_count = 0;
10216 v8::HandleScope scope; 10216 v8::HandleScope scope(v8::Isolate::GetCurrent());
10217 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10217 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10218 v8::Handle<v8::FunctionTemplate> method_templ = 10218 v8::Handle<v8::FunctionTemplate> method_templ =
10219 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10219 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10220 v8_str("method_data"), 10220 v8_str("method_data"),
10221 v8::Signature::New(fun_templ)); 10221 v8::Signature::New(fun_templ));
10222 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10222 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10223 proto_templ->Set(v8_str("method"), method_templ); 10223 proto_templ->Set(v8_str("method"), method_templ);
10224 fun_templ->SetHiddenPrototype(true); 10224 fun_templ->SetHiddenPrototype(true);
10225 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10225 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10226 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10226 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 18 matching lines...) Expand all
10245 " }" 10245 " }"
10246 "}"); 10246 "}");
10247 CHECK(try_catch.HasCaught()); 10247 CHECK(try_catch.HasCaught());
10248 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 10248 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
10249 try_catch.Exception()->ToString()); 10249 try_catch.Exception()->ToString());
10250 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10250 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10251 CHECK_GE(interceptor_call_count, 50); 10251 CHECK_GE(interceptor_call_count, 50);
10252 } 10252 }
10253 10253
10254 THREADED_TEST(CallICFastApi_TrivialSignature) { 10254 THREADED_TEST(CallICFastApi_TrivialSignature) {
10255 v8::HandleScope scope; 10255 v8::HandleScope scope(v8::Isolate::GetCurrent());
10256 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10256 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10257 v8::Handle<v8::FunctionTemplate> method_templ = 10257 v8::Handle<v8::FunctionTemplate> method_templ =
10258 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 10258 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
10259 v8_str("method_data"), 10259 v8_str("method_data"),
10260 v8::Handle<v8::Signature>()); 10260 v8::Handle<v8::Signature>());
10261 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10261 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10262 proto_templ->Set(v8_str("method"), method_templ); 10262 proto_templ->Set(v8_str("method"), method_templ);
10263 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10263 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10264 USE(templ); 10264 USE(templ);
10265 LocalContext context; 10265 LocalContext context;
10266 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10266 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10267 GenerateSomeGarbage(); 10267 GenerateSomeGarbage();
10268 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10268 context->Global()->Set(v8_str("o"), fun->NewInstance());
10269 CompileRun( 10269 CompileRun(
10270 "var result = 0;" 10270 "var result = 0;"
10271 "for (var i = 0; i < 100; i++) {" 10271 "for (var i = 0; i < 100; i++) {"
10272 " result = o.method(41);" 10272 " result = o.method(41);"
10273 "}"); 10273 "}");
10274 10274
10275 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10275 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10276 } 10276 }
10277 10277
10278 THREADED_TEST(CallICFastApi_SimpleSignature) { 10278 THREADED_TEST(CallICFastApi_SimpleSignature) {
10279 v8::HandleScope scope; 10279 v8::HandleScope scope(v8::Isolate::GetCurrent());
10280 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10280 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10281 v8::Handle<v8::FunctionTemplate> method_templ = 10281 v8::Handle<v8::FunctionTemplate> method_templ =
10282 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10282 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10283 v8_str("method_data"), 10283 v8_str("method_data"),
10284 v8::Signature::New(fun_templ)); 10284 v8::Signature::New(fun_templ));
10285 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10285 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10286 proto_templ->Set(v8_str("method"), method_templ); 10286 proto_templ->Set(v8_str("method"), method_templ);
10287 fun_templ->SetHiddenPrototype(true); 10287 fun_templ->SetHiddenPrototype(true);
10288 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10288 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10289 CHECK(!templ.IsEmpty()); 10289 CHECK(!templ.IsEmpty());
10290 LocalContext context; 10290 LocalContext context;
10291 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10291 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10292 GenerateSomeGarbage(); 10292 GenerateSomeGarbage();
10293 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10293 context->Global()->Set(v8_str("o"), fun->NewInstance());
10294 CompileRun( 10294 CompileRun(
10295 "o.foo = 17;" 10295 "o.foo = 17;"
10296 "var receiver = {};" 10296 "var receiver = {};"
10297 "receiver.__proto__ = o;" 10297 "receiver.__proto__ = o;"
10298 "var result = 0;" 10298 "var result = 0;"
10299 "for (var i = 0; i < 100; i++) {" 10299 "for (var i = 0; i < 100; i++) {"
10300 " result = receiver.method(41);" 10300 " result = receiver.method(41);"
10301 "}"); 10301 "}");
10302 10302
10303 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10303 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10304 } 10304 }
10305 10305
10306 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { 10306 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) {
10307 v8::HandleScope scope; 10307 v8::HandleScope scope(v8::Isolate::GetCurrent());
10308 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10308 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10309 v8::Handle<v8::FunctionTemplate> method_templ = 10309 v8::Handle<v8::FunctionTemplate> method_templ =
10310 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10310 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10311 v8_str("method_data"), 10311 v8_str("method_data"),
10312 v8::Signature::New(fun_templ)); 10312 v8::Signature::New(fun_templ));
10313 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10313 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10314 proto_templ->Set(v8_str("method"), method_templ); 10314 proto_templ->Set(v8_str("method"), method_templ);
10315 fun_templ->SetHiddenPrototype(true); 10315 fun_templ->SetHiddenPrototype(true);
10316 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10316 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10317 CHECK(!templ.IsEmpty()); 10317 CHECK(!templ.IsEmpty());
(...skipping 12 matching lines...) Expand all
10330 " if (i == 50) {" 10330 " if (i == 50) {"
10331 " saved_result = result;" 10331 " saved_result = result;"
10332 " receiver = {method: function(x) { return x - 1 }};" 10332 " receiver = {method: function(x) { return x - 1 }};"
10333 " }" 10333 " }"
10334 "}"); 10334 "}");
10335 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10335 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10336 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10336 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10337 } 10337 }
10338 10338
10339 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { 10339 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) {
10340 v8::HandleScope scope; 10340 v8::HandleScope scope(v8::Isolate::GetCurrent());
10341 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10341 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10342 v8::Handle<v8::FunctionTemplate> method_templ = 10342 v8::Handle<v8::FunctionTemplate> method_templ =
10343 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10343 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10344 v8_str("method_data"), 10344 v8_str("method_data"),
10345 v8::Signature::New(fun_templ)); 10345 v8::Signature::New(fun_templ));
10346 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10346 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10347 proto_templ->Set(v8_str("method"), method_templ); 10347 proto_templ->Set(v8_str("method"), method_templ);
10348 fun_templ->SetHiddenPrototype(true); 10348 fun_templ->SetHiddenPrototype(true);
10349 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10349 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10350 CHECK(!templ.IsEmpty()); 10350 CHECK(!templ.IsEmpty());
(...skipping 15 matching lines...) Expand all
10366 " receiver = 333;" 10366 " receiver = 333;"
10367 " }" 10367 " }"
10368 "}"); 10368 "}");
10369 CHECK(try_catch.HasCaught()); 10369 CHECK(try_catch.HasCaught());
10370 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 10370 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
10371 try_catch.Exception()->ToString()); 10371 try_catch.Exception()->ToString());
10372 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10372 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10373 } 10373 }
10374 10374
10375 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) { 10375 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) {
10376 v8::HandleScope scope; 10376 v8::HandleScope scope(v8::Isolate::GetCurrent());
10377 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10377 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10378 v8::Handle<v8::FunctionTemplate> method_templ = 10378 v8::Handle<v8::FunctionTemplate> method_templ =
10379 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10379 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10380 v8_str("method_data"), 10380 v8_str("method_data"),
10381 v8::Signature::New(fun_templ)); 10381 v8::Signature::New(fun_templ));
10382 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10382 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10383 proto_templ->Set(v8_str("method"), method_templ); 10383 proto_templ->Set(v8_str("method"), method_templ);
10384 fun_templ->SetHiddenPrototype(true); 10384 fun_templ->SetHiddenPrototype(true);
10385 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10385 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10386 CHECK(!templ.IsEmpty()); 10386 CHECK(!templ.IsEmpty());
(...skipping 30 matching lines...) Expand all
10417 if (v8_str("x")->Equals(name)) { 10417 if (v8_str("x")->Equals(name)) {
10418 return keyed_call_ic_function; 10418 return keyed_call_ic_function;
10419 } 10419 }
10420 return v8::Handle<Value>(); 10420 return v8::Handle<Value>();
10421 } 10421 }
10422 10422
10423 10423
10424 // Test the case when we stored cacheable lookup into 10424 // Test the case when we stored cacheable lookup into
10425 // a stub, but the function name changed (to another cacheable function). 10425 // a stub, but the function name changed (to another cacheable function).
10426 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { 10426 THREADED_TEST(InterceptorKeyedCallICKeyChange1) {
10427 v8::HandleScope scope; 10427 v8::HandleScope scope(v8::Isolate::GetCurrent());
10428 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10428 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10429 templ->SetNamedPropertyHandler(NoBlockGetterX); 10429 templ->SetNamedPropertyHandler(NoBlockGetterX);
10430 LocalContext context; 10430 LocalContext context;
10431 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10431 context->Global()->Set(v8_str("o"), templ->NewInstance());
10432 CompileRun( 10432 CompileRun(
10433 "proto = new Object();" 10433 "proto = new Object();"
10434 "proto.y = function(x) { return x + 1; };" 10434 "proto.y = function(x) { return x + 1; };"
10435 "proto.z = function(x) { return x - 1; };" 10435 "proto.z = function(x) { return x - 1; };"
10436 "o.__proto__ = proto;" 10436 "o.__proto__ = proto;"
10437 "var result = 0;" 10437 "var result = 0;"
10438 "var method = 'y';" 10438 "var method = 'y';"
10439 "for (var i = 0; i < 10; i++) {" 10439 "for (var i = 0; i < 10; i++) {"
10440 " if (i == 5) { method = 'z'; };" 10440 " if (i == 5) { method = 'z'; };"
10441 " result += o[method](41);" 10441 " result += o[method](41);"
10442 "}"); 10442 "}");
10443 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10443 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10444 } 10444 }
10445 10445
10446 10446
10447 // Test the case when we stored cacheable lookup into 10447 // Test the case when we stored cacheable lookup into
10448 // a stub, but the function name changed (and the new function is present 10448 // a stub, but the function name changed (and the new function is present
10449 // both before and after the interceptor in the prototype chain). 10449 // both before and after the interceptor in the prototype chain).
10450 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { 10450 THREADED_TEST(InterceptorKeyedCallICKeyChange2) {
10451 v8::HandleScope scope; 10451 v8::HandleScope scope(v8::Isolate::GetCurrent());
10452 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10452 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10453 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); 10453 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter);
10454 LocalContext context; 10454 LocalContext context;
10455 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); 10455 context->Global()->Set(v8_str("proto1"), templ->NewInstance());
10456 keyed_call_ic_function = 10456 keyed_call_ic_function =
10457 v8_compile("function f(x) { return x - 1; }; f")->Run(); 10457 v8_compile("function f(x) { return x - 1; }; f")->Run();
10458 CompileRun( 10458 CompileRun(
10459 "o = new Object();" 10459 "o = new Object();"
10460 "proto2 = new Object();" 10460 "proto2 = new Object();"
10461 "o.y = function(x) { return x + 1; };" 10461 "o.y = function(x) { return x + 1; };"
10462 "proto2.y = function(x) { return x + 2; };" 10462 "proto2.y = function(x) { return x + 2; };"
10463 "o.__proto__ = proto1;" 10463 "o.__proto__ = proto1;"
10464 "proto1.__proto__ = proto2;" 10464 "proto1.__proto__ = proto2;"
10465 "var result = 0;" 10465 "var result = 0;"
10466 "var method = 'x';" 10466 "var method = 'x';"
10467 "for (var i = 0; i < 10; i++) {" 10467 "for (var i = 0; i < 10; i++) {"
10468 " if (i == 5) { method = 'y'; };" 10468 " if (i == 5) { method = 'y'; };"
10469 " result += o[method](41);" 10469 " result += o[method](41);"
10470 "}"); 10470 "}");
10471 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10471 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10472 } 10472 }
10473 10473
10474 10474
10475 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit 10475 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit
10476 // on the global object. 10476 // on the global object.
10477 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { 10477 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) {
10478 v8::HandleScope scope; 10478 v8::HandleScope scope(v8::Isolate::GetCurrent());
10479 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10479 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10480 templ->SetNamedPropertyHandler(NoBlockGetterX); 10480 templ->SetNamedPropertyHandler(NoBlockGetterX);
10481 LocalContext context; 10481 LocalContext context;
10482 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10482 context->Global()->Set(v8_str("o"), templ->NewInstance());
10483 CompileRun( 10483 CompileRun(
10484 "function inc(x) { return x + 1; };" 10484 "function inc(x) { return x + 1; };"
10485 "inc(1);" 10485 "inc(1);"
10486 "function dec(x) { return x - 1; };" 10486 "function dec(x) { return x - 1; };"
10487 "dec(1);" 10487 "dec(1);"
10488 "o.__proto__ = this;" 10488 "o.__proto__ = this;"
10489 "this.__proto__.x = inc;" 10489 "this.__proto__.x = inc;"
10490 "this.__proto__.y = dec;" 10490 "this.__proto__.y = dec;"
10491 "var result = 0;" 10491 "var result = 0;"
10492 "var method = 'x';" 10492 "var method = 'x';"
10493 "for (var i = 0; i < 10; i++) {" 10493 "for (var i = 0; i < 10; i++) {"
10494 " if (i == 5) { method = 'y'; };" 10494 " if (i == 5) { method = 'y'; };"
10495 " result += o[method](41);" 10495 " result += o[method](41);"
10496 "}"); 10496 "}");
10497 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10497 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10498 } 10498 }
10499 10499
10500 10500
10501 // Test the case when actual function to call sits on global object. 10501 // Test the case when actual function to call sits on global object.
10502 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { 10502 THREADED_TEST(InterceptorKeyedCallICFromGlobal) {
10503 v8::HandleScope scope; 10503 v8::HandleScope scope(v8::Isolate::GetCurrent());
10504 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10504 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10505 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10505 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10506 LocalContext context; 10506 LocalContext context;
10507 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10507 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10508 10508
10509 CompileRun( 10509 CompileRun(
10510 "function len(x) { return x.length; };" 10510 "function len(x) { return x.length; };"
10511 "o.__proto__ = this;" 10511 "o.__proto__ = this;"
10512 "var m = 'parseFloat';" 10512 "var m = 'parseFloat';"
10513 "var result = 0;" 10513 "var result = 0;"
10514 "for (var i = 0; i < 10; i++) {" 10514 "for (var i = 0; i < 10; i++) {"
10515 " if (i == 5) {" 10515 " if (i == 5) {"
10516 " m = 'len';" 10516 " m = 'len';"
10517 " saved_result = result;" 10517 " saved_result = result;"
10518 " };" 10518 " };"
10519 " result = o[m]('239');" 10519 " result = o[m]('239');"
10520 "}"); 10520 "}");
10521 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); 10521 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value());
10522 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10522 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10523 } 10523 }
10524 10524
10525 // Test the map transition before the interceptor. 10525 // Test the map transition before the interceptor.
10526 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { 10526 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) {
10527 v8::HandleScope scope; 10527 v8::HandleScope scope(v8::Isolate::GetCurrent());
10528 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10528 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10529 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10529 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10530 LocalContext context; 10530 LocalContext context;
10531 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); 10531 context->Global()->Set(v8_str("proto"), templ_o->NewInstance());
10532 10532
10533 CompileRun( 10533 CompileRun(
10534 "var o = new Object();" 10534 "var o = new Object();"
10535 "o.__proto__ = proto;" 10535 "o.__proto__ = proto;"
10536 "o.method = function(x) { return x + 1; };" 10536 "o.method = function(x) { return x + 1; };"
10537 "var m = 'method';" 10537 "var m = 'method';"
10538 "var result = 0;" 10538 "var result = 0;"
10539 "for (var i = 0; i < 10; i++) {" 10539 "for (var i = 0; i < 10; i++) {"
10540 " if (i == 5) { o.method = function(x) { return x - 1; }; };" 10540 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
10541 " result += o[m](41);" 10541 " result += o[m](41);"
10542 "}"); 10542 "}");
10543 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10543 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10544 } 10544 }
10545 10545
10546 10546
10547 // Test the map transition after the interceptor. 10547 // Test the map transition after the interceptor.
10548 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { 10548 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) {
10549 v8::HandleScope scope; 10549 v8::HandleScope scope(v8::Isolate::GetCurrent());
10550 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10550 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10551 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10551 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10552 LocalContext context; 10552 LocalContext context;
10553 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10553 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10554 10554
10555 CompileRun( 10555 CompileRun(
10556 "var proto = new Object();" 10556 "var proto = new Object();"
10557 "o.__proto__ = proto;" 10557 "o.__proto__ = proto;"
10558 "proto.method = function(x) { return x + 1; };" 10558 "proto.method = function(x) { return x + 1; };"
10559 "var m = 'method';" 10559 "var m = 'method';"
(...skipping 15 matching lines...) Expand all
10575 return call_ic_function2; 10575 return call_ic_function2;
10576 } 10576 }
10577 return v8::Handle<Value>(); 10577 return v8::Handle<Value>();
10578 } 10578 }
10579 10579
10580 10580
10581 // This test should hit load and call ICs for the interceptor case. 10581 // This test should hit load and call ICs for the interceptor case.
10582 // Once in a while, the interceptor will reply that a property was not 10582 // Once in a while, the interceptor will reply that a property was not
10583 // found in which case we should get a reference error. 10583 // found in which case we should get a reference error.
10584 THREADED_TEST(InterceptorICReferenceErrors) { 10584 THREADED_TEST(InterceptorICReferenceErrors) {
10585 v8::HandleScope scope; 10585 v8::HandleScope scope(v8::Isolate::GetCurrent());
10586 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10586 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10587 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); 10587 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter);
10588 LocalContext context(0, templ, v8::Handle<Value>()); 10588 LocalContext context(0, templ, v8::Handle<Value>());
10589 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); 10589 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run();
10590 v8::Handle<Value> value = CompileRun( 10590 v8::Handle<Value> value = CompileRun(
10591 "function f() {" 10591 "function f() {"
10592 " for (var i = 0; i < 1000; i++) {" 10592 " for (var i = 0; i < 1000; i++) {"
10593 " try { x; } catch(e) { return true; }" 10593 " try { x; } catch(e) { return true; }"
10594 " }" 10594 " }"
10595 " return false;" 10595 " return false;"
(...skipping 26 matching lines...) Expand all
10622 return v8::ThrowException(v8_num(42)); 10622 return v8::ThrowException(v8_num(42));
10623 } 10623 }
10624 // Do not handle get for properties other than x. 10624 // Do not handle get for properties other than x.
10625 return v8::Handle<Value>(); 10625 return v8::Handle<Value>();
10626 } 10626 }
10627 10627
10628 // Test interceptor load/call IC where the interceptor throws an 10628 // Test interceptor load/call IC where the interceptor throws an
10629 // exception once in a while. 10629 // exception once in a while.
10630 THREADED_TEST(InterceptorICGetterExceptions) { 10630 THREADED_TEST(InterceptorICGetterExceptions) {
10631 interceptor_ic_exception_get_count = 0; 10631 interceptor_ic_exception_get_count = 0;
10632 v8::HandleScope scope; 10632 v8::HandleScope scope(v8::Isolate::GetCurrent());
10633 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10633 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10634 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); 10634 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter);
10635 LocalContext context(0, templ, v8::Handle<Value>()); 10635 LocalContext context(0, templ, v8::Handle<Value>());
10636 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); 10636 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run();
10637 v8::Handle<Value> value = CompileRun( 10637 v8::Handle<Value> value = CompileRun(
10638 "function f() {" 10638 "function f() {"
10639 " for (var i = 0; i < 100; i++) {" 10639 " for (var i = 0; i < 100; i++) {"
10640 " try { x; } catch(e) { return true; }" 10640 " try { x; } catch(e) { return true; }"
10641 " }" 10641 " }"
10642 " return false;" 10642 " return false;"
(...skipping 22 matching lines...) Expand all
10665 return v8::ThrowException(v8_num(42)); 10665 return v8::ThrowException(v8_num(42));
10666 } 10666 }
10667 // Do not actually handle setting. 10667 // Do not actually handle setting.
10668 return v8::Handle<Value>(); 10668 return v8::Handle<Value>();
10669 } 10669 }
10670 10670
10671 // Test interceptor store IC where the interceptor throws an exception 10671 // Test interceptor store IC where the interceptor throws an exception
10672 // once in a while. 10672 // once in a while.
10673 THREADED_TEST(InterceptorICSetterExceptions) { 10673 THREADED_TEST(InterceptorICSetterExceptions) {
10674 interceptor_ic_exception_set_count = 0; 10674 interceptor_ic_exception_set_count = 0;
10675 v8::HandleScope scope; 10675 v8::HandleScope scope(v8::Isolate::GetCurrent());
10676 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10676 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10677 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); 10677 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter);
10678 LocalContext context(0, templ, v8::Handle<Value>()); 10678 LocalContext context(0, templ, v8::Handle<Value>());
10679 v8::Handle<Value> value = CompileRun( 10679 v8::Handle<Value> value = CompileRun(
10680 "function f() {" 10680 "function f() {"
10681 " for (var i = 0; i < 100; i++) {" 10681 " for (var i = 0; i < 100; i++) {"
10682 " try { x = 42; } catch(e) { return true; }" 10682 " try { x = 42; } catch(e) { return true; }"
10683 " }" 10683 " }"
10684 " return false;" 10684 " return false;"
10685 "};" 10685 "};"
10686 "f();"); 10686 "f();");
10687 CHECK_EQ(true, value->BooleanValue()); 10687 CHECK_EQ(true, value->BooleanValue());
10688 } 10688 }
10689 10689
10690 10690
10691 // Test that we ignore null interceptors. 10691 // Test that we ignore null interceptors.
10692 THREADED_TEST(NullNamedInterceptor) { 10692 THREADED_TEST(NullNamedInterceptor) {
10693 v8::HandleScope scope; 10693 v8::HandleScope scope(v8::Isolate::GetCurrent());
10694 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10694 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10695 templ->SetNamedPropertyHandler(0); 10695 templ->SetNamedPropertyHandler(0);
10696 LocalContext context; 10696 LocalContext context;
10697 templ->Set("x", v8_num(42)); 10697 templ->Set("x", v8_num(42));
10698 v8::Handle<v8::Object> obj = templ->NewInstance(); 10698 v8::Handle<v8::Object> obj = templ->NewInstance();
10699 context->Global()->Set(v8_str("obj"), obj); 10699 context->Global()->Set(v8_str("obj"), obj);
10700 v8::Handle<Value> value = CompileRun("obj.x"); 10700 v8::Handle<Value> value = CompileRun("obj.x");
10701 CHECK(value->IsInt32()); 10701 CHECK(value->IsInt32());
10702 CHECK_EQ(42, value->Int32Value()); 10702 CHECK_EQ(42, value->Int32Value());
10703 } 10703 }
10704 10704
10705 10705
10706 // Test that we ignore null interceptors. 10706 // Test that we ignore null interceptors.
10707 THREADED_TEST(NullIndexedInterceptor) { 10707 THREADED_TEST(NullIndexedInterceptor) {
10708 v8::HandleScope scope; 10708 v8::HandleScope scope(v8::Isolate::GetCurrent());
10709 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10709 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10710 templ->SetIndexedPropertyHandler(0); 10710 templ->SetIndexedPropertyHandler(0);
10711 LocalContext context; 10711 LocalContext context;
10712 templ->Set("42", v8_num(42)); 10712 templ->Set("42", v8_num(42));
10713 v8::Handle<v8::Object> obj = templ->NewInstance(); 10713 v8::Handle<v8::Object> obj = templ->NewInstance();
10714 context->Global()->Set(v8_str("obj"), obj); 10714 context->Global()->Set(v8_str("obj"), obj);
10715 v8::Handle<Value> value = CompileRun("obj[42]"); 10715 v8::Handle<Value> value = CompileRun("obj[42]");
10716 CHECK(value->IsInt32()); 10716 CHECK(value->IsInt32());
10717 CHECK_EQ(42, value->Int32Value()); 10717 CHECK_EQ(42, value->Int32Value());
10718 } 10718 }
10719 10719
10720 10720
10721 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 10721 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
10722 v8::HandleScope scope; 10722 v8::HandleScope scope(v8::Isolate::GetCurrent());
10723 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10723 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10724 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10724 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10725 LocalContext env; 10725 LocalContext env;
10726 env->Global()->Set(v8_str("obj"), 10726 env->Global()->Set(v8_str("obj"),
10727 templ->GetFunction()->NewInstance()); 10727 templ->GetFunction()->NewInstance());
10728 ExpectTrue("obj.x === 42"); 10728 ExpectTrue("obj.x === 42");
10729 ExpectTrue("!obj.propertyIsEnumerable('x')"); 10729 ExpectTrue("!obj.propertyIsEnumerable('x')");
10730 } 10730 }
10731 10731
10732 10732
10733 static Handle<Value> ThrowingGetter(Local<String> name, 10733 static Handle<Value> ThrowingGetter(Local<String> name,
10734 const AccessorInfo& info) { 10734 const AccessorInfo& info) {
10735 ApiTestFuzzer::Fuzz(); 10735 ApiTestFuzzer::Fuzz();
10736 ThrowException(Handle<Value>()); 10736 ThrowException(Handle<Value>());
10737 return Undefined(); 10737 return Undefined();
10738 } 10738 }
10739 10739
10740 10740
10741 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 10741 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
10742 HandleScope scope;
10743 LocalContext context; 10742 LocalContext context;
10743 HandleScope scope(context->GetIsolate());
10744 10744
10745 Local<FunctionTemplate> templ = FunctionTemplate::New(); 10745 Local<FunctionTemplate> templ = FunctionTemplate::New();
10746 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 10746 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
10747 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 10747 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
10748 10748
10749 Local<Object> instance = templ->GetFunction()->NewInstance(); 10749 Local<Object> instance = templ->GetFunction()->NewInstance();
10750 10750
10751 Local<Object> another = Object::New(); 10751 Local<Object> another = Object::New();
10752 another->SetPrototype(instance); 10752 another->SetPrototype(instance);
10753 10753
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
10823 10823
10824 10824
10825 static void WebKitLike(Handle<Message> message, Handle<Value> data) { 10825 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
10826 Handle<String> errorMessageString = message->Get(); 10826 Handle<String> errorMessageString = message->Get();
10827 CHECK(!errorMessageString.IsEmpty()); 10827 CHECK(!errorMessageString.IsEmpty());
10828 message->GetStackTrace(); 10828 message->GetStackTrace();
10829 message->GetScriptResourceName(); 10829 message->GetScriptResourceName();
10830 } 10830 }
10831 10831
10832 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { 10832 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
10833 HandleScope scope;
10834 LocalContext context; 10833 LocalContext context;
10834 HandleScope scope(context->GetIsolate());
10835 10835
10836 Local<Function> func = 10836 Local<Function> func =
10837 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction(); 10837 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction();
10838 context->Global()->Set(v8_str("func"), func); 10838 context->Global()->Set(v8_str("func"), func);
10839 10839
10840 MessageCallback callbacks[] = 10840 MessageCallback callbacks[] =
10841 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; 10841 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
10842 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { 10842 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
10843 MessageCallback callback = callbacks[i]; 10843 MessageCallback callback = callbacks[i];
10844 if (callback != NULL) { 10844 if (callback != NULL) {
(...skipping 22 matching lines...) Expand all
10867 10867
10868 static v8::Handle<Value> ChildGetter(Local<String> name, 10868 static v8::Handle<Value> ChildGetter(Local<String> name,
10869 const AccessorInfo& info) { 10869 const AccessorInfo& info) {
10870 ApiTestFuzzer::Fuzz(); 10870 ApiTestFuzzer::Fuzz();
10871 return v8_num(42); 10871 return v8_num(42);
10872 } 10872 }
10873 10873
10874 10874
10875 THREADED_TEST(Overriding) { 10875 THREADED_TEST(Overriding) {
10876 i::FLAG_es5_readonly = true; 10876 i::FLAG_es5_readonly = true;
10877 v8::HandleScope scope;
10878 LocalContext context; 10877 LocalContext context;
10878 v8::HandleScope scope(context->GetIsolate());
10879 10879
10880 // Parent template. 10880 // Parent template.
10881 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); 10881 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New();
10882 Local<ObjectTemplate> parent_instance_templ = 10882 Local<ObjectTemplate> parent_instance_templ =
10883 parent_templ->InstanceTemplate(); 10883 parent_templ->InstanceTemplate();
10884 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); 10884 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter);
10885 10885
10886 // Template that inherits from the parent template. 10886 // Template that inherits from the parent template.
10887 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(); 10887 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New();
10888 Local<ObjectTemplate> child_instance_templ = 10888 Local<ObjectTemplate> child_instance_templ =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
10930 } 10930 }
10931 10931
10932 10932
10933 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) { 10933 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) {
10934 ApiTestFuzzer::Fuzz(); 10934 ApiTestFuzzer::Fuzz();
10935 return v8::Boolean::New(args.IsConstructCall()); 10935 return v8::Boolean::New(args.IsConstructCall());
10936 } 10936 }
10937 10937
10938 10938
10939 THREADED_TEST(IsConstructCall) { 10939 THREADED_TEST(IsConstructCall) {
10940 v8::HandleScope scope; 10940 v8::HandleScope scope(v8::Isolate::GetCurrent());
10941 10941
10942 // Function template with call handler. 10942 // Function template with call handler.
10943 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10943 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10944 templ->SetCallHandler(IsConstructHandler); 10944 templ->SetCallHandler(IsConstructHandler);
10945 10945
10946 LocalContext context; 10946 LocalContext context;
10947 10947
10948 context->Global()->Set(v8_str("f"), templ->GetFunction()); 10948 context->Global()->Set(v8_str("f"), templ->GetFunction());
10949 Local<Value> value = v8_compile("f()")->Run(); 10949 Local<Value> value = v8_compile("f()")->Run();
10950 CHECK(!value->BooleanValue()); 10950 CHECK(!value->BooleanValue());
10951 value = v8_compile("new f()")->Run(); 10951 value = v8_compile("new f()")->Run();
10952 CHECK(value->BooleanValue()); 10952 CHECK(value->BooleanValue());
10953 } 10953 }
10954 10954
10955 10955
10956 THREADED_TEST(ObjectProtoToString) { 10956 THREADED_TEST(ObjectProtoToString) {
10957 v8::HandleScope scope; 10957 v8::HandleScope scope(v8::Isolate::GetCurrent());
10958 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10958 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10959 templ->SetClassName(v8_str("MyClass")); 10959 templ->SetClassName(v8_str("MyClass"));
10960 10960
10961 LocalContext context; 10961 LocalContext context;
10962 10962
10963 Local<String> customized_tostring = v8_str("customized toString"); 10963 Local<String> customized_tostring = v8_str("customized toString");
10964 10964
10965 // Replace Object.prototype.toString 10965 // Replace Object.prototype.toString
10966 v8_compile("Object.prototype.toString = function() {" 10966 v8_compile("Object.prototype.toString = function() {"
10967 " return 'customized toString';" 10967 " return 'customized toString';"
(...skipping 13 matching lines...) Expand all
10981 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); 10981 CHECK(value->IsString() && value->Equals(v8_str("[object global]")));
10982 10982
10983 // Check ordinary object 10983 // Check ordinary object
10984 Local<Value> object = v8_compile("new Object()")->Run(); 10984 Local<Value> object = v8_compile("new Object()")->Run();
10985 value = object.As<v8::Object>()->ObjectProtoToString(); 10985 value = object.As<v8::Object>()->ObjectProtoToString();
10986 CHECK(value->IsString() && value->Equals(v8_str("[object Object]"))); 10986 CHECK(value->IsString() && value->Equals(v8_str("[object Object]")));
10987 } 10987 }
10988 10988
10989 10989
10990 THREADED_TEST(ObjectGetConstructorName) { 10990 THREADED_TEST(ObjectGetConstructorName) {
10991 v8::HandleScope scope;
10992 LocalContext context; 10991 LocalContext context;
10992 v8::HandleScope scope(context->GetIsolate());
10993 v8_compile("function Parent() {};" 10993 v8_compile("function Parent() {};"
10994 "function Child() {};" 10994 "function Child() {};"
10995 "Child.prototype = new Parent();" 10995 "Child.prototype = new Parent();"
10996 "var outer = { inner: function() { } };" 10996 "var outer = { inner: function() { } };"
10997 "var p = new Parent();" 10997 "var p = new Parent();"
10998 "var c = new Child();" 10998 "var c = new Child();"
10999 "var x = new outer.inner();")->Run(); 10999 "var x = new outer.inner();")->Run();
11000 11000
11001 Local<v8::Value> p = context->Global()->Get(v8_str("p")); 11001 Local<v8::Value> p = context->Global()->Get(v8_str("p"));
11002 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals( 11002 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals(
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
11173 } 11173 }
11174 11174
11175 11175
11176 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) { 11176 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) {
11177 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11177 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11178 ApiTestFuzzer::Fuzz(); 11178 ApiTestFuzzer::Fuzz();
11179 v8::Unlocker unlocker(CcTest::default_isolate()); 11179 v8::Unlocker unlocker(CcTest::default_isolate());
11180 const char* code = "throw 7;"; 11180 const char* code = "throw 7;";
11181 { 11181 {
11182 v8::Locker nested_locker(CcTest::default_isolate()); 11182 v8::Locker nested_locker(CcTest::default_isolate());
11183 v8::HandleScope scope; 11183 v8::HandleScope scope(args.GetIsolate());
11184 v8::Handle<Value> exception; 11184 v8::Handle<Value> exception;
11185 { v8::TryCatch try_catch; 11185 { v8::TryCatch try_catch;
11186 v8::Handle<Value> value = CompileRun(code); 11186 v8::Handle<Value> value = CompileRun(code);
11187 CHECK(value.IsEmpty()); 11187 CHECK(value.IsEmpty());
11188 CHECK(try_catch.HasCaught()); 11188 CHECK(try_catch.HasCaught());
11189 // Make sure to wrap the exception in a new handle because 11189 // Make sure to wrap the exception in a new handle because
11190 // the handle returned from the TryCatch is destroyed 11190 // the handle returned from the TryCatch is destroyed
11191 // when the TryCatch is destroyed. 11191 // when the TryCatch is destroyed.
11192 exception = Local<Value>::New(try_catch.Exception()); 11192 exception = Local<Value>::New(try_catch.Exception());
11193 } 11193 }
11194 return v8::ThrowException(exception); 11194 return v8::ThrowException(exception);
11195 } 11195 }
11196 } 11196 }
11197 11197
11198 11198
11199 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) { 11199 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) {
11200 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11200 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11201 ApiTestFuzzer::Fuzz(); 11201 ApiTestFuzzer::Fuzz();
11202 v8::Unlocker unlocker(CcTest::default_isolate()); 11202 v8::Unlocker unlocker(CcTest::default_isolate());
11203 const char* code = "throw 7;"; 11203 const char* code = "throw 7;";
11204 { 11204 {
11205 v8::Locker nested_locker(CcTest::default_isolate()); 11205 v8::Locker nested_locker(CcTest::default_isolate());
11206 v8::HandleScope scope; 11206 v8::HandleScope scope(args.GetIsolate());
11207 v8::Handle<Value> value = CompileRun(code); 11207 v8::Handle<Value> value = CompileRun(code);
11208 CHECK(value.IsEmpty()); 11208 CHECK(value.IsEmpty());
11209 return v8_str("foo"); 11209 return v8_str("foo");
11210 } 11210 }
11211 } 11211 }
11212 11212
11213 11213
11214 // These are locking tests that don't need to be run again 11214 // These are locking tests that don't need to be run again
11215 // as part of the locking aggregation tests. 11215 // as part of the locking aggregation tests.
11216 TEST(NestedLockers) { 11216 TEST(NestedLockers) {
11217 v8::Locker locker(CcTest::default_isolate()); 11217 v8::Locker locker(CcTest::default_isolate());
11218 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11218 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11219 v8::HandleScope scope;
11220 LocalContext env; 11219 LocalContext env;
11220 v8::HandleScope scope(env->GetIsolate());
11221 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); 11221 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS);
11222 Local<Function> fun = fun_templ->GetFunction(); 11222 Local<Function> fun = fun_templ->GetFunction();
11223 env->Global()->Set(v8_str("throw_in_js"), fun); 11223 env->Global()->Set(v8_str("throw_in_js"), fun);
11224 Local<Script> script = v8_compile("(function () {" 11224 Local<Script> script = v8_compile("(function () {"
11225 " try {" 11225 " try {"
11226 " throw_in_js();" 11226 " throw_in_js();"
11227 " return 42;" 11227 " return 42;"
11228 " } catch (e) {" 11228 " } catch (e) {"
11229 " return e * 13;" 11229 " return e * 13;"
11230 " }" 11230 " }"
11231 "})();"); 11231 "})();");
11232 CHECK_EQ(91, script->Run()->Int32Value()); 11232 CHECK_EQ(91, script->Run()->Int32Value());
11233 } 11233 }
11234 11234
11235 11235
11236 // These are locking tests that don't need to be run again 11236 // These are locking tests that don't need to be run again
11237 // as part of the locking aggregation tests. 11237 // as part of the locking aggregation tests.
11238 TEST(NestedLockersNoTryCatch) { 11238 TEST(NestedLockersNoTryCatch) {
11239 v8::Locker locker(CcTest::default_isolate()); 11239 v8::Locker locker(CcTest::default_isolate());
11240 v8::HandleScope scope;
11241 LocalContext env; 11240 LocalContext env;
11241 v8::HandleScope scope(env->GetIsolate());
11242 Local<v8::FunctionTemplate> fun_templ = 11242 Local<v8::FunctionTemplate> fun_templ =
11243 v8::FunctionTemplate::New(ThrowInJSNoCatch); 11243 v8::FunctionTemplate::New(ThrowInJSNoCatch);
11244 Local<Function> fun = fun_templ->GetFunction(); 11244 Local<Function> fun = fun_templ->GetFunction();
11245 env->Global()->Set(v8_str("throw_in_js"), fun); 11245 env->Global()->Set(v8_str("throw_in_js"), fun);
11246 Local<Script> script = v8_compile("(function () {" 11246 Local<Script> script = v8_compile("(function () {"
11247 " try {" 11247 " try {"
11248 " throw_in_js();" 11248 " throw_in_js();"
11249 " return 42;" 11249 " return 42;"
11250 " } catch (e) {" 11250 " } catch (e) {"
11251 " return e * 13;" 11251 " return e * 13;"
(...skipping 15 matching lines...) Expand all
11267 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) { 11267 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) {
11268 ApiTestFuzzer::Fuzz(); 11268 ApiTestFuzzer::Fuzz();
11269 v8::Unlocker unlocker(CcTest::default_isolate()); 11269 v8::Unlocker unlocker(CcTest::default_isolate());
11270 return v8::Undefined(); 11270 return v8::Undefined();
11271 } 11271 }
11272 11272
11273 11273
11274 THREADED_TEST(LockUnlockLock) { 11274 THREADED_TEST(LockUnlockLock) {
11275 { 11275 {
11276 v8::Locker locker(CcTest::default_isolate()); 11276 v8::Locker locker(CcTest::default_isolate());
11277 v8::HandleScope scope; 11277 v8::HandleScope scope(CcTest::default_isolate());
11278 LocalContext env; 11278 LocalContext env;
11279 Local<v8::FunctionTemplate> fun_templ = 11279 Local<v8::FunctionTemplate> fun_templ =
11280 v8::FunctionTemplate::New(UnlockForAMoment); 11280 v8::FunctionTemplate::New(UnlockForAMoment);
11281 Local<Function> fun = fun_templ->GetFunction(); 11281 Local<Function> fun = fun_templ->GetFunction();
11282 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 11282 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
11283 Local<Script> script = v8_compile("(function () {" 11283 Local<Script> script = v8_compile("(function () {"
11284 " unlock_for_a_moment();" 11284 " unlock_for_a_moment();"
11285 " return 42;" 11285 " return 42;"
11286 "})();"); 11286 "})();");
11287 CHECK_EQ(42, script->Run()->Int32Value()); 11287 CHECK_EQ(42, script->Run()->Int32Value());
11288 } 11288 }
11289 { 11289 {
11290 v8::Locker locker(CcTest::default_isolate()); 11290 v8::Locker locker(CcTest::default_isolate());
11291 v8::HandleScope scope; 11291 v8::HandleScope scope(CcTest::default_isolate());
11292 LocalContext env; 11292 LocalContext env;
11293 Local<v8::FunctionTemplate> fun_templ = 11293 Local<v8::FunctionTemplate> fun_templ =
11294 v8::FunctionTemplate::New(UnlockForAMoment); 11294 v8::FunctionTemplate::New(UnlockForAMoment);
11295 Local<Function> fun = fun_templ->GetFunction(); 11295 Local<Function> fun = fun_templ->GetFunction();
11296 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 11296 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
11297 Local<Script> script = v8_compile("(function () {" 11297 Local<Script> script = v8_compile("(function () {"
11298 " unlock_for_a_moment();" 11298 " unlock_for_a_moment();"
11299 " return 42;" 11299 " return 42;"
11300 "})();"); 11300 "})();");
11301 CHECK_EQ(42, script->Run()->Int32Value()); 11301 CHECK_EQ(42, script->Run()->Int32Value());
(...skipping 26 matching lines...) Expand all
11328 CHECK_EQ(expected, count); 11328 CHECK_EQ(expected, count);
11329 } 11329 }
11330 11330
11331 11331
11332 TEST(DontLeakGlobalObjects) { 11332 TEST(DontLeakGlobalObjects) {
11333 // Regression test for issues 1139850 and 1174891. 11333 // Regression test for issues 1139850 and 1174891.
11334 11334
11335 v8::V8::Initialize(); 11335 v8::V8::Initialize();
11336 11336
11337 for (int i = 0; i < 5; i++) { 11337 for (int i = 0; i < 5; i++) {
11338 { v8::HandleScope scope; 11338 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11339 LocalContext context; 11339 LocalContext context;
11340 } 11340 }
11341 v8::V8::ContextDisposedNotification(); 11341 v8::V8::ContextDisposedNotification();
11342 CheckSurvivingGlobalObjectsCount(0); 11342 CheckSurvivingGlobalObjectsCount(0);
11343 11343
11344 { v8::HandleScope scope; 11344 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11345 LocalContext context; 11345 LocalContext context;
11346 v8_compile("Date")->Run(); 11346 v8_compile("Date")->Run();
11347 } 11347 }
11348 v8::V8::ContextDisposedNotification(); 11348 v8::V8::ContextDisposedNotification();
11349 CheckSurvivingGlobalObjectsCount(0); 11349 CheckSurvivingGlobalObjectsCount(0);
11350 11350
11351 { v8::HandleScope scope; 11351 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11352 LocalContext context; 11352 LocalContext context;
11353 v8_compile("/aaa/")->Run(); 11353 v8_compile("/aaa/")->Run();
11354 } 11354 }
11355 v8::V8::ContextDisposedNotification(); 11355 v8::V8::ContextDisposedNotification();
11356 CheckSurvivingGlobalObjectsCount(0); 11356 CheckSurvivingGlobalObjectsCount(0);
11357 11357
11358 { v8::HandleScope scope; 11358 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11359 const char* extension_list[] = { "v8/gc" }; 11359 const char* extension_list[] = { "v8/gc" };
11360 v8::ExtensionConfiguration extensions(1, extension_list); 11360 v8::ExtensionConfiguration extensions(1, extension_list);
11361 LocalContext context(&extensions); 11361 LocalContext context(&extensions);
11362 v8_compile("gc();")->Run(); 11362 v8_compile("gc();")->Run();
11363 } 11363 }
11364 v8::V8::ContextDisposedNotification(); 11364 v8::V8::ContextDisposedNotification();
11365 CheckSurvivingGlobalObjectsCount(0); 11365 CheckSurvivingGlobalObjectsCount(0);
11366 } 11366 }
11367 } 11367 }
11368 11368
11369 11369
11370 v8::Persistent<v8::Object> some_object; 11370 v8::Persistent<v8::Object> some_object;
11371 v8::Persistent<v8::Object> bad_handle; 11371 v8::Persistent<v8::Object> bad_handle;
11372 11372
11373 void NewPersistentHandleCallback(v8::Isolate* isolate, 11373 void NewPersistentHandleCallback(v8::Isolate* isolate,
11374 v8::Persistent<v8::Value> handle, 11374 v8::Persistent<v8::Value> handle,
11375 void*) { 11375 void*) {
11376 v8::HandleScope scope; 11376 v8::HandleScope scope(isolate);
11377 bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object); 11377 bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object);
11378 handle.Dispose(isolate); 11378 handle.Dispose(isolate);
11379 } 11379 }
11380 11380
11381 11381
11382 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 11382 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
11383 LocalContext context; 11383 LocalContext context;
11384 v8::Isolate* isolate = context->GetIsolate(); 11384 v8::Isolate* isolate = context->GetIsolate();
11385 11385
11386 v8::Persistent<v8::Object> handle1, handle2; 11386 v8::Persistent<v8::Object> handle1, handle2;
11387 { 11387 {
11388 v8::HandleScope scope; 11388 v8::HandleScope scope(isolate);
11389 some_object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11389 some_object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11390 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11390 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11391 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11391 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11392 } 11392 }
11393 // Note: order is implementation dependent alas: currently 11393 // Note: order is implementation dependent alas: currently
11394 // global handle nodes are processed by PostGarbageCollectionProcessing 11394 // global handle nodes are processed by PostGarbageCollectionProcessing
11395 // in reverse allocation order, so if second allocated handle is deleted, 11395 // in reverse allocation order, so if second allocated handle is deleted,
11396 // weak callback of the first handle would be able to 'reallocate' it. 11396 // weak callback of the first handle would be able to 'reallocate' it.
11397 handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback); 11397 handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback);
11398 handle2.Dispose(isolate); 11398 handle2.Dispose(isolate);
(...skipping 11 matching lines...) Expand all
11410 handle.Dispose(isolate); 11410 handle.Dispose(isolate);
11411 } 11411 }
11412 11412
11413 11413
11414 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 11414 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
11415 LocalContext context; 11415 LocalContext context;
11416 v8::Isolate* isolate = context->GetIsolate(); 11416 v8::Isolate* isolate = context->GetIsolate();
11417 11417
11418 v8::Persistent<v8::Object> handle1, handle2; 11418 v8::Persistent<v8::Object> handle1, handle2;
11419 { 11419 {
11420 v8::HandleScope scope; 11420 v8::HandleScope scope(isolate);
11421 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11421 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11422 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11422 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11423 } 11423 }
11424 handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback); 11424 handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback);
11425 to_be_disposed = handle2; 11425 to_be_disposed = handle2;
11426 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11426 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11427 } 11427 }
11428 11428
11429 void DisposingCallback(v8::Isolate* isolate, 11429 void DisposingCallback(v8::Isolate* isolate,
11430 v8::Persistent<v8::Value> handle, 11430 v8::Persistent<v8::Value> handle,
11431 void*) { 11431 void*) {
11432 handle.Dispose(isolate); 11432 handle.Dispose(isolate);
11433 } 11433 }
11434 11434
11435 void HandleCreatingCallback(v8::Isolate* isolate, 11435 void HandleCreatingCallback(v8::Isolate* isolate,
11436 v8::Persistent<v8::Value> handle, 11436 v8::Persistent<v8::Value> handle,
11437 void*) { 11437 void*) {
11438 v8::HandleScope scope; 11438 v8::HandleScope scope(isolate);
11439 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11439 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11440 handle.Dispose(isolate); 11440 handle.Dispose(isolate);
11441 } 11441 }
11442 11442
11443 11443
11444 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 11444 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
11445 LocalContext context; 11445 LocalContext context;
11446 v8::Isolate* isolate = context->GetIsolate(); 11446 v8::Isolate* isolate = context->GetIsolate();
11447 11447
11448 v8::Persistent<v8::Object> handle1, handle2, handle3; 11448 v8::Persistent<v8::Object> handle1, handle2, handle3;
11449 { 11449 {
11450 v8::HandleScope scope; 11450 v8::HandleScope scope(isolate);
11451 handle3 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11451 handle3 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11452 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11452 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11453 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11453 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11454 } 11454 }
11455 handle2.MakeWeak(isolate, NULL, DisposingCallback); 11455 handle2.MakeWeak(isolate, NULL, DisposingCallback);
11456 handle3.MakeWeak(isolate, NULL, HandleCreatingCallback); 11456 handle3.MakeWeak(isolate, NULL, HandleCreatingCallback);
11457 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11457 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11458 } 11458 }
11459 11459
11460 11460
11461 THREADED_TEST(CheckForCrossContextObjectLiterals) { 11461 THREADED_TEST(CheckForCrossContextObjectLiterals) {
11462 v8::V8::Initialize(); 11462 v8::V8::Initialize();
11463 11463
11464 const int nof = 2; 11464 const int nof = 2;
11465 const char* sources[nof] = { 11465 const char* sources[nof] = {
11466 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", 11466 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
11467 "Object()" 11467 "Object()"
11468 }; 11468 };
11469 11469
11470 for (int i = 0; i < nof; i++) { 11470 for (int i = 0; i < nof; i++) {
11471 const char* source = sources[i]; 11471 const char* source = sources[i];
11472 { v8::HandleScope scope; 11472 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11473 LocalContext context; 11473 LocalContext context;
11474 CompileRun(source); 11474 CompileRun(source);
11475 } 11475 }
11476 { v8::HandleScope scope; 11476 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11477 LocalContext context; 11477 LocalContext context;
11478 CompileRun(source); 11478 CompileRun(source);
11479 } 11479 }
11480 } 11480 }
11481 } 11481 }
11482 11482
11483 11483
11484 static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) { 11484 static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) {
11485 v8::HandleScope inner; 11485 v8::HandleScope inner(env->GetIsolate());
11486 env->Enter(); 11486 env->Enter();
11487 v8::Handle<Value> three = v8_num(3); 11487 v8::Handle<Value> three = v8_num(3);
11488 v8::Handle<Value> value = inner.Close(three); 11488 v8::Handle<Value> value = inner.Close(three);
11489 env->Exit(); 11489 env->Exit();
11490 return value; 11490 return value;
11491 } 11491 }
11492 11492
11493 11493
11494 THREADED_TEST(NestedHandleScopeAndContexts) { 11494 THREADED_TEST(NestedHandleScopeAndContexts) {
11495 v8::HandleScope outer; 11495 v8::HandleScope outer(v8::Isolate::GetCurrent());
11496 v8::Persistent<Context> env = Context::New(); 11496 v8::Persistent<Context> env = Context::New();
11497 env->Enter(); 11497 env->Enter();
11498 v8::Handle<Value> value = NestedScope(env); 11498 v8::Handle<Value> value = NestedScope(env);
11499 v8::Handle<String> str(value->ToString()); 11499 v8::Handle<String> str(value->ToString());
11500 CHECK(!str.IsEmpty()); 11500 CHECK(!str.IsEmpty());
11501 env->Exit(); 11501 env->Exit();
11502 env.Dispose(env->GetIsolate()); 11502 env.Dispose(env->GetIsolate());
11503 } 11503 }
11504 11504
11505 11505
(...skipping 18 matching lines...) Expand all
11524 // TODO(siggi): Verify return_addr_location. 11524 // TODO(siggi): Verify return_addr_location.
11525 // This can be done by capturing JitCodeEvents, but requires an ordered 11525 // This can be done by capturing JitCodeEvents, but requires an ordered
11526 // collection. 11526 // collection.
11527 } 11527 }
11528 11528
11529 11529
11530 static void RunLoopInNewEnv() { 11530 static void RunLoopInNewEnv() {
11531 bar_ptr = NULL; 11531 bar_ptr = NULL;
11532 foo_ptr = NULL; 11532 foo_ptr = NULL;
11533 11533
11534 v8::HandleScope outer; 11534 v8::HandleScope outer(v8::Isolate::GetCurrent());
11535 v8::Persistent<Context> env = Context::New(); 11535 v8::Persistent<Context> env = Context::New();
11536 env->Enter(); 11536 env->Enter();
11537 11537
11538 const char* script = 11538 const char* script =
11539 "function bar() {" 11539 "function bar() {"
11540 " var sum = 0;" 11540 " var sum = 0;"
11541 " for (i = 0; i < 100; ++i)" 11541 " for (i = 0; i < 100; ++i)"
11542 " sum = foo(i);" 11542 " sum = foo(i);"
11543 " return sum;" 11543 " return sum;"
11544 "}" 11544 "}"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
11764 "}" 11764 "}"
11765 "function foo(i) { return i * i; };" 11765 "function foo(i) { return i * i; };"
11766 "bar();"; 11766 "bar();";
11767 11767
11768 // Run this test in a new isolate to make sure we don't 11768 // Run this test in a new isolate to make sure we don't
11769 // have remnants of state from other code. 11769 // have remnants of state from other code.
11770 v8::Isolate* isolate = v8::Isolate::New(); 11770 v8::Isolate* isolate = v8::Isolate::New();
11771 isolate->Enter(); 11771 isolate->Enter();
11772 11772
11773 { 11773 {
11774 v8::HandleScope scope; 11774 v8::HandleScope scope(isolate);
11775 i::HashMap code(MatchPointers); 11775 i::HashMap code(MatchPointers);
11776 code_map = &code; 11776 code_map = &code;
11777 11777
11778 i::HashMap lineinfo(MatchPointers); 11778 i::HashMap lineinfo(MatchPointers);
11779 jitcode_line_info = &lineinfo; 11779 jitcode_line_info = &lineinfo;
11780 11780
11781 saw_bar = 0; 11781 saw_bar = 0;
11782 move_events = 0; 11782 move_events = 0;
11783 11783
11784 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); 11784 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
11817 isolate->Exit(); 11817 isolate->Exit();
11818 isolate->Dispose(); 11818 isolate->Dispose();
11819 11819
11820 // Do this in a new isolate. 11820 // Do this in a new isolate.
11821 isolate = v8::Isolate::New(); 11821 isolate = v8::Isolate::New();
11822 isolate->Enter(); 11822 isolate->Enter();
11823 11823
11824 // Verify that we get callbacks for existing code objects when we 11824 // Verify that we get callbacks for existing code objects when we
11825 // request enumeration of existing code. 11825 // request enumeration of existing code.
11826 { 11826 {
11827 v8::HandleScope scope; 11827 v8::HandleScope scope(isolate);
11828 LocalContext env; 11828 LocalContext env;
11829 CompileRun(script); 11829 CompileRun(script);
11830 11830
11831 // Now get code through initial iteration. 11831 // Now get code through initial iteration.
11832 i::HashMap code(MatchPointers); 11832 i::HashMap code(MatchPointers);
11833 code_map = &code; 11833 code_map = &code;
11834 11834
11835 i::HashMap lineinfo(MatchPointers); 11835 i::HashMap lineinfo(MatchPointers);
11836 jitcode_line_info = &lineinfo; 11836 jitcode_line_info = &lineinfo;
11837 11837
(...skipping 12 matching lines...) Expand all
11850 11850
11851 isolate->Exit(); 11851 isolate->Exit();
11852 isolate->Dispose(); 11852 isolate->Dispose();
11853 } 11853 }
11854 11854
11855 11855
11856 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 11856 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
11857 11857
11858 11858
11859 THREADED_TEST(ExternalAllocatedMemory) { 11859 THREADED_TEST(ExternalAllocatedMemory) {
11860 v8::HandleScope outer; 11860 v8::HandleScope outer(v8::Isolate::GetCurrent());
11861 v8::Persistent<Context> env(Context::New()); 11861 v8::Persistent<Context> env(Context::New());
11862 CHECK(!env.IsEmpty()); 11862 CHECK(!env.IsEmpty());
11863 const intptr_t kSize = 1024*1024; 11863 const intptr_t kSize = 1024*1024;
11864 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)), 11864 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(kSize)),
11865 cast(kSize)); 11865 cast(kSize));
11866 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize)), 11866 CHECK_EQ(cast(v8::V8::AdjustAmountOfExternalAllocatedMemory(-kSize)),
11867 cast(0)); 11867 cast(0));
11868 } 11868 }
11869 11869
11870 11870
11871 THREADED_TEST(DisposeEnteredContext) { 11871 THREADED_TEST(DisposeEnteredContext) {
11872 v8::HandleScope scope;
11873 LocalContext outer; 11872 LocalContext outer;
11873 v8::HandleScope scope(outer->GetIsolate());
11874 { v8::Persistent<v8::Context> inner = v8::Context::New(); 11874 { v8::Persistent<v8::Context> inner = v8::Context::New();
11875 inner->Enter(); 11875 inner->Enter();
11876 inner.Dispose(inner->GetIsolate()); 11876 inner.Dispose(inner->GetIsolate());
11877 inner.Clear(); 11877 inner.Clear();
11878 inner->Exit(); 11878 inner->Exit();
11879 } 11879 }
11880 } 11880 }
11881 11881
11882 11882
11883 // Regression test for issue 54, object templates with internal fields 11883 // Regression test for issue 54, object templates with internal fields
11884 // but no accessors or interceptors did not get their internal field 11884 // but no accessors or interceptors did not get their internal field
11885 // count set on instances. 11885 // count set on instances.
11886 THREADED_TEST(Regress54) { 11886 THREADED_TEST(Regress54) {
11887 v8::HandleScope outer;
11888 LocalContext context; 11887 LocalContext context;
11889 v8::Isolate* isolate = context->GetIsolate(); 11888 v8::Isolate* isolate = context->GetIsolate();
11889 v8::HandleScope outer(isolate);
11890 static v8::Persistent<v8::ObjectTemplate> templ; 11890 static v8::Persistent<v8::ObjectTemplate> templ;
11891 if (templ.IsEmpty()) { 11891 if (templ.IsEmpty()) {
11892 v8::HandleScope inner; 11892 v8::HandleScope inner(isolate);
11893 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 11893 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
11894 local->SetInternalFieldCount(1); 11894 local->SetInternalFieldCount(1);
11895 templ = 11895 templ =
11896 v8::Persistent<v8::ObjectTemplate>::New(isolate, inner.Close(local)); 11896 v8::Persistent<v8::ObjectTemplate>::New(isolate, inner.Close(local));
11897 } 11897 }
11898 v8::Handle<v8::Object> result = templ->NewInstance(); 11898 v8::Handle<v8::Object> result = templ->NewInstance();
11899 CHECK_EQ(1, result->InternalFieldCount()); 11899 CHECK_EQ(1, result->InternalFieldCount());
11900 } 11900 }
11901 11901
11902 11902
11903 // If part of the threaded tests, this test makes ThreadingTest fail 11903 // If part of the threaded tests, this test makes ThreadingTest fail
11904 // on mac. 11904 // on mac.
11905 TEST(CatchStackOverflow) { 11905 TEST(CatchStackOverflow) {
11906 v8::HandleScope scope;
11907 LocalContext context; 11906 LocalContext context;
11907 v8::HandleScope scope(context->GetIsolate());
11908 v8::TryCatch try_catch; 11908 v8::TryCatch try_catch;
11909 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New( 11909 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(
11910 "function f() {" 11910 "function f() {"
11911 " return f();" 11911 " return f();"
11912 "}" 11912 "}"
11913 "" 11913 ""
11914 "f();")); 11914 "f();"));
11915 v8::Handle<v8::Value> result = script->Run(); 11915 v8::Handle<v8::Value> result = script->Run();
11916 CHECK(result.IsEmpty()); 11916 CHECK(result.IsEmpty());
11917 } 11917 }
11918 11918
11919 11919
11920 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 11920 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
11921 const char* resource_name, 11921 const char* resource_name,
11922 int line_offset) { 11922 int line_offset) {
11923 v8::HandleScope scope; 11923 v8::HandleScope scope(v8::Isolate::GetCurrent());
11924 v8::TryCatch try_catch; 11924 v8::TryCatch try_catch;
11925 v8::Handle<v8::Value> result = script->Run(); 11925 v8::Handle<v8::Value> result = script->Run();
11926 CHECK(result.IsEmpty()); 11926 CHECK(result.IsEmpty());
11927 CHECK(try_catch.HasCaught()); 11927 CHECK(try_catch.HasCaught());
11928 v8::Handle<v8::Message> message = try_catch.Message(); 11928 v8::Handle<v8::Message> message = try_catch.Message();
11929 CHECK(!message.IsEmpty()); 11929 CHECK(!message.IsEmpty());
11930 CHECK_EQ(10 + line_offset, message->GetLineNumber()); 11930 CHECK_EQ(10 + line_offset, message->GetLineNumber());
11931 CHECK_EQ(91, message->GetStartPosition()); 11931 CHECK_EQ(91, message->GetStartPosition());
11932 CHECK_EQ(92, message->GetEndPosition()); 11932 CHECK_EQ(92, message->GetEndPosition());
11933 CHECK_EQ(2, message->GetStartColumn()); 11933 CHECK_EQ(2, message->GetStartColumn());
11934 CHECK_EQ(3, message->GetEndColumn()); 11934 CHECK_EQ(3, message->GetEndColumn());
11935 v8::String::AsciiValue line(message->GetSourceLine()); 11935 v8::String::AsciiValue line(message->GetSourceLine());
11936 CHECK_EQ(" throw 'nirk';", *line); 11936 CHECK_EQ(" throw 'nirk';", *line);
11937 v8::String::AsciiValue name(message->GetScriptResourceName()); 11937 v8::String::AsciiValue name(message->GetScriptResourceName());
11938 CHECK_EQ(resource_name, *name); 11938 CHECK_EQ(resource_name, *name);
11939 } 11939 }
11940 11940
11941 11941
11942 THREADED_TEST(TryCatchSourceInfo) { 11942 THREADED_TEST(TryCatchSourceInfo) {
11943 v8::HandleScope scope;
11944 LocalContext context; 11943 LocalContext context;
11944 v8::HandleScope scope(context->GetIsolate());
11945 v8::Handle<v8::String> source = v8::String::New( 11945 v8::Handle<v8::String> source = v8::String::New(
11946 "function Foo() {\n" 11946 "function Foo() {\n"
11947 " return Bar();\n" 11947 " return Bar();\n"
11948 "}\n" 11948 "}\n"
11949 "\n" 11949 "\n"
11950 "function Bar() {\n" 11950 "function Bar() {\n"
11951 " return Baz();\n" 11951 " return Baz();\n"
11952 "}\n" 11952 "}\n"
11953 "\n" 11953 "\n"
11954 "function Baz() {\n" 11954 "function Baz() {\n"
(...skipping 14 matching lines...) Expand all
11969 CheckTryCatchSourceInfo(script, resource_name, 0); 11969 CheckTryCatchSourceInfo(script, resource_name, 0);
11970 11970
11971 resource_name = "test2.js"; 11971 resource_name = "test2.js";
11972 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7)); 11972 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7));
11973 script = v8::Script::Compile(source, &origin2); 11973 script = v8::Script::Compile(source, &origin2);
11974 CheckTryCatchSourceInfo(script, resource_name, 7); 11974 CheckTryCatchSourceInfo(script, resource_name, 7);
11975 } 11975 }
11976 11976
11977 11977
11978 THREADED_TEST(CompilationCache) { 11978 THREADED_TEST(CompilationCache) {
11979 v8::HandleScope scope;
11980 LocalContext context; 11979 LocalContext context;
11980 v8::HandleScope scope(context->GetIsolate());
11981 v8::Handle<v8::String> source0 = v8::String::New("1234"); 11981 v8::Handle<v8::String> source0 = v8::String::New("1234");
11982 v8::Handle<v8::String> source1 = v8::String::New("1234"); 11982 v8::Handle<v8::String> source1 = v8::String::New("1234");
11983 v8::Handle<v8::Script> script0 = 11983 v8::Handle<v8::Script> script0 =
11984 v8::Script::Compile(source0, v8::String::New("test.js")); 11984 v8::Script::Compile(source0, v8::String::New("test.js"));
11985 v8::Handle<v8::Script> script1 = 11985 v8::Handle<v8::Script> script1 =
11986 v8::Script::Compile(source1, v8::String::New("test.js")); 11986 v8::Script::Compile(source1, v8::String::New("test.js"));
11987 v8::Handle<v8::Script> script2 = 11987 v8::Handle<v8::Script> script2 =
11988 v8::Script::Compile(source0); // different origin 11988 v8::Script::Compile(source0); // different origin
11989 CHECK_EQ(1234, script0->Run()->Int32Value()); 11989 CHECK_EQ(1234, script0->Run()->Int32Value());
11990 CHECK_EQ(1234, script1->Run()->Int32Value()); 11990 CHECK_EQ(1234, script1->Run()->Int32Value());
11991 CHECK_EQ(1234, script2->Run()->Int32Value()); 11991 CHECK_EQ(1234, script2->Run()->Int32Value());
11992 } 11992 }
11993 11993
11994 11994
11995 static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) { 11995 static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) {
11996 ApiTestFuzzer::Fuzz(); 11996 ApiTestFuzzer::Fuzz();
11997 return v8_num(42); 11997 return v8_num(42);
11998 } 11998 }
11999 11999
12000 12000
12001 THREADED_TEST(CallbackFunctionName) { 12001 THREADED_TEST(CallbackFunctionName) {
12002 v8::HandleScope scope;
12003 LocalContext context; 12002 LocalContext context;
12003 v8::HandleScope scope(context->GetIsolate());
12004 Local<ObjectTemplate> t = ObjectTemplate::New(); 12004 Local<ObjectTemplate> t = ObjectTemplate::New();
12005 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback)); 12005 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback));
12006 context->Global()->Set(v8_str("obj"), t->NewInstance()); 12006 context->Global()->Set(v8_str("obj"), t->NewInstance());
12007 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 12007 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
12008 CHECK(value->IsString()); 12008 CHECK(value->IsString());
12009 v8::String::AsciiValue name(value); 12009 v8::String::AsciiValue name(value);
12010 CHECK_EQ("asdf", *name); 12010 CHECK_EQ("asdf", *name);
12011 } 12011 }
12012 12012
12013 12013
12014 THREADED_TEST(DateAccess) { 12014 THREADED_TEST(DateAccess) {
12015 v8::HandleScope scope;
12016 LocalContext context; 12015 LocalContext context;
12016 v8::HandleScope scope(context->GetIsolate());
12017 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); 12017 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0);
12018 CHECK(date->IsDate()); 12018 CHECK(date->IsDate());
12019 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue()); 12019 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue());
12020 } 12020 }
12021 12021
12022 12022
12023 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { 12023 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) {
12024 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 12024 v8::Handle<v8::Object> obj = val.As<v8::Object>();
12025 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 12025 v8::Handle<v8::Array> props = obj->GetPropertyNames();
12026 CHECK_EQ(elmc, props->Length()); 12026 CHECK_EQ(elmc, props->Length());
(...skipping 11 matching lines...) Expand all
12038 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); 12038 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames();
12039 CHECK_EQ(elmc, props->Length()); 12039 CHECK_EQ(elmc, props->Length());
12040 for (int i = 0; i < elmc; i++) { 12040 for (int i = 0; i < elmc; i++) {
12041 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 12041 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
12042 CHECK_EQ(elmv[i], *elm); 12042 CHECK_EQ(elmv[i], *elm);
12043 } 12043 }
12044 } 12044 }
12045 12045
12046 12046
12047 THREADED_TEST(PropertyEnumeration) { 12047 THREADED_TEST(PropertyEnumeration) {
12048 v8::HandleScope scope;
12049 LocalContext context; 12048 LocalContext context;
12049 v8::HandleScope scope(context->GetIsolate());
12050 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 12050 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New(
12051 "var result = [];" 12051 "var result = [];"
12052 "result[0] = {};" 12052 "result[0] = {};"
12053 "result[1] = {a: 1, b: 2};" 12053 "result[1] = {a: 1, b: 2};"
12054 "result[2] = [1, 2, 3];" 12054 "result[2] = [1, 2, 3];"
12055 "var proto = {x: 1, y: 2, z: 3};" 12055 "var proto = {x: 1, y: 2, z: 3};"
12056 "var x = { __proto__: proto, w: 0, z: 1 };" 12056 "var x = { __proto__: proto, w: 0, z: 1 };"
12057 "result[3] = x;" 12057 "result[3] = x;"
12058 "result;"))->Run(); 12058 "result;"))->Run();
12059 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 12059 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
(...skipping 12 matching lines...) Expand all
12072 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); 12072 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2);
12073 int elmc3 = 4; 12073 int elmc3 = 4;
12074 const char* elmv3[] = {"w", "z", "x", "y"}; 12074 const char* elmv3[] = {"w", "z", "x", "y"};
12075 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); 12075 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3);
12076 int elmc4 = 2; 12076 int elmc4 = 2;
12077 const char* elmv4[] = {"w", "z"}; 12077 const char* elmv4[] = {"w", "z"};
12078 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); 12078 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4);
12079 } 12079 }
12080 12080
12081 THREADED_TEST(PropertyEnumeration2) { 12081 THREADED_TEST(PropertyEnumeration2) {
12082 v8::HandleScope scope;
12083 LocalContext context; 12082 LocalContext context;
12083 v8::HandleScope scope(context->GetIsolate());
12084 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 12084 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New(
12085 "var result = [];" 12085 "var result = [];"
12086 "result[0] = {};" 12086 "result[0] = {};"
12087 "result[1] = {a: 1, b: 2};" 12087 "result[1] = {a: 1, b: 2};"
12088 "result[2] = [1, 2, 3];" 12088 "result[2] = [1, 2, 3];"
12089 "var proto = {x: 1, y: 2, z: 3};" 12089 "var proto = {x: 1, y: 2, z: 3};"
12090 "var x = { __proto__: proto, w: 0, z: 1 };" 12090 "var x = { __proto__: proto, w: 0, z: 1 };"
12091 "result[3] = x;" 12091 "result[3] = x;"
12092 "result;"))->Run(); 12092 "result;"))->Run();
12093 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 12093 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
(...skipping 20 matching lines...) Expand all
12114 12114
12115 static bool IndexedSetAccessBlocker(Local<v8::Object> obj, 12115 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
12116 uint32_t key, 12116 uint32_t key,
12117 v8::AccessType type, 12117 v8::AccessType type,
12118 Local<Value> data) { 12118 Local<Value> data) {
12119 return type != v8::ACCESS_SET; 12119 return type != v8::ACCESS_SET;
12120 } 12120 }
12121 12121
12122 12122
12123 THREADED_TEST(DisableAccessChecksWhileConfiguring) { 12123 THREADED_TEST(DisableAccessChecksWhileConfiguring) {
12124 v8::HandleScope scope;
12125 LocalContext context; 12124 LocalContext context;
12125 v8::HandleScope scope(context->GetIsolate());
12126 Local<ObjectTemplate> templ = ObjectTemplate::New(); 12126 Local<ObjectTemplate> templ = ObjectTemplate::New();
12127 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, 12127 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
12128 IndexedSetAccessBlocker); 12128 IndexedSetAccessBlocker);
12129 templ->Set(v8_str("x"), v8::True()); 12129 templ->Set(v8_str("x"), v8::True());
12130 Local<v8::Object> instance = templ->NewInstance(); 12130 Local<v8::Object> instance = templ->NewInstance();
12131 context->Global()->Set(v8_str("obj"), instance); 12131 context->Global()->Set(v8_str("obj"), instance);
12132 Local<Value> value = CompileRun("obj.x"); 12132 Local<Value> value = CompileRun("obj.x");
12133 CHECK(value->BooleanValue()); 12133 CHECK(value->BooleanValue());
12134 } 12134 }
12135 12135
12136 12136
12137 static bool NamedGetAccessBlocker(Local<v8::Object> obj, 12137 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
12138 Local<Value> name, 12138 Local<Value> name,
12139 v8::AccessType type, 12139 v8::AccessType type,
12140 Local<Value> data) { 12140 Local<Value> data) {
12141 return false; 12141 return false;
12142 } 12142 }
12143 12143
12144 12144
12145 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, 12145 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
12146 uint32_t key, 12146 uint32_t key,
12147 v8::AccessType type, 12147 v8::AccessType type,
12148 Local<Value> data) { 12148 Local<Value> data) {
12149 return false; 12149 return false;
12150 } 12150 }
12151 12151
12152 12152
12153 12153
12154 THREADED_TEST(AccessChecksReenabledCorrectly) { 12154 THREADED_TEST(AccessChecksReenabledCorrectly) {
12155 v8::HandleScope scope;
12156 LocalContext context; 12155 LocalContext context;
12156 v8::HandleScope scope(context->GetIsolate());
12157 Local<ObjectTemplate> templ = ObjectTemplate::New(); 12157 Local<ObjectTemplate> templ = ObjectTemplate::New();
12158 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, 12158 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
12159 IndexedGetAccessBlocker); 12159 IndexedGetAccessBlocker);
12160 templ->Set(v8_str("a"), v8_str("a")); 12160 templ->Set(v8_str("a"), v8_str("a"));
12161 // Add more than 8 (see kMaxFastProperties) properties 12161 // Add more than 8 (see kMaxFastProperties) properties
12162 // so that the constructor will force copying map. 12162 // so that the constructor will force copying map.
12163 // Cannot sprintf, gcc complains unsafety. 12163 // Cannot sprintf, gcc complains unsafety.
12164 char buf[4]; 12164 char buf[4];
12165 for (char i = '0'; i <= '9' ; i++) { 12165 for (char i = '0'; i <= '9' ; i++) {
12166 buf[0] = i; 12166 buf[0] = i;
(...skipping 17 matching lines...) Expand all
12184 context->Global()->Set(v8_str("obj_2"), instance_2); 12184 context->Global()->Set(v8_str("obj_2"), instance_2);
12185 12185
12186 Local<Value> value_2 = CompileRun("obj_2.a"); 12186 Local<Value> value_2 = CompileRun("obj_2.a");
12187 CHECK(value_2->IsUndefined()); 12187 CHECK(value_2->IsUndefined());
12188 } 12188 }
12189 12189
12190 12190
12191 // This tests that access check information remains on the global 12191 // This tests that access check information remains on the global
12192 // object template when creating contexts. 12192 // object template when creating contexts.
12193 THREADED_TEST(AccessControlRepeatedContextCreation) { 12193 THREADED_TEST(AccessControlRepeatedContextCreation) {
12194 v8::HandleScope handle_scope; 12194 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12195 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12195 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12196 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 12196 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
12197 IndexedSetAccessBlocker); 12197 IndexedSetAccessBlocker);
12198 i::Handle<i::ObjectTemplateInfo> internal_template = 12198 i::Handle<i::ObjectTemplateInfo> internal_template =
12199 v8::Utils::OpenHandle(*global_template); 12199 v8::Utils::OpenHandle(*global_template);
12200 CHECK(!internal_template->constructor()->IsUndefined()); 12200 CHECK(!internal_template->constructor()->IsUndefined());
12201 i::Handle<i::FunctionTemplateInfo> constructor( 12201 i::Handle<i::FunctionTemplateInfo> constructor(
12202 i::FunctionTemplateInfo::cast(internal_template->constructor())); 12202 i::FunctionTemplateInfo::cast(internal_template->constructor()));
12203 CHECK(!constructor->access_check_info()->IsUndefined()); 12203 CHECK(!constructor->access_check_info()->IsUndefined());
12204 v8::Persistent<Context> context0(Context::New(NULL, global_template)); 12204 v8::Persistent<Context> context0(Context::New(NULL, global_template));
12205 CHECK(!context0.IsEmpty()); 12205 CHECK(!context0.IsEmpty());
12206 CHECK(!constructor->access_check_info()->IsUndefined()); 12206 CHECK(!constructor->access_check_info()->IsUndefined());
12207 } 12207 }
12208 12208
12209 12209
12210 THREADED_TEST(TurnOnAccessCheck) { 12210 THREADED_TEST(TurnOnAccessCheck) {
12211 v8::HandleScope handle_scope; 12211 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12212 12212
12213 // Create an environment with access check to the global object disabled by 12213 // Create an environment with access check to the global object disabled by
12214 // default. 12214 // default.
12215 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12215 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12216 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 12216 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
12217 IndexedGetAccessBlocker, 12217 IndexedGetAccessBlocker,
12218 v8::Handle<v8::Value>(), 12218 v8::Handle<v8::Value>(),
12219 false); 12219 false);
12220 v8::Persistent<Context> context = Context::New(NULL, global_template); 12220 v8::Persistent<Context> context = Context::New(NULL, global_template);
12221 Context::Scope context_scope(context); 12221 Context::Scope context_scope(context);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
12281 Local<Value> data) { 12281 Local<Value> data) {
12282 if (!name->IsString()) return false; 12282 if (!name->IsString()) return false;
12283 i::Handle<i::String> name_handle = 12283 i::Handle<i::String> name_handle =
12284 v8::Utils::OpenHandle(String::Cast(*name)); 12284 v8::Utils::OpenHandle(String::Cast(*name));
12285 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA)) 12285 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA))
12286 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH)); 12286 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH));
12287 } 12287 }
12288 12288
12289 12289
12290 THREADED_TEST(TurnOnAccessCheckAndRecompile) { 12290 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
12291 v8::HandleScope handle_scope; 12291 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12292 12292
12293 // Create an environment with access check to the global object disabled by 12293 // Create an environment with access check to the global object disabled by
12294 // default. When the registered access checker will block access to properties 12294 // default. When the registered access checker will block access to properties
12295 // a and h. 12295 // a and h.
12296 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12296 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12297 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, 12297 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
12298 IndexedGetAccessBlocker, 12298 IndexedGetAccessBlocker,
12299 v8::Handle<v8::Value>(), 12299 v8::Handle<v8::Value>(),
12300 false); 12300 false);
12301 v8::Persistent<Context> context = Context::New(NULL, global_template); 12301 v8::Persistent<Context> context = Context::New(NULL, global_template);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
12445 12445
12446 CHECK_EQ(0, sd->Length()); 12446 CHECK_EQ(0, sd->Length());
12447 12447
12448 delete sd; 12448 delete sd;
12449 } 12449 }
12450 12450
12451 12451
12452 // Attempts to deserialize bad data. 12452 // Attempts to deserialize bad data.
12453 TEST(PreCompileInvalidPreparseDataError) { 12453 TEST(PreCompileInvalidPreparseDataError) {
12454 v8::V8::Initialize(); 12454 v8::V8::Initialize();
12455 v8::HandleScope scope;
12456 LocalContext context; 12455 LocalContext context;
12456 v8::HandleScope scope(context->GetIsolate());
12457 12457
12458 const char* script = "function foo(){ return 5;}\n" 12458 const char* script = "function foo(){ return 5;}\n"
12459 "function bar(){ return 6 + 7;} foo();"; 12459 "function bar(){ return 6 + 7;} foo();";
12460 v8::ScriptData* sd = 12460 v8::ScriptData* sd =
12461 v8::ScriptData::PreCompile(script, i::StrLength(script)); 12461 v8::ScriptData::PreCompile(script, i::StrLength(script));
12462 CHECK(!sd->HasError()); 12462 CHECK(!sd->HasError());
12463 // ScriptDataImpl private implementation details 12463 // ScriptDataImpl private implementation details
12464 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize; 12464 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize;
12465 const int kFunctionEntrySize = i::FunctionEntry::kSize; 12465 const int kFunctionEntrySize = i::FunctionEntry::kSize;
12466 const int kFunctionEntryStartOffset = 0; 12466 const int kFunctionEntryStartOffset = 0;
(...skipping 25 matching lines...) Expand all
12492 CHECK(!try_catch.HasCaught()); 12492 CHECK(!try_catch.HasCaught());
12493 12493
12494 delete sd; 12494 delete sd;
12495 } 12495 }
12496 12496
12497 12497
12498 // Verifies that the Handle<String> and const char* versions of the API produce 12498 // Verifies that the Handle<String> and const char* versions of the API produce
12499 // the same results (at least for one trivial case). 12499 // the same results (at least for one trivial case).
12500 TEST(PreCompileAPIVariationsAreSame) { 12500 TEST(PreCompileAPIVariationsAreSame) {
12501 v8::V8::Initialize(); 12501 v8::V8::Initialize();
12502 v8::HandleScope scope; 12502 v8::HandleScope scope(v8::Isolate::GetCurrent());
12503 12503
12504 const char* cstring = "function foo(a) { return a+1; }"; 12504 const char* cstring = "function foo(a) { return a+1; }";
12505 12505
12506 v8::ScriptData* sd_from_cstring = 12506 v8::ScriptData* sd_from_cstring =
12507 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring)); 12507 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
12508 12508
12509 TestAsciiResource* resource = new TestAsciiResource(cstring); 12509 TestAsciiResource* resource = new TestAsciiResource(cstring);
12510 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 12510 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
12511 v8::String::NewExternal(resource)); 12511 v8::String::NewExternal(resource));
12512 12512
(...skipping 16 matching lines...) Expand all
12529 delete sd_from_string; 12529 delete sd_from_string;
12530 } 12530 }
12531 12531
12532 12532
12533 // This tests that we do not allow dictionary load/call inline caches 12533 // This tests that we do not allow dictionary load/call inline caches
12534 // to use functions that have not yet been compiled. The potential 12534 // to use functions that have not yet been compiled. The potential
12535 // problem of loading a function that has not yet been compiled can 12535 // problem of loading a function that has not yet been compiled can
12536 // arise because we share code between contexts via the compilation 12536 // arise because we share code between contexts via the compilation
12537 // cache. 12537 // cache.
12538 THREADED_TEST(DictionaryICLoadedFunction) { 12538 THREADED_TEST(DictionaryICLoadedFunction) {
12539 v8::HandleScope scope; 12539 v8::HandleScope scope(v8::Isolate::GetCurrent());
12540 // Test LoadIC. 12540 // Test LoadIC.
12541 for (int i = 0; i < 2; i++) { 12541 for (int i = 0; i < 2; i++) {
12542 LocalContext context; 12542 LocalContext context;
12543 context->Global()->Set(v8_str("tmp"), v8::True()); 12543 context->Global()->Set(v8_str("tmp"), v8::True());
12544 context->Global()->Delete(v8_str("tmp")); 12544 context->Global()->Delete(v8_str("tmp"));
12545 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); 12545 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');");
12546 } 12546 }
12547 // Test CallIC. 12547 // Test CallIC.
12548 for (int i = 0; i < 2; i++) { 12548 for (int i = 0; i < 2; i++) {
12549 LocalContext context; 12549 LocalContext context;
12550 context->Global()->Set(v8_str("tmp"), v8::True()); 12550 context->Global()->Set(v8_str("tmp"), v8::True());
12551 context->Global()->Delete(v8_str("tmp")); 12551 context->Global()->Delete(v8_str("tmp"));
12552 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); 12552 CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
12553 } 12553 }
12554 } 12554 }
12555 12555
12556 12556
12557 // Test that cross-context new calls use the context of the callee to 12557 // Test that cross-context new calls use the context of the callee to
12558 // create the new JavaScript object. 12558 // create the new JavaScript object.
12559 THREADED_TEST(CrossContextNew) { 12559 THREADED_TEST(CrossContextNew) {
12560 v8::HandleScope scope; 12560 v8::HandleScope scope(v8::Isolate::GetCurrent());
12561 v8::Persistent<Context> context0 = Context::New(); 12561 v8::Persistent<Context> context0 = Context::New();
12562 v8::Persistent<Context> context1 = Context::New(); 12562 v8::Persistent<Context> context1 = Context::New();
12563 12563
12564 // Allow cross-domain access. 12564 // Allow cross-domain access.
12565 Local<String> token = v8_str("<security token>"); 12565 Local<String> token = v8_str("<security token>");
12566 context0->SetSecurityToken(token); 12566 context0->SetSecurityToken(token);
12567 context1->SetSecurityToken(token); 12567 context1->SetSecurityToken(token);
12568 12568
12569 // Set an 'x' property on the Object prototype and define a 12569 // Set an 'x' property on the Object prototype and define a
12570 // constructor function in context0. 12570 // constructor function in context0.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
12685 bool regexp_success_; 12685 bool regexp_success_;
12686 bool gc_success_; 12686 bool gc_success_;
12687 }; 12687 };
12688 12688
12689 12689
12690 // Test that a regular expression execution can be interrupted and 12690 // Test that a regular expression execution can be interrupted and
12691 // survive a garbage collection. 12691 // survive a garbage collection.
12692 TEST(RegExpInterruption) { 12692 TEST(RegExpInterruption) {
12693 v8::Locker lock(CcTest::default_isolate()); 12693 v8::Locker lock(CcTest::default_isolate());
12694 v8::V8::Initialize(); 12694 v8::V8::Initialize();
12695 v8::HandleScope scope; 12695 v8::HandleScope scope(CcTest::default_isolate());
12696 Local<Context> local_env; 12696 Local<Context> local_env;
12697 { 12697 {
12698 LocalContext env; 12698 LocalContext env;
12699 local_env = env.local(); 12699 local_env = env.local();
12700 } 12700 }
12701 12701
12702 // Local context should still be live. 12702 // Local context should still be live.
12703 CHECK(!local_env.IsEmpty()); 12703 CHECK(!local_env.IsEmpty());
12704 local_env->Enter(); 12704 local_env->Enter();
12705 12705
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
12794 bool apply_success_; 12794 bool apply_success_;
12795 bool gc_success_; 12795 bool gc_success_;
12796 }; 12796 };
12797 12797
12798 12798
12799 // Test that nothing bad happens if we get a preemption just when we were 12799 // Test that nothing bad happens if we get a preemption just when we were
12800 // about to do an apply(). 12800 // about to do an apply().
12801 TEST(ApplyInterruption) { 12801 TEST(ApplyInterruption) {
12802 v8::Locker lock(CcTest::default_isolate()); 12802 v8::Locker lock(CcTest::default_isolate());
12803 v8::V8::Initialize(); 12803 v8::V8::Initialize();
12804 v8::HandleScope scope; 12804 v8::HandleScope scope(CcTest::default_isolate());
12805 Local<Context> local_env; 12805 Local<Context> local_env;
12806 { 12806 {
12807 LocalContext env; 12807 LocalContext env;
12808 local_env = env.local(); 12808 local_env = env.local();
12809 } 12809 }
12810 12810
12811 // Local context should still be live. 12811 // Local context should still be live.
12812 CHECK(!local_env.IsEmpty()); 12812 CHECK(!local_env.IsEmpty());
12813 local_env->Enter(); 12813 local_env->Enter();
12814 12814
12815 // Should complete without problems. 12815 // Should complete without problems.
12816 ApplyInterruptTest().RunTest(); 12816 ApplyInterruptTest().RunTest();
12817 12817
12818 local_env->Exit(); 12818 local_env->Exit();
12819 } 12819 }
12820 12820
12821 12821
12822 // Verify that we can clone an object 12822 // Verify that we can clone an object
12823 TEST(ObjectClone) { 12823 TEST(ObjectClone) {
12824 v8::HandleScope scope;
12825 LocalContext env; 12824 LocalContext env;
12825 v8::HandleScope scope(env->GetIsolate());
12826 12826
12827 const char* sample = 12827 const char* sample =
12828 "var rv = {};" \ 12828 "var rv = {};" \
12829 "rv.alpha = 'hello';" \ 12829 "rv.alpha = 'hello';" \
12830 "rv.beta = 123;" \ 12830 "rv.beta = 123;" \
12831 "rv;"; 12831 "rv;";
12832 12832
12833 // Create an object, verify basics. 12833 // Create an object, verify basics.
12834 Local<Value> val = CompileRun(sample); 12834 Local<Value> val = CompileRun(sample);
12835 CHECK(val->IsObject()); 12835 CHECK(val->IsObject());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
12902 12902
12903 12903
12904 // Test that we can still flatten a string if the components it is built up 12904 // Test that we can still flatten a string if the components it is built up
12905 // from have been turned into 16 bit strings in the mean time. 12905 // from have been turned into 16 bit strings in the mean time.
12906 THREADED_TEST(MorphCompositeStringTest) { 12906 THREADED_TEST(MorphCompositeStringTest) {
12907 char utf_buffer[129]; 12907 char utf_buffer[129];
12908 const char* c_string = "Now is the time for all good men" 12908 const char* c_string = "Now is the time for all good men"
12909 " to come to the aid of the party"; 12909 " to come to the aid of the party";
12910 uint16_t* two_byte_string = AsciiToTwoByteString(c_string); 12910 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
12911 { 12911 {
12912 v8::HandleScope scope;
12913 LocalContext env; 12912 LocalContext env;
12913 v8::HandleScope scope(env->GetIsolate());
12914 AsciiVectorResource ascii_resource( 12914 AsciiVectorResource ascii_resource(
12915 i::Vector<const char>(c_string, i::StrLength(c_string))); 12915 i::Vector<const char>(c_string, i::StrLength(c_string)));
12916 UC16VectorResource uc16_resource( 12916 UC16VectorResource uc16_resource(
12917 i::Vector<const uint16_t>(two_byte_string, 12917 i::Vector<const uint16_t>(two_byte_string,
12918 i::StrLength(c_string))); 12918 i::StrLength(c_string)));
12919 12919
12920 Local<String> lhs(v8::Utils::ToLocal( 12920 Local<String> lhs(v8::Utils::ToLocal(
12921 FACTORY->NewExternalStringFromAscii(&ascii_resource))); 12921 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
12922 Local<String> rhs(v8::Utils::ToLocal( 12922 Local<String> rhs(v8::Utils::ToLocal(
12923 FACTORY->NewExternalStringFromAscii(&ascii_resource))); 12923 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
12967 CHECK_EQ(String::New(expected_slice), 12967 CHECK_EQ(String::New(expected_slice),
12968 env->Global()->Get(v8_str("slice"))); 12968 env->Global()->Get(v8_str("slice")));
12969 CHECK_EQ(String::New(expected_slice_on_cons), 12969 CHECK_EQ(String::New(expected_slice_on_cons),
12970 env->Global()->Get(v8_str("slice_on_cons"))); 12970 env->Global()->Get(v8_str("slice_on_cons")));
12971 } 12971 }
12972 i::DeleteArray(two_byte_string); 12972 i::DeleteArray(two_byte_string);
12973 } 12973 }
12974 12974
12975 12975
12976 TEST(CompileExternalTwoByteSource) { 12976 TEST(CompileExternalTwoByteSource) {
12977 v8::HandleScope scope;
12978 LocalContext context; 12977 LocalContext context;
12978 v8::HandleScope scope(context->GetIsolate());
12979 12979
12980 // This is a very short list of sources, which currently is to check for a 12980 // This is a very short list of sources, which currently is to check for a
12981 // regression caused by r2703. 12981 // regression caused by r2703.
12982 const char* ascii_sources[] = { 12982 const char* ascii_sources[] = {
12983 "0.5", 12983 "0.5",
12984 "-0.5", // This mainly testes PushBack in the Scanner. 12984 "-0.5", // This mainly testes PushBack in the Scanner.
12985 "--0.5", // This mainly testes PushBack in the Scanner. 12985 "--0.5", // This mainly testes PushBack in the Scanner.
12986 NULL 12986 NULL
12987 }; 12987 };
12988 12988
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
13076 } 13076 }
13077 morph_success_ = true; 13077 morph_success_ = true;
13078 } 13078 }
13079 13079
13080 void LongRunningRegExp() { 13080 void LongRunningRegExp() {
13081 block_->Signal(); // Enable morphing thread on next preemption. 13081 block_->Signal(); // Enable morphing thread on next preemption.
13082 while (morphs_during_regexp_ < kRequiredModifications && 13082 while (morphs_during_regexp_ < kRequiredModifications &&
13083 morphs_ < kMaxModifications) { 13083 morphs_ < kMaxModifications) {
13084 int morphs_before = morphs_; 13084 int morphs_before = morphs_;
13085 { 13085 {
13086 v8::HandleScope scope; 13086 v8::HandleScope scope(v8::Isolate::GetCurrent());
13087 // Match 15-30 "a"'s against 14 and a "b". 13087 // Match 15-30 "a"'s against 14 and a "b".
13088 const char* c_source = 13088 const char* c_source =
13089 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/" 13089 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
13090 ".exec(input) === null"; 13090 ".exec(input) === null";
13091 Local<String> source = String::New(c_source); 13091 Local<String> source = String::New(c_source);
13092 Local<Script> script = Script::Compile(source); 13092 Local<Script> script = Script::Compile(source);
13093 Local<Value> result = script->Run(); 13093 Local<Value> result = script->Run();
13094 CHECK(result->IsTrue()); 13094 CHECK(result->IsTrue());
13095 } 13095 }
13096 int morphs_after = morphs_; 13096 int morphs_after = morphs_;
(...skipping 12 matching lines...) Expand all
13109 AsciiVectorResource ascii_resource_; 13109 AsciiVectorResource ascii_resource_;
13110 UC16VectorResource uc16_resource_; 13110 UC16VectorResource uc16_resource_;
13111 }; 13111 };
13112 13112
13113 13113
13114 // Test that a regular expression execution can be interrupted and 13114 // Test that a regular expression execution can be interrupted and
13115 // the string changed without failing. 13115 // the string changed without failing.
13116 TEST(RegExpStringModification) { 13116 TEST(RegExpStringModification) {
13117 v8::Locker lock(CcTest::default_isolate()); 13117 v8::Locker lock(CcTest::default_isolate());
13118 v8::V8::Initialize(); 13118 v8::V8::Initialize();
13119 v8::HandleScope scope; 13119 v8::HandleScope scope(CcTest::default_isolate());
13120 Local<Context> local_env; 13120 Local<Context> local_env;
13121 { 13121 {
13122 LocalContext env; 13122 LocalContext env;
13123 local_env = env.local(); 13123 local_env = env.local();
13124 } 13124 }
13125 13125
13126 // Local context should still be live. 13126 // Local context should still be live.
13127 CHECK(!local_env.IsEmpty()); 13127 CHECK(!local_env.IsEmpty());
13128 local_env->Enter(); 13128 local_env->Enter();
13129 13129
13130 // Should complete without problems. 13130 // Should complete without problems.
13131 RegExpStringModificationTest().RunTest(); 13131 RegExpStringModificationTest().RunTest();
13132 13132
13133 local_env->Exit(); 13133 local_env->Exit();
13134 } 13134 }
13135 13135
13136 13136
13137 // Test that we cannot set a property on the global object if there 13137 // Test that we cannot set a property on the global object if there
13138 // is a read-only property in the prototype chain. 13138 // is a read-only property in the prototype chain.
13139 TEST(ReadOnlyPropertyInGlobalProto) { 13139 TEST(ReadOnlyPropertyInGlobalProto) {
13140 i::FLAG_es5_readonly = true; 13140 i::FLAG_es5_readonly = true;
13141 v8::HandleScope scope; 13141 v8::HandleScope scope(v8::Isolate::GetCurrent());
13142 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13142 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13143 LocalContext context(0, templ); 13143 LocalContext context(0, templ);
13144 v8::Handle<v8::Object> global = context->Global(); 13144 v8::Handle<v8::Object> global = context->Global();
13145 v8::Handle<v8::Object> global_proto = 13145 v8::Handle<v8::Object> global_proto =
13146 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 13146 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
13147 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); 13147 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly);
13148 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); 13148 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly);
13149 // Check without 'eval' or 'with'. 13149 // Check without 'eval' or 'with'.
13150 v8::Handle<v8::Value> res = 13150 v8::Handle<v8::Value> res =
13151 CompileRun("function f() { x = 42; return x; }; f()"); 13151 CompileRun("function f() { x = 42; return x; }; f()");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
13184 const v8::AccessorInfo& info) { 13184 const v8::AccessorInfo& info) {
13185 force_set_set_count++; 13185 force_set_set_count++;
13186 return v8::Undefined(); 13186 return v8::Undefined();
13187 } 13187 }
13188 13188
13189 TEST(ForceSet) { 13189 TEST(ForceSet) {
13190 force_set_get_count = 0; 13190 force_set_get_count = 0;
13191 force_set_set_count = 0; 13191 force_set_set_count = 0;
13192 pass_on_get = false; 13192 pass_on_get = false;
13193 13193
13194 v8::HandleScope scope; 13194 v8::HandleScope scope(v8::Isolate::GetCurrent());
13195 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13195 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13196 v8::Handle<v8::String> access_property = v8::String::New("a"); 13196 v8::Handle<v8::String> access_property = v8::String::New("a");
13197 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 13197 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
13198 LocalContext context(NULL, templ); 13198 LocalContext context(NULL, templ);
13199 v8::Handle<v8::Object> global = context->Global(); 13199 v8::Handle<v8::Object> global = context->Global();
13200 13200
13201 // Ordinary properties 13201 // Ordinary properties
13202 v8::Handle<v8::String> simple_property = v8::String::New("p"); 13202 v8::Handle<v8::String> simple_property = v8::String::New("p");
13203 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); 13203 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly);
13204 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 13204 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
(...skipping 20 matching lines...) Expand all
13225 CHECK_EQ(8, global->Get(access_property)->Int32Value()); 13225 CHECK_EQ(8, global->Get(access_property)->Int32Value());
13226 CHECK_EQ(1, force_set_set_count); 13226 CHECK_EQ(1, force_set_set_count);
13227 CHECK_EQ(2, force_set_get_count); 13227 CHECK_EQ(2, force_set_get_count);
13228 } 13228 }
13229 13229
13230 TEST(ForceSetWithInterceptor) { 13230 TEST(ForceSetWithInterceptor) {
13231 force_set_get_count = 0; 13231 force_set_get_count = 0;
13232 force_set_set_count = 0; 13232 force_set_set_count = 0;
13233 pass_on_get = false; 13233 pass_on_get = false;
13234 13234
13235 v8::HandleScope scope; 13235 v8::HandleScope scope(v8::Isolate::GetCurrent());
13236 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13236 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13237 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 13237 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
13238 LocalContext context(NULL, templ); 13238 LocalContext context(NULL, templ);
13239 v8::Handle<v8::Object> global = context->Global(); 13239 v8::Handle<v8::Object> global = context->Global();
13240 13240
13241 v8::Handle<v8::String> some_property = v8::String::New("a"); 13241 v8::Handle<v8::String> some_property = v8::String::New("a");
13242 CHECK_EQ(0, force_set_set_count); 13242 CHECK_EQ(0, force_set_set_count);
13243 CHECK_EQ(0, force_set_get_count); 13243 CHECK_EQ(0, force_set_get_count);
13244 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 13244 CHECK_EQ(3, global->Get(some_property)->Int32Value());
13245 // Setting the property shouldn't override it, just call the setter 13245 // Setting the property shouldn't override it, just call the setter
(...skipping 22 matching lines...) Expand all
13268 CHECK_EQ(1, force_set_set_count); 13268 CHECK_EQ(1, force_set_set_count);
13269 CHECK_EQ(5, force_set_get_count); 13269 CHECK_EQ(5, force_set_get_count);
13270 // The interceptor should also work for other properties 13270 // The interceptor should also work for other properties
13271 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); 13271 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value());
13272 CHECK_EQ(1, force_set_set_count); 13272 CHECK_EQ(1, force_set_set_count);
13273 CHECK_EQ(6, force_set_get_count); 13273 CHECK_EQ(6, force_set_get_count);
13274 } 13274 }
13275 13275
13276 13276
13277 THREADED_TEST(ForceDelete) { 13277 THREADED_TEST(ForceDelete) {
13278 v8::HandleScope scope; 13278 v8::HandleScope scope(v8::Isolate::GetCurrent());
13279 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13279 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13280 LocalContext context(NULL, templ); 13280 LocalContext context(NULL, templ);
13281 v8::Handle<v8::Object> global = context->Global(); 13281 v8::Handle<v8::Object> global = context->Global();
13282 13282
13283 // Ordinary properties 13283 // Ordinary properties
13284 v8::Handle<v8::String> simple_property = v8::String::New("p"); 13284 v8::Handle<v8::String> simple_property = v8::String::New("p");
13285 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); 13285 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete);
13286 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 13286 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
13287 // This should fail because the property is dont-delete. 13287 // This should fail because the property is dont-delete.
13288 CHECK(!global->Delete(simple_property)); 13288 CHECK(!global->Delete(simple_property));
(...skipping 17 matching lines...) Expand all
13306 } else { 13306 } else {
13307 return v8::True(); 13307 return v8::True();
13308 } 13308 }
13309 } 13309 }
13310 13310
13311 13311
13312 THREADED_TEST(ForceDeleteWithInterceptor) { 13312 THREADED_TEST(ForceDeleteWithInterceptor) {
13313 force_delete_interceptor_count = 0; 13313 force_delete_interceptor_count = 0;
13314 pass_on_delete = false; 13314 pass_on_delete = false;
13315 13315
13316 v8::HandleScope scope; 13316 v8::HandleScope scope(v8::Isolate::GetCurrent());
13317 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13317 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13318 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 13318 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
13319 LocalContext context(NULL, templ); 13319 LocalContext context(NULL, templ);
13320 v8::Handle<v8::Object> global = context->Global(); 13320 v8::Handle<v8::Object> global = context->Global();
13321 13321
13322 v8::Handle<v8::String> some_property = v8::String::New("a"); 13322 v8::Handle<v8::String> some_property = v8::String::New("a");
13323 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); 13323 global->Set(some_property, v8::Integer::New(42), v8::DontDelete);
13324 13324
13325 // Deleting a property should get intercepted and nothing should 13325 // Deleting a property should get intercepted and nothing should
13326 // happen. 13326 // happen.
(...skipping 11 matching lines...) Expand all
13338 // without calling the interceptor. 13338 // without calling the interceptor.
13339 CHECK(global->ForceDelete(some_property)); 13339 CHECK(global->ForceDelete(some_property));
13340 CHECK(global->Get(some_property)->IsUndefined()); 13340 CHECK(global->Get(some_property)->IsUndefined());
13341 CHECK_EQ(2, force_delete_interceptor_count); 13341 CHECK_EQ(2, force_delete_interceptor_count);
13342 } 13342 }
13343 13343
13344 13344
13345 // Make sure that forcing a delete invalidates any IC stubs, so we 13345 // Make sure that forcing a delete invalidates any IC stubs, so we
13346 // don't read the hole value. 13346 // don't read the hole value.
13347 THREADED_TEST(ForceDeleteIC) { 13347 THREADED_TEST(ForceDeleteIC) {
13348 v8::HandleScope scope;
13349 LocalContext context; 13348 LocalContext context;
13349 v8::HandleScope scope(context->GetIsolate());
13350 // Create a DontDelete variable on the global object. 13350 // Create a DontDelete variable on the global object.
13351 CompileRun("this.__proto__ = { foo: 'horse' };" 13351 CompileRun("this.__proto__ = { foo: 'horse' };"
13352 "var foo = 'fish';" 13352 "var foo = 'fish';"
13353 "function f() { return foo.length; }"); 13353 "function f() { return foo.length; }");
13354 // Initialize the IC for foo in f. 13354 // Initialize the IC for foo in f.
13355 CompileRun("for (var i = 0; i < 4; i++) f();"); 13355 CompileRun("for (var i = 0; i < 4; i++) f();");
13356 // Make sure the value of foo is correct before the deletion. 13356 // Make sure the value of foo is correct before the deletion.
13357 CHECK_EQ(4, CompileRun("f()")->Int32Value()); 13357 CHECK_EQ(4, CompileRun("f()")->Int32Value());
13358 // Force the deletion of foo. 13358 // Force the deletion of foo.
13359 CHECK(context->Global()->ForceDelete(v8_str("foo"))); 13359 CHECK(context->Global()->ForceDelete(v8_str("foo")));
13360 // Make sure the value for foo is read from the prototype, and that 13360 // Make sure the value for foo is read from the prototype, and that
13361 // we don't get in trouble with reading the deleted cell value 13361 // we don't get in trouble with reading the deleted cell value
13362 // sentinel. 13362 // sentinel.
13363 CHECK_EQ(5, CompileRun("f()")->Int32Value()); 13363 CHECK_EQ(5, CompileRun("f()")->Int32Value());
13364 } 13364 }
13365 13365
13366 13366
13367 TEST(InlinedFunctionAcrossContexts) { 13367 TEST(InlinedFunctionAcrossContexts) {
13368 i::FLAG_allow_natives_syntax = true; 13368 i::FLAG_allow_natives_syntax = true;
13369 v8::HandleScope outer_scope; 13369 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
13370 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 13370 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
13371 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 13371 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
13372 ctx1->Enter(); 13372 ctx1->Enter();
13373 13373
13374 { 13374 {
13375 v8::HandleScope inner_scope; 13375 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
13376 CompileRun("var G = 42; function foo() { return G; }"); 13376 CompileRun("var G = 42; function foo() { return G; }");
13377 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo")); 13377 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo"));
13378 ctx2->Enter(); 13378 ctx2->Enter();
13379 ctx2->Global()->Set(v8_str("o"), foo); 13379 ctx2->Global()->Set(v8_str("o"), foo);
13380 v8::Local<v8::Value> res = CompileRun( 13380 v8::Local<v8::Value> res = CompileRun(
13381 "function f() { return o(); }" 13381 "function f() { return o(); }"
13382 "for (var i = 0; i < 10; ++i) f();" 13382 "for (var i = 0; i < 10; ++i) f();"
13383 "%OptimizeFunctionOnNextCall(f);" 13383 "%OptimizeFunctionOnNextCall(f);"
13384 "f();"); 13384 "f();");
13385 CHECK_EQ(42, res->Int32Value()); 13385 CHECK_EQ(42, res->Int32Value());
(...skipping 29 matching lines...) Expand all
13415 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) { 13415 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) {
13416 ApiTestFuzzer::Fuzz(); 13416 ApiTestFuzzer::Fuzz();
13417 CHECK(Context::GetCurrent() == calling_context0); 13417 CHECK(Context::GetCurrent() == calling_context0);
13418 CHECK(Context::GetCalling() == calling_context1); 13418 CHECK(Context::GetCalling() == calling_context1);
13419 CHECK(Context::GetEntered() == calling_context2); 13419 CHECK(Context::GetEntered() == calling_context2);
13420 return v8::Integer::New(42); 13420 return v8::Integer::New(42);
13421 } 13421 }
13422 13422
13423 13423
13424 THREADED_TEST(GetCallingContext) { 13424 THREADED_TEST(GetCallingContext) {
13425 v8::HandleScope scope; 13425 v8::HandleScope scope(v8::Isolate::GetCurrent());
13426 13426
13427 calling_context0 = Context::New(); 13427 calling_context0 = Context::New();
13428 calling_context1 = Context::New(); 13428 calling_context1 = Context::New();
13429 calling_context2 = Context::New(); 13429 calling_context2 = Context::New();
13430 13430
13431 // Allow cross-domain access. 13431 // Allow cross-domain access.
13432 Local<String> token = v8_str("<security token>"); 13432 Local<String> token = v8_str("<security token>");
13433 calling_context0->SetSecurityToken(token); 13433 calling_context0->SetSecurityToken(token);
13434 calling_context1->SetSecurityToken(token); 13434 calling_context1->SetSecurityToken(token);
13435 calling_context2->SetSecurityToken(token); 13435 calling_context2->SetSecurityToken(token);
(...skipping 29 matching lines...) Expand all
13465 calling_context0.Clear(); 13465 calling_context0.Clear();
13466 calling_context1.Clear(); 13466 calling_context1.Clear();
13467 calling_context2.Clear(); 13467 calling_context2.Clear();
13468 } 13468 }
13469 13469
13470 13470
13471 // Check that a variable declaration with no explicit initialization 13471 // Check that a variable declaration with no explicit initialization
13472 // value does shadow an existing property in the prototype chain. 13472 // value does shadow an existing property in the prototype chain.
13473 THREADED_TEST(InitGlobalVarInProtoChain) { 13473 THREADED_TEST(InitGlobalVarInProtoChain) {
13474 i::FLAG_es52_globals = true; 13474 i::FLAG_es52_globals = true;
13475 v8::HandleScope scope;
13476 LocalContext context; 13475 LocalContext context;
13476 v8::HandleScope scope(context->GetIsolate());
13477 // Introduce a variable in the prototype chain. 13477 // Introduce a variable in the prototype chain.
13478 CompileRun("__proto__.x = 42"); 13478 CompileRun("__proto__.x = 42");
13479 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); 13479 v8::Handle<v8::Value> result = CompileRun("var x = 43; x");
13480 CHECK(!result->IsUndefined()); 13480 CHECK(!result->IsUndefined());
13481 CHECK_EQ(43, result->Int32Value()); 13481 CHECK_EQ(43, result->Int32Value());
13482 } 13482 }
13483 13483
13484 13484
13485 // Regression test for issue 398. 13485 // Regression test for issue 398.
13486 // If a function is added to an object, creating a constant function 13486 // If a function is added to an object, creating a constant function
13487 // field, and the result is cloned, replacing the constant function on the 13487 // field, and the result is cloned, replacing the constant function on the
13488 // original should not affect the clone. 13488 // original should not affect the clone.
13489 // See http://code.google.com/p/v8/issues/detail?id=398 13489 // See http://code.google.com/p/v8/issues/detail?id=398
13490 THREADED_TEST(ReplaceConstantFunction) { 13490 THREADED_TEST(ReplaceConstantFunction) {
13491 v8::HandleScope scope;
13492 LocalContext context; 13491 LocalContext context;
13492 v8::HandleScope scope(context->GetIsolate());
13493 v8::Handle<v8::Object> obj = v8::Object::New(); 13493 v8::Handle<v8::Object> obj = v8::Object::New();
13494 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 13494 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
13495 v8::Handle<v8::String> foo_string = v8::String::New("foo"); 13495 v8::Handle<v8::String> foo_string = v8::String::New("foo");
13496 obj->Set(foo_string, func_templ->GetFunction()); 13496 obj->Set(foo_string, func_templ->GetFunction());
13497 v8::Handle<v8::Object> obj_clone = obj->Clone(); 13497 v8::Handle<v8::Object> obj_clone = obj->Clone();
13498 obj_clone->Set(foo_string, v8::String::New("Hello")); 13498 obj_clone->Set(foo_string, v8::String::New("Hello"));
13499 CHECK(!obj->Get(foo_string)->IsUndefined()); 13499 CHECK(!obj->Get(foo_string)->IsUndefined());
13500 } 13500 }
13501 13501
13502 13502
13503 // Regression test for http://crbug.com/16276. 13503 // Regression test for http://crbug.com/16276.
13504 THREADED_TEST(Regress16276) { 13504 THREADED_TEST(Regress16276) {
13505 v8::HandleScope scope;
13506 LocalContext context; 13505 LocalContext context;
13506 v8::HandleScope scope(context->GetIsolate());
13507 // Force the IC in f to be a dictionary load IC. 13507 // Force the IC in f to be a dictionary load IC.
13508 CompileRun("function f(obj) { return obj.x; }\n" 13508 CompileRun("function f(obj) { return obj.x; }\n"
13509 "var obj = { x: { foo: 42 }, y: 87 };\n" 13509 "var obj = { x: { foo: 42 }, y: 87 };\n"
13510 "var x = obj.x;\n" 13510 "var x = obj.x;\n"
13511 "delete obj.y;\n" 13511 "delete obj.y;\n"
13512 "for (var i = 0; i < 5; i++) f(obj);"); 13512 "for (var i = 0; i < 5; i++) f(obj);");
13513 // Detach the global object to make 'this' refer directly to the 13513 // Detach the global object to make 'this' refer directly to the
13514 // global object (not the proxy), and make sure that the dictionary 13514 // global object (not the proxy), and make sure that the dictionary
13515 // load IC doesn't mess up loading directly from the global object. 13515 // load IC doesn't mess up loading directly from the global object.
13516 context->DetachGlobal(); 13516 context->DetachGlobal();
13517 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 13517 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
13518 } 13518 }
13519 13519
13520 13520
13521 THREADED_TEST(PixelArray) { 13521 THREADED_TEST(PixelArray) {
13522 v8::HandleScope scope;
13523 LocalContext context; 13522 LocalContext context;
13523 v8::HandleScope scope(context->GetIsolate());
13524 const int kElementCount = 260; 13524 const int kElementCount = 260;
13525 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 13525 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13526 i::Handle<i::ExternalPixelArray> pixels = 13526 i::Handle<i::ExternalPixelArray> pixels =
13527 i::Handle<i::ExternalPixelArray>::cast( 13527 i::Handle<i::ExternalPixelArray>::cast(
13528 FACTORY->NewExternalArray(kElementCount, 13528 FACTORY->NewExternalArray(kElementCount,
13529 v8::kExternalPixelArray, 13529 v8::kExternalPixelArray,
13530 pixel_data)); 13530 pixel_data));
13531 // Force GC to trigger verification. 13531 // Force GC to trigger verification.
13532 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 13532 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
13533 for (int i = 0; i < kElementCount; i++) { 13533 for (int i = 0; i < kElementCount; i++) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
13902 "}" 13902 "}"
13903 "result = pa_load(pixels);" 13903 "result = pa_load(pixels);"
13904 "result"); 13904 "result");
13905 CHECK_EQ(32640, result->Int32Value()); 13905 CHECK_EQ(32640, result->Int32Value());
13906 13906
13907 free(pixel_data); 13907 free(pixel_data);
13908 } 13908 }
13909 13909
13910 13910
13911 THREADED_TEST(PixelArrayInfo) { 13911 THREADED_TEST(PixelArrayInfo) {
13912 v8::HandleScope scope;
13913 LocalContext context; 13912 LocalContext context;
13913 v8::HandleScope scope(context->GetIsolate());
13914 for (int size = 0; size < 100; size += 10) { 13914 for (int size = 0; size < 100; size += 10) {
13915 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 13915 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
13916 v8::Handle<v8::Object> obj = v8::Object::New(); 13916 v8::Handle<v8::Object> obj = v8::Object::New();
13917 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 13917 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
13918 CHECK(obj->HasIndexedPropertiesInPixelData()); 13918 CHECK(obj->HasIndexedPropertiesInPixelData());
13919 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 13919 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
13920 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 13920 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
13921 free(pixel_data); 13921 free(pixel_data);
13922 } 13922 }
13923 } 13923 }
(...skipping 10 matching lines...) Expand all
13934 static v8::Handle<Value> NotHandledIndexedPropertySetter( 13934 static v8::Handle<Value> NotHandledIndexedPropertySetter(
13935 uint32_t index, 13935 uint32_t index,
13936 Local<Value> value, 13936 Local<Value> value,
13937 const AccessorInfo& info) { 13937 const AccessorInfo& info) {
13938 ApiTestFuzzer::Fuzz(); 13938 ApiTestFuzzer::Fuzz();
13939 return v8::Handle<Value>(); 13939 return v8::Handle<Value>();
13940 } 13940 }
13941 13941
13942 13942
13943 THREADED_TEST(PixelArrayWithInterceptor) { 13943 THREADED_TEST(PixelArrayWithInterceptor) {
13944 v8::HandleScope scope;
13945 LocalContext context; 13944 LocalContext context;
13945 v8::HandleScope scope(context->GetIsolate());
13946 const int kElementCount = 260; 13946 const int kElementCount = 260;
13947 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 13947 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13948 i::Handle<i::ExternalPixelArray> pixels = 13948 i::Handle<i::ExternalPixelArray> pixels =
13949 i::Handle<i::ExternalPixelArray>::cast( 13949 i::Handle<i::ExternalPixelArray>::cast(
13950 FACTORY->NewExternalArray(kElementCount, 13950 FACTORY->NewExternalArray(kElementCount,
13951 v8::kExternalPixelArray, 13951 v8::kExternalPixelArray,
13952 pixel_data)); 13952 pixel_data));
13953 for (int i = 0; i < kElementCount; i++) { 13953 for (int i = 0; i < kElementCount; i++) {
13954 pixels->set(i, i % 256); 13954 pixels->set(i, i % 256);
13955 } 13955 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
13998 } 13998 }
13999 UNREACHABLE(); 13999 UNREACHABLE();
14000 return -1; 14000 return -1;
14001 } 14001 }
14002 14002
14003 14003
14004 template <class ExternalArrayClass, class ElementType> 14004 template <class ExternalArrayClass, class ElementType>
14005 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, 14005 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
14006 int64_t low, 14006 int64_t low,
14007 int64_t high) { 14007 int64_t high) {
14008 v8::HandleScope scope;
14009 LocalContext context; 14008 LocalContext context;
14009 v8::HandleScope scope(context->GetIsolate());
14010 const int kElementCount = 40; 14010 const int kElementCount = 40;
14011 int element_size = ExternalArrayElementSize(array_type); 14011 int element_size = ExternalArrayElementSize(array_type);
14012 ElementType* array_data = 14012 ElementType* array_data =
14013 static_cast<ElementType*>(malloc(kElementCount * element_size)); 14013 static_cast<ElementType*>(malloc(kElementCount * element_size));
14014 i::Handle<ExternalArrayClass> array = 14014 i::Handle<ExternalArrayClass> array =
14015 i::Handle<ExternalArrayClass>::cast( 14015 i::Handle<ExternalArrayClass>::cast(
14016 FACTORY->NewExternalArray(kElementCount, array_type, array_data)); 14016 FACTORY->NewExternalArray(kElementCount, array_type, array_data));
14017 // Force GC to trigger verification. 14017 // Force GC to trigger verification.
14018 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 14018 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
14019 for (int i = 0; i < kElementCount; i++) { 14019 for (int i = 0; i < kElementCount; i++) {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
14569 TestExternalUnsignedByteArray(); 14569 TestExternalUnsignedByteArray();
14570 TestExternalShortArray(); 14570 TestExternalShortArray();
14571 TestExternalUnsignedShortArray(); 14571 TestExternalUnsignedShortArray();
14572 TestExternalIntArray(); 14572 TestExternalIntArray();
14573 TestExternalUnsignedIntArray(); 14573 TestExternalUnsignedIntArray();
14574 TestExternalFloatArray(); 14574 TestExternalFloatArray();
14575 } 14575 }
14576 14576
14577 14577
14578 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { 14578 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
14579 v8::HandleScope scope;
14580 LocalContext context; 14579 LocalContext context;
14580 v8::HandleScope scope(context->GetIsolate());
14581 for (int size = 0; size < 100; size += 10) { 14581 for (int size = 0; size < 100; size += 10) {
14582 int element_size = ExternalArrayElementSize(array_type); 14582 int element_size = ExternalArrayElementSize(array_type);
14583 void* external_data = malloc(size * element_size); 14583 void* external_data = malloc(size * element_size);
14584 v8::Handle<v8::Object> obj = v8::Object::New(); 14584 v8::Handle<v8::Object> obj = v8::Object::New();
14585 obj->SetIndexedPropertiesToExternalArrayData( 14585 obj->SetIndexedPropertiesToExternalArrayData(
14586 external_data, array_type, size); 14586 external_data, array_type, size);
14587 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); 14587 CHECK(obj->HasIndexedPropertiesInExternalArrayData());
14588 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); 14588 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
14589 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); 14589 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
14590 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); 14590 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
(...skipping 20 matching lines...) Expand all
14611 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 14611 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
14612 last_location = last_message = NULL; 14612 last_location = last_message = NULL;
14613 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); 14613 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size);
14614 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); 14614 CHECK(!obj->HasIndexedPropertiesInExternalArrayData());
14615 CHECK_NE(NULL, last_location); 14615 CHECK_NE(NULL, last_location);
14616 CHECK_NE(NULL, last_message); 14616 CHECK_NE(NULL, last_message);
14617 } 14617 }
14618 14618
14619 14619
14620 TEST(ExternalArrayLimits) { 14620 TEST(ExternalArrayLimits) {
14621 v8::HandleScope scope;
14622 LocalContext context; 14621 LocalContext context;
14622 v8::HandleScope scope(context->GetIsolate());
14623 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000); 14623 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000);
14624 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff); 14624 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff);
14625 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000); 14625 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000);
14626 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff); 14626 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff);
14627 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000); 14627 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000);
14628 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff); 14628 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff);
14629 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000); 14629 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000);
14630 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff); 14630 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff);
14631 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000); 14631 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000);
14632 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff); 14632 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff);
14633 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000); 14633 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000);
14634 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff); 14634 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff);
14635 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000); 14635 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000);
14636 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff); 14636 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff);
14637 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000); 14637 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000);
14638 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff); 14638 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff);
14639 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); 14639 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000);
14640 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); 14640 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff);
14641 } 14641 }
14642 14642
14643 14643
14644 THREADED_TEST(ScriptContextDependence) { 14644 THREADED_TEST(ScriptContextDependence) {
14645 v8::HandleScope scope;
14646 LocalContext c1; 14645 LocalContext c1;
14646 v8::HandleScope scope(c1->GetIsolate());
14647 const char *source = "foo"; 14647 const char *source = "foo";
14648 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 14648 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
14649 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 14649 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
14650 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 14650 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
14651 CHECK_EQ(dep->Run()->Int32Value(), 100); 14651 CHECK_EQ(dep->Run()->Int32Value(), 100);
14652 CHECK_EQ(indep->Run()->Int32Value(), 100); 14652 CHECK_EQ(indep->Run()->Int32Value(), 100);
14653 LocalContext c2; 14653 LocalContext c2;
14654 c2->Global()->Set(v8::String::New("foo"), v8::Integer::New(101)); 14654 c2->Global()->Set(v8::String::New("foo"), v8::Integer::New(101));
14655 CHECK_EQ(dep->Run()->Int32Value(), 100); 14655 CHECK_EQ(dep->Run()->Int32Value(), 100);
14656 CHECK_EQ(indep->Run()->Int32Value(), 101); 14656 CHECK_EQ(indep->Run()->Int32Value(), 101);
14657 } 14657 }
14658 14658
14659 14659
14660 THREADED_TEST(StackTrace) { 14660 THREADED_TEST(StackTrace) {
14661 v8::HandleScope scope;
14662 LocalContext context; 14661 LocalContext context;
14662 v8::HandleScope scope(context->GetIsolate());
14663 v8::TryCatch try_catch; 14663 v8::TryCatch try_catch;
14664 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 14664 const char *source = "function foo() { FAIL.FAIL; }; foo();";
14665 v8::Handle<v8::String> src = v8::String::New(source); 14665 v8::Handle<v8::String> src = v8::String::New(source);
14666 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); 14666 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test");
14667 v8::Script::New(src, origin)->Run(); 14667 v8::Script::New(src, origin)->Run();
14668 CHECK(try_catch.HasCaught()); 14668 CHECK(try_catch.HasCaught());
14669 v8::String::Utf8Value stack(try_catch.StackTrace()); 14669 v8::String::Utf8Value stack(try_catch.StackTrace());
14670 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 14670 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
14671 } 14671 }
14672 14672
14673 14673
14674 // Checks that a StackFrame has certain expected values. 14674 // Checks that a StackFrame has certain expected values.
14675 void checkStackFrame(const char* expected_script_name, 14675 void checkStackFrame(const char* expected_script_name,
14676 const char* expected_func_name, int expected_line_number, 14676 const char* expected_func_name, int expected_line_number,
14677 int expected_column, bool is_eval, bool is_constructor, 14677 int expected_column, bool is_eval, bool is_constructor,
14678 v8::Handle<v8::StackFrame> frame) { 14678 v8::Handle<v8::StackFrame> frame) {
14679 v8::HandleScope scope; 14679 v8::HandleScope scope(v8::Isolate::GetCurrent());
14680 v8::String::Utf8Value func_name(frame->GetFunctionName()); 14680 v8::String::Utf8Value func_name(frame->GetFunctionName());
14681 v8::String::Utf8Value script_name(frame->GetScriptName()); 14681 v8::String::Utf8Value script_name(frame->GetScriptName());
14682 if (*script_name == NULL) { 14682 if (*script_name == NULL) {
14683 // The situation where there is no associated script, like for evals. 14683 // The situation where there is no associated script, like for evals.
14684 CHECK(expected_script_name == NULL); 14684 CHECK(expected_script_name == NULL);
14685 } else { 14685 } else {
14686 CHECK(strstr(*script_name, expected_script_name) != NULL); 14686 CHECK(strstr(*script_name, expected_script_name) != NULL);
14687 } 14687 }
14688 CHECK(strstr(*func_name, expected_func_name) != NULL); 14688 CHECK(strstr(*func_name, expected_func_name) != NULL);
14689 CHECK_EQ(expected_line_number, frame->GetLineNumber()); 14689 CHECK_EQ(expected_line_number, frame->GetLineNumber());
14690 CHECK_EQ(expected_column, frame->GetColumn()); 14690 CHECK_EQ(expected_column, frame->GetColumn());
14691 CHECK_EQ(is_eval, frame->IsEval()); 14691 CHECK_EQ(is_eval, frame->IsEval());
14692 CHECK_EQ(is_constructor, frame->IsConstructor()); 14692 CHECK_EQ(is_constructor, frame->IsConstructor());
14693 } 14693 }
14694 14694
14695 14695
14696 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) { 14696 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) {
14697 v8::HandleScope scope; 14697 v8::HandleScope scope(args.GetIsolate());
14698 const char* origin = "capture-stack-trace-test"; 14698 const char* origin = "capture-stack-trace-test";
14699 const int kOverviewTest = 1; 14699 const int kOverviewTest = 1;
14700 const int kDetailedTest = 2; 14700 const int kDetailedTest = 2;
14701 14701
14702 ASSERT(args.Length() == 1); 14702 ASSERT(args.Length() == 1);
14703 14703
14704 int testGroup = args[0]->Int32Value(); 14704 int testGroup = args[0]->Int32Value();
14705 if (testGroup == kOverviewTest) { 14705 if (testGroup == kOverviewTest) {
14706 v8::Handle<v8::StackTrace> stackTrace = 14706 v8::Handle<v8::StackTrace> stackTrace =
14707 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview); 14707 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
14742 CHECK(stackTrace->AsArray()->IsArray()); 14742 CHECK(stackTrace->AsArray()->IsArray());
14743 } 14743 }
14744 return v8::Undefined(); 14744 return v8::Undefined();
14745 } 14745 }
14746 14746
14747 14747
14748 // Tests the C++ StackTrace API. 14748 // Tests the C++ StackTrace API.
14749 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 14749 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
14750 // THREADED_TEST(CaptureStackTrace) { 14750 // THREADED_TEST(CaptureStackTrace) {
14751 TEST(CaptureStackTrace) { 14751 TEST(CaptureStackTrace) {
14752 v8::HandleScope scope; 14752 v8::HandleScope scope(v8::Isolate::GetCurrent());
14753 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); 14753 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test");
14754 Local<ObjectTemplate> templ = ObjectTemplate::New(); 14754 Local<ObjectTemplate> templ = ObjectTemplate::New();
14755 templ->Set(v8_str("AnalyzeStackInNativeCode"), 14755 templ->Set(v8_str("AnalyzeStackInNativeCode"),
14756 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); 14756 v8::FunctionTemplate::New(AnalyzeStackInNativeCode));
14757 LocalContext context(0, templ); 14757 LocalContext context(0, templ);
14758 14758
14759 // Test getting OVERVIEW information. Should ignore information that is not 14759 // Test getting OVERVIEW information. Should ignore information that is not
14760 // script name, function name, line number, and column offset. 14760 // script name, function name, line number, and column offset.
14761 const char *overview_source = 14761 const char *overview_source =
14762 "function bar() {\n" 14762 "function bar() {\n"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
14801 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14801 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14802 CHECK_EQ(2, stack_trace->GetFrameCount()); 14802 CHECK_EQ(2, stack_trace->GetFrameCount());
14803 checkStackFrame("origin", "foo", 2, 3, false, false, 14803 checkStackFrame("origin", "foo", 2, 3, false, false,
14804 stack_trace->GetFrame(0)); 14804 stack_trace->GetFrame(0));
14805 checkStackFrame("origin", "bar", 5, 3, false, false, 14805 checkStackFrame("origin", "bar", 5, 3, false, false,
14806 stack_trace->GetFrame(1)); 14806 stack_trace->GetFrame(1));
14807 } 14807 }
14808 14808
14809 TEST(CaptureStackTraceForUncaughtException) { 14809 TEST(CaptureStackTraceForUncaughtException) {
14810 report_count = 0; 14810 report_count = 0;
14811 v8::HandleScope scope;
14812 LocalContext env; 14811 LocalContext env;
14812 v8::HandleScope scope(env->GetIsolate());
14813 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener); 14813 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener);
14814 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14814 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14815 14815
14816 Script::Compile(v8_str("function foo() {\n" 14816 Script::Compile(v8_str("function foo() {\n"
14817 " throw 1;\n" 14817 " throw 1;\n"
14818 "};\n" 14818 "};\n"
14819 "function bar() {\n" 14819 "function bar() {\n"
14820 " foo();\n" 14820 " foo();\n"
14821 "};"), 14821 "};"),
14822 v8_str("origin"))->Run(); 14822 v8_str("origin"))->Run();
14823 v8::Local<v8::Object> global = env->Global(); 14823 v8::Local<v8::Object> global = env->Global();
14824 Local<Value> trouble = global->Get(v8_str("bar")); 14824 Local<Value> trouble = global->Get(v8_str("bar"));
14825 CHECK(trouble->IsFunction()); 14825 CHECK(trouble->IsFunction());
14826 Function::Cast(*trouble)->Call(global, 0, NULL); 14826 Function::Cast(*trouble)->Call(global, 0, NULL);
14827 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14827 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14828 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); 14828 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
14829 } 14829 }
14830 14830
14831 14831
14832 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { 14832 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
14833 v8::HandleScope scope;
14834 LocalContext env; 14833 LocalContext env;
14834 v8::HandleScope scope(env->GetIsolate());
14835 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 14835 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true,
14836 1024, 14836 1024,
14837 v8::StackTrace::kDetailed); 14837 v8::StackTrace::kDetailed);
14838 14838
14839 CompileRun( 14839 CompileRun(
14840 "var setters = ['column', 'lineNumber', 'scriptName',\n" 14840 "var setters = ['column', 'lineNumber', 'scriptName',\n"
14841 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n" 14841 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
14842 " 'isConstructor'];\n" 14842 " 'isConstructor'];\n"
14843 "for (var i = 0; i < setters.length; i++) {\n" 14843 "for (var i = 0; i < setters.length; i++) {\n"
14844 " var prop = setters[i];\n" 14844 " var prop = setters[i];\n"
(...skipping 14 matching lines...) Expand all
14859 int line_number[] = {1, 2, 5}; 14859 int line_number[] = {1, 2, 5};
14860 for (int i = 0; i < frame_count; i++) { 14860 for (int i = 0; i < frame_count; i++) {
14861 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 14861 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14862 } 14862 }
14863 } 14863 }
14864 14864
14865 14865
14866 // Test that we only return the stack trace at the site where the exception 14866 // Test that we only return the stack trace at the site where the exception
14867 // is first thrown (not where it is rethrown). 14867 // is first thrown (not where it is rethrown).
14868 TEST(RethrowStackTrace) { 14868 TEST(RethrowStackTrace) {
14869 v8::HandleScope scope;
14870 LocalContext env; 14869 LocalContext env;
14870 v8::HandleScope scope(env->GetIsolate());
14871 // We make sure that 14871 // We make sure that
14872 // - the stack trace of the ReferenceError in g() is reported. 14872 // - the stack trace of the ReferenceError in g() is reported.
14873 // - the stack trace is not overwritten when e1 is rethrown by t(). 14873 // - the stack trace is not overwritten when e1 is rethrown by t().
14874 // - the stack trace of e2 does not overwrite that of e1. 14874 // - the stack trace of e2 does not overwrite that of e1.
14875 const char* source = 14875 const char* source =
14876 "function g() { error; } \n" 14876 "function g() { error; } \n"
14877 "function f() { g(); } \n" 14877 "function f() { g(); } \n"
14878 "function t(e) { throw e; } \n" 14878 "function t(e) { throw e; } \n"
14879 "try { \n" 14879 "try { \n"
14880 " f(); \n" 14880 " f(); \n"
(...skipping 20 matching lines...) Expand all
14901 CHECK_EQ(2, frame_count); 14901 CHECK_EQ(2, frame_count);
14902 int line_number[] = {3, 7}; 14902 int line_number[] = {3, 7};
14903 for (int i = 0; i < frame_count; i++) { 14903 for (int i = 0; i < frame_count; i++) {
14904 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 14904 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14905 } 14905 }
14906 } 14906 }
14907 14907
14908 14908
14909 // Test that we do not recognize identity for primitive exceptions. 14909 // Test that we do not recognize identity for primitive exceptions.
14910 TEST(RethrowPrimitiveStackTrace) { 14910 TEST(RethrowPrimitiveStackTrace) {
14911 v8::HandleScope scope;
14912 LocalContext env; 14911 LocalContext env;
14912 v8::HandleScope scope(env->GetIsolate());
14913 // We do not capture stack trace for non Error objects on creation time. 14913 // We do not capture stack trace for non Error objects on creation time.
14914 // Instead, we capture the stack trace on last throw. 14914 // Instead, we capture the stack trace on last throw.
14915 const char* source = 14915 const char* source =
14916 "function g() { throw 404; } \n" 14916 "function g() { throw 404; } \n"
14917 "function f() { g(); } \n" 14917 "function f() { g(); } \n"
14918 "function t(e) { throw e; } \n" 14918 "function t(e) { throw e; } \n"
14919 "try { \n" 14919 "try { \n"
14920 " f(); \n" 14920 " f(); \n"
14921 "} catch (e1) { \n" 14921 "} catch (e1) { \n"
14922 " t(e1) \n" 14922 " t(e1) \n"
(...skipping 12 matching lines...) Expand all
14935 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14935 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14936 CHECK(!stack_trace.IsEmpty()); 14936 CHECK(!stack_trace.IsEmpty());
14937 CHECK_EQ(1, stack_trace->GetFrameCount()); 14937 CHECK_EQ(1, stack_trace->GetFrameCount());
14938 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); 14938 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber());
14939 } 14939 }
14940 14940
14941 14941
14942 // Test that the stack trace is captured when the error object is created and 14942 // Test that the stack trace is captured when the error object is created and
14943 // not where it is thrown. 14943 // not where it is thrown.
14944 TEST(RethrowExistingStackTrace) { 14944 TEST(RethrowExistingStackTrace) {
14945 v8::HandleScope scope;
14946 LocalContext env; 14945 LocalContext env;
14946 v8::HandleScope scope(env->GetIsolate());
14947 const char* source = 14947 const char* source =
14948 "var e = new Error(); \n" 14948 "var e = new Error(); \n"
14949 "throw e; \n"; 14949 "throw e; \n";
14950 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler); 14950 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler);
14951 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14951 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14952 CompileRun(source); 14952 CompileRun(source);
14953 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14953 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14954 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler); 14954 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler);
14955 } 14955 }
14956 14956
14957 14957
14958 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message, 14958 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message,
14959 v8::Handle<v8::Value> data) { 14959 v8::Handle<v8::Value> data) {
14960 // Use the frame where JavaScript is called from. 14960 // Use the frame where JavaScript is called from.
14961 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14961 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14962 CHECK(!stack_trace.IsEmpty()); 14962 CHECK(!stack_trace.IsEmpty());
14963 CHECK_EQ(1, stack_trace->GetFrameCount()); 14963 CHECK_EQ(1, stack_trace->GetFrameCount());
14964 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber()); 14964 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber());
14965 } 14965 }
14966 14966
14967 14967
14968 // Test that the stack trace is captured where the bogus Error object is thrown. 14968 // Test that the stack trace is captured where the bogus Error object is thrown.
14969 TEST(RethrowBogusErrorStackTrace) { 14969 TEST(RethrowBogusErrorStackTrace) {
14970 v8::HandleScope scope;
14971 LocalContext env; 14970 LocalContext env;
14971 v8::HandleScope scope(env->GetIsolate());
14972 const char* source = 14972 const char* source =
14973 "var e = {__proto__: new Error()} \n" 14973 "var e = {__proto__: new Error()} \n"
14974 "throw e; \n"; 14974 "throw e; \n";
14975 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler); 14975 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler);
14976 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14976 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14977 CompileRun(source); 14977 CompileRun(source);
14978 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14978 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14979 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 14979 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
14980 } 14980 }
14981 14981
14982 14982
14983 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { 14983 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) {
14984 v8::HandleScope scope; 14984 v8::HandleScope scope(args.GetIsolate());
14985 v8::Handle<v8::StackTrace> stackTrace = 14985 v8::Handle<v8::StackTrace> stackTrace =
14986 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 14986 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
14987 CHECK_EQ(5, stackTrace->GetFrameCount()); 14987 CHECK_EQ(5, stackTrace->GetFrameCount());
14988 v8::Handle<v8::String> url = v8_str("eval_url"); 14988 v8::Handle<v8::String> url = v8_str("eval_url");
14989 for (int i = 0; i < 3; i++) { 14989 for (int i = 0; i < 3; i++) {
14990 v8::Handle<v8::String> name = 14990 v8::Handle<v8::String> name =
14991 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 14991 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
14992 CHECK(!name.IsEmpty()); 14992 CHECK(!name.IsEmpty());
14993 CHECK_EQ(url, name); 14993 CHECK_EQ(url, name);
14994 } 14994 }
14995 return v8::Undefined(); 14995 return v8::Undefined();
14996 } 14996 }
14997 14997
14998 14998
14999 TEST(SourceURLInStackTrace) { 14999 TEST(SourceURLInStackTrace) {
15000 v8::HandleScope scope; 15000 v8::HandleScope scope(v8::Isolate::GetCurrent());
15001 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15001 Local<ObjectTemplate> templ = ObjectTemplate::New();
15002 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 15002 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
15003 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); 15003 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL));
15004 LocalContext context(0, templ); 15004 LocalContext context(0, templ);
15005 15005
15006 const char *source = 15006 const char *source =
15007 "function outer() {\n" 15007 "function outer() {\n"
15008 "function bar() {\n" 15008 "function bar() {\n"
15009 " AnalyzeStackOfEvalWithSourceURL();\n" 15009 " AnalyzeStackOfEvalWithSourceURL();\n"
15010 "}\n" 15010 "}\n"
15011 "function foo() {\n" 15011 "function foo() {\n"
15012 "\n" 15012 "\n"
15013 " bar();\n" 15013 " bar();\n"
15014 "}\n" 15014 "}\n"
15015 "foo();\n" 15015 "foo();\n"
15016 "}\n" 15016 "}\n"
15017 "eval('(' + outer +')()//@ sourceURL=eval_url');"; 15017 "eval('(' + outer +')()//@ sourceURL=eval_url');";
15018 CHECK(CompileRun(source)->IsUndefined()); 15018 CHECK(CompileRun(source)->IsUndefined());
15019 } 15019 }
15020 15020
15021 15021
15022 v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL( 15022 v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL(
15023 const v8::Arguments& args) { 15023 const v8::Arguments& args) {
15024 v8::HandleScope scope; 15024 v8::HandleScope scope(args.GetIsolate());
15025 v8::Handle<v8::StackTrace> stackTrace = 15025 v8::Handle<v8::StackTrace> stackTrace =
15026 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15026 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
15027 CHECK_EQ(4, stackTrace->GetFrameCount()); 15027 CHECK_EQ(4, stackTrace->GetFrameCount());
15028 v8::Handle<v8::String> url = v8_str("url"); 15028 v8::Handle<v8::String> url = v8_str("url");
15029 for (int i = 0; i < 3; i++) { 15029 for (int i = 0; i < 3; i++) {
15030 v8::Handle<v8::String> name = 15030 v8::Handle<v8::String> name =
15031 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15031 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15032 CHECK(!name.IsEmpty()); 15032 CHECK(!name.IsEmpty());
15033 CHECK_EQ(url, name); 15033 CHECK_EQ(url, name);
15034 } 15034 }
15035 return v8::Undefined(); 15035 return v8::Undefined();
15036 } 15036 }
15037 15037
15038 15038
15039 TEST(InlineScriptWithSourceURLInStackTrace) { 15039 TEST(InlineScriptWithSourceURLInStackTrace) {
15040 v8::HandleScope scope; 15040 v8::HandleScope scope(v8::Isolate::GetCurrent());
15041 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15041 Local<ObjectTemplate> templ = ObjectTemplate::New();
15042 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 15042 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
15043 v8::FunctionTemplate::New( 15043 v8::FunctionTemplate::New(
15044 AnalyzeStackOfInlineScriptWithSourceURL)); 15044 AnalyzeStackOfInlineScriptWithSourceURL));
15045 LocalContext context(0, templ); 15045 LocalContext context(0, templ);
15046 15046
15047 const char *source = 15047 const char *source =
15048 "function outer() {\n" 15048 "function outer() {\n"
15049 "function bar() {\n" 15049 "function bar() {\n"
15050 " AnalyzeStackOfInlineScriptWithSourceURL();\n" 15050 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
15051 "}\n" 15051 "}\n"
15052 "function foo() {\n" 15052 "function foo() {\n"
15053 "\n" 15053 "\n"
15054 " bar();\n" 15054 " bar();\n"
15055 "}\n" 15055 "}\n"
15056 "foo();\n" 15056 "foo();\n"
15057 "}\n" 15057 "}\n"
15058 "outer()\n" 15058 "outer()\n"
15059 "//@ sourceURL=source_url"; 15059 "//@ sourceURL=source_url";
15060 CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined()); 15060 CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined());
15061 } 15061 }
15062 15062
15063 15063
15064 v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL( 15064 v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL(
15065 const v8::Arguments& args) { 15065 const v8::Arguments& args) {
15066 v8::HandleScope scope; 15066 v8::HandleScope scope(args.GetIsolate());
15067 v8::Handle<v8::StackTrace> stackTrace = 15067 v8::Handle<v8::StackTrace> stackTrace =
15068 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15068 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
15069 CHECK_EQ(4, stackTrace->GetFrameCount()); 15069 CHECK_EQ(4, stackTrace->GetFrameCount());
15070 v8::Handle<v8::String> url = v8_str("source_url"); 15070 v8::Handle<v8::String> url = v8_str("source_url");
15071 for (int i = 0; i < 3; i++) { 15071 for (int i = 0; i < 3; i++) {
15072 v8::Handle<v8::String> name = 15072 v8::Handle<v8::String> name =
15073 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15073 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15074 CHECK(!name.IsEmpty()); 15074 CHECK(!name.IsEmpty());
15075 CHECK_EQ(url, name); 15075 CHECK_EQ(url, name);
15076 } 15076 }
15077 return v8::Undefined(); 15077 return v8::Undefined();
15078 } 15078 }
15079 15079
15080 15080
15081 TEST(DynamicWithSourceURLInStackTrace) { 15081 TEST(DynamicWithSourceURLInStackTrace) {
15082 v8::HandleScope scope; 15082 v8::HandleScope scope(v8::Isolate::GetCurrent());
15083 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15083 Local<ObjectTemplate> templ = ObjectTemplate::New();
15084 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 15084 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
15085 v8::FunctionTemplate::New( 15085 v8::FunctionTemplate::New(
15086 AnalyzeStackOfDynamicScriptWithSourceURL)); 15086 AnalyzeStackOfDynamicScriptWithSourceURL));
15087 LocalContext context(0, templ); 15087 LocalContext context(0, templ);
15088 15088
15089 const char *source = 15089 const char *source =
15090 "function outer() {\n" 15090 "function outer() {\n"
15091 "function bar() {\n" 15091 "function bar() {\n"
15092 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" 15092 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
15093 "}\n" 15093 "}\n"
15094 "function foo() {\n" 15094 "function foo() {\n"
15095 "\n" 15095 "\n"
15096 " bar();\n" 15096 " bar();\n"
15097 "}\n" 15097 "}\n"
15098 "foo();\n" 15098 "foo();\n"
15099 "}\n" 15099 "}\n"
15100 "outer()\n" 15100 "outer()\n"
15101 "//@ sourceURL=source_url"; 15101 "//@ sourceURL=source_url";
15102 CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined()); 15102 CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined());
15103 } 15103 }
15104 15104
15105 static void CreateGarbageInOldSpace() { 15105 static void CreateGarbageInOldSpace() {
15106 v8::HandleScope scope; 15106 v8::HandleScope scope(v8::Isolate::GetCurrent());
15107 i::AlwaysAllocateScope always_allocate; 15107 i::AlwaysAllocateScope always_allocate;
15108 for (int i = 0; i < 1000; i++) { 15108 for (int i = 0; i < 1000; i++) {
15109 FACTORY->NewFixedArray(1000, i::TENURED); 15109 FACTORY->NewFixedArray(1000, i::TENURED);
15110 } 15110 }
15111 } 15111 }
15112 15112
15113 // Test that idle notification can be handled and eventually returns true. 15113 // Test that idle notification can be handled and eventually returns true.
15114 TEST(IdleNotification) { 15114 TEST(IdleNotification) {
15115 const intptr_t MB = 1024 * 1024; 15115 const intptr_t MB = 1024 * 1024;
15116 v8::HandleScope scope;
15117 LocalContext env; 15116 LocalContext env;
15117 v8::HandleScope scope(env->GetIsolate());
15118 intptr_t initial_size = HEAP->SizeOfObjects(); 15118 intptr_t initial_size = HEAP->SizeOfObjects();
15119 CreateGarbageInOldSpace(); 15119 CreateGarbageInOldSpace();
15120 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15120 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15121 CHECK_GT(size_with_garbage, initial_size + MB); 15121 CHECK_GT(size_with_garbage, initial_size + MB);
15122 bool finished = false; 15122 bool finished = false;
15123 for (int i = 0; i < 200 && !finished; i++) { 15123 for (int i = 0; i < 200 && !finished; i++) {
15124 finished = v8::V8::IdleNotification(); 15124 finished = v8::V8::IdleNotification();
15125 } 15125 }
15126 intptr_t final_size = HEAP->SizeOfObjects(); 15126 intptr_t final_size = HEAP->SizeOfObjects();
15127 CHECK(finished); 15127 CHECK(finished);
15128 CHECK_LT(final_size, initial_size + 1); 15128 CHECK_LT(final_size, initial_size + 1);
15129 } 15129 }
15130 15130
15131 15131
15132 // Test that idle notification can be handled and eventually collects garbage. 15132 // Test that idle notification can be handled and eventually collects garbage.
15133 TEST(IdleNotificationWithSmallHint) { 15133 TEST(IdleNotificationWithSmallHint) {
15134 const intptr_t MB = 1024 * 1024; 15134 const intptr_t MB = 1024 * 1024;
15135 const int IdlePauseInMs = 900; 15135 const int IdlePauseInMs = 900;
15136 v8::HandleScope scope;
15137 LocalContext env; 15136 LocalContext env;
15137 v8::HandleScope scope(env->GetIsolate());
15138 intptr_t initial_size = HEAP->SizeOfObjects(); 15138 intptr_t initial_size = HEAP->SizeOfObjects();
15139 CreateGarbageInOldSpace(); 15139 CreateGarbageInOldSpace();
15140 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15140 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15141 CHECK_GT(size_with_garbage, initial_size + MB); 15141 CHECK_GT(size_with_garbage, initial_size + MB);
15142 bool finished = false; 15142 bool finished = false;
15143 for (int i = 0; i < 200 && !finished; i++) { 15143 for (int i = 0; i < 200 && !finished; i++) {
15144 finished = v8::V8::IdleNotification(IdlePauseInMs); 15144 finished = v8::V8::IdleNotification(IdlePauseInMs);
15145 } 15145 }
15146 intptr_t final_size = HEAP->SizeOfObjects(); 15146 intptr_t final_size = HEAP->SizeOfObjects();
15147 CHECK(finished); 15147 CHECK(finished);
15148 CHECK_LT(final_size, initial_size + 1); 15148 CHECK_LT(final_size, initial_size + 1);
15149 } 15149 }
15150 15150
15151 15151
15152 // Test that idle notification can be handled and eventually collects garbage. 15152 // Test that idle notification can be handled and eventually collects garbage.
15153 TEST(IdleNotificationWithLargeHint) { 15153 TEST(IdleNotificationWithLargeHint) {
15154 const intptr_t MB = 1024 * 1024; 15154 const intptr_t MB = 1024 * 1024;
15155 const int IdlePauseInMs = 900; 15155 const int IdlePauseInMs = 900;
15156 v8::HandleScope scope;
15157 LocalContext env; 15156 LocalContext env;
15157 v8::HandleScope scope(env->GetIsolate());
15158 intptr_t initial_size = HEAP->SizeOfObjects(); 15158 intptr_t initial_size = HEAP->SizeOfObjects();
15159 CreateGarbageInOldSpace(); 15159 CreateGarbageInOldSpace();
15160 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15160 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15161 CHECK_GT(size_with_garbage, initial_size + MB); 15161 CHECK_GT(size_with_garbage, initial_size + MB);
15162 bool finished = false; 15162 bool finished = false;
15163 for (int i = 0; i < 200 && !finished; i++) { 15163 for (int i = 0; i < 200 && !finished; i++) {
15164 finished = v8::V8::IdleNotification(IdlePauseInMs); 15164 finished = v8::V8::IdleNotification(IdlePauseInMs);
15165 } 15165 }
15166 intptr_t final_size = HEAP->SizeOfObjects(); 15166 intptr_t final_size = HEAP->SizeOfObjects();
15167 CHECK(finished); 15167 CHECK(finished);
15168 CHECK_LT(final_size, initial_size + 1); 15168 CHECK_LT(final_size, initial_size + 1);
15169 } 15169 }
15170 15170
15171 15171
15172 TEST(Regress2107) { 15172 TEST(Regress2107) {
15173 const intptr_t MB = 1024 * 1024; 15173 const intptr_t MB = 1024 * 1024;
15174 const int kShortIdlePauseInMs = 100; 15174 const int kShortIdlePauseInMs = 100;
15175 const int kLongIdlePauseInMs = 1000; 15175 const int kLongIdlePauseInMs = 1000;
15176 v8::HandleScope scope;
15177 LocalContext env; 15176 LocalContext env;
15177 v8::HandleScope scope(env->GetIsolate());
15178 intptr_t initial_size = HEAP->SizeOfObjects(); 15178 intptr_t initial_size = HEAP->SizeOfObjects();
15179 // Send idle notification to start a round of incremental GCs. 15179 // Send idle notification to start a round of incremental GCs.
15180 v8::V8::IdleNotification(kShortIdlePauseInMs); 15180 v8::V8::IdleNotification(kShortIdlePauseInMs);
15181 // Emulate 7 page reloads. 15181 // Emulate 7 page reloads.
15182 for (int i = 0; i < 7; i++) { 15182 for (int i = 0; i < 7; i++) {
15183 v8::Persistent<v8::Context> ctx = v8::Context::New(); 15183 v8::Persistent<v8::Context> ctx = v8::Context::New();
15184 ctx->Enter(); 15184 ctx->Enter();
15185 CreateGarbageInOldSpace(); 15185 CreateGarbageInOldSpace();
15186 ctx->Exit(); 15186 ctx->Exit();
15187 ctx.Dispose(ctx->GetIsolate()); 15187 ctx.Dispose(ctx->GetIsolate());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
15226 TEST(SetResourceConstraints) { 15226 TEST(SetResourceConstraints) {
15227 static const int K = 1024; 15227 static const int K = 1024;
15228 uint32_t* set_limit = ComputeStackLimit(128 * K); 15228 uint32_t* set_limit = ComputeStackLimit(128 * K);
15229 15229
15230 // Set stack limit. 15230 // Set stack limit.
15231 v8::ResourceConstraints constraints; 15231 v8::ResourceConstraints constraints;
15232 constraints.set_stack_limit(set_limit); 15232 constraints.set_stack_limit(set_limit);
15233 CHECK(v8::SetResourceConstraints(&constraints)); 15233 CHECK(v8::SetResourceConstraints(&constraints));
15234 15234
15235 // Execute a script. 15235 // Execute a script.
15236 v8::HandleScope scope;
15237 LocalContext env; 15236 LocalContext env;
15237 v8::HandleScope scope(env->GetIsolate());
15238 Local<v8::FunctionTemplate> fun_templ = 15238 Local<v8::FunctionTemplate> fun_templ =
15239 v8::FunctionTemplate::New(GetStackLimitCallback); 15239 v8::FunctionTemplate::New(GetStackLimitCallback);
15240 Local<Function> fun = fun_templ->GetFunction(); 15240 Local<Function> fun = fun_templ->GetFunction();
15241 env->Global()->Set(v8_str("get_stack_limit"), fun); 15241 env->Global()->Set(v8_str("get_stack_limit"), fun);
15242 CompileRun("get_stack_limit();"); 15242 CompileRun("get_stack_limit();");
15243 15243
15244 CHECK(stack_limit == set_limit); 15244 CHECK(stack_limit == set_limit);
15245 } 15245 }
15246 15246
15247 15247
15248 TEST(SetResourceConstraintsInThread) { 15248 TEST(SetResourceConstraintsInThread) {
15249 uint32_t* set_limit; 15249 uint32_t* set_limit;
15250 { 15250 {
15251 v8::Locker locker(CcTest::default_isolate()); 15251 v8::Locker locker(CcTest::default_isolate());
15252 static const int K = 1024; 15252 static const int K = 1024;
15253 set_limit = ComputeStackLimit(128 * K); 15253 set_limit = ComputeStackLimit(128 * K);
15254 15254
15255 // Set stack limit. 15255 // Set stack limit.
15256 v8::ResourceConstraints constraints; 15256 v8::ResourceConstraints constraints;
15257 constraints.set_stack_limit(set_limit); 15257 constraints.set_stack_limit(set_limit);
15258 CHECK(v8::SetResourceConstraints(&constraints)); 15258 CHECK(v8::SetResourceConstraints(&constraints));
15259 15259
15260 // Execute a script. 15260 // Execute a script.
15261 v8::HandleScope scope; 15261 v8::HandleScope scope(CcTest::default_isolate());
15262 LocalContext env; 15262 LocalContext env;
15263 Local<v8::FunctionTemplate> fun_templ = 15263 Local<v8::FunctionTemplate> fun_templ =
15264 v8::FunctionTemplate::New(GetStackLimitCallback); 15264 v8::FunctionTemplate::New(GetStackLimitCallback);
15265 Local<Function> fun = fun_templ->GetFunction(); 15265 Local<Function> fun = fun_templ->GetFunction();
15266 env->Global()->Set(v8_str("get_stack_limit"), fun); 15266 env->Global()->Set(v8_str("get_stack_limit"), fun);
15267 CompileRun("get_stack_limit();"); 15267 CompileRun("get_stack_limit();");
15268 15268
15269 CHECK(stack_limit == set_limit); 15269 CHECK(stack_limit == set_limit);
15270 } 15270 }
15271 { 15271 {
15272 v8::Locker locker(CcTest::default_isolate()); 15272 v8::Locker locker(CcTest::default_isolate());
15273 CHECK(stack_limit == set_limit); 15273 CHECK(stack_limit == set_limit);
15274 } 15274 }
15275 } 15275 }
15276 15276
15277 15277
15278 THREADED_TEST(GetHeapStatistics) { 15278 THREADED_TEST(GetHeapStatistics) {
15279 v8::HandleScope scope;
15280 LocalContext c1; 15279 LocalContext c1;
15280 v8::HandleScope scope(c1->GetIsolate());
15281 v8::HeapStatistics heap_statistics; 15281 v8::HeapStatistics heap_statistics;
15282 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); 15282 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
15283 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); 15283 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
15284 c1->GetIsolate()->GetHeapStatistics(&heap_statistics); 15284 c1->GetIsolate()->GetHeapStatistics(&heap_statistics);
15285 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); 15285 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
15286 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); 15286 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
15287 } 15287 }
15288 15288
15289 15289
15290 class VisitorImpl : public v8::ExternalResourceVisitor { 15290 class VisitorImpl : public v8::ExternalResourceVisitor {
(...skipping 25 matching lines...) Expand all
15316 CHECK(found_resource_[i]); 15316 CHECK(found_resource_[i]);
15317 } 15317 }
15318 } 15318 }
15319 15319
15320 private: 15320 private:
15321 v8::String::ExternalStringResource* resource_[4]; 15321 v8::String::ExternalStringResource* resource_[4];
15322 bool found_resource_[4]; 15322 bool found_resource_[4];
15323 }; 15323 };
15324 15324
15325 TEST(VisitExternalStrings) { 15325 TEST(VisitExternalStrings) {
15326 v8::HandleScope scope;
15327 LocalContext env; 15326 LocalContext env;
15327 v8::HandleScope scope(env->GetIsolate());
15328 const char* string = "Some string"; 15328 const char* string = "Some string";
15329 uint16_t* two_byte_string = AsciiToTwoByteString(string); 15329 uint16_t* two_byte_string = AsciiToTwoByteString(string);
15330 TestResource* resource[4]; 15330 TestResource* resource[4];
15331 resource[0] = new TestResource(two_byte_string); 15331 resource[0] = new TestResource(two_byte_string);
15332 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]); 15332 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]);
15333 resource[1] = new TestResource(two_byte_string); 15333 resource[1] = new TestResource(two_byte_string);
15334 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]); 15334 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]);
15335 15335
15336 // Externalized symbol. 15336 // Externalized symbol.
15337 resource[2] = new TestResource(two_byte_string); 15337 resource[2] = new TestResource(two_byte_string);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
15382 } 15382 }
15383 15383
15384 // We don't have a consistent way to write 64-bit constants syntactically, so we 15384 // We don't have a consistent way to write 64-bit constants syntactically, so we
15385 // split them into two 32-bit constants and combine them programmatically. 15385 // split them into two 32-bit constants and combine them programmatically.
15386 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { 15386 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
15387 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); 15387 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
15388 } 15388 }
15389 15389
15390 15390
15391 THREADED_TEST(QuietSignalingNaNs) { 15391 THREADED_TEST(QuietSignalingNaNs) {
15392 v8::HandleScope scope;
15393 LocalContext context; 15392 LocalContext context;
15393 v8::HandleScope scope(context->GetIsolate());
15394 v8::TryCatch try_catch; 15394 v8::TryCatch try_catch;
15395 15395
15396 // Special double values. 15396 // Special double values.
15397 double snan = DoubleFromBits(0x7ff00000, 0x00000001); 15397 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
15398 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); 15398 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
15399 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); 15399 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
15400 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); 15400 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
15401 double min_normal = DoubleFromBits(0x00100000, 0x00000000); 15401 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
15402 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); 15402 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
15403 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); 15403 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
15466 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 15466 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
15467 #else 15467 #else
15468 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 15468 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
15469 #endif 15469 #endif
15470 } 15470 }
15471 } 15471 }
15472 } 15472 }
15473 15473
15474 15474
15475 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) { 15475 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) {
15476 v8::HandleScope scope; 15476 v8::HandleScope scope(args.GetIsolate());
15477 v8::TryCatch tc; 15477 v8::TryCatch tc;
15478 v8::Handle<v8::String> str(args[0]->ToString()); 15478 v8::Handle<v8::String> str(args[0]->ToString());
15479 USE(str); 15479 USE(str);
15480 if (tc.HasCaught()) 15480 if (tc.HasCaught())
15481 return tc.ReThrow(); 15481 return tc.ReThrow();
15482 return v8::Undefined(); 15482 return v8::Undefined();
15483 } 15483 }
15484 15484
15485 15485
15486 // Test that an exception can be propagated down through a spaghetti 15486 // Test that an exception can be propagated down through a spaghetti
15487 // stack using ReThrow. 15487 // stack using ReThrow.
15488 THREADED_TEST(SpaghettiStackReThrow) { 15488 THREADED_TEST(SpaghettiStackReThrow) {
15489 v8::HandleScope scope; 15489 v8::HandleScope scope(v8::Isolate::GetCurrent());
15490 LocalContext context; 15490 LocalContext context;
15491 context->Global()->Set( 15491 context->Global()->Set(
15492 v8::String::New("s"), 15492 v8::String::New("s"),
15493 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); 15493 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction());
15494 v8::TryCatch try_catch; 15494 v8::TryCatch try_catch;
15495 CompileRun( 15495 CompileRun(
15496 "var i = 0;" 15496 "var i = 0;"
15497 "var o = {" 15497 "var o = {"
15498 " toString: function () {" 15498 " toString: function () {"
15499 " if (i == 10) {" 15499 " if (i == 10) {"
15500 " throw 'Hey!';" 15500 " throw 'Hey!';"
15501 " } else {" 15501 " } else {"
15502 " i++;" 15502 " i++;"
15503 " return s(o);" 15503 " return s(o);"
15504 " }" 15504 " }"
15505 " }" 15505 " }"
15506 "};" 15506 "};"
15507 "s(o);"); 15507 "s(o);");
15508 CHECK(try_catch.HasCaught()); 15508 CHECK(try_catch.HasCaught());
15509 v8::String::Utf8Value value(try_catch.Exception()); 15509 v8::String::Utf8Value value(try_catch.Exception());
15510 CHECK_EQ(0, strcmp(*value, "Hey!")); 15510 CHECK_EQ(0, strcmp(*value, "Hey!"));
15511 } 15511 }
15512 15512
15513 15513
15514 TEST(Regress528) { 15514 TEST(Regress528) {
15515 v8::V8::Initialize(); 15515 v8::V8::Initialize();
15516 15516
15517 v8::HandleScope scope; 15517 v8::HandleScope scope(v8::Isolate::GetCurrent());
15518 v8::Persistent<Context> context; 15518 v8::Persistent<Context> context;
15519 v8::Persistent<Context> other_context; 15519 v8::Persistent<Context> other_context;
15520 int gc_count; 15520 int gc_count;
15521 15521
15522 // Create a context used to keep the code from aging in the compilation 15522 // Create a context used to keep the code from aging in the compilation
15523 // cache. 15523 // cache.
15524 other_context = Context::New(); 15524 other_context = Context::New();
15525 15525
15526 // Context-dependent context data creates reference from the compilation 15526 // Context-dependent context data creates reference from the compilation
15527 // cache to the global object. 15527 // cache to the global object.
15528 const char* source_simple = "1"; 15528 const char* source_simple = "1";
15529 context = Context::New(); 15529 context = Context::New();
15530 { 15530 {
15531 v8::HandleScope scope; 15531 v8::HandleScope scope(v8::Isolate::GetCurrent());
15532 15532
15533 context->Enter(); 15533 context->Enter();
15534 Local<v8::String> obj = v8::String::New(""); 15534 Local<v8::String> obj = v8::String::New("");
15535 context->SetEmbedderData(0, obj); 15535 context->SetEmbedderData(0, obj);
15536 CompileRun(source_simple); 15536 CompileRun(source_simple);
15537 context->Exit(); 15537 context->Exit();
15538 } 15538 }
15539 context.Dispose(context->GetIsolate()); 15539 context.Dispose(context->GetIsolate());
15540 v8::V8::ContextDisposedNotification(); 15540 v8::V8::ContextDisposedNotification();
15541 for (gc_count = 1; gc_count < 10; gc_count++) { 15541 for (gc_count = 1; gc_count < 10; gc_count++) {
15542 other_context->Enter(); 15542 other_context->Enter();
15543 CompileRun(source_simple); 15543 CompileRun(source_simple);
15544 other_context->Exit(); 15544 other_context->Exit();
15545 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15545 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15546 if (GetGlobalObjectsCount() == 1) break; 15546 if (GetGlobalObjectsCount() == 1) break;
15547 } 15547 }
15548 CHECK_GE(2, gc_count); 15548 CHECK_GE(2, gc_count);
15549 CHECK_EQ(1, GetGlobalObjectsCount()); 15549 CHECK_EQ(1, GetGlobalObjectsCount());
15550 15550
15551 // Eval in a function creates reference from the compilation cache to the 15551 // Eval in a function creates reference from the compilation cache to the
15552 // global object. 15552 // global object.
15553 const char* source_eval = "function f(){eval('1')}; f()"; 15553 const char* source_eval = "function f(){eval('1')}; f()";
15554 context = Context::New(); 15554 context = Context::New();
15555 { 15555 {
15556 v8::HandleScope scope; 15556 v8::HandleScope scope(v8::Isolate::GetCurrent());
15557 15557
15558 context->Enter(); 15558 context->Enter();
15559 CompileRun(source_eval); 15559 CompileRun(source_eval);
15560 context->Exit(); 15560 context->Exit();
15561 } 15561 }
15562 context.Dispose(context->GetIsolate()); 15562 context.Dispose(context->GetIsolate());
15563 v8::V8::ContextDisposedNotification(); 15563 v8::V8::ContextDisposedNotification();
15564 for (gc_count = 1; gc_count < 10; gc_count++) { 15564 for (gc_count = 1; gc_count < 10; gc_count++) {
15565 other_context->Enter(); 15565 other_context->Enter();
15566 CompileRun(source_eval); 15566 CompileRun(source_eval);
15567 other_context->Exit(); 15567 other_context->Exit();
15568 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15568 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15569 if (GetGlobalObjectsCount() == 1) break; 15569 if (GetGlobalObjectsCount() == 1) break;
15570 } 15570 }
15571 CHECK_GE(2, gc_count); 15571 CHECK_GE(2, gc_count);
15572 CHECK_EQ(1, GetGlobalObjectsCount()); 15572 CHECK_EQ(1, GetGlobalObjectsCount());
15573 15573
15574 // Looking up the line number for an exception creates reference from the 15574 // Looking up the line number for an exception creates reference from the
15575 // compilation cache to the global object. 15575 // compilation cache to the global object.
15576 const char* source_exception = "function f(){throw 1;} f()"; 15576 const char* source_exception = "function f(){throw 1;} f()";
15577 context = Context::New(); 15577 context = Context::New();
15578 { 15578 {
15579 v8::HandleScope scope; 15579 v8::HandleScope scope(v8::Isolate::GetCurrent());
15580 15580
15581 context->Enter(); 15581 context->Enter();
15582 v8::TryCatch try_catch; 15582 v8::TryCatch try_catch;
15583 CompileRun(source_exception); 15583 CompileRun(source_exception);
15584 CHECK(try_catch.HasCaught()); 15584 CHECK(try_catch.HasCaught());
15585 v8::Handle<v8::Message> message = try_catch.Message(); 15585 v8::Handle<v8::Message> message = try_catch.Message();
15586 CHECK(!message.IsEmpty()); 15586 CHECK(!message.IsEmpty());
15587 CHECK_EQ(1, message->GetLineNumber()); 15587 CHECK_EQ(1, message->GetLineNumber());
15588 context->Exit(); 15588 context->Exit();
15589 } 15589 }
15590 context.Dispose(context->GetIsolate()); 15590 context.Dispose(context->GetIsolate());
15591 v8::V8::ContextDisposedNotification(); 15591 v8::V8::ContextDisposedNotification();
15592 for (gc_count = 1; gc_count < 10; gc_count++) { 15592 for (gc_count = 1; gc_count < 10; gc_count++) {
15593 other_context->Enter(); 15593 other_context->Enter();
15594 CompileRun(source_exception); 15594 CompileRun(source_exception);
15595 other_context->Exit(); 15595 other_context->Exit();
15596 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15596 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15597 if (GetGlobalObjectsCount() == 1) break; 15597 if (GetGlobalObjectsCount() == 1) break;
15598 } 15598 }
15599 CHECK_GE(2, gc_count); 15599 CHECK_GE(2, gc_count);
15600 CHECK_EQ(1, GetGlobalObjectsCount()); 15600 CHECK_EQ(1, GetGlobalObjectsCount());
15601 15601
15602 other_context.Dispose(other_context->GetIsolate()); 15602 other_context.Dispose(other_context->GetIsolate());
15603 v8::V8::ContextDisposedNotification(); 15603 v8::V8::ContextDisposedNotification();
15604 } 15604 }
15605 15605
15606 15606
15607 THREADED_TEST(ScriptOrigin) { 15607 THREADED_TEST(ScriptOrigin) {
15608 v8::HandleScope scope;
15609 LocalContext env; 15608 LocalContext env;
15609 v8::HandleScope scope(env->GetIsolate());
15610 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15610 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15611 v8::Handle<v8::String> script = v8::String::New( 15611 v8::Handle<v8::String> script = v8::String::New(
15612 "function f() {}\n\nfunction g() {}"); 15612 "function f() {}\n\nfunction g() {}");
15613 v8::Script::Compile(script, &origin)->Run(); 15613 v8::Script::Compile(script, &origin)->Run();
15614 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15614 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15615 env->Global()->Get(v8::String::New("f"))); 15615 env->Global()->Get(v8::String::New("f")));
15616 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 15616 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
15617 env->Global()->Get(v8::String::New("g"))); 15617 env->Global()->Get(v8::String::New("g")));
15618 15618
15619 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); 15619 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin();
15620 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName())); 15620 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName()));
15621 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); 15621 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value());
15622 15622
15623 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); 15623 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin();
15624 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName())); 15624 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName()));
15625 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); 15625 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
15626 } 15626 }
15627 15627
15628 THREADED_TEST(FunctionGetInferredName) { 15628 THREADED_TEST(FunctionGetInferredName) {
15629 v8::HandleScope scope;
15630 LocalContext env; 15629 LocalContext env;
15630 v8::HandleScope scope(env->GetIsolate());
15631 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15631 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15632 v8::Handle<v8::String> script = v8::String::New( 15632 v8::Handle<v8::String> script = v8::String::New(
15633 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); 15633 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
15634 v8::Script::Compile(script, &origin)->Run(); 15634 v8::Script::Compile(script, &origin)->Run();
15635 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15635 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15636 env->Global()->Get(v8::String::New("f"))); 15636 env->Global()->Get(v8::String::New("f")));
15637 CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName())); 15637 CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName()));
15638 } 15638 }
15639 15639
15640 THREADED_TEST(ScriptLineNumber) { 15640 THREADED_TEST(ScriptLineNumber) {
15641 v8::HandleScope scope;
15642 LocalContext env; 15641 LocalContext env;
15642 v8::HandleScope scope(env->GetIsolate());
15643 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15643 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15644 v8::Handle<v8::String> script = v8::String::New( 15644 v8::Handle<v8::String> script = v8::String::New(
15645 "function f() {}\n\nfunction g() {}"); 15645 "function f() {}\n\nfunction g() {}");
15646 v8::Script::Compile(script, &origin)->Run(); 15646 v8::Script::Compile(script, &origin)->Run();
15647 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15647 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15648 env->Global()->Get(v8::String::New("f"))); 15648 env->Global()->Get(v8::String::New("f")));
15649 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 15649 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
15650 env->Global()->Get(v8::String::New("g"))); 15650 env->Global()->Get(v8::String::New("g")));
15651 CHECK_EQ(0, f->GetScriptLineNumber()); 15651 CHECK_EQ(0, f->GetScriptLineNumber());
15652 CHECK_EQ(2, g->GetScriptLineNumber()); 15652 CHECK_EQ(2, g->GetScriptLineNumber());
15653 } 15653 }
15654 15654
15655 15655
15656 THREADED_TEST(ScriptColumnNumber) { 15656 THREADED_TEST(ScriptColumnNumber) {
15657 v8::HandleScope scope;
15658 LocalContext env; 15657 LocalContext env;
15658 v8::HandleScope scope(env->GetIsolate());
15659 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 15659 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"),
15660 v8::Integer::New(3), v8::Integer::New(2)); 15660 v8::Integer::New(3), v8::Integer::New(2));
15661 v8::Handle<v8::String> script = v8::String::New( 15661 v8::Handle<v8::String> script = v8::String::New(
15662 "function foo() {}\n\n function bar() {}"); 15662 "function foo() {}\n\n function bar() {}");
15663 v8::Script::Compile(script, &origin)->Run(); 15663 v8::Script::Compile(script, &origin)->Run();
15664 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 15664 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
15665 env->Global()->Get(v8::String::New("foo"))); 15665 env->Global()->Get(v8::String::New("foo")));
15666 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 15666 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
15667 env->Global()->Get(v8::String::New("bar"))); 15667 env->Global()->Get(v8::String::New("bar")));
15668 CHECK_EQ(14, foo->GetScriptColumnNumber()); 15668 CHECK_EQ(14, foo->GetScriptColumnNumber());
15669 CHECK_EQ(17, bar->GetScriptColumnNumber()); 15669 CHECK_EQ(17, bar->GetScriptColumnNumber());
15670 } 15670 }
15671 15671
15672 15672
15673 THREADED_TEST(FunctionGetScriptId) { 15673 THREADED_TEST(FunctionGetScriptId) {
15674 v8::HandleScope scope;
15675 LocalContext env; 15674 LocalContext env;
15675 v8::HandleScope scope(env->GetIsolate());
15676 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 15676 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"),
15677 v8::Integer::New(3), v8::Integer::New(2)); 15677 v8::Integer::New(3), v8::Integer::New(2));
15678 v8::Handle<v8::String> scriptSource = v8::String::New( 15678 v8::Handle<v8::String> scriptSource = v8::String::New(
15679 "function foo() {}\n\n function bar() {}"); 15679 "function foo() {}\n\n function bar() {}");
15680 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 15680 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
15681 script->Run(); 15681 script->Run();
15682 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 15682 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
15683 env->Global()->Get(v8::String::New("foo"))); 15683 env->Global()->Get(v8::String::New("foo")));
15684 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 15684 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
15685 env->Global()->Get(v8::String::New("bar"))); 15685 env->Global()->Get(v8::String::New("bar")));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
15719 const AccessorInfo& info) { 15719 const AccessorInfo& info) {
15720 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 15720 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15721 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 15721 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15722 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); 15722 if (!name->Equals(v8_str("foo"))) return Handle<Value>();
15723 info.This()->Set(v8_str("y"), v8_num(23)); 15723 info.This()->Set(v8_str("y"), v8_num(23));
15724 return v8_num(23); 15724 return v8_num(23);
15725 } 15725 }
15726 15726
15727 15727
15728 TEST(SetterOnConstructorPrototype) { 15728 TEST(SetterOnConstructorPrototype) {
15729 v8::HandleScope scope; 15729 v8::HandleScope scope(v8::Isolate::GetCurrent());
15730 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15730 Local<ObjectTemplate> templ = ObjectTemplate::New();
15731 templ->SetAccessor(v8_str("x"), 15731 templ->SetAccessor(v8_str("x"),
15732 GetterWhichReturns42, 15732 GetterWhichReturns42,
15733 SetterWhichSetsYOnThisTo23); 15733 SetterWhichSetsYOnThisTo23);
15734 LocalContext context; 15734 LocalContext context;
15735 context->Global()->Set(v8_str("P"), templ->NewInstance()); 15735 context->Global()->Set(v8_str("P"), templ->NewInstance());
15736 CompileRun("function C1() {" 15736 CompileRun("function C1() {"
15737 " this.x = 23;" 15737 " this.x = 23;"
15738 "};" 15738 "};"
15739 "C1.prototype = P;" 15739 "C1.prototype = P;"
(...skipping 29 matching lines...) Expand all
15769 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23( 15769 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23(
15770 Local<String> name, Local<Value> value, const AccessorInfo& info) { 15770 Local<String> name, Local<Value> value, const AccessorInfo& info) {
15771 if (name->Equals(v8_str("x"))) { 15771 if (name->Equals(v8_str("x"))) {
15772 info.This()->Set(v8_str("y"), v8_num(23)); 15772 info.This()->Set(v8_str("y"), v8_num(23));
15773 } 15773 }
15774 return v8::Handle<Value>(); 15774 return v8::Handle<Value>();
15775 } 15775 }
15776 15776
15777 15777
15778 THREADED_TEST(InterceptorOnConstructorPrototype) { 15778 THREADED_TEST(InterceptorOnConstructorPrototype) {
15779 v8::HandleScope scope; 15779 v8::HandleScope scope(v8::Isolate::GetCurrent());
15780 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15780 Local<ObjectTemplate> templ = ObjectTemplate::New();
15781 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, 15781 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
15782 NamedPropertySetterWhichSetsYOnThisTo23); 15782 NamedPropertySetterWhichSetsYOnThisTo23);
15783 LocalContext context; 15783 LocalContext context;
15784 context->Global()->Set(v8_str("P"), templ->NewInstance()); 15784 context->Global()->Set(v8_str("P"), templ->NewInstance());
15785 CompileRun("function C1() {" 15785 CompileRun("function C1() {"
15786 " this.x = 23;" 15786 " this.x = 23;"
15787 "};" 15787 "};"
15788 "C1.prototype = P;" 15788 "C1.prototype = P;"
15789 "function C2() {" 15789 "function C2() {"
(...skipping 18 matching lines...) Expand all
15808 } 15808 }
15809 } 15809 }
15810 15810
15811 15811
15812 TEST(Bug618) { 15812 TEST(Bug618) {
15813 const char* source = "function C1() {" 15813 const char* source = "function C1() {"
15814 " this.x = 23;" 15814 " this.x = 23;"
15815 "};" 15815 "};"
15816 "C1.prototype = P;"; 15816 "C1.prototype = P;";
15817 15817
15818 v8::HandleScope scope;
15819 LocalContext context; 15818 LocalContext context;
15819 v8::HandleScope scope(context->GetIsolate());
15820 v8::Local<v8::Script> script; 15820 v8::Local<v8::Script> script;
15821 15821
15822 // Use a simple object as prototype. 15822 // Use a simple object as prototype.
15823 v8::Local<v8::Object> prototype = v8::Object::New(); 15823 v8::Local<v8::Object> prototype = v8::Object::New();
15824 prototype->Set(v8_str("y"), v8_num(42)); 15824 prototype->Set(v8_str("y"), v8_num(42));
15825 context->Global()->Set(v8_str("P"), prototype); 15825 context->Global()->Set(v8_str("P"), prototype);
15826 15826
15827 // This compile will add the code to the compilation cache. 15827 // This compile will add the code to the compilation cache.
15828 CompileRun(source); 15828 CompileRun(source);
15829 15829
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
15904 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15904 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15905 CHECK_EQ(2, prologue_call_count); 15905 CHECK_EQ(2, prologue_call_count);
15906 CHECK_EQ(2, epilogue_call_count); 15906 CHECK_EQ(2, epilogue_call_count);
15907 CHECK_EQ(2, prologue_call_count_second); 15907 CHECK_EQ(2, prologue_call_count_second);
15908 CHECK_EQ(2, epilogue_call_count_second); 15908 CHECK_EQ(2, epilogue_call_count_second);
15909 } 15909 }
15910 15910
15911 15911
15912 THREADED_TEST(AddToJSFunctionResultCache) { 15912 THREADED_TEST(AddToJSFunctionResultCache) {
15913 i::FLAG_allow_natives_syntax = true; 15913 i::FLAG_allow_natives_syntax = true;
15914 v8::HandleScope scope; 15914 v8::HandleScope scope(v8::Isolate::GetCurrent());
15915 15915
15916 LocalContext context; 15916 LocalContext context;
15917 15917
15918 const char* code = 15918 const char* code =
15919 "(function() {" 15919 "(function() {"
15920 " var key0 = 'a';" 15920 " var key0 = 'a';"
15921 " var key1 = 'b';" 15921 " var key1 = 'b';"
15922 " var r0 = %_GetFromCache(0, key0);" 15922 " var r0 = %_GetFromCache(0, key0);"
15923 " var r1 = %_GetFromCache(0, key1);" 15923 " var r1 = %_GetFromCache(0, key1);"
15924 " var r0_ = %_GetFromCache(0, key0);" 15924 " var r0_ = %_GetFromCache(0, key0);"
15925 " if (r0 !== r0_)" 15925 " if (r0 !== r0_)"
15926 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;" 15926 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
15927 " var r1_ = %_GetFromCache(0, key1);" 15927 " var r1_ = %_GetFromCache(0, key1);"
15928 " if (r1 !== r1_)" 15928 " if (r1 !== r1_)"
15929 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" 15929 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
15930 " return 'PASSED';" 15930 " return 'PASSED';"
15931 "})()"; 15931 "})()";
15932 HEAP->ClearJSFunctionResultCaches(); 15932 HEAP->ClearJSFunctionResultCaches();
15933 ExpectString(code, "PASSED"); 15933 ExpectString(code, "PASSED");
15934 } 15934 }
15935 15935
15936 15936
15937 static const int k0CacheSize = 16; 15937 static const int k0CacheSize = 16;
15938 15938
15939 THREADED_TEST(FillJSFunctionResultCache) { 15939 THREADED_TEST(FillJSFunctionResultCache) {
15940 i::FLAG_allow_natives_syntax = true; 15940 i::FLAG_allow_natives_syntax = true;
15941 v8::HandleScope scope;
15942
15943 LocalContext context; 15941 LocalContext context;
15942 v8::HandleScope scope(context->GetIsolate());
15944 15943
15945 const char* code = 15944 const char* code =
15946 "(function() {" 15945 "(function() {"
15947 " var k = 'a';" 15946 " var k = 'a';"
15948 " var r = %_GetFromCache(0, k);" 15947 " var r = %_GetFromCache(0, k);"
15949 " for (var i = 0; i < 16; i++) {" 15948 " for (var i = 0; i < 16; i++) {"
15950 " %_GetFromCache(0, 'a' + i);" 15949 " %_GetFromCache(0, 'a' + i);"
15951 " };" 15950 " };"
15952 " if (r === %_GetFromCache(0, k))" 15951 " if (r === %_GetFromCache(0, k))"
15953 " return 'FAILED: k0CacheSize is too small';" 15952 " return 'FAILED: k0CacheSize is too small';"
15954 " return 'PASSED';" 15953 " return 'PASSED';"
15955 "})()"; 15954 "})()";
15956 HEAP->ClearJSFunctionResultCaches(); 15955 HEAP->ClearJSFunctionResultCaches();
15957 ExpectString(code, "PASSED"); 15956 ExpectString(code, "PASSED");
15958 } 15957 }
15959 15958
15960 15959
15961 THREADED_TEST(RoundRobinGetFromCache) { 15960 THREADED_TEST(RoundRobinGetFromCache) {
15962 i::FLAG_allow_natives_syntax = true; 15961 i::FLAG_allow_natives_syntax = true;
15963 v8::HandleScope scope;
15964
15965 LocalContext context; 15962 LocalContext context;
15963 v8::HandleScope scope(context->GetIsolate());
15966 15964
15967 const char* code = 15965 const char* code =
15968 "(function() {" 15966 "(function() {"
15969 " var keys = [];" 15967 " var keys = [];"
15970 " for (var i = 0; i < 16; i++) keys.push(i);" 15968 " for (var i = 0; i < 16; i++) keys.push(i);"
15971 " var values = [];" 15969 " var values = [];"
15972 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 15970 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15973 " for (var i = 0; i < 16; i++) {" 15971 " for (var i = 0; i < 16; i++) {"
15974 " var v = %_GetFromCache(0, keys[i]);" 15972 " var v = %_GetFromCache(0, keys[i]);"
15975 " if (v.toString() !== values[i].toString())" 15973 " if (v.toString() !== values[i].toString())"
15976 " return 'Wrong value for ' + " 15974 " return 'Wrong value for ' + "
15977 " keys[i] + ': ' + v + ' vs. ' + values[i];" 15975 " keys[i] + ': ' + v + ' vs. ' + values[i];"
15978 " };" 15976 " };"
15979 " return 'PASSED';" 15977 " return 'PASSED';"
15980 "})()"; 15978 "})()";
15981 HEAP->ClearJSFunctionResultCaches(); 15979 HEAP->ClearJSFunctionResultCaches();
15982 ExpectString(code, "PASSED"); 15980 ExpectString(code, "PASSED");
15983 } 15981 }
15984 15982
15985 15983
15986 THREADED_TEST(ReverseGetFromCache) { 15984 THREADED_TEST(ReverseGetFromCache) {
15987 i::FLAG_allow_natives_syntax = true; 15985 i::FLAG_allow_natives_syntax = true;
15988 v8::HandleScope scope;
15989
15990 LocalContext context; 15986 LocalContext context;
15987 v8::HandleScope scope(context->GetIsolate());
15991 15988
15992 const char* code = 15989 const char* code =
15993 "(function() {" 15990 "(function() {"
15994 " var keys = [];" 15991 " var keys = [];"
15995 " for (var i = 0; i < 16; i++) keys.push(i);" 15992 " for (var i = 0; i < 16; i++) keys.push(i);"
15996 " var values = [];" 15993 " var values = [];"
15997 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 15994 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15998 " for (var i = 15; i >= 16; i--) {" 15995 " for (var i = 15; i >= 16; i--) {"
15999 " var v = %_GetFromCache(0, keys[i]);" 15996 " var v = %_GetFromCache(0, keys[i]);"
16000 " if (v !== values[i])" 15997 " if (v !== values[i])"
16001 " return 'Wrong value for ' + " 15998 " return 'Wrong value for ' + "
16002 " keys[i] + ': ' + v + ' vs. ' + values[i];" 15999 " keys[i] + ': ' + v + ' vs. ' + values[i];"
16003 " };" 16000 " };"
16004 " return 'PASSED';" 16001 " return 'PASSED';"
16005 "})()"; 16002 "})()";
16006 HEAP->ClearJSFunctionResultCaches(); 16003 HEAP->ClearJSFunctionResultCaches();
16007 ExpectString(code, "PASSED"); 16004 ExpectString(code, "PASSED");
16008 } 16005 }
16009 16006
16010 16007
16011 THREADED_TEST(TestEviction) { 16008 THREADED_TEST(TestEviction) {
16012 i::FLAG_allow_natives_syntax = true; 16009 i::FLAG_allow_natives_syntax = true;
16013 v8::HandleScope scope;
16014
16015 LocalContext context; 16010 LocalContext context;
16011 v8::HandleScope scope(context->GetIsolate());
16016 16012
16017 const char* code = 16013 const char* code =
16018 "(function() {" 16014 "(function() {"
16019 " for (var i = 0; i < 2*16; i++) {" 16015 " for (var i = 0; i < 2*16; i++) {"
16020 " %_GetFromCache(0, 'a' + i);" 16016 " %_GetFromCache(0, 'a' + i);"
16021 " };" 16017 " };"
16022 " return 'PASSED';" 16018 " return 'PASSED';"
16023 "})()"; 16019 "})()";
16024 HEAP->ClearJSFunctionResultCaches(); 16020 HEAP->ClearJSFunctionResultCaches();
16025 ExpectString(code, "PASSED"); 16021 ExpectString(code, "PASSED");
16026 } 16022 }
16027 16023
16028 16024
16029 THREADED_TEST(TwoByteStringInAsciiCons) { 16025 THREADED_TEST(TwoByteStringInAsciiCons) {
16030 // See Chromium issue 47824. 16026 // See Chromium issue 47824.
16031 v8::HandleScope scope; 16027 LocalContext context;
16028 v8::HandleScope scope(context->GetIsolate());
16032 16029
16033 LocalContext context;
16034 const char* init_code = 16030 const char* init_code =
16035 "var str1 = 'abelspendabel';" 16031 "var str1 = 'abelspendabel';"
16036 "var str2 = str1 + str1 + str1;" 16032 "var str2 = str1 + str1 + str1;"
16037 "str2;"; 16033 "str2;";
16038 Local<Value> result = CompileRun(init_code); 16034 Local<Value> result = CompileRun(init_code);
16039 16035
16040 Local<Value> indexof = CompileRun("str2.indexOf('els')"); 16036 Local<Value> indexof = CompileRun("str2.indexOf('els')");
16041 Local<Value> lastindexof = CompileRun("str2.lastIndexOf('dab')"); 16037 Local<Value> lastindexof = CompileRun("str2.lastIndexOf('dab')");
16042 16038
16043 CHECK(result->IsString()); 16039 CHECK(result->IsString());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
16122 } 16118 }
16123 16119
16124 16120
16125 TEST(GCInFailedAccessCheckCallback) { 16121 TEST(GCInFailedAccessCheckCallback) {
16126 // Install a failed access check callback that performs a GC on each 16122 // Install a failed access check callback that performs a GC on each
16127 // invocation. Then force the callback to be called from va 16123 // invocation. Then force the callback to be called from va
16128 16124
16129 v8::V8::Initialize(); 16125 v8::V8::Initialize();
16130 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 16126 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
16131 16127
16132 v8::HandleScope scope; 16128 v8::HandleScope scope(v8::Isolate::GetCurrent());
16133 16129
16134 // Create an ObjectTemplate for global objects and install access 16130 // Create an ObjectTemplate for global objects and install access
16135 // check callbacks that will block access. 16131 // check callbacks that will block access.
16136 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 16132 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
16137 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 16133 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
16138 IndexedGetAccessBlocker, 16134 IndexedGetAccessBlocker,
16139 v8::Handle<v8::Value>(), 16135 v8::Handle<v8::Value>(),
16140 false); 16136 false);
16141 16137
16142 // Create a context and set an x property on it's global object. 16138 // Create a context and set an x property on it's global object.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
16215 CHECK(current_isolate == v8::Isolate::GetCurrent()); 16211 CHECK(current_isolate == v8::Isolate::GetCurrent());
16216 16212
16217 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16213 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16218 last_location = last_message = NULL; 16214 last_location = last_message = NULL;
16219 isolate->Dispose(); 16215 isolate->Dispose();
16220 CHECK_EQ(last_location, NULL); 16216 CHECK_EQ(last_location, NULL);
16221 CHECK_EQ(last_message, NULL); 16217 CHECK_EQ(last_message, NULL);
16222 } 16218 }
16223 16219
16224 TEST(IsolateEnterExitDefault) { 16220 TEST(IsolateEnterExitDefault) {
16225 v8::HandleScope scope;
16226 LocalContext context;
16227 v8::Isolate* current_isolate = v8::Isolate::GetCurrent(); 16221 v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
16228 CHECK(current_isolate != NULL); // Default isolate. 16222 CHECK(current_isolate != NULL); // Default isolate.
16223 v8::HandleScope scope(current_isolate);
16224 LocalContext context;
16229 ExpectString("'hello'", "hello"); 16225 ExpectString("'hello'", "hello");
16230 current_isolate->Enter(); 16226 current_isolate->Enter();
16231 ExpectString("'still working'", "still working"); 16227 ExpectString("'still working'", "still working");
16232 current_isolate->Exit(); 16228 current_isolate->Exit();
16233 ExpectString("'still working 2'", "still working 2"); 16229 ExpectString("'still working 2'", "still working 2");
16234 current_isolate->Exit(); 16230 current_isolate->Exit();
16235 // Default isolate is always, well, 'default current'. 16231 // Default isolate is always, well, 'default current'.
16236 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate); 16232 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate);
16237 // Still working since default isolate is auto-entering any thread 16233 // Still working since default isolate is auto-entering any thread
16238 // that has no isolate and attempts to execute V8 APIs. 16234 // that has no isolate and attempts to execute V8 APIs.
16239 ExpectString("'still working 3'", "still working 3"); 16235 ExpectString("'still working 3'", "still working 3");
16240 } 16236 }
16241 16237
16242 TEST(DisposeDefaultIsolate) { 16238 TEST(DisposeDefaultIsolate) {
16243 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16239 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16244 16240
16245 // Run some V8 code to trigger default isolate to become 'current'. 16241 // Run some V8 code to trigger default isolate to become 'current'.
16246 v8::HandleScope scope; 16242 v8::HandleScope scope(v8::Isolate::GetCurrent());
16247 LocalContext context; 16243 LocalContext context;
16248 ExpectString("'run some V8'", "run some V8"); 16244 ExpectString("'run some V8'", "run some V8");
16249 16245
16250 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 16246 v8::Isolate* isolate = v8::Isolate::GetCurrent();
16251 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate()); 16247 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
16252 last_location = last_message = NULL; 16248 last_location = last_message = NULL;
16253 isolate->Dispose(); 16249 isolate->Dispose();
16254 // It is not possible to dispose default isolate via Isolate API. 16250 // It is not possible to dispose default isolate via Isolate API.
16255 CHECK_NE(last_location, NULL); 16251 CHECK_NE(last_location, NULL);
16256 CHECK_NE(last_message, NULL); 16252 CHECK_NE(last_message, NULL);
16257 } 16253 }
16258 16254
16259 TEST(RunDefaultAndAnotherIsolate) { 16255 TEST(RunDefaultAndAnotherIsolate) {
16260 v8::HandleScope scope; 16256 v8::HandleScope scope(v8::Isolate::GetCurrent());
16261 LocalContext context; 16257 LocalContext context;
16262 16258
16263 // Enter new isolate. 16259 // Enter new isolate.
16264 v8::Isolate* isolate = v8::Isolate::New(); 16260 v8::Isolate* isolate = v8::Isolate::New();
16265 CHECK(isolate); 16261 CHECK(isolate);
16266 isolate->Enter(); 16262 isolate->Enter();
16267 { // Need this block because subsequent Exit() will deallocate Heap, 16263 { // Need this block because subsequent Exit() will deallocate Heap,
16268 // so we need all scope objects to be deconstructed when it happens. 16264 // so we need all scope objects to be deconstructed when it happens.
16269 v8::HandleScope scope_new; 16265 v8::HandleScope scope_new(isolate);
16270 LocalContext context_new; 16266 LocalContext context_new;
16271 16267
16272 // Run something in new isolate. 16268 // Run something in new isolate.
16273 CompileRun("var foo = 153;"); 16269 CompileRun("var foo = 153;");
16274 ExpectTrue("function f() { return foo == 153; }; f()"); 16270 ExpectTrue("function f() { return foo == 153; }; f()");
16275 } 16271 }
16276 isolate->Exit(); 16272 isolate->Exit();
16277 16273
16278 // This runs automatically in default isolate. 16274 // This runs automatically in default isolate.
16279 // Variables in another isolate should be not available. 16275 // Variables in another isolate should be not available.
(...skipping 15 matching lines...) Expand all
16295 CHECK_EQ(last_message, NULL); 16291 CHECK_EQ(last_message, NULL);
16296 16292
16297 // Check that default isolate still runs. 16293 // Check that default isolate still runs.
16298 ExpectTrue("function f() { return bar == 371; }; f()"); 16294 ExpectTrue("function f() { return bar == 371; }; f()");
16299 } 16295 }
16300 16296
16301 TEST(DisposeIsolateWhenInUse) { 16297 TEST(DisposeIsolateWhenInUse) {
16302 v8::Isolate* isolate = v8::Isolate::New(); 16298 v8::Isolate* isolate = v8::Isolate::New();
16303 CHECK(isolate); 16299 CHECK(isolate);
16304 isolate->Enter(); 16300 isolate->Enter();
16305 v8::HandleScope scope; 16301 v8::HandleScope scope(isolate);
16306 LocalContext context; 16302 LocalContext context;
16307 // Run something in this isolate. 16303 // Run something in this isolate.
16308 ExpectTrue("true"); 16304 ExpectTrue("true");
16309 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16305 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16310 last_location = last_message = NULL; 16306 last_location = last_message = NULL;
16311 // Still entered, should fail. 16307 // Still entered, should fail.
16312 isolate->Dispose(); 16308 isolate->Dispose();
16313 CHECK_NE(last_location, NULL); 16309 CHECK_NE(last_location, NULL);
16314 CHECK_NE(last_message, NULL); 16310 CHECK_NE(last_message, NULL);
16315 } 16311 }
16316 16312
16317 TEST(RunTwoIsolatesOnSingleThread) { 16313 TEST(RunTwoIsolatesOnSingleThread) {
16318 // Run isolate 1. 16314 // Run isolate 1.
16319 v8::Isolate* isolate1 = v8::Isolate::New(); 16315 v8::Isolate* isolate1 = v8::Isolate::New();
16320 isolate1->Enter(); 16316 isolate1->Enter();
16321 v8::Persistent<v8::Context> context1 = v8::Context::New(); 16317 v8::Persistent<v8::Context> context1 = v8::Context::New();
16322 16318
16323 { 16319 {
16324 v8::Context::Scope cscope(context1); 16320 v8::Context::Scope cscope(context1);
16325 v8::HandleScope scope; 16321 v8::HandleScope scope(isolate1);
16326 // Run something in new isolate. 16322 // Run something in new isolate.
16327 CompileRun("var foo = 'isolate 1';"); 16323 CompileRun("var foo = 'isolate 1';");
16328 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16324 ExpectString("function f() { return foo; }; f()", "isolate 1");
16329 } 16325 }
16330 16326
16331 // Run isolate 2. 16327 // Run isolate 2.
16332 v8::Isolate* isolate2 = v8::Isolate::New(); 16328 v8::Isolate* isolate2 = v8::Isolate::New();
16333 v8::Persistent<v8::Context> context2; 16329 v8::Persistent<v8::Context> context2;
16334 16330
16335 { 16331 {
16336 v8::Isolate::Scope iscope(isolate2); 16332 v8::Isolate::Scope iscope(isolate2);
16337 context2 = v8::Context::New(); 16333 context2 = v8::Context::New();
16338 v8::Context::Scope cscope(context2); 16334 v8::Context::Scope cscope(context2);
16339 v8::HandleScope scope; 16335 v8::HandleScope scope(isolate2);
16340 16336
16341 // Run something in new isolate. 16337 // Run something in new isolate.
16342 CompileRun("var foo = 'isolate 2';"); 16338 CompileRun("var foo = 'isolate 2';");
16343 ExpectString("function f() { return foo; }; f()", "isolate 2"); 16339 ExpectString("function f() { return foo; }; f()", "isolate 2");
16344 } 16340 }
16345 16341
16346 { 16342 {
16347 v8::Context::Scope cscope(context1); 16343 v8::Context::Scope cscope(context1);
16348 v8::HandleScope scope; 16344 v8::HandleScope scope(isolate1);
16349 // Now again in isolate 1 16345 // Now again in isolate 1
16350 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16346 ExpectString("function f() { return foo; }; f()", "isolate 1");
16351 } 16347 }
16352 16348
16353 isolate1->Exit(); 16349 isolate1->Exit();
16354 16350
16355 // Run some stuff in default isolate. 16351 // Run some stuff in default isolate.
16356 v8::Persistent<v8::Context> context_default = v8::Context::New(); 16352 v8::Persistent<v8::Context> context_default = v8::Context::New();
16357 16353
16358 { 16354 {
16359 v8::Context::Scope cscope(context_default); 16355 v8::Context::Scope cscope(context_default);
16360 v8::HandleScope scope; 16356 v8::HandleScope scope(v8::Isolate::GetCurrent());
16361 // Variables in other isolates should be not available, verify there 16357 // Variables in other isolates should be not available, verify there
16362 // is an exception. 16358 // is an exception.
16363 ExpectTrue("function f() {" 16359 ExpectTrue("function f() {"
16364 " try {" 16360 " try {"
16365 " foo;" 16361 " foo;"
16366 " return false;" 16362 " return false;"
16367 " } catch(e) {" 16363 " } catch(e) {"
16368 " return true;" 16364 " return true;"
16369 " }" 16365 " }"
16370 "};" 16366 "};"
16371 "var isDefaultIsolate = true;" 16367 "var isDefaultIsolate = true;"
16372 "f()"); 16368 "f()");
16373 } 16369 }
16374 16370
16375 isolate1->Enter(); 16371 isolate1->Enter();
16376 16372
16377 { 16373 {
16378 v8::Isolate::Scope iscope(isolate2); 16374 v8::Isolate::Scope iscope(isolate2);
16379 v8::Context::Scope cscope(context2); 16375 v8::Context::Scope cscope(context2);
16380 v8::HandleScope scope; 16376 v8::HandleScope scope(v8::Isolate::GetCurrent());
16381 ExpectString("function f() { return foo; }; f()", "isolate 2"); 16377 ExpectString("function f() { return foo; }; f()", "isolate 2");
16382 } 16378 }
16383 16379
16384 { 16380 {
16385 v8::Context::Scope cscope(context1); 16381 v8::Context::Scope cscope(context1);
16386 v8::HandleScope scope; 16382 v8::HandleScope scope(v8::Isolate::GetCurrent());
16387 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16383 ExpectString("function f() { return foo; }; f()", "isolate 1");
16388 } 16384 }
16389 16385
16390 { 16386 {
16391 v8::Isolate::Scope iscope(isolate2); 16387 v8::Isolate::Scope iscope(isolate2);
16392 context2.Dispose(context2->GetIsolate()); 16388 context2.Dispose(context2->GetIsolate());
16393 } 16389 }
16394 16390
16395 context1.Dispose(context1->GetIsolate()); 16391 context1.Dispose(context1->GetIsolate());
16396 isolate1->Exit(); 16392 isolate1->Exit();
16397 16393
16398 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16394 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16399 last_location = last_message = NULL; 16395 last_location = last_message = NULL;
16400 16396
16401 isolate1->Dispose(); 16397 isolate1->Dispose();
16402 CHECK_EQ(last_location, NULL); 16398 CHECK_EQ(last_location, NULL);
16403 CHECK_EQ(last_message, NULL); 16399 CHECK_EQ(last_message, NULL);
16404 16400
16405 isolate2->Dispose(); 16401 isolate2->Dispose();
16406 CHECK_EQ(last_location, NULL); 16402 CHECK_EQ(last_location, NULL);
16407 CHECK_EQ(last_message, NULL); 16403 CHECK_EQ(last_message, NULL);
16408 16404
16409 // Check that default isolate still runs. 16405 // Check that default isolate still runs.
16410 { 16406 {
16411 v8::Context::Scope cscope(context_default); 16407 v8::Context::Scope cscope(context_default);
16412 v8::HandleScope scope; 16408 v8::HandleScope scope(v8::Isolate::GetCurrent());
16413 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); 16409 ExpectTrue("function f() { return isDefaultIsolate; }; f()");
16414 } 16410 }
16415 } 16411 }
16416 16412
16417 static int CalcFibonacci(v8::Isolate* isolate, int limit) { 16413 static int CalcFibonacci(v8::Isolate* isolate, int limit) {
16418 v8::Isolate::Scope isolate_scope(isolate); 16414 v8::Isolate::Scope isolate_scope(isolate);
16419 v8::HandleScope scope; 16415 v8::HandleScope scope(isolate);
16420 LocalContext context; 16416 LocalContext context;
16421 i::ScopedVector<char> code(1024); 16417 i::ScopedVector<char> code(1024);
16422 i::OS::SNPrintF(code, "function fib(n) {" 16418 i::OS::SNPrintF(code, "function fib(n) {"
16423 " if (n <= 2) return 1;" 16419 " if (n <= 2) return 1;"
16424 " return fib(n-1) + fib(n-2);" 16420 " return fib(n-1) + fib(n-2);"
16425 "}" 16421 "}"
16426 "fib(%d)", limit); 16422 "fib(%d)", limit);
16427 Local<Value> value = CompileRun(code.start()); 16423 Local<Value> value = CompileRun(code.start());
16428 CHECK(value->IsNumber()); 16424 CHECK(value->IsNumber());
16429 return static_cast<int>(value->NumberValue()); 16425 return static_cast<int>(value->NumberValue());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
16475 16471
16476 isolate1->Dispose(); 16472 isolate1->Dispose();
16477 isolate2->Dispose(); 16473 isolate2->Dispose();
16478 } 16474 }
16479 16475
16480 TEST(IsolateDifferentContexts) { 16476 TEST(IsolateDifferentContexts) {
16481 v8::Isolate* isolate = v8::Isolate::New(); 16477 v8::Isolate* isolate = v8::Isolate::New();
16482 Persistent<v8::Context> context; 16478 Persistent<v8::Context> context;
16483 { 16479 {
16484 v8::Isolate::Scope isolate_scope(isolate); 16480 v8::Isolate::Scope isolate_scope(isolate);
16485 v8::HandleScope handle_scope; 16481 v8::HandleScope handle_scope(isolate);
16486 context = v8::Context::New(); 16482 context = v8::Context::New();
16487 v8::Context::Scope context_scope(context); 16483 v8::Context::Scope context_scope(context);
16488 Local<Value> v = CompileRun("2"); 16484 Local<Value> v = CompileRun("2");
16489 CHECK(v->IsNumber()); 16485 CHECK(v->IsNumber());
16490 CHECK_EQ(2, static_cast<int>(v->NumberValue())); 16486 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
16491 } 16487 }
16492 { 16488 {
16493 v8::Isolate::Scope isolate_scope(isolate); 16489 v8::Isolate::Scope isolate_scope(isolate);
16494 v8::HandleScope handle_scope; 16490 v8::HandleScope handle_scope(isolate);
16495 context = v8::Context::New(); 16491 context = v8::Context::New();
16496 v8::Context::Scope context_scope(context); 16492 v8::Context::Scope context_scope(context);
16497 Local<Value> v = CompileRun("22"); 16493 Local<Value> v = CompileRun("22");
16498 CHECK(v->IsNumber()); 16494 CHECK(v->IsNumber());
16499 CHECK_EQ(22, static_cast<int>(v->NumberValue())); 16495 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
16500 } 16496 }
16501 isolate->Dispose(); 16497 isolate->Dispose();
16502 } 16498 }
16503 16499
16504 class InitDefaultIsolateThread : public v8::internal::Thread { 16500 class InitDefaultIsolateThread : public v8::internal::Thread {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
16590 InitializeTestHelper(InitDefaultIsolateThread::SetAddHistogramSampleFunction); 16586 InitializeTestHelper(InitDefaultIsolateThread::SetAddHistogramSampleFunction);
16591 } 16587 }
16592 16588
16593 16589
16594 TEST(StringCheckMultipleContexts) { 16590 TEST(StringCheckMultipleContexts) {
16595 const char* code = 16591 const char* code =
16596 "(function() { return \"a\".charAt(0); })()"; 16592 "(function() { return \"a\".charAt(0); })()";
16597 16593
16598 { 16594 {
16599 // Run the code twice in the first context to initialize the call IC. 16595 // Run the code twice in the first context to initialize the call IC.
16600 v8::HandleScope scope;
16601 LocalContext context1; 16596 LocalContext context1;
16597 v8::HandleScope scope(context1->GetIsolate());
16602 ExpectString(code, "a"); 16598 ExpectString(code, "a");
16603 ExpectString(code, "a"); 16599 ExpectString(code, "a");
16604 } 16600 }
16605 16601
16606 { 16602 {
16607 // Change the String.prototype in the second context and check 16603 // Change the String.prototype in the second context and check
16608 // that the right function gets called. 16604 // that the right function gets called.
16609 v8::HandleScope scope;
16610 LocalContext context2; 16605 LocalContext context2;
16606 v8::HandleScope scope(context2->GetIsolate());
16611 CompileRun("String.prototype.charAt = function() { return \"not a\"; }"); 16607 CompileRun("String.prototype.charAt = function() { return \"not a\"; }");
16612 ExpectString(code, "not a"); 16608 ExpectString(code, "not a");
16613 } 16609 }
16614 } 16610 }
16615 16611
16616 16612
16617 TEST(NumberCheckMultipleContexts) { 16613 TEST(NumberCheckMultipleContexts) {
16618 const char* code = 16614 const char* code =
16619 "(function() { return (42).toString(); })()"; 16615 "(function() { return (42).toString(); })()";
16620 16616
16621 { 16617 {
16622 // Run the code twice in the first context to initialize the call IC. 16618 // Run the code twice in the first context to initialize the call IC.
16623 v8::HandleScope scope;
16624 LocalContext context1; 16619 LocalContext context1;
16620 v8::HandleScope scope(context1->GetIsolate());
16625 ExpectString(code, "42"); 16621 ExpectString(code, "42");
16626 ExpectString(code, "42"); 16622 ExpectString(code, "42");
16627 } 16623 }
16628 16624
16629 { 16625 {
16630 // Change the Number.prototype in the second context and check 16626 // Change the Number.prototype in the second context and check
16631 // that the right function gets called. 16627 // that the right function gets called.
16632 v8::HandleScope scope;
16633 LocalContext context2; 16628 LocalContext context2;
16629 v8::HandleScope scope(context2->GetIsolate());
16634 CompileRun("Number.prototype.toString = function() { return \"not 42\"; }"); 16630 CompileRun("Number.prototype.toString = function() { return \"not 42\"; }");
16635 ExpectString(code, "not 42"); 16631 ExpectString(code, "not 42");
16636 } 16632 }
16637 } 16633 }
16638 16634
16639 16635
16640 TEST(BooleanCheckMultipleContexts) { 16636 TEST(BooleanCheckMultipleContexts) {
16641 const char* code = 16637 const char* code =
16642 "(function() { return true.toString(); })()"; 16638 "(function() { return true.toString(); })()";
16643 16639
16644 { 16640 {
16645 // Run the code twice in the first context to initialize the call IC. 16641 // Run the code twice in the first context to initialize the call IC.
16646 v8::HandleScope scope;
16647 LocalContext context1; 16642 LocalContext context1;
16643 v8::HandleScope scope(context1->GetIsolate());
16648 ExpectString(code, "true"); 16644 ExpectString(code, "true");
16649 ExpectString(code, "true"); 16645 ExpectString(code, "true");
16650 } 16646 }
16651 16647
16652 { 16648 {
16653 // Change the Boolean.prototype in the second context and check 16649 // Change the Boolean.prototype in the second context and check
16654 // that the right function gets called. 16650 // that the right function gets called.
16655 v8::HandleScope scope;
16656 LocalContext context2; 16651 LocalContext context2;
16652 v8::HandleScope scope(context2->GetIsolate());
16657 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); 16653 CompileRun("Boolean.prototype.toString = function() { return \"\"; }");
16658 ExpectString(code, ""); 16654 ExpectString(code, "");
16659 } 16655 }
16660 } 16656 }
16661 16657
16662 16658
16663 TEST(DontDeleteCellLoadIC) { 16659 TEST(DontDeleteCellLoadIC) {
16664 const char* function_code = 16660 const char* function_code =
16665 "function readCell() { while (true) { return cell; } }"; 16661 "function readCell() { while (true) { return cell; } }";
16666 16662
16667 { 16663 {
16668 // Run the code twice in the first context to initialize the load 16664 // Run the code twice in the first context to initialize the load
16669 // IC for a don't delete cell. 16665 // IC for a don't delete cell.
16670 v8::HandleScope scope;
16671 LocalContext context1; 16666 LocalContext context1;
16667 v8::HandleScope scope(context1->GetIsolate());
16672 CompileRun("var cell = \"first\";"); 16668 CompileRun("var cell = \"first\";");
16673 ExpectBoolean("delete cell", false); 16669 ExpectBoolean("delete cell", false);
16674 CompileRun(function_code); 16670 CompileRun(function_code);
16675 ExpectString("readCell()", "first"); 16671 ExpectString("readCell()", "first");
16676 ExpectString("readCell()", "first"); 16672 ExpectString("readCell()", "first");
16677 } 16673 }
16678 16674
16679 { 16675 {
16680 // Use a deletable cell in the second context. 16676 // Use a deletable cell in the second context.
16681 v8::HandleScope scope;
16682 LocalContext context2; 16677 LocalContext context2;
16678 v8::HandleScope scope(context2->GetIsolate());
16683 CompileRun("cell = \"second\";"); 16679 CompileRun("cell = \"second\";");
16684 CompileRun(function_code); 16680 CompileRun(function_code);
16685 ExpectString("readCell()", "second"); 16681 ExpectString("readCell()", "second");
16686 ExpectBoolean("delete cell", true); 16682 ExpectBoolean("delete cell", true);
16687 ExpectString("(function() {" 16683 ExpectString("(function() {"
16688 " try {" 16684 " try {"
16689 " return readCell();" 16685 " return readCell();"
16690 " } catch(e) {" 16686 " } catch(e) {"
16691 " return e.toString();" 16687 " return e.toString();"
16692 " }" 16688 " }"
16693 "})()", 16689 "})()",
16694 "ReferenceError: cell is not defined"); 16690 "ReferenceError: cell is not defined");
16695 CompileRun("cell = \"new_second\";"); 16691 CompileRun("cell = \"new_second\";");
16696 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16692 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16697 ExpectString("readCell()", "new_second"); 16693 ExpectString("readCell()", "new_second");
16698 ExpectString("readCell()", "new_second"); 16694 ExpectString("readCell()", "new_second");
16699 } 16695 }
16700 } 16696 }
16701 16697
16702 16698
16703 TEST(DontDeleteCellLoadICForceDelete) { 16699 TEST(DontDeleteCellLoadICForceDelete) {
16704 const char* function_code = 16700 const char* function_code =
16705 "function readCell() { while (true) { return cell; } }"; 16701 "function readCell() { while (true) { return cell; } }";
16706 16702
16707 // Run the code twice to initialize the load IC for a don't delete 16703 // Run the code twice to initialize the load IC for a don't delete
16708 // cell. 16704 // cell.
16709 v8::HandleScope scope;
16710 LocalContext context; 16705 LocalContext context;
16706 v8::HandleScope scope(context->GetIsolate());
16711 CompileRun("var cell = \"value\";"); 16707 CompileRun("var cell = \"value\";");
16712 ExpectBoolean("delete cell", false); 16708 ExpectBoolean("delete cell", false);
16713 CompileRun(function_code); 16709 CompileRun(function_code);
16714 ExpectString("readCell()", "value"); 16710 ExpectString("readCell()", "value");
16715 ExpectString("readCell()", "value"); 16711 ExpectString("readCell()", "value");
16716 16712
16717 // Delete the cell using the API and check the inlined code works 16713 // Delete the cell using the API and check the inlined code works
16718 // correctly. 16714 // correctly.
16719 CHECK(context->Global()->ForceDelete(v8_str("cell"))); 16715 CHECK(context->Global()->ForceDelete(v8_str("cell")));
16720 ExpectString("(function() {" 16716 ExpectString("(function() {"
16721 " try {" 16717 " try {"
16722 " return readCell();" 16718 " return readCell();"
16723 " } catch(e) {" 16719 " } catch(e) {"
16724 " return e.toString();" 16720 " return e.toString();"
16725 " }" 16721 " }"
16726 "})()", 16722 "})()",
16727 "ReferenceError: cell is not defined"); 16723 "ReferenceError: cell is not defined");
16728 } 16724 }
16729 16725
16730 16726
16731 TEST(DontDeleteCellLoadICAPI) { 16727 TEST(DontDeleteCellLoadICAPI) {
16732 const char* function_code = 16728 const char* function_code =
16733 "function readCell() { while (true) { return cell; } }"; 16729 "function readCell() { while (true) { return cell; } }";
16734 16730
16735 // Run the code twice to initialize the load IC for a don't delete 16731 // Run the code twice to initialize the load IC for a don't delete
16736 // cell created using the API. 16732 // cell created using the API.
16737 v8::HandleScope scope;
16738 LocalContext context; 16733 LocalContext context;
16734 v8::HandleScope scope(context->GetIsolate());
16739 context->Global()->Set(v8_str("cell"), v8_str("value"), v8::DontDelete); 16735 context->Global()->Set(v8_str("cell"), v8_str("value"), v8::DontDelete);
16740 ExpectBoolean("delete cell", false); 16736 ExpectBoolean("delete cell", false);
16741 CompileRun(function_code); 16737 CompileRun(function_code);
16742 ExpectString("readCell()", "value"); 16738 ExpectString("readCell()", "value");
16743 ExpectString("readCell()", "value"); 16739 ExpectString("readCell()", "value");
16744 16740
16745 // Delete the cell using the API and check the inlined code works 16741 // Delete the cell using the API and check the inlined code works
16746 // correctly. 16742 // correctly.
16747 CHECK(context->Global()->ForceDelete(v8_str("cell"))); 16743 CHECK(context->Global()->ForceDelete(v8_str("cell")));
16748 ExpectString("(function() {" 16744 ExpectString("(function() {"
(...skipping 23 matching lines...) Expand all
16772 ++counter_; 16768 ++counter_;
16773 } 16769 }
16774 } 16770 }
16775 16771
16776 int counter_; 16772 int counter_;
16777 v8::Persistent<v8::Object> object_; 16773 v8::Persistent<v8::Object> object_;
16778 }; 16774 };
16779 16775
16780 16776
16781 TEST(PersistentHandleVisitor) { 16777 TEST(PersistentHandleVisitor) {
16782 v8::HandleScope scope;
16783 LocalContext context; 16778 LocalContext context;
16784 v8::Isolate* isolate = context->GetIsolate(); 16779 v8::Isolate* isolate = context->GetIsolate();
16780 v8::HandleScope scope(isolate);
16785 v8::Persistent<v8::Object> object = 16781 v8::Persistent<v8::Object> object =
16786 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16782 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16787 CHECK_EQ(0, object.WrapperClassId(isolate)); 16783 CHECK_EQ(0, object.WrapperClassId(isolate));
16788 object.SetWrapperClassId(isolate, 42); 16784 object.SetWrapperClassId(isolate, 42);
16789 CHECK_EQ(42, object.WrapperClassId(isolate)); 16785 CHECK_EQ(42, object.WrapperClassId(isolate));
16790 16786
16791 Visitor42 visitor(object); 16787 Visitor42 visitor(object);
16792 v8::V8::VisitHandlesWithClassIds(&visitor); 16788 v8::V8::VisitHandlesWithClassIds(&visitor);
16793 CHECK_EQ(1, visitor.counter_); 16789 CHECK_EQ(1, visitor.counter_);
16794 16790
16795 object.Dispose(isolate); 16791 object.Dispose(isolate);
16796 } 16792 }
16797 16793
16798 16794
16799 TEST(WrapperClassId) { 16795 TEST(WrapperClassId) {
16800 v8::HandleScope scope;
16801 LocalContext context; 16796 LocalContext context;
16802 v8::Isolate* isolate = context->GetIsolate(); 16797 v8::Isolate* isolate = context->GetIsolate();
16798 v8::HandleScope scope(isolate);
16803 v8::Persistent<v8::Object> object = 16799 v8::Persistent<v8::Object> object =
16804 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16800 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16805 CHECK_EQ(0, object.WrapperClassId(isolate)); 16801 CHECK_EQ(0, object.WrapperClassId(isolate));
16806 object.SetWrapperClassId(isolate, 65535); 16802 object.SetWrapperClassId(isolate, 65535);
16807 CHECK_EQ(65535, object.WrapperClassId(isolate)); 16803 CHECK_EQ(65535, object.WrapperClassId(isolate));
16808 object.Dispose(isolate); 16804 object.Dispose(isolate);
16809 } 16805 }
16810 16806
16811 16807
16812 TEST(PersistentHandleInNewSpaceVisitor) { 16808 TEST(PersistentHandleInNewSpaceVisitor) {
16813 v8::HandleScope scope;
16814 LocalContext context; 16809 LocalContext context;
16815 v8::Isolate* isolate = context->GetIsolate(); 16810 v8::Isolate* isolate = context->GetIsolate();
16811 v8::HandleScope scope(isolate);
16816 v8::Persistent<v8::Object> object1 = 16812 v8::Persistent<v8::Object> object1 =
16817 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16813 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16818 CHECK_EQ(0, object1.WrapperClassId(isolate)); 16814 CHECK_EQ(0, object1.WrapperClassId(isolate));
16819 object1.SetWrapperClassId(isolate, 42); 16815 object1.SetWrapperClassId(isolate, 42);
16820 CHECK_EQ(42, object1.WrapperClassId(isolate)); 16816 CHECK_EQ(42, object1.WrapperClassId(isolate));
16821 16817
16822 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16818 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16823 16819
16824 v8::Persistent<v8::Object> object2 = 16820 v8::Persistent<v8::Object> object2 =
16825 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16821 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16826 CHECK_EQ(0, object2.WrapperClassId(isolate)); 16822 CHECK_EQ(0, object2.WrapperClassId(isolate));
16827 object2.SetWrapperClassId(isolate, 42); 16823 object2.SetWrapperClassId(isolate, 42);
16828 CHECK_EQ(42, object2.WrapperClassId(isolate)); 16824 CHECK_EQ(42, object2.WrapperClassId(isolate));
16829 16825
16830 Visitor42 visitor(object2); 16826 Visitor42 visitor(object2);
16831 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 16827 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
16832 CHECK_EQ(1, visitor.counter_); 16828 CHECK_EQ(1, visitor.counter_);
16833 16829
16834 object1.Dispose(isolate); 16830 object1.Dispose(isolate);
16835 object2.Dispose(isolate); 16831 object2.Dispose(isolate);
16836 } 16832 }
16837 16833
16838 16834
16839 TEST(RegExp) { 16835 TEST(RegExp) {
16840 v8::HandleScope scope;
16841 LocalContext context; 16836 LocalContext context;
16837 v8::HandleScope scope(context->GetIsolate());
16842 16838
16843 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); 16839 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
16844 CHECK(re->IsRegExp()); 16840 CHECK(re->IsRegExp());
16845 CHECK(re->GetSource()->Equals(v8_str("foo"))); 16841 CHECK(re->GetSource()->Equals(v8_str("foo")));
16846 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); 16842 CHECK_EQ(v8::RegExp::kNone, re->GetFlags());
16847 16843
16848 re = v8::RegExp::New(v8_str("bar"), 16844 re = v8::RegExp::New(v8_str("bar"),
16849 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | 16845 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
16850 v8::RegExp::kGlobal)); 16846 v8::RegExp::kGlobal));
16851 CHECK(re->IsRegExp()); 16847 CHECK(re->IsRegExp());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
16900 v8::TryCatch try_catch; 16896 v8::TryCatch try_catch;
16901 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 16897 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
16902 CHECK(re.IsEmpty()); 16898 CHECK(re.IsEmpty());
16903 CHECK(try_catch.HasCaught()); 16899 CHECK(try_catch.HasCaught());
16904 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 16900 context->Global()->Set(v8_str("ex"), try_catch.Exception());
16905 ExpectTrue("ex instanceof SyntaxError"); 16901 ExpectTrue("ex instanceof SyntaxError");
16906 } 16902 }
16907 16903
16908 16904
16909 THREADED_TEST(Equals) { 16905 THREADED_TEST(Equals) {
16910 v8::HandleScope handleScope;
16911 LocalContext localContext; 16906 LocalContext localContext;
16907 v8::HandleScope handleScope(localContext->GetIsolate());
16912 16908
16913 v8::Handle<v8::Object> globalProxy = localContext->Global(); 16909 v8::Handle<v8::Object> globalProxy = localContext->Global();
16914 v8::Handle<Value> global = globalProxy->GetPrototype(); 16910 v8::Handle<Value> global = globalProxy->GetPrototype();
16915 16911
16916 CHECK(global->StrictEquals(global)); 16912 CHECK(global->StrictEquals(global));
16917 CHECK(!global->StrictEquals(globalProxy)); 16913 CHECK(!global->StrictEquals(globalProxy));
16918 CHECK(!globalProxy->StrictEquals(global)); 16914 CHECK(!globalProxy->StrictEquals(global));
16919 CHECK(globalProxy->StrictEquals(globalProxy)); 16915 CHECK(globalProxy->StrictEquals(globalProxy));
16920 16916
16921 CHECK(global->Equals(global)); 16917 CHECK(global->Equals(global));
(...skipping 10 matching lines...) Expand all
16932 16928
16933 16929
16934 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { 16930 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) {
16935 v8::Handle<v8::Array> result = v8::Array::New(); 16931 v8::Handle<v8::Array> result = v8::Array::New();
16936 result->Set(0, v8_str("universalAnswer")); 16932 result->Set(0, v8_str("universalAnswer"));
16937 return result; 16933 return result;
16938 } 16934 }
16939 16935
16940 16936
16941 TEST(NamedEnumeratorAndForIn) { 16937 TEST(NamedEnumeratorAndForIn) {
16942 v8::HandleScope handle_scope;
16943 LocalContext context; 16938 LocalContext context;
16939 v8::HandleScope handle_scope(context->GetIsolate());
16944 v8::Context::Scope context_scope(context.local()); 16940 v8::Context::Scope context_scope(context.local());
16945 16941
16946 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 16942 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
16947 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 16943 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
16948 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 16944 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
16949 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 16945 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
16950 "var result = []; for (var k in o) result.push(k); result")); 16946 "var result = []; for (var k in o) result.push(k); result"));
16951 CHECK_EQ(1, result->Length()); 16947 CHECK_EQ(1, result->Length());
16952 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 16948 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
16953 } 16949 }
16954 16950
16955 16951
16956 TEST(DefinePropertyPostDetach) { 16952 TEST(DefinePropertyPostDetach) {
16957 v8::HandleScope scope;
16958 LocalContext context; 16953 LocalContext context;
16954 v8::HandleScope scope(context->GetIsolate());
16959 v8::Handle<v8::Object> proxy = context->Global(); 16955 v8::Handle<v8::Object> proxy = context->Global();
16960 v8::Handle<v8::Function> define_property = 16956 v8::Handle<v8::Function> define_property =
16961 CompileRun("(function() {" 16957 CompileRun("(function() {"
16962 " Object.defineProperty(" 16958 " Object.defineProperty("
16963 " this," 16959 " this,"
16964 " 1," 16960 " 1,"
16965 " { configurable: true, enumerable: true, value: 3 });" 16961 " { configurable: true, enumerable: true, value: 3 });"
16966 "})").As<Function>(); 16962 "})").As<Function>();
16967 context->DetachGlobal(); 16963 context->DetachGlobal();
16968 define_property->Call(proxy, 0, NULL); 16964 define_property->Call(proxy, 0, NULL);
16969 } 16965 }
16970 16966
16971 16967
16972 static void InstallContextId(v8::Handle<Context> context, int id) { 16968 static void InstallContextId(v8::Handle<Context> context, int id) {
16973 Context::Scope scope(context); 16969 Context::Scope scope(context);
16974 CompileRun("Object.prototype").As<Object>()-> 16970 CompileRun("Object.prototype").As<Object>()->
16975 Set(v8_str("context_id"), v8::Integer::New(id)); 16971 Set(v8_str("context_id"), v8::Integer::New(id));
16976 } 16972 }
16977 16973
16978 16974
16979 static void CheckContextId(v8::Handle<Object> object, int expected) { 16975 static void CheckContextId(v8::Handle<Object> object, int expected) {
16980 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 16976 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
16981 } 16977 }
16982 16978
16983 16979
16984 THREADED_TEST(CreationContext) { 16980 THREADED_TEST(CreationContext) {
16985 HandleScope handle_scope; 16981 HandleScope handle_scope(v8::Isolate::GetCurrent());
16986 Persistent<Context> context1 = Context::New(); 16982 Persistent<Context> context1 = Context::New();
16987 InstallContextId(context1, 1); 16983 InstallContextId(context1, 1);
16988 Persistent<Context> context2 = Context::New(); 16984 Persistent<Context> context2 = Context::New();
16989 InstallContextId(context2, 2); 16985 InstallContextId(context2, 2);
16990 Persistent<Context> context3 = Context::New(); 16986 Persistent<Context> context3 = Context::New();
16991 InstallContextId(context3, 3); 16987 InstallContextId(context3, 3);
16992 16988
16993 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); 16989 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New();
16994 16990
16995 Local<Object> object1; 16991 Local<Object> object1;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
17062 CheckContextId(instance2, 2); 17058 CheckContextId(instance2, 2);
17063 } 17059 }
17064 17060
17065 context1.Dispose(context1->GetIsolate()); 17061 context1.Dispose(context1->GetIsolate());
17066 context2.Dispose(context2->GetIsolate()); 17062 context2.Dispose(context2->GetIsolate());
17067 context3.Dispose(context3->GetIsolate()); 17063 context3.Dispose(context3->GetIsolate());
17068 } 17064 }
17069 17065
17070 17066
17071 THREADED_TEST(CreationContextOfJsFunction) { 17067 THREADED_TEST(CreationContextOfJsFunction) {
17072 HandleScope handle_scope; 17068 HandleScope handle_scope(v8::Isolate::GetCurrent());
17073 Persistent<Context> context = Context::New(); 17069 Persistent<Context> context = Context::New();
17074 InstallContextId(context, 1); 17070 InstallContextId(context, 1);
17075 17071
17076 Local<Object> function; 17072 Local<Object> function;
17077 { 17073 {
17078 Context::Scope scope(context); 17074 Context::Scope scope(context);
17079 function = CompileRun("function foo() {}; foo").As<Object>(); 17075 function = CompileRun("function foo() {}; foo").As<Object>();
17080 } 17076 }
17081 17077
17082 CHECK(function->CreationContext() == context); 17078 CHECK(function->CreationContext() == context);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
17121 } 17117 }
17122 17118
17123 17119
17124 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property, 17120 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property,
17125 const AccessorInfo& info) { 17121 const AccessorInfo& info) {
17126 return v8_str("yes"); 17122 return v8_str("yes");
17127 } 17123 }
17128 17124
17129 17125
17130 TEST(HasOwnProperty) { 17126 TEST(HasOwnProperty) {
17131 v8::HandleScope scope;
17132 LocalContext env; 17127 LocalContext env;
17128 v8::HandleScope scope(env->GetIsolate());
17133 { // Check normal properties and defined getters. 17129 { // Check normal properties and defined getters.
17134 Handle<Value> value = CompileRun( 17130 Handle<Value> value = CompileRun(
17135 "function Foo() {" 17131 "function Foo() {"
17136 " this.foo = 11;" 17132 " this.foo = 11;"
17137 " this.__defineGetter__('baz', function() { return 1; });" 17133 " this.__defineGetter__('baz', function() { return 1; });"
17138 "};" 17134 "};"
17139 "function Bar() { " 17135 "function Bar() { "
17140 " this.bar = 13;" 17136 " this.bar = 13;"
17141 " this.__defineGetter__('bla', function() { return 2; });" 17137 " this.__defineGetter__('bla', function() { return 2; });"
17142 "};" 17138 "};"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
17194 0, 17190 0,
17195 HasOwnPropertyNamedPropertyQuery2); 17191 HasOwnPropertyNamedPropertyQuery2);
17196 Handle<Object> instance = templ->NewInstance(); 17192 Handle<Object> instance = templ->NewInstance();
17197 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 17193 CHECK(!instance->HasOwnProperty(v8_str("foo")));
17198 CHECK(instance->HasOwnProperty(v8_str("bar"))); 17194 CHECK(instance->HasOwnProperty(v8_str("bar")));
17199 } 17195 }
17200 } 17196 }
17201 17197
17202 17198
17203 TEST(IndexedInterceptorWithStringProto) { 17199 TEST(IndexedInterceptorWithStringProto) {
17204 v8::HandleScope scope; 17200 v8::HandleScope scope(v8::Isolate::GetCurrent());
17205 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 17201 Handle<ObjectTemplate> templ = ObjectTemplate::New();
17206 templ->SetIndexedPropertyHandler(NULL, 17202 templ->SetIndexedPropertyHandler(NULL,
17207 NULL, 17203 NULL,
17208 HasOwnPropertyIndexedPropertyQuery); 17204 HasOwnPropertyIndexedPropertyQuery);
17209 LocalContext context; 17205 LocalContext context;
17210 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 17206 context->Global()->Set(v8_str("obj"), templ->NewInstance());
17211 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); 17207 CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
17212 // These should be intercepted. 17208 // These should be intercepted.
17213 CHECK(CompileRun("42 in obj")->BooleanValue()); 17209 CHECK(CompileRun("42 in obj")->BooleanValue());
17214 CHECK(CompileRun("'42' in obj")->BooleanValue()); 17210 CHECK(CompileRun("'42' in obj")->BooleanValue());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
17256 } 17252 }
17257 17253
17258 17254
17259 bool CodeGenerationDisallowed(Local<Context> context) { 17255 bool CodeGenerationDisallowed(Local<Context> context) {
17260 ApiTestFuzzer::Fuzz(); 17256 ApiTestFuzzer::Fuzz();
17261 return false; 17257 return false;
17262 } 17258 }
17263 17259
17264 17260
17265 THREADED_TEST(AllowCodeGenFromStrings) { 17261 THREADED_TEST(AllowCodeGenFromStrings) {
17266 v8::HandleScope scope;
17267 LocalContext context; 17262 LocalContext context;
17263 v8::HandleScope scope(context->GetIsolate());
17268 17264
17269 // eval and the Function constructor allowed by default. 17265 // eval and the Function constructor allowed by default.
17270 CHECK(context->IsCodeGenerationFromStringsAllowed()); 17266 CHECK(context->IsCodeGenerationFromStringsAllowed());
17271 CheckCodeGenerationAllowed(); 17267 CheckCodeGenerationAllowed();
17272 17268
17273 // Disallow eval and the Function constructor. 17269 // Disallow eval and the Function constructor.
17274 context->AllowCodeGenerationFromStrings(false); 17270 context->AllowCodeGenerationFromStrings(false);
17275 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17271 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17276 CheckCodeGenerationDisallowed(); 17272 CheckCodeGenerationDisallowed();
17277 17273
17278 // Allow again. 17274 // Allow again.
17279 context->AllowCodeGenerationFromStrings(true); 17275 context->AllowCodeGenerationFromStrings(true);
17280 CheckCodeGenerationAllowed(); 17276 CheckCodeGenerationAllowed();
17281 17277
17282 // Disallow but setting a global callback that will allow the calls. 17278 // Disallow but setting a global callback that will allow the calls.
17283 context->AllowCodeGenerationFromStrings(false); 17279 context->AllowCodeGenerationFromStrings(false);
17284 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); 17280 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed);
17285 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17281 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17286 CheckCodeGenerationAllowed(); 17282 CheckCodeGenerationAllowed();
17287 17283
17288 // Set a callback that disallows the code generation. 17284 // Set a callback that disallows the code generation.
17289 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 17285 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
17290 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17286 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17291 CheckCodeGenerationDisallowed(); 17287 CheckCodeGenerationDisallowed();
17292 } 17288 }
17293 17289
17294 17290
17295 TEST(SetErrorMessageForCodeGenFromStrings) { 17291 TEST(SetErrorMessageForCodeGenFromStrings) {
17296 v8::HandleScope scope;
17297 LocalContext context; 17292 LocalContext context;
17293 v8::HandleScope scope(context->GetIsolate());
17298 TryCatch try_catch; 17294 TryCatch try_catch;
17299 17295
17300 Handle<String> message = v8_str("Message") ; 17296 Handle<String> message = v8_str("Message") ;
17301 Handle<String> expected_message = v8_str("Uncaught EvalError: Message"); 17297 Handle<String> expected_message = v8_str("Uncaught EvalError: Message");
17302 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 17298 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
17303 context->AllowCodeGenerationFromStrings(false); 17299 context->AllowCodeGenerationFromStrings(false);
17304 context->SetErrorMessageForCodeGenerationFromStrings(message); 17300 context->SetErrorMessageForCodeGenerationFromStrings(message);
17305 Handle<Value> result = CompileRun("eval('42')"); 17301 Handle<Value> result = CompileRun("eval('42')");
17306 CHECK(result.IsEmpty()); 17302 CHECK(result.IsEmpty());
17307 CHECK(try_catch.HasCaught()); 17303 CHECK(try_catch.HasCaught());
17308 Handle<String> actual_message = try_catch.Message()->Get(); 17304 Handle<String> actual_message = try_catch.Message()->Get();
17309 CHECK(expected_message->Equals(actual_message)); 17305 CHECK(expected_message->Equals(actual_message));
17310 } 17306 }
17311 17307
17312 17308
17313 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) { 17309 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) {
17314 return v8::Undefined(); 17310 return v8::Undefined();
17315 } 17311 }
17316 17312
17317 17313
17318 THREADED_TEST(CallAPIFunctionOnNonObject) { 17314 THREADED_TEST(CallAPIFunctionOnNonObject) {
17319 v8::HandleScope scope;
17320 LocalContext context; 17315 LocalContext context;
17316 v8::HandleScope scope(context->GetIsolate());
17321 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 17317 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
17322 Handle<Function> function = templ->GetFunction(); 17318 Handle<Function> function = templ->GetFunction();
17323 context->Global()->Set(v8_str("f"), function); 17319 context->Global()->Set(v8_str("f"), function);
17324 TryCatch try_catch; 17320 TryCatch try_catch;
17325 CompileRun("f.call(2)"); 17321 CompileRun("f.call(2)");
17326 } 17322 }
17327 17323
17328 17324
17329 // Regression test for issue 1470. 17325 // Regression test for issue 1470.
17330 THREADED_TEST(ReadOnlyIndexedProperties) { 17326 THREADED_TEST(ReadOnlyIndexedProperties) {
17331 v8::HandleScope scope; 17327 v8::HandleScope scope(v8::Isolate::GetCurrent());
17332 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17328 Local<ObjectTemplate> templ = ObjectTemplate::New();
17333 17329
17334 LocalContext context; 17330 LocalContext context;
17335 Local<v8::Object> obj = templ->NewInstance(); 17331 Local<v8::Object> obj = templ->NewInstance();
17336 context->Global()->Set(v8_str("obj"), obj); 17332 context->Global()->Set(v8_str("obj"), obj);
17337 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 17333 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
17338 obj->Set(v8_str("1"), v8_str("foobar")); 17334 obj->Set(v8_str("1"), v8_str("foobar"));
17339 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 17335 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
17340 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 17336 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
17341 obj->Set(v8_num(2), v8_str("foobar")); 17337 obj->Set(v8_num(2), v8_str("foobar"));
17342 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 17338 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
17343 17339
17344 // Test non-smi case. 17340 // Test non-smi case.
17345 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 17341 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
17346 obj->Set(v8_str("2000000000"), v8_str("foobar")); 17342 obj->Set(v8_str("2000000000"), v8_str("foobar"));
17347 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 17343 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
17348 } 17344 }
17349 17345
17350 17346
17351 THREADED_TEST(Regress1516) { 17347 THREADED_TEST(Regress1516) {
17352 v8::HandleScope scope; 17348 LocalContext context;
17349 v8::HandleScope scope(context->GetIsolate());
17353 17350
17354 LocalContext context; 17351 { v8::HandleScope temp_scope(context->GetIsolate());
17355 { v8::HandleScope temp_scope;
17356 CompileRun("({'a': 0})"); 17352 CompileRun("({'a': 0})");
17357 } 17353 }
17358 17354
17359 int elements; 17355 int elements;
17360 { i::MapCache* map_cache = 17356 { i::MapCache* map_cache =
17361 i::MapCache::cast(i::Isolate::Current()->context()->map_cache()); 17357 i::MapCache::cast(i::Isolate::Current()->context()->map_cache());
17362 elements = map_cache->NumberOfElements(); 17358 elements = map_cache->NumberOfElements();
17363 CHECK_LE(1, elements); 17359 CHECK_LE(1, elements);
17364 } 17360 }
17365 17361
(...skipping 20 matching lines...) Expand all
17386 char buffer[10]; 17382 char buffer[10];
17387 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer)); 17383 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
17388 return strncmp(buffer, "__proto__", 9) != 0; 17384 return strncmp(buffer, "__proto__", 9) != 0;
17389 } 17385 }
17390 17386
17391 return true; 17387 return true;
17392 } 17388 }
17393 17389
17394 17390
17395 THREADED_TEST(Regress93759) { 17391 THREADED_TEST(Regress93759) {
17396 HandleScope scope; 17392 HandleScope scope(v8::Isolate::GetCurrent());
17397 17393
17398 // Template for object with security check. 17394 // Template for object with security check.
17399 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 17395 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
17400 // We don't do indexing, so any callback can be used for that. 17396 // We don't do indexing, so any callback can be used for that.
17401 no_proto_template->SetAccessCheckCallbacks( 17397 no_proto_template->SetAccessCheckCallbacks(
17402 BlockProtoNamedSecurityTestCallback, 17398 BlockProtoNamedSecurityTestCallback,
17403 IndexedSecurityTestCallback); 17399 IndexedSecurityTestCallback);
17404 17400
17405 // Templates for objects with hidden prototypes and possibly security check. 17401 // Templates for objects with hidden prototypes and possibly security check.
17406 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); 17402 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
17477 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 17473 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
17478 17474
17479 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 17475 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
17480 CHECK(result6->Equals(Undefined())); 17476 CHECK(result6->Equals(Undefined()));
17481 17477
17482 context.Dispose(context->GetIsolate()); 17478 context.Dispose(context->GetIsolate());
17483 } 17479 }
17484 17480
17485 17481
17486 THREADED_TEST(Regress125988) { 17482 THREADED_TEST(Regress125988) {
17487 v8::HandleScope scope; 17483 v8::HandleScope scope(v8::Isolate::GetCurrent());
17488 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 17484 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
17489 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 17485 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
17490 LocalContext env; 17486 LocalContext env;
17491 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 17487 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
17492 CompileRun("var a = new Object();" 17488 CompileRun("var a = new Object();"
17493 "var b = new Intercept();" 17489 "var b = new Intercept();"
17494 "var c = new Object();" 17490 "var c = new Object();"
17495 "c.__proto__ = b;" 17491 "c.__proto__ = b;"
17496 "b.__proto__ = a;" 17492 "b.__proto__ = a;"
17497 "a.x = 23;" 17493 "a.x = 23;"
(...skipping 13 matching lines...) Expand all
17511 Local<Value> expected_receiver, 17507 Local<Value> expected_receiver,
17512 const char* code) { 17508 const char* code) {
17513 Local<Value> result = CompileRun(code); 17509 Local<Value> result = CompileRun(code);
17514 CHECK(result->IsObject()); 17510 CHECK(result->IsObject());
17515 CHECK(expected_receiver->Equals(result->ToObject()->Get(1))); 17511 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
17516 CHECK(expected_result->Equals(result->ToObject()->Get(0))); 17512 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
17517 } 17513 }
17518 17514
17519 17515
17520 THREADED_TEST(ForeignFunctionReceiver) { 17516 THREADED_TEST(ForeignFunctionReceiver) {
17521 HandleScope scope; 17517 HandleScope scope(v8::Isolate::GetCurrent());
17522 17518
17523 // Create two contexts with different "id" properties ('i' and 'o'). 17519 // Create two contexts with different "id" properties ('i' and 'o').
17524 // Call a function both from its own context and from a the foreign 17520 // Call a function both from its own context and from a the foreign
17525 // context, and see what "this" is bound to (returning both "this" 17521 // context, and see what "this" is bound to (returning both "this"
17526 // and "this.id" for comparison). 17522 // and "this.id" for comparison).
17527 17523
17528 Persistent<Context> foreign_context = v8::Context::New(); 17524 Persistent<Context> foreign_context = v8::Context::New();
17529 foreign_context->Enter(); 17525 foreign_context->Enter();
17530 Local<Value> foreign_function = 17526 Local<Value> foreign_function =
17531 CompileRun("function func() { return { 0: this.id, " 17527 CompileRun("function func() { return { 0: this.id, "
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
17639 CHECK_EQ(0, callback_fired); 17635 CHECK_EQ(0, callback_fired);
17640 } else { 17636 } else {
17641 i::OS::Print("Recursion ends.\n"); 17637 i::OS::Print("Recursion ends.\n");
17642 CHECK_EQ(0, callback_fired); 17638 CHECK_EQ(0, callback_fired);
17643 } 17639 }
17644 return Undefined(); 17640 return Undefined();
17645 } 17641 }
17646 17642
17647 17643
17648 TEST(CallCompletedCallback) { 17644 TEST(CallCompletedCallback) {
17649 v8::HandleScope scope;
17650 LocalContext env; 17645 LocalContext env;
17646 v8::HandleScope scope(env->GetIsolate());
17651 v8::Handle<v8::FunctionTemplate> recursive_runtime = 17647 v8::Handle<v8::FunctionTemplate> recursive_runtime =
17652 v8::FunctionTemplate::New(RecursiveCall); 17648 v8::FunctionTemplate::New(RecursiveCall);
17653 env->Global()->Set(v8_str("recursion"), 17649 env->Global()->Set(v8_str("recursion"),
17654 recursive_runtime->GetFunction()); 17650 recursive_runtime->GetFunction());
17655 // Adding the same callback a second time has no effect. 17651 // Adding the same callback a second time has no effect.
17656 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 17652 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
17657 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 17653 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
17658 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); 17654 v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
17659 i::OS::Print("--- Script (1) ---\n"); 17655 i::OS::Print("--- Script (1) ---\n");
17660 Local<Script> script = 17656 Local<Script> script =
(...skipping 11 matching lines...) Expand all
17672 callback_fired = 0; 17668 callback_fired = 0;
17673 Local<Function> recursive_function = 17669 Local<Function> recursive_function =
17674 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 17670 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
17675 v8::Handle<Value> args[] = { v8_num(0) }; 17671 v8::Handle<Value> args[] = { v8_num(0) };
17676 recursive_function->Call(env->Global(), 1, args); 17672 recursive_function->Call(env->Global(), 1, args);
17677 CHECK_EQ(2, callback_fired); 17673 CHECK_EQ(2, callback_fired);
17678 } 17674 }
17679 17675
17680 17676
17681 void CallCompletedCallbackNoException() { 17677 void CallCompletedCallbackNoException() {
17682 v8::HandleScope scope; 17678 v8::HandleScope scope(v8::Isolate::GetCurrent());
17683 CompileRun("1+1;"); 17679 CompileRun("1+1;");
17684 } 17680 }
17685 17681
17686 17682
17687 void CallCompletedCallbackException() { 17683 void CallCompletedCallbackException() {
17688 v8::HandleScope scope; 17684 v8::HandleScope scope(v8::Isolate::GetCurrent());
17689 CompileRun("throw 'second exception';"); 17685 CompileRun("throw 'second exception';");
17690 } 17686 }
17691 17687
17692 17688
17693 TEST(CallCompletedCallbackOneException) { 17689 TEST(CallCompletedCallbackOneException) {
17694 v8::HandleScope scope;
17695 LocalContext env; 17690 LocalContext env;
17691 v8::HandleScope scope(env->GetIsolate());
17696 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); 17692 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException);
17697 CompileRun("throw 'exception';"); 17693 CompileRun("throw 'exception';");
17698 } 17694 }
17699 17695
17700 17696
17701 TEST(CallCompletedCallbackTwoExceptions) { 17697 TEST(CallCompletedCallbackTwoExceptions) {
17702 v8::HandleScope scope;
17703 LocalContext env; 17698 LocalContext env;
17699 v8::HandleScope scope(env->GetIsolate());
17704 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 17700 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
17705 CompileRun("throw 'first exception';"); 17701 CompileRun("throw 'first exception';");
17706 } 17702 }
17707 17703
17708 17704
17709 static int probes_counter = 0; 17705 static int probes_counter = 0;
17710 static int misses_counter = 0; 17706 static int misses_counter = 0;
17711 static int updates_counter = 0; 17707 static int updates_counter = 0;
17712 17708
17713 17709
(...skipping 27 matching lines...) Expand all
17741 V8::SetCounterFunction(LookupCounter); 17737 V8::SetCounterFunction(LookupCounter);
17742 USE(kMegamorphicTestProgram); 17738 USE(kMegamorphicTestProgram);
17743 #ifdef DEBUG 17739 #ifdef DEBUG
17744 i::FLAG_native_code_counters = true; 17740 i::FLAG_native_code_counters = true;
17745 if (primary) { 17741 if (primary) {
17746 i::FLAG_test_primary_stub_cache = true; 17742 i::FLAG_test_primary_stub_cache = true;
17747 } else { 17743 } else {
17748 i::FLAG_test_secondary_stub_cache = true; 17744 i::FLAG_test_secondary_stub_cache = true;
17749 } 17745 }
17750 i::FLAG_crankshaft = false; 17746 i::FLAG_crankshaft = false;
17751 v8::HandleScope scope;
17752 LocalContext env; 17747 LocalContext env;
17748 v8::HandleScope scope(env->GetIsolate());
17753 int initial_probes = probes_counter; 17749 int initial_probes = probes_counter;
17754 int initial_misses = misses_counter; 17750 int initial_misses = misses_counter;
17755 int initial_updates = updates_counter; 17751 int initial_updates = updates_counter;
17756 CompileRun(kMegamorphicTestProgram); 17752 CompileRun(kMegamorphicTestProgram);
17757 int probes = probes_counter - initial_probes; 17753 int probes = probes_counter - initial_probes;
17758 int misses = misses_counter - initial_misses; 17754 int misses = misses_counter - initial_misses;
17759 int updates = updates_counter - initial_updates; 17755 int updates = updates_counter - initial_updates;
17760 CHECK_LT(updates, 10); 17756 CHECK_LT(updates, 10);
17761 CHECK_LT(misses, 10); 17757 CHECK_LT(misses, 10);
17762 CHECK_GE(probes, 10000); 17758 CHECK_GE(probes, 10000);
(...skipping 12 matching lines...) Expand all
17775 17771
17776 17772
17777 static int fatal_error_callback_counter = 0; 17773 static int fatal_error_callback_counter = 0;
17778 static void CountingErrorCallback(const char* location, const char* message) { 17774 static void CountingErrorCallback(const char* location, const char* message) {
17779 printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message); 17775 printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
17780 fatal_error_callback_counter++; 17776 fatal_error_callback_counter++;
17781 } 17777 }
17782 17778
17783 17779
17784 TEST(StaticGetters) { 17780 TEST(StaticGetters) {
17785 v8::HandleScope scope;
17786 LocalContext context; 17781 LocalContext context;
17787 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17782 v8::Isolate* isolate = v8::Isolate::GetCurrent();
17783 v8::HandleScope scope(isolate);
17788 i::Handle<i::Object> undefined_value = FACTORY->undefined_value(); 17784 i::Handle<i::Object> undefined_value = FACTORY->undefined_value();
17789 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value); 17785 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value);
17790 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value); 17786 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value);
17791 i::Handle<i::Object> null_value = FACTORY->null_value(); 17787 i::Handle<i::Object> null_value = FACTORY->null_value();
17792 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value); 17788 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value);
17793 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value); 17789 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
17794 i::Handle<i::Object> true_value = FACTORY->true_value(); 17790 i::Handle<i::Object> true_value = FACTORY->true_value();
17795 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); 17791 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
17796 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); 17792 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
17797 i::Handle<i::Object> false_value = FACTORY->false_value(); 17793 i::Handle<i::Object> false_value = FACTORY->false_value();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
17837 ISOLATE->SetData(data2); 17833 ISOLATE->SetData(data2);
17838 CHECK_EQ(data2, isolate->GetData()); 17834 CHECK_EQ(data2, isolate->GetData());
17839 CHECK_EQ(data2, ISOLATE->GetData()); 17835 CHECK_EQ(data2, ISOLATE->GetData());
17840 ISOLATE->TearDown(); 17836 ISOLATE->TearDown();
17841 CHECK_EQ(data2, isolate->GetData()); 17837 CHECK_EQ(data2, isolate->GetData());
17842 CHECK_EQ(data2, ISOLATE->GetData()); 17838 CHECK_EQ(data2, ISOLATE->GetData());
17843 } 17839 }
17844 17840
17845 17841
17846 TEST(StringEmpty) { 17842 TEST(StringEmpty) {
17847 v8::HandleScope scope;
17848 LocalContext context; 17843 LocalContext context;
17849 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17844 v8::Isolate* isolate = v8::Isolate::GetCurrent();
17845 v8::HandleScope scope(isolate);
17850 i::Handle<i::Object> empty_string = FACTORY->empty_string(); 17846 i::Handle<i::Object> empty_string = FACTORY->empty_string();
17851 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); 17847 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
17852 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 17848 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
17853 17849
17854 // Test after-death behavior. 17850 // Test after-death behavior.
17855 CHECK(i::Internals::IsInitialized(isolate)); 17851 CHECK(i::Internals::IsInitialized(isolate));
17856 CHECK_EQ(0, fatal_error_callback_counter); 17852 CHECK_EQ(0, fatal_error_callback_counter);
17857 v8::V8::SetFatalErrorHandler(CountingErrorCallback); 17853 v8::V8::SetFatalErrorHandler(CountingErrorCallback);
17858 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); 17854 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8");
17859 i::Isolate::Current()->TearDown(); 17855 i::Isolate::Current()->TearDown();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
17940 // Cleanup so that closures start out fresh in next check. 17936 // Cleanup so that closures start out fresh in next check.
17941 CompileRun("%DeoptimizeFunction(test_get);" 17937 CompileRun("%DeoptimizeFunction(test_get);"
17942 "%ClearFunctionTypeFeedback(test_get);" 17938 "%ClearFunctionTypeFeedback(test_get);"
17943 "%DeoptimizeFunction(test_set);" 17939 "%DeoptimizeFunction(test_set);"
17944 "%ClearFunctionTypeFeedback(test_set);"); 17940 "%ClearFunctionTypeFeedback(test_set);");
17945 } 17941 }
17946 17942
17947 17943
17948 THREADED_TEST(InstanceCheckOnInstanceAccessor) { 17944 THREADED_TEST(InstanceCheckOnInstanceAccessor) {
17949 v8::internal::FLAG_allow_natives_syntax = true; 17945 v8::internal::FLAG_allow_natives_syntax = true;
17950 v8::HandleScope scope;
17951 LocalContext context; 17946 LocalContext context;
17947 v8::HandleScope scope(context->GetIsolate());
17952 17948
17953 Local<FunctionTemplate> templ = FunctionTemplate::New(); 17949 Local<FunctionTemplate> templ = FunctionTemplate::New();
17954 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 17950 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17955 inst->SetAccessor(v8_str("foo"), 17951 inst->SetAccessor(v8_str("foo"),
17956 InstanceCheckedGetter, InstanceCheckedSetter, 17952 InstanceCheckedGetter, InstanceCheckedSetter,
17957 Handle<Value>(), 17953 Handle<Value>(),
17958 v8::DEFAULT, 17954 v8::DEFAULT,
17959 v8::None, 17955 v8::None,
17960 v8::AccessorSignature::New(templ)); 17956 v8::AccessorSignature::New(templ));
17961 context->Global()->Set(v8_str("f"), templ->GetFunction()); 17957 context->Global()->Set(v8_str("f"), templ->GetFunction());
17962 17958
17963 printf("Testing positive ...\n"); 17959 printf("Testing positive ...\n");
17964 CompileRun("var obj = new f();"); 17960 CompileRun("var obj = new f();");
17965 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17961 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17966 CheckInstanceCheckedAccessors(true); 17962 CheckInstanceCheckedAccessors(true);
17967 17963
17968 printf("Testing negative ...\n"); 17964 printf("Testing negative ...\n");
17969 CompileRun("var obj = {};" 17965 CompileRun("var obj = {};"
17970 "obj.__proto__ = new f();"); 17966 "obj.__proto__ = new f();");
17971 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17967 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17972 CheckInstanceCheckedAccessors(false); 17968 CheckInstanceCheckedAccessors(false);
17973 } 17969 }
17974 17970
17975 17971
17976 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { 17972 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
17977 v8::internal::FLAG_allow_natives_syntax = true; 17973 v8::internal::FLAG_allow_natives_syntax = true;
17978 v8::HandleScope scope;
17979 LocalContext context; 17974 LocalContext context;
17975 v8::HandleScope scope(context->GetIsolate());
17980 17976
17981 Local<FunctionTemplate> templ = FunctionTemplate::New(); 17977 Local<FunctionTemplate> templ = FunctionTemplate::New();
17982 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 17978 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17983 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 17979 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
17984 inst->SetAccessor(v8_str("foo"), 17980 inst->SetAccessor(v8_str("foo"),
17985 InstanceCheckedGetter, InstanceCheckedSetter, 17981 InstanceCheckedGetter, InstanceCheckedSetter,
17986 Handle<Value>(), 17982 Handle<Value>(),
17987 v8::DEFAULT, 17983 v8::DEFAULT,
17988 v8::None, 17984 v8::None,
17989 v8::AccessorSignature::New(templ)); 17985 v8::AccessorSignature::New(templ));
17990 context->Global()->Set(v8_str("f"), templ->GetFunction()); 17986 context->Global()->Set(v8_str("f"), templ->GetFunction());
17991 17987
17992 printf("Testing positive ...\n"); 17988 printf("Testing positive ...\n");
17993 CompileRun("var obj = new f();"); 17989 CompileRun("var obj = new f();");
17994 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17990 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17995 CheckInstanceCheckedAccessors(true); 17991 CheckInstanceCheckedAccessors(true);
17996 17992
17997 printf("Testing negative ...\n"); 17993 printf("Testing negative ...\n");
17998 CompileRun("var obj = {};" 17994 CompileRun("var obj = {};"
17999 "obj.__proto__ = new f();"); 17995 "obj.__proto__ = new f();");
18000 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17996 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18001 CheckInstanceCheckedAccessors(false); 17997 CheckInstanceCheckedAccessors(false);
18002 } 17998 }
18003 17999
18004 18000
18005 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { 18001 THREADED_TEST(InstanceCheckOnPrototypeAccessor) {
18006 v8::internal::FLAG_allow_natives_syntax = true; 18002 v8::internal::FLAG_allow_natives_syntax = true;
18007 v8::HandleScope scope;
18008 LocalContext context; 18003 LocalContext context;
18004 v8::HandleScope scope(context->GetIsolate());
18009 18005
18010 Local<FunctionTemplate> templ = FunctionTemplate::New(); 18006 Local<FunctionTemplate> templ = FunctionTemplate::New();
18011 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); 18007 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
18012 proto->SetAccessor(v8_str("foo"), 18008 proto->SetAccessor(v8_str("foo"),
18013 InstanceCheckedGetter, InstanceCheckedSetter, 18009 InstanceCheckedGetter, InstanceCheckedSetter,
18014 Handle<Value>(), 18010 Handle<Value>(),
18015 v8::DEFAULT, 18011 v8::DEFAULT,
18016 v8::None, 18012 v8::None,
18017 v8::AccessorSignature::New(templ)); 18013 v8::AccessorSignature::New(templ));
18018 context->Global()->Set(v8_str("f"), templ->GetFunction()); 18014 context->Global()->Set(v8_str("f"), templ->GetFunction());
(...skipping 13 matching lines...) Expand all
18032 CompileRun("var obj = new f();" 18028 CompileRun("var obj = new f();"
18033 "var pro = {};" 18029 "var pro = {};"
18034 "pro.__proto__ = obj.__proto__;" 18030 "pro.__proto__ = obj.__proto__;"
18035 "obj.__proto__ = pro;"); 18031 "obj.__proto__ = pro;");
18036 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 18032 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18037 CheckInstanceCheckedAccessors(true); 18033 CheckInstanceCheckedAccessors(true);
18038 } 18034 }
18039 18035
18040 18036
18041 TEST(TryFinallyMessage) { 18037 TEST(TryFinallyMessage) {
18042 v8::HandleScope scope;
18043 LocalContext context; 18038 LocalContext context;
18039 v8::HandleScope scope(context->GetIsolate());
18044 { 18040 {
18045 // Test that the original error message is not lost if there is a 18041 // Test that the original error message is not lost if there is a
18046 // recursive call into Javascript is done in the finally block, e.g. to 18042 // recursive call into Javascript is done in the finally block, e.g. to
18047 // initialize an IC. (crbug.com/129171) 18043 // initialize an IC. (crbug.com/129171)
18048 TryCatch try_catch; 18044 TryCatch try_catch;
18049 const char* trigger_ic = 18045 const char* trigger_ic =
18050 "try { \n" 18046 "try { \n"
18051 " throw new Error('test'); \n" 18047 " throw new Error('test'); \n"
18052 "} finally { \n" 18048 "} finally { \n"
18053 " var x = 0; \n" 18049 " var x = 0; \n"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
18124 } else { 18120 } else {
18125 CHECK_EQ(do_store ? 23 : 42, 18121 CHECK_EQ(do_store ? 23 : 42,
18126 context->Global()->Get(v8_str("result"))->Int32Value()); 18122 context->Global()->Get(v8_str("result"))->Int32Value());
18127 } 18123 }
18128 } 18124 }
18129 18125
18130 18126
18131 THREADED_TEST(Regress137002a) { 18127 THREADED_TEST(Regress137002a) {
18132 i::FLAG_allow_natives_syntax = true; 18128 i::FLAG_allow_natives_syntax = true;
18133 i::FLAG_compilation_cache = false; 18129 i::FLAG_compilation_cache = false;
18134 v8::HandleScope scope; 18130 v8::HandleScope scope(v8::Isolate::GetCurrent());
18135 for (int i = 0; i < 16; i++) { 18131 for (int i = 0; i < 16; i++) {
18136 Helper137002(i & 8, i & 4, i & 2, i & 1); 18132 Helper137002(i & 8, i & 4, i & 2, i & 1);
18137 } 18133 }
18138 } 18134 }
18139 18135
18140 18136
18141 THREADED_TEST(Regress137002b) { 18137 THREADED_TEST(Regress137002b) {
18142 i::FLAG_allow_natives_syntax = true; 18138 i::FLAG_allow_natives_syntax = true;
18143 v8::HandleScope scope;
18144 LocalContext context; 18139 LocalContext context;
18140 v8::HandleScope scope(context->GetIsolate());
18145 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18141 Local<ObjectTemplate> templ = ObjectTemplate::New();
18146 templ->SetAccessor(v8_str("foo"), 18142 templ->SetAccessor(v8_str("foo"),
18147 GetterWhichReturns42, 18143 GetterWhichReturns42,
18148 SetterWhichSetsYOnThisTo23); 18144 SetterWhichSetsYOnThisTo23);
18149 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 18145 context->Global()->Set(v8_str("obj"), templ->NewInstance());
18150 18146
18151 // Turn monomorphic on slow object with native accessor, then just 18147 // Turn monomorphic on slow object with native accessor, then just
18152 // delete the property and fail. 18148 // delete the property and fail.
18153 CompileRun("function load(x) { return x.foo; }" 18149 CompileRun("function load(x) { return x.foo; }"
18154 "function store(x) { x.foo = void 0; }" 18150 "function store(x) { x.foo = void 0; }"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
18201 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined()); 18197 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined());
18202 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); 18198 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined());
18203 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); 18199 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined());
18204 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); 18200 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined());
18205 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); 18201 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined());
18206 } 18202 }
18207 18203
18208 18204
18209 THREADED_TEST(Regress142088) { 18205 THREADED_TEST(Regress142088) {
18210 i::FLAG_allow_natives_syntax = true; 18206 i::FLAG_allow_natives_syntax = true;
18211 v8::HandleScope scope;
18212 LocalContext context; 18207 LocalContext context;
18208 v8::HandleScope scope(context->GetIsolate());
18213 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18209 Local<ObjectTemplate> templ = ObjectTemplate::New();
18214 templ->SetAccessor(v8_str("foo"), 18210 templ->SetAccessor(v8_str("foo"),
18215 GetterWhichReturns42, 18211 GetterWhichReturns42,
18216 SetterWhichSetsYOnThisTo23); 18212 SetterWhichSetsYOnThisTo23);
18217 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 18213 context->Global()->Set(v8_str("obj"), templ->NewInstance());
18218 18214
18219 CompileRun("function load(x) { return x.foo; }" 18215 CompileRun("function load(x) { return x.foo; }"
18220 "var o = Object.create(obj);" 18216 "var o = Object.create(obj);"
18221 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" 18217 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
18222 "load(o); load(o); load(o); load(o);"); 18218 "load(o); load(o); load(o); load(o);");
18223 } 18219 }
18224 18220
18225 18221
18226 THREADED_TEST(Regress137496) { 18222 THREADED_TEST(Regress137496) {
18227 i::FLAG_expose_gc = true; 18223 i::FLAG_expose_gc = true;
18228 v8::HandleScope scope;
18229 LocalContext context; 18224 LocalContext context;
18225 v8::HandleScope scope(context->GetIsolate());
18230 18226
18231 // Compile a try-finally clause where the finally block causes a GC 18227 // Compile a try-finally clause where the finally block causes a GC
18232 // while there still is a message pending for external reporting. 18228 // while there still is a message pending for external reporting.
18233 TryCatch try_catch; 18229 TryCatch try_catch;
18234 try_catch.SetVerbose(true); 18230 try_catch.SetVerbose(true);
18235 CompileRun("try { throw new Error(); } finally { gc(); }"); 18231 CompileRun("try { throw new Error(); } finally { gc(); }");
18236 CHECK(try_catch.HasCaught()); 18232 CHECK(try_catch.HasCaught());
18237 } 18233 }
18238 18234
18239 18235
18240 THREADED_TEST(Regress149912) { 18236 THREADED_TEST(Regress149912) {
18241 v8::HandleScope scope;
18242 LocalContext context; 18237 LocalContext context;
18238 v8::HandleScope scope(context->GetIsolate());
18243 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 18239 Handle<FunctionTemplate> templ = FunctionTemplate::New();
18244 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 18240 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
18245 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); 18241 context->Global()->Set(v8_str("Bug"), templ->GetFunction());
18246 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); 18242 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
18247 } 18243 }
18248 18244
18249 18245
18250 THREADED_TEST(Regress157124) { 18246 THREADED_TEST(Regress157124) {
18251 v8::HandleScope scope;
18252 LocalContext context; 18247 LocalContext context;
18248 v8::HandleScope scope(context->GetIsolate());
18253 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18249 Local<ObjectTemplate> templ = ObjectTemplate::New();
18254 Local<Object> obj = templ->NewInstance(); 18250 Local<Object> obj = templ->NewInstance();
18255 obj->GetIdentityHash(); 18251 obj->GetIdentityHash();
18256 obj->DeleteHiddenValue(v8_str("Bug")); 18252 obj->DeleteHiddenValue(v8_str("Bug"));
18257 } 18253 }
18258 18254
18259 18255
18260 THREADED_TEST(Regress2535) { 18256 THREADED_TEST(Regress2535) {
18261 i::FLAG_harmony_collections = true; 18257 i::FLAG_harmony_collections = true;
18262 v8::HandleScope scope;
18263 LocalContext context; 18258 LocalContext context;
18259 v8::HandleScope scope(context->GetIsolate());
18264 Local<Value> set_value = CompileRun("new Set();"); 18260 Local<Value> set_value = CompileRun("new Set();");
18265 Local<Object> set_object(Object::Cast(*set_value)); 18261 Local<Object> set_object(Object::Cast(*set_value));
18266 CHECK_EQ(0, set_object->InternalFieldCount()); 18262 CHECK_EQ(0, set_object->InternalFieldCount());
18267 Local<Value> map_value = CompileRun("new Map();"); 18263 Local<Value> map_value = CompileRun("new Map();");
18268 Local<Object> map_object(Object::Cast(*map_value)); 18264 Local<Object> map_object(Object::Cast(*map_value));
18269 CHECK_EQ(0, map_object->InternalFieldCount()); 18265 CHECK_EQ(0, map_object->InternalFieldCount());
18270 } 18266 }
18271 18267
18272 18268
18273 #ifndef WIN32 18269 #ifndef WIN32
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
18326 i::Semaphore* sem_; 18322 i::Semaphore* sem_;
18327 volatile int sem_value_; 18323 volatile int sem_value_;
18328 }; 18324 };
18329 18325
18330 18326
18331 THREADED_TEST(SemaphoreInterruption) { 18327 THREADED_TEST(SemaphoreInterruption) {
18332 ThreadInterruptTest().RunTest(); 18328 ThreadInterruptTest().RunTest();
18333 } 18329 }
18334 18330
18335 #endif // WIN32 18331 #endif // WIN32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698