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

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

Issue 83343002: Remove usage of deprecated APIs from cctests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years 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/cctest.gyp ('k') | test/cctest/test-alloc.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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 CHECK(!value->BooleanValue()); 270 CHECK(!value->BooleanValue());
271 } 271 }
272 272
273 273
274 template <int C> 274 template <int C>
275 static void HandleAllocatingGetter( 275 static void HandleAllocatingGetter(
276 Local<String> name, 276 Local<String> name,
277 const v8::PropertyCallbackInfo<v8::Value>& info) { 277 const v8::PropertyCallbackInfo<v8::Value>& info) {
278 ApiTestFuzzer::Fuzz(); 278 ApiTestFuzzer::Fuzz();
279 for (int i = 0; i < C; i++) 279 for (int i = 0; i < C; i++)
280 v8::String::New("foo"); 280 v8::String::NewFromUtf8(info.GetIsolate(), "foo");
281 info.GetReturnValue().Set(v8::String::New("foo")); 281 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo"));
282 } 282 }
283 283
284 284
285 THREADED_TEST(HandleScopePop) { 285 THREADED_TEST(HandleScopePop) {
286 LocalContext context; 286 LocalContext context;
287 v8::HandleScope scope(context->GetIsolate()); 287 v8::HandleScope scope(context->GetIsolate());
288 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 288 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
289 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); 289 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>);
290 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); 290 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>);
291 v8::Handle<v8::Object> inst = obj->NewInstance(); 291 v8::Handle<v8::Object> inst = obj->NewInstance();
292 context->Global()->Set(v8::String::New("obj"), inst); 292 context->Global()->Set(v8::String::NewFromUtf8(context->GetIsolate(), "obj"),
293 inst);
293 i::Isolate* isolate = CcTest::i_isolate(); 294 i::Isolate* isolate = CcTest::i_isolate();
294 int count_before = i::HandleScope::NumberOfHandles(isolate); 295 int count_before = i::HandleScope::NumberOfHandles(isolate);
295 { 296 {
296 v8::HandleScope scope(context->GetIsolate()); 297 v8::HandleScope scope(context->GetIsolate());
297 CompileRun( 298 CompileRun(
298 "for (var i = 0; i < 1000; i++) {" 299 "for (var i = 0; i < 1000; i++) {"
299 " obj.one;" 300 " obj.one;"
300 " obj.many;" 301 " obj.many;"
301 "}"); 302 "}");
302 } 303 }
303 int count_after = i::HandleScope::NumberOfHandles(isolate); 304 int count_after = i::HandleScope::NumberOfHandles(isolate);
304 CHECK_EQ(count_before, count_after); 305 CHECK_EQ(count_before, count_after);
305 } 306 }
306 307
307 static void CheckAccessorArgsCorrect( 308 static void CheckAccessorArgsCorrect(
308 Local<String> name, 309 Local<String> name,
309 const v8::PropertyCallbackInfo<v8::Value>& info) { 310 const v8::PropertyCallbackInfo<v8::Value>& info) {
310 CHECK(info.GetIsolate() == CcTest::isolate()); 311 CHECK(info.GetIsolate() == CcTest::isolate());
311 CHECK(info.This() == info.Holder()); 312 CHECK(info.This() == info.Holder());
312 CHECK(info.Data()->Equals(v8::String::New("data"))); 313 CHECK(
314 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data")));
313 ApiTestFuzzer::Fuzz(); 315 ApiTestFuzzer::Fuzz();
314 CHECK(info.GetIsolate() == CcTest::isolate()); 316 CHECK(info.GetIsolate() == CcTest::isolate());
315 CHECK(info.This() == info.Holder()); 317 CHECK(info.This() == info.Holder());
316 CHECK(info.Data()->Equals(v8::String::New("data"))); 318 CHECK(
319 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data")));
317 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 320 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
318 CHECK(info.GetIsolate() == CcTest::isolate()); 321 CHECK(info.GetIsolate() == CcTest::isolate());
319 CHECK(info.This() == info.Holder()); 322 CHECK(info.This() == info.Holder());
320 CHECK(info.Data()->Equals(v8::String::New("data"))); 323 CHECK(
324 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data")));
321 info.GetReturnValue().Set(17); 325 info.GetReturnValue().Set(17);
322 } 326 }
323 327
324 328
325 THREADED_TEST(DirectCall) { 329 THREADED_TEST(DirectCall) {
326 LocalContext context; 330 LocalContext context;
327 v8::HandleScope scope(context->GetIsolate()); 331 v8::HandleScope scope(context->GetIsolate());
328 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 332 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
329 obj->SetAccessor(v8_str("xxx"), 333 obj->SetAccessor(v8_str("xxx"),
330 CheckAccessorArgsCorrect, 334 CheckAccessorArgsCorrect,
331 NULL, 335 NULL,
332 v8::String::New("data")); 336 v8::String::NewFromUtf8(context->GetIsolate(), "data"));
333 v8::Handle<v8::Object> inst = obj->NewInstance(); 337 v8::Handle<v8::Object> inst = obj->NewInstance();
334 context->Global()->Set(v8::String::New("obj"), inst); 338 context->Global()->Set(v8::String::NewFromUtf8(context->GetIsolate(), "obj"),
335 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 339 inst);
340 Local<Script> scr = v8::Script::Compile(
341 v8::String::NewFromUtf8(context->GetIsolate(), "obj.xxx"));
336 for (int i = 0; i < 10; i++) { 342 for (int i = 0; i < 10; i++) {
337 Local<Value> result = scr->Run(); 343 Local<Value> result = scr->Run();
338 CHECK(!result.IsEmpty()); 344 CHECK(!result.IsEmpty());
339 CHECK_EQ(17, result->Int32Value()); 345 CHECK_EQ(17, result->Int32Value());
340 } 346 }
341 } 347 }
342 348
343 static void EmptyGetter(Local<String> name, 349 static void EmptyGetter(Local<String> name,
344 const v8::PropertyCallbackInfo<v8::Value>& info) { 350 const v8::PropertyCallbackInfo<v8::Value>& info) {
345 CheckAccessorArgsCorrect(name, info); 351 CheckAccessorArgsCorrect(name, info);
346 ApiTestFuzzer::Fuzz(); 352 ApiTestFuzzer::Fuzz();
347 CheckAccessorArgsCorrect(name, info); 353 CheckAccessorArgsCorrect(name, info);
348 info.GetReturnValue().Set(v8::Handle<v8::Value>()); 354 info.GetReturnValue().Set(v8::Handle<v8::Value>());
349 } 355 }
350 356
351 357
352 THREADED_TEST(EmptyResult) { 358 THREADED_TEST(EmptyResult) {
353 LocalContext context; 359 LocalContext context;
354 v8::Isolate* isolate = context->GetIsolate(); 360 v8::Isolate* isolate = context->GetIsolate();
355 v8::HandleScope scope(isolate); 361 v8::HandleScope scope(isolate);
356 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 362 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
357 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); 363 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL,
364 v8::String::NewFromUtf8(isolate, "data"));
358 v8::Handle<v8::Object> inst = obj->NewInstance(); 365 v8::Handle<v8::Object> inst = obj->NewInstance();
359 context->Global()->Set(v8::String::New("obj"), inst); 366 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst);
360 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 367 Local<Script> scr =
368 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx"));
361 for (int i = 0; i < 10; i++) { 369 for (int i = 0; i < 10; i++) {
362 Local<Value> result = scr->Run(); 370 Local<Value> result = scr->Run();
363 CHECK(result == v8::Undefined(isolate)); 371 CHECK(result == v8::Undefined(isolate));
364 } 372 }
365 } 373 }
366 374
367 375
368 THREADED_TEST(NoReuseRegress) { 376 THREADED_TEST(NoReuseRegress) {
369 // Check that the IC generated for the one test doesn't get reused 377 // Check that the IC generated for the one test doesn't get reused
370 // for the other. 378 // for the other.
371 v8::Isolate* isolate = CcTest::isolate(); 379 v8::Isolate* isolate = CcTest::isolate();
372 v8::HandleScope scope(isolate); 380 v8::HandleScope scope(isolate);
373 { 381 {
374 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 382 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
375 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); 383 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL,
384 v8::String::NewFromUtf8(isolate, "data"));
376 LocalContext context; 385 LocalContext context;
377 v8::Handle<v8::Object> inst = obj->NewInstance(); 386 v8::Handle<v8::Object> inst = obj->NewInstance();
378 context->Global()->Set(v8::String::New("obj"), inst); 387 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst);
379 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 388 Local<Script> scr =
389 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx"));
380 for (int i = 0; i < 2; i++) { 390 for (int i = 0; i < 2; i++) {
381 Local<Value> result = scr->Run(); 391 Local<Value> result = scr->Run();
382 CHECK(result == v8::Undefined(isolate)); 392 CHECK(result == v8::Undefined(isolate));
383 } 393 }
384 } 394 }
385 { 395 {
386 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 396 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
387 obj->SetAccessor(v8_str("xxx"), 397 obj->SetAccessor(v8_str("xxx"),
388 CheckAccessorArgsCorrect, 398 CheckAccessorArgsCorrect,
389 NULL, 399 NULL,
390 v8::String::New("data")); 400 v8::String::NewFromUtf8(isolate, "data"));
391 LocalContext context; 401 LocalContext context;
392 v8::Handle<v8::Object> inst = obj->NewInstance(); 402 v8::Handle<v8::Object> inst = obj->NewInstance();
393 context->Global()->Set(v8::String::New("obj"), inst); 403 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst);
394 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 404 Local<Script> scr =
405 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx"));
395 for (int i = 0; i < 10; i++) { 406 for (int i = 0; i < 10; i++) {
396 Local<Value> result = scr->Run(); 407 Local<Value> result = scr->Run();
397 CHECK(!result.IsEmpty()); 408 CHECK(!result.IsEmpty());
398 CHECK_EQ(17, result->Int32Value()); 409 CHECK_EQ(17, result->Int32Value());
399 } 410 }
400 } 411 }
401 } 412 }
402 413
403 static void ThrowingGetAccessor( 414 static void ThrowingGetAccessor(
404 Local<String> name, 415 Local<String> name,
(...skipping 24 matching lines...) Expand all
429 // Use the throwing property setter/getter in a loop to force 440 // Use the throwing property setter/getter in a loop to force
430 // the accessor ICs to be initialized. 441 // the accessor ICs to be initialized.
431 v8::Handle<Value> result; 442 v8::Handle<Value> result;
432 result = Script::Compile(v8_str( 443 result = Script::Compile(v8_str(
433 "var result = '';" 444 "var result = '';"
434 "for (var i = 0; i < 5; i++) {" 445 "for (var i = 0; i < 5; i++) {"
435 " try { obj.x; } catch (e) { result += e; }" 446 " try { obj.x; } catch (e) { result += e; }"
436 "}; result"))->Run(); 447 "}; result"))->Run();
437 CHECK_EQ(v8_str("ggggg"), result); 448 CHECK_EQ(v8_str("ggggg"), result);
438 449
439 result = Script::Compile(String::New( 450 result = Script::Compile(String::NewFromUtf8(
451 env->GetIsolate(),
440 "var result = '';" 452 "var result = '';"
441 "for (var i = 0; i < 5; i++) {" 453 "for (var i = 0; i < 5; i++) {"
442 " try { obj.x = i; } catch (e) { result += e; }" 454 " try { obj.x = i; } catch (e) { result += e; }"
443 "}; result"))->Run(); 455 "}; result"))->Run();
444 CHECK_EQ(v8_str("01234"), result); 456 CHECK_EQ(v8_str("01234"), result);
445 } 457 }
446 458
447 459
448 static void AllocGetter(Local<String> name, 460 static void AllocGetter(Local<String> name,
449 const v8::PropertyCallbackInfo<v8::Value>& info) { 461 const v8::PropertyCallbackInfo<v8::Value>& info) {
450 ApiTestFuzzer::Fuzz(); 462 ApiTestFuzzer::Fuzz();
451 info.GetReturnValue().Set(v8::Array::New(1000)); 463 info.GetReturnValue().Set(v8::Array::New(1000));
452 } 464 }
453 465
454 466
455 THREADED_TEST(Gc) { 467 THREADED_TEST(Gc) {
456 LocalContext env; 468 LocalContext env;
457 v8::HandleScope scope(env->GetIsolate()); 469 v8::HandleScope scope(env->GetIsolate());
458 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 470 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
459 obj->SetAccessor(v8_str("xxx"), AllocGetter); 471 obj->SetAccessor(v8_str("xxx"), AllocGetter);
460 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 472 env->Global()->Set(v8_str("obj"), obj->NewInstance());
461 Script::Compile(String::New( 473 Script::Compile(String::NewFromUtf8(
474 env->GetIsolate(),
462 "var last = [];" 475 "var last = [];"
463 "for (var i = 0; i < 2048; i++) {" 476 "for (var i = 0; i < 2048; i++) {"
464 " var result = obj.xxx;" 477 " var result = obj.xxx;"
465 " result[0] = last;" 478 " result[0] = last;"
466 " last = result;" 479 " last = result;"
467 "}"))->Run(); 480 "}"))->Run();
468 } 481 }
469 482
470 483
471 static void StackCheck(Local<String> name, 484 static void StackCheck(Local<String> name,
(...skipping 12 matching lines...) Expand all
484 497
485 498
486 THREADED_TEST(StackIteration) { 499 THREADED_TEST(StackIteration) {
487 LocalContext env; 500 LocalContext env;
488 v8::HandleScope scope(env->GetIsolate()); 501 v8::HandleScope scope(env->GetIsolate());
489 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 502 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
490 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); 503 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
491 i::StringStream::ClearMentionedObjectCache(isolate); 504 i::StringStream::ClearMentionedObjectCache(isolate);
492 obj->SetAccessor(v8_str("xxx"), StackCheck); 505 obj->SetAccessor(v8_str("xxx"), StackCheck);
493 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 506 env->Global()->Set(v8_str("obj"), obj->NewInstance());
494 Script::Compile(String::New( 507 Script::Compile(String::NewFromUtf8(
508 env->GetIsolate(),
495 "function foo() {" 509 "function foo() {"
496 " return obj.xxx;" 510 " return obj.xxx;"
497 "}" 511 "}"
498 "for (var i = 0; i < 100; i++) {" 512 "for (var i = 0; i < 100; i++) {"
499 " foo();" 513 " foo();"
500 "}"))->Run(); 514 "}"))->Run();
501 } 515 }
502 516
503 517
504 static void AllocateHandles(Local<String> name, 518 static void AllocateHandles(Local<String> name,
505 const v8::PropertyCallbackInfo<v8::Value>& info) { 519 const v8::PropertyCallbackInfo<v8::Value>& info) {
506 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { 520 for (int i = 0; i < i::kHandleBlockSize + 1; i++) {
507 v8::Local<v8::Value>::New(info.GetIsolate(), name); 521 v8::Local<v8::Value>::New(info.GetIsolate(), name);
508 } 522 }
509 info.GetReturnValue().Set(v8::Integer::New(100)); 523 info.GetReturnValue().Set(v8::Integer::New(100));
510 } 524 }
511 525
512 526
513 THREADED_TEST(HandleScopeSegment) { 527 THREADED_TEST(HandleScopeSegment) {
514 // Check that we can return values past popping of handle scope 528 // Check that we can return values past popping of handle scope
515 // segments. 529 // segments.
516 LocalContext env; 530 LocalContext env;
517 v8::HandleScope scope(env->GetIsolate()); 531 v8::HandleScope scope(env->GetIsolate());
518 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 532 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
519 obj->SetAccessor(v8_str("xxx"), AllocateHandles); 533 obj->SetAccessor(v8_str("xxx"), AllocateHandles);
520 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 534 env->Global()->Set(v8_str("obj"), obj->NewInstance());
521 v8::Handle<v8::Value> result = Script::Compile(String::New( 535 v8::Handle<v8::Value> result = Script::Compile(String::NewFromUtf8(
536 env->GetIsolate(),
522 "var result;" 537 "var result;"
523 "for (var i = 0; i < 4; i++)" 538 "for (var i = 0; i < 4; i++)"
524 " result = obj.xxx;" 539 " result = obj.xxx;"
525 "result;"))->Run(); 540 "result;"))->Run();
526 CHECK_EQ(100, result->Int32Value()); 541 CHECK_EQ(100, result->Int32Value());
527 } 542 }
528 543
529 544
530 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 545 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
531 v8::Handle<v8::Array> array = v8::Array::New(1); 546 v8::Handle<v8::Array> array = v8::Array::New(1);
(...skipping 27 matching lines...) Expand all
559 v8::HandleScope scope(isolate); 574 v8::HandleScope scope(isolate);
560 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); 575 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property);
561 LocalContext switch_context; 576 LocalContext switch_context;
562 switch_context->Global()->Set(v8_str("fun"), fun); 577 switch_context->Global()->Set(v8_str("fun"), fun);
563 v8::TryCatch try_catch; 578 v8::TryCatch try_catch;
564 CompileRun( 579 CompileRun(
565 "var o = Object.create(null, { n: { get:fun } });" 580 "var o = Object.create(null, { n: { get:fun } });"
566 "for (var i = 0; i < 10; i++) o.n;"); 581 "for (var i = 0; i < 10; i++) o.n;");
567 CHECK(!try_catch.HasCaught()); 582 CHECK(!try_catch.HasCaught());
568 } 583 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/test-alloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698