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

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: Feedback. Rebased 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
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 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 LocalContext context;
3476 v8::HandleScope scope(context->GetIsolate());
3476 v8::V8::AddMessageListener(receive_message); 3477 v8::V8::AddMessageListener(receive_message);
3477 LocalContext context;
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 LocalContext context;
3819 v8::HandleScope scope(context->GetIsolate());
3819 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3820 Local<ObjectTemplate> templ = ObjectTemplate::New();
3820 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 3821 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
3821 LocalContext context;
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 LocalContext context;
3832 v8::HandleScope scope(context->GetIsolate());
3832 Local<ObjectTemplate> templ = ObjectTemplate::New(); 3833 Local<ObjectTemplate> templ = ObjectTemplate::New();
3833 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 3834 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
3834 LocalContext context;
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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
6338 CHECK_EQ((u1 & 0x3), c >> 18); 6338 CHECK_EQ((u1 & 0x3), c >> 18);
6339 } 6339 }
6340 } 6340 }
6341 } 6341 }
6342 } 6342 }
6343 } 6343 }
6344 6344
6345 6345
6346 THREADED_TEST(Utf16) { 6346 THREADED_TEST(Utf16) {
6347 LocalContext context; 6347 LocalContext context;
6348 v8::HandleScope scope; 6348 v8::HandleScope scope(context->GetIsolate());
6349 CompileRun( 6349 CompileRun(
6350 "var pad = '01234567890123456789';" 6350 "var pad = '01234567890123456789';"
6351 "var p = [];" 6351 "var p = [];"
6352 "var plens = [20, 3, 3];" 6352 "var plens = [20, 3, 3];"
6353 "p.push('01234567890123456789');" 6353 "p.push('01234567890123456789');"
6354 "var lead = 0xd800;" 6354 "var lead = 0xd800;"
6355 "var trail = 0xdc00;" 6355 "var trail = 0xdc00;"
6356 "p.push(String.fromCharCode(0xd800));" 6356 "p.push(String.fromCharCode(0xd800));"
6357 "p.push(String.fromCharCode(0xdc00));" 6357 "p.push(String.fromCharCode(0xdc00));"
6358 "var a = [];" 6358 "var a = [];"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
6404 6404
6405 static void SameSymbolHelper(const char* a, const char* b) { 6405 static void SameSymbolHelper(const char* a, const char* b) {
6406 Handle<String> symbol1 = v8::String::NewSymbol(a); 6406 Handle<String> symbol1 = v8::String::NewSymbol(a);
6407 Handle<String> symbol2 = v8::String::NewSymbol(b); 6407 Handle<String> symbol2 = v8::String::NewSymbol(b);
6408 CHECK(SameSymbol(symbol1, symbol2)); 6408 CHECK(SameSymbol(symbol1, symbol2));
6409 } 6409 }
6410 6410
6411 6411
6412 THREADED_TEST(Utf16Symbol) { 6412 THREADED_TEST(Utf16Symbol) {
6413 LocalContext context; 6413 LocalContext context;
6414 v8::HandleScope scope; 6414 v8::HandleScope scope(context->GetIsolate());
6415 6415
6416 Handle<String> symbol1 = v8::String::NewSymbol("abc"); 6416 Handle<String> symbol1 = v8::String::NewSymbol("abc");
6417 Handle<String> symbol2 = v8::String::NewSymbol("abc"); 6417 Handle<String> symbol2 = v8::String::NewSymbol("abc");
6418 CHECK(SameSymbol(symbol1, symbol2)); 6418 CHECK(SameSymbol(symbol1, symbol2));
6419 6419
6420 SameSymbolHelper("\360\220\220\205", // 4 byte encoding. 6420 SameSymbolHelper("\360\220\220\205", // 4 byte encoding.
6421 "\355\240\201\355\260\205"); // 2 3-byte surrogates. 6421 "\355\240\201\355\260\205"); // 2 3-byte surrogates.
6422 SameSymbolHelper("\355\240\201\355\260\206", // 2 3-byte surrogates. 6422 SameSymbolHelper("\355\240\201\355\260\206", // 2 3-byte surrogates.
6423 "\360\220\220\206"); // 4 byte encoding. 6423 "\360\220\220\206"); // 4 byte encoding.
6424 SameSymbolHelper("x\360\220\220\205", // 4 byte encoding. 6424 SameSymbolHelper("x\360\220\220\205", // 4 byte encoding.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6456 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0)))); 6456 CHECK(SameSymbol(sym0, Handle<String>(String::Cast(*s0))));
6457 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b)))); 6457 CHECK(SameSymbol(sym0b, Handle<String>(String::Cast(*s0b))));
6458 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1)))); 6458 CHECK(SameSymbol(sym1, Handle<String>(String::Cast(*s1))));
6459 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2)))); 6459 CHECK(SameSymbol(sym2, Handle<String>(String::Cast(*s2))));
6460 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3)))); 6460 CHECK(SameSymbol(sym3, Handle<String>(String::Cast(*s3))));
6461 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4)))); 6461 CHECK(SameSymbol(sym4, Handle<String>(String::Cast(*s4))));
6462 } 6462 }
6463 6463
6464 6464
6465 THREADED_TEST(ToArrayIndex) { 6465 THREADED_TEST(ToArrayIndex) {
6466 v8::HandleScope scope;
6467 LocalContext context; 6466 LocalContext context;
6467 v8::HandleScope scope(context->GetIsolate());
6468 6468
6469 v8::Handle<String> str = v8_str("42"); 6469 v8::Handle<String> str = v8_str("42");
6470 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 6470 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
6471 CHECK(!index.IsEmpty()); 6471 CHECK(!index.IsEmpty());
6472 CHECK_EQ(42.0, index->Uint32Value()); 6472 CHECK_EQ(42.0, index->Uint32Value());
6473 str = v8_str("42asdf"); 6473 str = v8_str("42asdf");
6474 index = str->ToArrayIndex(); 6474 index = str->ToArrayIndex();
6475 CHECK(index.IsEmpty()); 6475 CHECK(index.IsEmpty());
6476 str = v8_str("-42"); 6476 str = v8_str("-42");
6477 index = str->ToArrayIndex(); 6477 index = str->ToArrayIndex();
6478 CHECK(index.IsEmpty()); 6478 CHECK(index.IsEmpty());
6479 str = v8_str("4294967295"); 6479 str = v8_str("4294967295");
6480 index = str->ToArrayIndex(); 6480 index = str->ToArrayIndex();
6481 CHECK(!index.IsEmpty()); 6481 CHECK(!index.IsEmpty());
6482 CHECK_EQ(4294967295.0, index->Uint32Value()); 6482 CHECK_EQ(4294967295.0, index->Uint32Value());
6483 v8::Handle<v8::Number> num = v8::Number::New(1); 6483 v8::Handle<v8::Number> num = v8::Number::New(1);
6484 index = num->ToArrayIndex(); 6484 index = num->ToArrayIndex();
6485 CHECK(!index.IsEmpty()); 6485 CHECK(!index.IsEmpty());
6486 CHECK_EQ(1.0, index->Uint32Value()); 6486 CHECK_EQ(1.0, index->Uint32Value());
6487 num = v8::Number::New(-1); 6487 num = v8::Number::New(-1);
6488 index = num->ToArrayIndex(); 6488 index = num->ToArrayIndex();
6489 CHECK(index.IsEmpty()); 6489 CHECK(index.IsEmpty());
6490 v8::Handle<v8::Object> obj = v8::Object::New(); 6490 v8::Handle<v8::Object> obj = v8::Object::New();
6491 index = obj->ToArrayIndex(); 6491 index = obj->ToArrayIndex();
6492 CHECK(index.IsEmpty()); 6492 CHECK(index.IsEmpty());
6493 } 6493 }
6494 6494
6495 6495
6496 THREADED_TEST(ErrorConstruction) { 6496 THREADED_TEST(ErrorConstruction) {
6497 v8::HandleScope scope;
6498 LocalContext context; 6497 LocalContext context;
6498 v8::HandleScope scope(context->GetIsolate());
6499 6499
6500 v8::Handle<String> foo = v8_str("foo"); 6500 v8::Handle<String> foo = v8_str("foo");
6501 v8::Handle<String> message = v8_str("message"); 6501 v8::Handle<String> message = v8_str("message");
6502 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); 6502 v8::Handle<Value> range_error = v8::Exception::RangeError(foo);
6503 CHECK(range_error->IsObject()); 6503 CHECK(range_error->IsObject());
6504 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); 6504 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo));
6505 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); 6505 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo);
6506 CHECK(reference_error->IsObject()); 6506 CHECK(reference_error->IsObject());
6507 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); 6507 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo));
6508 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); 6508 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo);
(...skipping 18 matching lines...) Expand all
6527 Local<Value> value, 6527 Local<Value> value,
6528 const AccessorInfo& info) { 6528 const AccessorInfo& info) {
6529 if (info.This()->Has(name)) { 6529 if (info.This()->Has(name)) {
6530 info.This()->Delete(name); 6530 info.This()->Delete(name);
6531 } 6531 }
6532 info.This()->Set(name, value); 6532 info.This()->Set(name, value);
6533 } 6533 }
6534 6534
6535 6535
6536 THREADED_TEST(DeleteAccessor) { 6536 THREADED_TEST(DeleteAccessor) {
6537 v8::HandleScope scope; 6537 v8::HandleScope scope(v8::Isolate::GetCurrent());
6538 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 6538 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
6539 obj->SetAccessor(v8_str("y"), YGetter, YSetter); 6539 obj->SetAccessor(v8_str("y"), YGetter, YSetter);
6540 LocalContext context; 6540 LocalContext context;
6541 v8::Handle<v8::Object> holder = obj->NewInstance(); 6541 v8::Handle<v8::Object> holder = obj->NewInstance();
6542 context->Global()->Set(v8_str("holder"), holder); 6542 context->Global()->Set(v8_str("holder"), holder);
6543 v8::Handle<Value> result = CompileRun( 6543 v8::Handle<Value> result = CompileRun(
6544 "holder.y = 11; holder.y = 12; holder.y"); 6544 "holder.y = 11; holder.y = 12; holder.y");
6545 CHECK_EQ(12, result->Uint32Value()); 6545 CHECK_EQ(12, result->Uint32Value());
6546 } 6546 }
6547 6547
6548 6548
6549 THREADED_TEST(TypeSwitch) { 6549 THREADED_TEST(TypeSwitch) {
6550 v8::HandleScope scope; 6550 v8::HandleScope scope(v8::Isolate::GetCurrent());
6551 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(); 6551 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New();
6552 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(); 6552 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New();
6553 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(); 6553 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New();
6554 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 6554 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
6555 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 6555 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
6556 LocalContext context; 6556 LocalContext context;
6557 v8::Handle<v8::Object> obj0 = v8::Object::New(); 6557 v8::Handle<v8::Object> obj0 = v8::Object::New();
6558 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 6558 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
6559 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 6559 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
6560 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 6560 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6618 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, 6618 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>,
6619 v8::Handle<Value>) { 6619 v8::Handle<Value>) {
6620 report_count++; 6620 report_count++;
6621 } 6621 }
6622 6622
6623 6623
6624 // Counts uncaught exceptions, but other tests running in parallel 6624 // Counts uncaught exceptions, but other tests running in parallel
6625 // also have uncaught exceptions. 6625 // also have uncaught exceptions.
6626 TEST(ApiUncaughtException) { 6626 TEST(ApiUncaughtException) {
6627 report_count = 0; 6627 report_count = 0;
6628 v8::HandleScope scope;
6629 LocalContext env; 6628 LocalContext env;
6629 v8::HandleScope scope(env->GetIsolate());
6630 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 6630 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener);
6631 6631
6632 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 6632 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback);
6633 v8::Local<v8::Object> global = env->Global(); 6633 v8::Local<v8::Object> global = env->Global();
6634 global->Set(v8_str("trouble"), fun->GetFunction()); 6634 global->Set(v8_str("trouble"), fun->GetFunction());
6635 6635
6636 Script::Compile(v8_str("function trouble_callee() {" 6636 Script::Compile(v8_str("function trouble_callee() {"
6637 " var x = null;" 6637 " var x = null;"
6638 " return x.foo;" 6638 " return x.foo;"
6639 "};" 6639 "};"
(...skipping 17 matching lines...) Expand all
6657 v8::Handle<v8::Value> name_val = message->GetScriptResourceName(); 6657 v8::Handle<v8::Value> name_val = message->GetScriptResourceName();
6658 CHECK(!name_val.IsEmpty() && name_val->IsString()); 6658 CHECK(!name_val.IsEmpty() && name_val->IsString());
6659 v8::String::AsciiValue name(message->GetScriptResourceName()); 6659 v8::String::AsciiValue name(message->GetScriptResourceName());
6660 CHECK_EQ(script_resource_name, *name); 6660 CHECK_EQ(script_resource_name, *name);
6661 CHECK_EQ(3, message->GetLineNumber()); 6661 CHECK_EQ(3, message->GetLineNumber());
6662 v8::String::AsciiValue source_line(message->GetSourceLine()); 6662 v8::String::AsciiValue source_line(message->GetSourceLine());
6663 CHECK_EQ(" new o.foo();", *source_line); 6663 CHECK_EQ(" new o.foo();", *source_line);
6664 } 6664 }
6665 6665
6666 TEST(ExceptionInNativeScript) { 6666 TEST(ExceptionInNativeScript) {
6667 v8::HandleScope scope;
6668 LocalContext env; 6667 LocalContext env;
6668 v8::HandleScope scope(env->GetIsolate());
6669 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 6669 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
6670 6670
6671 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 6671 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback);
6672 v8::Local<v8::Object> global = env->Global(); 6672 v8::Local<v8::Object> global = env->Global();
6673 global->Set(v8_str("trouble"), fun->GetFunction()); 6673 global->Set(v8_str("trouble"), fun->GetFunction());
6674 6674
6675 Script::Compile(v8_str("function trouble() {\n" 6675 Script::Compile(v8_str("function trouble() {\n"
6676 " var o = {};\n" 6676 " var o = {};\n"
6677 " new o.foo();\n" 6677 " new o.foo();\n"
6678 "};"), v8::String::New(script_resource_name))->Run(); 6678 "};"), v8::String::New(script_resource_name))->Run();
6679 Local<Value> trouble = global->Get(v8_str("trouble")); 6679 Local<Value> trouble = global->Get(v8_str("trouble"));
6680 CHECK(trouble->IsFunction()); 6680 CHECK(trouble->IsFunction());
6681 Function::Cast(*trouble)->Call(global, 0, NULL); 6681 Function::Cast(*trouble)->Call(global, 0, NULL);
6682 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 6682 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
6683 } 6683 }
6684 6684
6685 6685
6686 TEST(CompilationErrorUsingTryCatchHandler) { 6686 TEST(CompilationErrorUsingTryCatchHandler) {
6687 v8::HandleScope scope;
6688 LocalContext env; 6687 LocalContext env;
6688 v8::HandleScope scope(env->GetIsolate());
6689 v8::TryCatch try_catch; 6689 v8::TryCatch try_catch;
6690 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); 6690 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile."));
6691 CHECK_NE(NULL, *try_catch.Exception()); 6691 CHECK_NE(NULL, *try_catch.Exception());
6692 CHECK(try_catch.HasCaught()); 6692 CHECK(try_catch.HasCaught());
6693 } 6693 }
6694 6694
6695 6695
6696 TEST(TryCatchFinallyUsingTryCatchHandler) { 6696 TEST(TryCatchFinallyUsingTryCatchHandler) {
6697 v8::HandleScope scope;
6698 LocalContext env; 6697 LocalContext env;
6698 v8::HandleScope scope(env->GetIsolate());
6699 v8::TryCatch try_catch; 6699 v8::TryCatch try_catch;
6700 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run(); 6700 Script::Compile(v8_str("try { throw ''; } catch (e) {}"))->Run();
6701 CHECK(!try_catch.HasCaught()); 6701 CHECK(!try_catch.HasCaught());
6702 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run(); 6702 Script::Compile(v8_str("try { throw ''; } finally {}"))->Run();
6703 CHECK(try_catch.HasCaught()); 6703 CHECK(try_catch.HasCaught());
6704 try_catch.Reset(); 6704 try_catch.Reset();
6705 Script::Compile(v8_str("(function() {" 6705 Script::Compile(v8_str("(function() {"
6706 "try { throw ''; } finally { return; }" 6706 "try { throw ''; } finally { return; }"
6707 "})()"))->Run(); 6707 "})()"))->Run();
6708 CHECK(!try_catch.HasCaught()); 6708 CHECK(!try_catch.HasCaught());
6709 Script::Compile(v8_str("(function()" 6709 Script::Compile(v8_str("(function()"
6710 " { try { throw ''; } finally { throw 0; }" 6710 " { try { throw ''; } finally { throw 0; }"
6711 "})()"))->Run(); 6711 "})()"))->Run();
6712 CHECK(try_catch.HasCaught()); 6712 CHECK(try_catch.HasCaught());
6713 } 6713 }
6714 6714
6715 6715
6716 // SecurityHandler can't be run twice 6716 // SecurityHandler can't be run twice
6717 TEST(SecurityHandler) { 6717 TEST(SecurityHandler) {
6718 v8::HandleScope scope0; 6718 v8::HandleScope scope0(v8::Isolate::GetCurrent());
6719 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 6719 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
6720 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback, 6720 global_template->SetAccessCheckCallbacks(NamedSecurityTestCallback,
6721 IndexedSecurityTestCallback); 6721 IndexedSecurityTestCallback);
6722 // Create an environment 6722 // Create an environment
6723 v8::Persistent<Context> context0 = 6723 v8::Persistent<Context> context0 =
6724 Context::New(NULL, global_template); 6724 Context::New(NULL, global_template);
6725 context0->Enter(); 6725 context0->Enter();
6726 6726
6727 v8::Handle<v8::Object> global0 = context0->Global(); 6727 v8::Handle<v8::Object> global0 = context0->Global();
6728 v8::Handle<Script> script0 = v8_compile("foo = 111"); 6728 v8::Handle<Script> script0 = v8_compile("foo = 111");
6729 script0->Run(); 6729 script0->Run();
6730 global0->Set(v8_str("0"), v8_num(999)); 6730 global0->Set(v8_str("0"), v8_num(999));
6731 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); 6731 v8::Handle<Value> foo0 = global0->Get(v8_str("foo"));
6732 CHECK_EQ(111, foo0->Int32Value()); 6732 CHECK_EQ(111, foo0->Int32Value());
6733 v8::Handle<Value> z0 = global0->Get(v8_str("0")); 6733 v8::Handle<Value> z0 = global0->Get(v8_str("0"));
6734 CHECK_EQ(999, z0->Int32Value()); 6734 CHECK_EQ(999, z0->Int32Value());
6735 6735
6736 // Create another environment, should fail security checks. 6736 // Create another environment, should fail security checks.
6737 v8::HandleScope scope1; 6737 v8::HandleScope scope1(v8::Isolate::GetCurrent());
6738 6738
6739 v8::Persistent<Context> context1 = 6739 v8::Persistent<Context> context1 =
6740 Context::New(NULL, global_template); 6740 Context::New(NULL, global_template);
6741 context1->Enter(); 6741 context1->Enter();
6742 6742
6743 v8::Handle<v8::Object> global1 = context1->Global(); 6743 v8::Handle<v8::Object> global1 = context1->Global();
6744 global1->Set(v8_str("othercontext"), global0); 6744 global1->Set(v8_str("othercontext"), global0);
6745 // This set will fail the security check. 6745 // This set will fail the security check.
6746 v8::Handle<Script> script1 = 6746 v8::Handle<Script> script1 =
6747 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); 6747 v8_compile("othercontext.foo = 222; othercontext[0] = 888;");
6748 script1->Run(); 6748 script1->Run();
6749 // This read will pass the security check. 6749 // This read will pass the security check.
6750 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); 6750 v8::Handle<Value> foo1 = global0->Get(v8_str("foo"));
6751 CHECK_EQ(111, foo1->Int32Value()); 6751 CHECK_EQ(111, foo1->Int32Value());
6752 // This read will pass the security check. 6752 // This read will pass the security check.
6753 v8::Handle<Value> z1 = global0->Get(v8_str("0")); 6753 v8::Handle<Value> z1 = global0->Get(v8_str("0"));
6754 CHECK_EQ(999, z1->Int32Value()); 6754 CHECK_EQ(999, z1->Int32Value());
6755 6755
6756 // Create another environment, should pass security checks. 6756 // Create another environment, should pass security checks.
6757 { g_security_callback_result = true; // allow security handler to pass. 6757 { g_security_callback_result = true; // allow security handler to pass.
6758 v8::HandleScope scope2; 6758 v8::HandleScope scope2(v8::Isolate::GetCurrent());
6759 LocalContext context2; 6759 LocalContext context2;
6760 v8::Handle<v8::Object> global2 = context2->Global(); 6760 v8::Handle<v8::Object> global2 = context2->Global();
6761 global2->Set(v8_str("othercontext"), global0); 6761 global2->Set(v8_str("othercontext"), global0);
6762 v8::Handle<Script> script2 = 6762 v8::Handle<Script> script2 =
6763 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 6763 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
6764 script2->Run(); 6764 script2->Run();
6765 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 6765 v8::Handle<Value> foo2 = global0->Get(v8_str("foo"));
6766 CHECK_EQ(333, foo2->Int32Value()); 6766 CHECK_EQ(333, foo2->Int32Value());
6767 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 6767 v8::Handle<Value> z2 = global0->Get(v8_str("0"));
6768 CHECK_EQ(888, z2->Int32Value()); 6768 CHECK_EQ(888, z2->Int32Value());
6769 } 6769 }
6770 6770
6771 context1->Exit(); 6771 context1->Exit();
6772 context1.Dispose(context1->GetIsolate()); 6772 context1.Dispose(context1->GetIsolate());
6773 6773
6774 context0->Exit(); 6774 context0->Exit();
6775 context0.Dispose(context0->GetIsolate()); 6775 context0.Dispose(context0->GetIsolate());
6776 } 6776 }
6777 6777
6778 6778
6779 THREADED_TEST(SecurityChecks) { 6779 THREADED_TEST(SecurityChecks) {
6780 v8::HandleScope handle_scope;
6781 LocalContext env1; 6780 LocalContext env1;
6781 v8::HandleScope handle_scope(env1->GetIsolate());
6782 v8::Persistent<Context> env2 = Context::New(); 6782 v8::Persistent<Context> env2 = Context::New();
6783 6783
6784 Local<Value> foo = v8_str("foo"); 6784 Local<Value> foo = v8_str("foo");
6785 Local<Value> bar = v8_str("bar"); 6785 Local<Value> bar = v8_str("bar");
6786 6786
6787 // Set to the same domain. 6787 // Set to the same domain.
6788 env1->SetSecurityToken(foo); 6788 env1->SetSecurityToken(foo);
6789 6789
6790 // Create a function in env1. 6790 // Create a function in env1.
6791 Script::Compile(v8_str("spy=function(){return spy;}"))->Run(); 6791 Script::Compile(v8_str("spy=function(){return spy;}"))->Run();
(...skipping 23 matching lines...) Expand all
6815 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); 6815 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL);
6816 CHECK(try_catch.HasCaught()); 6816 CHECK(try_catch.HasCaught());
6817 } 6817 }
6818 6818
6819 env2.Dispose(env2->GetIsolate()); 6819 env2.Dispose(env2->GetIsolate());
6820 } 6820 }
6821 6821
6822 6822
6823 // Regression test case for issue 1183439. 6823 // Regression test case for issue 1183439.
6824 THREADED_TEST(SecurityChecksForPrototypeChain) { 6824 THREADED_TEST(SecurityChecksForPrototypeChain) {
6825 v8::HandleScope scope;
6826 LocalContext current; 6825 LocalContext current;
6826 v8::HandleScope scope(current->GetIsolate());
6827 v8::Persistent<Context> other = Context::New(); 6827 v8::Persistent<Context> other = Context::New();
6828 6828
6829 // Change context to be able to get to the Object function in the 6829 // Change context to be able to get to the Object function in the
6830 // other context without hitting the security checks. 6830 // other context without hitting the security checks.
6831 v8::Local<Value> other_object; 6831 v8::Local<Value> other_object;
6832 { Context::Scope scope(other); 6832 { Context::Scope scope(other);
6833 other_object = other->Global()->Get(v8_str("Object")); 6833 other_object = other->Global()->Get(v8_str("Object"));
6834 other->Global()->Set(v8_num(42), v8_num(87)); 6834 other->Global()->Set(v8_num(42), v8_num(87));
6835 } 6835 }
6836 6836
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6883 CHECK(!access_f2->Run()->Equals(v8_num(100))); 6883 CHECK(!access_f2->Run()->Equals(v8_num(100)));
6884 CHECK(access_f2->Run()->IsUndefined()); 6884 CHECK(access_f2->Run()->IsUndefined());
6885 CHECK(!access_f3->Run()->Equals(v8_num(101))); 6885 CHECK(!access_f3->Run()->Equals(v8_num(101)));
6886 CHECK(access_f3->Run()->IsUndefined()); 6886 CHECK(access_f3->Run()->IsUndefined());
6887 } 6887 }
6888 other.Dispose(other->GetIsolate()); 6888 other.Dispose(other->GetIsolate());
6889 } 6889 }
6890 6890
6891 6891
6892 THREADED_TEST(CrossDomainDelete) { 6892 THREADED_TEST(CrossDomainDelete) {
6893 v8::HandleScope handle_scope;
6894 LocalContext env1; 6893 LocalContext env1;
6894 v8::HandleScope handle_scope(env1->GetIsolate());
6895 v8::Persistent<Context> env2 = Context::New(); 6895 v8::Persistent<Context> env2 = Context::New();
6896 6896
6897 Local<Value> foo = v8_str("foo"); 6897 Local<Value> foo = v8_str("foo");
6898 Local<Value> bar = v8_str("bar"); 6898 Local<Value> bar = v8_str("bar");
6899 6899
6900 // Set to the same domain. 6900 // Set to the same domain.
6901 env1->SetSecurityToken(foo); 6901 env1->SetSecurityToken(foo);
6902 env2->SetSecurityToken(foo); 6902 env2->SetSecurityToken(foo);
6903 6903
6904 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6904 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 11 matching lines...) Expand all
6916 // Check that env1.prop still exists. 6916 // Check that env1.prop still exists.
6917 Local<Value> v = env1->Global()->Get(v8_str("prop")); 6917 Local<Value> v = env1->Global()->Get(v8_str("prop"));
6918 CHECK(v->IsNumber()); 6918 CHECK(v->IsNumber());
6919 CHECK_EQ(3, v->Int32Value()); 6919 CHECK_EQ(3, v->Int32Value());
6920 6920
6921 env2.Dispose(env2->GetIsolate()); 6921 env2.Dispose(env2->GetIsolate());
6922 } 6922 }
6923 6923
6924 6924
6925 THREADED_TEST(CrossDomainIsPropertyEnumerable) { 6925 THREADED_TEST(CrossDomainIsPropertyEnumerable) {
6926 v8::HandleScope handle_scope;
6927 LocalContext env1; 6926 LocalContext env1;
6927 v8::HandleScope handle_scope(env1->GetIsolate());
6928 v8::Persistent<Context> env2 = Context::New(); 6928 v8::Persistent<Context> env2 = Context::New();
6929 6929
6930 Local<Value> foo = v8_str("foo"); 6930 Local<Value> foo = v8_str("foo");
6931 Local<Value> bar = v8_str("bar"); 6931 Local<Value> bar = v8_str("bar");
6932 6932
6933 // Set to the same domain. 6933 // Set to the same domain.
6934 env1->SetSecurityToken(foo); 6934 env1->SetSecurityToken(foo);
6935 env2->SetSecurityToken(foo); 6935 env2->SetSecurityToken(foo);
6936 6936
6937 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6937 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 13 matching lines...) Expand all
6951 Context::Scope scope_env2(env2); 6951 Context::Scope scope_env2(env2);
6952 Local<Value> result = Script::Compile(test)->Run(); 6952 Local<Value> result = Script::Compile(test)->Run();
6953 CHECK(result->IsFalse()); 6953 CHECK(result->IsFalse());
6954 } 6954 }
6955 6955
6956 env2.Dispose(env2->GetIsolate()); 6956 env2.Dispose(env2->GetIsolate());
6957 } 6957 }
6958 6958
6959 6959
6960 THREADED_TEST(CrossDomainForIn) { 6960 THREADED_TEST(CrossDomainForIn) {
6961 v8::HandleScope handle_scope;
6962 LocalContext env1; 6961 LocalContext env1;
6962 v8::HandleScope handle_scope(env1->GetIsolate());
6963 v8::Persistent<Context> env2 = Context::New(); 6963 v8::Persistent<Context> env2 = Context::New();
6964 6964
6965 Local<Value> foo = v8_str("foo"); 6965 Local<Value> foo = v8_str("foo");
6966 Local<Value> bar = v8_str("bar"); 6966 Local<Value> bar = v8_str("bar");
6967 6967
6968 // Set to the same domain. 6968 // Set to the same domain.
6969 env1->SetSecurityToken(foo); 6969 env1->SetSecurityToken(foo);
6970 env2->SetSecurityToken(foo); 6970 env2->SetSecurityToken(foo);
6971 6971
6972 env1->Global()->Set(v8_str("prop"), v8_num(3)); 6972 env1->Global()->Set(v8_str("prop"), v8_num(3));
(...skipping 11 matching lines...) Expand all
6984 "for (var p in obj)" 6984 "for (var p in obj)"
6985 " if (p == 'prop') return false;" 6985 " if (p == 'prop') return false;"
6986 "return true;})()"); 6986 "return true;})()");
6987 CHECK(result->IsTrue()); 6987 CHECK(result->IsTrue());
6988 } 6988 }
6989 env2.Dispose(env2->GetIsolate()); 6989 env2.Dispose(env2->GetIsolate());
6990 } 6990 }
6991 6991
6992 6992
6993 TEST(ContextDetachGlobal) { 6993 TEST(ContextDetachGlobal) {
6994 v8::HandleScope handle_scope;
6995 LocalContext env1; 6994 LocalContext env1;
6995 v8::HandleScope handle_scope(env1->GetIsolate());
6996 v8::Persistent<Context> env2 = Context::New(); 6996 v8::Persistent<Context> env2 = Context::New();
6997 6997
6998 Local<v8::Object> global1 = env1->Global(); 6998 Local<v8::Object> global1 = env1->Global();
6999 6999
7000 Local<Value> foo = v8_str("foo"); 7000 Local<Value> foo = v8_str("foo");
7001 7001
7002 // Set to the same domain. 7002 // Set to the same domain.
7003 env1->SetSecurityToken(foo); 7003 env1->SetSecurityToken(foo);
7004 env2->SetSecurityToken(foo); 7004 env2->SetSecurityToken(foo);
7005 7005
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
7048 Local<Value> r = global3->Get(v8_str("prop2")); 7048 Local<Value> r = global3->Get(v8_str("prop2"));
7049 CHECK(r->IsUndefined()); 7049 CHECK(r->IsUndefined());
7050 } 7050 }
7051 7051
7052 env2.Dispose(env2->GetIsolate()); 7052 env2.Dispose(env2->GetIsolate());
7053 env3.Dispose(env3->GetIsolate()); 7053 env3.Dispose(env3->GetIsolate());
7054 } 7054 }
7055 7055
7056 7056
7057 TEST(DetachAndReattachGlobal) { 7057 TEST(DetachAndReattachGlobal) {
7058 v8::HandleScope scope;
7059 LocalContext env1; 7058 LocalContext env1;
7059 v8::HandleScope scope(env1->GetIsolate());
7060 7060
7061 // Create second environment. 7061 // Create second environment.
7062 v8::Persistent<Context> env2 = Context::New(); 7062 v8::Persistent<Context> env2 = Context::New();
7063 7063
7064 Local<Value> foo = v8_str("foo"); 7064 Local<Value> foo = v8_str("foo");
7065 7065
7066 // Set same security token for env1 and env2. 7066 // Set same security token for env1 and env2.
7067 env1->SetSecurityToken(foo); 7067 env1->SetSecurityToken(foo);
7068 env2->SetSecurityToken(foo); 7068 env2->SetSecurityToken(foo);
7069 7069
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
7174 } 7174 }
7175 7175
7176 7176
7177 static void UnreachableSetter(Local<String>, Local<Value>, 7177 static void UnreachableSetter(Local<String>, Local<Value>,
7178 const AccessorInfo&) { 7178 const AccessorInfo&) {
7179 CHECK(false); // This function should nto be called. 7179 CHECK(false); // This function should nto be called.
7180 } 7180 }
7181 7181
7182 7182
7183 TEST(AccessControl) { 7183 TEST(AccessControl) {
7184 v8::HandleScope handle_scope; 7184 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7185 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7185 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7186 7186
7187 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7187 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7188 IndexedAccessBlocker); 7188 IndexedAccessBlocker);
7189 7189
7190 // Add an accessor accessible by cross-domain JS code. 7190 // Add an accessor accessible by cross-domain JS code.
7191 global_template->SetAccessor( 7191 global_template->SetAccessor(
7192 v8_str("accessible_prop"), 7192 v8_str("accessible_prop"),
7193 EchoGetter, EchoSetter, 7193 EchoGetter, EchoSetter,
7194 v8::Handle<Value>(), 7194 v8::Handle<Value>(),
(...skipping 25 matching lines...) Expand all
7220 7220
7221 // Define an element with JS getter and setter. 7221 // Define an element with JS getter and setter.
7222 CompileRun( 7222 CompileRun(
7223 "function el_getter() { return 'el_getter'; };\n" 7223 "function el_getter() { return 'el_getter'; };\n"
7224 "function el_setter() { return 'el_setter'; };\n" 7224 "function el_setter() { return 'el_setter'; };\n"
7225 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); 7225 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
7226 7226
7227 Local<Value> el_getter = global0->Get(v8_str("el_getter")); 7227 Local<Value> el_getter = global0->Get(v8_str("el_getter"));
7228 Local<Value> el_setter = global0->Get(v8_str("el_setter")); 7228 Local<Value> el_setter = global0->Get(v8_str("el_setter"));
7229 7229
7230 v8::HandleScope scope1; 7230 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7231 7231
7232 v8::Persistent<Context> context1 = Context::New(); 7232 v8::Persistent<Context> context1 = Context::New();
7233 context1->Enter(); 7233 context1->Enter();
7234 7234
7235 v8::Handle<v8::Object> global1 = context1->Global(); 7235 v8::Handle<v8::Object> global1 = context1->Global();
7236 global1->Set(v8_str("other"), global0); 7236 global1->Set(v8_str("other"), global0);
7237 7237
7238 // Access blocked property. 7238 // Access blocked property.
7239 CompileRun("other.blocked_prop = 1"); 7239 CompileRun("other.blocked_prop = 1");
7240 7240
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
7418 CHECK(value->IsTrue()); 7418 CHECK(value->IsTrue());
7419 7419
7420 context1->Exit(); 7420 context1->Exit();
7421 context0->Exit(); 7421 context0->Exit();
7422 context1.Dispose(context1->GetIsolate()); 7422 context1.Dispose(context1->GetIsolate());
7423 context0.Dispose(context0->GetIsolate()); 7423 context0.Dispose(context0->GetIsolate());
7424 } 7424 }
7425 7425
7426 7426
7427 TEST(AccessControlES5) { 7427 TEST(AccessControlES5) {
7428 v8::HandleScope handle_scope; 7428 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7429 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 7429 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
7430 7430
7431 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 7431 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
7432 IndexedAccessBlocker); 7432 IndexedAccessBlocker);
7433 7433
7434 // Add accessible accessor. 7434 // Add accessible accessor.
7435 global_template->SetAccessor( 7435 global_template->SetAccessor(
7436 v8_str("accessible_prop"), 7436 v8_str("accessible_prop"),
7437 EchoGetter, EchoSetter, 7437 EchoGetter, EchoSetter,
7438 v8::Handle<Value>(), 7438 v8::Handle<Value>(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
7504 7504
7505 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, 7505 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global,
7506 uint32_t key, 7506 uint32_t key,
7507 v8::AccessType type, 7507 v8::AccessType type,
7508 Local<Value> data) { 7508 Local<Value> data) {
7509 return false; 7509 return false;
7510 } 7510 }
7511 7511
7512 7512
7513 THREADED_TEST(AccessControlGetOwnPropertyNames) { 7513 THREADED_TEST(AccessControlGetOwnPropertyNames) {
7514 v8::HandleScope handle_scope; 7514 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7515 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 7515 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
7516 7516
7517 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 7517 obj_template->Set(v8_str("x"), v8::Integer::New(42));
7518 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker, 7518 obj_template->SetAccessCheckCallbacks(GetOwnPropertyNamesNamedBlocker,
7519 GetOwnPropertyNamesIndexedBlocker); 7519 GetOwnPropertyNamesIndexedBlocker);
7520 7520
7521 // Create an environment 7521 // Create an environment
7522 v8::Persistent<Context> context0 = Context::New(NULL, obj_template); 7522 v8::Persistent<Context> context0 = Context::New(NULL, obj_template);
7523 context0->Enter(); 7523 context0->Enter();
7524 7524
7525 v8::Handle<v8::Object> global0 = context0->Global(); 7525 v8::Handle<v8::Object> global0 = context0->Global();
7526 7526
7527 v8::HandleScope scope1; 7527 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7528 7528
7529 v8::Persistent<Context> context1 = Context::New(); 7529 v8::Persistent<Context> context1 = Context::New();
7530 context1->Enter(); 7530 context1->Enter();
7531 7531
7532 v8::Handle<v8::Object> global1 = context1->Global(); 7532 v8::Handle<v8::Object> global1 = context1->Global();
7533 global1->Set(v8_str("other"), global0); 7533 global1->Set(v8_str("other"), global0);
7534 global1->Set(v8_str("object"), obj_template->NewInstance()); 7534 global1->Set(v8_str("object"), obj_template->NewInstance());
7535 7535
7536 v8::Handle<Value> value; 7536 v8::Handle<Value> value;
7537 7537
(...skipping 25 matching lines...) Expand all
7563 7563
7564 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) { 7564 static v8::Handle<v8::Array> NamedPropertyEnumerator(const AccessorInfo& info) {
7565 v8::Handle<v8::Array> result = v8::Array::New(2); 7565 v8::Handle<v8::Array> result = v8::Array::New(2);
7566 result->Set(0, v8_str("x")); 7566 result->Set(0, v8_str("x"));
7567 result->Set(1, v8::Object::New()); 7567 result->Set(1, v8::Object::New());
7568 return result; 7568 return result;
7569 } 7569 }
7570 7570
7571 7571
7572 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) { 7572 THREADED_TEST(GetOwnPropertyNamesWithInterceptor) {
7573 v8::HandleScope handle_scope; 7573 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7574 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(); 7574 v8::Handle<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New();
7575 7575
7576 obj_template->Set(v8_str("7"), v8::Integer::New(7)); 7576 obj_template->Set(v8_str("7"), v8::Integer::New(7));
7577 obj_template->Set(v8_str("x"), v8::Integer::New(42)); 7577 obj_template->Set(v8_str("x"), v8::Integer::New(42));
7578 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL, 7578 obj_template->SetIndexedPropertyHandler(NULL, NULL, NULL, NULL,
7579 IndexedPropertyEnumerator); 7579 IndexedPropertyEnumerator);
7580 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL, 7580 obj_template->SetNamedPropertyHandler(NULL, NULL, NULL, NULL,
7581 NamedPropertyEnumerator); 7581 NamedPropertyEnumerator);
7582 7582
7583 LocalContext context; 7583 LocalContext context;
(...skipping 14 matching lines...) Expand all
7598 } 7598 }
7599 7599
7600 7600
7601 static v8::Handle<Value> ConstTenGetter(Local<String> name, 7601 static v8::Handle<Value> ConstTenGetter(Local<String> name,
7602 const AccessorInfo& info) { 7602 const AccessorInfo& info) {
7603 return v8_num(10); 7603 return v8_num(10);
7604 } 7604 }
7605 7605
7606 7606
7607 THREADED_TEST(CrossDomainAccessors) { 7607 THREADED_TEST(CrossDomainAccessors) {
7608 v8::HandleScope handle_scope; 7608 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7609 7609
7610 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 7610 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New();
7611 7611
7612 v8::Handle<v8::ObjectTemplate> global_template = 7612 v8::Handle<v8::ObjectTemplate> global_template =
7613 func_template->InstanceTemplate(); 7613 func_template->InstanceTemplate();
7614 7614
7615 v8::Handle<v8::ObjectTemplate> proto_template = 7615 v8::Handle<v8::ObjectTemplate> proto_template =
7616 func_template->PrototypeTemplate(); 7616 func_template->PrototypeTemplate();
7617 7617
7618 // Add an accessor to proto that's accessible by cross-domain JS code. 7618 // Add an accessor to proto that's accessible by cross-domain JS code.
7619 proto_template->SetAccessor(v8_str("accessible"), 7619 proto_template->SetAccessor(v8_str("accessible"),
7620 ConstTenGetter, 0, 7620 ConstTenGetter, 0,
7621 v8::Handle<Value>(), 7621 v8::Handle<Value>(),
7622 v8::ALL_CAN_READ); 7622 v8::ALL_CAN_READ);
7623 7623
7624 // Add an accessor that is not accessible by cross-domain JS code. 7624 // Add an accessor that is not accessible by cross-domain JS code.
7625 global_template->SetAccessor(v8_str("unreachable"), 7625 global_template->SetAccessor(v8_str("unreachable"),
7626 UnreachableGetter, 0, 7626 UnreachableGetter, 0,
7627 v8::Handle<Value>(), 7627 v8::Handle<Value>(),
7628 v8::DEFAULT); 7628 v8::DEFAULT);
7629 7629
7630 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 7630 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
7631 context0->Enter(); 7631 context0->Enter();
7632 7632
7633 Local<v8::Object> global = context0->Global(); 7633 Local<v8::Object> global = context0->Global();
7634 // Add a normal property that shadows 'accessible' 7634 // Add a normal property that shadows 'accessible'
7635 global->Set(v8_str("accessible"), v8_num(11)); 7635 global->Set(v8_str("accessible"), v8_num(11));
7636 7636
7637 // Enter a new context. 7637 // Enter a new context.
7638 v8::HandleScope scope1; 7638 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7639 v8::Persistent<Context> context1 = Context::New(); 7639 v8::Persistent<Context> context1 = Context::New();
7640 context1->Enter(); 7640 context1->Enter();
7641 7641
7642 v8::Handle<v8::Object> global1 = context1->Global(); 7642 v8::Handle<v8::Object> global1 = context1->Global();
7643 global1->Set(v8_str("other"), global); 7643 global1->Set(v8_str("other"), global);
7644 7644
7645 // Should return 10, instead of 11 7645 // Should return 10, instead of 11
7646 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 7646 v8::Handle<Value> value = v8_compile("other.accessible")->Run();
7647 CHECK(value->IsNumber()); 7647 CHECK(value->IsNumber());
7648 CHECK_EQ(10, value->Int32Value()); 7648 CHECK_EQ(10, value->Int32Value());
(...skipping 27 matching lines...) Expand all
7676 indexed_access_count++; 7676 indexed_access_count++;
7677 return true; 7677 return true;
7678 } 7678 }
7679 7679
7680 7680
7681 // This one is too easily disturbed by other tests. 7681 // This one is too easily disturbed by other tests.
7682 TEST(AccessControlIC) { 7682 TEST(AccessControlIC) {
7683 named_access_count = 0; 7683 named_access_count = 0;
7684 indexed_access_count = 0; 7684 indexed_access_count = 0;
7685 7685
7686 v8::HandleScope handle_scope; 7686 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7687 7687
7688 // Create an environment. 7688 // Create an environment.
7689 v8::Persistent<Context> context0 = Context::New(); 7689 v8::Persistent<Context> context0 = Context::New();
7690 context0->Enter(); 7690 context0->Enter();
7691 7691
7692 // Create an object that requires access-check functions to be 7692 // Create an object that requires access-check functions to be
7693 // called for cross-domain access. 7693 // called for cross-domain access.
7694 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7694 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7695 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 7695 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
7696 IndexedAccessCounter); 7696 IndexedAccessCounter);
7697 Local<v8::Object> object = object_template->NewInstance(); 7697 Local<v8::Object> object = object_template->NewInstance();
7698 7698
7699 v8::HandleScope scope1; 7699 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7700 7700
7701 // Create another environment. 7701 // Create another environment.
7702 v8::Persistent<Context> context1 = Context::New(); 7702 v8::Persistent<Context> context1 = Context::New();
7703 context1->Enter(); 7703 context1->Enter();
7704 7704
7705 // Make easy access to the object from the other environment. 7705 // Make easy access to the object from the other environment.
7706 v8::Handle<v8::Object> global1 = context1->Global(); 7706 v8::Handle<v8::Object> global1 = context1->Global();
7707 global1->Set(v8_str("obj"), object); 7707 global1->Set(v8_str("obj"), object);
7708 7708
7709 v8::Handle<Value> value; 7709 v8::Handle<Value> value;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
7825 7825
7826 // Regression test. In access checks, operations that may cause 7826 // Regression test. In access checks, operations that may cause
7827 // garbage collection are not allowed. It used to be the case that 7827 // garbage collection are not allowed. It used to be the case that
7828 // using the Write operation on a string could cause a garbage 7828 // using the Write operation on a string could cause a garbage
7829 // collection due to flattening of the string. This is no longer the 7829 // collection due to flattening of the string. This is no longer the
7830 // case. 7830 // case.
7831 THREADED_TEST(AccessControlFlatten) { 7831 THREADED_TEST(AccessControlFlatten) {
7832 named_access_count = 0; 7832 named_access_count = 0;
7833 indexed_access_count = 0; 7833 indexed_access_count = 0;
7834 7834
7835 v8::HandleScope handle_scope; 7835 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7836 7836
7837 // Create an environment. 7837 // Create an environment.
7838 v8::Persistent<Context> context0 = Context::New(); 7838 v8::Persistent<Context> context0 = Context::New();
7839 context0->Enter(); 7839 context0->Enter();
7840 7840
7841 // Create an object that requires access-check functions to be 7841 // Create an object that requires access-check functions to be
7842 // called for cross-domain access. 7842 // called for cross-domain access.
7843 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7843 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7844 object_template->SetAccessCheckCallbacks(NamedAccessFlatten, 7844 object_template->SetAccessCheckCallbacks(NamedAccessFlatten,
7845 IndexedAccessFlatten); 7845 IndexedAccessFlatten);
7846 Local<v8::Object> object = object_template->NewInstance(); 7846 Local<v8::Object> object = object_template->NewInstance();
7847 7847
7848 v8::HandleScope scope1; 7848 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7849 7849
7850 // Create another environment. 7850 // Create another environment.
7851 v8::Persistent<Context> context1 = Context::New(); 7851 v8::Persistent<Context> context1 = Context::New();
7852 context1->Enter(); 7852 context1->Enter();
7853 7853
7854 // Make easy access to the object from the other environment. 7854 // Make easy access to the object from the other environment.
7855 v8::Handle<v8::Object> global1 = context1->Global(); 7855 v8::Handle<v8::Object> global1 = context1->Global();
7856 global1->Set(v8_str("obj"), object); 7856 global1->Set(v8_str("obj"), object);
7857 7857
7858 v8::Handle<Value> value; 7858 v8::Handle<Value> value;
(...skipping 30 matching lines...) Expand all
7889 static v8::Handle<Value> AccessControlIndexedSetter( 7889 static v8::Handle<Value> AccessControlIndexedSetter(
7890 uint32_t, Local<Value> value, const AccessorInfo&) { 7890 uint32_t, Local<Value> value, const AccessorInfo&) {
7891 return value; 7891 return value;
7892 } 7892 }
7893 7893
7894 7894
7895 THREADED_TEST(AccessControlInterceptorIC) { 7895 THREADED_TEST(AccessControlInterceptorIC) {
7896 named_access_count = 0; 7896 named_access_count = 0;
7897 indexed_access_count = 0; 7897 indexed_access_count = 0;
7898 7898
7899 v8::HandleScope handle_scope; 7899 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
7900 7900
7901 // Create an environment. 7901 // Create an environment.
7902 v8::Persistent<Context> context0 = Context::New(); 7902 v8::Persistent<Context> context0 = Context::New();
7903 context0->Enter(); 7903 context0->Enter();
7904 7904
7905 // Create an object that requires access-check functions to be 7905 // Create an object that requires access-check functions to be
7906 // called for cross-domain access. The object also has interceptors 7906 // called for cross-domain access. The object also has interceptors
7907 // interceptor. 7907 // interceptor.
7908 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 7908 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
7909 object_template->SetAccessCheckCallbacks(NamedAccessCounter, 7909 object_template->SetAccessCheckCallbacks(NamedAccessCounter,
7910 IndexedAccessCounter); 7910 IndexedAccessCounter);
7911 object_template->SetNamedPropertyHandler(AccessControlNamedGetter, 7911 object_template->SetNamedPropertyHandler(AccessControlNamedGetter,
7912 AccessControlNamedSetter); 7912 AccessControlNamedSetter);
7913 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter, 7913 object_template->SetIndexedPropertyHandler(AccessControlIndexedGetter,
7914 AccessControlIndexedSetter); 7914 AccessControlIndexedSetter);
7915 Local<v8::Object> object = object_template->NewInstance(); 7915 Local<v8::Object> object = object_template->NewInstance();
7916 7916
7917 v8::HandleScope scope1; 7917 v8::HandleScope scope1(v8::Isolate::GetCurrent());
7918 7918
7919 // Create another environment. 7919 // Create another environment.
7920 v8::Persistent<Context> context1 = Context::New(); 7920 v8::Persistent<Context> context1 = Context::New();
7921 context1->Enter(); 7921 context1->Enter();
7922 7922
7923 // Make easy access to the object from the other environment. 7923 // Make easy access to the object from the other environment.
7924 v8::Handle<v8::Object> global1 = context1->Global(); 7924 v8::Handle<v8::Object> global1 = context1->Global();
7925 global1->Set(v8_str("obj"), object); 7925 global1->Set(v8_str("obj"), object);
7926 7926
7927 v8::Handle<Value> value; 7927 v8::Handle<Value> value;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7964 } 7964 }
7965 7965
7966 7966
7967 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) { 7967 static v8::Handle<Value> InstanceFunctionCallback(const v8::Arguments& args) {
7968 ApiTestFuzzer::Fuzz(); 7968 ApiTestFuzzer::Fuzz();
7969 return v8_num(12); 7969 return v8_num(12);
7970 } 7970 }
7971 7971
7972 7972
7973 THREADED_TEST(InstanceProperties) { 7973 THREADED_TEST(InstanceProperties) {
7974 v8::HandleScope handle_scope;
7975 LocalContext context; 7974 LocalContext context;
7975 v8::HandleScope handle_scope(context->GetIsolate());
7976 7976
7977 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 7977 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
7978 Local<ObjectTemplate> instance = t->InstanceTemplate(); 7978 Local<ObjectTemplate> instance = t->InstanceTemplate();
7979 7979
7980 instance->Set(v8_str("x"), v8_num(42)); 7980 instance->Set(v8_str("x"), v8_num(42));
7981 instance->Set(v8_str("f"), 7981 instance->Set(v8_str("f"),
7982 v8::FunctionTemplate::New(InstanceFunctionCallback)); 7982 v8::FunctionTemplate::New(InstanceFunctionCallback));
7983 7983
7984 Local<Value> o = t->GetFunction()->NewInstance(); 7984 Local<Value> o = t->GetFunction()->NewInstance();
7985 7985
7986 context->Global()->Set(v8_str("i"), o); 7986 context->Global()->Set(v8_str("i"), o);
7987 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); 7987 Local<Value> value = Script::Compile(v8_str("i.x"))->Run();
7988 CHECK_EQ(42, value->Int32Value()); 7988 CHECK_EQ(42, value->Int32Value());
7989 7989
7990 value = Script::Compile(v8_str("i.f()"))->Run(); 7990 value = Script::Compile(v8_str("i.f()"))->Run();
7991 CHECK_EQ(12, value->Int32Value()); 7991 CHECK_EQ(12, value->Int32Value());
7992 } 7992 }
7993 7993
7994 7994
7995 static v8::Handle<Value> 7995 static v8::Handle<Value>
7996 GlobalObjectInstancePropertiesGet(Local<String> key, const AccessorInfo&) { 7996 GlobalObjectInstancePropertiesGet(Local<String> key, const AccessorInfo&) {
7997 ApiTestFuzzer::Fuzz(); 7997 ApiTestFuzzer::Fuzz();
7998 return v8::Handle<Value>(); 7998 return v8::Handle<Value>();
7999 } 7999 }
8000 8000
8001 8001
8002 THREADED_TEST(GlobalObjectInstanceProperties) { 8002 THREADED_TEST(GlobalObjectInstanceProperties) {
8003 v8::HandleScope handle_scope; 8003 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8004 8004
8005 Local<Value> global_object; 8005 Local<Value> global_object;
8006 8006
8007 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8007 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8008 t->InstanceTemplate()->SetNamedPropertyHandler( 8008 t->InstanceTemplate()->SetNamedPropertyHandler(
8009 GlobalObjectInstancePropertiesGet); 8009 GlobalObjectInstancePropertiesGet);
8010 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8010 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8011 instance_template->Set(v8_str("x"), v8_num(42)); 8011 instance_template->Set(v8_str("x"), v8_num(42));
8012 instance_template->Set(v8_str("f"), 8012 instance_template->Set(v8_str("f"),
8013 v8::FunctionTemplate::New(InstanceFunctionCallback)); 8013 v8::FunctionTemplate::New(InstanceFunctionCallback));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
8049 CHECK_EQ(42, value->Int32Value()); 8049 CHECK_EQ(42, value->Int32Value());
8050 value = Script::Compile(v8_str("f()"))->Run(); 8050 value = Script::Compile(v8_str("f()"))->Run();
8051 CHECK_EQ(12, value->Int32Value()); 8051 CHECK_EQ(12, value->Int32Value());
8052 value = Script::Compile(v8_str(script))->Run(); 8052 value = Script::Compile(v8_str(script))->Run();
8053 CHECK_EQ(1, value->Int32Value()); 8053 CHECK_EQ(1, value->Int32Value());
8054 } 8054 }
8055 } 8055 }
8056 8056
8057 8057
8058 THREADED_TEST(CallKnownGlobalReceiver) { 8058 THREADED_TEST(CallKnownGlobalReceiver) {
8059 v8::HandleScope handle_scope; 8059 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8060 8060
8061 Local<Value> global_object; 8061 Local<Value> global_object;
8062 8062
8063 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8063 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8064 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8064 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8065 8065
8066 // The script to check that we leave global object not 8066 // The script to check that we leave global object not
8067 // global object proxy on stack when we deoptimize from inside 8067 // global object proxy on stack when we deoptimize from inside
8068 // arguments evaluation. 8068 // arguments evaluation.
8069 // To provoke error we need to both force deoptimization 8069 // To provoke error we need to both force deoptimization
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8127 8127
8128 8128
8129 static v8::Handle<Value> ShadowNamedGet(Local<String> key, 8129 static v8::Handle<Value> ShadowNamedGet(Local<String> key,
8130 const AccessorInfo&) { 8130 const AccessorInfo&) {
8131 return v8::Handle<Value>(); 8131 return v8::Handle<Value>();
8132 } 8132 }
8133 8133
8134 8134
8135 THREADED_TEST(ShadowObject) { 8135 THREADED_TEST(ShadowObject) {
8136 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 8136 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
8137 v8::HandleScope handle_scope; 8137 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
8138 8138
8139 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 8139 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New();
8140 LocalContext context(NULL, global_template); 8140 LocalContext context(NULL, global_template);
8141 8141
8142 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8142 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8143 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); 8143 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
8144 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); 8144 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
8145 Local<ObjectTemplate> proto = t->PrototypeTemplate(); 8145 Local<ObjectTemplate> proto = t->PrototypeTemplate();
8146 Local<ObjectTemplate> instance = t->InstanceTemplate(); 8146 Local<ObjectTemplate> instance = t->InstanceTemplate();
8147 8147
(...skipping 19 matching lines...) Expand all
8167 8167
8168 Script::Compile(v8_str("y = 43"))->Run(); 8168 Script::Compile(v8_str("y = 43"))->Run();
8169 CHECK_EQ(1, shadow_y_setter_call_count); 8169 CHECK_EQ(1, shadow_y_setter_call_count);
8170 value = Script::Compile(v8_str("y"))->Run(); 8170 value = Script::Compile(v8_str("y"))->Run();
8171 CHECK_EQ(1, shadow_y_getter_call_count); 8171 CHECK_EQ(1, shadow_y_getter_call_count);
8172 CHECK_EQ(42, value->Int32Value()); 8172 CHECK_EQ(42, value->Int32Value());
8173 } 8173 }
8174 8174
8175 8175
8176 THREADED_TEST(HiddenPrototype) { 8176 THREADED_TEST(HiddenPrototype) {
8177 v8::HandleScope handle_scope;
8178 LocalContext context; 8177 LocalContext context;
8178 v8::HandleScope handle_scope(context->GetIsolate());
8179 8179
8180 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 8180 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
8181 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8181 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8182 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8182 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8183 t1->SetHiddenPrototype(true); 8183 t1->SetHiddenPrototype(true);
8184 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 8184 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
8185 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8185 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8186 t2->SetHiddenPrototype(true); 8186 t2->SetHiddenPrototype(true);
8187 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 8187 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
8188 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8188 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 22 matching lines...) Expand all
8211 // Getting the prototype of o0 should get the first visible one 8211 // Getting the prototype of o0 should get the first visible one
8212 // which is o3. Therefore, z should not be defined on the prototype 8212 // which is o3. Therefore, z should not be defined on the prototype
8213 // object. 8213 // object.
8214 Local<Value> proto = o0->Get(v8_str("__proto__")); 8214 Local<Value> proto = o0->Get(v8_str("__proto__"));
8215 CHECK(proto->IsObject()); 8215 CHECK(proto->IsObject());
8216 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); 8216 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined());
8217 } 8217 }
8218 8218
8219 8219
8220 THREADED_TEST(HiddenPrototypeSet) { 8220 THREADED_TEST(HiddenPrototypeSet) {
8221 v8::HandleScope handle_scope;
8222 LocalContext context; 8221 LocalContext context;
8222 v8::HandleScope handle_scope(context->GetIsolate());
8223 8223
8224 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(); 8224 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New();
8225 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(); 8225 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New();
8226 ht->SetHiddenPrototype(true); 8226 ht->SetHiddenPrototype(true);
8227 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(); 8227 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New();
8228 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8228 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8229 8229
8230 Local<v8::Object> o = ot->GetFunction()->NewInstance(); 8230 Local<v8::Object> o = ot->GetFunction()->NewInstance();
8231 Local<v8::Object> h = ht->GetFunction()->NewInstance(); 8231 Local<v8::Object> h = ht->GetFunction()->NewInstance();
8232 Local<v8::Object> p = pt->GetFunction()->NewInstance(); 8232 Local<v8::Object> p = pt->GetFunction()->NewInstance();
(...skipping 20 matching lines...) Expand all
8253 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 8253 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
8254 o->Set(v8_str("z"), v8_num(9)); 8254 o->Set(v8_str("z"), v8_num(9));
8255 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value()); 8255 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value());
8256 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); 8256 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value());
8257 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 8257 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
8258 } 8258 }
8259 8259
8260 8260
8261 // Regression test for issue 2457. 8261 // Regression test for issue 2457.
8262 THREADED_TEST(HiddenPrototypeIdentityHash) { 8262 THREADED_TEST(HiddenPrototypeIdentityHash) {
8263 v8::HandleScope handle_scope;
8264 LocalContext context; 8263 LocalContext context;
8264 v8::HandleScope handle_scope(context->GetIsolate());
8265 8265
8266 Handle<FunctionTemplate> t = FunctionTemplate::New(); 8266 Handle<FunctionTemplate> t = FunctionTemplate::New();
8267 t->SetHiddenPrototype(true); 8267 t->SetHiddenPrototype(true);
8268 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 8268 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
8269 Handle<Object> p = t->GetFunction()->NewInstance(); 8269 Handle<Object> p = t->GetFunction()->NewInstance();
8270 Handle<Object> o = Object::New(); 8270 Handle<Object> o = Object::New();
8271 o->SetPrototype(p); 8271 o->SetPrototype(p);
8272 8272
8273 int hash = o->GetIdentityHash(); 8273 int hash = o->GetIdentityHash();
8274 USE(hash); 8274 USE(hash);
8275 o->Set(v8_str("foo"), v8_num(42)); 8275 o->Set(v8_str("foo"), v8_num(42));
8276 ASSERT_EQ(hash, o->GetIdentityHash()); 8276 ASSERT_EQ(hash, o->GetIdentityHash());
8277 } 8277 }
8278 8278
8279 8279
8280 THREADED_TEST(SetPrototype) { 8280 THREADED_TEST(SetPrototype) {
8281 v8::HandleScope handle_scope;
8282 LocalContext context; 8281 LocalContext context;
8282 v8::HandleScope handle_scope(context->GetIsolate());
8283 8283
8284 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 8284 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New();
8285 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 8285 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
8286 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8286 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8287 t1->SetHiddenPrototype(true); 8287 t1->SetHiddenPrototype(true);
8288 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 8288 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
8289 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8289 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8290 t2->SetHiddenPrototype(true); 8290 t2->SetHiddenPrototype(true);
8291 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 8291 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
8292 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8292 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
8332 CHECK(proto2->IsObject()); 8332 CHECK(proto2->IsObject());
8333 CHECK_EQ(proto2.As<v8::Object>(), o3); 8333 CHECK_EQ(proto2.As<v8::Object>(), o3);
8334 } 8334 }
8335 8335
8336 8336
8337 // Getting property names of an object with a prototype chain that 8337 // Getting property names of an object with a prototype chain that
8338 // triggers dictionary elements in GetLocalPropertyNames() shouldn't 8338 // triggers dictionary elements in GetLocalPropertyNames() shouldn't
8339 // crash the runtime. 8339 // crash the runtime.
8340 THREADED_TEST(Regress91517) { 8340 THREADED_TEST(Regress91517) {
8341 i::FLAG_allow_natives_syntax = true; 8341 i::FLAG_allow_natives_syntax = true;
8342 v8::HandleScope handle_scope;
8343 LocalContext context; 8342 LocalContext context;
8343 v8::HandleScope handle_scope(context->GetIsolate());
8344 8344
8345 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8345 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8346 t1->SetHiddenPrototype(true); 8346 t1->SetHiddenPrototype(true);
8347 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 8347 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
8348 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8348 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8349 t2->SetHiddenPrototype(true); 8349 t2->SetHiddenPrototype(true);
8350 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 8350 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
8351 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); 8351 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New());
8352 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 8352 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
8353 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 8353 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New();
(...skipping 28 matching lines...) Expand all
8382 ExpectTrue("names.indexOf(\"baz\") >= 0"); 8382 ExpectTrue("names.indexOf(\"baz\") >= 0");
8383 ExpectTrue("names.indexOf(\"boo\") >= 0"); 8383 ExpectTrue("names.indexOf(\"boo\") >= 0");
8384 ExpectTrue("names.indexOf(\"foo\") >= 0"); 8384 ExpectTrue("names.indexOf(\"foo\") >= 0");
8385 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 8385 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
8386 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 8386 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
8387 ExpectFalse("names[1005] == undefined"); 8387 ExpectFalse("names[1005] == undefined");
8388 } 8388 }
8389 8389
8390 8390
8391 THREADED_TEST(FunctionReadOnlyPrototype) { 8391 THREADED_TEST(FunctionReadOnlyPrototype) {
8392 v8::HandleScope handle_scope;
8393 LocalContext context; 8392 LocalContext context;
8393 v8::HandleScope handle_scope(context->GetIsolate());
8394 8394
8395 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 8395 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New();
8396 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 8396 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
8397 t1->ReadOnlyPrototype(); 8397 t1->ReadOnlyPrototype();
8398 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 8398 context->Global()->Set(v8_str("func1"), t1->GetFunction());
8399 // Configured value of ReadOnly flag. 8399 // Configured value of ReadOnly flag.
8400 CHECK(CompileRun( 8400 CHECK(CompileRun(
8401 "(function() {" 8401 "(function() {"
8402 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 8402 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
8403 " return (descriptor['writable'] == false);" 8403 " return (descriptor['writable'] == false);"
8404 "})()")->BooleanValue()); 8404 "})()")->BooleanValue());
8405 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 8405 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
8406 CHECK_EQ(42, 8406 CHECK_EQ(42,
8407 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 8407 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
8408 8408
8409 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 8409 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New();
8410 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 8410 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
8411 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 8411 context->Global()->Set(v8_str("func2"), t2->GetFunction());
8412 // Default value of ReadOnly flag. 8412 // Default value of ReadOnly flag.
8413 CHECK(CompileRun( 8413 CHECK(CompileRun(
8414 "(function() {" 8414 "(function() {"
8415 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 8415 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
8416 " return (descriptor['writable'] == true);" 8416 " return (descriptor['writable'] == true);"
8417 "})()")->BooleanValue()); 8417 "})()")->BooleanValue());
8418 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 8418 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
8419 } 8419 }
8420 8420
8421 8421
8422 THREADED_TEST(SetPrototypeThrows) { 8422 THREADED_TEST(SetPrototypeThrows) {
8423 v8::HandleScope handle_scope;
8424 LocalContext context; 8423 LocalContext context;
8424 v8::HandleScope handle_scope(context->GetIsolate());
8425 8425
8426 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8426 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8427 8427
8428 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 8428 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
8429 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 8429 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
8430 8430
8431 CHECK(o0->SetPrototype(o1)); 8431 CHECK(o0->SetPrototype(o1));
8432 // If setting the prototype leads to the cycle, SetPrototype should 8432 // If setting the prototype leads to the cycle, SetPrototype should
8433 // return false and keep VM in sane state. 8433 // return false and keep VM in sane state.
8434 v8::TryCatch try_catch; 8434 v8::TryCatch try_catch;
8435 CHECK(!o1->SetPrototype(o0)); 8435 CHECK(!o1->SetPrototype(o0));
8436 CHECK(!try_catch.HasCaught()); 8436 CHECK(!try_catch.HasCaught());
8437 ASSERT(!i::Isolate::Current()->has_pending_exception()); 8437 ASSERT(!i::Isolate::Current()->has_pending_exception());
8438 8438
8439 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 8439 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value());
8440 } 8440 }
8441 8441
8442 8442
8443 THREADED_TEST(GetterSetterExceptions) { 8443 THREADED_TEST(GetterSetterExceptions) {
8444 v8::HandleScope handle_scope;
8445 LocalContext context; 8444 LocalContext context;
8445 v8::HandleScope handle_scope(context->GetIsolate());
8446 CompileRun( 8446 CompileRun(
8447 "function Foo() { };" 8447 "function Foo() { };"
8448 "function Throw() { throw 5; };" 8448 "function Throw() { throw 5; };"
8449 "var x = { };" 8449 "var x = { };"
8450 "x.__defineSetter__('set', Throw);" 8450 "x.__defineSetter__('set', Throw);"
8451 "x.__defineGetter__('get', Throw);"); 8451 "x.__defineGetter__('get', Throw);");
8452 Local<v8::Object> x = 8452 Local<v8::Object> x =
8453 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); 8453 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x")));
8454 v8::TryCatch try_catch; 8454 v8::TryCatch try_catch;
8455 x->Set(v8_str("set"), v8::Integer::New(8)); 8455 x->Set(v8_str("set"), v8::Integer::New(8));
8456 x->Get(v8_str("get")); 8456 x->Get(v8_str("get"));
8457 x->Set(v8_str("set"), v8::Integer::New(8)); 8457 x->Set(v8_str("set"), v8::Integer::New(8));
8458 x->Get(v8_str("get")); 8458 x->Get(v8_str("get"));
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 } 8463 }
8464 8464
8465 8465
8466 THREADED_TEST(Constructor) { 8466 THREADED_TEST(Constructor) {
8467 v8::HandleScope handle_scope;
8468 LocalContext context; 8467 LocalContext context;
8468 v8::HandleScope handle_scope(context->GetIsolate());
8469 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 8469 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
8470 templ->SetClassName(v8_str("Fun")); 8470 templ->SetClassName(v8_str("Fun"));
8471 Local<Function> cons = templ->GetFunction(); 8471 Local<Function> cons = templ->GetFunction();
8472 context->Global()->Set(v8_str("Fun"), cons); 8472 context->Global()->Set(v8_str("Fun"), cons);
8473 Local<v8::Object> inst = cons->NewInstance(); 8473 Local<v8::Object> inst = cons->NewInstance();
8474 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 8474 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
8475 CHECK(obj->IsJSObject()); 8475 CHECK(obj->IsJSObject());
8476 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 8476 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
8477 CHECK(value->BooleanValue()); 8477 CHECK(value->BooleanValue());
8478 } 8478 }
(...skipping 19 matching lines...) Expand all
8498 } 8498 }
8499 8499
8500 8500
8501 static Handle<Value> FakeConstructorCallback(const Arguments& args) { 8501 static Handle<Value> FakeConstructorCallback(const Arguments& args) {
8502 ApiTestFuzzer::Fuzz(); 8502 ApiTestFuzzer::Fuzz();
8503 return args[0]; 8503 return args[0];
8504 } 8504 }
8505 8505
8506 8506
8507 THREADED_TEST(ConstructorForObject) { 8507 THREADED_TEST(ConstructorForObject) {
8508 v8::HandleScope handle_scope;
8509 LocalContext context; 8508 LocalContext context;
8509 v8::HandleScope handle_scope(context->GetIsolate());
8510 8510
8511 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 8511 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
8512 instance_template->SetCallAsFunctionHandler(ConstructorCallback); 8512 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
8513 Local<Object> instance = instance_template->NewInstance(); 8513 Local<Object> instance = instance_template->NewInstance();
8514 context->Global()->Set(v8_str("obj"), instance); 8514 context->Global()->Set(v8_str("obj"), instance);
8515 v8::TryCatch try_catch; 8515 v8::TryCatch try_catch;
8516 Local<Value> value; 8516 Local<Value> value;
8517 CHECK(!try_catch.HasCaught()); 8517 CHECK(!try_catch.HasCaught());
8518 8518
8519 // Call the Object's constructor with a 32-bit signed integer. 8519 // Call the Object's constructor with a 32-bit signed integer.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
8665 8665
8666 Local<Value> args2[] = { v8_num(28) }; 8666 Local<Value> args2[] = { v8_num(28) };
8667 value = instance2->CallAsConstructor(1, args2); 8667 value = instance2->CallAsConstructor(1, args2);
8668 CHECK(!try_catch.HasCaught()); 8668 CHECK(!try_catch.HasCaught());
8669 CHECK(!value->IsObject()); 8669 CHECK(!value->IsObject());
8670 } 8670 }
8671 } 8671 }
8672 8672
8673 8673
8674 THREADED_TEST(FunctionDescriptorException) { 8674 THREADED_TEST(FunctionDescriptorException) {
8675 v8::HandleScope handle_scope;
8676 LocalContext context; 8675 LocalContext context;
8676 v8::HandleScope handle_scope(context->GetIsolate());
8677 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 8677 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
8678 templ->SetClassName(v8_str("Fun")); 8678 templ->SetClassName(v8_str("Fun"));
8679 Local<Function> cons = templ->GetFunction(); 8679 Local<Function> cons = templ->GetFunction();
8680 context->Global()->Set(v8_str("Fun"), cons); 8680 context->Global()->Set(v8_str("Fun"), cons);
8681 Local<Value> value = CompileRun( 8681 Local<Value> value = CompileRun(
8682 "function test() {" 8682 "function test() {"
8683 " try {" 8683 " try {"
8684 " (new Fun()).blah()" 8684 " (new Fun()).blah()"
8685 " } catch (e) {" 8685 " } catch (e) {"
8686 " var str = String(e);" 8686 " var str = String(e);"
8687 " if (str.indexOf('TypeError') == -1) return 1;" 8687 " if (str.indexOf('TypeError') == -1) return 1;"
8688 " if (str.indexOf('[object Fun]') != -1) return 2;" 8688 " if (str.indexOf('[object Fun]') != -1) return 2;"
8689 " if (str.indexOf('#<Fun>') == -1) return 3;" 8689 " if (str.indexOf('#<Fun>') == -1) return 3;"
8690 " return 0;" 8690 " return 0;"
8691 " }" 8691 " }"
8692 " return 4;" 8692 " return 4;"
8693 "}" 8693 "}"
8694 "test();"); 8694 "test();");
8695 CHECK_EQ(0, value->Int32Value()); 8695 CHECK_EQ(0, value->Int32Value());
8696 } 8696 }
8697 8697
8698 8698
8699 THREADED_TEST(EvalAliasedDynamic) { 8699 THREADED_TEST(EvalAliasedDynamic) {
8700 v8::HandleScope scope;
8701 LocalContext current; 8700 LocalContext current;
8701 v8::HandleScope scope(current->GetIsolate());
8702 8702
8703 // Tests where aliased eval can only be resolved dynamically. 8703 // Tests where aliased eval can only be resolved dynamically.
8704 Local<Script> script = 8704 Local<Script> script =
8705 Script::Compile(v8_str("function f(x) { " 8705 Script::Compile(v8_str("function f(x) { "
8706 " var foo = 2;" 8706 " var foo = 2;"
8707 " with (x) { return eval('foo'); }" 8707 " with (x) { return eval('foo'); }"
8708 "}" 8708 "}"
8709 "foo = 0;" 8709 "foo = 0;"
8710 "result1 = f(new Object());" 8710 "result1 = f(new Object());"
8711 "result2 = f(this);" 8711 "result2 = f(this);"
(...skipping 14 matching lines...) Expand all
8726 "result4 = f(this)")); 8726 "result4 = f(this)"));
8727 script->Run(); 8727 script->Run();
8728 CHECK(!try_catch.HasCaught()); 8728 CHECK(!try_catch.HasCaught());
8729 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); 8729 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value());
8730 8730
8731 try_catch.Reset(); 8731 try_catch.Reset();
8732 } 8732 }
8733 8733
8734 8734
8735 THREADED_TEST(CrossEval) { 8735 THREADED_TEST(CrossEval) {
8736 v8::HandleScope scope; 8736 v8::HandleScope scope(v8::Isolate::GetCurrent());
8737 LocalContext other; 8737 LocalContext other;
8738 LocalContext current; 8738 LocalContext current;
8739 8739
8740 Local<String> token = v8_str("<security token>"); 8740 Local<String> token = v8_str("<security token>");
8741 other->SetSecurityToken(token); 8741 other->SetSecurityToken(token);
8742 current->SetSecurityToken(token); 8742 current->SetSecurityToken(token);
8743 8743
8744 // Set up reference from current to other. 8744 // Set up reference from current to other.
8745 current->Global()->Set(v8_str("other"), other->Global()); 8745 current->Global()->Set(v8_str("other"), other->Global());
8746 8746
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
8809 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')")); 8809 Script::Compile(v8_str("other.y = 1; eval.call(other, 'y')"));
8810 result = script->Run(); 8810 result = script->Run();
8811 CHECK(try_catch.HasCaught()); 8811 CHECK(try_catch.HasCaught());
8812 } 8812 }
8813 8813
8814 8814
8815 // Test that calling eval in a context which has been detached from 8815 // Test that calling eval in a context which has been detached from
8816 // its global throws an exception. This behavior is consistent with 8816 // its global throws an exception. This behavior is consistent with
8817 // other JavaScript implementations. 8817 // other JavaScript implementations.
8818 THREADED_TEST(EvalInDetachedGlobal) { 8818 THREADED_TEST(EvalInDetachedGlobal) {
8819 v8::HandleScope scope; 8819 v8::HandleScope scope(v8::Isolate::GetCurrent());
8820 8820
8821 v8::Persistent<Context> context0 = Context::New(); 8821 v8::Persistent<Context> context0 = Context::New();
8822 v8::Persistent<Context> context1 = Context::New(); 8822 v8::Persistent<Context> context1 = Context::New();
8823 8823
8824 // Set up function in context0 that uses eval from context0. 8824 // Set up function in context0 that uses eval from context0.
8825 context0->Enter(); 8825 context0->Enter();
8826 v8::Handle<v8::Value> fun = 8826 v8::Handle<v8::Value> fun =
8827 CompileRun("var x = 42;" 8827 CompileRun("var x = 42;"
8828 "(function() {" 8828 "(function() {"
8829 " var e = eval;" 8829 " var e = eval;"
(...skipping 14 matching lines...) Expand all
8844 CHECK(x_value.IsEmpty()); 8844 CHECK(x_value.IsEmpty());
8845 CHECK(catcher.HasCaught()); 8845 CHECK(catcher.HasCaught());
8846 context1->Exit(); 8846 context1->Exit();
8847 8847
8848 context1.Dispose(context1->GetIsolate()); 8848 context1.Dispose(context1->GetIsolate());
8849 context0.Dispose(context0->GetIsolate()); 8849 context0.Dispose(context0->GetIsolate());
8850 } 8850 }
8851 8851
8852 8852
8853 THREADED_TEST(CrossLazyLoad) { 8853 THREADED_TEST(CrossLazyLoad) {
8854 v8::HandleScope scope; 8854 v8::HandleScope scope(v8::Isolate::GetCurrent());
8855 LocalContext other; 8855 LocalContext other;
8856 LocalContext current; 8856 LocalContext current;
8857 8857
8858 Local<String> token = v8_str("<security token>"); 8858 Local<String> token = v8_str("<security token>");
8859 other->SetSecurityToken(token); 8859 other->SetSecurityToken(token);
8860 current->SetSecurityToken(token); 8860 current->SetSecurityToken(token);
8861 8861
8862 // Set up reference from current to other. 8862 // Set up reference from current to other.
8863 current->Global()->Set(v8_str("other"), other->Global()); 8863 current->Global()->Set(v8_str("other"), other->Global());
8864 8864
(...skipping 14 matching lines...) Expand all
8879 } 8879 }
8880 8880
8881 return args[0]; 8881 return args[0];
8882 } 8882 }
8883 8883
8884 8884
8885 // Test that a call handler can be set for objects which will allow 8885 // Test that a call handler can be set for objects which will allow
8886 // non-function objects created through the API to be called as 8886 // non-function objects created through the API to be called as
8887 // functions. 8887 // functions.
8888 THREADED_TEST(CallAsFunction) { 8888 THREADED_TEST(CallAsFunction) {
8889 v8::HandleScope scope;
8890 LocalContext context; 8889 LocalContext context;
8890 v8::HandleScope scope(context->GetIsolate());
8891 8891
8892 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 8892 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
8893 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 8893 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
8894 instance_template->SetCallAsFunctionHandler(call_as_function); 8894 instance_template->SetCallAsFunctionHandler(call_as_function);
8895 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 8895 Local<v8::Object> instance = t->GetFunction()->NewInstance();
8896 context->Global()->Set(v8_str("obj"), instance); 8896 context->Global()->Set(v8_str("obj"), instance);
8897 v8::TryCatch try_catch; 8897 v8::TryCatch try_catch;
8898 Local<Value> value; 8898 Local<Value> value;
8899 CHECK(!try_catch.HasCaught()); 8899 CHECK(!try_catch.HasCaught());
8900 8900
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
8992 CHECK(try_catch.HasCaught()); 8992 CHECK(try_catch.HasCaught());
8993 String::AsciiValue exception_value2(try_catch.Exception()); 8993 String::AsciiValue exception_value2(try_catch.Exception());
8994 CHECK_EQ("23", *exception_value2); 8994 CHECK_EQ("23", *exception_value2);
8995 try_catch.Reset(); 8995 try_catch.Reset();
8996 } 8996 }
8997 } 8997 }
8998 8998
8999 8999
9000 // Check whether a non-function object is callable. 9000 // Check whether a non-function object is callable.
9001 THREADED_TEST(CallableObject) { 9001 THREADED_TEST(CallableObject) {
9002 v8::HandleScope scope;
9003 LocalContext context; 9002 LocalContext context;
9003 v8::HandleScope scope(context->GetIsolate());
9004 9004
9005 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 9005 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
9006 instance_template->SetCallAsFunctionHandler(call_as_function); 9006 instance_template->SetCallAsFunctionHandler(call_as_function);
9007 Local<Object> instance = instance_template->NewInstance(); 9007 Local<Object> instance = instance_template->NewInstance();
9008 v8::TryCatch try_catch; 9008 v8::TryCatch try_catch;
9009 9009
9010 CHECK(instance->IsCallable()); 9010 CHECK(instance->IsCallable());
9011 CHECK(!try_catch.HasCaught()); 9011 CHECK(!try_catch.HasCaught());
9012 } 9012 }
9013 9013
(...skipping 25 matching lines...) Expand all
9039 } 9039 }
9040 } 9040 }
9041 9041
9042 9042
9043 static int CountHandles() { 9043 static int CountHandles() {
9044 return v8::HandleScope::NumberOfHandles(); 9044 return v8::HandleScope::NumberOfHandles();
9045 } 9045 }
9046 9046
9047 9047
9048 static int Recurse(int depth, int iterations) { 9048 static int Recurse(int depth, int iterations) {
9049 v8::HandleScope scope; 9049 v8::HandleScope scope(v8::Isolate::GetCurrent());
9050 if (depth == 0) return CountHandles(); 9050 if (depth == 0) return CountHandles();
9051 for (int i = 0; i < iterations; i++) { 9051 for (int i = 0; i < iterations; i++) {
9052 Local<v8::Number> n(v8::Integer::New(42)); 9052 Local<v8::Number> n(v8::Integer::New(42));
9053 } 9053 }
9054 return Recurse(depth - 1, iterations); 9054 return Recurse(depth - 1, iterations);
9055 } 9055 }
9056 9056
9057 9057
9058 THREADED_TEST(HandleIteration) { 9058 THREADED_TEST(HandleIteration) {
9059 static const int kIterations = 500; 9059 static const int kIterations = 500;
9060 static const int kNesting = 200; 9060 static const int kNesting = 200;
9061 CHECK_EQ(0, CountHandles()); 9061 CHECK_EQ(0, CountHandles());
9062 { 9062 {
9063 v8::HandleScope scope1; 9063 v8::HandleScope scope1(v8::Isolate::GetCurrent());
9064 CHECK_EQ(0, CountHandles()); 9064 CHECK_EQ(0, CountHandles());
9065 for (int i = 0; i < kIterations; i++) { 9065 for (int i = 0; i < kIterations; i++) {
9066 Local<v8::Number> n(v8::Integer::New(42)); 9066 Local<v8::Number> n(v8::Integer::New(42));
9067 CHECK_EQ(i + 1, CountHandles()); 9067 CHECK_EQ(i + 1, CountHandles());
9068 } 9068 }
9069 9069
9070 CHECK_EQ(kIterations, CountHandles()); 9070 CHECK_EQ(kIterations, CountHandles());
9071 { 9071 {
9072 v8::HandleScope scope2; 9072 v8::HandleScope scope2(v8::Isolate::GetCurrent());
9073 for (int j = 0; j < kIterations; j++) { 9073 for (int j = 0; j < kIterations; j++) {
9074 Local<v8::Number> n(v8::Integer::New(42)); 9074 Local<v8::Number> n(v8::Integer::New(42));
9075 CHECK_EQ(j + 1 + kIterations, CountHandles()); 9075 CHECK_EQ(j + 1 + kIterations, CountHandles());
9076 } 9076 }
9077 } 9077 }
9078 CHECK_EQ(kIterations, CountHandles()); 9078 CHECK_EQ(kIterations, CountHandles());
9079 } 9079 }
9080 CHECK_EQ(0, CountHandles()); 9080 CHECK_EQ(0, CountHandles());
9081 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations)); 9081 CHECK_EQ(kNesting * kIterations, Recurse(kNesting, kIterations));
9082 } 9082 }
9083 9083
9084 9084
9085 static v8::Handle<Value> InterceptorHasOwnPropertyGetter( 9085 static v8::Handle<Value> InterceptorHasOwnPropertyGetter(
9086 Local<String> name, 9086 Local<String> name,
9087 const AccessorInfo& info) { 9087 const AccessorInfo& info) {
9088 ApiTestFuzzer::Fuzz(); 9088 ApiTestFuzzer::Fuzz();
9089 return v8::Handle<Value>(); 9089 return v8::Handle<Value>();
9090 } 9090 }
9091 9091
9092 9092
9093 THREADED_TEST(InterceptorHasOwnProperty) { 9093 THREADED_TEST(InterceptorHasOwnProperty) {
9094 v8::HandleScope scope;
9095 LocalContext context; 9094 LocalContext context;
9095 v8::HandleScope scope(context->GetIsolate());
9096 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9096 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9097 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9097 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9098 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); 9098 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
9099 Local<Function> function = fun_templ->GetFunction(); 9099 Local<Function> function = fun_templ->GetFunction();
9100 context->Global()->Set(v8_str("constructor"), function); 9100 context->Global()->Set(v8_str("constructor"), function);
9101 v8::Handle<Value> value = CompileRun( 9101 v8::Handle<Value> value = CompileRun(
9102 "var o = new constructor();" 9102 "var o = new constructor();"
9103 "o.hasOwnProperty('ostehaps');"); 9103 "o.hasOwnProperty('ostehaps');");
9104 CHECK_EQ(false, value->BooleanValue()); 9104 CHECK_EQ(false, value->BooleanValue());
9105 value = CompileRun( 9105 value = CompileRun(
(...skipping 10 matching lines...) Expand all
9116 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC( 9116 static v8::Handle<Value> InterceptorHasOwnPropertyGetterGC(
9117 Local<String> name, 9117 Local<String> name,
9118 const AccessorInfo& info) { 9118 const AccessorInfo& info) {
9119 ApiTestFuzzer::Fuzz(); 9119 ApiTestFuzzer::Fuzz();
9120 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 9120 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
9121 return v8::Handle<Value>(); 9121 return v8::Handle<Value>();
9122 } 9122 }
9123 9123
9124 9124
9125 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 9125 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
9126 v8::HandleScope scope;
9127 LocalContext context; 9126 LocalContext context;
9127 v8::HandleScope scope(context->GetIsolate());
9128 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 9128 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
9129 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 9129 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
9130 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); 9130 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
9131 Local<Function> function = fun_templ->GetFunction(); 9131 Local<Function> function = fun_templ->GetFunction();
9132 context->Global()->Set(v8_str("constructor"), function); 9132 context->Global()->Set(v8_str("constructor"), function);
9133 // Let's first make some stuff so we can be sure to get a good GC. 9133 // Let's first make some stuff so we can be sure to get a good GC.
9134 CompileRun( 9134 CompileRun(
9135 "function makestr(size) {" 9135 "function makestr(size) {"
9136 " switch (size) {" 9136 " switch (size) {"
9137 " case 1: return 'f';" 9137 " case 1: return 'f';"
(...skipping 13 matching lines...) Expand all
9151 } 9151 }
9152 9152
9153 9153
9154 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property, 9154 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property,
9155 const AccessorInfo& info); 9155 const AccessorInfo& info);
9156 9156
9157 9157
9158 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, 9158 static void CheckInterceptorLoadIC(NamedPropertyGetter getter,
9159 const char* source, 9159 const char* source,
9160 int expected) { 9160 int expected) {
9161 v8::HandleScope scope; 9161 v8::HandleScope scope(v8::Isolate::GetCurrent());
9162 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9162 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9163 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data")); 9163 templ->SetNamedPropertyHandler(getter, 0, 0, 0, 0, v8_str("data"));
9164 LocalContext context; 9164 LocalContext context;
9165 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9165 context->Global()->Set(v8_str("o"), templ->NewInstance());
9166 v8::Handle<Value> value = CompileRun(source); 9166 v8::Handle<Value> value = CompileRun(source);
9167 CHECK_EQ(expected, value->Int32Value()); 9167 CHECK_EQ(expected, value->Int32Value());
9168 } 9168 }
9169 9169
9170 9170
9171 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, 9171 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name,
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
9360 9360
9361 9361
9362 static void SetOnThis(Local<String> name, 9362 static void SetOnThis(Local<String> name,
9363 Local<Value> value, 9363 Local<Value> value,
9364 const AccessorInfo& info) { 9364 const AccessorInfo& info) {
9365 info.This()->ForceSet(name, value); 9365 info.This()->ForceSet(name, value);
9366 } 9366 }
9367 9367
9368 9368
9369 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) { 9369 THREADED_TEST(InterceptorLoadICWithCallbackOnHolder) {
9370 v8::HandleScope scope; 9370 v8::HandleScope scope(v8::Isolate::GetCurrent());
9371 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9371 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9372 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9372 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9373 templ->SetAccessor(v8_str("y"), Return239); 9373 templ->SetAccessor(v8_str("y"), Return239);
9374 LocalContext context; 9374 LocalContext context;
9375 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9375 context->Global()->Set(v8_str("o"), templ->NewInstance());
9376 9376
9377 // Check the case when receiver and interceptor's holder 9377 // Check the case when receiver and interceptor's holder
9378 // are the same objects. 9378 // are the same objects.
9379 v8::Handle<Value> value = CompileRun( 9379 v8::Handle<Value> value = CompileRun(
9380 "var result = 0;" 9380 "var result = 0;"
9381 "for (var i = 0; i < 7; i++) {" 9381 "for (var i = 0; i < 7; i++) {"
9382 " result = o.y;" 9382 " result = o.y;"
9383 "}"); 9383 "}");
9384 CHECK_EQ(239, value->Int32Value()); 9384 CHECK_EQ(239, value->Int32Value());
9385 9385
9386 // Check the case when interceptor's holder is in proto chain 9386 // Check the case when interceptor's holder is in proto chain
9387 // of receiver. 9387 // of receiver.
9388 value = CompileRun( 9388 value = CompileRun(
9389 "r = { __proto__: o };" 9389 "r = { __proto__: o };"
9390 "var result = 0;" 9390 "var result = 0;"
9391 "for (var i = 0; i < 7; i++) {" 9391 "for (var i = 0; i < 7; i++) {"
9392 " result = r.y;" 9392 " result = r.y;"
9393 "}"); 9393 "}");
9394 CHECK_EQ(239, value->Int32Value()); 9394 CHECK_EQ(239, value->Int32Value());
9395 } 9395 }
9396 9396
9397 9397
9398 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) { 9398 THREADED_TEST(InterceptorLoadICWithCallbackOnProto) {
9399 v8::HandleScope scope; 9399 v8::HandleScope scope(v8::Isolate::GetCurrent());
9400 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9400 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9401 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9401 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9402 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9402 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9403 templ_p->SetAccessor(v8_str("y"), Return239); 9403 templ_p->SetAccessor(v8_str("y"), Return239);
9404 9404
9405 LocalContext context; 9405 LocalContext context;
9406 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9406 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9407 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9407 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9408 9408
9409 // Check the case when receiver and interceptor's holder 9409 // Check the case when receiver and interceptor's holder
(...skipping 12 matching lines...) Expand all
9422 "r = { __proto__: o };" 9422 "r = { __proto__: o };"
9423 "var result = 0;" 9423 "var result = 0;"
9424 "for (var i = 0; i < 7; i++) {" 9424 "for (var i = 0; i < 7; i++) {"
9425 " result = r.x + r.y;" 9425 " result = r.x + r.y;"
9426 "}"); 9426 "}");
9427 CHECK_EQ(239 + 42, value->Int32Value()); 9427 CHECK_EQ(239 + 42, value->Int32Value());
9428 } 9428 }
9429 9429
9430 9430
9431 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) { 9431 THREADED_TEST(InterceptorLoadICForCallbackWithOverride) {
9432 v8::HandleScope scope; 9432 v8::HandleScope scope(v8::Isolate::GetCurrent());
9433 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9433 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9434 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9434 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9435 templ->SetAccessor(v8_str("y"), Return239); 9435 templ->SetAccessor(v8_str("y"), Return239);
9436 9436
9437 LocalContext context; 9437 LocalContext context;
9438 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9438 context->Global()->Set(v8_str("o"), templ->NewInstance());
9439 9439
9440 v8::Handle<Value> value = CompileRun( 9440 v8::Handle<Value> value = CompileRun(
9441 "fst = new Object(); fst.__proto__ = o;" 9441 "fst = new Object(); fst.__proto__ = o;"
9442 "snd = new Object(); snd.__proto__ = fst;" 9442 "snd = new Object(); snd.__proto__ = fst;"
9443 "var result1 = 0;" 9443 "var result1 = 0;"
9444 "for (var i = 0; i < 7; i++) {" 9444 "for (var i = 0; i < 7; i++) {"
9445 " result1 = snd.x;" 9445 " result1 = snd.x;"
9446 "}" 9446 "}"
9447 "fst.x = 239;" 9447 "fst.x = 239;"
9448 "var result = 0;" 9448 "var result = 0;"
9449 "for (var i = 0; i < 7; i++) {" 9449 "for (var i = 0; i < 7; i++) {"
9450 " result = snd.x;" 9450 " result = snd.x;"
9451 "}" 9451 "}"
9452 "result + result1"); 9452 "result + result1");
9453 CHECK_EQ(239 + 42, value->Int32Value()); 9453 CHECK_EQ(239 + 42, value->Int32Value());
9454 } 9454 }
9455 9455
9456 9456
9457 // Test the case when we stored callback into 9457 // Test the case when we stored callback into
9458 // a stub, but interceptor produced value on its own. 9458 // a stub, but interceptor produced value on its own.
9459 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) { 9459 THREADED_TEST(InterceptorLoadICCallbackNotNeeded) {
9460 v8::HandleScope scope; 9460 v8::HandleScope scope(v8::Isolate::GetCurrent());
9461 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9461 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9462 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9462 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9463 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9463 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9464 templ_p->SetAccessor(v8_str("y"), Return239); 9464 templ_p->SetAccessor(v8_str("y"), Return239);
9465 9465
9466 LocalContext context; 9466 LocalContext context;
9467 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9467 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9468 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9468 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9469 9469
9470 v8::Handle<Value> value = CompileRun( 9470 v8::Handle<Value> value = CompileRun(
9471 "o.__proto__ = p;" 9471 "o.__proto__ = p;"
9472 "for (var i = 0; i < 7; i++) {" 9472 "for (var i = 0; i < 7; i++) {"
9473 " o.x;" 9473 " o.x;"
9474 // Now it should be ICed and keep a reference to x defined on p 9474 // Now it should be ICed and keep a reference to x defined on p
9475 "}" 9475 "}"
9476 "var result = 0;" 9476 "var result = 0;"
9477 "for (var i = 0; i < 7; i++) {" 9477 "for (var i = 0; i < 7; i++) {"
9478 " result += o.x;" 9478 " result += o.x;"
9479 "}" 9479 "}"
9480 "result"); 9480 "result");
9481 CHECK_EQ(42 * 7, value->Int32Value()); 9481 CHECK_EQ(42 * 7, value->Int32Value());
9482 } 9482 }
9483 9483
9484 9484
9485 // Test the case when we stored callback into 9485 // Test the case when we stored callback into
9486 // a stub, but it got invalidated later on. 9486 // a stub, but it got invalidated later on.
9487 THREADED_TEST(InterceptorLoadICInvalidatedCallback) { 9487 THREADED_TEST(InterceptorLoadICInvalidatedCallback) {
9488 v8::HandleScope scope; 9488 v8::HandleScope scope(v8::Isolate::GetCurrent());
9489 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9489 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9490 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9490 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9491 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9491 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9492 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 9492 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis);
9493 9493
9494 LocalContext context; 9494 LocalContext context;
9495 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9495 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9496 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9496 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9497 9497
9498 v8::Handle<Value> value = CompileRun( 9498 v8::Handle<Value> value = CompileRun(
(...skipping 11 matching lines...) Expand all
9510 "}" 9510 "}"
9511 "result"); 9511 "result");
9512 CHECK_EQ(42 * 10, value->Int32Value()); 9512 CHECK_EQ(42 * 10, value->Int32Value());
9513 } 9513 }
9514 9514
9515 9515
9516 // Test the case when we stored callback into 9516 // Test the case when we stored callback into
9517 // a stub, but it got invalidated later on due to override on 9517 // a stub, but it got invalidated later on due to override on
9518 // global object which is between interceptor and callbacks' holders. 9518 // global object which is between interceptor and callbacks' holders.
9519 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) { 9519 THREADED_TEST(InterceptorLoadICInvalidatedCallbackViaGlobal) {
9520 v8::HandleScope scope; 9520 v8::HandleScope scope(v8::Isolate::GetCurrent());
9521 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9521 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9522 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9522 templ_o->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9523 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New(); 9523 v8::Handle<v8::ObjectTemplate> templ_p = ObjectTemplate::New();
9524 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis); 9524 templ_p->SetAccessor(v8_str("y"), Return239, SetOnThis);
9525 9525
9526 LocalContext context; 9526 LocalContext context;
9527 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9527 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9528 context->Global()->Set(v8_str("p"), templ_p->NewInstance()); 9528 context->Global()->Set(v8_str("p"), templ_p->NewInstance());
9529 9529
9530 v8::Handle<Value> value = CompileRun( 9530 v8::Handle<Value> value = CompileRun(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
9562 static v8::Handle<Value> InterceptorStoreICSetter( 9562 static v8::Handle<Value> InterceptorStoreICSetter(
9563 Local<String> key, Local<Value> value, const AccessorInfo&) { 9563 Local<String> key, Local<Value> value, const AccessorInfo&) {
9564 CHECK(v8_str("x")->Equals(key)); 9564 CHECK(v8_str("x")->Equals(key));
9565 CHECK_EQ(42, value->Int32Value()); 9565 CHECK_EQ(42, value->Int32Value());
9566 return value; 9566 return value;
9567 } 9567 }
9568 9568
9569 9569
9570 // This test should hit the store IC for the interceptor case. 9570 // This test should hit the store IC for the interceptor case.
9571 THREADED_TEST(InterceptorStoreIC) { 9571 THREADED_TEST(InterceptorStoreIC) {
9572 v8::HandleScope scope; 9572 v8::HandleScope scope(v8::Isolate::GetCurrent());
9573 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9573 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9574 templ->SetNamedPropertyHandler(InterceptorLoadICGetter, 9574 templ->SetNamedPropertyHandler(InterceptorLoadICGetter,
9575 InterceptorStoreICSetter, 9575 InterceptorStoreICSetter,
9576 0, 0, 0, v8_str("data")); 9576 0, 0, 0, v8_str("data"));
9577 LocalContext context; 9577 LocalContext context;
9578 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9578 context->Global()->Set(v8_str("o"), templ->NewInstance());
9579 CompileRun( 9579 CompileRun(
9580 "for (var i = 0; i < 1000; i++) {" 9580 "for (var i = 0; i < 1000; i++) {"
9581 " o.x = 42;" 9581 " o.x = 42;"
9582 "}"); 9582 "}");
9583 } 9583 }
9584 9584
9585 9585
9586 THREADED_TEST(InterceptorStoreICWithNoSetter) { 9586 THREADED_TEST(InterceptorStoreICWithNoSetter) {
9587 v8::HandleScope scope; 9587 v8::HandleScope scope(v8::Isolate::GetCurrent());
9588 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9588 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9589 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); 9589 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter);
9590 LocalContext context; 9590 LocalContext context;
9591 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9591 context->Global()->Set(v8_str("o"), templ->NewInstance());
9592 v8::Handle<Value> value = CompileRun( 9592 v8::Handle<Value> value = CompileRun(
9593 "for (var i = 0; i < 1000; i++) {" 9593 "for (var i = 0; i < 1000; i++) {"
9594 " o.y = 239;" 9594 " o.y = 239;"
9595 "}" 9595 "}"
9596 "42 + o.y"); 9596 "42 + o.y");
9597 CHECK_EQ(239 + 42, value->Int32Value()); 9597 CHECK_EQ(239 + 42, value->Int32Value());
9598 } 9598 }
9599 9599
9600 9600
9601 9601
9602 9602
9603 v8::Handle<Value> call_ic_function; 9603 v8::Handle<Value> call_ic_function;
9604 v8::Handle<Value> call_ic_function2; 9604 v8::Handle<Value> call_ic_function2;
9605 v8::Handle<Value> call_ic_function3; 9605 v8::Handle<Value> call_ic_function3;
9606 9606
9607 static v8::Handle<Value> InterceptorCallICGetter(Local<String> name, 9607 static v8::Handle<Value> InterceptorCallICGetter(Local<String> name,
9608 const AccessorInfo& info) { 9608 const AccessorInfo& info) {
9609 ApiTestFuzzer::Fuzz(); 9609 ApiTestFuzzer::Fuzz();
9610 CHECK(v8_str("x")->Equals(name)); 9610 CHECK(v8_str("x")->Equals(name));
9611 return call_ic_function; 9611 return call_ic_function;
9612 } 9612 }
9613 9613
9614 9614
9615 // This test should hit the call IC for the interceptor case. 9615 // This test should hit the call IC for the interceptor case.
9616 THREADED_TEST(InterceptorCallIC) { 9616 THREADED_TEST(InterceptorCallIC) {
9617 v8::HandleScope scope; 9617 v8::HandleScope scope(v8::Isolate::GetCurrent());
9618 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9618 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9619 templ->SetNamedPropertyHandler(InterceptorCallICGetter); 9619 templ->SetNamedPropertyHandler(InterceptorCallICGetter);
9620 LocalContext context; 9620 LocalContext context;
9621 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9621 context->Global()->Set(v8_str("o"), templ->NewInstance());
9622 call_ic_function = 9622 call_ic_function =
9623 v8_compile("function f(x) { return x + 1; }; f")->Run(); 9623 v8_compile("function f(x) { return x + 1; }; f")->Run();
9624 v8::Handle<Value> value = CompileRun( 9624 v8::Handle<Value> value = CompileRun(
9625 "var result = 0;" 9625 "var result = 0;"
9626 "for (var i = 0; i < 1000; i++) {" 9626 "for (var i = 0; i < 1000; i++) {"
9627 " result = o.x(41);" 9627 " result = o.x(41);"
9628 "}"); 9628 "}");
9629 CHECK_EQ(42, value->Int32Value()); 9629 CHECK_EQ(42, value->Int32Value());
9630 } 9630 }
9631 9631
9632 9632
9633 // This test checks that if interceptor doesn't provide 9633 // This test checks that if interceptor doesn't provide
9634 // a value, we can fetch regular value. 9634 // a value, we can fetch regular value.
9635 THREADED_TEST(InterceptorCallICSeesOthers) { 9635 THREADED_TEST(InterceptorCallICSeesOthers) {
9636 v8::HandleScope scope; 9636 v8::HandleScope scope(v8::Isolate::GetCurrent());
9637 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9637 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9638 templ->SetNamedPropertyHandler(NoBlockGetterX); 9638 templ->SetNamedPropertyHandler(NoBlockGetterX);
9639 LocalContext context; 9639 LocalContext context;
9640 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9640 context->Global()->Set(v8_str("o"), templ->NewInstance());
9641 v8::Handle<Value> value = CompileRun( 9641 v8::Handle<Value> value = CompileRun(
9642 "o.x = function f(x) { return x + 1; };" 9642 "o.x = function f(x) { return x + 1; };"
9643 "var result = 0;" 9643 "var result = 0;"
9644 "for (var i = 0; i < 7; i++) {" 9644 "for (var i = 0; i < 7; i++) {"
9645 " result = o.x(41);" 9645 " result = o.x(41);"
9646 "}"); 9646 "}");
9647 CHECK_EQ(42, value->Int32Value()); 9647 CHECK_EQ(42, value->Int32Value());
9648 } 9648 }
9649 9649
9650 9650
9651 static v8::Handle<Value> call_ic_function4; 9651 static v8::Handle<Value> call_ic_function4;
9652 static v8::Handle<Value> InterceptorCallICGetter4(Local<String> name, 9652 static v8::Handle<Value> InterceptorCallICGetter4(Local<String> name,
9653 const AccessorInfo& info) { 9653 const AccessorInfo& info) {
9654 ApiTestFuzzer::Fuzz(); 9654 ApiTestFuzzer::Fuzz();
9655 CHECK(v8_str("x")->Equals(name)); 9655 CHECK(v8_str("x")->Equals(name));
9656 return call_ic_function4; 9656 return call_ic_function4;
9657 } 9657 }
9658 9658
9659 9659
9660 // This test checks that if interceptor provides a function, 9660 // This test checks that if interceptor provides a function,
9661 // even if we cached shadowed variant, interceptor's function 9661 // even if we cached shadowed variant, interceptor's function
9662 // is invoked 9662 // is invoked
9663 THREADED_TEST(InterceptorCallICCacheableNotNeeded) { 9663 THREADED_TEST(InterceptorCallICCacheableNotNeeded) {
9664 v8::HandleScope scope; 9664 v8::HandleScope scope(v8::Isolate::GetCurrent());
9665 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9665 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9666 templ->SetNamedPropertyHandler(InterceptorCallICGetter4); 9666 templ->SetNamedPropertyHandler(InterceptorCallICGetter4);
9667 LocalContext context; 9667 LocalContext context;
9668 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9668 context->Global()->Set(v8_str("o"), templ->NewInstance());
9669 call_ic_function4 = 9669 call_ic_function4 =
9670 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9670 v8_compile("function f(x) { return x - 1; }; f")->Run();
9671 v8::Handle<Value> value = CompileRun( 9671 v8::Handle<Value> value = CompileRun(
9672 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };" 9672 "Object.getPrototypeOf(o).x = function(x) { return x + 1; };"
9673 "var result = 0;" 9673 "var result = 0;"
9674 "for (var i = 0; i < 1000; i++) {" 9674 "for (var i = 0; i < 1000; i++) {"
9675 " result = o.x(42);" 9675 " result = o.x(42);"
9676 "}"); 9676 "}");
9677 CHECK_EQ(41, value->Int32Value()); 9677 CHECK_EQ(41, value->Int32Value());
9678 } 9678 }
9679 9679
9680 9680
9681 // Test the case when we stored cacheable lookup into 9681 // Test the case when we stored cacheable lookup into
9682 // a stub, but it got invalidated later on 9682 // a stub, but it got invalidated later on
9683 THREADED_TEST(InterceptorCallICInvalidatedCacheable) { 9683 THREADED_TEST(InterceptorCallICInvalidatedCacheable) {
9684 v8::HandleScope scope; 9684 v8::HandleScope scope(v8::Isolate::GetCurrent());
9685 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9685 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9686 templ->SetNamedPropertyHandler(NoBlockGetterX); 9686 templ->SetNamedPropertyHandler(NoBlockGetterX);
9687 LocalContext context; 9687 LocalContext context;
9688 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9688 context->Global()->Set(v8_str("o"), templ->NewInstance());
9689 v8::Handle<Value> value = CompileRun( 9689 v8::Handle<Value> value = CompileRun(
9690 "proto1 = new Object();" 9690 "proto1 = new Object();"
9691 "proto2 = new Object();" 9691 "proto2 = new Object();"
9692 "o.__proto__ = proto1;" 9692 "o.__proto__ = proto1;"
9693 "proto1.__proto__ = proto2;" 9693 "proto1.__proto__ = proto2;"
9694 "proto2.y = function(x) { return x + 1; };" 9694 "proto2.y = function(x) { return x + 1; };"
9695 // Invoke it many times to compile a stub 9695 // Invoke it many times to compile a stub
9696 "for (var i = 0; i < 7; i++) {" 9696 "for (var i = 0; i < 7; i++) {"
9697 " o.y(42);" 9697 " o.y(42);"
9698 "}" 9698 "}"
9699 "proto1.y = function(x) { return x - 1; };" 9699 "proto1.y = function(x) { return x - 1; };"
9700 "var result = 0;" 9700 "var result = 0;"
9701 "for (var i = 0; i < 7; i++) {" 9701 "for (var i = 0; i < 7; i++) {"
9702 " result += o.y(42);" 9702 " result += o.y(42);"
9703 "}"); 9703 "}");
9704 CHECK_EQ(41 * 7, value->Int32Value()); 9704 CHECK_EQ(41 * 7, value->Int32Value());
9705 } 9705 }
9706 9706
9707 9707
9708 // This test checks that if interceptor doesn't provide a function, 9708 // This test checks that if interceptor doesn't provide a function,
9709 // cached constant function is used 9709 // cached constant function is used
9710 THREADED_TEST(InterceptorCallICConstantFunctionUsed) { 9710 THREADED_TEST(InterceptorCallICConstantFunctionUsed) {
9711 v8::HandleScope scope; 9711 v8::HandleScope scope(v8::Isolate::GetCurrent());
9712 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9712 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9713 templ->SetNamedPropertyHandler(NoBlockGetterX); 9713 templ->SetNamedPropertyHandler(NoBlockGetterX);
9714 LocalContext context; 9714 LocalContext context;
9715 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9715 context->Global()->Set(v8_str("o"), templ->NewInstance());
9716 v8::Handle<Value> value = CompileRun( 9716 v8::Handle<Value> value = CompileRun(
9717 "function inc(x) { return x + 1; };" 9717 "function inc(x) { return x + 1; };"
9718 "inc(1);" 9718 "inc(1);"
9719 "o.x = inc;" 9719 "o.x = inc;"
9720 "var result = 0;" 9720 "var result = 0;"
9721 "for (var i = 0; i < 1000; i++) {" 9721 "for (var i = 0; i < 1000; i++) {"
(...skipping 11 matching lines...) Expand all
9733 return call_ic_function5; 9733 return call_ic_function5;
9734 else 9734 else
9735 return Local<Value>(); 9735 return Local<Value>();
9736 } 9736 }
9737 9737
9738 9738
9739 // This test checks that if interceptor provides a function, 9739 // This test checks that if interceptor provides a function,
9740 // even if we cached constant function, interceptor's function 9740 // even if we cached constant function, interceptor's function
9741 // is invoked 9741 // is invoked
9742 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) { 9742 THREADED_TEST(InterceptorCallICConstantFunctionNotNeeded) {
9743 v8::HandleScope scope; 9743 v8::HandleScope scope(v8::Isolate::GetCurrent());
9744 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9744 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9745 templ->SetNamedPropertyHandler(InterceptorCallICGetter5); 9745 templ->SetNamedPropertyHandler(InterceptorCallICGetter5);
9746 LocalContext context; 9746 LocalContext context;
9747 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9747 context->Global()->Set(v8_str("o"), templ->NewInstance());
9748 call_ic_function5 = 9748 call_ic_function5 =
9749 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9749 v8_compile("function f(x) { return x - 1; }; f")->Run();
9750 v8::Handle<Value> value = CompileRun( 9750 v8::Handle<Value> value = CompileRun(
9751 "function inc(x) { return x + 1; };" 9751 "function inc(x) { return x + 1; };"
9752 "inc(1);" 9752 "inc(1);"
9753 "o.x = inc;" 9753 "o.x = inc;"
(...skipping 13 matching lines...) Expand all
9767 return call_ic_function6; 9767 return call_ic_function6;
9768 else 9768 else
9769 return Local<Value>(); 9769 return Local<Value>();
9770 } 9770 }
9771 9771
9772 9772
9773 // Same test as above, except the code is wrapped in a function 9773 // Same test as above, except the code is wrapped in a function
9774 // to test the optimized compiler. 9774 // to test the optimized compiler.
9775 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) { 9775 THREADED_TEST(InterceptorCallICConstantFunctionNotNeededWrapped) {
9776 i::FLAG_allow_natives_syntax = true; 9776 i::FLAG_allow_natives_syntax = true;
9777 v8::HandleScope scope; 9777 v8::HandleScope scope(v8::Isolate::GetCurrent());
9778 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9778 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9779 templ->SetNamedPropertyHandler(InterceptorCallICGetter6); 9779 templ->SetNamedPropertyHandler(InterceptorCallICGetter6);
9780 LocalContext context; 9780 LocalContext context;
9781 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9781 context->Global()->Set(v8_str("o"), templ->NewInstance());
9782 call_ic_function6 = 9782 call_ic_function6 =
9783 v8_compile("function f(x) { return x - 1; }; f")->Run(); 9783 v8_compile("function f(x) { return x - 1; }; f")->Run();
9784 v8::Handle<Value> value = CompileRun( 9784 v8::Handle<Value> value = CompileRun(
9785 "function inc(x) { return x + 1; };" 9785 "function inc(x) { return x + 1; };"
9786 "inc(1);" 9786 "inc(1);"
9787 "o.x = inc;" 9787 "o.x = inc;"
9788 "function test() {" 9788 "function test() {"
9789 " var result = 0;" 9789 " var result = 0;"
9790 " for (var i = 0; i < 1000; i++) {" 9790 " for (var i = 0; i < 1000; i++) {"
9791 " result = o.x(42);" 9791 " result = o.x(42);"
9792 " }" 9792 " }"
9793 " return result;" 9793 " return result;"
9794 "};" 9794 "};"
9795 "test();" 9795 "test();"
9796 "test();" 9796 "test();"
9797 "test();" 9797 "test();"
9798 "%OptimizeFunctionOnNextCall(test);" 9798 "%OptimizeFunctionOnNextCall(test);"
9799 "test()"); 9799 "test()");
9800 CHECK_EQ(41, value->Int32Value()); 9800 CHECK_EQ(41, value->Int32Value());
9801 } 9801 }
9802 9802
9803 9803
9804 // Test the case when we stored constant function into 9804 // Test the case when we stored constant function into
9805 // a stub, but it got invalidated later on 9805 // a stub, but it got invalidated later on
9806 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) { 9806 THREADED_TEST(InterceptorCallICInvalidatedConstantFunction) {
9807 v8::HandleScope scope; 9807 v8::HandleScope scope(v8::Isolate::GetCurrent());
9808 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9808 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9809 templ->SetNamedPropertyHandler(NoBlockGetterX); 9809 templ->SetNamedPropertyHandler(NoBlockGetterX);
9810 LocalContext context; 9810 LocalContext context;
9811 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9811 context->Global()->Set(v8_str("o"), templ->NewInstance());
9812 v8::Handle<Value> value = CompileRun( 9812 v8::Handle<Value> value = CompileRun(
9813 "function inc(x) { return x + 1; };" 9813 "function inc(x) { return x + 1; };"
9814 "inc(1);" 9814 "inc(1);"
9815 "proto1 = new Object();" 9815 "proto1 = new Object();"
9816 "proto2 = new Object();" 9816 "proto2 = new Object();"
9817 "o.__proto__ = proto1;" 9817 "o.__proto__ = proto1;"
9818 "proto1.__proto__ = proto2;" 9818 "proto1.__proto__ = proto2;"
9819 "proto2.y = inc;" 9819 "proto2.y = inc;"
9820 // Invoke it many times to compile a stub 9820 // Invoke it many times to compile a stub
9821 "for (var i = 0; i < 7; i++) {" 9821 "for (var i = 0; i < 7; i++) {"
9822 " o.y(42);" 9822 " o.y(42);"
9823 "}" 9823 "}"
9824 "proto1.y = function(x) { return x - 1; };" 9824 "proto1.y = function(x) { return x - 1; };"
9825 "var result = 0;" 9825 "var result = 0;"
9826 "for (var i = 0; i < 7; i++) {" 9826 "for (var i = 0; i < 7; i++) {"
9827 " result += o.y(42);" 9827 " result += o.y(42);"
9828 "}"); 9828 "}");
9829 CHECK_EQ(41 * 7, value->Int32Value()); 9829 CHECK_EQ(41 * 7, value->Int32Value());
9830 } 9830 }
9831 9831
9832 9832
9833 // Test the case when we stored constant function into 9833 // Test the case when we stored constant function into
9834 // a stub, but it got invalidated later on due to override on 9834 // a stub, but it got invalidated later on due to override on
9835 // global object which is between interceptor and constant function' holders. 9835 // global object which is between interceptor and constant function' holders.
9836 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) { 9836 THREADED_TEST(InterceptorCallICInvalidatedConstantFunctionViaGlobal) {
9837 v8::HandleScope scope; 9837 v8::HandleScope scope(v8::Isolate::GetCurrent());
9838 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 9838 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
9839 templ->SetNamedPropertyHandler(NoBlockGetterX); 9839 templ->SetNamedPropertyHandler(NoBlockGetterX);
9840 LocalContext context; 9840 LocalContext context;
9841 context->Global()->Set(v8_str("o"), templ->NewInstance()); 9841 context->Global()->Set(v8_str("o"), templ->NewInstance());
9842 v8::Handle<Value> value = CompileRun( 9842 v8::Handle<Value> value = CompileRun(
9843 "function inc(x) { return x + 1; };" 9843 "function inc(x) { return x + 1; };"
9844 "inc(1);" 9844 "inc(1);"
9845 "o.__proto__ = this;" 9845 "o.__proto__ = this;"
9846 "this.__proto__.y = inc;" 9846 "this.__proto__.y = inc;"
9847 // Invoke it many times to compile a stub 9847 // Invoke it many times to compile a stub
9848 "for (var i = 0; i < 7; i++) {" 9848 "for (var i = 0; i < 7; i++) {"
9849 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);" 9849 " if (o.y(42) != 43) throw 'oops: ' + o.y(42);"
9850 "}" 9850 "}"
9851 "this.y = function(x) { return x - 1; };" 9851 "this.y = function(x) { return x - 1; };"
9852 "var result = 0;" 9852 "var result = 0;"
9853 "for (var i = 0; i < 7; i++) {" 9853 "for (var i = 0; i < 7; i++) {"
9854 " result += o.y(42);" 9854 " result += o.y(42);"
9855 "}"); 9855 "}");
9856 CHECK_EQ(41 * 7, value->Int32Value()); 9856 CHECK_EQ(41 * 7, value->Int32Value());
9857 } 9857 }
9858 9858
9859 9859
9860 // Test the case when actual function to call sits on global object. 9860 // Test the case when actual function to call sits on global object.
9861 THREADED_TEST(InterceptorCallICCachedFromGlobal) { 9861 THREADED_TEST(InterceptorCallICCachedFromGlobal) {
9862 v8::HandleScope scope; 9862 v8::HandleScope scope(v8::Isolate::GetCurrent());
9863 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 9863 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
9864 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 9864 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
9865 9865
9866 LocalContext context; 9866 LocalContext context;
9867 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 9867 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
9868 9868
9869 v8::Handle<Value> value = CompileRun( 9869 v8::Handle<Value> value = CompileRun(
9870 "try {" 9870 "try {"
9871 " o.__proto__ = this;" 9871 " o.__proto__ = this;"
9872 " for (var i = 0; i < 10; i++) {" 9872 " for (var i = 0; i < 10; i++) {"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
9936 if (count++ % 3 == 0) { 9936 if (count++ % 3 == 0) {
9937 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 9937 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
9938 // This should move the stub 9938 // This should move the stub
9939 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 9939 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
9940 } 9940 }
9941 return v8::Handle<v8::Value>(); 9941 return v8::Handle<v8::Value>();
9942 } 9942 }
9943 9943
9944 9944
9945 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 9945 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
9946 v8::HandleScope scope;
9947 LocalContext context; 9946 LocalContext context;
9947 v8::HandleScope scope(context->GetIsolate());
9948 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 9948 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
9949 nativeobject_templ->Set("callback", 9949 nativeobject_templ->Set("callback",
9950 v8::FunctionTemplate::New(DirectApiCallback)); 9950 v8::FunctionTemplate::New(DirectApiCallback));
9951 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 9951 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
9952 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 9952 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
9953 // call the api function multiple times to ensure direct call stub creation. 9953 // call the api function multiple times to ensure direct call stub creation.
9954 CompileRun( 9954 CompileRun(
9955 "function f() {" 9955 "function f() {"
9956 " for (var i = 1; i <= 30; i++) {" 9956 " for (var i = 1; i <= 30; i++) {"
9957 " nativeobject.callback();" 9957 " nativeobject.callback();"
9958 " }" 9958 " }"
9959 "}" 9959 "}"
9960 "f();"); 9960 "f();");
9961 } 9961 }
9962 9962
9963 9963
9964 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) { 9964 v8::Handle<v8::Value> ThrowingDirectApiCallback(const v8::Arguments& args) {
9965 return v8::ThrowException(v8_str("g")); 9965 return v8::ThrowException(v8_str("g"));
9966 } 9966 }
9967 9967
9968 9968
9969 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 9969 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
9970 v8::HandleScope scope;
9971 LocalContext context; 9970 LocalContext context;
9971 v8::HandleScope scope(context->GetIsolate());
9972 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 9972 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
9973 nativeobject_templ->Set("callback", 9973 nativeobject_templ->Set("callback",
9974 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); 9974 v8::FunctionTemplate::New(ThrowingDirectApiCallback));
9975 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 9975 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
9976 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 9976 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
9977 // call the api function multiple times to ensure direct call stub creation. 9977 // call the api function multiple times to ensure direct call stub creation.
9978 v8::Handle<Value> result = CompileRun( 9978 v8::Handle<Value> result = CompileRun(
9979 "var result = '';" 9979 "var result = '';"
9980 "function f() {" 9980 "function f() {"
9981 " for (var i = 1; i <= 5; i++) {" 9981 " for (var i = 1; i <= 5; i++) {"
9982 " try { nativeobject.callback(); } catch (e) { result += e; }" 9982 " try { nativeobject.callback(); } catch (e) { result += e; }"
9983 " }" 9983 " }"
9984 "}" 9984 "}"
9985 "f(); result;"); 9985 "f(); result;");
9986 CHECK_EQ(v8_str("ggggg"), result); 9986 CHECK_EQ(v8_str("ggggg"), result);
9987 } 9987 }
9988 9988
9989 9989
9990 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name, 9990 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name,
9991 const v8::AccessorInfo& info) { 9991 const v8::AccessorInfo& info) {
9992 if (++p_getter_count % 3 == 0) { 9992 if (++p_getter_count % 3 == 0) {
9993 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 9993 HEAP->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
9994 GenerateSomeGarbage(); 9994 GenerateSomeGarbage();
9995 } 9995 }
9996 return v8::Handle<v8::Value>(); 9996 return v8::Handle<v8::Value>();
9997 } 9997 }
9998 9998
9999 9999
10000 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 10000 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
10001 v8::HandleScope scope;
10002 LocalContext context; 10001 LocalContext context;
10002 v8::HandleScope scope(context->GetIsolate());
10003 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10003 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10004 obj->SetAccessor(v8_str("p1"), DirectGetterCallback); 10004 obj->SetAccessor(v8_str("p1"), DirectGetterCallback);
10005 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10005 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10006 p_getter_count = 0; 10006 p_getter_count = 0;
10007 CompileRun( 10007 CompileRun(
10008 "function f() {" 10008 "function f() {"
10009 " for (var i = 0; i < 30; i++) o1.p1;" 10009 " for (var i = 0; i < 30; i++) o1.p1;"
10010 "}" 10010 "}"
10011 "f();"); 10011 "f();");
10012 CHECK_EQ(30, p_getter_count); 10012 CHECK_EQ(30, p_getter_count);
10013 } 10013 }
10014 10014
10015 10015
10016 v8::Handle<v8::Value> ThrowingDirectGetterCallback( 10016 v8::Handle<v8::Value> ThrowingDirectGetterCallback(
10017 Local<String> name, const v8::AccessorInfo& info) { 10017 Local<String> name, const v8::AccessorInfo& info) {
10018 return v8::ThrowException(v8_str("g")); 10018 return v8::ThrowException(v8_str("g"));
10019 } 10019 }
10020 10020
10021 10021
10022 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 10022 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
10023 v8::HandleScope scope;
10024 LocalContext context; 10023 LocalContext context;
10024 v8::HandleScope scope(context->GetIsolate());
10025 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); 10025 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
10026 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); 10026 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
10027 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 10027 context->Global()->Set(v8_str("o1"), obj->NewInstance());
10028 v8::Handle<Value> result = CompileRun( 10028 v8::Handle<Value> result = CompileRun(
10029 "var result = '';" 10029 "var result = '';"
10030 "for (var i = 0; i < 5; i++) {" 10030 "for (var i = 0; i < 5; i++) {"
10031 " try { o1.p1; } catch (e) { result += e; }" 10031 " try { o1.p1; } catch (e) { result += e; }"
10032 "}" 10032 "}"
10033 "result;"); 10033 "result;");
10034 CHECK_EQ(v8_str("ggggg"), result); 10034 CHECK_EQ(v8_str("ggggg"), result);
10035 } 10035 }
10036 10036
10037 10037
10038 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { 10038 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
10039 int interceptor_call_count = 0; 10039 int interceptor_call_count = 0;
10040 v8::HandleScope scope; 10040 v8::HandleScope scope(v8::Isolate::GetCurrent());
10041 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10041 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10042 v8::Handle<v8::FunctionTemplate> method_templ = 10042 v8::Handle<v8::FunctionTemplate> method_templ =
10043 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 10043 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
10044 v8_str("method_data"), 10044 v8_str("method_data"),
10045 v8::Handle<v8::Signature>()); 10045 v8::Handle<v8::Signature>());
10046 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10046 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10047 proto_templ->Set(v8_str("method"), method_templ); 10047 proto_templ->Set(v8_str("method"), method_templ);
10048 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10048 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10049 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10049 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
10050 NULL, NULL, NULL, NULL, 10050 NULL, NULL, NULL, NULL,
10051 v8::External::New(&interceptor_call_count)); 10051 v8::External::New(&interceptor_call_count));
10052 LocalContext context; 10052 LocalContext context;
10053 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10053 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10054 GenerateSomeGarbage(); 10054 GenerateSomeGarbage();
10055 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10055 context->Global()->Set(v8_str("o"), fun->NewInstance());
10056 CompileRun( 10056 CompileRun(
10057 "var result = 0;" 10057 "var result = 0;"
10058 "for (var i = 0; i < 100; i++) {" 10058 "for (var i = 0; i < 100; i++) {"
10059 " result = o.method(41);" 10059 " result = o.method(41);"
10060 "}"); 10060 "}");
10061 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10061 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10062 CHECK_EQ(100, interceptor_call_count); 10062 CHECK_EQ(100, interceptor_call_count);
10063 } 10063 }
10064 10064
10065 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) { 10065 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature) {
10066 int interceptor_call_count = 0; 10066 int interceptor_call_count = 0;
10067 v8::HandleScope scope; 10067 v8::HandleScope scope(v8::Isolate::GetCurrent());
10068 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10068 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10069 v8::Handle<v8::FunctionTemplate> method_templ = 10069 v8::Handle<v8::FunctionTemplate> method_templ =
10070 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10070 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10071 v8_str("method_data"), 10071 v8_str("method_data"),
10072 v8::Signature::New(fun_templ)); 10072 v8::Signature::New(fun_templ));
10073 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10073 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10074 proto_templ->Set(v8_str("method"), method_templ); 10074 proto_templ->Set(v8_str("method"), method_templ);
10075 fun_templ->SetHiddenPrototype(true); 10075 fun_templ->SetHiddenPrototype(true);
10076 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10076 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10077 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10077 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 10 matching lines...) Expand all
10088 "var result = 0;" 10088 "var result = 0;"
10089 "for (var i = 0; i < 100; i++) {" 10089 "for (var i = 0; i < 100; i++) {"
10090 " result = receiver.method(41);" 10090 " result = receiver.method(41);"
10091 "}"); 10091 "}");
10092 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10092 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10093 CHECK_EQ(100, interceptor_call_count); 10093 CHECK_EQ(100, interceptor_call_count);
10094 } 10094 }
10095 10095
10096 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 10096 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
10097 int interceptor_call_count = 0; 10097 int interceptor_call_count = 0;
10098 v8::HandleScope scope; 10098 v8::HandleScope scope(v8::Isolate::GetCurrent());
10099 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10099 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10100 v8::Handle<v8::FunctionTemplate> method_templ = 10100 v8::Handle<v8::FunctionTemplate> method_templ =
10101 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10101 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10102 v8_str("method_data"), 10102 v8_str("method_data"),
10103 v8::Signature::New(fun_templ)); 10103 v8::Signature::New(fun_templ));
10104 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10104 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10105 proto_templ->Set(v8_str("method"), method_templ); 10105 proto_templ->Set(v8_str("method"), method_templ);
10106 fun_templ->SetHiddenPrototype(true); 10106 fun_templ->SetHiddenPrototype(true);
10107 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10107 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10108 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10108 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 16 matching lines...) Expand all
10125 " receiver = {method: function(x) { return x - 1 }};" 10125 " receiver = {method: function(x) { return x - 1 }};"
10126 " }" 10126 " }"
10127 "}"); 10127 "}");
10128 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10128 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10129 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10129 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10130 CHECK_GE(interceptor_call_count, 50); 10130 CHECK_GE(interceptor_call_count, 50);
10131 } 10131 }
10132 10132
10133 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 10133 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
10134 int interceptor_call_count = 0; 10134 int interceptor_call_count = 0;
10135 v8::HandleScope scope; 10135 v8::HandleScope scope(v8::Isolate::GetCurrent());
10136 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10136 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10137 v8::Handle<v8::FunctionTemplate> method_templ = 10137 v8::Handle<v8::FunctionTemplate> method_templ =
10138 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10138 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10139 v8_str("method_data"), 10139 v8_str("method_data"),
10140 v8::Signature::New(fun_templ)); 10140 v8::Signature::New(fun_templ));
10141 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10141 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10142 proto_templ->Set(v8_str("method"), method_templ); 10142 proto_templ->Set(v8_str("method"), method_templ);
10143 fun_templ->SetHiddenPrototype(true); 10143 fun_templ->SetHiddenPrototype(true);
10144 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10144 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10145 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10145 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 16 matching lines...) Expand all
10162 " o.method = function(x) { return x - 1 };" 10162 " o.method = function(x) { return x - 1 };"
10163 " }" 10163 " }"
10164 "}"); 10164 "}");
10165 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10165 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10166 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10166 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10167 CHECK_GE(interceptor_call_count, 50); 10167 CHECK_GE(interceptor_call_count, 50);
10168 } 10168 }
10169 10169
10170 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 10170 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
10171 int interceptor_call_count = 0; 10171 int interceptor_call_count = 0;
10172 v8::HandleScope scope; 10172 v8::HandleScope scope(v8::Isolate::GetCurrent());
10173 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10173 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10174 v8::Handle<v8::FunctionTemplate> method_templ = 10174 v8::Handle<v8::FunctionTemplate> method_templ =
10175 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10175 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10176 v8_str("method_data"), 10176 v8_str("method_data"),
10177 v8::Signature::New(fun_templ)); 10177 v8::Signature::New(fun_templ));
10178 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10178 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10179 proto_templ->Set(v8_str("method"), method_templ); 10179 proto_templ->Set(v8_str("method"), method_templ);
10180 fun_templ->SetHiddenPrototype(true); 10180 fun_templ->SetHiddenPrototype(true);
10181 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10181 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10182 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10182 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 19 matching lines...) Expand all
10202 "}"); 10202 "}");
10203 CHECK(try_catch.HasCaught()); 10203 CHECK(try_catch.HasCaught());
10204 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 10204 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
10205 try_catch.Exception()->ToString()); 10205 try_catch.Exception()->ToString());
10206 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10206 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10207 CHECK_GE(interceptor_call_count, 50); 10207 CHECK_GE(interceptor_call_count, 50);
10208 } 10208 }
10209 10209
10210 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 10210 THREADED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
10211 int interceptor_call_count = 0; 10211 int interceptor_call_count = 0;
10212 v8::HandleScope scope; 10212 v8::HandleScope scope(v8::Isolate::GetCurrent());
10213 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10213 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10214 v8::Handle<v8::FunctionTemplate> method_templ = 10214 v8::Handle<v8::FunctionTemplate> method_templ =
10215 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10215 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10216 v8_str("method_data"), 10216 v8_str("method_data"),
10217 v8::Signature::New(fun_templ)); 10217 v8::Signature::New(fun_templ));
10218 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10218 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10219 proto_templ->Set(v8_str("method"), method_templ); 10219 proto_templ->Set(v8_str("method"), method_templ);
10220 fun_templ->SetHiddenPrototype(true); 10220 fun_templ->SetHiddenPrototype(true);
10221 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 10221 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10222 templ->SetNamedPropertyHandler(InterceptorCallICFastApi, 10222 templ->SetNamedPropertyHandler(InterceptorCallICFastApi,
(...skipping 18 matching lines...) Expand all
10241 " }" 10241 " }"
10242 "}"); 10242 "}");
10243 CHECK(try_catch.HasCaught()); 10243 CHECK(try_catch.HasCaught());
10244 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 10244 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
10245 try_catch.Exception()->ToString()); 10245 try_catch.Exception()->ToString());
10246 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10246 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10247 CHECK_GE(interceptor_call_count, 50); 10247 CHECK_GE(interceptor_call_count, 50);
10248 } 10248 }
10249 10249
10250 THREADED_TEST(CallICFastApi_TrivialSignature) { 10250 THREADED_TEST(CallICFastApi_TrivialSignature) {
10251 v8::HandleScope scope; 10251 v8::HandleScope scope(v8::Isolate::GetCurrent());
10252 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10252 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10253 v8::Handle<v8::FunctionTemplate> method_templ = 10253 v8::Handle<v8::FunctionTemplate> method_templ =
10254 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 10254 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
10255 v8_str("method_data"), 10255 v8_str("method_data"),
10256 v8::Handle<v8::Signature>()); 10256 v8::Handle<v8::Signature>());
10257 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10257 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10258 proto_templ->Set(v8_str("method"), method_templ); 10258 proto_templ->Set(v8_str("method"), method_templ);
10259 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10259 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10260 USE(templ); 10260 USE(templ);
10261 LocalContext context; 10261 LocalContext context;
10262 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10262 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10263 GenerateSomeGarbage(); 10263 GenerateSomeGarbage();
10264 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10264 context->Global()->Set(v8_str("o"), fun->NewInstance());
10265 CompileRun( 10265 CompileRun(
10266 "var result = 0;" 10266 "var result = 0;"
10267 "for (var i = 0; i < 100; i++) {" 10267 "for (var i = 0; i < 100; i++) {"
10268 " result = o.method(41);" 10268 " result = o.method(41);"
10269 "}"); 10269 "}");
10270 10270
10271 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10271 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10272 } 10272 }
10273 10273
10274 THREADED_TEST(CallICFastApi_SimpleSignature) { 10274 THREADED_TEST(CallICFastApi_SimpleSignature) {
10275 v8::HandleScope scope; 10275 v8::HandleScope scope(v8::Isolate::GetCurrent());
10276 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10276 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10277 v8::Handle<v8::FunctionTemplate> method_templ = 10277 v8::Handle<v8::FunctionTemplate> method_templ =
10278 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10278 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10279 v8_str("method_data"), 10279 v8_str("method_data"),
10280 v8::Signature::New(fun_templ)); 10280 v8::Signature::New(fun_templ));
10281 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10281 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10282 proto_templ->Set(v8_str("method"), method_templ); 10282 proto_templ->Set(v8_str("method"), method_templ);
10283 fun_templ->SetHiddenPrototype(true); 10283 fun_templ->SetHiddenPrototype(true);
10284 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10284 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10285 CHECK(!templ.IsEmpty()); 10285 CHECK(!templ.IsEmpty());
10286 LocalContext context; 10286 LocalContext context;
10287 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 10287 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
10288 GenerateSomeGarbage(); 10288 GenerateSomeGarbage();
10289 context->Global()->Set(v8_str("o"), fun->NewInstance()); 10289 context->Global()->Set(v8_str("o"), fun->NewInstance());
10290 CompileRun( 10290 CompileRun(
10291 "o.foo = 17;" 10291 "o.foo = 17;"
10292 "var receiver = {};" 10292 "var receiver = {};"
10293 "receiver.__proto__ = o;" 10293 "receiver.__proto__ = o;"
10294 "var result = 0;" 10294 "var result = 0;"
10295 "for (var i = 0; i < 100; i++) {" 10295 "for (var i = 0; i < 100; i++) {"
10296 " result = receiver.method(41);" 10296 " result = receiver.method(41);"
10297 "}"); 10297 "}");
10298 10298
10299 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 10299 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
10300 } 10300 }
10301 10301
10302 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) { 10302 THREADED_TEST(CallICFastApi_SimpleSignature_Miss1) {
10303 v8::HandleScope scope; 10303 v8::HandleScope scope(v8::Isolate::GetCurrent());
10304 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10304 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10305 v8::Handle<v8::FunctionTemplate> method_templ = 10305 v8::Handle<v8::FunctionTemplate> method_templ =
10306 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10306 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10307 v8_str("method_data"), 10307 v8_str("method_data"),
10308 v8::Signature::New(fun_templ)); 10308 v8::Signature::New(fun_templ));
10309 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10309 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10310 proto_templ->Set(v8_str("method"), method_templ); 10310 proto_templ->Set(v8_str("method"), method_templ);
10311 fun_templ->SetHiddenPrototype(true); 10311 fun_templ->SetHiddenPrototype(true);
10312 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10312 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10313 CHECK(!templ.IsEmpty()); 10313 CHECK(!templ.IsEmpty());
(...skipping 12 matching lines...) Expand all
10326 " if (i == 50) {" 10326 " if (i == 50) {"
10327 " saved_result = result;" 10327 " saved_result = result;"
10328 " receiver = {method: function(x) { return x - 1 }};" 10328 " receiver = {method: function(x) { return x - 1 }};"
10329 " }" 10329 " }"
10330 "}"); 10330 "}");
10331 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 10331 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
10332 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10332 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10333 } 10333 }
10334 10334
10335 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) { 10335 THREADED_TEST(CallICFastApi_SimpleSignature_Miss2) {
10336 v8::HandleScope scope; 10336 v8::HandleScope scope(v8::Isolate::GetCurrent());
10337 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10337 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10338 v8::Handle<v8::FunctionTemplate> method_templ = 10338 v8::Handle<v8::FunctionTemplate> method_templ =
10339 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10339 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10340 v8_str("method_data"), 10340 v8_str("method_data"),
10341 v8::Signature::New(fun_templ)); 10341 v8::Signature::New(fun_templ));
10342 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10342 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10343 proto_templ->Set(v8_str("method"), method_templ); 10343 proto_templ->Set(v8_str("method"), method_templ);
10344 fun_templ->SetHiddenPrototype(true); 10344 fun_templ->SetHiddenPrototype(true);
10345 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10345 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10346 CHECK(!templ.IsEmpty()); 10346 CHECK(!templ.IsEmpty());
(...skipping 15 matching lines...) Expand all
10362 " receiver = 333;" 10362 " receiver = 333;"
10363 " }" 10363 " }"
10364 "}"); 10364 "}");
10365 CHECK(try_catch.HasCaught()); 10365 CHECK(try_catch.HasCaught());
10366 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 10366 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
10367 try_catch.Exception()->ToString()); 10367 try_catch.Exception()->ToString());
10368 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10368 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10369 } 10369 }
10370 10370
10371 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) { 10371 THREADED_TEST(CallICFastApi_SimpleSignature_TypeError) {
10372 v8::HandleScope scope; 10372 v8::HandleScope scope(v8::Isolate::GetCurrent());
10373 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10373 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
10374 v8::Handle<v8::FunctionTemplate> method_templ = 10374 v8::Handle<v8::FunctionTemplate> method_templ =
10375 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature, 10375 v8::FunctionTemplate::New(FastApiCallback_SimpleSignature,
10376 v8_str("method_data"), 10376 v8_str("method_data"),
10377 v8::Signature::New(fun_templ)); 10377 v8::Signature::New(fun_templ));
10378 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 10378 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10379 proto_templ->Set(v8_str("method"), method_templ); 10379 proto_templ->Set(v8_str("method"), method_templ);
10380 fun_templ->SetHiddenPrototype(true); 10380 fun_templ->SetHiddenPrototype(true);
10381 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 10381 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10382 CHECK(!templ.IsEmpty()); 10382 CHECK(!templ.IsEmpty());
(...skipping 30 matching lines...) Expand all
10413 if (v8_str("x")->Equals(name)) { 10413 if (v8_str("x")->Equals(name)) {
10414 return keyed_call_ic_function; 10414 return keyed_call_ic_function;
10415 } 10415 }
10416 return v8::Handle<Value>(); 10416 return v8::Handle<Value>();
10417 } 10417 }
10418 10418
10419 10419
10420 // Test the case when we stored cacheable lookup into 10420 // Test the case when we stored cacheable lookup into
10421 // a stub, but the function name changed (to another cacheable function). 10421 // a stub, but the function name changed (to another cacheable function).
10422 THREADED_TEST(InterceptorKeyedCallICKeyChange1) { 10422 THREADED_TEST(InterceptorKeyedCallICKeyChange1) {
10423 v8::HandleScope scope; 10423 v8::HandleScope scope(v8::Isolate::GetCurrent());
10424 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10424 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10425 templ->SetNamedPropertyHandler(NoBlockGetterX); 10425 templ->SetNamedPropertyHandler(NoBlockGetterX);
10426 LocalContext context; 10426 LocalContext context;
10427 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10427 context->Global()->Set(v8_str("o"), templ->NewInstance());
10428 CompileRun( 10428 CompileRun(
10429 "proto = new Object();" 10429 "proto = new Object();"
10430 "proto.y = function(x) { return x + 1; };" 10430 "proto.y = function(x) { return x + 1; };"
10431 "proto.z = function(x) { return x - 1; };" 10431 "proto.z = function(x) { return x - 1; };"
10432 "o.__proto__ = proto;" 10432 "o.__proto__ = proto;"
10433 "var result = 0;" 10433 "var result = 0;"
10434 "var method = 'y';" 10434 "var method = 'y';"
10435 "for (var i = 0; i < 10; i++) {" 10435 "for (var i = 0; i < 10; i++) {"
10436 " if (i == 5) { method = 'z'; };" 10436 " if (i == 5) { method = 'z'; };"
10437 " result += o[method](41);" 10437 " result += o[method](41);"
10438 "}"); 10438 "}");
10439 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10439 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10440 } 10440 }
10441 10441
10442 10442
10443 // Test the case when we stored cacheable lookup into 10443 // Test the case when we stored cacheable lookup into
10444 // a stub, but the function name changed (and the new function is present 10444 // a stub, but the function name changed (and the new function is present
10445 // both before and after the interceptor in the prototype chain). 10445 // both before and after the interceptor in the prototype chain).
10446 THREADED_TEST(InterceptorKeyedCallICKeyChange2) { 10446 THREADED_TEST(InterceptorKeyedCallICKeyChange2) {
10447 v8::HandleScope scope; 10447 v8::HandleScope scope(v8::Isolate::GetCurrent());
10448 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10448 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10449 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter); 10449 templ->SetNamedPropertyHandler(InterceptorKeyedCallICGetter);
10450 LocalContext context; 10450 LocalContext context;
10451 context->Global()->Set(v8_str("proto1"), templ->NewInstance()); 10451 context->Global()->Set(v8_str("proto1"), templ->NewInstance());
10452 keyed_call_ic_function = 10452 keyed_call_ic_function =
10453 v8_compile("function f(x) { return x - 1; }; f")->Run(); 10453 v8_compile("function f(x) { return x - 1; }; f")->Run();
10454 CompileRun( 10454 CompileRun(
10455 "o = new Object();" 10455 "o = new Object();"
10456 "proto2 = new Object();" 10456 "proto2 = new Object();"
10457 "o.y = function(x) { return x + 1; };" 10457 "o.y = function(x) { return x + 1; };"
10458 "proto2.y = function(x) { return x + 2; };" 10458 "proto2.y = function(x) { return x + 2; };"
10459 "o.__proto__ = proto1;" 10459 "o.__proto__ = proto1;"
10460 "proto1.__proto__ = proto2;" 10460 "proto1.__proto__ = proto2;"
10461 "var result = 0;" 10461 "var result = 0;"
10462 "var method = 'x';" 10462 "var method = 'x';"
10463 "for (var i = 0; i < 10; i++) {" 10463 "for (var i = 0; i < 10; i++) {"
10464 " if (i == 5) { method = 'y'; };" 10464 " if (i == 5) { method = 'y'; };"
10465 " result += o[method](41);" 10465 " result += o[method](41);"
10466 "}"); 10466 "}");
10467 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10467 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10468 } 10468 }
10469 10469
10470 10470
10471 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit 10471 // Same as InterceptorKeyedCallICKeyChange1 only the cacheable function sit
10472 // on the global object. 10472 // on the global object.
10473 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) { 10473 THREADED_TEST(InterceptorKeyedCallICKeyChangeOnGlobal) {
10474 v8::HandleScope scope; 10474 v8::HandleScope scope(v8::Isolate::GetCurrent());
10475 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10475 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10476 templ->SetNamedPropertyHandler(NoBlockGetterX); 10476 templ->SetNamedPropertyHandler(NoBlockGetterX);
10477 LocalContext context; 10477 LocalContext context;
10478 context->Global()->Set(v8_str("o"), templ->NewInstance()); 10478 context->Global()->Set(v8_str("o"), templ->NewInstance());
10479 CompileRun( 10479 CompileRun(
10480 "function inc(x) { return x + 1; };" 10480 "function inc(x) { return x + 1; };"
10481 "inc(1);" 10481 "inc(1);"
10482 "function dec(x) { return x - 1; };" 10482 "function dec(x) { return x - 1; };"
10483 "dec(1);" 10483 "dec(1);"
10484 "o.__proto__ = this;" 10484 "o.__proto__ = this;"
10485 "this.__proto__.x = inc;" 10485 "this.__proto__.x = inc;"
10486 "this.__proto__.y = dec;" 10486 "this.__proto__.y = dec;"
10487 "var result = 0;" 10487 "var result = 0;"
10488 "var method = 'x';" 10488 "var method = 'x';"
10489 "for (var i = 0; i < 10; i++) {" 10489 "for (var i = 0; i < 10; i++) {"
10490 " if (i == 5) { method = 'y'; };" 10490 " if (i == 5) { method = 'y'; };"
10491 " result += o[method](41);" 10491 " result += o[method](41);"
10492 "}"); 10492 "}");
10493 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10493 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10494 } 10494 }
10495 10495
10496 10496
10497 // Test the case when actual function to call sits on global object. 10497 // Test the case when actual function to call sits on global object.
10498 THREADED_TEST(InterceptorKeyedCallICFromGlobal) { 10498 THREADED_TEST(InterceptorKeyedCallICFromGlobal) {
10499 v8::HandleScope scope; 10499 v8::HandleScope scope(v8::Isolate::GetCurrent());
10500 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10500 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10501 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10501 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10502 LocalContext context; 10502 LocalContext context;
10503 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10503 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10504 10504
10505 CompileRun( 10505 CompileRun(
10506 "function len(x) { return x.length; };" 10506 "function len(x) { return x.length; };"
10507 "o.__proto__ = this;" 10507 "o.__proto__ = this;"
10508 "var m = 'parseFloat';" 10508 "var m = 'parseFloat';"
10509 "var result = 0;" 10509 "var result = 0;"
10510 "for (var i = 0; i < 10; i++) {" 10510 "for (var i = 0; i < 10; i++) {"
10511 " if (i == 5) {" 10511 " if (i == 5) {"
10512 " m = 'len';" 10512 " m = 'len';"
10513 " saved_result = result;" 10513 " saved_result = result;"
10514 " };" 10514 " };"
10515 " result = o[m]('239');" 10515 " result = o[m]('239');"
10516 "}"); 10516 "}");
10517 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value()); 10517 CHECK_EQ(3, context->Global()->Get(v8_str("result"))->Int32Value());
10518 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 10518 CHECK_EQ(239, context->Global()->Get(v8_str("saved_result"))->Int32Value());
10519 } 10519 }
10520 10520
10521 // Test the map transition before the interceptor. 10521 // Test the map transition before the interceptor.
10522 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) { 10522 THREADED_TEST(InterceptorKeyedCallICMapChangeBefore) {
10523 v8::HandleScope scope; 10523 v8::HandleScope scope(v8::Isolate::GetCurrent());
10524 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10524 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10525 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10525 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10526 LocalContext context; 10526 LocalContext context;
10527 context->Global()->Set(v8_str("proto"), templ_o->NewInstance()); 10527 context->Global()->Set(v8_str("proto"), templ_o->NewInstance());
10528 10528
10529 CompileRun( 10529 CompileRun(
10530 "var o = new Object();" 10530 "var o = new Object();"
10531 "o.__proto__ = proto;" 10531 "o.__proto__ = proto;"
10532 "o.method = function(x) { return x + 1; };" 10532 "o.method = function(x) { return x + 1; };"
10533 "var m = 'method';" 10533 "var m = 'method';"
10534 "var result = 0;" 10534 "var result = 0;"
10535 "for (var i = 0; i < 10; i++) {" 10535 "for (var i = 0; i < 10; i++) {"
10536 " if (i == 5) { o.method = function(x) { return x - 1; }; };" 10536 " if (i == 5) { o.method = function(x) { return x - 1; }; };"
10537 " result += o[m](41);" 10537 " result += o[m](41);"
10538 "}"); 10538 "}");
10539 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value()); 10539 CHECK_EQ(42*5 + 40*5, context->Global()->Get(v8_str("result"))->Int32Value());
10540 } 10540 }
10541 10541
10542 10542
10543 // Test the map transition after the interceptor. 10543 // Test the map transition after the interceptor.
10544 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) { 10544 THREADED_TEST(InterceptorKeyedCallICMapChangeAfter) {
10545 v8::HandleScope scope; 10545 v8::HandleScope scope(v8::Isolate::GetCurrent());
10546 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New(); 10546 v8::Handle<v8::ObjectTemplate> templ_o = ObjectTemplate::New();
10547 templ_o->SetNamedPropertyHandler(NoBlockGetterX); 10547 templ_o->SetNamedPropertyHandler(NoBlockGetterX);
10548 LocalContext context; 10548 LocalContext context;
10549 context->Global()->Set(v8_str("o"), templ_o->NewInstance()); 10549 context->Global()->Set(v8_str("o"), templ_o->NewInstance());
10550 10550
10551 CompileRun( 10551 CompileRun(
10552 "var proto = new Object();" 10552 "var proto = new Object();"
10553 "o.__proto__ = proto;" 10553 "o.__proto__ = proto;"
10554 "proto.method = function(x) { return x + 1; };" 10554 "proto.method = function(x) { return x + 1; };"
10555 "var m = 'method';" 10555 "var m = 'method';"
(...skipping 15 matching lines...) Expand all
10571 return call_ic_function2; 10571 return call_ic_function2;
10572 } 10572 }
10573 return v8::Handle<Value>(); 10573 return v8::Handle<Value>();
10574 } 10574 }
10575 10575
10576 10576
10577 // This test should hit load and call ICs for the interceptor case. 10577 // This test should hit load and call ICs for the interceptor case.
10578 // Once in a while, the interceptor will reply that a property was not 10578 // Once in a while, the interceptor will reply that a property was not
10579 // found in which case we should get a reference error. 10579 // found in which case we should get a reference error.
10580 THREADED_TEST(InterceptorICReferenceErrors) { 10580 THREADED_TEST(InterceptorICReferenceErrors) {
10581 v8::HandleScope scope; 10581 v8::HandleScope scope(v8::Isolate::GetCurrent());
10582 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10582 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10583 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter); 10583 templ->SetNamedPropertyHandler(InterceptorICRefErrorGetter);
10584 LocalContext context(0, templ, v8::Handle<Value>()); 10584 LocalContext context(0, templ, v8::Handle<Value>());
10585 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run(); 10585 call_ic_function2 = v8_compile("function h(x) { return x; }; h")->Run();
10586 v8::Handle<Value> value = CompileRun( 10586 v8::Handle<Value> value = CompileRun(
10587 "function f() {" 10587 "function f() {"
10588 " for (var i = 0; i < 1000; i++) {" 10588 " for (var i = 0; i < 1000; i++) {"
10589 " try { x; } catch(e) { return true; }" 10589 " try { x; } catch(e) { return true; }"
10590 " }" 10590 " }"
10591 " return false;" 10591 " return false;"
(...skipping 26 matching lines...) Expand all
10618 return v8::ThrowException(v8_num(42)); 10618 return v8::ThrowException(v8_num(42));
10619 } 10619 }
10620 // Do not handle get for properties other than x. 10620 // Do not handle get for properties other than x.
10621 return v8::Handle<Value>(); 10621 return v8::Handle<Value>();
10622 } 10622 }
10623 10623
10624 // Test interceptor load/call IC where the interceptor throws an 10624 // Test interceptor load/call IC where the interceptor throws an
10625 // exception once in a while. 10625 // exception once in a while.
10626 THREADED_TEST(InterceptorICGetterExceptions) { 10626 THREADED_TEST(InterceptorICGetterExceptions) {
10627 interceptor_ic_exception_get_count = 0; 10627 interceptor_ic_exception_get_count = 0;
10628 v8::HandleScope scope; 10628 v8::HandleScope scope(v8::Isolate::GetCurrent());
10629 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10629 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10630 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter); 10630 templ->SetNamedPropertyHandler(InterceptorICExceptionGetter);
10631 LocalContext context(0, templ, v8::Handle<Value>()); 10631 LocalContext context(0, templ, v8::Handle<Value>());
10632 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run(); 10632 call_ic_function3 = v8_compile("function h(x) { return x; }; h")->Run();
10633 v8::Handle<Value> value = CompileRun( 10633 v8::Handle<Value> value = CompileRun(
10634 "function f() {" 10634 "function f() {"
10635 " for (var i = 0; i < 100; i++) {" 10635 " for (var i = 0; i < 100; i++) {"
10636 " try { x; } catch(e) { return true; }" 10636 " try { x; } catch(e) { return true; }"
10637 " }" 10637 " }"
10638 " return false;" 10638 " return false;"
(...skipping 22 matching lines...) Expand all
10661 return v8::ThrowException(v8_num(42)); 10661 return v8::ThrowException(v8_num(42));
10662 } 10662 }
10663 // Do not actually handle setting. 10663 // Do not actually handle setting.
10664 return v8::Handle<Value>(); 10664 return v8::Handle<Value>();
10665 } 10665 }
10666 10666
10667 // Test interceptor store IC where the interceptor throws an exception 10667 // Test interceptor store IC where the interceptor throws an exception
10668 // once in a while. 10668 // once in a while.
10669 THREADED_TEST(InterceptorICSetterExceptions) { 10669 THREADED_TEST(InterceptorICSetterExceptions) {
10670 interceptor_ic_exception_set_count = 0; 10670 interceptor_ic_exception_set_count = 0;
10671 v8::HandleScope scope; 10671 v8::HandleScope scope(v8::Isolate::GetCurrent());
10672 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10672 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10673 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter); 10673 templ->SetNamedPropertyHandler(0, InterceptorICExceptionSetter);
10674 LocalContext context(0, templ, v8::Handle<Value>()); 10674 LocalContext context(0, templ, v8::Handle<Value>());
10675 v8::Handle<Value> value = CompileRun( 10675 v8::Handle<Value> value = CompileRun(
10676 "function f() {" 10676 "function f() {"
10677 " for (var i = 0; i < 100; i++) {" 10677 " for (var i = 0; i < 100; i++) {"
10678 " try { x = 42; } catch(e) { return true; }" 10678 " try { x = 42; } catch(e) { return true; }"
10679 " }" 10679 " }"
10680 " return false;" 10680 " return false;"
10681 "};" 10681 "};"
10682 "f();"); 10682 "f();");
10683 CHECK_EQ(true, value->BooleanValue()); 10683 CHECK_EQ(true, value->BooleanValue());
10684 } 10684 }
10685 10685
10686 10686
10687 // Test that we ignore null interceptors. 10687 // Test that we ignore null interceptors.
10688 THREADED_TEST(NullNamedInterceptor) { 10688 THREADED_TEST(NullNamedInterceptor) {
10689 v8::HandleScope scope; 10689 v8::HandleScope scope(v8::Isolate::GetCurrent());
10690 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10690 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10691 templ->SetNamedPropertyHandler(0); 10691 templ->SetNamedPropertyHandler(0);
10692 LocalContext context; 10692 LocalContext context;
10693 templ->Set("x", v8_num(42)); 10693 templ->Set("x", v8_num(42));
10694 v8::Handle<v8::Object> obj = templ->NewInstance(); 10694 v8::Handle<v8::Object> obj = templ->NewInstance();
10695 context->Global()->Set(v8_str("obj"), obj); 10695 context->Global()->Set(v8_str("obj"), obj);
10696 v8::Handle<Value> value = CompileRun("obj.x"); 10696 v8::Handle<Value> value = CompileRun("obj.x");
10697 CHECK(value->IsInt32()); 10697 CHECK(value->IsInt32());
10698 CHECK_EQ(42, value->Int32Value()); 10698 CHECK_EQ(42, value->Int32Value());
10699 } 10699 }
10700 10700
10701 10701
10702 // Test that we ignore null interceptors. 10702 // Test that we ignore null interceptors.
10703 THREADED_TEST(NullIndexedInterceptor) { 10703 THREADED_TEST(NullIndexedInterceptor) {
10704 v8::HandleScope scope; 10704 v8::HandleScope scope(v8::Isolate::GetCurrent());
10705 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); 10705 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New();
10706 templ->SetIndexedPropertyHandler(0); 10706 templ->SetIndexedPropertyHandler(0);
10707 LocalContext context; 10707 LocalContext context;
10708 templ->Set("42", v8_num(42)); 10708 templ->Set("42", v8_num(42));
10709 v8::Handle<v8::Object> obj = templ->NewInstance(); 10709 v8::Handle<v8::Object> obj = templ->NewInstance();
10710 context->Global()->Set(v8_str("obj"), obj); 10710 context->Global()->Set(v8_str("obj"), obj);
10711 v8::Handle<Value> value = CompileRun("obj[42]"); 10711 v8::Handle<Value> value = CompileRun("obj[42]");
10712 CHECK(value->IsInt32()); 10712 CHECK(value->IsInt32());
10713 CHECK_EQ(42, value->Int32Value()); 10713 CHECK_EQ(42, value->Int32Value());
10714 } 10714 }
10715 10715
10716 10716
10717 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 10717 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
10718 v8::HandleScope scope; 10718 v8::HandleScope scope(v8::Isolate::GetCurrent());
10719 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10719 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10720 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 10720 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
10721 LocalContext env; 10721 LocalContext env;
10722 env->Global()->Set(v8_str("obj"), 10722 env->Global()->Set(v8_str("obj"),
10723 templ->GetFunction()->NewInstance()); 10723 templ->GetFunction()->NewInstance());
10724 ExpectTrue("obj.x === 42"); 10724 ExpectTrue("obj.x === 42");
10725 ExpectTrue("!obj.propertyIsEnumerable('x')"); 10725 ExpectTrue("!obj.propertyIsEnumerable('x')");
10726 } 10726 }
10727 10727
10728 10728
10729 static Handle<Value> ThrowingGetter(Local<String> name, 10729 static Handle<Value> ThrowingGetter(Local<String> name,
10730 const AccessorInfo& info) { 10730 const AccessorInfo& info) {
10731 ApiTestFuzzer::Fuzz(); 10731 ApiTestFuzzer::Fuzz();
10732 ThrowException(Handle<Value>()); 10732 ThrowException(Handle<Value>());
10733 return Undefined(); 10733 return Undefined();
10734 } 10734 }
10735 10735
10736 10736
10737 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 10737 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
10738 HandleScope scope;
10739 LocalContext context; 10738 LocalContext context;
10739 HandleScope scope(context->GetIsolate());
10740 10740
10741 Local<FunctionTemplate> templ = FunctionTemplate::New(); 10741 Local<FunctionTemplate> templ = FunctionTemplate::New();
10742 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 10742 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
10743 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 10743 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
10744 10744
10745 Local<Object> instance = templ->GetFunction()->NewInstance(); 10745 Local<Object> instance = templ->GetFunction()->NewInstance();
10746 10746
10747 Local<Object> another = Object::New(); 10747 Local<Object> another = Object::New();
10748 another->SetPrototype(instance); 10748 another->SetPrototype(instance);
10749 10749
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
10819 10819
10820 10820
10821 static void WebKitLike(Handle<Message> message, Handle<Value> data) { 10821 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
10822 Handle<String> errorMessageString = message->Get(); 10822 Handle<String> errorMessageString = message->Get();
10823 CHECK(!errorMessageString.IsEmpty()); 10823 CHECK(!errorMessageString.IsEmpty());
10824 message->GetStackTrace(); 10824 message->GetStackTrace();
10825 message->GetScriptResourceName(); 10825 message->GetScriptResourceName();
10826 } 10826 }
10827 10827
10828 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { 10828 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
10829 HandleScope scope;
10830 LocalContext context; 10829 LocalContext context;
10830 HandleScope scope(context->GetIsolate());
10831 10831
10832 Local<Function> func = 10832 Local<Function> func =
10833 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction(); 10833 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction();
10834 context->Global()->Set(v8_str("func"), func); 10834 context->Global()->Set(v8_str("func"), func);
10835 10835
10836 MessageCallback callbacks[] = 10836 MessageCallback callbacks[] =
10837 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; 10837 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
10838 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { 10838 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
10839 MessageCallback callback = callbacks[i]; 10839 MessageCallback callback = callbacks[i];
10840 if (callback != NULL) { 10840 if (callback != NULL) {
(...skipping 22 matching lines...) Expand all
10863 10863
10864 static v8::Handle<Value> ChildGetter(Local<String> name, 10864 static v8::Handle<Value> ChildGetter(Local<String> name,
10865 const AccessorInfo& info) { 10865 const AccessorInfo& info) {
10866 ApiTestFuzzer::Fuzz(); 10866 ApiTestFuzzer::Fuzz();
10867 return v8_num(42); 10867 return v8_num(42);
10868 } 10868 }
10869 10869
10870 10870
10871 THREADED_TEST(Overriding) { 10871 THREADED_TEST(Overriding) {
10872 i::FLAG_es5_readonly = true; 10872 i::FLAG_es5_readonly = true;
10873 v8::HandleScope scope;
10874 LocalContext context; 10873 LocalContext context;
10874 v8::HandleScope scope(context->GetIsolate());
10875 10875
10876 // Parent template. 10876 // Parent template.
10877 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); 10877 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New();
10878 Local<ObjectTemplate> parent_instance_templ = 10878 Local<ObjectTemplate> parent_instance_templ =
10879 parent_templ->InstanceTemplate(); 10879 parent_templ->InstanceTemplate();
10880 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); 10880 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter);
10881 10881
10882 // Template that inherits from the parent template. 10882 // Template that inherits from the parent template.
10883 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(); 10883 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New();
10884 Local<ObjectTemplate> child_instance_templ = 10884 Local<ObjectTemplate> child_instance_templ =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
10926 } 10926 }
10927 10927
10928 10928
10929 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) { 10929 static v8::Handle<Value> IsConstructHandler(const v8::Arguments& args) {
10930 ApiTestFuzzer::Fuzz(); 10930 ApiTestFuzzer::Fuzz();
10931 return v8::Boolean::New(args.IsConstructCall()); 10931 return v8::Boolean::New(args.IsConstructCall());
10932 } 10932 }
10933 10933
10934 10934
10935 THREADED_TEST(IsConstructCall) { 10935 THREADED_TEST(IsConstructCall) {
10936 v8::HandleScope scope; 10936 v8::HandleScope scope(v8::Isolate::GetCurrent());
10937 10937
10938 // Function template with call handler. 10938 // Function template with call handler.
10939 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10939 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10940 templ->SetCallHandler(IsConstructHandler); 10940 templ->SetCallHandler(IsConstructHandler);
10941 10941
10942 LocalContext context; 10942 LocalContext context;
10943 10943
10944 context->Global()->Set(v8_str("f"), templ->GetFunction()); 10944 context->Global()->Set(v8_str("f"), templ->GetFunction());
10945 Local<Value> value = v8_compile("f()")->Run(); 10945 Local<Value> value = v8_compile("f()")->Run();
10946 CHECK(!value->BooleanValue()); 10946 CHECK(!value->BooleanValue());
10947 value = v8_compile("new f()")->Run(); 10947 value = v8_compile("new f()")->Run();
10948 CHECK(value->BooleanValue()); 10948 CHECK(value->BooleanValue());
10949 } 10949 }
10950 10950
10951 10951
10952 THREADED_TEST(ObjectProtoToString) { 10952 THREADED_TEST(ObjectProtoToString) {
10953 v8::HandleScope scope; 10953 v8::HandleScope scope(v8::Isolate::GetCurrent());
10954 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10954 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
10955 templ->SetClassName(v8_str("MyClass")); 10955 templ->SetClassName(v8_str("MyClass"));
10956 10956
10957 LocalContext context; 10957 LocalContext context;
10958 10958
10959 Local<String> customized_tostring = v8_str("customized toString"); 10959 Local<String> customized_tostring = v8_str("customized toString");
10960 10960
10961 // Replace Object.prototype.toString 10961 // Replace Object.prototype.toString
10962 v8_compile("Object.prototype.toString = function() {" 10962 v8_compile("Object.prototype.toString = function() {"
10963 " return 'customized toString';" 10963 " return 'customized toString';"
(...skipping 13 matching lines...) Expand all
10977 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); 10977 CHECK(value->IsString() && value->Equals(v8_str("[object global]")));
10978 10978
10979 // Check ordinary object 10979 // Check ordinary object
10980 Local<Value> object = v8_compile("new Object()")->Run(); 10980 Local<Value> object = v8_compile("new Object()")->Run();
10981 value = object.As<v8::Object>()->ObjectProtoToString(); 10981 value = object.As<v8::Object>()->ObjectProtoToString();
10982 CHECK(value->IsString() && value->Equals(v8_str("[object Object]"))); 10982 CHECK(value->IsString() && value->Equals(v8_str("[object Object]")));
10983 } 10983 }
10984 10984
10985 10985
10986 THREADED_TEST(ObjectGetConstructorName) { 10986 THREADED_TEST(ObjectGetConstructorName) {
10987 v8::HandleScope scope;
10988 LocalContext context; 10987 LocalContext context;
10988 v8::HandleScope scope(context->GetIsolate());
10989 v8_compile("function Parent() {};" 10989 v8_compile("function Parent() {};"
10990 "function Child() {};" 10990 "function Child() {};"
10991 "Child.prototype = new Parent();" 10991 "Child.prototype = new Parent();"
10992 "var outer = { inner: function() { } };" 10992 "var outer = { inner: function() { } };"
10993 "var p = new Parent();" 10993 "var p = new Parent();"
10994 "var c = new Child();" 10994 "var c = new Child();"
10995 "var x = new outer.inner();")->Run(); 10995 "var x = new outer.inner();")->Run();
10996 10996
10997 Local<v8::Value> p = context->Global()->Get(v8_str("p")); 10997 Local<v8::Value> p = context->Global()->Get(v8_str("p"));
10998 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals( 10998 CHECK(p->IsObject() && p->ToObject()->GetConstructorName()->Equals(
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
11169 } 11169 }
11170 11170
11171 11171
11172 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) { 11172 static v8::Handle<Value> ThrowInJS(const v8::Arguments& args) {
11173 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11173 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11174 ApiTestFuzzer::Fuzz(); 11174 ApiTestFuzzer::Fuzz();
11175 v8::Unlocker unlocker(CcTest::default_isolate()); 11175 v8::Unlocker unlocker(CcTest::default_isolate());
11176 const char* code = "throw 7;"; 11176 const char* code = "throw 7;";
11177 { 11177 {
11178 v8::Locker nested_locker(CcTest::default_isolate()); 11178 v8::Locker nested_locker(CcTest::default_isolate());
11179 v8::HandleScope scope; 11179 v8::HandleScope scope(args.GetIsolate());
11180 v8::Handle<Value> exception; 11180 v8::Handle<Value> exception;
11181 { v8::TryCatch try_catch; 11181 { v8::TryCatch try_catch;
11182 v8::Handle<Value> value = CompileRun(code); 11182 v8::Handle<Value> value = CompileRun(code);
11183 CHECK(value.IsEmpty()); 11183 CHECK(value.IsEmpty());
11184 CHECK(try_catch.HasCaught()); 11184 CHECK(try_catch.HasCaught());
11185 // Make sure to wrap the exception in a new handle because 11185 // Make sure to wrap the exception in a new handle because
11186 // the handle returned from the TryCatch is destroyed 11186 // the handle returned from the TryCatch is destroyed
11187 // when the TryCatch is destroyed. 11187 // when the TryCatch is destroyed.
11188 exception = Local<Value>::New(try_catch.Exception()); 11188 exception = Local<Value>::New(try_catch.Exception());
11189 } 11189 }
11190 return v8::ThrowException(exception); 11190 return v8::ThrowException(exception);
11191 } 11191 }
11192 } 11192 }
11193 11193
11194 11194
11195 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) { 11195 static v8::Handle<Value> ThrowInJSNoCatch(const v8::Arguments& args) {
11196 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11196 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11197 ApiTestFuzzer::Fuzz(); 11197 ApiTestFuzzer::Fuzz();
11198 v8::Unlocker unlocker(CcTest::default_isolate()); 11198 v8::Unlocker unlocker(CcTest::default_isolate());
11199 const char* code = "throw 7;"; 11199 const char* code = "throw 7;";
11200 { 11200 {
11201 v8::Locker nested_locker(CcTest::default_isolate()); 11201 v8::Locker nested_locker(CcTest::default_isolate());
11202 v8::HandleScope scope; 11202 v8::HandleScope scope(args.GetIsolate());
11203 v8::Handle<Value> value = CompileRun(code); 11203 v8::Handle<Value> value = CompileRun(code);
11204 CHECK(value.IsEmpty()); 11204 CHECK(value.IsEmpty());
11205 return v8_str("foo"); 11205 return v8_str("foo");
11206 } 11206 }
11207 } 11207 }
11208 11208
11209 11209
11210 // These are locking tests that don't need to be run again 11210 // These are locking tests that don't need to be run again
11211 // as part of the locking aggregation tests. 11211 // as part of the locking aggregation tests.
11212 TEST(NestedLockers) { 11212 TEST(NestedLockers) {
11213 v8::Locker locker(CcTest::default_isolate()); 11213 v8::Locker locker(CcTest::default_isolate());
11214 CHECK(v8::Locker::IsLocked(CcTest::default_isolate())); 11214 CHECK(v8::Locker::IsLocked(CcTest::default_isolate()));
11215 v8::HandleScope scope;
11216 LocalContext env; 11215 LocalContext env;
11216 v8::HandleScope scope(env->GetIsolate());
11217 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); 11217 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS);
11218 Local<Function> fun = fun_templ->GetFunction(); 11218 Local<Function> fun = fun_templ->GetFunction();
11219 env->Global()->Set(v8_str("throw_in_js"), fun); 11219 env->Global()->Set(v8_str("throw_in_js"), fun);
11220 Local<Script> script = v8_compile("(function () {" 11220 Local<Script> script = v8_compile("(function () {"
11221 " try {" 11221 " try {"
11222 " throw_in_js();" 11222 " throw_in_js();"
11223 " return 42;" 11223 " return 42;"
11224 " } catch (e) {" 11224 " } catch (e) {"
11225 " return e * 13;" 11225 " return e * 13;"
11226 " }" 11226 " }"
11227 "})();"); 11227 "})();");
11228 CHECK_EQ(91, script->Run()->Int32Value()); 11228 CHECK_EQ(91, script->Run()->Int32Value());
11229 } 11229 }
11230 11230
11231 11231
11232 // These are locking tests that don't need to be run again 11232 // These are locking tests that don't need to be run again
11233 // as part of the locking aggregation tests. 11233 // as part of the locking aggregation tests.
11234 TEST(NestedLockersNoTryCatch) { 11234 TEST(NestedLockersNoTryCatch) {
11235 v8::Locker locker(CcTest::default_isolate()); 11235 v8::Locker locker(CcTest::default_isolate());
11236 v8::HandleScope scope;
11237 LocalContext env; 11236 LocalContext env;
11237 v8::HandleScope scope(env->GetIsolate());
11238 Local<v8::FunctionTemplate> fun_templ = 11238 Local<v8::FunctionTemplate> fun_templ =
11239 v8::FunctionTemplate::New(ThrowInJSNoCatch); 11239 v8::FunctionTemplate::New(ThrowInJSNoCatch);
11240 Local<Function> fun = fun_templ->GetFunction(); 11240 Local<Function> fun = fun_templ->GetFunction();
11241 env->Global()->Set(v8_str("throw_in_js"), fun); 11241 env->Global()->Set(v8_str("throw_in_js"), fun);
11242 Local<Script> script = v8_compile("(function () {" 11242 Local<Script> script = v8_compile("(function () {"
11243 " try {" 11243 " try {"
11244 " throw_in_js();" 11244 " throw_in_js();"
11245 " return 42;" 11245 " return 42;"
11246 " } catch (e) {" 11246 " } catch (e) {"
11247 " return e * 13;" 11247 " return e * 13;"
(...skipping 15 matching lines...) Expand all
11263 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) { 11263 static v8::Handle<Value> UnlockForAMoment(const v8::Arguments& args) {
11264 ApiTestFuzzer::Fuzz(); 11264 ApiTestFuzzer::Fuzz();
11265 v8::Unlocker unlocker(CcTest::default_isolate()); 11265 v8::Unlocker unlocker(CcTest::default_isolate());
11266 return v8::Undefined(); 11266 return v8::Undefined();
11267 } 11267 }
11268 11268
11269 11269
11270 THREADED_TEST(LockUnlockLock) { 11270 THREADED_TEST(LockUnlockLock) {
11271 { 11271 {
11272 v8::Locker locker(CcTest::default_isolate()); 11272 v8::Locker locker(CcTest::default_isolate());
11273 v8::HandleScope scope; 11273 v8::HandleScope scope(CcTest::default_isolate());
11274 LocalContext env; 11274 LocalContext env;
11275 Local<v8::FunctionTemplate> fun_templ = 11275 Local<v8::FunctionTemplate> fun_templ =
11276 v8::FunctionTemplate::New(UnlockForAMoment); 11276 v8::FunctionTemplate::New(UnlockForAMoment);
11277 Local<Function> fun = fun_templ->GetFunction(); 11277 Local<Function> fun = fun_templ->GetFunction();
11278 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 11278 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
11279 Local<Script> script = v8_compile("(function () {" 11279 Local<Script> script = v8_compile("(function () {"
11280 " unlock_for_a_moment();" 11280 " unlock_for_a_moment();"
11281 " return 42;" 11281 " return 42;"
11282 "})();"); 11282 "})();");
11283 CHECK_EQ(42, script->Run()->Int32Value()); 11283 CHECK_EQ(42, script->Run()->Int32Value());
11284 } 11284 }
11285 { 11285 {
11286 v8::Locker locker(CcTest::default_isolate()); 11286 v8::Locker locker(CcTest::default_isolate());
11287 v8::HandleScope scope; 11287 v8::HandleScope scope(CcTest::default_isolate());
11288 LocalContext env; 11288 LocalContext env;
11289 Local<v8::FunctionTemplate> fun_templ = 11289 Local<v8::FunctionTemplate> fun_templ =
11290 v8::FunctionTemplate::New(UnlockForAMoment); 11290 v8::FunctionTemplate::New(UnlockForAMoment);
11291 Local<Function> fun = fun_templ->GetFunction(); 11291 Local<Function> fun = fun_templ->GetFunction();
11292 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 11292 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
11293 Local<Script> script = v8_compile("(function () {" 11293 Local<Script> script = v8_compile("(function () {"
11294 " unlock_for_a_moment();" 11294 " unlock_for_a_moment();"
11295 " return 42;" 11295 " return 42;"
11296 "})();"); 11296 "})();");
11297 CHECK_EQ(42, script->Run()->Int32Value()); 11297 CHECK_EQ(42, script->Run()->Int32Value());
(...skipping 26 matching lines...) Expand all
11324 CHECK_EQ(expected, count); 11324 CHECK_EQ(expected, count);
11325 } 11325 }
11326 11326
11327 11327
11328 TEST(DontLeakGlobalObjects) { 11328 TEST(DontLeakGlobalObjects) {
11329 // Regression test for issues 1139850 and 1174891. 11329 // Regression test for issues 1139850 and 1174891.
11330 11330
11331 v8::V8::Initialize(); 11331 v8::V8::Initialize();
11332 11332
11333 for (int i = 0; i < 5; i++) { 11333 for (int i = 0; i < 5; i++) {
11334 { v8::HandleScope scope; 11334 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11335 LocalContext context; 11335 LocalContext context;
11336 } 11336 }
11337 v8::V8::ContextDisposedNotification(); 11337 v8::V8::ContextDisposedNotification();
11338 CheckSurvivingGlobalObjectsCount(0); 11338 CheckSurvivingGlobalObjectsCount(0);
11339 11339
11340 { v8::HandleScope scope; 11340 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11341 LocalContext context; 11341 LocalContext context;
11342 v8_compile("Date")->Run(); 11342 v8_compile("Date")->Run();
11343 } 11343 }
11344 v8::V8::ContextDisposedNotification(); 11344 v8::V8::ContextDisposedNotification();
11345 CheckSurvivingGlobalObjectsCount(0); 11345 CheckSurvivingGlobalObjectsCount(0);
11346 11346
11347 { v8::HandleScope scope; 11347 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11348 LocalContext context; 11348 LocalContext context;
11349 v8_compile("/aaa/")->Run(); 11349 v8_compile("/aaa/")->Run();
11350 } 11350 }
11351 v8::V8::ContextDisposedNotification(); 11351 v8::V8::ContextDisposedNotification();
11352 CheckSurvivingGlobalObjectsCount(0); 11352 CheckSurvivingGlobalObjectsCount(0);
11353 11353
11354 { v8::HandleScope scope; 11354 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11355 const char* extension_list[] = { "v8/gc" }; 11355 const char* extension_list[] = { "v8/gc" };
11356 v8::ExtensionConfiguration extensions(1, extension_list); 11356 v8::ExtensionConfiguration extensions(1, extension_list);
11357 LocalContext context(&extensions); 11357 LocalContext context(&extensions);
11358 v8_compile("gc();")->Run(); 11358 v8_compile("gc();")->Run();
11359 } 11359 }
11360 v8::V8::ContextDisposedNotification(); 11360 v8::V8::ContextDisposedNotification();
11361 CheckSurvivingGlobalObjectsCount(0); 11361 CheckSurvivingGlobalObjectsCount(0);
11362 } 11362 }
11363 } 11363 }
11364 11364
11365 11365
11366 v8::Persistent<v8::Object> some_object; 11366 v8::Persistent<v8::Object> some_object;
11367 v8::Persistent<v8::Object> bad_handle; 11367 v8::Persistent<v8::Object> bad_handle;
11368 11368
11369 void NewPersistentHandleCallback(v8::Isolate* isolate, 11369 void NewPersistentHandleCallback(v8::Isolate* isolate,
11370 v8::Persistent<v8::Value> handle, 11370 v8::Persistent<v8::Value> handle,
11371 void*) { 11371 void*) {
11372 v8::HandleScope scope; 11372 v8::HandleScope scope(isolate);
11373 bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object); 11373 bad_handle = v8::Persistent<v8::Object>::New(isolate, some_object);
11374 handle.Dispose(isolate); 11374 handle.Dispose(isolate);
11375 } 11375 }
11376 11376
11377 11377
11378 THREADED_TEST(NewPersistentHandleFromWeakCallback) { 11378 THREADED_TEST(NewPersistentHandleFromWeakCallback) {
11379 LocalContext context; 11379 LocalContext context;
11380 v8::Isolate* isolate = context->GetIsolate(); 11380 v8::Isolate* isolate = context->GetIsolate();
11381 11381
11382 v8::Persistent<v8::Object> handle1, handle2; 11382 v8::Persistent<v8::Object> handle1, handle2;
11383 { 11383 {
11384 v8::HandleScope scope; 11384 v8::HandleScope scope(isolate);
11385 some_object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11385 some_object = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11386 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11386 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11387 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11387 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11388 } 11388 }
11389 // Note: order is implementation dependent alas: currently 11389 // Note: order is implementation dependent alas: currently
11390 // global handle nodes are processed by PostGarbageCollectionProcessing 11390 // global handle nodes are processed by PostGarbageCollectionProcessing
11391 // in reverse allocation order, so if second allocated handle is deleted, 11391 // in reverse allocation order, so if second allocated handle is deleted,
11392 // weak callback of the first handle would be able to 'reallocate' it. 11392 // weak callback of the first handle would be able to 'reallocate' it.
11393 handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback); 11393 handle1.MakeWeak(isolate, NULL, NewPersistentHandleCallback);
11394 handle2.Dispose(isolate); 11394 handle2.Dispose(isolate);
(...skipping 11 matching lines...) Expand all
11406 handle.Dispose(isolate); 11406 handle.Dispose(isolate);
11407 } 11407 }
11408 11408
11409 11409
11410 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) { 11410 THREADED_TEST(DoNotUseDeletedNodesInSecondLevelGc) {
11411 LocalContext context; 11411 LocalContext context;
11412 v8::Isolate* isolate = context->GetIsolate(); 11412 v8::Isolate* isolate = context->GetIsolate();
11413 11413
11414 v8::Persistent<v8::Object> handle1, handle2; 11414 v8::Persistent<v8::Object> handle1, handle2;
11415 { 11415 {
11416 v8::HandleScope scope; 11416 v8::HandleScope scope(isolate);
11417 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11417 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11418 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11418 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11419 } 11419 }
11420 handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback); 11420 handle1.MakeWeak(isolate, NULL, DisposeAndForceGcCallback);
11421 to_be_disposed = handle2; 11421 to_be_disposed = handle2;
11422 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11422 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11423 } 11423 }
11424 11424
11425 void DisposingCallback(v8::Isolate* isolate, 11425 void DisposingCallback(v8::Isolate* isolate,
11426 v8::Persistent<v8::Value> handle, 11426 v8::Persistent<v8::Value> handle,
11427 void*) { 11427 void*) {
11428 handle.Dispose(isolate); 11428 handle.Dispose(isolate);
11429 } 11429 }
11430 11430
11431 void HandleCreatingCallback(v8::Isolate* isolate, 11431 void HandleCreatingCallback(v8::Isolate* isolate,
11432 v8::Persistent<v8::Value> handle, 11432 v8::Persistent<v8::Value> handle,
11433 void*) { 11433 void*) {
11434 v8::HandleScope scope; 11434 v8::HandleScope scope(isolate);
11435 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11435 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11436 handle.Dispose(isolate); 11436 handle.Dispose(isolate);
11437 } 11437 }
11438 11438
11439 11439
11440 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) { 11440 THREADED_TEST(NoGlobalHandlesOrphaningDueToWeakCallback) {
11441 LocalContext context; 11441 LocalContext context;
11442 v8::Isolate* isolate = context->GetIsolate(); 11442 v8::Isolate* isolate = context->GetIsolate();
11443 11443
11444 v8::Persistent<v8::Object> handle1, handle2, handle3; 11444 v8::Persistent<v8::Object> handle1, handle2, handle3;
11445 { 11445 {
11446 v8::HandleScope scope; 11446 v8::HandleScope scope(isolate);
11447 handle3 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11447 handle3 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11448 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11448 handle2 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11449 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 11449 handle1 = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
11450 } 11450 }
11451 handle2.MakeWeak(isolate, NULL, DisposingCallback); 11451 handle2.MakeWeak(isolate, NULL, DisposingCallback);
11452 handle3.MakeWeak(isolate, NULL, HandleCreatingCallback); 11452 handle3.MakeWeak(isolate, NULL, HandleCreatingCallback);
11453 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 11453 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
11454 } 11454 }
11455 11455
11456 11456
11457 THREADED_TEST(CheckForCrossContextObjectLiterals) { 11457 THREADED_TEST(CheckForCrossContextObjectLiterals) {
11458 v8::V8::Initialize(); 11458 v8::V8::Initialize();
11459 11459
11460 const int nof = 2; 11460 const int nof = 2;
11461 const char* sources[nof] = { 11461 const char* sources[nof] = {
11462 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }", 11462 "try { [ 2, 3, 4 ].forEach(5); } catch(e) { e.toString(); }",
11463 "Object()" 11463 "Object()"
11464 }; 11464 };
11465 11465
11466 for (int i = 0; i < nof; i++) { 11466 for (int i = 0; i < nof; i++) {
11467 const char* source = sources[i]; 11467 const char* source = sources[i];
11468 { v8::HandleScope scope; 11468 { v8::HandleScope scope(v8::Isolate::GetCurrent());
11469 LocalContext context; 11469 LocalContext context;
11470 CompileRun(source); 11470 CompileRun(source);
11471 } 11471 }
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 } 11476 }
11477 } 11477 }
11478 11478
11479 11479
11480 static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) { 11480 static v8::Handle<Value> NestedScope(v8::Persistent<Context> env) {
11481 v8::HandleScope inner; 11481 v8::HandleScope inner(env->GetIsolate());
11482 env->Enter(); 11482 env->Enter();
11483 v8::Handle<Value> three = v8_num(3); 11483 v8::Handle<Value> three = v8_num(3);
11484 v8::Handle<Value> value = inner.Close(three); 11484 v8::Handle<Value> value = inner.Close(three);
11485 env->Exit(); 11485 env->Exit();
11486 return value; 11486 return value;
11487 } 11487 }
11488 11488
11489 11489
11490 THREADED_TEST(NestedHandleScopeAndContexts) { 11490 THREADED_TEST(NestedHandleScopeAndContexts) {
11491 v8::HandleScope outer; 11491 v8::HandleScope outer(v8::Isolate::GetCurrent());
11492 v8::Persistent<Context> env = Context::New(); 11492 v8::Persistent<Context> env = Context::New();
11493 env->Enter(); 11493 env->Enter();
11494 v8::Handle<Value> value = NestedScope(env); 11494 v8::Handle<Value> value = NestedScope(env);
11495 v8::Handle<String> str(value->ToString()); 11495 v8::Handle<String> str(value->ToString());
11496 CHECK(!str.IsEmpty()); 11496 CHECK(!str.IsEmpty());
11497 env->Exit(); 11497 env->Exit();
11498 env.Dispose(env->GetIsolate()); 11498 env.Dispose(env->GetIsolate());
11499 } 11499 }
11500 11500
11501 11501
(...skipping 18 matching lines...) Expand all
11520 // TODO(siggi): Verify return_addr_location. 11520 // TODO(siggi): Verify return_addr_location.
11521 // This can be done by capturing JitCodeEvents, but requires an ordered 11521 // This can be done by capturing JitCodeEvents, but requires an ordered
11522 // collection. 11522 // collection.
11523 } 11523 }
11524 11524
11525 11525
11526 static void RunLoopInNewEnv() { 11526 static void RunLoopInNewEnv() {
11527 bar_ptr = NULL; 11527 bar_ptr = NULL;
11528 foo_ptr = NULL; 11528 foo_ptr = NULL;
11529 11529
11530 v8::HandleScope outer; 11530 v8::HandleScope outer(v8::Isolate::GetCurrent());
11531 v8::Persistent<Context> env = Context::New(); 11531 v8::Persistent<Context> env = Context::New();
11532 env->Enter(); 11532 env->Enter();
11533 11533
11534 const char* script = 11534 const char* script =
11535 "function bar() {" 11535 "function bar() {"
11536 " var sum = 0;" 11536 " var sum = 0;"
11537 " for (i = 0; i < 100; ++i)" 11537 " for (i = 0; i < 100; ++i)"
11538 " sum = foo(i);" 11538 " sum = foo(i);"
11539 " return sum;" 11539 " return sum;"
11540 "}" 11540 "}"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
11760 "}" 11760 "}"
11761 "function foo(i) { return i * i; };" 11761 "function foo(i) { return i * i; };"
11762 "bar();"; 11762 "bar();";
11763 11763
11764 // Run this test in a new isolate to make sure we don't 11764 // Run this test in a new isolate to make sure we don't
11765 // have remnants of state from other code. 11765 // have remnants of state from other code.
11766 v8::Isolate* isolate = v8::Isolate::New(); 11766 v8::Isolate* isolate = v8::Isolate::New();
11767 isolate->Enter(); 11767 isolate->Enter();
11768 11768
11769 { 11769 {
11770 v8::HandleScope scope; 11770 v8::HandleScope scope(isolate);
11771 i::HashMap code(MatchPointers); 11771 i::HashMap code(MatchPointers);
11772 code_map = &code; 11772 code_map = &code;
11773 11773
11774 i::HashMap lineinfo(MatchPointers); 11774 i::HashMap lineinfo(MatchPointers);
11775 jitcode_line_info = &lineinfo; 11775 jitcode_line_info = &lineinfo;
11776 11776
11777 saw_bar = 0; 11777 saw_bar = 0;
11778 move_events = 0; 11778 move_events = 0;
11779 11779
11780 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler); 11780 V8::SetJitCodeEventHandler(v8::kJitCodeEventDefault, event_handler);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
11813 isolate->Exit(); 11813 isolate->Exit();
11814 isolate->Dispose(); 11814 isolate->Dispose();
11815 11815
11816 // Do this in a new isolate. 11816 // Do this in a new isolate.
11817 isolate = v8::Isolate::New(); 11817 isolate = v8::Isolate::New();
11818 isolate->Enter(); 11818 isolate->Enter();
11819 11819
11820 // Verify that we get callbacks for existing code objects when we 11820 // Verify that we get callbacks for existing code objects when we
11821 // request enumeration of existing code. 11821 // request enumeration of existing code.
11822 { 11822 {
11823 v8::HandleScope scope; 11823 v8::HandleScope scope(isolate);
11824 LocalContext env; 11824 LocalContext env;
11825 CompileRun(script); 11825 CompileRun(script);
11826 11826
11827 // Now get code through initial iteration. 11827 // Now get code through initial iteration.
11828 i::HashMap code(MatchPointers); 11828 i::HashMap code(MatchPointers);
11829 code_map = &code; 11829 code_map = &code;
11830 11830
11831 i::HashMap lineinfo(MatchPointers); 11831 i::HashMap lineinfo(MatchPointers);
11832 jitcode_line_info = &lineinfo; 11832 jitcode_line_info = &lineinfo;
11833 11833
(...skipping 12 matching lines...) Expand all
11846 11846
11847 isolate->Exit(); 11847 isolate->Exit();
11848 isolate->Dispose(); 11848 isolate->Dispose();
11849 } 11849 }
11850 11850
11851 11851
11852 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); } 11852 static int64_t cast(intptr_t x) { return static_cast<int64_t>(x); }
11853 11853
11854 11854
11855 THREADED_TEST(ExternalAllocatedMemory) { 11855 THREADED_TEST(ExternalAllocatedMemory) {
11856 v8::HandleScope outer; 11856 v8::HandleScope outer(v8::Isolate::GetCurrent());
11857 v8::Persistent<Context> env(Context::New()); 11857 v8::Persistent<Context> env(Context::New());
11858 CHECK(!env.IsEmpty()); 11858 CHECK(!env.IsEmpty());
11859 const intptr_t kSize = 1024*1024; 11859 const intptr_t kSize = 1024*1024;
11860 v8::Isolate* isolate = env->GetIsolate(); 11860 v8::Isolate* isolate = env->GetIsolate();
11861 CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)), 11861 CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(kSize)),
11862 cast(kSize)); 11862 cast(kSize));
11863 CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize)), 11863 CHECK_EQ(cast(isolate->AdjustAmountOfExternalAllocatedMemory(-kSize)),
11864 cast(0)); 11864 cast(0));
11865 } 11865 }
11866 11866
11867 11867
11868 THREADED_TEST(DisposeEnteredContext) { 11868 THREADED_TEST(DisposeEnteredContext) {
11869 v8::HandleScope scope;
11870 LocalContext outer; 11869 LocalContext outer;
11870 v8::HandleScope scope(outer->GetIsolate());
11871 { v8::Persistent<v8::Context> inner = v8::Context::New(); 11871 { v8::Persistent<v8::Context> inner = v8::Context::New();
11872 inner->Enter(); 11872 inner->Enter();
11873 inner.Dispose(inner->GetIsolate()); 11873 inner.Dispose(inner->GetIsolate());
11874 inner.Clear(); 11874 inner.Clear();
11875 inner->Exit(); 11875 inner->Exit();
11876 } 11876 }
11877 } 11877 }
11878 11878
11879 11879
11880 // Regression test for issue 54, object templates with internal fields 11880 // Regression test for issue 54, object templates with internal fields
11881 // but no accessors or interceptors did not get their internal field 11881 // but no accessors or interceptors did not get their internal field
11882 // count set on instances. 11882 // count set on instances.
11883 THREADED_TEST(Regress54) { 11883 THREADED_TEST(Regress54) {
11884 v8::HandleScope outer;
11885 LocalContext context; 11884 LocalContext context;
11886 v8::Isolate* isolate = context->GetIsolate(); 11885 v8::Isolate* isolate = context->GetIsolate();
11886 v8::HandleScope outer(isolate);
11887 static v8::Persistent<v8::ObjectTemplate> templ; 11887 static v8::Persistent<v8::ObjectTemplate> templ;
11888 if (templ.IsEmpty()) { 11888 if (templ.IsEmpty()) {
11889 v8::HandleScope inner; 11889 v8::HandleScope inner(isolate);
11890 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New(); 11890 v8::Handle<v8::ObjectTemplate> local = v8::ObjectTemplate::New();
11891 local->SetInternalFieldCount(1); 11891 local->SetInternalFieldCount(1);
11892 templ = 11892 templ =
11893 v8::Persistent<v8::ObjectTemplate>::New(isolate, inner.Close(local)); 11893 v8::Persistent<v8::ObjectTemplate>::New(isolate, inner.Close(local));
11894 } 11894 }
11895 v8::Handle<v8::Object> result = templ->NewInstance(); 11895 v8::Handle<v8::Object> result = templ->NewInstance();
11896 CHECK_EQ(1, result->InternalFieldCount()); 11896 CHECK_EQ(1, result->InternalFieldCount());
11897 } 11897 }
11898 11898
11899 11899
11900 // If part of the threaded tests, this test makes ThreadingTest fail 11900 // If part of the threaded tests, this test makes ThreadingTest fail
11901 // on mac. 11901 // on mac.
11902 TEST(CatchStackOverflow) { 11902 TEST(CatchStackOverflow) {
11903 v8::HandleScope scope;
11904 LocalContext context; 11903 LocalContext context;
11904 v8::HandleScope scope(context->GetIsolate());
11905 v8::TryCatch try_catch; 11905 v8::TryCatch try_catch;
11906 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New( 11906 v8::Handle<v8::Script> script = v8::Script::Compile(v8::String::New(
11907 "function f() {" 11907 "function f() {"
11908 " return f();" 11908 " return f();"
11909 "}" 11909 "}"
11910 "" 11910 ""
11911 "f();")); 11911 "f();"));
11912 v8::Handle<v8::Value> result = script->Run(); 11912 v8::Handle<v8::Value> result = script->Run();
11913 CHECK(result.IsEmpty()); 11913 CHECK(result.IsEmpty());
11914 } 11914 }
11915 11915
11916 11916
11917 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 11917 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script,
11918 const char* resource_name, 11918 const char* resource_name,
11919 int line_offset) { 11919 int line_offset) {
11920 v8::HandleScope scope; 11920 v8::HandleScope scope(v8::Isolate::GetCurrent());
11921 v8::TryCatch try_catch; 11921 v8::TryCatch try_catch;
11922 v8::Handle<v8::Value> result = script->Run(); 11922 v8::Handle<v8::Value> result = script->Run();
11923 CHECK(result.IsEmpty()); 11923 CHECK(result.IsEmpty());
11924 CHECK(try_catch.HasCaught()); 11924 CHECK(try_catch.HasCaught());
11925 v8::Handle<v8::Message> message = try_catch.Message(); 11925 v8::Handle<v8::Message> message = try_catch.Message();
11926 CHECK(!message.IsEmpty()); 11926 CHECK(!message.IsEmpty());
11927 CHECK_EQ(10 + line_offset, message->GetLineNumber()); 11927 CHECK_EQ(10 + line_offset, message->GetLineNumber());
11928 CHECK_EQ(91, message->GetStartPosition()); 11928 CHECK_EQ(91, message->GetStartPosition());
11929 CHECK_EQ(92, message->GetEndPosition()); 11929 CHECK_EQ(92, message->GetEndPosition());
11930 CHECK_EQ(2, message->GetStartColumn()); 11930 CHECK_EQ(2, message->GetStartColumn());
11931 CHECK_EQ(3, message->GetEndColumn()); 11931 CHECK_EQ(3, message->GetEndColumn());
11932 v8::String::AsciiValue line(message->GetSourceLine()); 11932 v8::String::AsciiValue line(message->GetSourceLine());
11933 CHECK_EQ(" throw 'nirk';", *line); 11933 CHECK_EQ(" throw 'nirk';", *line);
11934 v8::String::AsciiValue name(message->GetScriptResourceName()); 11934 v8::String::AsciiValue name(message->GetScriptResourceName());
11935 CHECK_EQ(resource_name, *name); 11935 CHECK_EQ(resource_name, *name);
11936 } 11936 }
11937 11937
11938 11938
11939 THREADED_TEST(TryCatchSourceInfo) { 11939 THREADED_TEST(TryCatchSourceInfo) {
11940 v8::HandleScope scope;
11941 LocalContext context; 11940 LocalContext context;
11941 v8::HandleScope scope(context->GetIsolate());
11942 v8::Handle<v8::String> source = v8::String::New( 11942 v8::Handle<v8::String> source = v8::String::New(
11943 "function Foo() {\n" 11943 "function Foo() {\n"
11944 " return Bar();\n" 11944 " return Bar();\n"
11945 "}\n" 11945 "}\n"
11946 "\n" 11946 "\n"
11947 "function Bar() {\n" 11947 "function Bar() {\n"
11948 " return Baz();\n" 11948 " return Baz();\n"
11949 "}\n" 11949 "}\n"
11950 "\n" 11950 "\n"
11951 "function Baz() {\n" 11951 "function Baz() {\n"
(...skipping 14 matching lines...) Expand all
11966 CheckTryCatchSourceInfo(script, resource_name, 0); 11966 CheckTryCatchSourceInfo(script, resource_name, 0);
11967 11967
11968 resource_name = "test2.js"; 11968 resource_name = "test2.js";
11969 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7)); 11969 v8::ScriptOrigin origin2(v8::String::New(resource_name), v8::Integer::New(7));
11970 script = v8::Script::Compile(source, &origin2); 11970 script = v8::Script::Compile(source, &origin2);
11971 CheckTryCatchSourceInfo(script, resource_name, 7); 11971 CheckTryCatchSourceInfo(script, resource_name, 7);
11972 } 11972 }
11973 11973
11974 11974
11975 THREADED_TEST(CompilationCache) { 11975 THREADED_TEST(CompilationCache) {
11976 v8::HandleScope scope;
11977 LocalContext context; 11976 LocalContext context;
11977 v8::HandleScope scope(context->GetIsolate());
11978 v8::Handle<v8::String> source0 = v8::String::New("1234"); 11978 v8::Handle<v8::String> source0 = v8::String::New("1234");
11979 v8::Handle<v8::String> source1 = v8::String::New("1234"); 11979 v8::Handle<v8::String> source1 = v8::String::New("1234");
11980 v8::Handle<v8::Script> script0 = 11980 v8::Handle<v8::Script> script0 =
11981 v8::Script::Compile(source0, v8::String::New("test.js")); 11981 v8::Script::Compile(source0, v8::String::New("test.js"));
11982 v8::Handle<v8::Script> script1 = 11982 v8::Handle<v8::Script> script1 =
11983 v8::Script::Compile(source1, v8::String::New("test.js")); 11983 v8::Script::Compile(source1, v8::String::New("test.js"));
11984 v8::Handle<v8::Script> script2 = 11984 v8::Handle<v8::Script> script2 =
11985 v8::Script::Compile(source0); // different origin 11985 v8::Script::Compile(source0); // different origin
11986 CHECK_EQ(1234, script0->Run()->Int32Value()); 11986 CHECK_EQ(1234, script0->Run()->Int32Value());
11987 CHECK_EQ(1234, script1->Run()->Int32Value()); 11987 CHECK_EQ(1234, script1->Run()->Int32Value());
11988 CHECK_EQ(1234, script2->Run()->Int32Value()); 11988 CHECK_EQ(1234, script2->Run()->Int32Value());
11989 } 11989 }
11990 11990
11991 11991
11992 static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) { 11992 static v8::Handle<Value> FunctionNameCallback(const v8::Arguments& args) {
11993 ApiTestFuzzer::Fuzz(); 11993 ApiTestFuzzer::Fuzz();
11994 return v8_num(42); 11994 return v8_num(42);
11995 } 11995 }
11996 11996
11997 11997
11998 THREADED_TEST(CallbackFunctionName) { 11998 THREADED_TEST(CallbackFunctionName) {
11999 v8::HandleScope scope;
12000 LocalContext context; 11999 LocalContext context;
12000 v8::HandleScope scope(context->GetIsolate());
12001 Local<ObjectTemplate> t = ObjectTemplate::New(); 12001 Local<ObjectTemplate> t = ObjectTemplate::New();
12002 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback)); 12002 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback));
12003 context->Global()->Set(v8_str("obj"), t->NewInstance()); 12003 context->Global()->Set(v8_str("obj"), t->NewInstance());
12004 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 12004 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
12005 CHECK(value->IsString()); 12005 CHECK(value->IsString());
12006 v8::String::AsciiValue name(value); 12006 v8::String::AsciiValue name(value);
12007 CHECK_EQ("asdf", *name); 12007 CHECK_EQ("asdf", *name);
12008 } 12008 }
12009 12009
12010 12010
12011 THREADED_TEST(DateAccess) { 12011 THREADED_TEST(DateAccess) {
12012 v8::HandleScope scope;
12013 LocalContext context; 12012 LocalContext context;
12013 v8::HandleScope scope(context->GetIsolate());
12014 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0); 12014 v8::Handle<v8::Value> date = v8::Date::New(1224744689038.0);
12015 CHECK(date->IsDate()); 12015 CHECK(date->IsDate());
12016 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue()); 12016 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->NumberValue());
12017 } 12017 }
12018 12018
12019 12019
12020 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) { 12020 void CheckProperties(v8::Handle<v8::Value> val, int elmc, const char* elmv[]) {
12021 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 12021 v8::Handle<v8::Object> obj = val.As<v8::Object>();
12022 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 12022 v8::Handle<v8::Array> props = obj->GetPropertyNames();
12023 CHECK_EQ(elmc, props->Length()); 12023 CHECK_EQ(elmc, props->Length());
(...skipping 11 matching lines...) Expand all
12035 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); 12035 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames();
12036 CHECK_EQ(elmc, props->Length()); 12036 CHECK_EQ(elmc, props->Length());
12037 for (int i = 0; i < elmc; i++) { 12037 for (int i = 0; i < elmc; i++) {
12038 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i))); 12038 v8::String::Utf8Value elm(props->Get(v8::Integer::New(i)));
12039 CHECK_EQ(elmv[i], *elm); 12039 CHECK_EQ(elmv[i], *elm);
12040 } 12040 }
12041 } 12041 }
12042 12042
12043 12043
12044 THREADED_TEST(PropertyEnumeration) { 12044 THREADED_TEST(PropertyEnumeration) {
12045 v8::HandleScope scope;
12046 LocalContext context; 12045 LocalContext context;
12046 v8::HandleScope scope(context->GetIsolate());
12047 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 12047 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New(
12048 "var result = [];" 12048 "var result = [];"
12049 "result[0] = {};" 12049 "result[0] = {};"
12050 "result[1] = {a: 1, b: 2};" 12050 "result[1] = {a: 1, b: 2};"
12051 "result[2] = [1, 2, 3];" 12051 "result[2] = [1, 2, 3];"
12052 "var proto = {x: 1, y: 2, z: 3};" 12052 "var proto = {x: 1, y: 2, z: 3};"
12053 "var x = { __proto__: proto, w: 0, z: 1 };" 12053 "var x = { __proto__: proto, w: 0, z: 1 };"
12054 "result[3] = x;" 12054 "result[3] = x;"
12055 "result;"))->Run(); 12055 "result;"))->Run();
12056 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 12056 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
(...skipping 12 matching lines...) Expand all
12069 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2); 12069 CheckOwnProperties(elms->Get(v8::Integer::New(2)), elmc2, elmv2);
12070 int elmc3 = 4; 12070 int elmc3 = 4;
12071 const char* elmv3[] = {"w", "z", "x", "y"}; 12071 const char* elmv3[] = {"w", "z", "x", "y"};
12072 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3); 12072 CheckProperties(elms->Get(v8::Integer::New(3)), elmc3, elmv3);
12073 int elmc4 = 2; 12073 int elmc4 = 2;
12074 const char* elmv4[] = {"w", "z"}; 12074 const char* elmv4[] = {"w", "z"};
12075 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4); 12075 CheckOwnProperties(elms->Get(v8::Integer::New(3)), elmc4, elmv4);
12076 } 12076 }
12077 12077
12078 THREADED_TEST(PropertyEnumeration2) { 12078 THREADED_TEST(PropertyEnumeration2) {
12079 v8::HandleScope scope;
12080 LocalContext context; 12079 LocalContext context;
12080 v8::HandleScope scope(context->GetIsolate());
12081 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New( 12081 v8::Handle<v8::Value> obj = v8::Script::Compile(v8::String::New(
12082 "var result = [];" 12082 "var result = [];"
12083 "result[0] = {};" 12083 "result[0] = {};"
12084 "result[1] = {a: 1, b: 2};" 12084 "result[1] = {a: 1, b: 2};"
12085 "result[2] = [1, 2, 3];" 12085 "result[2] = [1, 2, 3];"
12086 "var proto = {x: 1, y: 2, z: 3};" 12086 "var proto = {x: 1, y: 2, z: 3};"
12087 "var x = { __proto__: proto, w: 0, z: 1 };" 12087 "var x = { __proto__: proto, w: 0, z: 1 };"
12088 "result[3] = x;" 12088 "result[3] = x;"
12089 "result;"))->Run(); 12089 "result;"))->Run();
12090 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 12090 v8::Handle<v8::Array> elms = obj.As<v8::Array>();
(...skipping 20 matching lines...) Expand all
12111 12111
12112 static bool IndexedSetAccessBlocker(Local<v8::Object> obj, 12112 static bool IndexedSetAccessBlocker(Local<v8::Object> obj,
12113 uint32_t key, 12113 uint32_t key,
12114 v8::AccessType type, 12114 v8::AccessType type,
12115 Local<Value> data) { 12115 Local<Value> data) {
12116 return type != v8::ACCESS_SET; 12116 return type != v8::ACCESS_SET;
12117 } 12117 }
12118 12118
12119 12119
12120 THREADED_TEST(DisableAccessChecksWhileConfiguring) { 12120 THREADED_TEST(DisableAccessChecksWhileConfiguring) {
12121 v8::HandleScope scope;
12122 LocalContext context; 12121 LocalContext context;
12122 v8::HandleScope scope(context->GetIsolate());
12123 Local<ObjectTemplate> templ = ObjectTemplate::New(); 12123 Local<ObjectTemplate> templ = ObjectTemplate::New();
12124 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, 12124 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
12125 IndexedSetAccessBlocker); 12125 IndexedSetAccessBlocker);
12126 templ->Set(v8_str("x"), v8::True()); 12126 templ->Set(v8_str("x"), v8::True());
12127 Local<v8::Object> instance = templ->NewInstance(); 12127 Local<v8::Object> instance = templ->NewInstance();
12128 context->Global()->Set(v8_str("obj"), instance); 12128 context->Global()->Set(v8_str("obj"), instance);
12129 Local<Value> value = CompileRun("obj.x"); 12129 Local<Value> value = CompileRun("obj.x");
12130 CHECK(value->BooleanValue()); 12130 CHECK(value->BooleanValue());
12131 } 12131 }
12132 12132
12133 12133
12134 static bool NamedGetAccessBlocker(Local<v8::Object> obj, 12134 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
12135 Local<Value> name, 12135 Local<Value> name,
12136 v8::AccessType type, 12136 v8::AccessType type,
12137 Local<Value> data) { 12137 Local<Value> data) {
12138 return false; 12138 return false;
12139 } 12139 }
12140 12140
12141 12141
12142 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, 12142 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
12143 uint32_t key, 12143 uint32_t key,
12144 v8::AccessType type, 12144 v8::AccessType type,
12145 Local<Value> data) { 12145 Local<Value> data) {
12146 return false; 12146 return false;
12147 } 12147 }
12148 12148
12149 12149
12150 12150
12151 THREADED_TEST(AccessChecksReenabledCorrectly) { 12151 THREADED_TEST(AccessChecksReenabledCorrectly) {
12152 v8::HandleScope scope;
12153 LocalContext context; 12152 LocalContext context;
12153 v8::HandleScope scope(context->GetIsolate());
12154 Local<ObjectTemplate> templ = ObjectTemplate::New(); 12154 Local<ObjectTemplate> templ = ObjectTemplate::New();
12155 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker, 12155 templ->SetAccessCheckCallbacks(NamedGetAccessBlocker,
12156 IndexedGetAccessBlocker); 12156 IndexedGetAccessBlocker);
12157 templ->Set(v8_str("a"), v8_str("a")); 12157 templ->Set(v8_str("a"), v8_str("a"));
12158 // Add more than 8 (see kMaxFastProperties) properties 12158 // Add more than 8 (see kMaxFastProperties) properties
12159 // so that the constructor will force copying map. 12159 // so that the constructor will force copying map.
12160 // Cannot sprintf, gcc complains unsafety. 12160 // Cannot sprintf, gcc complains unsafety.
12161 char buf[4]; 12161 char buf[4];
12162 for (char i = '0'; i <= '9' ; i++) { 12162 for (char i = '0'; i <= '9' ; i++) {
12163 buf[0] = i; 12163 buf[0] = i;
(...skipping 17 matching lines...) Expand all
12181 context->Global()->Set(v8_str("obj_2"), instance_2); 12181 context->Global()->Set(v8_str("obj_2"), instance_2);
12182 12182
12183 Local<Value> value_2 = CompileRun("obj_2.a"); 12183 Local<Value> value_2 = CompileRun("obj_2.a");
12184 CHECK(value_2->IsUndefined()); 12184 CHECK(value_2->IsUndefined());
12185 } 12185 }
12186 12186
12187 12187
12188 // This tests that access check information remains on the global 12188 // This tests that access check information remains on the global
12189 // object template when creating contexts. 12189 // object template when creating contexts.
12190 THREADED_TEST(AccessControlRepeatedContextCreation) { 12190 THREADED_TEST(AccessControlRepeatedContextCreation) {
12191 v8::HandleScope handle_scope; 12191 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12192 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12192 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12193 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 12193 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
12194 IndexedSetAccessBlocker); 12194 IndexedSetAccessBlocker);
12195 i::Handle<i::ObjectTemplateInfo> internal_template = 12195 i::Handle<i::ObjectTemplateInfo> internal_template =
12196 v8::Utils::OpenHandle(*global_template); 12196 v8::Utils::OpenHandle(*global_template);
12197 CHECK(!internal_template->constructor()->IsUndefined()); 12197 CHECK(!internal_template->constructor()->IsUndefined());
12198 i::Handle<i::FunctionTemplateInfo> constructor( 12198 i::Handle<i::FunctionTemplateInfo> constructor(
12199 i::FunctionTemplateInfo::cast(internal_template->constructor())); 12199 i::FunctionTemplateInfo::cast(internal_template->constructor()));
12200 CHECK(!constructor->access_check_info()->IsUndefined()); 12200 CHECK(!constructor->access_check_info()->IsUndefined());
12201 v8::Persistent<Context> context0(Context::New(NULL, global_template)); 12201 v8::Persistent<Context> context0(Context::New(NULL, global_template));
12202 CHECK(!context0.IsEmpty()); 12202 CHECK(!context0.IsEmpty());
12203 CHECK(!constructor->access_check_info()->IsUndefined()); 12203 CHECK(!constructor->access_check_info()->IsUndefined());
12204 } 12204 }
12205 12205
12206 12206
12207 THREADED_TEST(TurnOnAccessCheck) { 12207 THREADED_TEST(TurnOnAccessCheck) {
12208 v8::HandleScope handle_scope; 12208 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12209 12209
12210 // Create an environment with access check to the global object disabled by 12210 // Create an environment with access check to the global object disabled by
12211 // default. 12211 // default.
12212 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12212 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12213 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 12213 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
12214 IndexedGetAccessBlocker, 12214 IndexedGetAccessBlocker,
12215 v8::Handle<v8::Value>(), 12215 v8::Handle<v8::Value>(),
12216 false); 12216 false);
12217 v8::Persistent<Context> context = Context::New(NULL, global_template); 12217 v8::Persistent<Context> context = Context::New(NULL, global_template);
12218 Context::Scope context_scope(context); 12218 Context::Scope context_scope(context);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
12278 Local<Value> data) { 12278 Local<Value> data) {
12279 if (!name->IsString()) return false; 12279 if (!name->IsString()) return false;
12280 i::Handle<i::String> name_handle = 12280 i::Handle<i::String> name_handle =
12281 v8::Utils::OpenHandle(String::Cast(*name)); 12281 v8::Utils::OpenHandle(String::Cast(*name));
12282 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA)) 12282 return !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyA))
12283 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH)); 12283 && !name_handle->IsUtf8EqualTo(i::CStrVector(kPropertyH));
12284 } 12284 }
12285 12285
12286 12286
12287 THREADED_TEST(TurnOnAccessCheckAndRecompile) { 12287 THREADED_TEST(TurnOnAccessCheckAndRecompile) {
12288 v8::HandleScope handle_scope; 12288 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
12289 12289
12290 // Create an environment with access check to the global object disabled by 12290 // Create an environment with access check to the global object disabled by
12291 // default. When the registered access checker will block access to properties 12291 // default. When the registered access checker will block access to properties
12292 // a and h. 12292 // a and h.
12293 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 12293 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
12294 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH, 12294 global_template->SetAccessCheckCallbacks(NamedGetAccessBlockAandH,
12295 IndexedGetAccessBlocker, 12295 IndexedGetAccessBlocker,
12296 v8::Handle<v8::Value>(), 12296 v8::Handle<v8::Value>(),
12297 false); 12297 false);
12298 v8::Persistent<Context> context = Context::New(NULL, global_template); 12298 v8::Persistent<Context> context = Context::New(NULL, global_template);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
12442 12442
12443 CHECK_EQ(0, sd->Length()); 12443 CHECK_EQ(0, sd->Length());
12444 12444
12445 delete sd; 12445 delete sd;
12446 } 12446 }
12447 12447
12448 12448
12449 // Attempts to deserialize bad data. 12449 // Attempts to deserialize bad data.
12450 TEST(PreCompileInvalidPreparseDataError) { 12450 TEST(PreCompileInvalidPreparseDataError) {
12451 v8::V8::Initialize(); 12451 v8::V8::Initialize();
12452 v8::HandleScope scope;
12453 LocalContext context; 12452 LocalContext context;
12453 v8::HandleScope scope(context->GetIsolate());
12454 12454
12455 const char* script = "function foo(){ return 5;}\n" 12455 const char* script = "function foo(){ return 5;}\n"
12456 "function bar(){ return 6 + 7;} foo();"; 12456 "function bar(){ return 6 + 7;} foo();";
12457 v8::ScriptData* sd = 12457 v8::ScriptData* sd =
12458 v8::ScriptData::PreCompile(script, i::StrLength(script)); 12458 v8::ScriptData::PreCompile(script, i::StrLength(script));
12459 CHECK(!sd->HasError()); 12459 CHECK(!sd->HasError());
12460 // ScriptDataImpl private implementation details 12460 // ScriptDataImpl private implementation details
12461 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize; 12461 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize;
12462 const int kFunctionEntrySize = i::FunctionEntry::kSize; 12462 const int kFunctionEntrySize = i::FunctionEntry::kSize;
12463 const int kFunctionEntryStartOffset = 0; 12463 const int kFunctionEntryStartOffset = 0;
(...skipping 25 matching lines...) Expand all
12489 CHECK(!try_catch.HasCaught()); 12489 CHECK(!try_catch.HasCaught());
12490 12490
12491 delete sd; 12491 delete sd;
12492 } 12492 }
12493 12493
12494 12494
12495 // Verifies that the Handle<String> and const char* versions of the API produce 12495 // Verifies that the Handle<String> and const char* versions of the API produce
12496 // the same results (at least for one trivial case). 12496 // the same results (at least for one trivial case).
12497 TEST(PreCompileAPIVariationsAreSame) { 12497 TEST(PreCompileAPIVariationsAreSame) {
12498 v8::V8::Initialize(); 12498 v8::V8::Initialize();
12499 v8::HandleScope scope; 12499 v8::HandleScope scope(v8::Isolate::GetCurrent());
12500 12500
12501 const char* cstring = "function foo(a) { return a+1; }"; 12501 const char* cstring = "function foo(a) { return a+1; }";
12502 12502
12503 v8::ScriptData* sd_from_cstring = 12503 v8::ScriptData* sd_from_cstring =
12504 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring)); 12504 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring));
12505 12505
12506 TestAsciiResource* resource = new TestAsciiResource(cstring); 12506 TestAsciiResource* resource = new TestAsciiResource(cstring);
12507 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 12507 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
12508 v8::String::NewExternal(resource)); 12508 v8::String::NewExternal(resource));
12509 12509
(...skipping 16 matching lines...) Expand all
12526 delete sd_from_string; 12526 delete sd_from_string;
12527 } 12527 }
12528 12528
12529 12529
12530 // This tests that we do not allow dictionary load/call inline caches 12530 // This tests that we do not allow dictionary load/call inline caches
12531 // to use functions that have not yet been compiled. The potential 12531 // to use functions that have not yet been compiled. The potential
12532 // problem of loading a function that has not yet been compiled can 12532 // problem of loading a function that has not yet been compiled can
12533 // arise because we share code between contexts via the compilation 12533 // arise because we share code between contexts via the compilation
12534 // cache. 12534 // cache.
12535 THREADED_TEST(DictionaryICLoadedFunction) { 12535 THREADED_TEST(DictionaryICLoadedFunction) {
12536 v8::HandleScope scope; 12536 v8::HandleScope scope(v8::Isolate::GetCurrent());
12537 // Test LoadIC. 12537 // Test LoadIC.
12538 for (int i = 0; i < 2; i++) { 12538 for (int i = 0; i < 2; i++) {
12539 LocalContext context; 12539 LocalContext context;
12540 context->Global()->Set(v8_str("tmp"), v8::True()); 12540 context->Global()->Set(v8_str("tmp"), v8::True());
12541 context->Global()->Delete(v8_str("tmp")); 12541 context->Global()->Delete(v8_str("tmp"));
12542 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); 12542 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');");
12543 } 12543 }
12544 // Test CallIC. 12544 // Test CallIC.
12545 for (int i = 0; i < 2; i++) { 12545 for (int i = 0; i < 2; i++) {
12546 LocalContext context; 12546 LocalContext context;
12547 context->Global()->Set(v8_str("tmp"), v8::True()); 12547 context->Global()->Set(v8_str("tmp"), v8::True());
12548 context->Global()->Delete(v8_str("tmp")); 12548 context->Global()->Delete(v8_str("tmp"));
12549 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); 12549 CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
12550 } 12550 }
12551 } 12551 }
12552 12552
12553 12553
12554 // Test that cross-context new calls use the context of the callee to 12554 // Test that cross-context new calls use the context of the callee to
12555 // create the new JavaScript object. 12555 // create the new JavaScript object.
12556 THREADED_TEST(CrossContextNew) { 12556 THREADED_TEST(CrossContextNew) {
12557 v8::HandleScope scope; 12557 v8::HandleScope scope(v8::Isolate::GetCurrent());
12558 v8::Persistent<Context> context0 = Context::New(); 12558 v8::Persistent<Context> context0 = Context::New();
12559 v8::Persistent<Context> context1 = Context::New(); 12559 v8::Persistent<Context> context1 = Context::New();
12560 12560
12561 // Allow cross-domain access. 12561 // Allow cross-domain access.
12562 Local<String> token = v8_str("<security token>"); 12562 Local<String> token = v8_str("<security token>");
12563 context0->SetSecurityToken(token); 12563 context0->SetSecurityToken(token);
12564 context1->SetSecurityToken(token); 12564 context1->SetSecurityToken(token);
12565 12565
12566 // Set an 'x' property on the Object prototype and define a 12566 // Set an 'x' property on the Object prototype and define a
12567 // constructor function in context0. 12567 // constructor function in context0.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
12682 bool regexp_success_; 12682 bool regexp_success_;
12683 bool gc_success_; 12683 bool gc_success_;
12684 }; 12684 };
12685 12685
12686 12686
12687 // Test that a regular expression execution can be interrupted and 12687 // Test that a regular expression execution can be interrupted and
12688 // survive a garbage collection. 12688 // survive a garbage collection.
12689 TEST(RegExpInterruption) { 12689 TEST(RegExpInterruption) {
12690 v8::Locker lock(CcTest::default_isolate()); 12690 v8::Locker lock(CcTest::default_isolate());
12691 v8::V8::Initialize(); 12691 v8::V8::Initialize();
12692 v8::HandleScope scope; 12692 v8::HandleScope scope(CcTest::default_isolate());
12693 Local<Context> local_env; 12693 Local<Context> local_env;
12694 { 12694 {
12695 LocalContext env; 12695 LocalContext env;
12696 local_env = env.local(); 12696 local_env = env.local();
12697 } 12697 }
12698 12698
12699 // Local context should still be live. 12699 // Local context should still be live.
12700 CHECK(!local_env.IsEmpty()); 12700 CHECK(!local_env.IsEmpty());
12701 local_env->Enter(); 12701 local_env->Enter();
12702 12702
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
12791 bool apply_success_; 12791 bool apply_success_;
12792 bool gc_success_; 12792 bool gc_success_;
12793 }; 12793 };
12794 12794
12795 12795
12796 // Test that nothing bad happens if we get a preemption just when we were 12796 // Test that nothing bad happens if we get a preemption just when we were
12797 // about to do an apply(). 12797 // about to do an apply().
12798 TEST(ApplyInterruption) { 12798 TEST(ApplyInterruption) {
12799 v8::Locker lock(CcTest::default_isolate()); 12799 v8::Locker lock(CcTest::default_isolate());
12800 v8::V8::Initialize(); 12800 v8::V8::Initialize();
12801 v8::HandleScope scope; 12801 v8::HandleScope scope(CcTest::default_isolate());
12802 Local<Context> local_env; 12802 Local<Context> local_env;
12803 { 12803 {
12804 LocalContext env; 12804 LocalContext env;
12805 local_env = env.local(); 12805 local_env = env.local();
12806 } 12806 }
12807 12807
12808 // Local context should still be live. 12808 // Local context should still be live.
12809 CHECK(!local_env.IsEmpty()); 12809 CHECK(!local_env.IsEmpty());
12810 local_env->Enter(); 12810 local_env->Enter();
12811 12811
12812 // Should complete without problems. 12812 // Should complete without problems.
12813 ApplyInterruptTest().RunTest(); 12813 ApplyInterruptTest().RunTest();
12814 12814
12815 local_env->Exit(); 12815 local_env->Exit();
12816 } 12816 }
12817 12817
12818 12818
12819 // Verify that we can clone an object 12819 // Verify that we can clone an object
12820 TEST(ObjectClone) { 12820 TEST(ObjectClone) {
12821 v8::HandleScope scope;
12822 LocalContext env; 12821 LocalContext env;
12822 v8::HandleScope scope(env->GetIsolate());
12823 12823
12824 const char* sample = 12824 const char* sample =
12825 "var rv = {};" \ 12825 "var rv = {};" \
12826 "rv.alpha = 'hello';" \ 12826 "rv.alpha = 'hello';" \
12827 "rv.beta = 123;" \ 12827 "rv.beta = 123;" \
12828 "rv;"; 12828 "rv;";
12829 12829
12830 // Create an object, verify basics. 12830 // Create an object, verify basics.
12831 Local<Value> val = CompileRun(sample); 12831 Local<Value> val = CompileRun(sample);
12832 CHECK(val->IsObject()); 12832 CHECK(val->IsObject());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
12899 12899
12900 12900
12901 // Test that we can still flatten a string if the components it is built up 12901 // Test that we can still flatten a string if the components it is built up
12902 // from have been turned into 16 bit strings in the mean time. 12902 // from have been turned into 16 bit strings in the mean time.
12903 THREADED_TEST(MorphCompositeStringTest) { 12903 THREADED_TEST(MorphCompositeStringTest) {
12904 char utf_buffer[129]; 12904 char utf_buffer[129];
12905 const char* c_string = "Now is the time for all good men" 12905 const char* c_string = "Now is the time for all good men"
12906 " to come to the aid of the party"; 12906 " to come to the aid of the party";
12907 uint16_t* two_byte_string = AsciiToTwoByteString(c_string); 12907 uint16_t* two_byte_string = AsciiToTwoByteString(c_string);
12908 { 12908 {
12909 v8::HandleScope scope;
12910 LocalContext env; 12909 LocalContext env;
12910 v8::HandleScope scope(env->GetIsolate());
12911 AsciiVectorResource ascii_resource( 12911 AsciiVectorResource ascii_resource(
12912 i::Vector<const char>(c_string, i::StrLength(c_string))); 12912 i::Vector<const char>(c_string, i::StrLength(c_string)));
12913 UC16VectorResource uc16_resource( 12913 UC16VectorResource uc16_resource(
12914 i::Vector<const uint16_t>(two_byte_string, 12914 i::Vector<const uint16_t>(two_byte_string,
12915 i::StrLength(c_string))); 12915 i::StrLength(c_string)));
12916 12916
12917 Local<String> lhs(v8::Utils::ToLocal( 12917 Local<String> lhs(v8::Utils::ToLocal(
12918 FACTORY->NewExternalStringFromAscii(&ascii_resource))); 12918 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
12919 Local<String> rhs(v8::Utils::ToLocal( 12919 Local<String> rhs(v8::Utils::ToLocal(
12920 FACTORY->NewExternalStringFromAscii(&ascii_resource))); 12920 FACTORY->NewExternalStringFromAscii(&ascii_resource)));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
12962 CHECK_EQ(String::New(expected_slice), 12962 CHECK_EQ(String::New(expected_slice),
12963 env->Global()->Get(v8_str("slice"))); 12963 env->Global()->Get(v8_str("slice")));
12964 CHECK_EQ(String::New(expected_slice_on_cons), 12964 CHECK_EQ(String::New(expected_slice_on_cons),
12965 env->Global()->Get(v8_str("slice_on_cons"))); 12965 env->Global()->Get(v8_str("slice_on_cons")));
12966 } 12966 }
12967 i::DeleteArray(two_byte_string); 12967 i::DeleteArray(two_byte_string);
12968 } 12968 }
12969 12969
12970 12970
12971 TEST(CompileExternalTwoByteSource) { 12971 TEST(CompileExternalTwoByteSource) {
12972 v8::HandleScope scope;
12973 LocalContext context; 12972 LocalContext context;
12973 v8::HandleScope scope(context->GetIsolate());
12974 12974
12975 // This is a very short list of sources, which currently is to check for a 12975 // This is a very short list of sources, which currently is to check for a
12976 // regression caused by r2703. 12976 // regression caused by r2703.
12977 const char* ascii_sources[] = { 12977 const char* ascii_sources[] = {
12978 "0.5", 12978 "0.5",
12979 "-0.5", // This mainly testes PushBack in the Scanner. 12979 "-0.5", // This mainly testes PushBack in the Scanner.
12980 "--0.5", // This mainly testes PushBack in the Scanner. 12980 "--0.5", // This mainly testes PushBack in the Scanner.
12981 NULL 12981 NULL
12982 }; 12982 };
12983 12983
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
13071 } 13071 }
13072 morph_success_ = true; 13072 morph_success_ = true;
13073 } 13073 }
13074 13074
13075 void LongRunningRegExp() { 13075 void LongRunningRegExp() {
13076 block_->Signal(); // Enable morphing thread on next preemption. 13076 block_->Signal(); // Enable morphing thread on next preemption.
13077 while (morphs_during_regexp_ < kRequiredModifications && 13077 while (morphs_during_regexp_ < kRequiredModifications &&
13078 morphs_ < kMaxModifications) { 13078 morphs_ < kMaxModifications) {
13079 int morphs_before = morphs_; 13079 int morphs_before = morphs_;
13080 { 13080 {
13081 v8::HandleScope scope; 13081 v8::HandleScope scope(v8::Isolate::GetCurrent());
13082 // Match 15-30 "a"'s against 14 and a "b". 13082 // Match 15-30 "a"'s against 14 and a "b".
13083 const char* c_source = 13083 const char* c_source =
13084 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/" 13084 "/a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaa/"
13085 ".exec(input) === null"; 13085 ".exec(input) === null";
13086 Local<String> source = String::New(c_source); 13086 Local<String> source = String::New(c_source);
13087 Local<Script> script = Script::Compile(source); 13087 Local<Script> script = Script::Compile(source);
13088 Local<Value> result = script->Run(); 13088 Local<Value> result = script->Run();
13089 CHECK(result->IsTrue()); 13089 CHECK(result->IsTrue());
13090 } 13090 }
13091 int morphs_after = morphs_; 13091 int morphs_after = morphs_;
(...skipping 12 matching lines...) Expand all
13104 AsciiVectorResource ascii_resource_; 13104 AsciiVectorResource ascii_resource_;
13105 UC16VectorResource uc16_resource_; 13105 UC16VectorResource uc16_resource_;
13106 }; 13106 };
13107 13107
13108 13108
13109 // Test that a regular expression execution can be interrupted and 13109 // Test that a regular expression execution can be interrupted and
13110 // the string changed without failing. 13110 // the string changed without failing.
13111 TEST(RegExpStringModification) { 13111 TEST(RegExpStringModification) {
13112 v8::Locker lock(CcTest::default_isolate()); 13112 v8::Locker lock(CcTest::default_isolate());
13113 v8::V8::Initialize(); 13113 v8::V8::Initialize();
13114 v8::HandleScope scope; 13114 v8::HandleScope scope(CcTest::default_isolate());
13115 Local<Context> local_env; 13115 Local<Context> local_env;
13116 { 13116 {
13117 LocalContext env; 13117 LocalContext env;
13118 local_env = env.local(); 13118 local_env = env.local();
13119 } 13119 }
13120 13120
13121 // Local context should still be live. 13121 // Local context should still be live.
13122 CHECK(!local_env.IsEmpty()); 13122 CHECK(!local_env.IsEmpty());
13123 local_env->Enter(); 13123 local_env->Enter();
13124 13124
13125 // Should complete without problems. 13125 // Should complete without problems.
13126 RegExpStringModificationTest().RunTest(); 13126 RegExpStringModificationTest().RunTest();
13127 13127
13128 local_env->Exit(); 13128 local_env->Exit();
13129 } 13129 }
13130 13130
13131 13131
13132 // Test that we cannot set a property on the global object if there 13132 // Test that we cannot set a property on the global object if there
13133 // is a read-only property in the prototype chain. 13133 // is a read-only property in the prototype chain.
13134 TEST(ReadOnlyPropertyInGlobalProto) { 13134 TEST(ReadOnlyPropertyInGlobalProto) {
13135 i::FLAG_es5_readonly = true; 13135 i::FLAG_es5_readonly = true;
13136 v8::HandleScope scope; 13136 v8::HandleScope scope(v8::Isolate::GetCurrent());
13137 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13137 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13138 LocalContext context(0, templ); 13138 LocalContext context(0, templ);
13139 v8::Handle<v8::Object> global = context->Global(); 13139 v8::Handle<v8::Object> global = context->Global();
13140 v8::Handle<v8::Object> global_proto = 13140 v8::Handle<v8::Object> global_proto =
13141 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 13141 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__")));
13142 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly); 13142 global_proto->Set(v8_str("x"), v8::Integer::New(0), v8::ReadOnly);
13143 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly); 13143 global_proto->Set(v8_str("y"), v8::Integer::New(0), v8::ReadOnly);
13144 // Check without 'eval' or 'with'. 13144 // Check without 'eval' or 'with'.
13145 v8::Handle<v8::Value> res = 13145 v8::Handle<v8::Value> res =
13146 CompileRun("function f() { x = 42; return x; }; f()"); 13146 CompileRun("function f() { x = 42; return x; }; f()");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
13179 const v8::AccessorInfo& info) { 13179 const v8::AccessorInfo& info) {
13180 force_set_set_count++; 13180 force_set_set_count++;
13181 return v8::Undefined(); 13181 return v8::Undefined();
13182 } 13182 }
13183 13183
13184 TEST(ForceSet) { 13184 TEST(ForceSet) {
13185 force_set_get_count = 0; 13185 force_set_get_count = 0;
13186 force_set_set_count = 0; 13186 force_set_set_count = 0;
13187 pass_on_get = false; 13187 pass_on_get = false;
13188 13188
13189 v8::HandleScope scope; 13189 v8::HandleScope scope(v8::Isolate::GetCurrent());
13190 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13190 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13191 v8::Handle<v8::String> access_property = v8::String::New("a"); 13191 v8::Handle<v8::String> access_property = v8::String::New("a");
13192 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 13192 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
13193 LocalContext context(NULL, templ); 13193 LocalContext context(NULL, templ);
13194 v8::Handle<v8::Object> global = context->Global(); 13194 v8::Handle<v8::Object> global = context->Global();
13195 13195
13196 // Ordinary properties 13196 // Ordinary properties
13197 v8::Handle<v8::String> simple_property = v8::String::New("p"); 13197 v8::Handle<v8::String> simple_property = v8::String::New("p");
13198 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly); 13198 global->Set(simple_property, v8::Int32::New(4), v8::ReadOnly);
13199 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 13199 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
(...skipping 20 matching lines...) Expand all
13220 CHECK_EQ(8, global->Get(access_property)->Int32Value()); 13220 CHECK_EQ(8, global->Get(access_property)->Int32Value());
13221 CHECK_EQ(1, force_set_set_count); 13221 CHECK_EQ(1, force_set_set_count);
13222 CHECK_EQ(2, force_set_get_count); 13222 CHECK_EQ(2, force_set_get_count);
13223 } 13223 }
13224 13224
13225 TEST(ForceSetWithInterceptor) { 13225 TEST(ForceSetWithInterceptor) {
13226 force_set_get_count = 0; 13226 force_set_get_count = 0;
13227 force_set_set_count = 0; 13227 force_set_set_count = 0;
13228 pass_on_get = false; 13228 pass_on_get = false;
13229 13229
13230 v8::HandleScope scope; 13230 v8::HandleScope scope(v8::Isolate::GetCurrent());
13231 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13231 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13232 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter); 13232 templ->SetNamedPropertyHandler(ForceSetGetter, ForceSetInterceptSetter);
13233 LocalContext context(NULL, templ); 13233 LocalContext context(NULL, templ);
13234 v8::Handle<v8::Object> global = context->Global(); 13234 v8::Handle<v8::Object> global = context->Global();
13235 13235
13236 v8::Handle<v8::String> some_property = v8::String::New("a"); 13236 v8::Handle<v8::String> some_property = v8::String::New("a");
13237 CHECK_EQ(0, force_set_set_count); 13237 CHECK_EQ(0, force_set_set_count);
13238 CHECK_EQ(0, force_set_get_count); 13238 CHECK_EQ(0, force_set_get_count);
13239 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 13239 CHECK_EQ(3, global->Get(some_property)->Int32Value());
13240 // Setting the property shouldn't override it, just call the setter 13240 // Setting the property shouldn't override it, just call the setter
(...skipping 22 matching lines...) Expand all
13263 CHECK_EQ(1, force_set_set_count); 13263 CHECK_EQ(1, force_set_set_count);
13264 CHECK_EQ(5, force_set_get_count); 13264 CHECK_EQ(5, force_set_get_count);
13265 // The interceptor should also work for other properties 13265 // The interceptor should also work for other properties
13266 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value()); 13266 CHECK_EQ(3, global->Get(v8::String::New("b"))->Int32Value());
13267 CHECK_EQ(1, force_set_set_count); 13267 CHECK_EQ(1, force_set_set_count);
13268 CHECK_EQ(6, force_set_get_count); 13268 CHECK_EQ(6, force_set_get_count);
13269 } 13269 }
13270 13270
13271 13271
13272 THREADED_TEST(ForceDelete) { 13272 THREADED_TEST(ForceDelete) {
13273 v8::HandleScope scope; 13273 v8::HandleScope scope(v8::Isolate::GetCurrent());
13274 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13274 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13275 LocalContext context(NULL, templ); 13275 LocalContext context(NULL, templ);
13276 v8::Handle<v8::Object> global = context->Global(); 13276 v8::Handle<v8::Object> global = context->Global();
13277 13277
13278 // Ordinary properties 13278 // Ordinary properties
13279 v8::Handle<v8::String> simple_property = v8::String::New("p"); 13279 v8::Handle<v8::String> simple_property = v8::String::New("p");
13280 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete); 13280 global->Set(simple_property, v8::Int32::New(4), v8::DontDelete);
13281 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 13281 CHECK_EQ(4, global->Get(simple_property)->Int32Value());
13282 // This should fail because the property is dont-delete. 13282 // This should fail because the property is dont-delete.
13283 CHECK(!global->Delete(simple_property)); 13283 CHECK(!global->Delete(simple_property));
(...skipping 17 matching lines...) Expand all
13301 } else { 13301 } else {
13302 return v8::True(); 13302 return v8::True();
13303 } 13303 }
13304 } 13304 }
13305 13305
13306 13306
13307 THREADED_TEST(ForceDeleteWithInterceptor) { 13307 THREADED_TEST(ForceDeleteWithInterceptor) {
13308 force_delete_interceptor_count = 0; 13308 force_delete_interceptor_count = 0;
13309 pass_on_delete = false; 13309 pass_on_delete = false;
13310 13310
13311 v8::HandleScope scope; 13311 v8::HandleScope scope(v8::Isolate::GetCurrent());
13312 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 13312 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
13313 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter); 13313 templ->SetNamedPropertyHandler(0, 0, 0, ForceDeleteDeleter);
13314 LocalContext context(NULL, templ); 13314 LocalContext context(NULL, templ);
13315 v8::Handle<v8::Object> global = context->Global(); 13315 v8::Handle<v8::Object> global = context->Global();
13316 13316
13317 v8::Handle<v8::String> some_property = v8::String::New("a"); 13317 v8::Handle<v8::String> some_property = v8::String::New("a");
13318 global->Set(some_property, v8::Integer::New(42), v8::DontDelete); 13318 global->Set(some_property, v8::Integer::New(42), v8::DontDelete);
13319 13319
13320 // Deleting a property should get intercepted and nothing should 13320 // Deleting a property should get intercepted and nothing should
13321 // happen. 13321 // happen.
(...skipping 11 matching lines...) Expand all
13333 // without calling the interceptor. 13333 // without calling the interceptor.
13334 CHECK(global->ForceDelete(some_property)); 13334 CHECK(global->ForceDelete(some_property));
13335 CHECK(global->Get(some_property)->IsUndefined()); 13335 CHECK(global->Get(some_property)->IsUndefined());
13336 CHECK_EQ(2, force_delete_interceptor_count); 13336 CHECK_EQ(2, force_delete_interceptor_count);
13337 } 13337 }
13338 13338
13339 13339
13340 // Make sure that forcing a delete invalidates any IC stubs, so we 13340 // Make sure that forcing a delete invalidates any IC stubs, so we
13341 // don't read the hole value. 13341 // don't read the hole value.
13342 THREADED_TEST(ForceDeleteIC) { 13342 THREADED_TEST(ForceDeleteIC) {
13343 v8::HandleScope scope;
13344 LocalContext context; 13343 LocalContext context;
13344 v8::HandleScope scope(context->GetIsolate());
13345 // Create a DontDelete variable on the global object. 13345 // Create a DontDelete variable on the global object.
13346 CompileRun("this.__proto__ = { foo: 'horse' };" 13346 CompileRun("this.__proto__ = { foo: 'horse' };"
13347 "var foo = 'fish';" 13347 "var foo = 'fish';"
13348 "function f() { return foo.length; }"); 13348 "function f() { return foo.length; }");
13349 // Initialize the IC for foo in f. 13349 // Initialize the IC for foo in f.
13350 CompileRun("for (var i = 0; i < 4; i++) f();"); 13350 CompileRun("for (var i = 0; i < 4; i++) f();");
13351 // Make sure the value of foo is correct before the deletion. 13351 // Make sure the value of foo is correct before the deletion.
13352 CHECK_EQ(4, CompileRun("f()")->Int32Value()); 13352 CHECK_EQ(4, CompileRun("f()")->Int32Value());
13353 // Force the deletion of foo. 13353 // Force the deletion of foo.
13354 CHECK(context->Global()->ForceDelete(v8_str("foo"))); 13354 CHECK(context->Global()->ForceDelete(v8_str("foo")));
13355 // Make sure the value for foo is read from the prototype, and that 13355 // Make sure the value for foo is read from the prototype, and that
13356 // we don't get in trouble with reading the deleted cell value 13356 // we don't get in trouble with reading the deleted cell value
13357 // sentinel. 13357 // sentinel.
13358 CHECK_EQ(5, CompileRun("f()")->Int32Value()); 13358 CHECK_EQ(5, CompileRun("f()")->Int32Value());
13359 } 13359 }
13360 13360
13361 13361
13362 TEST(InlinedFunctionAcrossContexts) { 13362 TEST(InlinedFunctionAcrossContexts) {
13363 i::FLAG_allow_natives_syntax = true; 13363 i::FLAG_allow_natives_syntax = true;
13364 v8::HandleScope outer_scope; 13364 v8::HandleScope outer_scope(v8::Isolate::GetCurrent());
13365 v8::Persistent<v8::Context> ctx1 = v8::Context::New(); 13365 v8::Persistent<v8::Context> ctx1 = v8::Context::New();
13366 v8::Persistent<v8::Context> ctx2 = v8::Context::New(); 13366 v8::Persistent<v8::Context> ctx2 = v8::Context::New();
13367 ctx1->Enter(); 13367 ctx1->Enter();
13368 13368
13369 { 13369 {
13370 v8::HandleScope inner_scope; 13370 v8::HandleScope inner_scope(v8::Isolate::GetCurrent());
13371 CompileRun("var G = 42; function foo() { return G; }"); 13371 CompileRun("var G = 42; function foo() { return G; }");
13372 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo")); 13372 v8::Local<v8::Value> foo = ctx1->Global()->Get(v8_str("foo"));
13373 ctx2->Enter(); 13373 ctx2->Enter();
13374 ctx2->Global()->Set(v8_str("o"), foo); 13374 ctx2->Global()->Set(v8_str("o"), foo);
13375 v8::Local<v8::Value> res = CompileRun( 13375 v8::Local<v8::Value> res = CompileRun(
13376 "function f() { return o(); }" 13376 "function f() { return o(); }"
13377 "for (var i = 0; i < 10; ++i) f();" 13377 "for (var i = 0; i < 10; ++i) f();"
13378 "%OptimizeFunctionOnNextCall(f);" 13378 "%OptimizeFunctionOnNextCall(f);"
13379 "f();"); 13379 "f();");
13380 CHECK_EQ(42, res->Int32Value()); 13380 CHECK_EQ(42, res->Int32Value());
(...skipping 29 matching lines...) Expand all
13410 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) { 13410 static v8::Handle<Value> GetCallingContextCallback(const v8::Arguments& args) {
13411 ApiTestFuzzer::Fuzz(); 13411 ApiTestFuzzer::Fuzz();
13412 CHECK(Context::GetCurrent() == calling_context0); 13412 CHECK(Context::GetCurrent() == calling_context0);
13413 CHECK(Context::GetCalling() == calling_context1); 13413 CHECK(Context::GetCalling() == calling_context1);
13414 CHECK(Context::GetEntered() == calling_context2); 13414 CHECK(Context::GetEntered() == calling_context2);
13415 return v8::Integer::New(42); 13415 return v8::Integer::New(42);
13416 } 13416 }
13417 13417
13418 13418
13419 THREADED_TEST(GetCallingContext) { 13419 THREADED_TEST(GetCallingContext) {
13420 v8::HandleScope scope; 13420 v8::HandleScope scope(v8::Isolate::GetCurrent());
13421 13421
13422 calling_context0 = Context::New(); 13422 calling_context0 = Context::New();
13423 calling_context1 = Context::New(); 13423 calling_context1 = Context::New();
13424 calling_context2 = Context::New(); 13424 calling_context2 = Context::New();
13425 13425
13426 // Allow cross-domain access. 13426 // Allow cross-domain access.
13427 Local<String> token = v8_str("<security token>"); 13427 Local<String> token = v8_str("<security token>");
13428 calling_context0->SetSecurityToken(token); 13428 calling_context0->SetSecurityToken(token);
13429 calling_context1->SetSecurityToken(token); 13429 calling_context1->SetSecurityToken(token);
13430 calling_context2->SetSecurityToken(token); 13430 calling_context2->SetSecurityToken(token);
(...skipping 29 matching lines...) Expand all
13460 calling_context0.Clear(); 13460 calling_context0.Clear();
13461 calling_context1.Clear(); 13461 calling_context1.Clear();
13462 calling_context2.Clear(); 13462 calling_context2.Clear();
13463 } 13463 }
13464 13464
13465 13465
13466 // Check that a variable declaration with no explicit initialization 13466 // Check that a variable declaration with no explicit initialization
13467 // value does shadow an existing property in the prototype chain. 13467 // value does shadow an existing property in the prototype chain.
13468 THREADED_TEST(InitGlobalVarInProtoChain) { 13468 THREADED_TEST(InitGlobalVarInProtoChain) {
13469 i::FLAG_es52_globals = true; 13469 i::FLAG_es52_globals = true;
13470 v8::HandleScope scope;
13471 LocalContext context; 13470 LocalContext context;
13471 v8::HandleScope scope(context->GetIsolate());
13472 // Introduce a variable in the prototype chain. 13472 // Introduce a variable in the prototype chain.
13473 CompileRun("__proto__.x = 42"); 13473 CompileRun("__proto__.x = 42");
13474 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); 13474 v8::Handle<v8::Value> result = CompileRun("var x = 43; x");
13475 CHECK(!result->IsUndefined()); 13475 CHECK(!result->IsUndefined());
13476 CHECK_EQ(43, result->Int32Value()); 13476 CHECK_EQ(43, result->Int32Value());
13477 } 13477 }
13478 13478
13479 13479
13480 // Regression test for issue 398. 13480 // Regression test for issue 398.
13481 // If a function is added to an object, creating a constant function 13481 // If a function is added to an object, creating a constant function
13482 // field, and the result is cloned, replacing the constant function on the 13482 // field, and the result is cloned, replacing the constant function on the
13483 // original should not affect the clone. 13483 // original should not affect the clone.
13484 // See http://code.google.com/p/v8/issues/detail?id=398 13484 // See http://code.google.com/p/v8/issues/detail?id=398
13485 THREADED_TEST(ReplaceConstantFunction) { 13485 THREADED_TEST(ReplaceConstantFunction) {
13486 v8::HandleScope scope;
13487 LocalContext context; 13486 LocalContext context;
13487 v8::HandleScope scope(context->GetIsolate());
13488 v8::Handle<v8::Object> obj = v8::Object::New(); 13488 v8::Handle<v8::Object> obj = v8::Object::New();
13489 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 13489 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New();
13490 v8::Handle<v8::String> foo_string = v8::String::New("foo"); 13490 v8::Handle<v8::String> foo_string = v8::String::New("foo");
13491 obj->Set(foo_string, func_templ->GetFunction()); 13491 obj->Set(foo_string, func_templ->GetFunction());
13492 v8::Handle<v8::Object> obj_clone = obj->Clone(); 13492 v8::Handle<v8::Object> obj_clone = obj->Clone();
13493 obj_clone->Set(foo_string, v8::String::New("Hello")); 13493 obj_clone->Set(foo_string, v8::String::New("Hello"));
13494 CHECK(!obj->Get(foo_string)->IsUndefined()); 13494 CHECK(!obj->Get(foo_string)->IsUndefined());
13495 } 13495 }
13496 13496
13497 13497
13498 // Regression test for http://crbug.com/16276. 13498 // Regression test for http://crbug.com/16276.
13499 THREADED_TEST(Regress16276) { 13499 THREADED_TEST(Regress16276) {
13500 v8::HandleScope scope;
13501 LocalContext context; 13500 LocalContext context;
13501 v8::HandleScope scope(context->GetIsolate());
13502 // Force the IC in f to be a dictionary load IC. 13502 // Force the IC in f to be a dictionary load IC.
13503 CompileRun("function f(obj) { return obj.x; }\n" 13503 CompileRun("function f(obj) { return obj.x; }\n"
13504 "var obj = { x: { foo: 42 }, y: 87 };\n" 13504 "var obj = { x: { foo: 42 }, y: 87 };\n"
13505 "var x = obj.x;\n" 13505 "var x = obj.x;\n"
13506 "delete obj.y;\n" 13506 "delete obj.y;\n"
13507 "for (var i = 0; i < 5; i++) f(obj);"); 13507 "for (var i = 0; i < 5; i++) f(obj);");
13508 // Detach the global object to make 'this' refer directly to the 13508 // Detach the global object to make 'this' refer directly to the
13509 // global object (not the proxy), and make sure that the dictionary 13509 // global object (not the proxy), and make sure that the dictionary
13510 // load IC doesn't mess up loading directly from the global object. 13510 // load IC doesn't mess up loading directly from the global object.
13511 context->DetachGlobal(); 13511 context->DetachGlobal();
13512 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 13512 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
13513 } 13513 }
13514 13514
13515 13515
13516 THREADED_TEST(PixelArray) { 13516 THREADED_TEST(PixelArray) {
13517 v8::HandleScope scope;
13518 LocalContext context; 13517 LocalContext context;
13518 v8::HandleScope scope(context->GetIsolate());
13519 const int kElementCount = 260; 13519 const int kElementCount = 260;
13520 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 13520 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13521 i::Handle<i::ExternalPixelArray> pixels = 13521 i::Handle<i::ExternalPixelArray> pixels =
13522 i::Handle<i::ExternalPixelArray>::cast( 13522 i::Handle<i::ExternalPixelArray>::cast(
13523 FACTORY->NewExternalArray(kElementCount, 13523 FACTORY->NewExternalArray(kElementCount,
13524 v8::kExternalPixelArray, 13524 v8::kExternalPixelArray,
13525 pixel_data)); 13525 pixel_data));
13526 // Force GC to trigger verification. 13526 // Force GC to trigger verification.
13527 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 13527 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
13528 for (int i = 0; i < kElementCount; i++) { 13528 for (int i = 0; i < kElementCount; i++) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
13897 "}" 13897 "}"
13898 "result = pa_load(pixels);" 13898 "result = pa_load(pixels);"
13899 "result"); 13899 "result");
13900 CHECK_EQ(32640, result->Int32Value()); 13900 CHECK_EQ(32640, result->Int32Value());
13901 13901
13902 free(pixel_data); 13902 free(pixel_data);
13903 } 13903 }
13904 13904
13905 13905
13906 THREADED_TEST(PixelArrayInfo) { 13906 THREADED_TEST(PixelArrayInfo) {
13907 v8::HandleScope scope;
13908 LocalContext context; 13907 LocalContext context;
13908 v8::HandleScope scope(context->GetIsolate());
13909 for (int size = 0; size < 100; size += 10) { 13909 for (int size = 0; size < 100; size += 10) {
13910 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 13910 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
13911 v8::Handle<v8::Object> obj = v8::Object::New(); 13911 v8::Handle<v8::Object> obj = v8::Object::New();
13912 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 13912 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
13913 CHECK(obj->HasIndexedPropertiesInPixelData()); 13913 CHECK(obj->HasIndexedPropertiesInPixelData());
13914 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 13914 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
13915 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 13915 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
13916 free(pixel_data); 13916 free(pixel_data);
13917 } 13917 }
13918 } 13918 }
(...skipping 10 matching lines...) Expand all
13929 static v8::Handle<Value> NotHandledIndexedPropertySetter( 13929 static v8::Handle<Value> NotHandledIndexedPropertySetter(
13930 uint32_t index, 13930 uint32_t index,
13931 Local<Value> value, 13931 Local<Value> value,
13932 const AccessorInfo& info) { 13932 const AccessorInfo& info) {
13933 ApiTestFuzzer::Fuzz(); 13933 ApiTestFuzzer::Fuzz();
13934 return v8::Handle<Value>(); 13934 return v8::Handle<Value>();
13935 } 13935 }
13936 13936
13937 13937
13938 THREADED_TEST(PixelArrayWithInterceptor) { 13938 THREADED_TEST(PixelArrayWithInterceptor) {
13939 v8::HandleScope scope;
13940 LocalContext context; 13939 LocalContext context;
13940 v8::HandleScope scope(context->GetIsolate());
13941 const int kElementCount = 260; 13941 const int kElementCount = 260;
13942 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 13942 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
13943 i::Handle<i::ExternalPixelArray> pixels = 13943 i::Handle<i::ExternalPixelArray> pixels =
13944 i::Handle<i::ExternalPixelArray>::cast( 13944 i::Handle<i::ExternalPixelArray>::cast(
13945 FACTORY->NewExternalArray(kElementCount, 13945 FACTORY->NewExternalArray(kElementCount,
13946 v8::kExternalPixelArray, 13946 v8::kExternalPixelArray,
13947 pixel_data)); 13947 pixel_data));
13948 for (int i = 0; i < kElementCount; i++) { 13948 for (int i = 0; i < kElementCount; i++) {
13949 pixels->set(i, i % 256); 13949 pixels->set(i, i % 256);
13950 } 13950 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
13993 } 13993 }
13994 UNREACHABLE(); 13994 UNREACHABLE();
13995 return -1; 13995 return -1;
13996 } 13996 }
13997 13997
13998 13998
13999 template <class ExternalArrayClass, class ElementType> 13999 template <class ExternalArrayClass, class ElementType>
14000 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type, 14000 static void ExternalArrayTestHelper(v8::ExternalArrayType array_type,
14001 int64_t low, 14001 int64_t low,
14002 int64_t high) { 14002 int64_t high) {
14003 v8::HandleScope scope;
14004 LocalContext context; 14003 LocalContext context;
14004 v8::HandleScope scope(context->GetIsolate());
14005 const int kElementCount = 40; 14005 const int kElementCount = 40;
14006 int element_size = ExternalArrayElementSize(array_type); 14006 int element_size = ExternalArrayElementSize(array_type);
14007 ElementType* array_data = 14007 ElementType* array_data =
14008 static_cast<ElementType*>(malloc(kElementCount * element_size)); 14008 static_cast<ElementType*>(malloc(kElementCount * element_size));
14009 i::Handle<ExternalArrayClass> array = 14009 i::Handle<ExternalArrayClass> array =
14010 i::Handle<ExternalArrayClass>::cast( 14010 i::Handle<ExternalArrayClass>::cast(
14011 FACTORY->NewExternalArray(kElementCount, array_type, array_data)); 14011 FACTORY->NewExternalArray(kElementCount, array_type, array_data));
14012 // Force GC to trigger verification. 14012 // Force GC to trigger verification.
14013 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 14013 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
14014 for (int i = 0; i < kElementCount; i++) { 14014 for (int i = 0; i < kElementCount; i++) {
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
14564 TestExternalUnsignedByteArray(); 14564 TestExternalUnsignedByteArray();
14565 TestExternalShortArray(); 14565 TestExternalShortArray();
14566 TestExternalUnsignedShortArray(); 14566 TestExternalUnsignedShortArray();
14567 TestExternalIntArray(); 14567 TestExternalIntArray();
14568 TestExternalUnsignedIntArray(); 14568 TestExternalUnsignedIntArray();
14569 TestExternalFloatArray(); 14569 TestExternalFloatArray();
14570 } 14570 }
14571 14571
14572 14572
14573 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) { 14573 void ExternalArrayInfoTestHelper(v8::ExternalArrayType array_type) {
14574 v8::HandleScope scope;
14575 LocalContext context; 14574 LocalContext context;
14575 v8::HandleScope scope(context->GetIsolate());
14576 for (int size = 0; size < 100; size += 10) { 14576 for (int size = 0; size < 100; size += 10) {
14577 int element_size = ExternalArrayElementSize(array_type); 14577 int element_size = ExternalArrayElementSize(array_type);
14578 void* external_data = malloc(size * element_size); 14578 void* external_data = malloc(size * element_size);
14579 v8::Handle<v8::Object> obj = v8::Object::New(); 14579 v8::Handle<v8::Object> obj = v8::Object::New();
14580 obj->SetIndexedPropertiesToExternalArrayData( 14580 obj->SetIndexedPropertiesToExternalArrayData(
14581 external_data, array_type, size); 14581 external_data, array_type, size);
14582 CHECK(obj->HasIndexedPropertiesInExternalArrayData()); 14582 CHECK(obj->HasIndexedPropertiesInExternalArrayData());
14583 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData()); 14583 CHECK_EQ(external_data, obj->GetIndexedPropertiesExternalArrayData());
14584 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType()); 14584 CHECK_EQ(array_type, obj->GetIndexedPropertiesExternalArrayDataType());
14585 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength()); 14585 CHECK_EQ(size, obj->GetIndexedPropertiesExternalArrayDataLength());
(...skipping 20 matching lines...) Expand all
14606 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 14606 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
14607 last_location = last_message = NULL; 14607 last_location = last_message = NULL;
14608 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size); 14608 obj->SetIndexedPropertiesToExternalArrayData(NULL, array_type, size);
14609 CHECK(!obj->HasIndexedPropertiesInExternalArrayData()); 14609 CHECK(!obj->HasIndexedPropertiesInExternalArrayData());
14610 CHECK_NE(NULL, last_location); 14610 CHECK_NE(NULL, last_location);
14611 CHECK_NE(NULL, last_message); 14611 CHECK_NE(NULL, last_message);
14612 } 14612 }
14613 14613
14614 14614
14615 TEST(ExternalArrayLimits) { 14615 TEST(ExternalArrayLimits) {
14616 v8::HandleScope scope;
14617 LocalContext context; 14616 LocalContext context;
14617 v8::HandleScope scope(context->GetIsolate());
14618 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000); 14618 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0x40000000);
14619 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff); 14619 ExternalArrayLimitTestHelper(v8::kExternalByteArray, 0xffffffff);
14620 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000); 14620 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0x40000000);
14621 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff); 14621 ExternalArrayLimitTestHelper(v8::kExternalUnsignedByteArray, 0xffffffff);
14622 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000); 14622 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0x40000000);
14623 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff); 14623 ExternalArrayLimitTestHelper(v8::kExternalShortArray, 0xffffffff);
14624 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000); 14624 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0x40000000);
14625 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff); 14625 ExternalArrayLimitTestHelper(v8::kExternalUnsignedShortArray, 0xffffffff);
14626 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000); 14626 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0x40000000);
14627 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff); 14627 ExternalArrayLimitTestHelper(v8::kExternalIntArray, 0xffffffff);
14628 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000); 14628 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0x40000000);
14629 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff); 14629 ExternalArrayLimitTestHelper(v8::kExternalUnsignedIntArray, 0xffffffff);
14630 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000); 14630 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0x40000000);
14631 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff); 14631 ExternalArrayLimitTestHelper(v8::kExternalFloatArray, 0xffffffff);
14632 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000); 14632 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0x40000000);
14633 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff); 14633 ExternalArrayLimitTestHelper(v8::kExternalDoubleArray, 0xffffffff);
14634 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000); 14634 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0x40000000);
14635 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff); 14635 ExternalArrayLimitTestHelper(v8::kExternalPixelArray, 0xffffffff);
14636 } 14636 }
14637 14637
14638 14638
14639 THREADED_TEST(ScriptContextDependence) { 14639 THREADED_TEST(ScriptContextDependence) {
14640 v8::HandleScope scope;
14641 LocalContext c1; 14640 LocalContext c1;
14641 v8::HandleScope scope(c1->GetIsolate());
14642 const char *source = "foo"; 14642 const char *source = "foo";
14643 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 14643 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
14644 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 14644 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
14645 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 14645 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
14646 CHECK_EQ(dep->Run()->Int32Value(), 100); 14646 CHECK_EQ(dep->Run()->Int32Value(), 100);
14647 CHECK_EQ(indep->Run()->Int32Value(), 100); 14647 CHECK_EQ(indep->Run()->Int32Value(), 100);
14648 LocalContext c2; 14648 LocalContext c2;
14649 c2->Global()->Set(v8::String::New("foo"), v8::Integer::New(101)); 14649 c2->Global()->Set(v8::String::New("foo"), v8::Integer::New(101));
14650 CHECK_EQ(dep->Run()->Int32Value(), 100); 14650 CHECK_EQ(dep->Run()->Int32Value(), 100);
14651 CHECK_EQ(indep->Run()->Int32Value(), 101); 14651 CHECK_EQ(indep->Run()->Int32Value(), 101);
14652 } 14652 }
14653 14653
14654 14654
14655 THREADED_TEST(StackTrace) { 14655 THREADED_TEST(StackTrace) {
14656 v8::HandleScope scope;
14657 LocalContext context; 14656 LocalContext context;
14657 v8::HandleScope scope(context->GetIsolate());
14658 v8::TryCatch try_catch; 14658 v8::TryCatch try_catch;
14659 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 14659 const char *source = "function foo() { FAIL.FAIL; }; foo();";
14660 v8::Handle<v8::String> src = v8::String::New(source); 14660 v8::Handle<v8::String> src = v8::String::New(source);
14661 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test"); 14661 v8::Handle<v8::String> origin = v8::String::New("stack-trace-test");
14662 v8::Script::New(src, origin)->Run(); 14662 v8::Script::New(src, origin)->Run();
14663 CHECK(try_catch.HasCaught()); 14663 CHECK(try_catch.HasCaught());
14664 v8::String::Utf8Value stack(try_catch.StackTrace()); 14664 v8::String::Utf8Value stack(try_catch.StackTrace());
14665 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 14665 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
14666 } 14666 }
14667 14667
14668 14668
14669 // Checks that a StackFrame has certain expected values. 14669 // Checks that a StackFrame has certain expected values.
14670 void checkStackFrame(const char* expected_script_name, 14670 void checkStackFrame(const char* expected_script_name,
14671 const char* expected_func_name, int expected_line_number, 14671 const char* expected_func_name, int expected_line_number,
14672 int expected_column, bool is_eval, bool is_constructor, 14672 int expected_column, bool is_eval, bool is_constructor,
14673 v8::Handle<v8::StackFrame> frame) { 14673 v8::Handle<v8::StackFrame> frame) {
14674 v8::HandleScope scope; 14674 v8::HandleScope scope(v8::Isolate::GetCurrent());
14675 v8::String::Utf8Value func_name(frame->GetFunctionName()); 14675 v8::String::Utf8Value func_name(frame->GetFunctionName());
14676 v8::String::Utf8Value script_name(frame->GetScriptName()); 14676 v8::String::Utf8Value script_name(frame->GetScriptName());
14677 if (*script_name == NULL) { 14677 if (*script_name == NULL) {
14678 // The situation where there is no associated script, like for evals. 14678 // The situation where there is no associated script, like for evals.
14679 CHECK(expected_script_name == NULL); 14679 CHECK(expected_script_name == NULL);
14680 } else { 14680 } else {
14681 CHECK(strstr(*script_name, expected_script_name) != NULL); 14681 CHECK(strstr(*script_name, expected_script_name) != NULL);
14682 } 14682 }
14683 CHECK(strstr(*func_name, expected_func_name) != NULL); 14683 CHECK(strstr(*func_name, expected_func_name) != NULL);
14684 CHECK_EQ(expected_line_number, frame->GetLineNumber()); 14684 CHECK_EQ(expected_line_number, frame->GetLineNumber());
14685 CHECK_EQ(expected_column, frame->GetColumn()); 14685 CHECK_EQ(expected_column, frame->GetColumn());
14686 CHECK_EQ(is_eval, frame->IsEval()); 14686 CHECK_EQ(is_eval, frame->IsEval());
14687 CHECK_EQ(is_constructor, frame->IsConstructor()); 14687 CHECK_EQ(is_constructor, frame->IsConstructor());
14688 } 14688 }
14689 14689
14690 14690
14691 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) { 14691 v8::Handle<Value> AnalyzeStackInNativeCode(const v8::Arguments& args) {
14692 v8::HandleScope scope; 14692 v8::HandleScope scope(args.GetIsolate());
14693 const char* origin = "capture-stack-trace-test"; 14693 const char* origin = "capture-stack-trace-test";
14694 const int kOverviewTest = 1; 14694 const int kOverviewTest = 1;
14695 const int kDetailedTest = 2; 14695 const int kDetailedTest = 2;
14696 14696
14697 ASSERT(args.Length() == 1); 14697 ASSERT(args.Length() == 1);
14698 14698
14699 int testGroup = args[0]->Int32Value(); 14699 int testGroup = args[0]->Int32Value();
14700 if (testGroup == kOverviewTest) { 14700 if (testGroup == kOverviewTest) {
14701 v8::Handle<v8::StackTrace> stackTrace = 14701 v8::Handle<v8::StackTrace> stackTrace =
14702 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview); 14702 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kOverview);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
14737 CHECK(stackTrace->AsArray()->IsArray()); 14737 CHECK(stackTrace->AsArray()->IsArray());
14738 } 14738 }
14739 return v8::Undefined(); 14739 return v8::Undefined();
14740 } 14740 }
14741 14741
14742 14742
14743 // Tests the C++ StackTrace API. 14743 // Tests the C++ StackTrace API.
14744 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 14744 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
14745 // THREADED_TEST(CaptureStackTrace) { 14745 // THREADED_TEST(CaptureStackTrace) {
14746 TEST(CaptureStackTrace) { 14746 TEST(CaptureStackTrace) {
14747 v8::HandleScope scope; 14747 v8::HandleScope scope(v8::Isolate::GetCurrent());
14748 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test"); 14748 v8::Handle<v8::String> origin = v8::String::New("capture-stack-trace-test");
14749 Local<ObjectTemplate> templ = ObjectTemplate::New(); 14749 Local<ObjectTemplate> templ = ObjectTemplate::New();
14750 templ->Set(v8_str("AnalyzeStackInNativeCode"), 14750 templ->Set(v8_str("AnalyzeStackInNativeCode"),
14751 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); 14751 v8::FunctionTemplate::New(AnalyzeStackInNativeCode));
14752 LocalContext context(0, templ); 14752 LocalContext context(0, templ);
14753 14753
14754 // Test getting OVERVIEW information. Should ignore information that is not 14754 // Test getting OVERVIEW information. Should ignore information that is not
14755 // script name, function name, line number, and column offset. 14755 // script name, function name, line number, and column offset.
14756 const char *overview_source = 14756 const char *overview_source =
14757 "function bar() {\n" 14757 "function bar() {\n"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
14796 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14796 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14797 CHECK_EQ(2, stack_trace->GetFrameCount()); 14797 CHECK_EQ(2, stack_trace->GetFrameCount());
14798 checkStackFrame("origin", "foo", 2, 3, false, false, 14798 checkStackFrame("origin", "foo", 2, 3, false, false,
14799 stack_trace->GetFrame(0)); 14799 stack_trace->GetFrame(0));
14800 checkStackFrame("origin", "bar", 5, 3, false, false, 14800 checkStackFrame("origin", "bar", 5, 3, false, false,
14801 stack_trace->GetFrame(1)); 14801 stack_trace->GetFrame(1));
14802 } 14802 }
14803 14803
14804 TEST(CaptureStackTraceForUncaughtException) { 14804 TEST(CaptureStackTraceForUncaughtException) {
14805 report_count = 0; 14805 report_count = 0;
14806 v8::HandleScope scope;
14807 LocalContext env; 14806 LocalContext env;
14807 v8::HandleScope scope(env->GetIsolate());
14808 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener); 14808 v8::V8::AddMessageListener(StackTraceForUncaughtExceptionListener);
14809 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14809 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14810 14810
14811 Script::Compile(v8_str("function foo() {\n" 14811 Script::Compile(v8_str("function foo() {\n"
14812 " throw 1;\n" 14812 " throw 1;\n"
14813 "};\n" 14813 "};\n"
14814 "function bar() {\n" 14814 "function bar() {\n"
14815 " foo();\n" 14815 " foo();\n"
14816 "};"), 14816 "};"),
14817 v8_str("origin"))->Run(); 14817 v8_str("origin"))->Run();
14818 v8::Local<v8::Object> global = env->Global(); 14818 v8::Local<v8::Object> global = env->Global();
14819 Local<Value> trouble = global->Get(v8_str("bar")); 14819 Local<Value> trouble = global->Get(v8_str("bar"));
14820 CHECK(trouble->IsFunction()); 14820 CHECK(trouble->IsFunction());
14821 Function::Cast(*trouble)->Call(global, 0, NULL); 14821 Function::Cast(*trouble)->Call(global, 0, NULL);
14822 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14822 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14823 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); 14823 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener);
14824 } 14824 }
14825 14825
14826 14826
14827 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { 14827 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) {
14828 v8::HandleScope scope;
14829 LocalContext env; 14828 LocalContext env;
14829 v8::HandleScope scope(env->GetIsolate());
14830 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 14830 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true,
14831 1024, 14831 1024,
14832 v8::StackTrace::kDetailed); 14832 v8::StackTrace::kDetailed);
14833 14833
14834 CompileRun( 14834 CompileRun(
14835 "var setters = ['column', 'lineNumber', 'scriptName',\n" 14835 "var setters = ['column', 'lineNumber', 'scriptName',\n"
14836 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n" 14836 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n"
14837 " 'isConstructor'];\n" 14837 " 'isConstructor'];\n"
14838 "for (var i = 0; i < setters.length; i++) {\n" 14838 "for (var i = 0; i < setters.length; i++) {\n"
14839 " var prop = setters[i];\n" 14839 " var prop = setters[i];\n"
(...skipping 14 matching lines...) Expand all
14854 int line_number[] = {1, 2, 5}; 14854 int line_number[] = {1, 2, 5};
14855 for (int i = 0; i < frame_count; i++) { 14855 for (int i = 0; i < frame_count; i++) {
14856 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 14856 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14857 } 14857 }
14858 } 14858 }
14859 14859
14860 14860
14861 // Test that we only return the stack trace at the site where the exception 14861 // Test that we only return the stack trace at the site where the exception
14862 // is first thrown (not where it is rethrown). 14862 // is first thrown (not where it is rethrown).
14863 TEST(RethrowStackTrace) { 14863 TEST(RethrowStackTrace) {
14864 v8::HandleScope scope;
14865 LocalContext env; 14864 LocalContext env;
14865 v8::HandleScope scope(env->GetIsolate());
14866 // We make sure that 14866 // We make sure that
14867 // - the stack trace of the ReferenceError in g() is reported. 14867 // - the stack trace of the ReferenceError in g() is reported.
14868 // - the stack trace is not overwritten when e1 is rethrown by t(). 14868 // - the stack trace is not overwritten when e1 is rethrown by t().
14869 // - the stack trace of e2 does not overwrite that of e1. 14869 // - the stack trace of e2 does not overwrite that of e1.
14870 const char* source = 14870 const char* source =
14871 "function g() { error; } \n" 14871 "function g() { error; } \n"
14872 "function f() { g(); } \n" 14872 "function f() { g(); } \n"
14873 "function t(e) { throw e; } \n" 14873 "function t(e) { throw e; } \n"
14874 "try { \n" 14874 "try { \n"
14875 " f(); \n" 14875 " f(); \n"
(...skipping 20 matching lines...) Expand all
14896 CHECK_EQ(2, frame_count); 14896 CHECK_EQ(2, frame_count);
14897 int line_number[] = {3, 7}; 14897 int line_number[] = {3, 7};
14898 for (int i = 0; i < frame_count; i++) { 14898 for (int i = 0; i < frame_count; i++) {
14899 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 14899 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14900 } 14900 }
14901 } 14901 }
14902 14902
14903 14903
14904 // Test that we do not recognize identity for primitive exceptions. 14904 // Test that we do not recognize identity for primitive exceptions.
14905 TEST(RethrowPrimitiveStackTrace) { 14905 TEST(RethrowPrimitiveStackTrace) {
14906 v8::HandleScope scope;
14907 LocalContext env; 14906 LocalContext env;
14907 v8::HandleScope scope(env->GetIsolate());
14908 // We do not capture stack trace for non Error objects on creation time. 14908 // We do not capture stack trace for non Error objects on creation time.
14909 // Instead, we capture the stack trace on last throw. 14909 // Instead, we capture the stack trace on last throw.
14910 const char* source = 14910 const char* source =
14911 "function g() { throw 404; } \n" 14911 "function g() { throw 404; } \n"
14912 "function f() { g(); } \n" 14912 "function f() { g(); } \n"
14913 "function t(e) { throw e; } \n" 14913 "function t(e) { throw e; } \n"
14914 "try { \n" 14914 "try { \n"
14915 " f(); \n" 14915 " f(); \n"
14916 "} catch (e1) { \n" 14916 "} catch (e1) { \n"
14917 " t(e1) \n" 14917 " t(e1) \n"
(...skipping 12 matching lines...) Expand all
14930 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14930 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14931 CHECK(!stack_trace.IsEmpty()); 14931 CHECK(!stack_trace.IsEmpty());
14932 CHECK_EQ(1, stack_trace->GetFrameCount()); 14932 CHECK_EQ(1, stack_trace->GetFrameCount());
14933 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); 14933 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber());
14934 } 14934 }
14935 14935
14936 14936
14937 // Test that the stack trace is captured when the error object is created and 14937 // Test that the stack trace is captured when the error object is created and
14938 // not where it is thrown. 14938 // not where it is thrown.
14939 TEST(RethrowExistingStackTrace) { 14939 TEST(RethrowExistingStackTrace) {
14940 v8::HandleScope scope;
14941 LocalContext env; 14940 LocalContext env;
14941 v8::HandleScope scope(env->GetIsolate());
14942 const char* source = 14942 const char* source =
14943 "var e = new Error(); \n" 14943 "var e = new Error(); \n"
14944 "throw e; \n"; 14944 "throw e; \n";
14945 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler); 14945 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler);
14946 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14946 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14947 CompileRun(source); 14947 CompileRun(source);
14948 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14948 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14949 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler); 14949 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler);
14950 } 14950 }
14951 14951
14952 14952
14953 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message, 14953 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message,
14954 v8::Handle<v8::Value> data) { 14954 v8::Handle<v8::Value> data) {
14955 // Use the frame where JavaScript is called from. 14955 // Use the frame where JavaScript is called from.
14956 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 14956 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace();
14957 CHECK(!stack_trace.IsEmpty()); 14957 CHECK(!stack_trace.IsEmpty());
14958 CHECK_EQ(1, stack_trace->GetFrameCount()); 14958 CHECK_EQ(1, stack_trace->GetFrameCount());
14959 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber()); 14959 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber());
14960 } 14960 }
14961 14961
14962 14962
14963 // Test that the stack trace is captured where the bogus Error object is thrown. 14963 // Test that the stack trace is captured where the bogus Error object is thrown.
14964 TEST(RethrowBogusErrorStackTrace) { 14964 TEST(RethrowBogusErrorStackTrace) {
14965 v8::HandleScope scope;
14966 LocalContext env; 14965 LocalContext env;
14966 v8::HandleScope scope(env->GetIsolate());
14967 const char* source = 14967 const char* source =
14968 "var e = {__proto__: new Error()} \n" 14968 "var e = {__proto__: new Error()} \n"
14969 "throw e; \n"; 14969 "throw e; \n";
14970 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler); 14970 v8::V8::AddMessageListener(RethrowBogusErrorStackTraceHandler);
14971 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 14971 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14972 CompileRun(source); 14972 CompileRun(source);
14973 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 14973 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14974 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler); 14974 v8::V8::RemoveMessageListeners(RethrowBogusErrorStackTraceHandler);
14975 } 14975 }
14976 14976
14977 14977
14978 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { 14978 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) {
14979 v8::HandleScope scope; 14979 v8::HandleScope scope(args.GetIsolate());
14980 v8::Handle<v8::StackTrace> stackTrace = 14980 v8::Handle<v8::StackTrace> stackTrace =
14981 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 14981 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
14982 CHECK_EQ(5, stackTrace->GetFrameCount()); 14982 CHECK_EQ(5, stackTrace->GetFrameCount());
14983 v8::Handle<v8::String> url = v8_str("eval_url"); 14983 v8::Handle<v8::String> url = v8_str("eval_url");
14984 for (int i = 0; i < 3; i++) { 14984 for (int i = 0; i < 3; i++) {
14985 v8::Handle<v8::String> name = 14985 v8::Handle<v8::String> name =
14986 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 14986 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
14987 CHECK(!name.IsEmpty()); 14987 CHECK(!name.IsEmpty());
14988 CHECK_EQ(url, name); 14988 CHECK_EQ(url, name);
14989 } 14989 }
14990 return v8::Undefined(); 14990 return v8::Undefined();
14991 } 14991 }
14992 14992
14993 14993
14994 TEST(SourceURLInStackTrace) { 14994 TEST(SourceURLInStackTrace) {
14995 v8::HandleScope scope; 14995 v8::HandleScope scope(v8::Isolate::GetCurrent());
14996 Local<ObjectTemplate> templ = ObjectTemplate::New(); 14996 Local<ObjectTemplate> templ = ObjectTemplate::New();
14997 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 14997 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
14998 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); 14998 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL));
14999 LocalContext context(0, templ); 14999 LocalContext context(0, templ);
15000 15000
15001 const char *source = 15001 const char *source =
15002 "function outer() {\n" 15002 "function outer() {\n"
15003 "function bar() {\n" 15003 "function bar() {\n"
15004 " AnalyzeStackOfEvalWithSourceURL();\n" 15004 " AnalyzeStackOfEvalWithSourceURL();\n"
15005 "}\n" 15005 "}\n"
15006 "function foo() {\n" 15006 "function foo() {\n"
15007 "\n" 15007 "\n"
15008 " bar();\n" 15008 " bar();\n"
15009 "}\n" 15009 "}\n"
15010 "foo();\n" 15010 "foo();\n"
15011 "}\n" 15011 "}\n"
15012 "eval('(' + outer +')()//@ sourceURL=eval_url');"; 15012 "eval('(' + outer +')()//@ sourceURL=eval_url');";
15013 CHECK(CompileRun(source)->IsUndefined()); 15013 CHECK(CompileRun(source)->IsUndefined());
15014 } 15014 }
15015 15015
15016 15016
15017 v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL( 15017 v8::Handle<Value> AnalyzeStackOfInlineScriptWithSourceURL(
15018 const v8::Arguments& args) { 15018 const v8::Arguments& args) {
15019 v8::HandleScope scope; 15019 v8::HandleScope scope(args.GetIsolate());
15020 v8::Handle<v8::StackTrace> stackTrace = 15020 v8::Handle<v8::StackTrace> stackTrace =
15021 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15021 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
15022 CHECK_EQ(4, stackTrace->GetFrameCount()); 15022 CHECK_EQ(4, stackTrace->GetFrameCount());
15023 v8::Handle<v8::String> url = v8_str("url"); 15023 v8::Handle<v8::String> url = v8_str("url");
15024 for (int i = 0; i < 3; i++) { 15024 for (int i = 0; i < 3; i++) {
15025 v8::Handle<v8::String> name = 15025 v8::Handle<v8::String> name =
15026 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15026 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15027 CHECK(!name.IsEmpty()); 15027 CHECK(!name.IsEmpty());
15028 CHECK_EQ(url, name); 15028 CHECK_EQ(url, name);
15029 } 15029 }
15030 return v8::Undefined(); 15030 return v8::Undefined();
15031 } 15031 }
15032 15032
15033 15033
15034 TEST(InlineScriptWithSourceURLInStackTrace) { 15034 TEST(InlineScriptWithSourceURLInStackTrace) {
15035 v8::HandleScope scope; 15035 v8::HandleScope scope(v8::Isolate::GetCurrent());
15036 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15036 Local<ObjectTemplate> templ = ObjectTemplate::New();
15037 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 15037 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
15038 v8::FunctionTemplate::New( 15038 v8::FunctionTemplate::New(
15039 AnalyzeStackOfInlineScriptWithSourceURL)); 15039 AnalyzeStackOfInlineScriptWithSourceURL));
15040 LocalContext context(0, templ); 15040 LocalContext context(0, templ);
15041 15041
15042 const char *source = 15042 const char *source =
15043 "function outer() {\n" 15043 "function outer() {\n"
15044 "function bar() {\n" 15044 "function bar() {\n"
15045 " AnalyzeStackOfInlineScriptWithSourceURL();\n" 15045 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
15046 "}\n" 15046 "}\n"
15047 "function foo() {\n" 15047 "function foo() {\n"
15048 "\n" 15048 "\n"
15049 " bar();\n" 15049 " bar();\n"
15050 "}\n" 15050 "}\n"
15051 "foo();\n" 15051 "foo();\n"
15052 "}\n" 15052 "}\n"
15053 "outer()\n" 15053 "outer()\n"
15054 "//@ sourceURL=source_url"; 15054 "//@ sourceURL=source_url";
15055 CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined()); 15055 CHECK(CompileRunWithOrigin(source, "url", 0, 1)->IsUndefined());
15056 } 15056 }
15057 15057
15058 15058
15059 v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL( 15059 v8::Handle<Value> AnalyzeStackOfDynamicScriptWithSourceURL(
15060 const v8::Arguments& args) { 15060 const v8::Arguments& args) {
15061 v8::HandleScope scope; 15061 v8::HandleScope scope(args.GetIsolate());
15062 v8::Handle<v8::StackTrace> stackTrace = 15062 v8::Handle<v8::StackTrace> stackTrace =
15063 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); 15063 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed);
15064 CHECK_EQ(4, stackTrace->GetFrameCount()); 15064 CHECK_EQ(4, stackTrace->GetFrameCount());
15065 v8::Handle<v8::String> url = v8_str("source_url"); 15065 v8::Handle<v8::String> url = v8_str("source_url");
15066 for (int i = 0; i < 3; i++) { 15066 for (int i = 0; i < 3; i++) {
15067 v8::Handle<v8::String> name = 15067 v8::Handle<v8::String> name =
15068 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 15068 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15069 CHECK(!name.IsEmpty()); 15069 CHECK(!name.IsEmpty());
15070 CHECK_EQ(url, name); 15070 CHECK_EQ(url, name);
15071 } 15071 }
15072 return v8::Undefined(); 15072 return v8::Undefined();
15073 } 15073 }
15074 15074
15075 15075
15076 TEST(DynamicWithSourceURLInStackTrace) { 15076 TEST(DynamicWithSourceURLInStackTrace) {
15077 v8::HandleScope scope; 15077 v8::HandleScope scope(v8::Isolate::GetCurrent());
15078 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15078 Local<ObjectTemplate> templ = ObjectTemplate::New();
15079 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 15079 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
15080 v8::FunctionTemplate::New( 15080 v8::FunctionTemplate::New(
15081 AnalyzeStackOfDynamicScriptWithSourceURL)); 15081 AnalyzeStackOfDynamicScriptWithSourceURL));
15082 LocalContext context(0, templ); 15082 LocalContext context(0, templ);
15083 15083
15084 const char *source = 15084 const char *source =
15085 "function outer() {\n" 15085 "function outer() {\n"
15086 "function bar() {\n" 15086 "function bar() {\n"
15087 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" 15087 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
15088 "}\n" 15088 "}\n"
15089 "function foo() {\n" 15089 "function foo() {\n"
15090 "\n" 15090 "\n"
15091 " bar();\n" 15091 " bar();\n"
15092 "}\n" 15092 "}\n"
15093 "foo();\n" 15093 "foo();\n"
15094 "}\n" 15094 "}\n"
15095 "outer()\n" 15095 "outer()\n"
15096 "//@ sourceURL=source_url"; 15096 "//@ sourceURL=source_url";
15097 CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined()); 15097 CHECK(CompileRunWithOrigin(source, "url", 0, 0)->IsUndefined());
15098 } 15098 }
15099 15099
15100 static void CreateGarbageInOldSpace() { 15100 static void CreateGarbageInOldSpace() {
15101 v8::HandleScope scope; 15101 v8::HandleScope scope(v8::Isolate::GetCurrent());
15102 i::AlwaysAllocateScope always_allocate; 15102 i::AlwaysAllocateScope always_allocate;
15103 for (int i = 0; i < 1000; i++) { 15103 for (int i = 0; i < 1000; i++) {
15104 FACTORY->NewFixedArray(1000, i::TENURED); 15104 FACTORY->NewFixedArray(1000, i::TENURED);
15105 } 15105 }
15106 } 15106 }
15107 15107
15108 // Test that idle notification can be handled and eventually returns true. 15108 // Test that idle notification can be handled and eventually returns true.
15109 TEST(IdleNotification) { 15109 TEST(IdleNotification) {
15110 const intptr_t MB = 1024 * 1024; 15110 const intptr_t MB = 1024 * 1024;
15111 v8::HandleScope scope;
15112 LocalContext env; 15111 LocalContext env;
15112 v8::HandleScope scope(env->GetIsolate());
15113 intptr_t initial_size = HEAP->SizeOfObjects(); 15113 intptr_t initial_size = HEAP->SizeOfObjects();
15114 CreateGarbageInOldSpace(); 15114 CreateGarbageInOldSpace();
15115 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15115 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15116 CHECK_GT(size_with_garbage, initial_size + MB); 15116 CHECK_GT(size_with_garbage, initial_size + MB);
15117 bool finished = false; 15117 bool finished = false;
15118 for (int i = 0; i < 200 && !finished; i++) { 15118 for (int i = 0; i < 200 && !finished; i++) {
15119 finished = v8::V8::IdleNotification(); 15119 finished = v8::V8::IdleNotification();
15120 } 15120 }
15121 intptr_t final_size = HEAP->SizeOfObjects(); 15121 intptr_t final_size = HEAP->SizeOfObjects();
15122 CHECK(finished); 15122 CHECK(finished);
15123 CHECK_LT(final_size, initial_size + 1); 15123 CHECK_LT(final_size, initial_size + 1);
15124 } 15124 }
15125 15125
15126 15126
15127 // Test that idle notification can be handled and eventually collects garbage. 15127 // Test that idle notification can be handled and eventually collects garbage.
15128 TEST(IdleNotificationWithSmallHint) { 15128 TEST(IdleNotificationWithSmallHint) {
15129 const intptr_t MB = 1024 * 1024; 15129 const intptr_t MB = 1024 * 1024;
15130 const int IdlePauseInMs = 900; 15130 const int IdlePauseInMs = 900;
15131 v8::HandleScope scope;
15132 LocalContext env; 15131 LocalContext env;
15132 v8::HandleScope scope(env->GetIsolate());
15133 intptr_t initial_size = HEAP->SizeOfObjects(); 15133 intptr_t initial_size = HEAP->SizeOfObjects();
15134 CreateGarbageInOldSpace(); 15134 CreateGarbageInOldSpace();
15135 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15135 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15136 CHECK_GT(size_with_garbage, initial_size + MB); 15136 CHECK_GT(size_with_garbage, initial_size + MB);
15137 bool finished = false; 15137 bool finished = false;
15138 for (int i = 0; i < 200 && !finished; i++) { 15138 for (int i = 0; i < 200 && !finished; i++) {
15139 finished = v8::V8::IdleNotification(IdlePauseInMs); 15139 finished = v8::V8::IdleNotification(IdlePauseInMs);
15140 } 15140 }
15141 intptr_t final_size = HEAP->SizeOfObjects(); 15141 intptr_t final_size = HEAP->SizeOfObjects();
15142 CHECK(finished); 15142 CHECK(finished);
15143 CHECK_LT(final_size, initial_size + 1); 15143 CHECK_LT(final_size, initial_size + 1);
15144 } 15144 }
15145 15145
15146 15146
15147 // Test that idle notification can be handled and eventually collects garbage. 15147 // Test that idle notification can be handled and eventually collects garbage.
15148 TEST(IdleNotificationWithLargeHint) { 15148 TEST(IdleNotificationWithLargeHint) {
15149 const intptr_t MB = 1024 * 1024; 15149 const intptr_t MB = 1024 * 1024;
15150 const int IdlePauseInMs = 900; 15150 const int IdlePauseInMs = 900;
15151 v8::HandleScope scope;
15152 LocalContext env; 15151 LocalContext env;
15152 v8::HandleScope scope(env->GetIsolate());
15153 intptr_t initial_size = HEAP->SizeOfObjects(); 15153 intptr_t initial_size = HEAP->SizeOfObjects();
15154 CreateGarbageInOldSpace(); 15154 CreateGarbageInOldSpace();
15155 intptr_t size_with_garbage = HEAP->SizeOfObjects(); 15155 intptr_t size_with_garbage = HEAP->SizeOfObjects();
15156 CHECK_GT(size_with_garbage, initial_size + MB); 15156 CHECK_GT(size_with_garbage, initial_size + MB);
15157 bool finished = false; 15157 bool finished = false;
15158 for (int i = 0; i < 200 && !finished; i++) { 15158 for (int i = 0; i < 200 && !finished; i++) {
15159 finished = v8::V8::IdleNotification(IdlePauseInMs); 15159 finished = v8::V8::IdleNotification(IdlePauseInMs);
15160 } 15160 }
15161 intptr_t final_size = HEAP->SizeOfObjects(); 15161 intptr_t final_size = HEAP->SizeOfObjects();
15162 CHECK(finished); 15162 CHECK(finished);
15163 CHECK_LT(final_size, initial_size + 1); 15163 CHECK_LT(final_size, initial_size + 1);
15164 } 15164 }
15165 15165
15166 15166
15167 TEST(Regress2107) { 15167 TEST(Regress2107) {
15168 const intptr_t MB = 1024 * 1024; 15168 const intptr_t MB = 1024 * 1024;
15169 const int kShortIdlePauseInMs = 100; 15169 const int kShortIdlePauseInMs = 100;
15170 const int kLongIdlePauseInMs = 1000; 15170 const int kLongIdlePauseInMs = 1000;
15171 v8::HandleScope scope;
15172 LocalContext env; 15171 LocalContext env;
15172 v8::HandleScope scope(env->GetIsolate());
15173 intptr_t initial_size = HEAP->SizeOfObjects(); 15173 intptr_t initial_size = HEAP->SizeOfObjects();
15174 // Send idle notification to start a round of incremental GCs. 15174 // Send idle notification to start a round of incremental GCs.
15175 v8::V8::IdleNotification(kShortIdlePauseInMs); 15175 v8::V8::IdleNotification(kShortIdlePauseInMs);
15176 // Emulate 7 page reloads. 15176 // Emulate 7 page reloads.
15177 for (int i = 0; i < 7; i++) { 15177 for (int i = 0; i < 7; i++) {
15178 v8::Persistent<v8::Context> ctx = v8::Context::New(); 15178 v8::Persistent<v8::Context> ctx = v8::Context::New();
15179 ctx->Enter(); 15179 ctx->Enter();
15180 CreateGarbageInOldSpace(); 15180 CreateGarbageInOldSpace();
15181 ctx->Exit(); 15181 ctx->Exit();
15182 ctx.Dispose(ctx->GetIsolate()); 15182 ctx.Dispose(ctx->GetIsolate());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
15221 TEST(SetResourceConstraints) { 15221 TEST(SetResourceConstraints) {
15222 static const int K = 1024; 15222 static const int K = 1024;
15223 uint32_t* set_limit = ComputeStackLimit(128 * K); 15223 uint32_t* set_limit = ComputeStackLimit(128 * K);
15224 15224
15225 // Set stack limit. 15225 // Set stack limit.
15226 v8::ResourceConstraints constraints; 15226 v8::ResourceConstraints constraints;
15227 constraints.set_stack_limit(set_limit); 15227 constraints.set_stack_limit(set_limit);
15228 CHECK(v8::SetResourceConstraints(&constraints)); 15228 CHECK(v8::SetResourceConstraints(&constraints));
15229 15229
15230 // Execute a script. 15230 // Execute a script.
15231 v8::HandleScope scope;
15232 LocalContext env; 15231 LocalContext env;
15232 v8::HandleScope scope(env->GetIsolate());
15233 Local<v8::FunctionTemplate> fun_templ = 15233 Local<v8::FunctionTemplate> fun_templ =
15234 v8::FunctionTemplate::New(GetStackLimitCallback); 15234 v8::FunctionTemplate::New(GetStackLimitCallback);
15235 Local<Function> fun = fun_templ->GetFunction(); 15235 Local<Function> fun = fun_templ->GetFunction();
15236 env->Global()->Set(v8_str("get_stack_limit"), fun); 15236 env->Global()->Set(v8_str("get_stack_limit"), fun);
15237 CompileRun("get_stack_limit();"); 15237 CompileRun("get_stack_limit();");
15238 15238
15239 CHECK(stack_limit == set_limit); 15239 CHECK(stack_limit == set_limit);
15240 } 15240 }
15241 15241
15242 15242
15243 TEST(SetResourceConstraintsInThread) { 15243 TEST(SetResourceConstraintsInThread) {
15244 uint32_t* set_limit; 15244 uint32_t* set_limit;
15245 { 15245 {
15246 v8::Locker locker(CcTest::default_isolate()); 15246 v8::Locker locker(CcTest::default_isolate());
15247 static const int K = 1024; 15247 static const int K = 1024;
15248 set_limit = ComputeStackLimit(128 * K); 15248 set_limit = ComputeStackLimit(128 * K);
15249 15249
15250 // Set stack limit. 15250 // Set stack limit.
15251 v8::ResourceConstraints constraints; 15251 v8::ResourceConstraints constraints;
15252 constraints.set_stack_limit(set_limit); 15252 constraints.set_stack_limit(set_limit);
15253 CHECK(v8::SetResourceConstraints(&constraints)); 15253 CHECK(v8::SetResourceConstraints(&constraints));
15254 15254
15255 // Execute a script. 15255 // Execute a script.
15256 v8::HandleScope scope; 15256 v8::HandleScope scope(CcTest::default_isolate());
15257 LocalContext env; 15257 LocalContext env;
15258 Local<v8::FunctionTemplate> fun_templ = 15258 Local<v8::FunctionTemplate> fun_templ =
15259 v8::FunctionTemplate::New(GetStackLimitCallback); 15259 v8::FunctionTemplate::New(GetStackLimitCallback);
15260 Local<Function> fun = fun_templ->GetFunction(); 15260 Local<Function> fun = fun_templ->GetFunction();
15261 env->Global()->Set(v8_str("get_stack_limit"), fun); 15261 env->Global()->Set(v8_str("get_stack_limit"), fun);
15262 CompileRun("get_stack_limit();"); 15262 CompileRun("get_stack_limit();");
15263 15263
15264 CHECK(stack_limit == set_limit); 15264 CHECK(stack_limit == set_limit);
15265 } 15265 }
15266 { 15266 {
15267 v8::Locker locker(CcTest::default_isolate()); 15267 v8::Locker locker(CcTest::default_isolate());
15268 CHECK(stack_limit == set_limit); 15268 CHECK(stack_limit == set_limit);
15269 } 15269 }
15270 } 15270 }
15271 15271
15272 15272
15273 THREADED_TEST(GetHeapStatistics) { 15273 THREADED_TEST(GetHeapStatistics) {
15274 v8::HandleScope scope;
15275 LocalContext c1; 15274 LocalContext c1;
15275 v8::HandleScope scope(c1->GetIsolate());
15276 v8::HeapStatistics heap_statistics; 15276 v8::HeapStatistics heap_statistics;
15277 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); 15277 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0);
15278 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); 15278 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0);
15279 c1->GetIsolate()->GetHeapStatistics(&heap_statistics); 15279 c1->GetIsolate()->GetHeapStatistics(&heap_statistics);
15280 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); 15280 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0);
15281 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); 15281 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0);
15282 } 15282 }
15283 15283
15284 15284
15285 class VisitorImpl : public v8::ExternalResourceVisitor { 15285 class VisitorImpl : public v8::ExternalResourceVisitor {
(...skipping 25 matching lines...) Expand all
15311 CHECK(found_resource_[i]); 15311 CHECK(found_resource_[i]);
15312 } 15312 }
15313 } 15313 }
15314 15314
15315 private: 15315 private:
15316 v8::String::ExternalStringResource* resource_[4]; 15316 v8::String::ExternalStringResource* resource_[4];
15317 bool found_resource_[4]; 15317 bool found_resource_[4];
15318 }; 15318 };
15319 15319
15320 TEST(VisitExternalStrings) { 15320 TEST(VisitExternalStrings) {
15321 v8::HandleScope scope;
15322 LocalContext env; 15321 LocalContext env;
15322 v8::HandleScope scope(env->GetIsolate());
15323 const char* string = "Some string"; 15323 const char* string = "Some string";
15324 uint16_t* two_byte_string = AsciiToTwoByteString(string); 15324 uint16_t* two_byte_string = AsciiToTwoByteString(string);
15325 TestResource* resource[4]; 15325 TestResource* resource[4];
15326 resource[0] = new TestResource(two_byte_string); 15326 resource[0] = new TestResource(two_byte_string);
15327 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]); 15327 v8::Local<v8::String> string0 = v8::String::NewExternal(resource[0]);
15328 resource[1] = new TestResource(two_byte_string); 15328 resource[1] = new TestResource(two_byte_string);
15329 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]); 15329 v8::Local<v8::String> string1 = v8::String::NewExternal(resource[1]);
15330 15330
15331 // Externalized symbol. 15331 // Externalized symbol.
15332 resource[2] = new TestResource(two_byte_string); 15332 resource[2] = new TestResource(two_byte_string);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
15377 } 15377 }
15378 15378
15379 // We don't have a consistent way to write 64-bit constants syntactically, so we 15379 // We don't have a consistent way to write 64-bit constants syntactically, so we
15380 // split them into two 32-bit constants and combine them programmatically. 15380 // split them into two 32-bit constants and combine them programmatically.
15381 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) { 15381 static double DoubleFromBits(uint32_t high_bits, uint32_t low_bits) {
15382 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits); 15382 return DoubleFromBits((static_cast<uint64_t>(high_bits) << 32) | low_bits);
15383 } 15383 }
15384 15384
15385 15385
15386 THREADED_TEST(QuietSignalingNaNs) { 15386 THREADED_TEST(QuietSignalingNaNs) {
15387 v8::HandleScope scope;
15388 LocalContext context; 15387 LocalContext context;
15388 v8::HandleScope scope(context->GetIsolate());
15389 v8::TryCatch try_catch; 15389 v8::TryCatch try_catch;
15390 15390
15391 // Special double values. 15391 // Special double values.
15392 double snan = DoubleFromBits(0x7ff00000, 0x00000001); 15392 double snan = DoubleFromBits(0x7ff00000, 0x00000001);
15393 double qnan = DoubleFromBits(0x7ff80000, 0x00000000); 15393 double qnan = DoubleFromBits(0x7ff80000, 0x00000000);
15394 double infinity = DoubleFromBits(0x7ff00000, 0x00000000); 15394 double infinity = DoubleFromBits(0x7ff00000, 0x00000000);
15395 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu); 15395 double max_normal = DoubleFromBits(0x7fefffff, 0xffffffffu);
15396 double min_normal = DoubleFromBits(0x00100000, 0x00000000); 15396 double min_normal = DoubleFromBits(0x00100000, 0x00000000);
15397 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu); 15397 double max_denormal = DoubleFromBits(0x000fffff, 0xffffffffu);
15398 double min_denormal = DoubleFromBits(0x00000000, 0x00000001); 15398 double min_denormal = DoubleFromBits(0x00000000, 0x00000001);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
15461 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 15461 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
15462 #else 15462 #else
15463 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 15463 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
15464 #endif 15464 #endif
15465 } 15465 }
15466 } 15466 }
15467 } 15467 }
15468 15468
15469 15469
15470 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) { 15470 static v8::Handle<Value> SpaghettiIncident(const v8::Arguments& args) {
15471 v8::HandleScope scope; 15471 v8::HandleScope scope(args.GetIsolate());
15472 v8::TryCatch tc; 15472 v8::TryCatch tc;
15473 v8::Handle<v8::String> str(args[0]->ToString()); 15473 v8::Handle<v8::String> str(args[0]->ToString());
15474 USE(str); 15474 USE(str);
15475 if (tc.HasCaught()) 15475 if (tc.HasCaught())
15476 return tc.ReThrow(); 15476 return tc.ReThrow();
15477 return v8::Undefined(); 15477 return v8::Undefined();
15478 } 15478 }
15479 15479
15480 15480
15481 // Test that an exception can be propagated down through a spaghetti 15481 // Test that an exception can be propagated down through a spaghetti
15482 // stack using ReThrow. 15482 // stack using ReThrow.
15483 THREADED_TEST(SpaghettiStackReThrow) { 15483 THREADED_TEST(SpaghettiStackReThrow) {
15484 v8::HandleScope scope; 15484 v8::HandleScope scope(v8::Isolate::GetCurrent());
15485 LocalContext context; 15485 LocalContext context;
15486 context->Global()->Set( 15486 context->Global()->Set(
15487 v8::String::New("s"), 15487 v8::String::New("s"),
15488 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); 15488 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction());
15489 v8::TryCatch try_catch; 15489 v8::TryCatch try_catch;
15490 CompileRun( 15490 CompileRun(
15491 "var i = 0;" 15491 "var i = 0;"
15492 "var o = {" 15492 "var o = {"
15493 " toString: function () {" 15493 " toString: function () {"
15494 " if (i == 10) {" 15494 " if (i == 10) {"
15495 " throw 'Hey!';" 15495 " throw 'Hey!';"
15496 " } else {" 15496 " } else {"
15497 " i++;" 15497 " i++;"
15498 " return s(o);" 15498 " return s(o);"
15499 " }" 15499 " }"
15500 " }" 15500 " }"
15501 "};" 15501 "};"
15502 "s(o);"); 15502 "s(o);");
15503 CHECK(try_catch.HasCaught()); 15503 CHECK(try_catch.HasCaught());
15504 v8::String::Utf8Value value(try_catch.Exception()); 15504 v8::String::Utf8Value value(try_catch.Exception());
15505 CHECK_EQ(0, strcmp(*value, "Hey!")); 15505 CHECK_EQ(0, strcmp(*value, "Hey!"));
15506 } 15506 }
15507 15507
15508 15508
15509 TEST(Regress528) { 15509 TEST(Regress528) {
15510 v8::V8::Initialize(); 15510 v8::V8::Initialize();
15511 15511
15512 v8::HandleScope scope; 15512 v8::HandleScope scope(v8::Isolate::GetCurrent());
15513 v8::Persistent<Context> context; 15513 v8::Persistent<Context> context;
15514 v8::Persistent<Context> other_context; 15514 v8::Persistent<Context> other_context;
15515 int gc_count; 15515 int gc_count;
15516 15516
15517 // Create a context used to keep the code from aging in the compilation 15517 // Create a context used to keep the code from aging in the compilation
15518 // cache. 15518 // cache.
15519 other_context = Context::New(); 15519 other_context = Context::New();
15520 15520
15521 // Context-dependent context data creates reference from the compilation 15521 // Context-dependent context data creates reference from the compilation
15522 // cache to the global object. 15522 // cache to the global object.
15523 const char* source_simple = "1"; 15523 const char* source_simple = "1";
15524 context = Context::New(); 15524 context = Context::New();
15525 { 15525 {
15526 v8::HandleScope scope; 15526 v8::HandleScope scope(v8::Isolate::GetCurrent());
15527 15527
15528 context->Enter(); 15528 context->Enter();
15529 Local<v8::String> obj = v8::String::New(""); 15529 Local<v8::String> obj = v8::String::New("");
15530 context->SetEmbedderData(0, obj); 15530 context->SetEmbedderData(0, obj);
15531 CompileRun(source_simple); 15531 CompileRun(source_simple);
15532 context->Exit(); 15532 context->Exit();
15533 } 15533 }
15534 context.Dispose(context->GetIsolate()); 15534 context.Dispose(context->GetIsolate());
15535 v8::V8::ContextDisposedNotification(); 15535 v8::V8::ContextDisposedNotification();
15536 for (gc_count = 1; gc_count < 10; gc_count++) { 15536 for (gc_count = 1; gc_count < 10; gc_count++) {
15537 other_context->Enter(); 15537 other_context->Enter();
15538 CompileRun(source_simple); 15538 CompileRun(source_simple);
15539 other_context->Exit(); 15539 other_context->Exit();
15540 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15540 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15541 if (GetGlobalObjectsCount() == 1) break; 15541 if (GetGlobalObjectsCount() == 1) break;
15542 } 15542 }
15543 CHECK_GE(2, gc_count); 15543 CHECK_GE(2, gc_count);
15544 CHECK_EQ(1, GetGlobalObjectsCount()); 15544 CHECK_EQ(1, GetGlobalObjectsCount());
15545 15545
15546 // Eval in a function creates reference from the compilation cache to the 15546 // Eval in a function creates reference from the compilation cache to the
15547 // global object. 15547 // global object.
15548 const char* source_eval = "function f(){eval('1')}; f()"; 15548 const char* source_eval = "function f(){eval('1')}; f()";
15549 context = Context::New(); 15549 context = Context::New();
15550 { 15550 {
15551 v8::HandleScope scope; 15551 v8::HandleScope scope(v8::Isolate::GetCurrent());
15552 15552
15553 context->Enter(); 15553 context->Enter();
15554 CompileRun(source_eval); 15554 CompileRun(source_eval);
15555 context->Exit(); 15555 context->Exit();
15556 } 15556 }
15557 context.Dispose(context->GetIsolate()); 15557 context.Dispose(context->GetIsolate());
15558 v8::V8::ContextDisposedNotification(); 15558 v8::V8::ContextDisposedNotification();
15559 for (gc_count = 1; gc_count < 10; gc_count++) { 15559 for (gc_count = 1; gc_count < 10; gc_count++) {
15560 other_context->Enter(); 15560 other_context->Enter();
15561 CompileRun(source_eval); 15561 CompileRun(source_eval);
15562 other_context->Exit(); 15562 other_context->Exit();
15563 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15563 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15564 if (GetGlobalObjectsCount() == 1) break; 15564 if (GetGlobalObjectsCount() == 1) break;
15565 } 15565 }
15566 CHECK_GE(2, gc_count); 15566 CHECK_GE(2, gc_count);
15567 CHECK_EQ(1, GetGlobalObjectsCount()); 15567 CHECK_EQ(1, GetGlobalObjectsCount());
15568 15568
15569 // Looking up the line number for an exception creates reference from the 15569 // Looking up the line number for an exception creates reference from the
15570 // compilation cache to the global object. 15570 // compilation cache to the global object.
15571 const char* source_exception = "function f(){throw 1;} f()"; 15571 const char* source_exception = "function f(){throw 1;} f()";
15572 context = Context::New(); 15572 context = Context::New();
15573 { 15573 {
15574 v8::HandleScope scope; 15574 v8::HandleScope scope(v8::Isolate::GetCurrent());
15575 15575
15576 context->Enter(); 15576 context->Enter();
15577 v8::TryCatch try_catch; 15577 v8::TryCatch try_catch;
15578 CompileRun(source_exception); 15578 CompileRun(source_exception);
15579 CHECK(try_catch.HasCaught()); 15579 CHECK(try_catch.HasCaught());
15580 v8::Handle<v8::Message> message = try_catch.Message(); 15580 v8::Handle<v8::Message> message = try_catch.Message();
15581 CHECK(!message.IsEmpty()); 15581 CHECK(!message.IsEmpty());
15582 CHECK_EQ(1, message->GetLineNumber()); 15582 CHECK_EQ(1, message->GetLineNumber());
15583 context->Exit(); 15583 context->Exit();
15584 } 15584 }
15585 context.Dispose(context->GetIsolate()); 15585 context.Dispose(context->GetIsolate());
15586 v8::V8::ContextDisposedNotification(); 15586 v8::V8::ContextDisposedNotification();
15587 for (gc_count = 1; gc_count < 10; gc_count++) { 15587 for (gc_count = 1; gc_count < 10; gc_count++) {
15588 other_context->Enter(); 15588 other_context->Enter();
15589 CompileRun(source_exception); 15589 CompileRun(source_exception);
15590 other_context->Exit(); 15590 other_context->Exit();
15591 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15591 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15592 if (GetGlobalObjectsCount() == 1) break; 15592 if (GetGlobalObjectsCount() == 1) break;
15593 } 15593 }
15594 CHECK_GE(2, gc_count); 15594 CHECK_GE(2, gc_count);
15595 CHECK_EQ(1, GetGlobalObjectsCount()); 15595 CHECK_EQ(1, GetGlobalObjectsCount());
15596 15596
15597 other_context.Dispose(other_context->GetIsolate()); 15597 other_context.Dispose(other_context->GetIsolate());
15598 v8::V8::ContextDisposedNotification(); 15598 v8::V8::ContextDisposedNotification();
15599 } 15599 }
15600 15600
15601 15601
15602 THREADED_TEST(ScriptOrigin) { 15602 THREADED_TEST(ScriptOrigin) {
15603 v8::HandleScope scope;
15604 LocalContext env; 15603 LocalContext env;
15604 v8::HandleScope scope(env->GetIsolate());
15605 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15605 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15606 v8::Handle<v8::String> script = v8::String::New( 15606 v8::Handle<v8::String> script = v8::String::New(
15607 "function f() {}\n\nfunction g() {}"); 15607 "function f() {}\n\nfunction g() {}");
15608 v8::Script::Compile(script, &origin)->Run(); 15608 v8::Script::Compile(script, &origin)->Run();
15609 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15609 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15610 env->Global()->Get(v8::String::New("f"))); 15610 env->Global()->Get(v8::String::New("f")));
15611 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 15611 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
15612 env->Global()->Get(v8::String::New("g"))); 15612 env->Global()->Get(v8::String::New("g")));
15613 15613
15614 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); 15614 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin();
15615 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName())); 15615 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName()));
15616 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); 15616 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value());
15617 15617
15618 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); 15618 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin();
15619 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName())); 15619 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName()));
15620 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); 15620 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
15621 } 15621 }
15622 15622
15623 THREADED_TEST(FunctionGetInferredName) { 15623 THREADED_TEST(FunctionGetInferredName) {
15624 v8::HandleScope scope;
15625 LocalContext env; 15624 LocalContext env;
15625 v8::HandleScope scope(env->GetIsolate());
15626 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15626 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15627 v8::Handle<v8::String> script = v8::String::New( 15627 v8::Handle<v8::String> script = v8::String::New(
15628 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); 15628 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;");
15629 v8::Script::Compile(script, &origin)->Run(); 15629 v8::Script::Compile(script, &origin)->Run();
15630 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15630 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15631 env->Global()->Get(v8::String::New("f"))); 15631 env->Global()->Get(v8::String::New("f")));
15632 CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName())); 15632 CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName()));
15633 } 15633 }
15634 15634
15635 THREADED_TEST(ScriptLineNumber) { 15635 THREADED_TEST(ScriptLineNumber) {
15636 v8::HandleScope scope;
15637 LocalContext env; 15636 LocalContext env;
15637 v8::HandleScope scope(env->GetIsolate());
15638 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 15638 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
15639 v8::Handle<v8::String> script = v8::String::New( 15639 v8::Handle<v8::String> script = v8::String::New(
15640 "function f() {}\n\nfunction g() {}"); 15640 "function f() {}\n\nfunction g() {}");
15641 v8::Script::Compile(script, &origin)->Run(); 15641 v8::Script::Compile(script, &origin)->Run();
15642 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 15642 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
15643 env->Global()->Get(v8::String::New("f"))); 15643 env->Global()->Get(v8::String::New("f")));
15644 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 15644 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
15645 env->Global()->Get(v8::String::New("g"))); 15645 env->Global()->Get(v8::String::New("g")));
15646 CHECK_EQ(0, f->GetScriptLineNumber()); 15646 CHECK_EQ(0, f->GetScriptLineNumber());
15647 CHECK_EQ(2, g->GetScriptLineNumber()); 15647 CHECK_EQ(2, g->GetScriptLineNumber());
15648 } 15648 }
15649 15649
15650 15650
15651 THREADED_TEST(ScriptColumnNumber) { 15651 THREADED_TEST(ScriptColumnNumber) {
15652 v8::HandleScope scope;
15653 LocalContext env; 15652 LocalContext env;
15653 v8::HandleScope scope(env->GetIsolate());
15654 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 15654 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"),
15655 v8::Integer::New(3), v8::Integer::New(2)); 15655 v8::Integer::New(3), v8::Integer::New(2));
15656 v8::Handle<v8::String> script = v8::String::New( 15656 v8::Handle<v8::String> script = v8::String::New(
15657 "function foo() {}\n\n function bar() {}"); 15657 "function foo() {}\n\n function bar() {}");
15658 v8::Script::Compile(script, &origin)->Run(); 15658 v8::Script::Compile(script, &origin)->Run();
15659 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 15659 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
15660 env->Global()->Get(v8::String::New("foo"))); 15660 env->Global()->Get(v8::String::New("foo")));
15661 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 15661 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
15662 env->Global()->Get(v8::String::New("bar"))); 15662 env->Global()->Get(v8::String::New("bar")));
15663 CHECK_EQ(14, foo->GetScriptColumnNumber()); 15663 CHECK_EQ(14, foo->GetScriptColumnNumber());
15664 CHECK_EQ(17, bar->GetScriptColumnNumber()); 15664 CHECK_EQ(17, bar->GetScriptColumnNumber());
15665 } 15665 }
15666 15666
15667 15667
15668 THREADED_TEST(FunctionGetScriptId) { 15668 THREADED_TEST(FunctionGetScriptId) {
15669 v8::HandleScope scope;
15670 LocalContext env; 15669 LocalContext env;
15670 v8::HandleScope scope(env->GetIsolate());
15671 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"), 15671 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"),
15672 v8::Integer::New(3), v8::Integer::New(2)); 15672 v8::Integer::New(3), v8::Integer::New(2));
15673 v8::Handle<v8::String> scriptSource = v8::String::New( 15673 v8::Handle<v8::String> scriptSource = v8::String::New(
15674 "function foo() {}\n\n function bar() {}"); 15674 "function foo() {}\n\n function bar() {}");
15675 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 15675 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
15676 script->Run(); 15676 script->Run();
15677 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 15677 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast(
15678 env->Global()->Get(v8::String::New("foo"))); 15678 env->Global()->Get(v8::String::New("foo")));
15679 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 15679 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast(
15680 env->Global()->Get(v8::String::New("bar"))); 15680 env->Global()->Get(v8::String::New("bar")));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
15714 const AccessorInfo& info) { 15714 const AccessorInfo& info) {
15715 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); 15715 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject());
15716 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); 15716 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject());
15717 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); 15717 if (!name->Equals(v8_str("foo"))) return Handle<Value>();
15718 info.This()->Set(v8_str("y"), v8_num(23)); 15718 info.This()->Set(v8_str("y"), v8_num(23));
15719 return v8_num(23); 15719 return v8_num(23);
15720 } 15720 }
15721 15721
15722 15722
15723 TEST(SetterOnConstructorPrototype) { 15723 TEST(SetterOnConstructorPrototype) {
15724 v8::HandleScope scope; 15724 v8::HandleScope scope(v8::Isolate::GetCurrent());
15725 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15725 Local<ObjectTemplate> templ = ObjectTemplate::New();
15726 templ->SetAccessor(v8_str("x"), 15726 templ->SetAccessor(v8_str("x"),
15727 GetterWhichReturns42, 15727 GetterWhichReturns42,
15728 SetterWhichSetsYOnThisTo23); 15728 SetterWhichSetsYOnThisTo23);
15729 LocalContext context; 15729 LocalContext context;
15730 context->Global()->Set(v8_str("P"), templ->NewInstance()); 15730 context->Global()->Set(v8_str("P"), templ->NewInstance());
15731 CompileRun("function C1() {" 15731 CompileRun("function C1() {"
15732 " this.x = 23;" 15732 " this.x = 23;"
15733 "};" 15733 "};"
15734 "C1.prototype = P;" 15734 "C1.prototype = P;"
(...skipping 29 matching lines...) Expand all
15764 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23( 15764 static v8::Handle<Value> NamedPropertySetterWhichSetsYOnThisTo23(
15765 Local<String> name, Local<Value> value, const AccessorInfo& info) { 15765 Local<String> name, Local<Value> value, const AccessorInfo& info) {
15766 if (name->Equals(v8_str("x"))) { 15766 if (name->Equals(v8_str("x"))) {
15767 info.This()->Set(v8_str("y"), v8_num(23)); 15767 info.This()->Set(v8_str("y"), v8_num(23));
15768 } 15768 }
15769 return v8::Handle<Value>(); 15769 return v8::Handle<Value>();
15770 } 15770 }
15771 15771
15772 15772
15773 THREADED_TEST(InterceptorOnConstructorPrototype) { 15773 THREADED_TEST(InterceptorOnConstructorPrototype) {
15774 v8::HandleScope scope; 15774 v8::HandleScope scope(v8::Isolate::GetCurrent());
15775 Local<ObjectTemplate> templ = ObjectTemplate::New(); 15775 Local<ObjectTemplate> templ = ObjectTemplate::New();
15776 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42, 15776 templ->SetNamedPropertyHandler(NamedPropertyGetterWhichReturns42,
15777 NamedPropertySetterWhichSetsYOnThisTo23); 15777 NamedPropertySetterWhichSetsYOnThisTo23);
15778 LocalContext context; 15778 LocalContext context;
15779 context->Global()->Set(v8_str("P"), templ->NewInstance()); 15779 context->Global()->Set(v8_str("P"), templ->NewInstance());
15780 CompileRun("function C1() {" 15780 CompileRun("function C1() {"
15781 " this.x = 23;" 15781 " this.x = 23;"
15782 "};" 15782 "};"
15783 "C1.prototype = P;" 15783 "C1.prototype = P;"
15784 "function C2() {" 15784 "function C2() {"
(...skipping 18 matching lines...) Expand all
15803 } 15803 }
15804 } 15804 }
15805 15805
15806 15806
15807 TEST(Bug618) { 15807 TEST(Bug618) {
15808 const char* source = "function C1() {" 15808 const char* source = "function C1() {"
15809 " this.x = 23;" 15809 " this.x = 23;"
15810 "};" 15810 "};"
15811 "C1.prototype = P;"; 15811 "C1.prototype = P;";
15812 15812
15813 v8::HandleScope scope;
15814 LocalContext context; 15813 LocalContext context;
15814 v8::HandleScope scope(context->GetIsolate());
15815 v8::Local<v8::Script> script; 15815 v8::Local<v8::Script> script;
15816 15816
15817 // Use a simple object as prototype. 15817 // Use a simple object as prototype.
15818 v8::Local<v8::Object> prototype = v8::Object::New(); 15818 v8::Local<v8::Object> prototype = v8::Object::New();
15819 prototype->Set(v8_str("y"), v8_num(42)); 15819 prototype->Set(v8_str("y"), v8_num(42));
15820 context->Global()->Set(v8_str("P"), prototype); 15820 context->Global()->Set(v8_str("P"), prototype);
15821 15821
15822 // This compile will add the code to the compilation cache. 15822 // This compile will add the code to the compilation cache.
15823 CompileRun(source); 15823 CompileRun(source);
15824 15824
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
15899 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 15899 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
15900 CHECK_EQ(2, prologue_call_count); 15900 CHECK_EQ(2, prologue_call_count);
15901 CHECK_EQ(2, epilogue_call_count); 15901 CHECK_EQ(2, epilogue_call_count);
15902 CHECK_EQ(2, prologue_call_count_second); 15902 CHECK_EQ(2, prologue_call_count_second);
15903 CHECK_EQ(2, epilogue_call_count_second); 15903 CHECK_EQ(2, epilogue_call_count_second);
15904 } 15904 }
15905 15905
15906 15906
15907 THREADED_TEST(AddToJSFunctionResultCache) { 15907 THREADED_TEST(AddToJSFunctionResultCache) {
15908 i::FLAG_allow_natives_syntax = true; 15908 i::FLAG_allow_natives_syntax = true;
15909 v8::HandleScope scope; 15909 v8::HandleScope scope(v8::Isolate::GetCurrent());
15910 15910
15911 LocalContext context; 15911 LocalContext context;
15912 15912
15913 const char* code = 15913 const char* code =
15914 "(function() {" 15914 "(function() {"
15915 " var key0 = 'a';" 15915 " var key0 = 'a';"
15916 " var key1 = 'b';" 15916 " var key1 = 'b';"
15917 " var r0 = %_GetFromCache(0, key0);" 15917 " var r0 = %_GetFromCache(0, key0);"
15918 " var r1 = %_GetFromCache(0, key1);" 15918 " var r1 = %_GetFromCache(0, key1);"
15919 " var r0_ = %_GetFromCache(0, key0);" 15919 " var r0_ = %_GetFromCache(0, key0);"
15920 " if (r0 !== r0_)" 15920 " if (r0 !== r0_)"
15921 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;" 15921 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
15922 " var r1_ = %_GetFromCache(0, key1);" 15922 " var r1_ = %_GetFromCache(0, key1);"
15923 " if (r1 !== r1_)" 15923 " if (r1 !== r1_)"
15924 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" 15924 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
15925 " return 'PASSED';" 15925 " return 'PASSED';"
15926 "})()"; 15926 "})()";
15927 HEAP->ClearJSFunctionResultCaches(); 15927 HEAP->ClearJSFunctionResultCaches();
15928 ExpectString(code, "PASSED"); 15928 ExpectString(code, "PASSED");
15929 } 15929 }
15930 15930
15931 15931
15932 static const int k0CacheSize = 16; 15932 static const int k0CacheSize = 16;
15933 15933
15934 THREADED_TEST(FillJSFunctionResultCache) { 15934 THREADED_TEST(FillJSFunctionResultCache) {
15935 i::FLAG_allow_natives_syntax = true; 15935 i::FLAG_allow_natives_syntax = true;
15936 v8::HandleScope scope;
15937
15938 LocalContext context; 15936 LocalContext context;
15937 v8::HandleScope scope(context->GetIsolate());
15939 15938
15940 const char* code = 15939 const char* code =
15941 "(function() {" 15940 "(function() {"
15942 " var k = 'a';" 15941 " var k = 'a';"
15943 " var r = %_GetFromCache(0, k);" 15942 " var r = %_GetFromCache(0, k);"
15944 " for (var i = 0; i < 16; i++) {" 15943 " for (var i = 0; i < 16; i++) {"
15945 " %_GetFromCache(0, 'a' + i);" 15944 " %_GetFromCache(0, 'a' + i);"
15946 " };" 15945 " };"
15947 " if (r === %_GetFromCache(0, k))" 15946 " if (r === %_GetFromCache(0, k))"
15948 " return 'FAILED: k0CacheSize is too small';" 15947 " return 'FAILED: k0CacheSize is too small';"
15949 " return 'PASSED';" 15948 " return 'PASSED';"
15950 "})()"; 15949 "})()";
15951 HEAP->ClearJSFunctionResultCaches(); 15950 HEAP->ClearJSFunctionResultCaches();
15952 ExpectString(code, "PASSED"); 15951 ExpectString(code, "PASSED");
15953 } 15952 }
15954 15953
15955 15954
15956 THREADED_TEST(RoundRobinGetFromCache) { 15955 THREADED_TEST(RoundRobinGetFromCache) {
15957 i::FLAG_allow_natives_syntax = true; 15956 i::FLAG_allow_natives_syntax = true;
15958 v8::HandleScope scope;
15959
15960 LocalContext context; 15957 LocalContext context;
15958 v8::HandleScope scope(context->GetIsolate());
15961 15959
15962 const char* code = 15960 const char* code =
15963 "(function() {" 15961 "(function() {"
15964 " var keys = [];" 15962 " var keys = [];"
15965 " for (var i = 0; i < 16; i++) keys.push(i);" 15963 " for (var i = 0; i < 16; i++) keys.push(i);"
15966 " var values = [];" 15964 " var values = [];"
15967 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 15965 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15968 " for (var i = 0; i < 16; i++) {" 15966 " for (var i = 0; i < 16; i++) {"
15969 " var v = %_GetFromCache(0, keys[i]);" 15967 " var v = %_GetFromCache(0, keys[i]);"
15970 " if (v.toString() !== values[i].toString())" 15968 " if (v.toString() !== values[i].toString())"
15971 " return 'Wrong value for ' + " 15969 " return 'Wrong value for ' + "
15972 " keys[i] + ': ' + v + ' vs. ' + values[i];" 15970 " keys[i] + ': ' + v + ' vs. ' + values[i];"
15973 " };" 15971 " };"
15974 " return 'PASSED';" 15972 " return 'PASSED';"
15975 "})()"; 15973 "})()";
15976 HEAP->ClearJSFunctionResultCaches(); 15974 HEAP->ClearJSFunctionResultCaches();
15977 ExpectString(code, "PASSED"); 15975 ExpectString(code, "PASSED");
15978 } 15976 }
15979 15977
15980 15978
15981 THREADED_TEST(ReverseGetFromCache) { 15979 THREADED_TEST(ReverseGetFromCache) {
15982 i::FLAG_allow_natives_syntax = true; 15980 i::FLAG_allow_natives_syntax = true;
15983 v8::HandleScope scope;
15984
15985 LocalContext context; 15981 LocalContext context;
15982 v8::HandleScope scope(context->GetIsolate());
15986 15983
15987 const char* code = 15984 const char* code =
15988 "(function() {" 15985 "(function() {"
15989 " var keys = [];" 15986 " var keys = [];"
15990 " for (var i = 0; i < 16; i++) keys.push(i);" 15987 " for (var i = 0; i < 16; i++) keys.push(i);"
15991 " var values = [];" 15988 " var values = [];"
15992 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" 15989 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
15993 " for (var i = 15; i >= 16; i--) {" 15990 " for (var i = 15; i >= 16; i--) {"
15994 " var v = %_GetFromCache(0, keys[i]);" 15991 " var v = %_GetFromCache(0, keys[i]);"
15995 " if (v !== values[i])" 15992 " if (v !== values[i])"
15996 " return 'Wrong value for ' + " 15993 " return 'Wrong value for ' + "
15997 " keys[i] + ': ' + v + ' vs. ' + values[i];" 15994 " keys[i] + ': ' + v + ' vs. ' + values[i];"
15998 " };" 15995 " };"
15999 " return 'PASSED';" 15996 " return 'PASSED';"
16000 "})()"; 15997 "})()";
16001 HEAP->ClearJSFunctionResultCaches(); 15998 HEAP->ClearJSFunctionResultCaches();
16002 ExpectString(code, "PASSED"); 15999 ExpectString(code, "PASSED");
16003 } 16000 }
16004 16001
16005 16002
16006 THREADED_TEST(TestEviction) { 16003 THREADED_TEST(TestEviction) {
16007 i::FLAG_allow_natives_syntax = true; 16004 i::FLAG_allow_natives_syntax = true;
16008 v8::HandleScope scope;
16009
16010 LocalContext context; 16005 LocalContext context;
16006 v8::HandleScope scope(context->GetIsolate());
16011 16007
16012 const char* code = 16008 const char* code =
16013 "(function() {" 16009 "(function() {"
16014 " for (var i = 0; i < 2*16; i++) {" 16010 " for (var i = 0; i < 2*16; i++) {"
16015 " %_GetFromCache(0, 'a' + i);" 16011 " %_GetFromCache(0, 'a' + i);"
16016 " };" 16012 " };"
16017 " return 'PASSED';" 16013 " return 'PASSED';"
16018 "})()"; 16014 "})()";
16019 HEAP->ClearJSFunctionResultCaches(); 16015 HEAP->ClearJSFunctionResultCaches();
16020 ExpectString(code, "PASSED"); 16016 ExpectString(code, "PASSED");
16021 } 16017 }
16022 16018
16023 16019
16024 THREADED_TEST(TwoByteStringInAsciiCons) { 16020 THREADED_TEST(TwoByteStringInAsciiCons) {
16025 // See Chromium issue 47824. 16021 // See Chromium issue 47824.
16026 v8::HandleScope scope; 16022 LocalContext context;
16023 v8::HandleScope scope(context->GetIsolate());
16027 16024
16028 LocalContext context;
16029 const char* init_code = 16025 const char* init_code =
16030 "var str1 = 'abelspendabel';" 16026 "var str1 = 'abelspendabel';"
16031 "var str2 = str1 + str1 + str1;" 16027 "var str2 = str1 + str1 + str1;"
16032 "str2;"; 16028 "str2;";
16033 Local<Value> result = CompileRun(init_code); 16029 Local<Value> result = CompileRun(init_code);
16034 16030
16035 Local<Value> indexof = CompileRun("str2.indexOf('els')"); 16031 Local<Value> indexof = CompileRun("str2.indexOf('els')");
16036 Local<Value> lastindexof = CompileRun("str2.lastIndexOf('dab')"); 16032 Local<Value> lastindexof = CompileRun("str2.lastIndexOf('dab')");
16037 16033
16038 CHECK(result->IsString()); 16034 CHECK(result->IsString());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
16117 } 16113 }
16118 16114
16119 16115
16120 TEST(GCInFailedAccessCheckCallback) { 16116 TEST(GCInFailedAccessCheckCallback) {
16121 // Install a failed access check callback that performs a GC on each 16117 // Install a failed access check callback that performs a GC on each
16122 // invocation. Then force the callback to be called from va 16118 // invocation. Then force the callback to be called from va
16123 16119
16124 v8::V8::Initialize(); 16120 v8::V8::Initialize();
16125 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 16121 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
16126 16122
16127 v8::HandleScope scope; 16123 v8::HandleScope scope(v8::Isolate::GetCurrent());
16128 16124
16129 // Create an ObjectTemplate for global objects and install access 16125 // Create an ObjectTemplate for global objects and install access
16130 // check callbacks that will block access. 16126 // check callbacks that will block access.
16131 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 16127 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
16132 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker, 16128 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
16133 IndexedGetAccessBlocker, 16129 IndexedGetAccessBlocker,
16134 v8::Handle<v8::Value>(), 16130 v8::Handle<v8::Value>(),
16135 false); 16131 false);
16136 16132
16137 // Create a context and set an x property on it's global object. 16133 // 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
16210 CHECK(current_isolate == v8::Isolate::GetCurrent()); 16206 CHECK(current_isolate == v8::Isolate::GetCurrent());
16211 16207
16212 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16208 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16213 last_location = last_message = NULL; 16209 last_location = last_message = NULL;
16214 isolate->Dispose(); 16210 isolate->Dispose();
16215 CHECK_EQ(last_location, NULL); 16211 CHECK_EQ(last_location, NULL);
16216 CHECK_EQ(last_message, NULL); 16212 CHECK_EQ(last_message, NULL);
16217 } 16213 }
16218 16214
16219 TEST(IsolateEnterExitDefault) { 16215 TEST(IsolateEnterExitDefault) {
16220 v8::HandleScope scope;
16221 LocalContext context;
16222 v8::Isolate* current_isolate = v8::Isolate::GetCurrent(); 16216 v8::Isolate* current_isolate = v8::Isolate::GetCurrent();
16223 CHECK(current_isolate != NULL); // Default isolate. 16217 CHECK(current_isolate != NULL); // Default isolate.
16218 v8::HandleScope scope(current_isolate);
16219 LocalContext context;
16224 ExpectString("'hello'", "hello"); 16220 ExpectString("'hello'", "hello");
16225 current_isolate->Enter(); 16221 current_isolate->Enter();
16226 ExpectString("'still working'", "still working"); 16222 ExpectString("'still working'", "still working");
16227 current_isolate->Exit(); 16223 current_isolate->Exit();
16228 ExpectString("'still working 2'", "still working 2"); 16224 ExpectString("'still working 2'", "still working 2");
16229 current_isolate->Exit(); 16225 current_isolate->Exit();
16230 // Default isolate is always, well, 'default current'. 16226 // Default isolate is always, well, 'default current'.
16231 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate); 16227 CHECK_EQ(v8::Isolate::GetCurrent(), current_isolate);
16232 // Still working since default isolate is auto-entering any thread 16228 // Still working since default isolate is auto-entering any thread
16233 // that has no isolate and attempts to execute V8 APIs. 16229 // that has no isolate and attempts to execute V8 APIs.
16234 ExpectString("'still working 3'", "still working 3"); 16230 ExpectString("'still working 3'", "still working 3");
16235 } 16231 }
16236 16232
16237 TEST(DisposeDefaultIsolate) { 16233 TEST(DisposeDefaultIsolate) {
16238 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16234 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16239 16235
16240 // Run some V8 code to trigger default isolate to become 'current'. 16236 // Run some V8 code to trigger default isolate to become 'current'.
16241 v8::HandleScope scope; 16237 v8::HandleScope scope(v8::Isolate::GetCurrent());
16242 LocalContext context; 16238 LocalContext context;
16243 ExpectString("'run some V8'", "run some V8"); 16239 ExpectString("'run some V8'", "run some V8");
16244 16240
16245 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 16241 v8::Isolate* isolate = v8::Isolate::GetCurrent();
16246 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate()); 16242 CHECK(reinterpret_cast<i::Isolate*>(isolate)->IsDefaultIsolate());
16247 last_location = last_message = NULL; 16243 last_location = last_message = NULL;
16248 isolate->Dispose(); 16244 isolate->Dispose();
16249 // It is not possible to dispose default isolate via Isolate API. 16245 // It is not possible to dispose default isolate via Isolate API.
16250 CHECK_NE(last_location, NULL); 16246 CHECK_NE(last_location, NULL);
16251 CHECK_NE(last_message, NULL); 16247 CHECK_NE(last_message, NULL);
16252 } 16248 }
16253 16249
16254 TEST(RunDefaultAndAnotherIsolate) { 16250 TEST(RunDefaultAndAnotherIsolate) {
16255 v8::HandleScope scope; 16251 v8::HandleScope scope(v8::Isolate::GetCurrent());
16256 LocalContext context; 16252 LocalContext context;
16257 16253
16258 // Enter new isolate. 16254 // Enter new isolate.
16259 v8::Isolate* isolate = v8::Isolate::New(); 16255 v8::Isolate* isolate = v8::Isolate::New();
16260 CHECK(isolate); 16256 CHECK(isolate);
16261 isolate->Enter(); 16257 isolate->Enter();
16262 { // Need this block because subsequent Exit() will deallocate Heap, 16258 { // Need this block because subsequent Exit() will deallocate Heap,
16263 // so we need all scope objects to be deconstructed when it happens. 16259 // so we need all scope objects to be deconstructed when it happens.
16264 v8::HandleScope scope_new; 16260 v8::HandleScope scope_new(isolate);
16265 LocalContext context_new; 16261 LocalContext context_new;
16266 16262
16267 // Run something in new isolate. 16263 // Run something in new isolate.
16268 CompileRun("var foo = 153;"); 16264 CompileRun("var foo = 153;");
16269 ExpectTrue("function f() { return foo == 153; }; f()"); 16265 ExpectTrue("function f() { return foo == 153; }; f()");
16270 } 16266 }
16271 isolate->Exit(); 16267 isolate->Exit();
16272 16268
16273 // This runs automatically in default isolate. 16269 // This runs automatically in default isolate.
16274 // Variables in another isolate should be not available. 16270 // Variables in another isolate should be not available.
(...skipping 15 matching lines...) Expand all
16290 CHECK_EQ(last_message, NULL); 16286 CHECK_EQ(last_message, NULL);
16291 16287
16292 // Check that default isolate still runs. 16288 // Check that default isolate still runs.
16293 ExpectTrue("function f() { return bar == 371; }; f()"); 16289 ExpectTrue("function f() { return bar == 371; }; f()");
16294 } 16290 }
16295 16291
16296 TEST(DisposeIsolateWhenInUse) { 16292 TEST(DisposeIsolateWhenInUse) {
16297 v8::Isolate* isolate = v8::Isolate::New(); 16293 v8::Isolate* isolate = v8::Isolate::New();
16298 CHECK(isolate); 16294 CHECK(isolate);
16299 isolate->Enter(); 16295 isolate->Enter();
16300 v8::HandleScope scope; 16296 v8::HandleScope scope(isolate);
16301 LocalContext context; 16297 LocalContext context;
16302 // Run something in this isolate. 16298 // Run something in this isolate.
16303 ExpectTrue("true"); 16299 ExpectTrue("true");
16304 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16300 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16305 last_location = last_message = NULL; 16301 last_location = last_message = NULL;
16306 // Still entered, should fail. 16302 // Still entered, should fail.
16307 isolate->Dispose(); 16303 isolate->Dispose();
16308 CHECK_NE(last_location, NULL); 16304 CHECK_NE(last_location, NULL);
16309 CHECK_NE(last_message, NULL); 16305 CHECK_NE(last_message, NULL);
16310 } 16306 }
16311 16307
16312 TEST(RunTwoIsolatesOnSingleThread) { 16308 TEST(RunTwoIsolatesOnSingleThread) {
16313 // Run isolate 1. 16309 // Run isolate 1.
16314 v8::Isolate* isolate1 = v8::Isolate::New(); 16310 v8::Isolate* isolate1 = v8::Isolate::New();
16315 isolate1->Enter(); 16311 isolate1->Enter();
16316 v8::Persistent<v8::Context> context1 = v8::Context::New(); 16312 v8::Persistent<v8::Context> context1 = v8::Context::New();
16317 16313
16318 { 16314 {
16319 v8::Context::Scope cscope(context1); 16315 v8::Context::Scope cscope(context1);
16320 v8::HandleScope scope; 16316 v8::HandleScope scope(isolate1);
16321 // Run something in new isolate. 16317 // Run something in new isolate.
16322 CompileRun("var foo = 'isolate 1';"); 16318 CompileRun("var foo = 'isolate 1';");
16323 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16319 ExpectString("function f() { return foo; }; f()", "isolate 1");
16324 } 16320 }
16325 16321
16326 // Run isolate 2. 16322 // Run isolate 2.
16327 v8::Isolate* isolate2 = v8::Isolate::New(); 16323 v8::Isolate* isolate2 = v8::Isolate::New();
16328 v8::Persistent<v8::Context> context2; 16324 v8::Persistent<v8::Context> context2;
16329 16325
16330 { 16326 {
16331 v8::Isolate::Scope iscope(isolate2); 16327 v8::Isolate::Scope iscope(isolate2);
16332 context2 = v8::Context::New(); 16328 context2 = v8::Context::New();
16333 v8::Context::Scope cscope(context2); 16329 v8::Context::Scope cscope(context2);
16334 v8::HandleScope scope; 16330 v8::HandleScope scope(isolate2);
16335 16331
16336 // Run something in new isolate. 16332 // Run something in new isolate.
16337 CompileRun("var foo = 'isolate 2';"); 16333 CompileRun("var foo = 'isolate 2';");
16338 ExpectString("function f() { return foo; }; f()", "isolate 2"); 16334 ExpectString("function f() { return foo; }; f()", "isolate 2");
16339 } 16335 }
16340 16336
16341 { 16337 {
16342 v8::Context::Scope cscope(context1); 16338 v8::Context::Scope cscope(context1);
16343 v8::HandleScope scope; 16339 v8::HandleScope scope(isolate1);
16344 // Now again in isolate 1 16340 // Now again in isolate 1
16345 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16341 ExpectString("function f() { return foo; }; f()", "isolate 1");
16346 } 16342 }
16347 16343
16348 isolate1->Exit(); 16344 isolate1->Exit();
16349 16345
16350 // Run some stuff in default isolate. 16346 // Run some stuff in default isolate.
16351 v8::Persistent<v8::Context> context_default = v8::Context::New(); 16347 v8::Persistent<v8::Context> context_default = v8::Context::New();
16352 16348
16353 { 16349 {
16354 v8::Context::Scope cscope(context_default); 16350 v8::Context::Scope cscope(context_default);
16355 v8::HandleScope scope; 16351 v8::HandleScope scope(v8::Isolate::GetCurrent());
16356 // Variables in other isolates should be not available, verify there 16352 // Variables in other isolates should be not available, verify there
16357 // is an exception. 16353 // is an exception.
16358 ExpectTrue("function f() {" 16354 ExpectTrue("function f() {"
16359 " try {" 16355 " try {"
16360 " foo;" 16356 " foo;"
16361 " return false;" 16357 " return false;"
16362 " } catch(e) {" 16358 " } catch(e) {"
16363 " return true;" 16359 " return true;"
16364 " }" 16360 " }"
16365 "};" 16361 "};"
16366 "var isDefaultIsolate = true;" 16362 "var isDefaultIsolate = true;"
16367 "f()"); 16363 "f()");
16368 } 16364 }
16369 16365
16370 isolate1->Enter(); 16366 isolate1->Enter();
16371 16367
16372 { 16368 {
16373 v8::Isolate::Scope iscope(isolate2); 16369 v8::Isolate::Scope iscope(isolate2);
16374 v8::Context::Scope cscope(context2); 16370 v8::Context::Scope cscope(context2);
16375 v8::HandleScope scope; 16371 v8::HandleScope scope(v8::Isolate::GetCurrent());
16376 ExpectString("function f() { return foo; }; f()", "isolate 2"); 16372 ExpectString("function f() { return foo; }; f()", "isolate 2");
16377 } 16373 }
16378 16374
16379 { 16375 {
16380 v8::Context::Scope cscope(context1); 16376 v8::Context::Scope cscope(context1);
16381 v8::HandleScope scope; 16377 v8::HandleScope scope(v8::Isolate::GetCurrent());
16382 ExpectString("function f() { return foo; }; f()", "isolate 1"); 16378 ExpectString("function f() { return foo; }; f()", "isolate 1");
16383 } 16379 }
16384 16380
16385 { 16381 {
16386 v8::Isolate::Scope iscope(isolate2); 16382 v8::Isolate::Scope iscope(isolate2);
16387 context2.Dispose(context2->GetIsolate()); 16383 context2.Dispose(context2->GetIsolate());
16388 } 16384 }
16389 16385
16390 context1.Dispose(context1->GetIsolate()); 16386 context1.Dispose(context1->GetIsolate());
16391 isolate1->Exit(); 16387 isolate1->Exit();
16392 16388
16393 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 16389 v8::V8::SetFatalErrorHandler(StoringErrorCallback);
16394 last_location = last_message = NULL; 16390 last_location = last_message = NULL;
16395 16391
16396 isolate1->Dispose(); 16392 isolate1->Dispose();
16397 CHECK_EQ(last_location, NULL); 16393 CHECK_EQ(last_location, NULL);
16398 CHECK_EQ(last_message, NULL); 16394 CHECK_EQ(last_message, NULL);
16399 16395
16400 isolate2->Dispose(); 16396 isolate2->Dispose();
16401 CHECK_EQ(last_location, NULL); 16397 CHECK_EQ(last_location, NULL);
16402 CHECK_EQ(last_message, NULL); 16398 CHECK_EQ(last_message, NULL);
16403 16399
16404 // Check that default isolate still runs. 16400 // Check that default isolate still runs.
16405 { 16401 {
16406 v8::Context::Scope cscope(context_default); 16402 v8::Context::Scope cscope(context_default);
16407 v8::HandleScope scope; 16403 v8::HandleScope scope(v8::Isolate::GetCurrent());
16408 ExpectTrue("function f() { return isDefaultIsolate; }; f()"); 16404 ExpectTrue("function f() { return isDefaultIsolate; }; f()");
16409 } 16405 }
16410 } 16406 }
16411 16407
16412 static int CalcFibonacci(v8::Isolate* isolate, int limit) { 16408 static int CalcFibonacci(v8::Isolate* isolate, int limit) {
16413 v8::Isolate::Scope isolate_scope(isolate); 16409 v8::Isolate::Scope isolate_scope(isolate);
16414 v8::HandleScope scope; 16410 v8::HandleScope scope(isolate);
16415 LocalContext context; 16411 LocalContext context;
16416 i::ScopedVector<char> code(1024); 16412 i::ScopedVector<char> code(1024);
16417 i::OS::SNPrintF(code, "function fib(n) {" 16413 i::OS::SNPrintF(code, "function fib(n) {"
16418 " if (n <= 2) return 1;" 16414 " if (n <= 2) return 1;"
16419 " return fib(n-1) + fib(n-2);" 16415 " return fib(n-1) + fib(n-2);"
16420 "}" 16416 "}"
16421 "fib(%d)", limit); 16417 "fib(%d)", limit);
16422 Local<Value> value = CompileRun(code.start()); 16418 Local<Value> value = CompileRun(code.start());
16423 CHECK(value->IsNumber()); 16419 CHECK(value->IsNumber());
16424 return static_cast<int>(value->NumberValue()); 16420 return static_cast<int>(value->NumberValue());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
16470 16466
16471 isolate1->Dispose(); 16467 isolate1->Dispose();
16472 isolate2->Dispose(); 16468 isolate2->Dispose();
16473 } 16469 }
16474 16470
16475 TEST(IsolateDifferentContexts) { 16471 TEST(IsolateDifferentContexts) {
16476 v8::Isolate* isolate = v8::Isolate::New(); 16472 v8::Isolate* isolate = v8::Isolate::New();
16477 Persistent<v8::Context> context; 16473 Persistent<v8::Context> context;
16478 { 16474 {
16479 v8::Isolate::Scope isolate_scope(isolate); 16475 v8::Isolate::Scope isolate_scope(isolate);
16480 v8::HandleScope handle_scope; 16476 v8::HandleScope handle_scope(isolate);
16481 context = v8::Context::New(); 16477 context = v8::Context::New();
16482 v8::Context::Scope context_scope(context); 16478 v8::Context::Scope context_scope(context);
16483 Local<Value> v = CompileRun("2"); 16479 Local<Value> v = CompileRun("2");
16484 CHECK(v->IsNumber()); 16480 CHECK(v->IsNumber());
16485 CHECK_EQ(2, static_cast<int>(v->NumberValue())); 16481 CHECK_EQ(2, static_cast<int>(v->NumberValue()));
16486 } 16482 }
16487 { 16483 {
16488 v8::Isolate::Scope isolate_scope(isolate); 16484 v8::Isolate::Scope isolate_scope(isolate);
16489 v8::HandleScope handle_scope; 16485 v8::HandleScope handle_scope(isolate);
16490 context = v8::Context::New(); 16486 context = v8::Context::New();
16491 v8::Context::Scope context_scope(context); 16487 v8::Context::Scope context_scope(context);
16492 Local<Value> v = CompileRun("22"); 16488 Local<Value> v = CompileRun("22");
16493 CHECK(v->IsNumber()); 16489 CHECK(v->IsNumber());
16494 CHECK_EQ(22, static_cast<int>(v->NumberValue())); 16490 CHECK_EQ(22, static_cast<int>(v->NumberValue()));
16495 } 16491 }
16496 isolate->Dispose(); 16492 isolate->Dispose();
16497 } 16493 }
16498 16494
16499 class InitDefaultIsolateThread : public v8::internal::Thread { 16495 class InitDefaultIsolateThread : public v8::internal::Thread {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
16585 InitializeTestHelper(InitDefaultIsolateThread::SetAddHistogramSampleFunction); 16581 InitializeTestHelper(InitDefaultIsolateThread::SetAddHistogramSampleFunction);
16586 } 16582 }
16587 16583
16588 16584
16589 TEST(StringCheckMultipleContexts) { 16585 TEST(StringCheckMultipleContexts) {
16590 const char* code = 16586 const char* code =
16591 "(function() { return \"a\".charAt(0); })()"; 16587 "(function() { return \"a\".charAt(0); })()";
16592 16588
16593 { 16589 {
16594 // Run the code twice in the first context to initialize the call IC. 16590 // Run the code twice in the first context to initialize the call IC.
16595 v8::HandleScope scope;
16596 LocalContext context1; 16591 LocalContext context1;
16592 v8::HandleScope scope(context1->GetIsolate());
16597 ExpectString(code, "a"); 16593 ExpectString(code, "a");
16598 ExpectString(code, "a"); 16594 ExpectString(code, "a");
16599 } 16595 }
16600 16596
16601 { 16597 {
16602 // Change the String.prototype in the second context and check 16598 // Change the String.prototype in the second context and check
16603 // that the right function gets called. 16599 // that the right function gets called.
16604 v8::HandleScope scope;
16605 LocalContext context2; 16600 LocalContext context2;
16601 v8::HandleScope scope(context2->GetIsolate());
16606 CompileRun("String.prototype.charAt = function() { return \"not a\"; }"); 16602 CompileRun("String.prototype.charAt = function() { return \"not a\"; }");
16607 ExpectString(code, "not a"); 16603 ExpectString(code, "not a");
16608 } 16604 }
16609 } 16605 }
16610 16606
16611 16607
16612 TEST(NumberCheckMultipleContexts) { 16608 TEST(NumberCheckMultipleContexts) {
16613 const char* code = 16609 const char* code =
16614 "(function() { return (42).toString(); })()"; 16610 "(function() { return (42).toString(); })()";
16615 16611
16616 { 16612 {
16617 // Run the code twice in the first context to initialize the call IC. 16613 // Run the code twice in the first context to initialize the call IC.
16618 v8::HandleScope scope;
16619 LocalContext context1; 16614 LocalContext context1;
16615 v8::HandleScope scope(context1->GetIsolate());
16620 ExpectString(code, "42"); 16616 ExpectString(code, "42");
16621 ExpectString(code, "42"); 16617 ExpectString(code, "42");
16622 } 16618 }
16623 16619
16624 { 16620 {
16625 // Change the Number.prototype in the second context and check 16621 // Change the Number.prototype in the second context and check
16626 // that the right function gets called. 16622 // that the right function gets called.
16627 v8::HandleScope scope;
16628 LocalContext context2; 16623 LocalContext context2;
16624 v8::HandleScope scope(context2->GetIsolate());
16629 CompileRun("Number.prototype.toString = function() { return \"not 42\"; }"); 16625 CompileRun("Number.prototype.toString = function() { return \"not 42\"; }");
16630 ExpectString(code, "not 42"); 16626 ExpectString(code, "not 42");
16631 } 16627 }
16632 } 16628 }
16633 16629
16634 16630
16635 TEST(BooleanCheckMultipleContexts) { 16631 TEST(BooleanCheckMultipleContexts) {
16636 const char* code = 16632 const char* code =
16637 "(function() { return true.toString(); })()"; 16633 "(function() { return true.toString(); })()";
16638 16634
16639 { 16635 {
16640 // Run the code twice in the first context to initialize the call IC. 16636 // Run the code twice in the first context to initialize the call IC.
16641 v8::HandleScope scope;
16642 LocalContext context1; 16637 LocalContext context1;
16638 v8::HandleScope scope(context1->GetIsolate());
16643 ExpectString(code, "true"); 16639 ExpectString(code, "true");
16644 ExpectString(code, "true"); 16640 ExpectString(code, "true");
16645 } 16641 }
16646 16642
16647 { 16643 {
16648 // Change the Boolean.prototype in the second context and check 16644 // Change the Boolean.prototype in the second context and check
16649 // that the right function gets called. 16645 // that the right function gets called.
16650 v8::HandleScope scope;
16651 LocalContext context2; 16646 LocalContext context2;
16647 v8::HandleScope scope(context2->GetIsolate());
16652 CompileRun("Boolean.prototype.toString = function() { return \"\"; }"); 16648 CompileRun("Boolean.prototype.toString = function() { return \"\"; }");
16653 ExpectString(code, ""); 16649 ExpectString(code, "");
16654 } 16650 }
16655 } 16651 }
16656 16652
16657 16653
16658 TEST(DontDeleteCellLoadIC) { 16654 TEST(DontDeleteCellLoadIC) {
16659 const char* function_code = 16655 const char* function_code =
16660 "function readCell() { while (true) { return cell; } }"; 16656 "function readCell() { while (true) { return cell; } }";
16661 16657
16662 { 16658 {
16663 // Run the code twice in the first context to initialize the load 16659 // Run the code twice in the first context to initialize the load
16664 // IC for a don't delete cell. 16660 // IC for a don't delete cell.
16665 v8::HandleScope scope;
16666 LocalContext context1; 16661 LocalContext context1;
16662 v8::HandleScope scope(context1->GetIsolate());
16667 CompileRun("var cell = \"first\";"); 16663 CompileRun("var cell = \"first\";");
16668 ExpectBoolean("delete cell", false); 16664 ExpectBoolean("delete cell", false);
16669 CompileRun(function_code); 16665 CompileRun(function_code);
16670 ExpectString("readCell()", "first"); 16666 ExpectString("readCell()", "first");
16671 ExpectString("readCell()", "first"); 16667 ExpectString("readCell()", "first");
16672 } 16668 }
16673 16669
16674 { 16670 {
16675 // Use a deletable cell in the second context. 16671 // Use a deletable cell in the second context.
16676 v8::HandleScope scope;
16677 LocalContext context2; 16672 LocalContext context2;
16673 v8::HandleScope scope(context2->GetIsolate());
16678 CompileRun("cell = \"second\";"); 16674 CompileRun("cell = \"second\";");
16679 CompileRun(function_code); 16675 CompileRun(function_code);
16680 ExpectString("readCell()", "second"); 16676 ExpectString("readCell()", "second");
16681 ExpectBoolean("delete cell", true); 16677 ExpectBoolean("delete cell", true);
16682 ExpectString("(function() {" 16678 ExpectString("(function() {"
16683 " try {" 16679 " try {"
16684 " return readCell();" 16680 " return readCell();"
16685 " } catch(e) {" 16681 " } catch(e) {"
16686 " return e.toString();" 16682 " return e.toString();"
16687 " }" 16683 " }"
16688 "})()", 16684 "})()",
16689 "ReferenceError: cell is not defined"); 16685 "ReferenceError: cell is not defined");
16690 CompileRun("cell = \"new_second\";"); 16686 CompileRun("cell = \"new_second\";");
16691 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16687 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16692 ExpectString("readCell()", "new_second"); 16688 ExpectString("readCell()", "new_second");
16693 ExpectString("readCell()", "new_second"); 16689 ExpectString("readCell()", "new_second");
16694 } 16690 }
16695 } 16691 }
16696 16692
16697 16693
16698 TEST(DontDeleteCellLoadICForceDelete) { 16694 TEST(DontDeleteCellLoadICForceDelete) {
16699 const char* function_code = 16695 const char* function_code =
16700 "function readCell() { while (true) { return cell; } }"; 16696 "function readCell() { while (true) { return cell; } }";
16701 16697
16702 // Run the code twice to initialize the load IC for a don't delete 16698 // Run the code twice to initialize the load IC for a don't delete
16703 // cell. 16699 // cell.
16704 v8::HandleScope scope;
16705 LocalContext context; 16700 LocalContext context;
16701 v8::HandleScope scope(context->GetIsolate());
16706 CompileRun("var cell = \"value\";"); 16702 CompileRun("var cell = \"value\";");
16707 ExpectBoolean("delete cell", false); 16703 ExpectBoolean("delete cell", false);
16708 CompileRun(function_code); 16704 CompileRun(function_code);
16709 ExpectString("readCell()", "value"); 16705 ExpectString("readCell()", "value");
16710 ExpectString("readCell()", "value"); 16706 ExpectString("readCell()", "value");
16711 16707
16712 // Delete the cell using the API and check the inlined code works 16708 // Delete the cell using the API and check the inlined code works
16713 // correctly. 16709 // correctly.
16714 CHECK(context->Global()->ForceDelete(v8_str("cell"))); 16710 CHECK(context->Global()->ForceDelete(v8_str("cell")));
16715 ExpectString("(function() {" 16711 ExpectString("(function() {"
16716 " try {" 16712 " try {"
16717 " return readCell();" 16713 " return readCell();"
16718 " } catch(e) {" 16714 " } catch(e) {"
16719 " return e.toString();" 16715 " return e.toString();"
16720 " }" 16716 " }"
16721 "})()", 16717 "})()",
16722 "ReferenceError: cell is not defined"); 16718 "ReferenceError: cell is not defined");
16723 } 16719 }
16724 16720
16725 16721
16726 TEST(DontDeleteCellLoadICAPI) { 16722 TEST(DontDeleteCellLoadICAPI) {
16727 const char* function_code = 16723 const char* function_code =
16728 "function readCell() { while (true) { return cell; } }"; 16724 "function readCell() { while (true) { return cell; } }";
16729 16725
16730 // Run the code twice to initialize the load IC for a don't delete 16726 // Run the code twice to initialize the load IC for a don't delete
16731 // cell created using the API. 16727 // cell created using the API.
16732 v8::HandleScope scope;
16733 LocalContext context; 16728 LocalContext context;
16729 v8::HandleScope scope(context->GetIsolate());
16734 context->Global()->Set(v8_str("cell"), v8_str("value"), v8::DontDelete); 16730 context->Global()->Set(v8_str("cell"), v8_str("value"), v8::DontDelete);
16735 ExpectBoolean("delete cell", false); 16731 ExpectBoolean("delete cell", false);
16736 CompileRun(function_code); 16732 CompileRun(function_code);
16737 ExpectString("readCell()", "value"); 16733 ExpectString("readCell()", "value");
16738 ExpectString("readCell()", "value"); 16734 ExpectString("readCell()", "value");
16739 16735
16740 // Delete the cell using the API and check the inlined code works 16736 // Delete the cell using the API and check the inlined code works
16741 // correctly. 16737 // correctly.
16742 CHECK(context->Global()->ForceDelete(v8_str("cell"))); 16738 CHECK(context->Global()->ForceDelete(v8_str("cell")));
16743 ExpectString("(function() {" 16739 ExpectString("(function() {"
(...skipping 23 matching lines...) Expand all
16767 ++counter_; 16763 ++counter_;
16768 } 16764 }
16769 } 16765 }
16770 16766
16771 int counter_; 16767 int counter_;
16772 v8::Persistent<v8::Object> object_; 16768 v8::Persistent<v8::Object> object_;
16773 }; 16769 };
16774 16770
16775 16771
16776 TEST(PersistentHandleVisitor) { 16772 TEST(PersistentHandleVisitor) {
16777 v8::HandleScope scope;
16778 LocalContext context; 16773 LocalContext context;
16779 v8::Isolate* isolate = context->GetIsolate(); 16774 v8::Isolate* isolate = context->GetIsolate();
16775 v8::HandleScope scope(isolate);
16780 v8::Persistent<v8::Object> object = 16776 v8::Persistent<v8::Object> object =
16781 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16777 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16782 CHECK_EQ(0, object.WrapperClassId(isolate)); 16778 CHECK_EQ(0, object.WrapperClassId(isolate));
16783 object.SetWrapperClassId(isolate, 42); 16779 object.SetWrapperClassId(isolate, 42);
16784 CHECK_EQ(42, object.WrapperClassId(isolate)); 16780 CHECK_EQ(42, object.WrapperClassId(isolate));
16785 16781
16786 Visitor42 visitor(object); 16782 Visitor42 visitor(object);
16787 v8::V8::VisitHandlesWithClassIds(&visitor); 16783 v8::V8::VisitHandlesWithClassIds(&visitor);
16788 CHECK_EQ(1, visitor.counter_); 16784 CHECK_EQ(1, visitor.counter_);
16789 16785
16790 object.Dispose(isolate); 16786 object.Dispose(isolate);
16791 } 16787 }
16792 16788
16793 16789
16794 TEST(WrapperClassId) { 16790 TEST(WrapperClassId) {
16795 v8::HandleScope scope;
16796 LocalContext context; 16791 LocalContext context;
16797 v8::Isolate* isolate = context->GetIsolate(); 16792 v8::Isolate* isolate = context->GetIsolate();
16793 v8::HandleScope scope(isolate);
16798 v8::Persistent<v8::Object> object = 16794 v8::Persistent<v8::Object> object =
16799 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16795 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16800 CHECK_EQ(0, object.WrapperClassId(isolate)); 16796 CHECK_EQ(0, object.WrapperClassId(isolate));
16801 object.SetWrapperClassId(isolate, 65535); 16797 object.SetWrapperClassId(isolate, 65535);
16802 CHECK_EQ(65535, object.WrapperClassId(isolate)); 16798 CHECK_EQ(65535, object.WrapperClassId(isolate));
16803 object.Dispose(isolate); 16799 object.Dispose(isolate);
16804 } 16800 }
16805 16801
16806 16802
16807 TEST(PersistentHandleInNewSpaceVisitor) { 16803 TEST(PersistentHandleInNewSpaceVisitor) {
16808 v8::HandleScope scope;
16809 LocalContext context; 16804 LocalContext context;
16810 v8::Isolate* isolate = context->GetIsolate(); 16805 v8::Isolate* isolate = context->GetIsolate();
16806 v8::HandleScope scope(isolate);
16811 v8::Persistent<v8::Object> object1 = 16807 v8::Persistent<v8::Object> object1 =
16812 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16808 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16813 CHECK_EQ(0, object1.WrapperClassId(isolate)); 16809 CHECK_EQ(0, object1.WrapperClassId(isolate));
16814 object1.SetWrapperClassId(isolate, 42); 16810 object1.SetWrapperClassId(isolate, 42);
16815 CHECK_EQ(42, object1.WrapperClassId(isolate)); 16811 CHECK_EQ(42, object1.WrapperClassId(isolate));
16816 16812
16817 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 16813 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
16818 16814
16819 v8::Persistent<v8::Object> object2 = 16815 v8::Persistent<v8::Object> object2 =
16820 v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); 16816 v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
16821 CHECK_EQ(0, object2.WrapperClassId(isolate)); 16817 CHECK_EQ(0, object2.WrapperClassId(isolate));
16822 object2.SetWrapperClassId(isolate, 42); 16818 object2.SetWrapperClassId(isolate, 42);
16823 CHECK_EQ(42, object2.WrapperClassId(isolate)); 16819 CHECK_EQ(42, object2.WrapperClassId(isolate));
16824 16820
16825 Visitor42 visitor(object2); 16821 Visitor42 visitor(object2);
16826 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor); 16822 v8::V8::VisitHandlesForPartialDependence(isolate, &visitor);
16827 CHECK_EQ(1, visitor.counter_); 16823 CHECK_EQ(1, visitor.counter_);
16828 16824
16829 object1.Dispose(isolate); 16825 object1.Dispose(isolate);
16830 object2.Dispose(isolate); 16826 object2.Dispose(isolate);
16831 } 16827 }
16832 16828
16833 16829
16834 TEST(RegExp) { 16830 TEST(RegExp) {
16835 v8::HandleScope scope;
16836 LocalContext context; 16831 LocalContext context;
16832 v8::HandleScope scope(context->GetIsolate());
16837 16833
16838 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); 16834 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
16839 CHECK(re->IsRegExp()); 16835 CHECK(re->IsRegExp());
16840 CHECK(re->GetSource()->Equals(v8_str("foo"))); 16836 CHECK(re->GetSource()->Equals(v8_str("foo")));
16841 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); 16837 CHECK_EQ(v8::RegExp::kNone, re->GetFlags());
16842 16838
16843 re = v8::RegExp::New(v8_str("bar"), 16839 re = v8::RegExp::New(v8_str("bar"),
16844 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | 16840 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
16845 v8::RegExp::kGlobal)); 16841 v8::RegExp::kGlobal));
16846 CHECK(re->IsRegExp()); 16842 CHECK(re->IsRegExp());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
16895 v8::TryCatch try_catch; 16891 v8::TryCatch try_catch;
16896 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 16892 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
16897 CHECK(re.IsEmpty()); 16893 CHECK(re.IsEmpty());
16898 CHECK(try_catch.HasCaught()); 16894 CHECK(try_catch.HasCaught());
16899 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 16895 context->Global()->Set(v8_str("ex"), try_catch.Exception());
16900 ExpectTrue("ex instanceof SyntaxError"); 16896 ExpectTrue("ex instanceof SyntaxError");
16901 } 16897 }
16902 16898
16903 16899
16904 THREADED_TEST(Equals) { 16900 THREADED_TEST(Equals) {
16905 v8::HandleScope handleScope;
16906 LocalContext localContext; 16901 LocalContext localContext;
16902 v8::HandleScope handleScope(localContext->GetIsolate());
16907 16903
16908 v8::Handle<v8::Object> globalProxy = localContext->Global(); 16904 v8::Handle<v8::Object> globalProxy = localContext->Global();
16909 v8::Handle<Value> global = globalProxy->GetPrototype(); 16905 v8::Handle<Value> global = globalProxy->GetPrototype();
16910 16906
16911 CHECK(global->StrictEquals(global)); 16907 CHECK(global->StrictEquals(global));
16912 CHECK(!global->StrictEquals(globalProxy)); 16908 CHECK(!global->StrictEquals(globalProxy));
16913 CHECK(!globalProxy->StrictEquals(global)); 16909 CHECK(!globalProxy->StrictEquals(global));
16914 CHECK(globalProxy->StrictEquals(globalProxy)); 16910 CHECK(globalProxy->StrictEquals(globalProxy));
16915 16911
16916 CHECK(global->Equals(global)); 16912 CHECK(global->Equals(global));
(...skipping 10 matching lines...) Expand all
16927 16923
16928 16924
16929 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { 16925 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) {
16930 v8::Handle<v8::Array> result = v8::Array::New(); 16926 v8::Handle<v8::Array> result = v8::Array::New();
16931 result->Set(0, v8_str("universalAnswer")); 16927 result->Set(0, v8_str("universalAnswer"));
16932 return result; 16928 return result;
16933 } 16929 }
16934 16930
16935 16931
16936 TEST(NamedEnumeratorAndForIn) { 16932 TEST(NamedEnumeratorAndForIn) {
16937 v8::HandleScope handle_scope;
16938 LocalContext context; 16933 LocalContext context;
16934 v8::HandleScope handle_scope(context->GetIsolate());
16939 v8::Context::Scope context_scope(context.local()); 16935 v8::Context::Scope context_scope(context.local());
16940 16936
16941 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 16937 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
16942 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 16938 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
16943 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 16939 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
16944 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 16940 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
16945 "var result = []; for (var k in o) result.push(k); result")); 16941 "var result = []; for (var k in o) result.push(k); result"));
16946 CHECK_EQ(1, result->Length()); 16942 CHECK_EQ(1, result->Length());
16947 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 16943 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
16948 } 16944 }
16949 16945
16950 16946
16951 TEST(DefinePropertyPostDetach) { 16947 TEST(DefinePropertyPostDetach) {
16952 v8::HandleScope scope;
16953 LocalContext context; 16948 LocalContext context;
16949 v8::HandleScope scope(context->GetIsolate());
16954 v8::Handle<v8::Object> proxy = context->Global(); 16950 v8::Handle<v8::Object> proxy = context->Global();
16955 v8::Handle<v8::Function> define_property = 16951 v8::Handle<v8::Function> define_property =
16956 CompileRun("(function() {" 16952 CompileRun("(function() {"
16957 " Object.defineProperty(" 16953 " Object.defineProperty("
16958 " this," 16954 " this,"
16959 " 1," 16955 " 1,"
16960 " { configurable: true, enumerable: true, value: 3 });" 16956 " { configurable: true, enumerable: true, value: 3 });"
16961 "})").As<Function>(); 16957 "})").As<Function>();
16962 context->DetachGlobal(); 16958 context->DetachGlobal();
16963 define_property->Call(proxy, 0, NULL); 16959 define_property->Call(proxy, 0, NULL);
16964 } 16960 }
16965 16961
16966 16962
16967 static void InstallContextId(v8::Handle<Context> context, int id) { 16963 static void InstallContextId(v8::Handle<Context> context, int id) {
16968 Context::Scope scope(context); 16964 Context::Scope scope(context);
16969 CompileRun("Object.prototype").As<Object>()-> 16965 CompileRun("Object.prototype").As<Object>()->
16970 Set(v8_str("context_id"), v8::Integer::New(id)); 16966 Set(v8_str("context_id"), v8::Integer::New(id));
16971 } 16967 }
16972 16968
16973 16969
16974 static void CheckContextId(v8::Handle<Object> object, int expected) { 16970 static void CheckContextId(v8::Handle<Object> object, int expected) {
16975 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 16971 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
16976 } 16972 }
16977 16973
16978 16974
16979 THREADED_TEST(CreationContext) { 16975 THREADED_TEST(CreationContext) {
16980 HandleScope handle_scope; 16976 HandleScope handle_scope(v8::Isolate::GetCurrent());
16981 Persistent<Context> context1 = Context::New(); 16977 Persistent<Context> context1 = Context::New();
16982 InstallContextId(context1, 1); 16978 InstallContextId(context1, 1);
16983 Persistent<Context> context2 = Context::New(); 16979 Persistent<Context> context2 = Context::New();
16984 InstallContextId(context2, 2); 16980 InstallContextId(context2, 2);
16985 Persistent<Context> context3 = Context::New(); 16981 Persistent<Context> context3 = Context::New();
16986 InstallContextId(context3, 3); 16982 InstallContextId(context3, 3);
16987 16983
16988 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); 16984 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New();
16989 16985
16990 Local<Object> object1; 16986 Local<Object> object1;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
17057 CheckContextId(instance2, 2); 17053 CheckContextId(instance2, 2);
17058 } 17054 }
17059 17055
17060 context1.Dispose(context1->GetIsolate()); 17056 context1.Dispose(context1->GetIsolate());
17061 context2.Dispose(context2->GetIsolate()); 17057 context2.Dispose(context2->GetIsolate());
17062 context3.Dispose(context3->GetIsolate()); 17058 context3.Dispose(context3->GetIsolate());
17063 } 17059 }
17064 17060
17065 17061
17066 THREADED_TEST(CreationContextOfJsFunction) { 17062 THREADED_TEST(CreationContextOfJsFunction) {
17067 HandleScope handle_scope; 17063 HandleScope handle_scope(v8::Isolate::GetCurrent());
17068 Persistent<Context> context = Context::New(); 17064 Persistent<Context> context = Context::New();
17069 InstallContextId(context, 1); 17065 InstallContextId(context, 1);
17070 17066
17071 Local<Object> function; 17067 Local<Object> function;
17072 { 17068 {
17073 Context::Scope scope(context); 17069 Context::Scope scope(context);
17074 function = CompileRun("function foo() {}; foo").As<Object>(); 17070 function = CompileRun("function foo() {}; foo").As<Object>();
17075 } 17071 }
17076 17072
17077 CHECK(function->CreationContext() == context); 17073 CHECK(function->CreationContext() == context);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
17116 } 17112 }
17117 17113
17118 17114
17119 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property, 17115 Handle<Value> HasOwnPropertyAccessorGetter(Local<String> property,
17120 const AccessorInfo& info) { 17116 const AccessorInfo& info) {
17121 return v8_str("yes"); 17117 return v8_str("yes");
17122 } 17118 }
17123 17119
17124 17120
17125 TEST(HasOwnProperty) { 17121 TEST(HasOwnProperty) {
17126 v8::HandleScope scope;
17127 LocalContext env; 17122 LocalContext env;
17123 v8::HandleScope scope(env->GetIsolate());
17128 { // Check normal properties and defined getters. 17124 { // Check normal properties and defined getters.
17129 Handle<Value> value = CompileRun( 17125 Handle<Value> value = CompileRun(
17130 "function Foo() {" 17126 "function Foo() {"
17131 " this.foo = 11;" 17127 " this.foo = 11;"
17132 " this.__defineGetter__('baz', function() { return 1; });" 17128 " this.__defineGetter__('baz', function() { return 1; });"
17133 "};" 17129 "};"
17134 "function Bar() { " 17130 "function Bar() { "
17135 " this.bar = 13;" 17131 " this.bar = 13;"
17136 " this.__defineGetter__('bla', function() { return 2; });" 17132 " this.__defineGetter__('bla', function() { return 2; });"
17137 "};" 17133 "};"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
17189 0, 17185 0,
17190 HasOwnPropertyNamedPropertyQuery2); 17186 HasOwnPropertyNamedPropertyQuery2);
17191 Handle<Object> instance = templ->NewInstance(); 17187 Handle<Object> instance = templ->NewInstance();
17192 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 17188 CHECK(!instance->HasOwnProperty(v8_str("foo")));
17193 CHECK(instance->HasOwnProperty(v8_str("bar"))); 17189 CHECK(instance->HasOwnProperty(v8_str("bar")));
17194 } 17190 }
17195 } 17191 }
17196 17192
17197 17193
17198 TEST(IndexedInterceptorWithStringProto) { 17194 TEST(IndexedInterceptorWithStringProto) {
17199 v8::HandleScope scope; 17195 v8::HandleScope scope(v8::Isolate::GetCurrent());
17200 Handle<ObjectTemplate> templ = ObjectTemplate::New(); 17196 Handle<ObjectTemplate> templ = ObjectTemplate::New();
17201 templ->SetIndexedPropertyHandler(NULL, 17197 templ->SetIndexedPropertyHandler(NULL,
17202 NULL, 17198 NULL,
17203 HasOwnPropertyIndexedPropertyQuery); 17199 HasOwnPropertyIndexedPropertyQuery);
17204 LocalContext context; 17200 LocalContext context;
17205 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 17201 context->Global()->Set(v8_str("obj"), templ->NewInstance());
17206 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); 17202 CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
17207 // These should be intercepted. 17203 // These should be intercepted.
17208 CHECK(CompileRun("42 in obj")->BooleanValue()); 17204 CHECK(CompileRun("42 in obj")->BooleanValue());
17209 CHECK(CompileRun("'42' in obj")->BooleanValue()); 17205 CHECK(CompileRun("'42' in obj")->BooleanValue());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
17251 } 17247 }
17252 17248
17253 17249
17254 bool CodeGenerationDisallowed(Local<Context> context) { 17250 bool CodeGenerationDisallowed(Local<Context> context) {
17255 ApiTestFuzzer::Fuzz(); 17251 ApiTestFuzzer::Fuzz();
17256 return false; 17252 return false;
17257 } 17253 }
17258 17254
17259 17255
17260 THREADED_TEST(AllowCodeGenFromStrings) { 17256 THREADED_TEST(AllowCodeGenFromStrings) {
17261 v8::HandleScope scope;
17262 LocalContext context; 17257 LocalContext context;
17258 v8::HandleScope scope(context->GetIsolate());
17263 17259
17264 // eval and the Function constructor allowed by default. 17260 // eval and the Function constructor allowed by default.
17265 CHECK(context->IsCodeGenerationFromStringsAllowed()); 17261 CHECK(context->IsCodeGenerationFromStringsAllowed());
17266 CheckCodeGenerationAllowed(); 17262 CheckCodeGenerationAllowed();
17267 17263
17268 // Disallow eval and the Function constructor. 17264 // Disallow eval and the Function constructor.
17269 context->AllowCodeGenerationFromStrings(false); 17265 context->AllowCodeGenerationFromStrings(false);
17270 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17266 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17271 CheckCodeGenerationDisallowed(); 17267 CheckCodeGenerationDisallowed();
17272 17268
17273 // Allow again. 17269 // Allow again.
17274 context->AllowCodeGenerationFromStrings(true); 17270 context->AllowCodeGenerationFromStrings(true);
17275 CheckCodeGenerationAllowed(); 17271 CheckCodeGenerationAllowed();
17276 17272
17277 // Disallow but setting a global callback that will allow the calls. 17273 // Disallow but setting a global callback that will allow the calls.
17278 context->AllowCodeGenerationFromStrings(false); 17274 context->AllowCodeGenerationFromStrings(false);
17279 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); 17275 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed);
17280 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17276 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17281 CheckCodeGenerationAllowed(); 17277 CheckCodeGenerationAllowed();
17282 17278
17283 // Set a callback that disallows the code generation. 17279 // Set a callback that disallows the code generation.
17284 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 17280 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
17285 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 17281 CHECK(!context->IsCodeGenerationFromStringsAllowed());
17286 CheckCodeGenerationDisallowed(); 17282 CheckCodeGenerationDisallowed();
17287 } 17283 }
17288 17284
17289 17285
17290 TEST(SetErrorMessageForCodeGenFromStrings) { 17286 TEST(SetErrorMessageForCodeGenFromStrings) {
17291 v8::HandleScope scope;
17292 LocalContext context; 17287 LocalContext context;
17288 v8::HandleScope scope(context->GetIsolate());
17293 TryCatch try_catch; 17289 TryCatch try_catch;
17294 17290
17295 Handle<String> message = v8_str("Message") ; 17291 Handle<String> message = v8_str("Message") ;
17296 Handle<String> expected_message = v8_str("Uncaught EvalError: Message"); 17292 Handle<String> expected_message = v8_str("Uncaught EvalError: Message");
17297 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 17293 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
17298 context->AllowCodeGenerationFromStrings(false); 17294 context->AllowCodeGenerationFromStrings(false);
17299 context->SetErrorMessageForCodeGenerationFromStrings(message); 17295 context->SetErrorMessageForCodeGenerationFromStrings(message);
17300 Handle<Value> result = CompileRun("eval('42')"); 17296 Handle<Value> result = CompileRun("eval('42')");
17301 CHECK(result.IsEmpty()); 17297 CHECK(result.IsEmpty());
17302 CHECK(try_catch.HasCaught()); 17298 CHECK(try_catch.HasCaught());
17303 Handle<String> actual_message = try_catch.Message()->Get(); 17299 Handle<String> actual_message = try_catch.Message()->Get();
17304 CHECK(expected_message->Equals(actual_message)); 17300 CHECK(expected_message->Equals(actual_message));
17305 } 17301 }
17306 17302
17307 17303
17308 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) { 17304 static v8::Handle<Value> NonObjectThis(const v8::Arguments& args) {
17309 return v8::Undefined(); 17305 return v8::Undefined();
17310 } 17306 }
17311 17307
17312 17308
17313 THREADED_TEST(CallAPIFunctionOnNonObject) { 17309 THREADED_TEST(CallAPIFunctionOnNonObject) {
17314 v8::HandleScope scope;
17315 LocalContext context; 17310 LocalContext context;
17311 v8::HandleScope scope(context->GetIsolate());
17316 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 17312 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis);
17317 Handle<Function> function = templ->GetFunction(); 17313 Handle<Function> function = templ->GetFunction();
17318 context->Global()->Set(v8_str("f"), function); 17314 context->Global()->Set(v8_str("f"), function);
17319 TryCatch try_catch; 17315 TryCatch try_catch;
17320 CompileRun("f.call(2)"); 17316 CompileRun("f.call(2)");
17321 } 17317 }
17322 17318
17323 17319
17324 // Regression test for issue 1470. 17320 // Regression test for issue 1470.
17325 THREADED_TEST(ReadOnlyIndexedProperties) { 17321 THREADED_TEST(ReadOnlyIndexedProperties) {
17326 v8::HandleScope scope; 17322 v8::HandleScope scope(v8::Isolate::GetCurrent());
17327 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17323 Local<ObjectTemplate> templ = ObjectTemplate::New();
17328 17324
17329 LocalContext context; 17325 LocalContext context;
17330 Local<v8::Object> obj = templ->NewInstance(); 17326 Local<v8::Object> obj = templ->NewInstance();
17331 context->Global()->Set(v8_str("obj"), obj); 17327 context->Global()->Set(v8_str("obj"), obj);
17332 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 17328 obj->Set(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
17333 obj->Set(v8_str("1"), v8_str("foobar")); 17329 obj->Set(v8_str("1"), v8_str("foobar"));
17334 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1"))); 17330 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("1")));
17335 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 17331 obj->Set(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
17336 obj->Set(v8_num(2), v8_str("foobar")); 17332 obj->Set(v8_num(2), v8_str("foobar"));
17337 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2))); 17333 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_num(2)));
17338 17334
17339 // Test non-smi case. 17335 // Test non-smi case.
17340 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 17336 obj->Set(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
17341 obj->Set(v8_str("2000000000"), v8_str("foobar")); 17337 obj->Set(v8_str("2000000000"), v8_str("foobar"));
17342 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000"))); 17338 CHECK_EQ(v8_str("DONT_CHANGE"), obj->Get(v8_str("2000000000")));
17343 } 17339 }
17344 17340
17345 17341
17346 THREADED_TEST(Regress1516) { 17342 THREADED_TEST(Regress1516) {
17347 v8::HandleScope scope; 17343 LocalContext context;
17344 v8::HandleScope scope(context->GetIsolate());
17348 17345
17349 LocalContext context; 17346 { v8::HandleScope temp_scope(context->GetIsolate());
17350 { v8::HandleScope temp_scope;
17351 CompileRun("({'a': 0})"); 17347 CompileRun("({'a': 0})");
17352 } 17348 }
17353 17349
17354 int elements; 17350 int elements;
17355 { i::MapCache* map_cache = 17351 { i::MapCache* map_cache =
17356 i::MapCache::cast(i::Isolate::Current()->context()->map_cache()); 17352 i::MapCache::cast(i::Isolate::Current()->context()->map_cache());
17357 elements = map_cache->NumberOfElements(); 17353 elements = map_cache->NumberOfElements();
17358 CHECK_LE(1, elements); 17354 CHECK_LE(1, elements);
17359 } 17355 }
17360 17356
(...skipping 20 matching lines...) Expand all
17381 char buffer[10]; 17377 char buffer[10];
17382 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer)); 17378 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
17383 return strncmp(buffer, "__proto__", 9) != 0; 17379 return strncmp(buffer, "__proto__", 9) != 0;
17384 } 17380 }
17385 17381
17386 return true; 17382 return true;
17387 } 17383 }
17388 17384
17389 17385
17390 THREADED_TEST(Regress93759) { 17386 THREADED_TEST(Regress93759) {
17391 HandleScope scope; 17387 HandleScope scope(v8::Isolate::GetCurrent());
17392 17388
17393 // Template for object with security check. 17389 // Template for object with security check.
17394 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 17390 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
17395 // We don't do indexing, so any callback can be used for that. 17391 // We don't do indexing, so any callback can be used for that.
17396 no_proto_template->SetAccessCheckCallbacks( 17392 no_proto_template->SetAccessCheckCallbacks(
17397 BlockProtoNamedSecurityTestCallback, 17393 BlockProtoNamedSecurityTestCallback,
17398 IndexedSecurityTestCallback); 17394 IndexedSecurityTestCallback);
17399 17395
17400 // Templates for objects with hidden prototypes and possibly security check. 17396 // Templates for objects with hidden prototypes and possibly security check.
17401 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); 17397 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
17472 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 17468 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
17473 17469
17474 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 17470 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
17475 CHECK(result6->Equals(Undefined())); 17471 CHECK(result6->Equals(Undefined()));
17476 17472
17477 context.Dispose(context->GetIsolate()); 17473 context.Dispose(context->GetIsolate());
17478 } 17474 }
17479 17475
17480 17476
17481 THREADED_TEST(Regress125988) { 17477 THREADED_TEST(Regress125988) {
17482 v8::HandleScope scope; 17478 v8::HandleScope scope(v8::Isolate::GetCurrent());
17483 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 17479 Handle<FunctionTemplate> intercept = FunctionTemplate::New();
17484 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 17480 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
17485 LocalContext env; 17481 LocalContext env;
17486 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 17482 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
17487 CompileRun("var a = new Object();" 17483 CompileRun("var a = new Object();"
17488 "var b = new Intercept();" 17484 "var b = new Intercept();"
17489 "var c = new Object();" 17485 "var c = new Object();"
17490 "c.__proto__ = b;" 17486 "c.__proto__ = b;"
17491 "b.__proto__ = a;" 17487 "b.__proto__ = a;"
17492 "a.x = 23;" 17488 "a.x = 23;"
(...skipping 13 matching lines...) Expand all
17506 Local<Value> expected_receiver, 17502 Local<Value> expected_receiver,
17507 const char* code) { 17503 const char* code) {
17508 Local<Value> result = CompileRun(code); 17504 Local<Value> result = CompileRun(code);
17509 CHECK(result->IsObject()); 17505 CHECK(result->IsObject());
17510 CHECK(expected_receiver->Equals(result->ToObject()->Get(1))); 17506 CHECK(expected_receiver->Equals(result->ToObject()->Get(1)));
17511 CHECK(expected_result->Equals(result->ToObject()->Get(0))); 17507 CHECK(expected_result->Equals(result->ToObject()->Get(0)));
17512 } 17508 }
17513 17509
17514 17510
17515 THREADED_TEST(ForeignFunctionReceiver) { 17511 THREADED_TEST(ForeignFunctionReceiver) {
17516 HandleScope scope; 17512 HandleScope scope(v8::Isolate::GetCurrent());
17517 17513
17518 // Create two contexts with different "id" properties ('i' and 'o'). 17514 // Create two contexts with different "id" properties ('i' and 'o').
17519 // Call a function both from its own context and from a the foreign 17515 // Call a function both from its own context and from a the foreign
17520 // context, and see what "this" is bound to (returning both "this" 17516 // context, and see what "this" is bound to (returning both "this"
17521 // and "this.id" for comparison). 17517 // and "this.id" for comparison).
17522 17518
17523 Persistent<Context> foreign_context = v8::Context::New(); 17519 Persistent<Context> foreign_context = v8::Context::New();
17524 foreign_context->Enter(); 17520 foreign_context->Enter();
17525 Local<Value> foreign_function = 17521 Local<Value> foreign_function =
17526 CompileRun("function func() { return { 0: this.id, " 17522 CompileRun("function func() { return { 0: this.id, "
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
17634 CHECK_EQ(0, callback_fired); 17630 CHECK_EQ(0, callback_fired);
17635 } else { 17631 } else {
17636 i::OS::Print("Recursion ends.\n"); 17632 i::OS::Print("Recursion ends.\n");
17637 CHECK_EQ(0, callback_fired); 17633 CHECK_EQ(0, callback_fired);
17638 } 17634 }
17639 return Undefined(); 17635 return Undefined();
17640 } 17636 }
17641 17637
17642 17638
17643 TEST(CallCompletedCallback) { 17639 TEST(CallCompletedCallback) {
17644 v8::HandleScope scope;
17645 LocalContext env; 17640 LocalContext env;
17641 v8::HandleScope scope(env->GetIsolate());
17646 v8::Handle<v8::FunctionTemplate> recursive_runtime = 17642 v8::Handle<v8::FunctionTemplate> recursive_runtime =
17647 v8::FunctionTemplate::New(RecursiveCall); 17643 v8::FunctionTemplate::New(RecursiveCall);
17648 env->Global()->Set(v8_str("recursion"), 17644 env->Global()->Set(v8_str("recursion"),
17649 recursive_runtime->GetFunction()); 17645 recursive_runtime->GetFunction());
17650 // Adding the same callback a second time has no effect. 17646 // Adding the same callback a second time has no effect.
17651 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 17647 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
17652 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 17648 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
17653 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); 17649 v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
17654 i::OS::Print("--- Script (1) ---\n"); 17650 i::OS::Print("--- Script (1) ---\n");
17655 Local<Script> script = 17651 Local<Script> script =
(...skipping 11 matching lines...) Expand all
17667 callback_fired = 0; 17663 callback_fired = 0;
17668 Local<Function> recursive_function = 17664 Local<Function> recursive_function =
17669 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 17665 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
17670 v8::Handle<Value> args[] = { v8_num(0) }; 17666 v8::Handle<Value> args[] = { v8_num(0) };
17671 recursive_function->Call(env->Global(), 1, args); 17667 recursive_function->Call(env->Global(), 1, args);
17672 CHECK_EQ(2, callback_fired); 17668 CHECK_EQ(2, callback_fired);
17673 } 17669 }
17674 17670
17675 17671
17676 void CallCompletedCallbackNoException() { 17672 void CallCompletedCallbackNoException() {
17677 v8::HandleScope scope; 17673 v8::HandleScope scope(v8::Isolate::GetCurrent());
17678 CompileRun("1+1;"); 17674 CompileRun("1+1;");
17679 } 17675 }
17680 17676
17681 17677
17682 void CallCompletedCallbackException() { 17678 void CallCompletedCallbackException() {
17683 v8::HandleScope scope; 17679 v8::HandleScope scope(v8::Isolate::GetCurrent());
17684 CompileRun("throw 'second exception';"); 17680 CompileRun("throw 'second exception';");
17685 } 17681 }
17686 17682
17687 17683
17688 TEST(CallCompletedCallbackOneException) { 17684 TEST(CallCompletedCallbackOneException) {
17689 v8::HandleScope scope;
17690 LocalContext env; 17685 LocalContext env;
17686 v8::HandleScope scope(env->GetIsolate());
17691 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException); 17687 v8::V8::AddCallCompletedCallback(CallCompletedCallbackNoException);
17692 CompileRun("throw 'exception';"); 17688 CompileRun("throw 'exception';");
17693 } 17689 }
17694 17690
17695 17691
17696 TEST(CallCompletedCallbackTwoExceptions) { 17692 TEST(CallCompletedCallbackTwoExceptions) {
17697 v8::HandleScope scope;
17698 LocalContext env; 17693 LocalContext env;
17694 v8::HandleScope scope(env->GetIsolate());
17699 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException); 17695 v8::V8::AddCallCompletedCallback(CallCompletedCallbackException);
17700 CompileRun("throw 'first exception';"); 17696 CompileRun("throw 'first exception';");
17701 } 17697 }
17702 17698
17703 17699
17704 static int probes_counter = 0; 17700 static int probes_counter = 0;
17705 static int misses_counter = 0; 17701 static int misses_counter = 0;
17706 static int updates_counter = 0; 17702 static int updates_counter = 0;
17707 17703
17708 17704
(...skipping 27 matching lines...) Expand all
17736 V8::SetCounterFunction(LookupCounter); 17732 V8::SetCounterFunction(LookupCounter);
17737 USE(kMegamorphicTestProgram); 17733 USE(kMegamorphicTestProgram);
17738 #ifdef DEBUG 17734 #ifdef DEBUG
17739 i::FLAG_native_code_counters = true; 17735 i::FLAG_native_code_counters = true;
17740 if (primary) { 17736 if (primary) {
17741 i::FLAG_test_primary_stub_cache = true; 17737 i::FLAG_test_primary_stub_cache = true;
17742 } else { 17738 } else {
17743 i::FLAG_test_secondary_stub_cache = true; 17739 i::FLAG_test_secondary_stub_cache = true;
17744 } 17740 }
17745 i::FLAG_crankshaft = false; 17741 i::FLAG_crankshaft = false;
17746 v8::HandleScope scope;
17747 LocalContext env; 17742 LocalContext env;
17743 v8::HandleScope scope(env->GetIsolate());
17748 int initial_probes = probes_counter; 17744 int initial_probes = probes_counter;
17749 int initial_misses = misses_counter; 17745 int initial_misses = misses_counter;
17750 int initial_updates = updates_counter; 17746 int initial_updates = updates_counter;
17751 CompileRun(kMegamorphicTestProgram); 17747 CompileRun(kMegamorphicTestProgram);
17752 int probes = probes_counter - initial_probes; 17748 int probes = probes_counter - initial_probes;
17753 int misses = misses_counter - initial_misses; 17749 int misses = misses_counter - initial_misses;
17754 int updates = updates_counter - initial_updates; 17750 int updates = updates_counter - initial_updates;
17755 CHECK_LT(updates, 10); 17751 CHECK_LT(updates, 10);
17756 CHECK_LT(misses, 10); 17752 CHECK_LT(misses, 10);
17757 CHECK_GE(probes, 10000); 17753 CHECK_GE(probes, 10000);
(...skipping 12 matching lines...) Expand all
17770 17766
17771 17767
17772 static int fatal_error_callback_counter = 0; 17768 static int fatal_error_callback_counter = 0;
17773 static void CountingErrorCallback(const char* location, const char* message) { 17769 static void CountingErrorCallback(const char* location, const char* message) {
17774 printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message); 17770 printf("CountingErrorCallback(\"%s\", \"%s\")\n", location, message);
17775 fatal_error_callback_counter++; 17771 fatal_error_callback_counter++;
17776 } 17772 }
17777 17773
17778 17774
17779 TEST(StaticGetters) { 17775 TEST(StaticGetters) {
17780 v8::HandleScope scope;
17781 LocalContext context; 17776 LocalContext context;
17782 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17777 v8::Isolate* isolate = v8::Isolate::GetCurrent();
17778 v8::HandleScope scope(isolate);
17783 i::Handle<i::Object> undefined_value = FACTORY->undefined_value(); 17779 i::Handle<i::Object> undefined_value = FACTORY->undefined_value();
17784 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value); 17780 CHECK(*v8::Utils::OpenHandle(*v8::Undefined()) == *undefined_value);
17785 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value); 17781 CHECK(*v8::Utils::OpenHandle(*v8::Undefined(isolate)) == *undefined_value);
17786 i::Handle<i::Object> null_value = FACTORY->null_value(); 17782 i::Handle<i::Object> null_value = FACTORY->null_value();
17787 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value); 17783 CHECK(*v8::Utils::OpenHandle(*v8::Null()) == *null_value);
17788 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value); 17784 CHECK(*v8::Utils::OpenHandle(*v8::Null(isolate)) == *null_value);
17789 i::Handle<i::Object> true_value = FACTORY->true_value(); 17785 i::Handle<i::Object> true_value = FACTORY->true_value();
17790 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value); 17786 CHECK(*v8::Utils::OpenHandle(*v8::True()) == *true_value);
17791 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value); 17787 CHECK(*v8::Utils::OpenHandle(*v8::True(isolate)) == *true_value);
17792 i::Handle<i::Object> false_value = FACTORY->false_value(); 17788 i::Handle<i::Object> false_value = FACTORY->false_value();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
17832 ISOLATE->SetData(data2); 17828 ISOLATE->SetData(data2);
17833 CHECK_EQ(data2, isolate->GetData()); 17829 CHECK_EQ(data2, isolate->GetData());
17834 CHECK_EQ(data2, ISOLATE->GetData()); 17830 CHECK_EQ(data2, ISOLATE->GetData());
17835 ISOLATE->TearDown(); 17831 ISOLATE->TearDown();
17836 CHECK_EQ(data2, isolate->GetData()); 17832 CHECK_EQ(data2, isolate->GetData());
17837 CHECK_EQ(data2, ISOLATE->GetData()); 17833 CHECK_EQ(data2, ISOLATE->GetData());
17838 } 17834 }
17839 17835
17840 17836
17841 TEST(StringEmpty) { 17837 TEST(StringEmpty) {
17842 v8::HandleScope scope;
17843 LocalContext context; 17838 LocalContext context;
17844 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 17839 v8::Isolate* isolate = v8::Isolate::GetCurrent();
17840 v8::HandleScope scope(isolate);
17845 i::Handle<i::Object> empty_string = FACTORY->empty_string(); 17841 i::Handle<i::Object> empty_string = FACTORY->empty_string();
17846 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string); 17842 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty()) == *empty_string);
17847 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string); 17843 CHECK(*v8::Utils::OpenHandle(*v8::String::Empty(isolate)) == *empty_string);
17848 17844
17849 // Test after-death behavior. 17845 // Test after-death behavior.
17850 CHECK(i::Internals::IsInitialized(isolate)); 17846 CHECK(i::Internals::IsInitialized(isolate));
17851 CHECK_EQ(0, fatal_error_callback_counter); 17847 CHECK_EQ(0, fatal_error_callback_counter);
17852 v8::V8::SetFatalErrorHandler(CountingErrorCallback); 17848 v8::V8::SetFatalErrorHandler(CountingErrorCallback);
17853 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8"); 17849 v8::Utils::ReportApiFailure("StringEmpty()", "Kill V8");
17854 i::Isolate::Current()->TearDown(); 17850 i::Isolate::Current()->TearDown();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
17935 // Cleanup so that closures start out fresh in next check. 17931 // Cleanup so that closures start out fresh in next check.
17936 CompileRun("%DeoptimizeFunction(test_get);" 17932 CompileRun("%DeoptimizeFunction(test_get);"
17937 "%ClearFunctionTypeFeedback(test_get);" 17933 "%ClearFunctionTypeFeedback(test_get);"
17938 "%DeoptimizeFunction(test_set);" 17934 "%DeoptimizeFunction(test_set);"
17939 "%ClearFunctionTypeFeedback(test_set);"); 17935 "%ClearFunctionTypeFeedback(test_set);");
17940 } 17936 }
17941 17937
17942 17938
17943 THREADED_TEST(InstanceCheckOnInstanceAccessor) { 17939 THREADED_TEST(InstanceCheckOnInstanceAccessor) {
17944 v8::internal::FLAG_allow_natives_syntax = true; 17940 v8::internal::FLAG_allow_natives_syntax = true;
17945 v8::HandleScope scope;
17946 LocalContext context; 17941 LocalContext context;
17942 v8::HandleScope scope(context->GetIsolate());
17947 17943
17948 Local<FunctionTemplate> templ = FunctionTemplate::New(); 17944 Local<FunctionTemplate> templ = FunctionTemplate::New();
17949 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 17945 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17950 inst->SetAccessor(v8_str("foo"), 17946 inst->SetAccessor(v8_str("foo"),
17951 InstanceCheckedGetter, InstanceCheckedSetter, 17947 InstanceCheckedGetter, InstanceCheckedSetter,
17952 Handle<Value>(), 17948 Handle<Value>(),
17953 v8::DEFAULT, 17949 v8::DEFAULT,
17954 v8::None, 17950 v8::None,
17955 v8::AccessorSignature::New(templ)); 17951 v8::AccessorSignature::New(templ));
17956 context->Global()->Set(v8_str("f"), templ->GetFunction()); 17952 context->Global()->Set(v8_str("f"), templ->GetFunction());
17957 17953
17958 printf("Testing positive ...\n"); 17954 printf("Testing positive ...\n");
17959 CompileRun("var obj = new f();"); 17955 CompileRun("var obj = new f();");
17960 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17956 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17961 CheckInstanceCheckedAccessors(true); 17957 CheckInstanceCheckedAccessors(true);
17962 17958
17963 printf("Testing negative ...\n"); 17959 printf("Testing negative ...\n");
17964 CompileRun("var obj = {};" 17960 CompileRun("var obj = {};"
17965 "obj.__proto__ = new f();"); 17961 "obj.__proto__ = new f();");
17966 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17962 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17967 CheckInstanceCheckedAccessors(false); 17963 CheckInstanceCheckedAccessors(false);
17968 } 17964 }
17969 17965
17970 17966
17971 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { 17967 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
17972 v8::internal::FLAG_allow_natives_syntax = true; 17968 v8::internal::FLAG_allow_natives_syntax = true;
17973 v8::HandleScope scope;
17974 LocalContext context; 17969 LocalContext context;
17970 v8::HandleScope scope(context->GetIsolate());
17975 17971
17976 Local<FunctionTemplate> templ = FunctionTemplate::New(); 17972 Local<FunctionTemplate> templ = FunctionTemplate::New();
17977 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 17973 Local<ObjectTemplate> inst = templ->InstanceTemplate();
17978 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 17974 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
17979 inst->SetAccessor(v8_str("foo"), 17975 inst->SetAccessor(v8_str("foo"),
17980 InstanceCheckedGetter, InstanceCheckedSetter, 17976 InstanceCheckedGetter, InstanceCheckedSetter,
17981 Handle<Value>(), 17977 Handle<Value>(),
17982 v8::DEFAULT, 17978 v8::DEFAULT,
17983 v8::None, 17979 v8::None,
17984 v8::AccessorSignature::New(templ)); 17980 v8::AccessorSignature::New(templ));
17985 context->Global()->Set(v8_str("f"), templ->GetFunction()); 17981 context->Global()->Set(v8_str("f"), templ->GetFunction());
17986 17982
17987 printf("Testing positive ...\n"); 17983 printf("Testing positive ...\n");
17988 CompileRun("var obj = new f();"); 17984 CompileRun("var obj = new f();");
17989 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17985 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17990 CheckInstanceCheckedAccessors(true); 17986 CheckInstanceCheckedAccessors(true);
17991 17987
17992 printf("Testing negative ...\n"); 17988 printf("Testing negative ...\n");
17993 CompileRun("var obj = {};" 17989 CompileRun("var obj = {};"
17994 "obj.__proto__ = new f();"); 17990 "obj.__proto__ = new f();");
17995 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 17991 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
17996 CheckInstanceCheckedAccessors(false); 17992 CheckInstanceCheckedAccessors(false);
17997 } 17993 }
17998 17994
17999 17995
18000 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { 17996 THREADED_TEST(InstanceCheckOnPrototypeAccessor) {
18001 v8::internal::FLAG_allow_natives_syntax = true; 17997 v8::internal::FLAG_allow_natives_syntax = true;
18002 v8::HandleScope scope;
18003 LocalContext context; 17998 LocalContext context;
17999 v8::HandleScope scope(context->GetIsolate());
18004 18000
18005 Local<FunctionTemplate> templ = FunctionTemplate::New(); 18001 Local<FunctionTemplate> templ = FunctionTemplate::New();
18006 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); 18002 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
18007 proto->SetAccessor(v8_str("foo"), 18003 proto->SetAccessor(v8_str("foo"),
18008 InstanceCheckedGetter, InstanceCheckedSetter, 18004 InstanceCheckedGetter, InstanceCheckedSetter,
18009 Handle<Value>(), 18005 Handle<Value>(),
18010 v8::DEFAULT, 18006 v8::DEFAULT,
18011 v8::None, 18007 v8::None,
18012 v8::AccessorSignature::New(templ)); 18008 v8::AccessorSignature::New(templ));
18013 context->Global()->Set(v8_str("f"), templ->GetFunction()); 18009 context->Global()->Set(v8_str("f"), templ->GetFunction());
(...skipping 13 matching lines...) Expand all
18027 CompileRun("var obj = new f();" 18023 CompileRun("var obj = new f();"
18028 "var pro = {};" 18024 "var pro = {};"
18029 "pro.__proto__ = obj.__proto__;" 18025 "pro.__proto__ = obj.__proto__;"
18030 "obj.__proto__ = pro;"); 18026 "obj.__proto__ = pro;");
18031 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 18027 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18032 CheckInstanceCheckedAccessors(true); 18028 CheckInstanceCheckedAccessors(true);
18033 } 18029 }
18034 18030
18035 18031
18036 TEST(TryFinallyMessage) { 18032 TEST(TryFinallyMessage) {
18037 v8::HandleScope scope;
18038 LocalContext context; 18033 LocalContext context;
18034 v8::HandleScope scope(context->GetIsolate());
18039 { 18035 {
18040 // Test that the original error message is not lost if there is a 18036 // Test that the original error message is not lost if there is a
18041 // recursive call into Javascript is done in the finally block, e.g. to 18037 // recursive call into Javascript is done in the finally block, e.g. to
18042 // initialize an IC. (crbug.com/129171) 18038 // initialize an IC. (crbug.com/129171)
18043 TryCatch try_catch; 18039 TryCatch try_catch;
18044 const char* trigger_ic = 18040 const char* trigger_ic =
18045 "try { \n" 18041 "try { \n"
18046 " throw new Error('test'); \n" 18042 " throw new Error('test'); \n"
18047 "} finally { \n" 18043 "} finally { \n"
18048 " var x = 0; \n" 18044 " var x = 0; \n"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
18119 } else { 18115 } else {
18120 CHECK_EQ(do_store ? 23 : 42, 18116 CHECK_EQ(do_store ? 23 : 42,
18121 context->Global()->Get(v8_str("result"))->Int32Value()); 18117 context->Global()->Get(v8_str("result"))->Int32Value());
18122 } 18118 }
18123 } 18119 }
18124 18120
18125 18121
18126 THREADED_TEST(Regress137002a) { 18122 THREADED_TEST(Regress137002a) {
18127 i::FLAG_allow_natives_syntax = true; 18123 i::FLAG_allow_natives_syntax = true;
18128 i::FLAG_compilation_cache = false; 18124 i::FLAG_compilation_cache = false;
18129 v8::HandleScope scope; 18125 v8::HandleScope scope(v8::Isolate::GetCurrent());
18130 for (int i = 0; i < 16; i++) { 18126 for (int i = 0; i < 16; i++) {
18131 Helper137002(i & 8, i & 4, i & 2, i & 1); 18127 Helper137002(i & 8, i & 4, i & 2, i & 1);
18132 } 18128 }
18133 } 18129 }
18134 18130
18135 18131
18136 THREADED_TEST(Regress137002b) { 18132 THREADED_TEST(Regress137002b) {
18137 i::FLAG_allow_natives_syntax = true; 18133 i::FLAG_allow_natives_syntax = true;
18138 v8::HandleScope scope;
18139 LocalContext context; 18134 LocalContext context;
18135 v8::HandleScope scope(context->GetIsolate());
18140 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18136 Local<ObjectTemplate> templ = ObjectTemplate::New();
18141 templ->SetAccessor(v8_str("foo"), 18137 templ->SetAccessor(v8_str("foo"),
18142 GetterWhichReturns42, 18138 GetterWhichReturns42,
18143 SetterWhichSetsYOnThisTo23); 18139 SetterWhichSetsYOnThisTo23);
18144 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 18140 context->Global()->Set(v8_str("obj"), templ->NewInstance());
18145 18141
18146 // Turn monomorphic on slow object with native accessor, then just 18142 // Turn monomorphic on slow object with native accessor, then just
18147 // delete the property and fail. 18143 // delete the property and fail.
18148 CompileRun("function load(x) { return x.foo; }" 18144 CompileRun("function load(x) { return x.foo; }"
18149 "function store(x) { x.foo = void 0; }" 18145 "function store(x) { x.foo = void 0; }"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
18196 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined()); 18192 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined());
18197 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); 18193 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined());
18198 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); 18194 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined());
18199 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); 18195 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined());
18200 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); 18196 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined());
18201 } 18197 }
18202 18198
18203 18199
18204 THREADED_TEST(Regress142088) { 18200 THREADED_TEST(Regress142088) {
18205 i::FLAG_allow_natives_syntax = true; 18201 i::FLAG_allow_natives_syntax = true;
18206 v8::HandleScope scope;
18207 LocalContext context; 18202 LocalContext context;
18203 v8::HandleScope scope(context->GetIsolate());
18208 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18204 Local<ObjectTemplate> templ = ObjectTemplate::New();
18209 templ->SetAccessor(v8_str("foo"), 18205 templ->SetAccessor(v8_str("foo"),
18210 GetterWhichReturns42, 18206 GetterWhichReturns42,
18211 SetterWhichSetsYOnThisTo23); 18207 SetterWhichSetsYOnThisTo23);
18212 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 18208 context->Global()->Set(v8_str("obj"), templ->NewInstance());
18213 18209
18214 CompileRun("function load(x) { return x.foo; }" 18210 CompileRun("function load(x) { return x.foo; }"
18215 "var o = Object.create(obj);" 18211 "var o = Object.create(obj);"
18216 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" 18212 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
18217 "load(o); load(o); load(o); load(o);"); 18213 "load(o); load(o); load(o); load(o);");
18218 } 18214 }
18219 18215
18220 18216
18221 THREADED_TEST(Regress137496) { 18217 THREADED_TEST(Regress137496) {
18222 i::FLAG_expose_gc = true; 18218 i::FLAG_expose_gc = true;
18223 v8::HandleScope scope;
18224 LocalContext context; 18219 LocalContext context;
18220 v8::HandleScope scope(context->GetIsolate());
18225 18221
18226 // Compile a try-finally clause where the finally block causes a GC 18222 // Compile a try-finally clause where the finally block causes a GC
18227 // while there still is a message pending for external reporting. 18223 // while there still is a message pending for external reporting.
18228 TryCatch try_catch; 18224 TryCatch try_catch;
18229 try_catch.SetVerbose(true); 18225 try_catch.SetVerbose(true);
18230 CompileRun("try { throw new Error(); } finally { gc(); }"); 18226 CompileRun("try { throw new Error(); } finally { gc(); }");
18231 CHECK(try_catch.HasCaught()); 18227 CHECK(try_catch.HasCaught());
18232 } 18228 }
18233 18229
18234 18230
18235 THREADED_TEST(Regress149912) { 18231 THREADED_TEST(Regress149912) {
18236 v8::HandleScope scope;
18237 LocalContext context; 18232 LocalContext context;
18233 v8::HandleScope scope(context->GetIsolate());
18238 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 18234 Handle<FunctionTemplate> templ = FunctionTemplate::New();
18239 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 18235 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
18240 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); 18236 context->Global()->Set(v8_str("Bug"), templ->GetFunction());
18241 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); 18237 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
18242 } 18238 }
18243 18239
18244 18240
18245 THREADED_TEST(Regress157124) { 18241 THREADED_TEST(Regress157124) {
18246 v8::HandleScope scope;
18247 LocalContext context; 18242 LocalContext context;
18243 v8::HandleScope scope(context->GetIsolate());
18248 Local<ObjectTemplate> templ = ObjectTemplate::New(); 18244 Local<ObjectTemplate> templ = ObjectTemplate::New();
18249 Local<Object> obj = templ->NewInstance(); 18245 Local<Object> obj = templ->NewInstance();
18250 obj->GetIdentityHash(); 18246 obj->GetIdentityHash();
18251 obj->DeleteHiddenValue(v8_str("Bug")); 18247 obj->DeleteHiddenValue(v8_str("Bug"));
18252 } 18248 }
18253 18249
18254 18250
18255 THREADED_TEST(Regress2535) { 18251 THREADED_TEST(Regress2535) {
18256 i::FLAG_harmony_collections = true; 18252 i::FLAG_harmony_collections = true;
18257 v8::HandleScope scope;
18258 LocalContext context; 18253 LocalContext context;
18254 v8::HandleScope scope(context->GetIsolate());
18259 Local<Value> set_value = CompileRun("new Set();"); 18255 Local<Value> set_value = CompileRun("new Set();");
18260 Local<Object> set_object(Object::Cast(*set_value)); 18256 Local<Object> set_object(Object::Cast(*set_value));
18261 CHECK_EQ(0, set_object->InternalFieldCount()); 18257 CHECK_EQ(0, set_object->InternalFieldCount());
18262 Local<Value> map_value = CompileRun("new Map();"); 18258 Local<Value> map_value = CompileRun("new Map();");
18263 Local<Object> map_object(Object::Cast(*map_value)); 18259 Local<Object> map_object(Object::Cast(*map_value));
18264 CHECK_EQ(0, map_object->InternalFieldCount()); 18260 CHECK_EQ(0, map_object->InternalFieldCount());
18265 } 18261 }
18266 18262
18267 18263
18268 #ifndef WIN32 18264 #ifndef WIN32
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
18321 i::Semaphore* sem_; 18317 i::Semaphore* sem_;
18322 volatile int sem_value_; 18318 volatile int sem_value_;
18323 }; 18319 };
18324 18320
18325 18321
18326 THREADED_TEST(SemaphoreInterruption) { 18322 THREADED_TEST(SemaphoreInterruption) {
18327 ThreadInterruptTest().RunTest(); 18323 ThreadInterruptTest().RunTest();
18328 } 18324 }
18329 18325
18330 #endif // WIN32 18326 #endif // WIN32
OLDNEW
« no previous file with comments | « test/cctest/test-alloc.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698