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

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

Issue 6697023: Merge 6800:7180 from the bleeding edge branch to the experimental/gc branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: Created 9 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/cctest.status ('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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 2673 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 THREADED_TEST(CatchExceptionFromWith) { 2684 THREADED_TEST(CatchExceptionFromWith) {
2685 v8::HandleScope scope; 2685 v8::HandleScope scope;
2686 LocalContext context; 2686 LocalContext context;
2687 v8::TryCatch try_catch; 2687 v8::TryCatch try_catch;
2688 CHECK(!try_catch.HasCaught()); 2688 CHECK(!try_catch.HasCaught());
2689 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); 2689 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run();
2690 CHECK(try_catch.HasCaught()); 2690 CHECK(try_catch.HasCaught());
2691 } 2691 }
2692 2692
2693 2693
2694 THREADED_TEST(TryCatchAndFinallyHidingException) {
2695 v8::HandleScope scope;
2696 LocalContext context;
2697 v8::TryCatch try_catch;
2698 CHECK(!try_catch.HasCaught());
2699 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };");
2700 CompileRun("f({toString: function() { throw 42; }});");
2701 CHECK(!try_catch.HasCaught());
2702 }
2703
2704
2705 v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) {
2706 v8::TryCatch try_catch;
2707 return v8::Undefined();
2708 }
2709
2710
2711 THREADED_TEST(TryCatchAndFinally) {
2712 v8::HandleScope scope;
2713 LocalContext context;
2714 context->Global()->Set(
2715 v8_str("native_with_try_catch"),
2716 v8::FunctionTemplate::New(WithTryCatch)->GetFunction());
2717 v8::TryCatch try_catch;
2718 CHECK(!try_catch.HasCaught());
2719 CompileRun(
2720 "try {\n"
2721 " throw new Error('a');\n"
2722 "} finally {\n"
2723 " native_with_try_catch();\n"
2724 "}\n");
2725 CHECK(try_catch.HasCaught());
2726 }
2727
2728
2694 THREADED_TEST(Equality) { 2729 THREADED_TEST(Equality) {
2695 v8::HandleScope scope; 2730 v8::HandleScope scope;
2696 LocalContext context; 2731 LocalContext context;
2697 // Check that equality works at all before relying on CHECK_EQ 2732 // Check that equality works at all before relying on CHECK_EQ
2698 CHECK(v8_str("a")->Equals(v8_str("a"))); 2733 CHECK(v8_str("a")->Equals(v8_str("a")));
2699 CHECK(!v8_str("a")->Equals(v8_str("b"))); 2734 CHECK(!v8_str("a")->Equals(v8_str("b")));
2700 2735
2701 CHECK_EQ(v8_str("a"), v8_str("a")); 2736 CHECK_EQ(v8_str("a"), v8_str("a"));
2702 CHECK_NE(v8_str("a"), v8_str("b")); 2737 CHECK_NE(v8_str("a"), v8_str("b"));
2703 CHECK_EQ(v8_num(1), v8_num(1)); 2738 CHECK_EQ(v8_num(1), v8_num(1));
(...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after
5610 "return true;})()"); 5645 "return true;})()");
5611 CHECK(value->IsTrue()); 5646 CHECK(value->IsTrue());
5612 5647
5613 context1->Exit(); 5648 context1->Exit();
5614 context0->Exit(); 5649 context0->Exit();
5615 context1.Dispose(); 5650 context1.Dispose();
5616 context0.Dispose(); 5651 context0.Dispose();
5617 } 5652 }
5618 5653
5619 5654
5620 // This is a regression test for issue 1154. 5655 TEST(AccessControlES5) {
5621 TEST(AccessControlObjectKeys) {
5622 v8::HandleScope handle_scope; 5656 v8::HandleScope handle_scope;
5623 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5657 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5624 5658
5625 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, 5659 global_template->SetAccessCheckCallbacks(NamedAccessBlocker,
5626 IndexedAccessBlocker); 5660 IndexedAccessBlocker);
5627 5661
5662 // Add accessible accessor.
5663 global_template->SetAccessor(
5664 v8_str("accessible_prop"),
5665 EchoGetter, EchoSetter,
5666 v8::Handle<Value>(),
5667 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
5668
5669
5628 // Add an accessor that is not accessible by cross-domain JS code. 5670 // Add an accessor that is not accessible by cross-domain JS code.
5629 global_template->SetAccessor(v8_str("blocked_prop"), 5671 global_template->SetAccessor(v8_str("blocked_prop"),
5630 UnreachableGetter, UnreachableSetter, 5672 UnreachableGetter, UnreachableSetter,
5631 v8::Handle<Value>(), 5673 v8::Handle<Value>(),
5632 v8::DEFAULT); 5674 v8::DEFAULT);
5633 5675
5634 // Create an environment 5676 // Create an environment
5635 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 5677 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
5636 context0->Enter(); 5678 context0->Enter();
5637 5679
5638 v8::Handle<v8::Object> global0 = context0->Global(); 5680 v8::Handle<v8::Object> global0 = context0->Global();
5639 5681
5640 v8::Persistent<Context> context1 = Context::New(); 5682 v8::Persistent<Context> context1 = Context::New();
5641 context1->Enter(); 5683 context1->Enter();
5642 v8::Handle<v8::Object> global1 = context1->Global(); 5684 v8::Handle<v8::Object> global1 = context1->Global();
5643 global1->Set(v8_str("other"), global0); 5685 global1->Set(v8_str("other"), global0);
5644 5686
5687 // Regression test for issue 1154.
5645 ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1"); 5688 ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1");
5689
5690 ExpectUndefined("other.blocked_prop");
5691
5692 // Regression test for issue 1027.
5693 CompileRun("Object.defineProperty(\n"
5694 " other, 'blocked_prop', {configurable: false})");
5695 ExpectUndefined("other.blocked_prop");
5696 ExpectUndefined(
5697 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')");
5698
5699 // Regression test for issue 1171.
5700 ExpectTrue("Object.isExtensible(other)");
5701 CompileRun("Object.preventExtensions(other)");
5702 ExpectTrue("Object.isExtensible(other)");
5703
5704 // Object.seal and Object.freeze.
5705 CompileRun("Object.freeze(other)");
5706 ExpectTrue("Object.isExtensible(other)");
5707
5708 CompileRun("Object.seal(other)");
5709 ExpectTrue("Object.isExtensible(other)");
5710
5711 // Regression test for issue 1250.
5712 // Make sure that we can set the accessible accessors value using normal
5713 // assignment.
5714 CompileRun("other.accessible_prop = 42");
5715 CHECK_EQ(42, g_echo_value);
5716
5717 v8::Handle<Value> value;
5718 // We follow Safari in ignoring assignments to host object accessors.
5719 CompileRun("Object.defineProperty(other, 'accessible_prop', {value: -1})");
5720 value = CompileRun("other.accessible_prop == 42");
5721 CHECK(value->IsTrue());
5646 } 5722 }
5647 5723
5648 5724
5649 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, 5725 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global,
5650 Local<Value> name, 5726 Local<Value> name,
5651 v8::AccessType type, 5727 v8::AccessType type,
5652 Local<Value> data) { 5728 Local<Value> data) {
5653 return false; 5729 return false;
5654 } 5730 }
5655 5731
(...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after
7564 // Helper to maximize the odds of object moving. 7640 // Helper to maximize the odds of object moving.
7565 static void GenerateSomeGarbage() { 7641 static void GenerateSomeGarbage() {
7566 CompileRun( 7642 CompileRun(
7567 "var garbage;" 7643 "var garbage;"
7568 "for (var i = 0; i < 1000; i++) {" 7644 "for (var i = 0; i < 1000; i++) {"
7569 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" 7645 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
7570 "}" 7646 "}"
7571 "garbage = undefined;"); 7647 "garbage = undefined;");
7572 } 7648 }
7573 7649
7650
7574 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { 7651 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) {
7575 static int count = 0; 7652 static int count = 0;
7576 if (count++ % 3 == 0) { 7653 if (count++ % 3 == 0) {
7577 v8::V8::LowMemoryNotification(); // This should move the stub 7654 i::Heap::CollectAllGarbage(true); // This should move the stub
7578 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 7655 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
7579 } 7656 }
7580 return v8::Handle<v8::Value>(); 7657 return v8::Handle<v8::Value>();
7581 } 7658 }
7582 7659
7583 7660
7584 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 7661 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
7585 v8::HandleScope scope; 7662 v8::HandleScope scope;
7586 LocalContext context; 7663 LocalContext context;
7587 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 7664 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
7619 "function f() {" 7696 "function f() {"
7620 " for (var i = 1; i <= 5; i++) {" 7697 " for (var i = 1; i <= 5; i++) {"
7621 " try { nativeobject.callback(); } catch (e) { result += e; }" 7698 " try { nativeobject.callback(); } catch (e) { result += e; }"
7622 " }" 7699 " }"
7623 "}" 7700 "}"
7624 "f(); result;"); 7701 "f(); result;");
7625 CHECK_EQ(v8_str("ggggg"), result); 7702 CHECK_EQ(v8_str("ggggg"), result);
7626 } 7703 }
7627 7704
7628 7705
7706 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name,
7707 const v8::AccessorInfo& info) {
7708 if (++p_getter_count % 3 == 0) {
7709 i::Heap::CollectAllGarbage(true);
7710 GenerateSomeGarbage();
7711 }
7712 return v8::Handle<v8::Value>();
7713 }
7714
7715
7716 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
7717 v8::HandleScope scope;
7718 LocalContext context;
7719 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
7720 obj->SetAccessor(v8_str("p1"), DirectGetterCallback);
7721 context->Global()->Set(v8_str("o1"), obj->NewInstance());
7722 p_getter_count = 0;
7723 CompileRun(
7724 "function f() {"
7725 " for (var i = 0; i < 30; i++) o1.p1;"
7726 "}"
7727 "f();");
7728 CHECK_EQ(30, p_getter_count);
7729 }
7730
7731
7732 v8::Handle<v8::Value> ThrowingDirectGetterCallback(
7733 Local<String> name, const v8::AccessorInfo& info) {
7734 return v8::ThrowException(v8_str("g"));
7735 }
7736
7737
7738 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
7739 v8::HandleScope scope;
7740 LocalContext context;
7741 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New();
7742 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
7743 context->Global()->Set(v8_str("o1"), obj->NewInstance());
7744 v8::Handle<Value> result = CompileRun(
7745 "var result = '';"
7746 "for (var i = 0; i < 5; i++) {"
7747 " try { o1.p1; } catch (e) { result += e; }"
7748 "}"
7749 "result;");
7750 CHECK_EQ(v8_str("ggggg"), result);
7751 }
7752
7753
7629 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { 7754 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) {
7630 int interceptor_call_count = 0; 7755 int interceptor_call_count = 0;
7631 v8::HandleScope scope; 7756 v8::HandleScope scope;
7632 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 7757 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
7633 v8::Handle<v8::FunctionTemplate> method_templ = 7758 v8::Handle<v8::FunctionTemplate> method_templ =
7634 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 7759 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature,
7635 v8_str("method_data"), 7760 v8_str("method_data"),
7636 v8::Handle<v8::Signature>()); 7761 v8::Handle<v8::Signature>());
7637 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 7762 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
7638 proto_templ->Set(v8_str("method"), method_templ); 7763 proto_templ->Set(v8_str("method"), method_templ);
(...skipping 2340 matching lines...) Expand 10 before | Expand all | Expand 10 after
9979 } 10104 }
9980 two_byte_content_[14] = 'b'; 10105 two_byte_content_[14] = 'b';
9981 10106
9982 // Create the input string for the regexp - the one we are going to change 10107 // Create the input string for the regexp - the one we are going to change
9983 // properties of. 10108 // properties of.
9984 input_ = i::Factory::NewExternalStringFromAscii(&ascii_resource_); 10109 input_ = i::Factory::NewExternalStringFromAscii(&ascii_resource_);
9985 10110
9986 // Inject the input as a global variable. 10111 // Inject the input as a global variable.
9987 i::Handle<i::String> input_name = 10112 i::Handle<i::String> input_name =
9988 i::Factory::NewStringFromAscii(i::Vector<const char>("input", 5)); 10113 i::Factory::NewStringFromAscii(i::Vector<const char>("input", 5));
9989 i::Top::global_context()->global()->SetProperty(*input_name, 10114 i::Top::global_context()->global()->SetProperty(
9990 *input_, 10115 *input_name,
9991 NONE)->ToObjectChecked(); 10116 *input_,
9992 10117 NONE,
10118 i::kNonStrictMode)->ToObjectChecked();
9993 10119
9994 MorphThread morph_thread(this); 10120 MorphThread morph_thread(this);
9995 morph_thread.Start(); 10121 morph_thread.Start();
9996 v8::Locker::StartPreemption(1); 10122 v8::Locker::StartPreemption(1);
9997 LongRunningRegExp(); 10123 LongRunningRegExp();
9998 { 10124 {
9999 v8::Unlocker unlock; 10125 v8::Unlocker unlock;
10000 morph_thread.Join(); 10126 morph_thread.Join();
10001 } 10127 }
10002 v8::Locker::StopPreemption(); 10128 v8::Locker::StopPreemption();
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
10436 context->DetachGlobal(); 10562 context->DetachGlobal();
10437 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value()); 10563 CHECK_EQ(42, CompileRun("f(this).foo")->Int32Value());
10438 } 10564 }
10439 10565
10440 10566
10441 THREADED_TEST(PixelArray) { 10567 THREADED_TEST(PixelArray) {
10442 v8::HandleScope scope; 10568 v8::HandleScope scope;
10443 LocalContext context; 10569 LocalContext context;
10444 const int kElementCount = 260; 10570 const int kElementCount = 260;
10445 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); 10571 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10446 i::Handle<i::PixelArray> pixels = i::Factory::NewPixelArray(kElementCount, 10572 i::Handle<i::ExternalPixelArray> pixels =
10447 pixel_data); 10573 i::Handle<i::ExternalPixelArray>::cast(
10574 i::Factory::NewExternalArray(kElementCount,
10575 v8::kExternalPixelArray,
10576 pixel_data));
10448 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. 10577 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification.
10449 for (int i = 0; i < kElementCount; i++) { 10578 for (int i = 0; i < kElementCount; i++) {
10450 pixels->set(i, i % 256); 10579 pixels->set(i, i % 256);
10451 } 10580 }
10452 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification. 10581 i::Heap::CollectAllGarbage(false); // Force GC to trigger verification.
10453 for (int i = 0; i < kElementCount; i++) { 10582 for (int i = 0; i < kElementCount; i++) {
10454 CHECK_EQ(i % 256, pixels->get(i)); 10583 CHECK_EQ(i % 256, pixels->get(i));
10455 CHECK_EQ(i % 256, pixel_data[i]); 10584 CHECK_EQ(i % 256, pixel_data[i]);
10456 } 10585 }
10457 10586
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
10504 CHECK_EQ(28, result->Int32Value()); 10633 CHECK_EQ(28, result->Int32Value());
10505 10634
10506 result = CompileRun("var sum = 0;" 10635 result = CompileRun("var sum = 0;"
10507 "for (var i = 0; i < 8; i++) {" 10636 "for (var i = 0; i < 8; i++) {"
10508 " sum += pixels[i];" 10637 " sum += pixels[i];"
10509 "}" 10638 "}"
10510 "sum;"); 10639 "sum;");
10511 CHECK_EQ(28, result->Int32Value()); 10640 CHECK_EQ(28, result->Int32Value());
10512 10641
10513 i::Handle<i::Smi> value(i::Smi::FromInt(2)); 10642 i::Handle<i::Smi> value(i::Smi::FromInt(2));
10514 i::SetElement(jsobj, 1, value); 10643 i::SetElement(jsobj, 1, value, i::kNonStrictMode);
10515 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); 10644 CHECK_EQ(2, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
10516 *value.location() = i::Smi::FromInt(256); 10645 *value.location() = i::Smi::FromInt(256);
10517 i::SetElement(jsobj, 1, value); 10646 i::SetElement(jsobj, 1, value, i::kNonStrictMode);
10518 CHECK_EQ(255, 10647 CHECK_EQ(255,
10519 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); 10648 i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
10520 *value.location() = i::Smi::FromInt(-1); 10649 *value.location() = i::Smi::FromInt(-1);
10521 i::SetElement(jsobj, 1, value); 10650 i::SetElement(jsobj, 1, value, i::kNonStrictMode);
10522 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); 10651 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
10523 10652
10524 result = CompileRun("for (var i = 0; i < 8; i++) {" 10653 result = CompileRun("for (var i = 0; i < 8; i++) {"
10525 " pixels[i] = (i * 65) - 109;" 10654 " pixels[i] = (i * 65) - 109;"
10526 "}" 10655 "}"
10527 "pixels[1] + pixels[6];"); 10656 "pixels[1] + pixels[6];");
10528 CHECK_EQ(255, result->Int32Value()); 10657 CHECK_EQ(255, result->Int32Value());
10529 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value()); 10658 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(0)->ToObjectChecked())->value());
10530 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value()); 10659 CHECK_EQ(0, i::Smi::cast(jsobj->GetElement(1)->ToObjectChecked())->value());
10531 CHECK_EQ(21, 10660 CHECK_EQ(21,
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
10777 10906
10778 // Make sure that pixel array loads are optimized by crankshaft. 10907 // Make sure that pixel array loads are optimized by crankshaft.
10779 result = CompileRun("function pa_load(p) {" 10908 result = CompileRun("function pa_load(p) {"
10780 " var sum = 0;" 10909 " var sum = 0;"
10781 " for (var i=0; i<256; ++i) {" 10910 " for (var i=0; i<256; ++i) {"
10782 " sum += p[i];" 10911 " sum += p[i];"
10783 " }" 10912 " }"
10784 " return sum; " 10913 " return sum; "
10785 "}" 10914 "}"
10786 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" 10915 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }"
10787 "for (var i = 0; i < 10000; ++i) {" 10916 "for (var i = 0; i < 5000; ++i) {"
10788 " result = pa_load(pixels);" 10917 " result = pa_load(pixels);"
10789 "}" 10918 "}"
10790 "result"); 10919 "result");
10791 CHECK_EQ(32640, result->Int32Value()); 10920 CHECK_EQ(32640, result->Int32Value());
10792 10921
10922 // Make sure that pixel array stores are optimized by crankshaft.
10923 result = CompileRun("function pa_init(p) {"
10924 "for (var i = 0; i < 256; ++i) { p[i] = i; }"
10925 "}"
10926 "function pa_load(p) {"
10927 " var sum = 0;"
10928 " for (var i=0; i<256; ++i) {"
10929 " sum += p[i];"
10930 " }"
10931 " return sum; "
10932 "}"
10933 "for (var i = 0; i < 5000; ++i) {"
10934 " pa_init(pixels);"
10935 "}"
10936 "result = pa_load(pixels);"
10937 "result");
10938 CHECK_EQ(32640, result->Int32Value());
10939
10793 free(pixel_data); 10940 free(pixel_data);
10794 } 10941 }
10795 10942
10796 10943
10797 THREADED_TEST(PixelArrayInfo) { 10944 THREADED_TEST(PixelArrayInfo) {
10798 v8::HandleScope scope; 10945 v8::HandleScope scope;
10799 LocalContext context; 10946 LocalContext context;
10800 for (int size = 0; size < 100; size += 10) { 10947 for (int size = 0; size < 100; size += 10) {
10801 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); 10948 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size));
10802 v8::Handle<v8::Object> obj = v8::Object::New(); 10949 v8::Handle<v8::Object> obj = v8::Object::New();
10803 obj->SetIndexedPropertiesToPixelData(pixel_data, size); 10950 obj->SetIndexedPropertiesToPixelData(pixel_data, size);
10804 CHECK(obj->HasIndexedPropertiesInPixelData()); 10951 CHECK(obj->HasIndexedPropertiesInPixelData());
10805 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); 10952 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData());
10806 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); 10953 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength());
10807 free(pixel_data); 10954 free(pixel_data);
10808 } 10955 }
10809 } 10956 }
10810 10957
10811 10958
10959 static v8::Handle<Value> NotHandledIndexedPropertyGetter(
10960 uint32_t index,
10961 const AccessorInfo& info) {
10962 ApiTestFuzzer::Fuzz();
10963 return v8::Handle<Value>();
10964 }
10965
10966
10967 static v8::Handle<Value> NotHandledIndexedPropertySetter(
10968 uint32_t index,
10969 Local<Value> value,
10970 const AccessorInfo& info) {
10971 ApiTestFuzzer::Fuzz();
10972 return v8::Handle<Value>();
10973 }
10974
10975
10976 THREADED_TEST(PixelArrayWithInterceptor) {
10977 v8::HandleScope scope;
10978 LocalContext context;
10979 const int kElementCount = 260;
10980 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount));
10981 i::Handle<i::ExternalPixelArray> pixels =
10982 i::Handle<i::ExternalPixelArray>::cast(
10983 i::Factory::NewExternalArray(kElementCount,
10984 v8::kExternalPixelArray,
10985 pixel_data));
10986 for (int i = 0; i < kElementCount; i++) {
10987 pixels->set(i, i % 256);
10988 }
10989 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
10990 templ->SetIndexedPropertyHandler(NotHandledIndexedPropertyGetter,
10991 NotHandledIndexedPropertySetter);
10992 v8::Handle<v8::Object> obj = templ->NewInstance();
10993 obj->SetIndexedPropertiesToPixelData(pixel_data, kElementCount);
10994 context->Global()->Set(v8_str("pixels"), obj);
10995 v8::Handle<v8::Value> result = CompileRun("pixels[1]");
10996 CHECK_EQ(1, result->Int32Value());
10997 result = CompileRun("var sum = 0;"
10998 "for (var i = 0; i < 8; i++) {"
10999 " sum += pixels[i] = pixels[i] = -i;"
11000 "}"
11001 "sum;");
11002 CHECK_EQ(-28, result->Int32Value());
11003 result = CompileRun("pixels.hasOwnProperty('1')");
11004 CHECK(result->BooleanValue());
11005 free(pixel_data);
11006 }
11007
11008
10812 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { 11009 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) {
10813 switch (array_type) { 11010 switch (array_type) {
10814 case v8::kExternalByteArray: 11011 case v8::kExternalByteArray:
10815 case v8::kExternalUnsignedByteArray: 11012 case v8::kExternalUnsignedByteArray:
11013 case v8::kExternalPixelArray:
10816 return 1; 11014 return 1;
10817 break; 11015 break;
10818 case v8::kExternalShortArray: 11016 case v8::kExternalShortArray:
10819 case v8::kExternalUnsignedShortArray: 11017 case v8::kExternalUnsignedShortArray:
10820 return 2; 11018 return 2;
10821 break; 11019 break;
10822 case v8::kExternalIntArray: 11020 case v8::kExternalIntArray:
10823 case v8::kExternalUnsignedIntArray: 11021 case v8::kExternalUnsignedIntArray:
10824 case v8::kExternalFloatArray: 11022 case v8::kExternalFloatArray:
10825 return 4; 11023 return 4;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
11027 CHECK_EQ(0, 11225 CHECK_EQ(0,
11028 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11226 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11029 11227
11030 result = CompileRun("for (var i = 0; i < 8; i++) {" 11228 result = CompileRun("for (var i = 0; i < 8; i++) {"
11031 " ext_array[i] = 5;" 11229 " ext_array[i] = 5;"
11032 "}" 11230 "}"
11033 "for (var i = 0; i < 8; i++) {" 11231 "for (var i = 0; i < 8; i++) {"
11034 " ext_array[i] = Infinity;" 11232 " ext_array[i] = Infinity;"
11035 "}" 11233 "}"
11036 "ext_array[5];"); 11234 "ext_array[5];");
11037 CHECK_EQ(0, result->Int32Value()); 11235 int expected_value =
11038 CHECK_EQ(0, 11236 (array_type == v8::kExternalPixelArray) ? 255 : 0;
11237 CHECK_EQ(expected_value, result->Int32Value());
11238 CHECK_EQ(expected_value,
11039 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11239 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11040 11240
11041 result = CompileRun("for (var i = 0; i < 8; i++) {" 11241 result = CompileRun("for (var i = 0; i < 8; i++) {"
11042 " ext_array[i] = 5;" 11242 " ext_array[i] = 5;"
11043 "}" 11243 "}"
11044 "for (var i = 0; i < 8; i++) {" 11244 "for (var i = 0; i < 8; i++) {"
11045 " ext_array[i] = -Infinity;" 11245 " ext_array[i] = -Infinity;"
11046 "}" 11246 "}"
11047 "ext_array[5];"); 11247 "ext_array[5];");
11048 CHECK_EQ(0, result->Int32Value()); 11248 CHECK_EQ(0, result->Int32Value());
11049 CHECK_EQ(0, 11249 CHECK_EQ(0,
11050 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value()); 11250 i::Smi::cast(jsobj->GetElement(5)->ToObjectChecked())->value());
11051 11251
11052 // Check truncation behavior of integral arrays. 11252 // Check truncation behavior of integral arrays.
11053 const char* unsigned_data = 11253 const char* unsigned_data =
11054 "var source_data = [0.6, 10.6];" 11254 "var source_data = [0.6, 10.6];"
11055 "var expected_results = [0, 10];"; 11255 "var expected_results = [0, 10];";
11056 const char* signed_data = 11256 const char* signed_data =
11057 "var source_data = [0.6, 10.6, -0.6, -10.6];" 11257 "var source_data = [0.6, 10.6, -0.6, -10.6];"
11058 "var expected_results = [0, 10, 0, -10];"; 11258 "var expected_results = [0, 10, 0, -10];";
11259 const char* pixel_data =
11260 "var source_data = [0.6, 10.6];"
11261 "var expected_results = [1, 11];";
11059 bool is_unsigned = 11262 bool is_unsigned =
11060 (array_type == v8::kExternalUnsignedByteArray || 11263 (array_type == v8::kExternalUnsignedByteArray ||
11061 array_type == v8::kExternalUnsignedShortArray || 11264 array_type == v8::kExternalUnsignedShortArray ||
11062 array_type == v8::kExternalUnsignedIntArray); 11265 array_type == v8::kExternalUnsignedIntArray);
11266 bool is_pixel_data = array_type == v8::kExternalPixelArray;
11063 11267
11064 i::OS::SNPrintF(test_buf, 11268 i::OS::SNPrintF(test_buf,
11065 "%s" 11269 "%s"
11066 "var all_passed = true;" 11270 "var all_passed = true;"
11067 "for (var i = 0; i < source_data.length; i++) {" 11271 "for (var i = 0; i < source_data.length; i++) {"
11068 " for (var j = 0; j < 8; j++) {" 11272 " for (var j = 0; j < 8; j++) {"
11069 " ext_array[j] = source_data[i];" 11273 " ext_array[j] = source_data[i];"
11070 " }" 11274 " }"
11071 " all_passed = all_passed &&" 11275 " all_passed = all_passed &&"
11072 " (ext_array[5] == expected_results[i]);" 11276 " (ext_array[5] == expected_results[i]);"
11073 "}" 11277 "}"
11074 "all_passed;", 11278 "all_passed;",
11075 (is_unsigned ? unsigned_data : signed_data)); 11279 (is_unsigned ?
11280 unsigned_data :
11281 (is_pixel_data ? pixel_data : signed_data)));
11076 result = CompileRun(test_buf.start()); 11282 result = CompileRun(test_buf.start());
11077 CHECK_EQ(true, result->BooleanValue()); 11283 CHECK_EQ(true, result->BooleanValue());
11078 } 11284 }
11079 11285
11080 result = CompileRun("ext_array[3] = 33;" 11286 result = CompileRun("ext_array[3] = 33;"
11081 "delete ext_array[3];" 11287 "delete ext_array[3];"
11082 "ext_array[3];"); 11288 "ext_array[3];");
11083 CHECK_EQ(33, result->Int32Value()); 11289 CHECK_EQ(33, result->Int32Value());
11084 11290
11085 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" 11291 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
11196 11402
11197 11403
11198 THREADED_TEST(ExternalUnsignedByteArray) { 11404 THREADED_TEST(ExternalUnsignedByteArray) {
11199 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>( 11405 ExternalArrayTestHelper<i::ExternalUnsignedByteArray, uint8_t>(
11200 v8::kExternalUnsignedByteArray, 11406 v8::kExternalUnsignedByteArray,
11201 0, 11407 0,
11202 255); 11408 255);
11203 } 11409 }
11204 11410
11205 11411
11412 THREADED_TEST(ExternalPixelArray) {
11413 ExternalArrayTestHelper<i::ExternalPixelArray, uint8_t>(
11414 v8::kExternalPixelArray,
11415 0,
11416 255);
11417 }
11418
11419
11206 THREADED_TEST(ExternalShortArray) { 11420 THREADED_TEST(ExternalShortArray) {
11207 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>( 11421 ExternalArrayTestHelper<i::ExternalShortArray, int16_t>(
11208 v8::kExternalShortArray, 11422 v8::kExternalShortArray,
11209 -32768, 11423 -32768,
11210 32767); 11424 32767);
11211 } 11425 }
11212 11426
11213 11427
11214 THREADED_TEST(ExternalUnsignedShortArray) { 11428 THREADED_TEST(ExternalUnsignedShortArray) {
11215 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>( 11429 ExternalArrayTestHelper<i::ExternalUnsignedShortArray, uint16_t>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
11273 11487
11274 11488
11275 THREADED_TEST(ExternalArrayInfo) { 11489 THREADED_TEST(ExternalArrayInfo) {
11276 ExternalArrayInfoTestHelper(v8::kExternalByteArray); 11490 ExternalArrayInfoTestHelper(v8::kExternalByteArray);
11277 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray); 11491 ExternalArrayInfoTestHelper(v8::kExternalUnsignedByteArray);
11278 ExternalArrayInfoTestHelper(v8::kExternalShortArray); 11492 ExternalArrayInfoTestHelper(v8::kExternalShortArray);
11279 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray); 11493 ExternalArrayInfoTestHelper(v8::kExternalUnsignedShortArray);
11280 ExternalArrayInfoTestHelper(v8::kExternalIntArray); 11494 ExternalArrayInfoTestHelper(v8::kExternalIntArray);
11281 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray); 11495 ExternalArrayInfoTestHelper(v8::kExternalUnsignedIntArray);
11282 ExternalArrayInfoTestHelper(v8::kExternalFloatArray); 11496 ExternalArrayInfoTestHelper(v8::kExternalFloatArray);
11497 ExternalArrayInfoTestHelper(v8::kExternalPixelArray);
11283 } 11498 }
11284 11499
11285 11500
11286 THREADED_TEST(ScriptContextDependence) { 11501 THREADED_TEST(ScriptContextDependence) {
11287 v8::HandleScope scope; 11502 v8::HandleScope scope;
11288 LocalContext c1; 11503 LocalContext c1;
11289 const char *source = "foo"; 11504 const char *source = "foo";
11290 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source)); 11505 v8::Handle<v8::Script> dep = v8::Script::Compile(v8::String::New(source));
11291 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source)); 11506 v8::Handle<v8::Script> indep = v8::Script::New(v8::String::New(source));
11292 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100)); 11507 c1->Global()->Set(v8::String::New("foo"), v8::Integer::New(100));
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after
12713 v8::Handle<v8::Function> define_property = 12928 v8::Handle<v8::Function> define_property =
12714 CompileRun("(function() {" 12929 CompileRun("(function() {"
12715 " Object.defineProperty(" 12930 " Object.defineProperty("
12716 " this," 12931 " this,"
12717 " 1," 12932 " 1,"
12718 " { configurable: true, enumerable: true, value: 3 });" 12933 " { configurable: true, enumerable: true, value: 3 });"
12719 "})").As<Function>(); 12934 "})").As<Function>();
12720 context->DetachGlobal(); 12935 context->DetachGlobal();
12721 define_property->Call(proxy, 0, NULL); 12936 define_property->Call(proxy, 0, NULL);
12722 } 12937 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-assembler-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698