| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 187 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 188 CHECK_EQ(1, info.Length()); | 188 CHECK_EQ(1, info.Length()); |
| 189 XSetter(info[0], info, 1); | 189 XSetter(info[0], info, 1); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 |
| 193 THREADED_TEST(AccessorIC) { | 193 THREADED_TEST(AccessorIC) { |
| 194 LocalContext context; | 194 LocalContext context; |
| 195 v8::Isolate* isolate = context->GetIsolate(); | 195 v8::Isolate* isolate = context->GetIsolate(); |
| 196 v8::HandleScope scope(isolate); | 196 v8::HandleScope scope(isolate); |
| 197 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 197 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 198 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); | 198 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); |
| 199 obj->SetAccessorProperty(v8_str("x1"), | 199 obj->SetAccessorProperty(v8_str("x1"), |
| 200 v8::FunctionTemplate::New(isolate, XGetter), | 200 v8::FunctionTemplate::New(isolate, XGetter), |
| 201 v8::FunctionTemplate::New(isolate, XSetter)); | 201 v8::FunctionTemplate::New(isolate, XSetter)); |
| 202 x_holder = obj->NewInstance(); | 202 x_holder = obj->NewInstance(); |
| 203 context->Global()->Set(v8_str("holder"), x_holder); | 203 context->Global()->Set(v8_str("holder"), x_holder); |
| 204 x_receiver = v8::Object::New(isolate); | 204 x_receiver = v8::Object::New(isolate); |
| 205 context->Global()->Set(v8_str("obj"), x_receiver); | 205 context->Global()->Set(v8_str("obj"), x_receiver); |
| 206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( | 206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( |
| 207 "obj.__proto__ = holder;" | 207 "obj.__proto__ = holder;" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 231 static void AccessorProhibitsOverwritingGetter( | 231 static void AccessorProhibitsOverwritingGetter( |
| 232 Local<String> name, | 232 Local<String> name, |
| 233 const v8::PropertyCallbackInfo<v8::Value>& info) { | 233 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 234 ApiTestFuzzer::Fuzz(); | 234 ApiTestFuzzer::Fuzz(); |
| 235 info.GetReturnValue().Set(true); | 235 info.GetReturnValue().Set(true); |
| 236 } | 236 } |
| 237 | 237 |
| 238 | 238 |
| 239 THREADED_TEST(AccessorProhibitsOverwriting) { | 239 THREADED_TEST(AccessorProhibitsOverwriting) { |
| 240 LocalContext context; | 240 LocalContext context; |
| 241 v8::HandleScope scope(context->GetIsolate()); | 241 v8::Isolate* isolate = context->GetIsolate(); |
| 242 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 242 v8::HandleScope scope(isolate); |
| 243 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
| 243 templ->SetAccessor(v8_str("x"), | 244 templ->SetAccessor(v8_str("x"), |
| 244 AccessorProhibitsOverwritingGetter, | 245 AccessorProhibitsOverwritingGetter, |
| 245 0, | 246 0, |
| 246 v8::Handle<Value>(), | 247 v8::Handle<Value>(), |
| 247 v8::PROHIBITS_OVERWRITING, | 248 v8::PROHIBITS_OVERWRITING, |
| 248 v8::ReadOnly); | 249 v8::ReadOnly); |
| 249 Local<v8::Object> instance = templ->NewInstance(); | 250 Local<v8::Object> instance = templ->NewInstance(); |
| 250 context->Global()->Set(v8_str("obj"), instance); | 251 context->Global()->Set(v8_str("obj"), instance); |
| 251 Local<Value> value = CompileRun( | 252 Local<Value> value = CompileRun( |
| 252 "obj.__defineGetter__('x', function() { return false; });" | 253 "obj.__defineGetter__('x', function() { return false; });" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 281 const v8::PropertyCallbackInfo<v8::Value>& info) { | 282 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 282 ApiTestFuzzer::Fuzz(); | 283 ApiTestFuzzer::Fuzz(); |
| 283 for (int i = 0; i < C; i++) | 284 for (int i = 0; i < C; i++) |
| 284 v8::String::NewFromUtf8(info.GetIsolate(), "foo"); | 285 v8::String::NewFromUtf8(info.GetIsolate(), "foo"); |
| 285 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo")); | 286 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo")); |
| 286 } | 287 } |
| 287 | 288 |
| 288 | 289 |
| 289 THREADED_TEST(HandleScopePop) { | 290 THREADED_TEST(HandleScopePop) { |
| 290 LocalContext context; | 291 LocalContext context; |
| 291 v8::HandleScope scope(context->GetIsolate()); | 292 v8::Isolate* isolate = context->GetIsolate(); |
| 292 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 293 v8::HandleScope scope(isolate); |
| 294 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 293 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); | 295 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); |
| 294 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); | 296 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); |
| 295 v8::Handle<v8::Object> inst = obj->NewInstance(); | 297 v8::Handle<v8::Object> inst = obj->NewInstance(); |
| 296 context->Global()->Set(v8::String::NewFromUtf8(context->GetIsolate(), "obj"), | 298 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); |
| 297 inst); | 299 int count_before = |
| 298 i::Isolate* isolate = CcTest::i_isolate(); | 300 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); |
| 299 int count_before = i::HandleScope::NumberOfHandles(isolate); | |
| 300 { | 301 { |
| 301 v8::HandleScope scope(context->GetIsolate()); | 302 v8::HandleScope scope(isolate); |
| 302 CompileRun( | 303 CompileRun( |
| 303 "for (var i = 0; i < 1000; i++) {" | 304 "for (var i = 0; i < 1000; i++) {" |
| 304 " obj.one;" | 305 " obj.one;" |
| 305 " obj.many;" | 306 " obj.many;" |
| 306 "}"); | 307 "}"); |
| 307 } | 308 } |
| 308 int count_after = i::HandleScope::NumberOfHandles(isolate); | 309 int count_after = |
| 310 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); |
| 309 CHECK_EQ(count_before, count_after); | 311 CHECK_EQ(count_before, count_after); |
| 310 } | 312 } |
| 311 | 313 |
| 312 static void CheckAccessorArgsCorrect( | 314 static void CheckAccessorArgsCorrect( |
| 313 Local<String> name, | 315 Local<String> name, |
| 314 const v8::PropertyCallbackInfo<v8::Value>& info) { | 316 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 315 CHECK(info.GetIsolate() == CcTest::isolate()); | 317 CHECK(info.GetIsolate() == CcTest::isolate()); |
| 316 CHECK(info.This() == info.Holder()); | 318 CHECK(info.This() == info.Holder()); |
| 317 CHECK( | 319 CHECK( |
| 318 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 320 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); |
| 319 ApiTestFuzzer::Fuzz(); | 321 ApiTestFuzzer::Fuzz(); |
| 320 CHECK(info.GetIsolate() == CcTest::isolate()); | 322 CHECK(info.GetIsolate() == CcTest::isolate()); |
| 321 CHECK(info.This() == info.Holder()); | 323 CHECK(info.This() == info.Holder()); |
| 322 CHECK( | 324 CHECK( |
| 323 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 325 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); |
| 324 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | 326 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 325 CHECK(info.GetIsolate() == CcTest::isolate()); | 327 CHECK(info.GetIsolate() == CcTest::isolate()); |
| 326 CHECK(info.This() == info.Holder()); | 328 CHECK(info.This() == info.Holder()); |
| 327 CHECK( | 329 CHECK( |
| 328 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 330 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); |
| 329 info.GetReturnValue().Set(17); | 331 info.GetReturnValue().Set(17); |
| 330 } | 332 } |
| 331 | 333 |
| 332 | 334 |
| 333 THREADED_TEST(DirectCall) { | 335 THREADED_TEST(DirectCall) { |
| 334 LocalContext context; | 336 LocalContext context; |
| 335 v8::HandleScope scope(context->GetIsolate()); | 337 v8::Isolate* isolate = context->GetIsolate(); |
| 336 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 338 v8::HandleScope scope(isolate); |
| 339 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 337 obj->SetAccessor(v8_str("xxx"), | 340 obj->SetAccessor(v8_str("xxx"), |
| 338 CheckAccessorArgsCorrect, | 341 CheckAccessorArgsCorrect, |
| 339 NULL, | 342 NULL, |
| 340 v8::String::NewFromUtf8(context->GetIsolate(), "data")); | 343 v8::String::NewFromUtf8(isolate, "data")); |
| 341 v8::Handle<v8::Object> inst = obj->NewInstance(); | 344 v8::Handle<v8::Object> inst = obj->NewInstance(); |
| 342 context->Global()->Set(v8::String::NewFromUtf8(context->GetIsolate(), "obj"), | 345 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), |
| 343 inst); | 346 inst); |
| 344 Local<Script> scr = v8::Script::Compile( | 347 Local<Script> scr = v8::Script::Compile( |
| 345 v8::String::NewFromUtf8(context->GetIsolate(), "obj.xxx")); | 348 v8::String::NewFromUtf8(isolate, "obj.xxx")); |
| 346 for (int i = 0; i < 10; i++) { | 349 for (int i = 0; i < 10; i++) { |
| 347 Local<Value> result = scr->Run(); | 350 Local<Value> result = scr->Run(); |
| 348 CHECK(!result.IsEmpty()); | 351 CHECK(!result.IsEmpty()); |
| 349 CHECK_EQ(17, result->Int32Value()); | 352 CHECK_EQ(17, result->Int32Value()); |
| 350 } | 353 } |
| 351 } | 354 } |
| 352 | 355 |
| 353 static void EmptyGetter(Local<String> name, | 356 static void EmptyGetter(Local<String> name, |
| 354 const v8::PropertyCallbackInfo<v8::Value>& info) { | 357 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 355 CheckAccessorArgsCorrect(name, info); | 358 CheckAccessorArgsCorrect(name, info); |
| 356 ApiTestFuzzer::Fuzz(); | 359 ApiTestFuzzer::Fuzz(); |
| 357 CheckAccessorArgsCorrect(name, info); | 360 CheckAccessorArgsCorrect(name, info); |
| 358 info.GetReturnValue().Set(v8::Handle<v8::Value>()); | 361 info.GetReturnValue().Set(v8::Handle<v8::Value>()); |
| 359 } | 362 } |
| 360 | 363 |
| 361 | 364 |
| 362 THREADED_TEST(EmptyResult) { | 365 THREADED_TEST(EmptyResult) { |
| 363 LocalContext context; | 366 LocalContext context; |
| 364 v8::Isolate* isolate = context->GetIsolate(); | 367 v8::Isolate* isolate = context->GetIsolate(); |
| 365 v8::HandleScope scope(isolate); | 368 v8::HandleScope scope(isolate); |
| 366 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 369 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 367 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, | 370 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, |
| 368 v8::String::NewFromUtf8(isolate, "data")); | 371 v8::String::NewFromUtf8(isolate, "data")); |
| 369 v8::Handle<v8::Object> inst = obj->NewInstance(); | 372 v8::Handle<v8::Object> inst = obj->NewInstance(); |
| 370 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 373 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); |
| 371 Local<Script> scr = | 374 Local<Script> scr = |
| 372 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 375 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); |
| 373 for (int i = 0; i < 10; i++) { | 376 for (int i = 0; i < 10; i++) { |
| 374 Local<Value> result = scr->Run(); | 377 Local<Value> result = scr->Run(); |
| 375 CHECK(result == v8::Undefined(isolate)); | 378 CHECK(result == v8::Undefined(isolate)); |
| 376 } | 379 } |
| 377 } | 380 } |
| 378 | 381 |
| 379 | 382 |
| 380 THREADED_TEST(NoReuseRegress) { | 383 THREADED_TEST(NoReuseRegress) { |
| 381 // Check that the IC generated for the one test doesn't get reused | 384 // Check that the IC generated for the one test doesn't get reused |
| 382 // for the other. | 385 // for the other. |
| 383 v8::Isolate* isolate = CcTest::isolate(); | 386 v8::Isolate* isolate = CcTest::isolate(); |
| 384 v8::HandleScope scope(isolate); | 387 v8::HandleScope scope(isolate); |
| 385 { | 388 { |
| 386 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 389 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 387 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, | 390 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, |
| 388 v8::String::NewFromUtf8(isolate, "data")); | 391 v8::String::NewFromUtf8(isolate, "data")); |
| 389 LocalContext context; | 392 LocalContext context; |
| 390 v8::Handle<v8::Object> inst = obj->NewInstance(); | 393 v8::Handle<v8::Object> inst = obj->NewInstance(); |
| 391 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 394 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); |
| 392 Local<Script> scr = | 395 Local<Script> scr = |
| 393 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 396 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); |
| 394 for (int i = 0; i < 2; i++) { | 397 for (int i = 0; i < 2; i++) { |
| 395 Local<Value> result = scr->Run(); | 398 Local<Value> result = scr->Run(); |
| 396 CHECK(result == v8::Undefined(isolate)); | 399 CHECK(result == v8::Undefined(isolate)); |
| 397 } | 400 } |
| 398 } | 401 } |
| 399 { | 402 { |
| 400 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 403 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 401 obj->SetAccessor(v8_str("xxx"), | 404 obj->SetAccessor(v8_str("xxx"), |
| 402 CheckAccessorArgsCorrect, | 405 CheckAccessorArgsCorrect, |
| 403 NULL, | 406 NULL, |
| 404 v8::String::NewFromUtf8(isolate, "data")); | 407 v8::String::NewFromUtf8(isolate, "data")); |
| 405 LocalContext context; | 408 LocalContext context; |
| 406 v8::Handle<v8::Object> inst = obj->NewInstance(); | 409 v8::Handle<v8::Object> inst = obj->NewInstance(); |
| 407 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 410 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); |
| 408 Local<Script> scr = | 411 Local<Script> scr = |
| 409 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 412 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); |
| 410 for (int i = 0; i < 10; i++) { | 413 for (int i = 0; i < 10; i++) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 425 | 428 |
| 426 static void ThrowingSetAccessor(Local<String> name, | 429 static void ThrowingSetAccessor(Local<String> name, |
| 427 Local<Value> value, | 430 Local<Value> value, |
| 428 const v8::PropertyCallbackInfo<void>& info) { | 431 const v8::PropertyCallbackInfo<void>& info) { |
| 429 info.GetIsolate()->ThrowException(value); | 432 info.GetIsolate()->ThrowException(value); |
| 430 } | 433 } |
| 431 | 434 |
| 432 | 435 |
| 433 THREADED_TEST(Regress1054726) { | 436 THREADED_TEST(Regress1054726) { |
| 434 LocalContext env; | 437 LocalContext env; |
| 435 v8::HandleScope scope(env->GetIsolate()); | 438 v8::Isolate* isolate = env->GetIsolate(); |
| 436 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 439 v8::HandleScope scope(isolate); |
| 440 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 437 obj->SetAccessor(v8_str("x"), | 441 obj->SetAccessor(v8_str("x"), |
| 438 ThrowingGetAccessor, | 442 ThrowingGetAccessor, |
| 439 ThrowingSetAccessor, | 443 ThrowingSetAccessor, |
| 440 Local<Value>()); | 444 Local<Value>()); |
| 441 | 445 |
| 442 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 446 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 443 | 447 |
| 444 // Use the throwing property setter/getter in a loop to force | 448 // Use the throwing property setter/getter in a loop to force |
| 445 // the accessor ICs to be initialized. | 449 // the accessor ICs to be initialized. |
| 446 v8::Handle<Value> result; | 450 v8::Handle<Value> result; |
| 447 result = Script::Compile(v8_str( | 451 result = Script::Compile(v8_str( |
| 448 "var result = '';" | 452 "var result = '';" |
| 449 "for (var i = 0; i < 5; i++) {" | 453 "for (var i = 0; i < 5; i++) {" |
| 450 " try { obj.x; } catch (e) { result += e; }" | 454 " try { obj.x; } catch (e) { result += e; }" |
| 451 "}; result"))->Run(); | 455 "}; result"))->Run(); |
| 452 CHECK_EQ(v8_str("ggggg"), result); | 456 CHECK_EQ(v8_str("ggggg"), result); |
| 453 | 457 |
| 454 result = Script::Compile(String::NewFromUtf8( | 458 result = Script::Compile(String::NewFromUtf8( |
| 455 env->GetIsolate(), | 459 isolate, |
| 456 "var result = '';" | 460 "var result = '';" |
| 457 "for (var i = 0; i < 5; i++) {" | 461 "for (var i = 0; i < 5; i++) {" |
| 458 " try { obj.x = i; } catch (e) { result += e; }" | 462 " try { obj.x = i; } catch (e) { result += e; }" |
| 459 "}; result"))->Run(); | 463 "}; result"))->Run(); |
| 460 CHECK_EQ(v8_str("01234"), result); | 464 CHECK_EQ(v8_str("01234"), result); |
| 461 } | 465 } |
| 462 | 466 |
| 463 | 467 |
| 464 static void AllocGetter(Local<String> name, | 468 static void AllocGetter(Local<String> name, |
| 465 const v8::PropertyCallbackInfo<v8::Value>& info) { | 469 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 466 ApiTestFuzzer::Fuzz(); | 470 ApiTestFuzzer::Fuzz(); |
| 467 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000)); | 471 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000)); |
| 468 } | 472 } |
| 469 | 473 |
| 470 | 474 |
| 471 THREADED_TEST(Gc) { | 475 THREADED_TEST(Gc) { |
| 472 LocalContext env; | 476 LocalContext env; |
| 473 v8::HandleScope scope(env->GetIsolate()); | 477 v8::Isolate* isolate = env->GetIsolate(); |
| 474 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 478 v8::HandleScope scope(isolate); |
| 479 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 475 obj->SetAccessor(v8_str("xxx"), AllocGetter); | 480 obj->SetAccessor(v8_str("xxx"), AllocGetter); |
| 476 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 481 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 477 Script::Compile(String::NewFromUtf8( | 482 Script::Compile(String::NewFromUtf8( |
| 478 env->GetIsolate(), | 483 isolate, |
| 479 "var last = [];" | 484 "var last = [];" |
| 480 "for (var i = 0; i < 2048; i++) {" | 485 "for (var i = 0; i < 2048; i++) {" |
| 481 " var result = obj.xxx;" | 486 " var result = obj.xxx;" |
| 482 " result[0] = last;" | 487 " result[0] = last;" |
| 483 " last = result;" | 488 " last = result;" |
| 484 "}"))->Run(); | 489 "}"))->Run(); |
| 485 } | 490 } |
| 486 | 491 |
| 487 | 492 |
| 488 static void StackCheck(Local<String> name, | 493 static void StackCheck(Local<String> name, |
| 489 const v8::PropertyCallbackInfo<v8::Value>& info) { | 494 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 490 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); | 495 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); |
| 491 for (int i = 0; !iter.done(); i++) { | 496 for (int i = 0; !iter.done(); i++) { |
| 492 i::StackFrame* frame = iter.frame(); | 497 i::StackFrame* frame = iter.frame(); |
| 493 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); | 498 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); |
| 494 i::Code* code = frame->LookupCode(); | 499 i::Code* code = frame->LookupCode(); |
| 495 CHECK(code->IsCode()); | 500 CHECK(code->IsCode()); |
| 496 i::Address pc = frame->pc(); | 501 i::Address pc = frame->pc(); |
| 497 CHECK(code->contains(pc)); | 502 CHECK(code->contains(pc)); |
| 498 iter.Advance(); | 503 iter.Advance(); |
| 499 } | 504 } |
| 500 } | 505 } |
| 501 | 506 |
| 502 | 507 |
| 503 THREADED_TEST(StackIteration) { | 508 THREADED_TEST(StackIteration) { |
| 504 LocalContext env; | 509 LocalContext env; |
| 505 v8::HandleScope scope(env->GetIsolate()); | 510 v8::Isolate* isolate = env->GetIsolate(); |
| 506 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 511 v8::HandleScope scope(isolate); |
| 507 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); | 512 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 508 i::StringStream::ClearMentionedObjectCache(isolate); | 513 i::StringStream::ClearMentionedObjectCache( |
| 514 reinterpret_cast<i::Isolate*>(isolate)); |
| 509 obj->SetAccessor(v8_str("xxx"), StackCheck); | 515 obj->SetAccessor(v8_str("xxx"), StackCheck); |
| 510 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 516 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 511 Script::Compile(String::NewFromUtf8( | 517 Script::Compile(String::NewFromUtf8( |
| 512 env->GetIsolate(), | 518 isolate, |
| 513 "function foo() {" | 519 "function foo() {" |
| 514 " return obj.xxx;" | 520 " return obj.xxx;" |
| 515 "}" | 521 "}" |
| 516 "for (var i = 0; i < 100; i++) {" | 522 "for (var i = 0; i < 100; i++) {" |
| 517 " foo();" | 523 " foo();" |
| 518 "}"))->Run(); | 524 "}"))->Run(); |
| 519 } | 525 } |
| 520 | 526 |
| 521 | 527 |
| 522 static void AllocateHandles(Local<String> name, | 528 static void AllocateHandles(Local<String> name, |
| 523 const v8::PropertyCallbackInfo<v8::Value>& info) { | 529 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 524 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { | 530 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { |
| 525 v8::Local<v8::Value>::New(info.GetIsolate(), name); | 531 v8::Local<v8::Value>::New(info.GetIsolate(), name); |
| 526 } | 532 } |
| 527 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100)); | 533 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100)); |
| 528 } | 534 } |
| 529 | 535 |
| 530 | 536 |
| 531 THREADED_TEST(HandleScopeSegment) { | 537 THREADED_TEST(HandleScopeSegment) { |
| 532 // Check that we can return values past popping of handle scope | 538 // Check that we can return values past popping of handle scope |
| 533 // segments. | 539 // segments. |
| 534 LocalContext env; | 540 LocalContext env; |
| 535 v8::HandleScope scope(env->GetIsolate()); | 541 v8::Isolate* isolate = env->GetIsolate(); |
| 536 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 542 v8::HandleScope scope(isolate); |
| 543 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 537 obj->SetAccessor(v8_str("xxx"), AllocateHandles); | 544 obj->SetAccessor(v8_str("xxx"), AllocateHandles); |
| 538 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 545 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 539 v8::Handle<v8::Value> result = Script::Compile(String::NewFromUtf8( | 546 v8::Handle<v8::Value> result = Script::Compile(String::NewFromUtf8( |
| 540 env->GetIsolate(), | 547 isolate, |
| 541 "var result;" | 548 "var result;" |
| 542 "for (var i = 0; i < 4; i++)" | 549 "for (var i = 0; i < 4; i++)" |
| 543 " result = obj.xxx;" | 550 " result = obj.xxx;" |
| 544 "result;"))->Run(); | 551 "result;"))->Run(); |
| 545 CHECK_EQ(100, result->Int32Value()); | 552 CHECK_EQ(100, result->Int32Value()); |
| 546 } | 553 } |
| 547 | 554 |
| 548 | 555 |
| 549 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 556 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
| 550 v8::Handle<v8::Array> array = v8::Array::New(info.GetIsolate(), 1); | 557 v8::Handle<v8::Array> array = v8::Array::New(info.GetIsolate(), 1); |
| 551 array->Set(0, v8_str("regress")); | 558 array->Set(0, v8_str("regress")); |
| 552 info.GetReturnValue().Set(array); | 559 info.GetReturnValue().Set(array); |
| 553 } | 560 } |
| 554 | 561 |
| 555 | 562 |
| 556 void JSONStringifyGetter(Local<String> name, | 563 void JSONStringifyGetter(Local<String> name, |
| 557 const v8::PropertyCallbackInfo<v8::Value>& info) { | 564 const v8::PropertyCallbackInfo<v8::Value>& info) { |
| 558 info.GetReturnValue().Set(v8_str("crbug-161028")); | 565 info.GetReturnValue().Set(v8_str("crbug-161028")); |
| 559 } | 566 } |
| 560 | 567 |
| 561 | 568 |
| 562 THREADED_TEST(JSONStringifyNamedInterceptorObject) { | 569 THREADED_TEST(JSONStringifyNamedInterceptorObject) { |
| 563 LocalContext env; | 570 LocalContext env; |
| 564 v8::HandleScope scope(env->GetIsolate()); | 571 v8::Isolate* isolate = env->GetIsolate(); |
| 572 v8::HandleScope scope(isolate); |
| 565 | 573 |
| 566 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 574 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
| 567 obj->SetNamedPropertyHandler( | 575 obj->SetNamedPropertyHandler( |
| 568 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); | 576 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); |
| 569 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 577 env->Global()->Set(v8_str("obj"), obj->NewInstance()); |
| 570 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | 578 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); |
| 571 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); | 579 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); |
| 572 } | 580 } |
| 573 | 581 |
| 574 | 582 |
| 575 THREADED_TEST(AccessorPropertyCrossContext) { | 583 THREADED_TEST(AccessorPropertyCrossContext) { |
| 576 LocalContext env; | 584 LocalContext env; |
| 577 v8::Isolate* isolate = env->GetIsolate(); | 585 v8::Isolate* isolate = env->GetIsolate(); |
| 578 v8::HandleScope scope(isolate); | 586 v8::HandleScope scope(isolate); |
| 579 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); | 587 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); |
| 580 LocalContext switch_context; | 588 LocalContext switch_context; |
| 581 switch_context->Global()->Set(v8_str("fun"), fun); | 589 switch_context->Global()->Set(v8_str("fun"), fun); |
| 582 v8::TryCatch try_catch; | 590 v8::TryCatch try_catch; |
| 583 CompileRun( | 591 CompileRun( |
| 584 "var o = Object.create(null, { n: { get:fun } });" | 592 "var o = Object.create(null, { n: { get:fun } });" |
| 585 "for (var i = 0; i < 10; i++) o.n;"); | 593 "for (var i = 0; i < 10; i++) o.n;"); |
| 586 CHECK(!try_catch.HasCaught()); | 594 CHECK(!try_catch.HasCaught()); |
| 587 } | 595 } |
| OLD | NEW |