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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 325 } |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 #define EXPECT_RECORDS(records, expectations) \ | 329 #define EXPECT_RECORDS(records, expectations) \ |
330 ExpectRecords(isolate.GetIsolate(), records, expectations, \ | 330 ExpectRecords(isolate.GetIsolate(), records, expectations, \ |
331 ARRAY_SIZE(expectations)) | 331 ARRAY_SIZE(expectations)) |
332 | 332 |
333 TEST(APITestBasicMutation) { | 333 TEST(APITestBasicMutation) { |
334 HarmonyIsolate isolate; | 334 HarmonyIsolate isolate; |
335 HandleScope scope(isolate.GetIsolate()); | 335 v8::Isolate* v8_isolate = isolate.GetIsolate(); |
336 LocalContext context(isolate.GetIsolate()); | 336 HandleScope scope(v8_isolate); |
| 337 LocalContext context(v8_isolate); |
337 Handle<Object> obj = Handle<Object>::Cast(CompileRun( | 338 Handle<Object> obj = Handle<Object>::Cast(CompileRun( |
338 "var records = [];" | 339 "var records = [];" |
339 "var obj = {};" | 340 "var obj = {};" |
340 "function observer(r) { [].push.apply(records, r); };" | 341 "function observer(r) { [].push.apply(records, r); };" |
341 "Object.observe(obj, observer);" | 342 "Object.observe(obj, observer);" |
342 "obj")); | 343 "obj")); |
343 obj->Set(String::NewFromUtf8(isolate.GetIsolate(), "foo"), Number::New(7)); | 344 obj->Set(String::NewFromUtf8(v8_isolate, "foo"), |
344 obj->Set(1, Number::New(2)); | 345 Number::New(v8_isolate, 7)); |
| 346 obj->Set(1, Number::New(v8_isolate, 2)); |
345 // ForceSet should work just as well as Set | 347 // ForceSet should work just as well as Set |
346 obj->ForceSet(String::NewFromUtf8(isolate.GetIsolate(), "foo"), | 348 obj->ForceSet(String::NewFromUtf8(v8_isolate, "foo"), |
347 Number::New(3)); | 349 Number::New(v8_isolate, 3)); |
348 obj->ForceSet(Number::New(1), Number::New(4)); | 350 obj->ForceSet(Number::New(v8_isolate, 1), Number::New(v8_isolate, 4)); |
349 // Setting an indexed element via the property setting method | 351 // Setting an indexed element via the property setting method |
350 obj->Set(Number::New(1), Number::New(5)); | 352 obj->Set(Number::New(v8_isolate, 1), Number::New(v8_isolate, 5)); |
351 // Setting with a non-String, non-uint32 key | 353 // Setting with a non-String, non-uint32 key |
352 obj->Set(Number::New(1.1), Number::New(6), DontDelete); | 354 obj->Set(Number::New(v8_isolate, 1.1), |
353 obj->Delete(String::NewFromUtf8(isolate.GetIsolate(), "foo")); | 355 Number::New(v8_isolate, 6), DontDelete); |
| 356 obj->Delete(String::NewFromUtf8(v8_isolate, "foo")); |
354 obj->Delete(1); | 357 obj->Delete(1); |
355 obj->ForceDelete(Number::New(1.1)); | 358 obj->ForceDelete(Number::New(v8_isolate, 1.1)); |
356 | 359 |
357 // Force delivery | 360 // Force delivery |
358 // TODO(adamk): Should the above set methods trigger delivery themselves? | 361 // TODO(adamk): Should the above set methods trigger delivery themselves? |
359 CompileRun("void 0"); | 362 CompileRun("void 0"); |
360 CHECK_EQ(9, CompileRun("records.length")->Int32Value()); | 363 CHECK_EQ(9, CompileRun("records.length")->Int32Value()); |
361 const RecordExpectation expected_records[] = { | 364 const RecordExpectation expected_records[] = { |
362 { obj, "add", "foo", Handle<Value>() }, | 365 { obj, "add", "foo", Handle<Value>() }, |
363 { obj, "add", "1", Handle<Value>() }, | 366 { obj, "add", "1", Handle<Value>() }, |
364 // Note: use 7 not 1 below, as the latter triggers a nifty VS10 compiler bug | 367 // Note: use 7 not 1 below, as the latter triggers a nifty VS10 compiler bug |
365 // where instead of 1.0, a garbage value would be passed into Number::New. | 368 // where instead of 1.0, a garbage value would be passed into Number::New. |
366 { obj, "update", "foo", Number::New(7) }, | 369 { obj, "update", "foo", Number::New(v8_isolate, 7) }, |
367 { obj, "update", "1", Number::New(2) }, | 370 { obj, "update", "1", Number::New(v8_isolate, 2) }, |
368 { obj, "update", "1", Number::New(4) }, | 371 { obj, "update", "1", Number::New(v8_isolate, 4) }, |
369 { obj, "add", "1.1", Handle<Value>() }, | 372 { obj, "add", "1.1", Handle<Value>() }, |
370 { obj, "delete", "foo", Number::New(3) }, | 373 { obj, "delete", "foo", Number::New(v8_isolate, 3) }, |
371 { obj, "delete", "1", Number::New(5) }, | 374 { obj, "delete", "1", Number::New(v8_isolate, 5) }, |
372 { obj, "delete", "1.1", Number::New(6) } | 375 { obj, "delete", "1.1", Number::New(v8_isolate, 6) } |
373 }; | 376 }; |
374 EXPECT_RECORDS(CompileRun("records"), expected_records); | 377 EXPECT_RECORDS(CompileRun("records"), expected_records); |
375 } | 378 } |
376 | 379 |
377 | 380 |
378 TEST(HiddenPrototypeObservation) { | 381 TEST(HiddenPrototypeObservation) { |
379 HarmonyIsolate isolate; | 382 HarmonyIsolate isolate; |
380 HandleScope scope(isolate.GetIsolate()); | 383 v8::Isolate* v8_isolate = isolate.GetIsolate(); |
381 LocalContext context(isolate.GetIsolate()); | 384 HandleScope scope(v8_isolate); |
382 Handle<FunctionTemplate> tmpl = FunctionTemplate::New(isolate.GetIsolate()); | 385 LocalContext context(v8_isolate); |
| 386 Handle<FunctionTemplate> tmpl = FunctionTemplate::New(v8_isolate); |
383 tmpl->SetHiddenPrototype(true); | 387 tmpl->SetHiddenPrototype(true); |
384 tmpl->InstanceTemplate()->Set( | 388 tmpl->InstanceTemplate()->Set( |
385 String::NewFromUtf8(isolate.GetIsolate(), "foo"), Number::New(75)); | 389 String::NewFromUtf8(v8_isolate, "foo"), Number::New(v8_isolate, 75)); |
386 Handle<Object> proto = tmpl->GetFunction()->NewInstance(); | 390 Handle<Object> proto = tmpl->GetFunction()->NewInstance(); |
387 Handle<Object> obj = Object::New(); | 391 Handle<Object> obj = Object::New(v8_isolate); |
388 obj->SetPrototype(proto); | 392 obj->SetPrototype(proto); |
389 context->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"), obj); | 393 context->Global()->Set(String::NewFromUtf8(v8_isolate, "obj"), obj); |
390 context->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "proto"), | 394 context->Global()->Set(String::NewFromUtf8(v8_isolate, "proto"), |
391 proto); | 395 proto); |
392 CompileRun( | 396 CompileRun( |
393 "var records;" | 397 "var records;" |
394 "function observer(r) { records = r; };" | 398 "function observer(r) { records = r; };" |
395 "Object.observe(obj, observer);" | 399 "Object.observe(obj, observer);" |
396 "obj.foo = 41;" // triggers a notification | 400 "obj.foo = 41;" // triggers a notification |
397 "proto.foo = 42;"); // does not trigger a notification | 401 "proto.foo = 42;"); // does not trigger a notification |
398 const RecordExpectation expected_records[] = { | 402 const RecordExpectation expected_records[] = { |
399 { obj, "update", "foo", Number::New(75) } | 403 { obj, "update", "foo", Number::New(v8_isolate, 75) } |
400 }; | 404 }; |
401 EXPECT_RECORDS(CompileRun("records"), expected_records); | 405 EXPECT_RECORDS(CompileRun("records"), expected_records); |
402 obj->SetPrototype(Null(isolate.GetIsolate())); | 406 obj->SetPrototype(Null(v8_isolate)); |
403 CompileRun("obj.foo = 43"); | 407 CompileRun("obj.foo = 43"); |
404 const RecordExpectation expected_records2[] = { | 408 const RecordExpectation expected_records2[] = { |
405 { obj, "add", "foo", Handle<Value>() } | 409 { obj, "add", "foo", Handle<Value>() } |
406 }; | 410 }; |
407 EXPECT_RECORDS(CompileRun("records"), expected_records2); | 411 EXPECT_RECORDS(CompileRun("records"), expected_records2); |
408 obj->SetPrototype(proto); | 412 obj->SetPrototype(proto); |
409 CompileRun( | 413 CompileRun( |
410 "Object.observe(proto, observer);" | 414 "Object.observe(proto, observer);" |
411 "proto.bar = 1;" | 415 "proto.bar = 1;" |
412 "Object.unobserve(obj, observer);" | 416 "Object.unobserve(obj, observer);" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 "Object.observe(objNoCheck, observer2);" | 558 "Object.observe(objNoCheck, observer2);" |
555 "obj.foo = 'bar';" | 559 "obj.foo = 'bar';" |
556 "Object.defineProperty(obj, 'foo', {value: 5});" | 560 "Object.defineProperty(obj, 'foo', {value: 5});" |
557 "Object.defineProperty(obj, 'foo', {get: function(){}});" | 561 "Object.defineProperty(obj, 'foo', {get: function(){}});" |
558 "obj.bar = 'baz';" | 562 "obj.bar = 'baz';" |
559 "objNoCheck.baz = 'quux'"); | 563 "objNoCheck.baz = 'quux'"); |
560 const RecordExpectation expected_records2[] = { | 564 const RecordExpectation expected_records2[] = { |
561 { instance, "add", "foo", Handle<Value>() }, | 565 { instance, "add", "foo", Handle<Value>() }, |
562 { instance, "update", "foo", | 566 { instance, "update", "foo", |
563 String::NewFromUtf8(isolate.GetIsolate(), "bar") }, | 567 String::NewFromUtf8(isolate.GetIsolate(), "bar") }, |
564 { instance, "reconfigure", "foo", Number::New(5) }, | 568 { instance, "reconfigure", "foo", |
| 569 Number::New(isolate.GetIsolate(), 5) }, |
565 { instance, "add", "bar", Handle<Value>() }, | 570 { instance, "add", "bar", Handle<Value>() }, |
566 { obj_no_check, "add", "baz", Handle<Value>() }, | 571 { obj_no_check, "add", "baz", Handle<Value>() }, |
567 }; | 572 }; |
568 EXPECT_RECORDS(CompileRun("records2"), expected_records2); | 573 EXPECT_RECORDS(CompileRun("records2"), expected_records2); |
569 } | 574 } |
570 const RecordExpectation expected_records[] = { | 575 const RecordExpectation expected_records[] = { |
571 { instance, "add", "bar", Handle<Value>() }, | 576 { instance, "add", "bar", Handle<Value>() }, |
572 { obj_no_check, "add", "baz", Handle<Value>() } | 577 { obj_no_check, "add", "baz", Handle<Value>() } |
573 }; | 578 }; |
574 EXPECT_RECORDS(CompileRun("records"), expected_records); | 579 EXPECT_RECORDS(CompileRun("records"), expected_records); |
575 } | 580 } |
576 } | 581 } |
577 | 582 |
578 | 583 |
579 TEST(IndexedAccessCheck) { | 584 TEST(IndexedAccessCheck) { |
580 HarmonyIsolate isolate; | 585 HarmonyIsolate isolate; |
581 const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; | 586 const AccessType types[] = { ACCESS_GET, ACCESS_HAS }; |
582 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { | 587 for (size_t i = 0; i < ARRAY_SIZE(types); ++i) { |
583 HandleScope scope(isolate.GetIsolate()); | 588 HandleScope scope(isolate.GetIsolate()); |
584 LocalContext context(isolate.GetIsolate()); | 589 LocalContext context(isolate.GetIsolate()); |
585 g_access_block_type = types[i]; | 590 g_access_block_type = types[i]; |
586 Handle<Object> instance = CreateAccessCheckedObject( | 591 Handle<Object> instance = CreateAccessCheckedObject( |
587 isolate.GetIsolate(), NamedAccessAlwaysAllowed, | 592 isolate.GetIsolate(), NamedAccessAlwaysAllowed, |
588 IndexedAccessAllowUnlessBlocked, Number::New(7)); | 593 IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 7)); |
589 CompileRun("var records = null;" | 594 CompileRun("var records = null;" |
590 "var objNoCheck = {};" | 595 "var objNoCheck = {};" |
591 "var observer = function(r) { records = r };" | 596 "var observer = function(r) { records = r };" |
592 "Object.observe(obj, observer);" | 597 "Object.observe(obj, observer);" |
593 "Object.observe(objNoCheck, observer);"); | 598 "Object.observe(objNoCheck, observer);"); |
594 Handle<Value> obj_no_check = CompileRun("objNoCheck"); | 599 Handle<Value> obj_no_check = CompileRun("objNoCheck"); |
595 { | 600 { |
596 LocalContext context2(isolate.GetIsolate()); | 601 LocalContext context2(isolate.GetIsolate()); |
597 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"), | 602 context2->Global()->Set(String::NewFromUtf8(isolate.GetIsolate(), "obj"), |
598 instance); | 603 instance); |
599 context2->Global()->Set( | 604 context2->Global()->Set( |
600 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), | 605 String::NewFromUtf8(isolate.GetIsolate(), "objNoCheck"), |
601 obj_no_check); | 606 obj_no_check); |
602 CompileRun("var records2 = null;" | 607 CompileRun("var records2 = null;" |
603 "var observer2 = function(r) { records2 = r };" | 608 "var observer2 = function(r) { records2 = r };" |
604 "Object.observe(obj, observer2);" | 609 "Object.observe(obj, observer2);" |
605 "Object.observe(objNoCheck, observer2);" | 610 "Object.observe(objNoCheck, observer2);" |
606 "obj[7] = 'foo';" | 611 "obj[7] = 'foo';" |
607 "Object.defineProperty(obj, '7', {value: 5});" | 612 "Object.defineProperty(obj, '7', {value: 5});" |
608 "Object.defineProperty(obj, '7', {get: function(){}});" | 613 "Object.defineProperty(obj, '7', {get: function(){}});" |
609 "obj[8] = 'bar';" | 614 "obj[8] = 'bar';" |
610 "objNoCheck[42] = 'quux'"); | 615 "objNoCheck[42] = 'quux'"); |
611 const RecordExpectation expected_records2[] = { | 616 const RecordExpectation expected_records2[] = { |
612 { instance, "add", "7", Handle<Value>() }, | 617 { instance, "add", "7", Handle<Value>() }, |
613 { instance, "update", "7", | 618 { instance, "update", "7", |
614 String::NewFromUtf8(isolate.GetIsolate(), "foo") }, | 619 String::NewFromUtf8(isolate.GetIsolate(), "foo") }, |
615 { instance, "reconfigure", "7", Number::New(5) }, | 620 { instance, "reconfigure", "7", Number::New(isolate.GetIsolate(), 5) }, |
616 { instance, "add", "8", Handle<Value>() }, | 621 { instance, "add", "8", Handle<Value>() }, |
617 { obj_no_check, "add", "42", Handle<Value>() } | 622 { obj_no_check, "add", "42", Handle<Value>() } |
618 }; | 623 }; |
619 EXPECT_RECORDS(CompileRun("records2"), expected_records2); | 624 EXPECT_RECORDS(CompileRun("records2"), expected_records2); |
620 } | 625 } |
621 const RecordExpectation expected_records[] = { | 626 const RecordExpectation expected_records[] = { |
622 { instance, "add", "8", Handle<Value>() }, | 627 { instance, "add", "8", Handle<Value>() }, |
623 { obj_no_check, "add", "42", Handle<Value>() } | 628 { obj_no_check, "add", "42", Handle<Value>() } |
624 }; | 629 }; |
625 EXPECT_RECORDS(CompileRun("records"), expected_records); | 630 EXPECT_RECORDS(CompileRun("records"), expected_records); |
626 } | 631 } |
627 } | 632 } |
628 | 633 |
629 | 634 |
630 TEST(SpliceAccessCheck) { | 635 TEST(SpliceAccessCheck) { |
631 HarmonyIsolate isolate; | 636 HarmonyIsolate isolate; |
632 HandleScope scope(isolate.GetIsolate()); | 637 HandleScope scope(isolate.GetIsolate()); |
633 LocalContext context(isolate.GetIsolate()); | 638 LocalContext context(isolate.GetIsolate()); |
634 g_access_block_type = ACCESS_GET; | 639 g_access_block_type = ACCESS_GET; |
635 Handle<Object> instance = CreateAccessCheckedObject( | 640 Handle<Object> instance = CreateAccessCheckedObject( |
636 isolate.GetIsolate(), NamedAccessAlwaysAllowed, | 641 isolate.GetIsolate(), NamedAccessAlwaysAllowed, |
637 IndexedAccessAllowUnlessBlocked, Number::New(1)); | 642 IndexedAccessAllowUnlessBlocked, Number::New(isolate.GetIsolate(), 1)); |
638 CompileRun("var records = null;" | 643 CompileRun("var records = null;" |
639 "obj[1] = 'foo';" | 644 "obj[1] = 'foo';" |
640 "obj.length = 2;" | 645 "obj.length = 2;" |
641 "var objNoCheck = {1: 'bar', length: 2};" | 646 "var objNoCheck = {1: 'bar', length: 2};" |
642 "observer = function(r) { records = r };" | 647 "observer = function(r) { records = r };" |
643 "Array.observe(obj, observer);" | 648 "Array.observe(obj, observer);" |
644 "Array.observe(objNoCheck, observer);"); | 649 "Array.observe(objNoCheck, observer);"); |
645 Handle<Value> obj_no_check = CompileRun("objNoCheck"); | 650 Handle<Value> obj_no_check = CompileRun("objNoCheck"); |
646 { | 651 { |
647 LocalContext context2(isolate.GetIsolate()); | 652 LocalContext context2(isolate.GetIsolate()); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 "var observer = function(r) { records = r };" | 757 "var observer = function(r) { records = r };" |
753 "Object.observe(obj, observer);"); | 758 "Object.observe(obj, observer);"); |
754 Handle<Value> obj = | 759 Handle<Value> obj = |
755 context->Global()->Get(String::NewFromUtf8(isolate.GetIsolate(), "obj")); | 760 context->Global()->Get(String::NewFromUtf8(isolate.GetIsolate(), "obj")); |
756 Handle<Object>::Cast(obj) | 761 Handle<Object>::Cast(obj) |
757 ->SetHiddenValue(String::NewFromUtf8(isolate.GetIsolate(), "foo"), | 762 ->SetHiddenValue(String::NewFromUtf8(isolate.GetIsolate(), "foo"), |
758 Null(isolate.GetIsolate())); | 763 Null(isolate.GetIsolate())); |
759 CompileRun(""); // trigger delivery | 764 CompileRun(""); // trigger delivery |
760 CHECK(CompileRun("records")->IsNull()); | 765 CHECK(CompileRun("records")->IsNull()); |
761 } | 766 } |
OLD | NEW |