| OLD | NEW |
| 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 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 // the random number generator should be evaluated. | 1641 // the random number generator should be evaluated. |
| 1642 CHECK_NE(hash, hash2); | 1642 CHECK_NE(hash, hash2); |
| 1643 HEAP->CollectAllGarbage(false); | 1643 HEAP->CollectAllGarbage(false); |
| 1644 int hash3 = v8::Object::New()->GetIdentityHash(); | 1644 int hash3 = v8::Object::New()->GetIdentityHash(); |
| 1645 // Make sure that the identity hash is not based on the initial address of | 1645 // Make sure that the identity hash is not based on the initial address of |
| 1646 // the object alone. If the test below fails the random number generator | 1646 // the object alone. If the test below fails the random number generator |
| 1647 // should be evaluated. | 1647 // should be evaluated. |
| 1648 CHECK_NE(hash, hash3); | 1648 CHECK_NE(hash, hash3); |
| 1649 int hash4 = obj->GetIdentityHash(); | 1649 int hash4 = obj->GetIdentityHash(); |
| 1650 CHECK_EQ(hash, hash4); | 1650 CHECK_EQ(hash, hash4); |
| 1651 |
| 1652 // Check identity hashes behaviour in the presence of JS accessors. |
| 1653 // Put a getter for 'v8::IdentityHash' on the Object's prototype: |
| 1654 { |
| 1655 CompileRun("Object.prototype['v8::IdentityHash'] = 42;\n"); |
| 1656 Local<v8::Object> o1 = v8::Object::New(); |
| 1657 Local<v8::Object> o2 = v8::Object::New(); |
| 1658 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); |
| 1659 } |
| 1660 { |
| 1661 CompileRun( |
| 1662 "function cnst() { return 42; };\n" |
| 1663 "Object.prototype.__defineGetter__('v8::IdentityHash', cnst);\n"); |
| 1664 Local<v8::Object> o1 = v8::Object::New(); |
| 1665 Local<v8::Object> o2 = v8::Object::New(); |
| 1666 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); |
| 1667 } |
| 1651 } | 1668 } |
| 1652 | 1669 |
| 1653 | 1670 |
| 1654 THREADED_TEST(HiddenProperties) { | 1671 THREADED_TEST(HiddenProperties) { |
| 1655 v8::HandleScope scope; | 1672 v8::HandleScope scope; |
| 1656 LocalContext env; | 1673 LocalContext env; |
| 1657 | 1674 |
| 1658 v8::Local<v8::Object> obj = v8::Object::New(); | 1675 v8::Local<v8::Object> obj = v8::Object::New(); |
| 1659 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); | 1676 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); |
| 1660 v8::Local<v8::String> empty = v8_str(""); | 1677 v8::Local<v8::String> empty = v8_str(""); |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2666 THREADED_TEST(CatchExceptionFromWith) { | 2683 THREADED_TEST(CatchExceptionFromWith) { |
| 2667 v8::HandleScope scope; | 2684 v8::HandleScope scope; |
| 2668 LocalContext context; | 2685 LocalContext context; |
| 2669 v8::TryCatch try_catch; | 2686 v8::TryCatch try_catch; |
| 2670 CHECK(!try_catch.HasCaught()); | 2687 CHECK(!try_catch.HasCaught()); |
| 2671 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); | 2688 Script::Compile(v8_str("var o = {}; with (o) { throw 42; }"))->Run(); |
| 2672 CHECK(try_catch.HasCaught()); | 2689 CHECK(try_catch.HasCaught()); |
| 2673 } | 2690 } |
| 2674 | 2691 |
| 2675 | 2692 |
| 2693 THREADED_TEST(TryCatchAndFinallyHidingException) { |
| 2694 v8::HandleScope scope; |
| 2695 LocalContext context; |
| 2696 v8::TryCatch try_catch; |
| 2697 CHECK(!try_catch.HasCaught()); |
| 2698 CompileRun("function f(k) { try { this[k]; } finally { return 0; } };"); |
| 2699 CompileRun("f({toString: function() { throw 42; }});"); |
| 2700 CHECK(!try_catch.HasCaught()); |
| 2701 } |
| 2702 |
| 2703 |
| 2704 v8::Handle<v8::Value> WithTryCatch(const v8::Arguments& args) { |
| 2705 v8::TryCatch try_catch; |
| 2706 return v8::Undefined(); |
| 2707 } |
| 2708 |
| 2709 |
| 2710 THREADED_TEST(TryCatchAndFinally) { |
| 2711 v8::HandleScope scope; |
| 2712 LocalContext context; |
| 2713 context->Global()->Set( |
| 2714 v8_str("native_with_try_catch"), |
| 2715 v8::FunctionTemplate::New(WithTryCatch)->GetFunction()); |
| 2716 v8::TryCatch try_catch; |
| 2717 CHECK(!try_catch.HasCaught()); |
| 2718 CompileRun( |
| 2719 "try {\n" |
| 2720 " throw new Error('a');\n" |
| 2721 "} finally {\n" |
| 2722 " native_with_try_catch();\n" |
| 2723 "}\n"); |
| 2724 CHECK(try_catch.HasCaught()); |
| 2725 } |
| 2726 |
| 2727 |
| 2676 THREADED_TEST(Equality) { | 2728 THREADED_TEST(Equality) { |
| 2677 v8::HandleScope scope; | 2729 v8::HandleScope scope; |
| 2678 LocalContext context; | 2730 LocalContext context; |
| 2679 // Check that equality works at all before relying on CHECK_EQ | 2731 // Check that equality works at all before relying on CHECK_EQ |
| 2680 CHECK(v8_str("a")->Equals(v8_str("a"))); | 2732 CHECK(v8_str("a")->Equals(v8_str("a"))); |
| 2681 CHECK(!v8_str("a")->Equals(v8_str("b"))); | 2733 CHECK(!v8_str("a")->Equals(v8_str("b"))); |
| 2682 | 2734 |
| 2683 CHECK_EQ(v8_str("a"), v8_str("a")); | 2735 CHECK_EQ(v8_str("a"), v8_str("a")); |
| 2684 CHECK_NE(v8_str("a"), v8_str("b")); | 2736 CHECK_NE(v8_str("a"), v8_str("b")); |
| 2685 CHECK_EQ(v8_num(1), v8_num(1)); | 2737 CHECK_EQ(v8_num(1), v8_num(1)); |
| (...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5592 "return true;})()"); | 5644 "return true;})()"); |
| 5593 CHECK(value->IsTrue()); | 5645 CHECK(value->IsTrue()); |
| 5594 | 5646 |
| 5595 context1->Exit(); | 5647 context1->Exit(); |
| 5596 context0->Exit(); | 5648 context0->Exit(); |
| 5597 context1.Dispose(); | 5649 context1.Dispose(); |
| 5598 context0.Dispose(); | 5650 context0.Dispose(); |
| 5599 } | 5651 } |
| 5600 | 5652 |
| 5601 | 5653 |
| 5654 TEST(AccessControlES5) { |
| 5655 v8::HandleScope handle_scope; |
| 5656 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); |
| 5657 |
| 5658 global_template->SetAccessCheckCallbacks(NamedAccessBlocker, |
| 5659 IndexedAccessBlocker); |
| 5660 |
| 5661 // Add an accessor that is not accessible by cross-domain JS code. |
| 5662 global_template->SetAccessor(v8_str("blocked_prop"), |
| 5663 UnreachableGetter, UnreachableSetter, |
| 5664 v8::Handle<Value>(), |
| 5665 v8::DEFAULT); |
| 5666 |
| 5667 // Create an environment |
| 5668 v8::Persistent<Context> context0 = Context::New(NULL, global_template); |
| 5669 context0->Enter(); |
| 5670 |
| 5671 v8::Handle<v8::Object> global0 = context0->Global(); |
| 5672 |
| 5673 v8::Persistent<Context> context1 = Context::New(); |
| 5674 context1->Enter(); |
| 5675 v8::Handle<v8::Object> global1 = context1->Global(); |
| 5676 global1->Set(v8_str("other"), global0); |
| 5677 |
| 5678 // Regression test for issue 1154. |
| 5679 ExpectTrue("Object.keys(other).indexOf('blocked_prop') == -1"); |
| 5680 |
| 5681 ExpectUndefined("other.blocked_prop"); |
| 5682 |
| 5683 // Regression test for issue 1027. |
| 5684 CompileRun("Object.defineProperty(\n" |
| 5685 " other, 'blocked_prop', {configurable: false})"); |
| 5686 ExpectUndefined("other.blocked_prop"); |
| 5687 ExpectUndefined( |
| 5688 "Object.getOwnPropertyDescriptor(other, 'blocked_prop')"); |
| 5689 |
| 5690 // Regression test for issue 1171. |
| 5691 ExpectTrue("Object.isExtensible(other)"); |
| 5692 CompileRun("Object.preventExtensions(other)"); |
| 5693 ExpectTrue("Object.isExtensible(other)"); |
| 5694 |
| 5695 // Object.seal and Object.freeze. |
| 5696 CompileRun("Object.freeze(other)"); |
| 5697 ExpectTrue("Object.isExtensible(other)"); |
| 5698 |
| 5699 CompileRun("Object.seal(other)"); |
| 5700 ExpectTrue("Object.isExtensible(other)"); |
| 5701 } |
| 5702 |
| 5703 |
| 5602 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, | 5704 static bool GetOwnPropertyNamesNamedBlocker(Local<v8::Object> global, |
| 5603 Local<Value> name, | 5705 Local<Value> name, |
| 5604 v8::AccessType type, | 5706 v8::AccessType type, |
| 5605 Local<Value> data) { | 5707 Local<Value> data) { |
| 5606 return false; | 5708 return false; |
| 5607 } | 5709 } |
| 5608 | 5710 |
| 5609 | 5711 |
| 5610 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, | 5712 static bool GetOwnPropertyNamesIndexedBlocker(Local<v8::Object> global, |
| 5611 uint32_t key, | 5713 uint32_t key, |
| (...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7517 // Helper to maximize the odds of object moving. | 7619 // Helper to maximize the odds of object moving. |
| 7518 static void GenerateSomeGarbage() { | 7620 static void GenerateSomeGarbage() { |
| 7519 CompileRun( | 7621 CompileRun( |
| 7520 "var garbage;" | 7622 "var garbage;" |
| 7521 "for (var i = 0; i < 1000; i++) {" | 7623 "for (var i = 0; i < 1000; i++) {" |
| 7522 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 7624 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
| 7523 "}" | 7625 "}" |
| 7524 "garbage = undefined;"); | 7626 "garbage = undefined;"); |
| 7525 } | 7627 } |
| 7526 | 7628 |
| 7629 |
| 7527 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { | 7630 v8::Handle<v8::Value> DirectApiCallback(const v8::Arguments& args) { |
| 7528 static int count = 0; | 7631 static int count = 0; |
| 7529 if (count++ % 3 == 0) { | 7632 if (count++ % 3 == 0) { |
| 7530 v8::V8::LowMemoryNotification(); // This should move the stub | 7633 HEAP-> CollectAllGarbage(true); // This should move the stub |
| 7531 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed | 7634 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
| 7532 } | 7635 } |
| 7533 return v8::Handle<v8::Value>(); | 7636 return v8::Handle<v8::Value>(); |
| 7534 } | 7637 } |
| 7535 | 7638 |
| 7536 | 7639 |
| 7537 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { | 7640 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
| 7538 v8::HandleScope scope; | 7641 v8::HandleScope scope; |
| 7539 LocalContext context; | 7642 LocalContext context; |
| 7540 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); | 7643 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7572 "function f() {" | 7675 "function f() {" |
| 7573 " for (var i = 1; i <= 5; i++) {" | 7676 " for (var i = 1; i <= 5; i++) {" |
| 7574 " try { nativeobject.callback(); } catch (e) { result += e; }" | 7677 " try { nativeobject.callback(); } catch (e) { result += e; }" |
| 7575 " }" | 7678 " }" |
| 7576 "}" | 7679 "}" |
| 7577 "f(); result;"); | 7680 "f(); result;"); |
| 7578 CHECK_EQ(v8_str("ggggg"), result); | 7681 CHECK_EQ(v8_str("ggggg"), result); |
| 7579 } | 7682 } |
| 7580 | 7683 |
| 7581 | 7684 |
| 7685 v8::Handle<v8::Value> DirectGetterCallback(Local<String> name, |
| 7686 const v8::AccessorInfo& info) { |
| 7687 if (++p_getter_count % 3 == 0) { |
| 7688 HEAP->CollectAllGarbage(true); |
| 7689 GenerateSomeGarbage(); |
| 7690 } |
| 7691 return v8::Handle<v8::Value>(); |
| 7692 } |
| 7693 |
| 7694 |
| 7695 THREADED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { |
| 7696 v8::HandleScope scope; |
| 7697 LocalContext context; |
| 7698 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); |
| 7699 obj->SetAccessor(v8_str("p1"), DirectGetterCallback); |
| 7700 context->Global()->Set(v8_str("o1"), obj->NewInstance()); |
| 7701 p_getter_count = 0; |
| 7702 CompileRun( |
| 7703 "function f() {" |
| 7704 " for (var i = 0; i < 30; i++) o1.p1;" |
| 7705 "}" |
| 7706 "f();"); |
| 7707 CHECK_EQ(30, p_getter_count); |
| 7708 } |
| 7709 |
| 7710 |
| 7711 v8::Handle<v8::Value> ThrowingDirectGetterCallback( |
| 7712 Local<String> name, const v8::AccessorInfo& info) { |
| 7713 return v8::ThrowException(v8_str("g")); |
| 7714 } |
| 7715 |
| 7716 |
| 7717 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { |
| 7718 v8::HandleScope scope; |
| 7719 LocalContext context; |
| 7720 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(); |
| 7721 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); |
| 7722 context->Global()->Set(v8_str("o1"), obj->NewInstance()); |
| 7723 v8::Handle<Value> result = CompileRun( |
| 7724 "var result = '';" |
| 7725 "for (var i = 0; i < 5; i++) {" |
| 7726 " try { o1.p1; } catch (e) { result += e; }" |
| 7727 "}" |
| 7728 "result;"); |
| 7729 CHECK_EQ(v8_str("ggggg"), result); |
| 7730 } |
| 7731 |
| 7732 |
| 7582 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 7733 THREADED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
| 7583 int interceptor_call_count = 0; | 7734 int interceptor_call_count = 0; |
| 7584 v8::HandleScope scope; | 7735 v8::HandleScope scope; |
| 7585 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 7736 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); |
| 7586 v8::Handle<v8::FunctionTemplate> method_templ = | 7737 v8::Handle<v8::FunctionTemplate> method_templ = |
| 7587 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, | 7738 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, |
| 7588 v8_str("method_data"), | 7739 v8_str("method_data"), |
| 7589 v8::Handle<v8::Signature>()); | 7740 v8::Handle<v8::Signature>()); |
| 7590 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 7741 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
| 7591 proto_templ->Set(v8_str("method"), method_templ); | 7742 proto_templ->Set(v8_str("method"), method_templ); |
| (...skipping 2366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9958 } | 10109 } |
| 9959 two_byte_content_[14] = 'b'; | 10110 two_byte_content_[14] = 'b'; |
| 9960 | 10111 |
| 9961 // Create the input string for the regexp - the one we are going to change | 10112 // Create the input string for the regexp - the one we are going to change |
| 9962 // properties of. | 10113 // properties of. |
| 9963 input_ = FACTORY->NewExternalStringFromAscii(&ascii_resource_); | 10114 input_ = FACTORY->NewExternalStringFromAscii(&ascii_resource_); |
| 9964 | 10115 |
| 9965 // Inject the input as a global variable. | 10116 // Inject the input as a global variable. |
| 9966 i::Handle<i::String> input_name = | 10117 i::Handle<i::String> input_name = |
| 9967 FACTORY->NewStringFromAscii(i::Vector<const char>("input", 5)); | 10118 FACTORY->NewStringFromAscii(i::Vector<const char>("input", 5)); |
| 9968 i::Isolate::Current()->global_context()->global()-> | 10119 i::Isolate::Current()->global_context()->global()->SetProperty( |
| 9969 SetProperty(*input_name, *input_, NONE)->ToObjectChecked(); | 10120 *input_name, |
| 9970 | 10121 *input_, |
| 10122 NONE, |
| 10123 i::kNonStrictMode)->ToObjectChecked(); |
| 9971 | 10124 |
| 9972 MorphThread morph_thread(i::Isolate::Current(), this); | 10125 MorphThread morph_thread(i::Isolate::Current(), this); |
| 9973 morph_thread.Start(); | 10126 morph_thread.Start(); |
| 9974 v8::Locker::StartPreemption(1); | 10127 v8::Locker::StartPreemption(1); |
| 9975 LongRunningRegExp(); | 10128 LongRunningRegExp(); |
| 9976 { | 10129 { |
| 9977 v8::Unlocker unlock; | 10130 v8::Unlocker unlock; |
| 9978 morph_thread.Join(); | 10131 morph_thread.Join(); |
| 9979 } | 10132 } |
| 9980 v8::Locker::StopPreemption(); | 10133 v8::Locker::StopPreemption(); |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10692 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" | 10845 "for (var i = 0; i < 10; ++i) { pa_load(pixels); }" |
| 10693 "sparse_array = new Object();" | 10846 "sparse_array = new Object();" |
| 10694 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }" | 10847 "for (var i = 0; i < 256; ++i) { sparse_array[i] = i; }" |
| 10695 "sparse_array[1000000] = 3;" | 10848 "sparse_array[1000000] = 3;" |
| 10696 "for (var i = 0; i < 10; ++i) {" | 10849 "for (var i = 0; i < 10; ++i) {" |
| 10697 " result = pa_load(sparse_array);" | 10850 " result = pa_load(sparse_array);" |
| 10698 "}" | 10851 "}" |
| 10699 "result"); | 10852 "result"); |
| 10700 CHECK_EQ(32640, result->Int32Value()); | 10853 CHECK_EQ(32640, result->Int32Value()); |
| 10701 | 10854 |
| 10855 // Make sure that pixel array store ICs clamp values correctly. |
| 10856 result = CompileRun("function pa_store(p) {" |
| 10857 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }" |
| 10858 "}" |
| 10859 "pa_store(pixels);" |
| 10860 "var sum = 0;" |
| 10861 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" |
| 10862 "sum"); |
| 10863 CHECK_EQ(48896, result->Int32Value()); |
| 10864 |
| 10865 // Make sure that pixel array stores correctly handle accesses outside |
| 10866 // of the pixel array.. |
| 10867 result = CompileRun("function pa_store(p,start) {" |
| 10868 " for (var j = 0; j < 256; j++) {" |
| 10869 " p[j+start] = j * 2;" |
| 10870 " }" |
| 10871 "}" |
| 10872 "pa_store(pixels,0);" |
| 10873 "pa_store(pixels,-128);" |
| 10874 "var sum = 0;" |
| 10875 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" |
| 10876 "sum"); |
| 10877 CHECK_EQ(65280, result->Int32Value()); |
| 10878 |
| 10879 // Make sure that the generic store stub correctly handle accesses outside |
| 10880 // of the pixel array.. |
| 10881 result = CompileRun("function pa_store(p,start) {" |
| 10882 " for (var j = 0; j < 256; j++) {" |
| 10883 " p[j+start] = j * 2;" |
| 10884 " }" |
| 10885 "}" |
| 10886 "pa_store(pixels,0);" |
| 10887 "just_ints = new Object();" |
| 10888 "for (var i = 0; i < 256; ++i) { just_ints[i] = i; }" |
| 10889 "pa_store(just_ints, 0);" |
| 10890 "pa_store(pixels,-128);" |
| 10891 "var sum = 0;" |
| 10892 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" |
| 10893 "sum"); |
| 10894 CHECK_EQ(65280, result->Int32Value()); |
| 10895 |
| 10896 // Make sure that the generic keyed store stub clamps pixel array values |
| 10897 // correctly. |
| 10898 result = CompileRun("function pa_store(p) {" |
| 10899 " for (var j = 0; j < 256; j++) { p[j] = j * 2; }" |
| 10900 "}" |
| 10901 "pa_store(pixels);" |
| 10902 "just_ints = new Object();" |
| 10903 "pa_store(just_ints);" |
| 10904 "pa_store(pixels);" |
| 10905 "var sum = 0;" |
| 10906 "for (var j = 0; j < 256; j++) { sum += pixels[j]; }" |
| 10907 "sum"); |
| 10908 CHECK_EQ(48896, result->Int32Value()); |
| 10909 |
| 10910 // Make sure that pixel array loads are optimized by crankshaft. |
| 10911 result = CompileRun("function pa_load(p) {" |
| 10912 " var sum = 0;" |
| 10913 " for (var i=0; i<256; ++i) {" |
| 10914 " sum += p[i];" |
| 10915 " }" |
| 10916 " return sum; " |
| 10917 "}" |
| 10918 "for (var i = 0; i < 256; ++i) { pixels[i] = i; }" |
| 10919 "for (var i = 0; i < 10000; ++i) {" |
| 10920 " result = pa_load(pixels);" |
| 10921 "}" |
| 10922 "result"); |
| 10923 CHECK_EQ(32640, result->Int32Value()); |
| 10924 |
| 10925 // Make sure that pixel array stores are optimized by crankshaft. |
| 10926 result = CompileRun("function pa_init(p) {" |
| 10927 "for (var i = 0; i < 256; ++i) { p[i] = i; }" |
| 10928 "}" |
| 10929 "function pa_load(p) {" |
| 10930 " var sum = 0;" |
| 10931 " for (var i=0; i<256; ++i) {" |
| 10932 " sum += p[i];" |
| 10933 " }" |
| 10934 " return sum; " |
| 10935 "}" |
| 10936 "for (var i = 0; i < 100000; ++i) {" |
| 10937 " pa_init(pixels);" |
| 10938 "}" |
| 10939 "result = pa_load(pixels);" |
| 10940 "result"); |
| 10941 CHECK_EQ(32640, result->Int32Value()); |
| 10942 |
| 10702 free(pixel_data); | 10943 free(pixel_data); |
| 10703 } | 10944 } |
| 10704 | 10945 |
| 10705 | 10946 |
| 10706 THREADED_TEST(PixelArrayInfo) { | 10947 THREADED_TEST(PixelArrayInfo) { |
| 10707 v8::HandleScope scope; | 10948 v8::HandleScope scope; |
| 10708 LocalContext context; | 10949 LocalContext context; |
| 10709 for (int size = 0; size < 100; size += 10) { | 10950 for (int size = 0; size < 100; size += 10) { |
| 10710 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); | 10951 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(size)); |
| 10711 v8::Handle<v8::Object> obj = v8::Object::New(); | 10952 v8::Handle<v8::Object> obj = v8::Object::New(); |
| 10712 obj->SetIndexedPropertiesToPixelData(pixel_data, size); | 10953 obj->SetIndexedPropertiesToPixelData(pixel_data, size); |
| 10713 CHECK(obj->HasIndexedPropertiesInPixelData()); | 10954 CHECK(obj->HasIndexedPropertiesInPixelData()); |
| 10714 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); | 10955 CHECK_EQ(pixel_data, obj->GetIndexedPropertiesPixelData()); |
| 10715 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); | 10956 CHECK_EQ(size, obj->GetIndexedPropertiesPixelDataLength()); |
| 10716 free(pixel_data); | 10957 free(pixel_data); |
| 10717 } | 10958 } |
| 10718 } | 10959 } |
| 10719 | 10960 |
| 10720 | 10961 |
| 10962 static v8::Handle<Value> NotHandledIndexedPropertyGetter( |
| 10963 uint32_t index, |
| 10964 const AccessorInfo& info) { |
| 10965 ApiTestFuzzer::Fuzz(); |
| 10966 return v8::Handle<Value>(); |
| 10967 } |
| 10968 |
| 10969 |
| 10970 static v8::Handle<Value> NotHandledIndexedPropertySetter( |
| 10971 uint32_t index, |
| 10972 Local<Value> value, |
| 10973 const AccessorInfo& info) { |
| 10974 ApiTestFuzzer::Fuzz(); |
| 10975 return v8::Handle<Value>(); |
| 10976 } |
| 10977 |
| 10978 |
| 10979 THREADED_TEST(PixelArrayWithInterceptor) { |
| 10980 v8::HandleScope scope; |
| 10981 LocalContext context; |
| 10982 const int kElementCount = 260; |
| 10983 uint8_t* pixel_data = reinterpret_cast<uint8_t*>(malloc(kElementCount)); |
| 10984 i::Handle<i::PixelArray> pixels = |
| 10985 FACTORY->NewPixelArray(kElementCount, 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 |
| 10721 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { | 11009 static int ExternalArrayElementSize(v8::ExternalArrayType array_type) { |
| 10722 switch (array_type) { | 11010 switch (array_type) { |
| 10723 case v8::kExternalByteArray: | 11011 case v8::kExternalByteArray: |
| 10724 case v8::kExternalUnsignedByteArray: | 11012 case v8::kExternalUnsignedByteArray: |
| 10725 return 1; | 11013 return 1; |
| 10726 break; | 11014 break; |
| 10727 case v8::kExternalShortArray: | 11015 case v8::kExternalShortArray: |
| 10728 case v8::kExternalUnsignedShortArray: | 11016 case v8::kExternalUnsignedShortArray: |
| 10729 return 2; | 11017 return 2; |
| 10730 break; | 11018 break; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11371 v8_str("origin"))->Run(); | 11659 v8_str("origin"))->Run(); |
| 11372 v8::Local<v8::Object> global = env->Global(); | 11660 v8::Local<v8::Object> global = env->Global(); |
| 11373 Local<Value> trouble = global->Get(v8_str("bar")); | 11661 Local<Value> trouble = global->Get(v8_str("bar")); |
| 11374 CHECK(trouble->IsFunction()); | 11662 CHECK(trouble->IsFunction()); |
| 11375 Function::Cast(*trouble)->Call(global, 0, NULL); | 11663 Function::Cast(*trouble)->Call(global, 0, NULL); |
| 11376 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 11664 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
| 11377 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); | 11665 v8::V8::RemoveMessageListeners(StackTraceForUncaughtExceptionListener); |
| 11378 } | 11666 } |
| 11379 | 11667 |
| 11380 | 11668 |
| 11669 TEST(CaptureStackTraceForUncaughtExceptionAndSetters) { |
| 11670 v8::HandleScope scope; |
| 11671 LocalContext env; |
| 11672 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, |
| 11673 1024, |
| 11674 v8::StackTrace::kDetailed); |
| 11675 |
| 11676 CompileRun( |
| 11677 "var setters = ['column', 'lineNumber', 'scriptName',\n" |
| 11678 " 'scriptNameOrSourceURL', 'functionName', 'isEval',\n" |
| 11679 " 'isConstructor'];\n" |
| 11680 "for (var i = 0; i < setters.length; i++) {\n" |
| 11681 " var prop = setters[i];\n" |
| 11682 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" |
| 11683 "}\n"); |
| 11684 CompileRun("throw 'exception';"); |
| 11685 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
| 11686 } |
| 11687 |
| 11688 |
| 11381 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { | 11689 v8::Handle<Value> AnalyzeStackOfEvalWithSourceURL(const v8::Arguments& args) { |
| 11382 v8::HandleScope scope; | 11690 v8::HandleScope scope; |
| 11383 v8::Handle<v8::StackTrace> stackTrace = | 11691 v8::Handle<v8::StackTrace> stackTrace = |
| 11384 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); | 11692 v8::StackTrace::CurrentStackTrace(10, v8::StackTrace::kDetailed); |
| 11385 CHECK_EQ(5, stackTrace->GetFrameCount()); | 11693 CHECK_EQ(5, stackTrace->GetFrameCount()); |
| 11386 v8::Handle<v8::String> url = v8_str("eval_url"); | 11694 v8::Handle<v8::String> url = v8_str("eval_url"); |
| 11387 for (int i = 0; i < 3; i++) { | 11695 for (int i = 0; i < 3; i++) { |
| 11388 v8::Handle<v8::String> name = | 11696 v8::Handle<v8::String> name = |
| 11389 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 11697 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
| 11390 CHECK(!name.IsEmpty()); | 11698 CHECK(!name.IsEmpty()); |
| (...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12820 | 13128 |
| 12821 v8::TryCatch try_catch; | 13129 v8::TryCatch try_catch; |
| 12822 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 13130 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
| 12823 CHECK(re.IsEmpty()); | 13131 CHECK(re.IsEmpty()); |
| 12824 CHECK(try_catch.HasCaught()); | 13132 CHECK(try_catch.HasCaught()); |
| 12825 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 13133 context->Global()->Set(v8_str("ex"), try_catch.Exception()); |
| 12826 ExpectTrue("ex instanceof SyntaxError"); | 13134 ExpectTrue("ex instanceof SyntaxError"); |
| 12827 } | 13135 } |
| 12828 | 13136 |
| 12829 | 13137 |
| 13138 THREADED_TEST(Equals) { |
| 13139 v8::HandleScope handleScope; |
| 13140 LocalContext localContext; |
| 13141 |
| 13142 v8::Handle<v8::Object> globalProxy = localContext->Global(); |
| 13143 v8::Handle<Value> global = globalProxy->GetPrototype(); |
| 13144 |
| 13145 CHECK(global->StrictEquals(global)); |
| 13146 CHECK(!global->StrictEquals(globalProxy)); |
| 13147 CHECK(!globalProxy->StrictEquals(global)); |
| 13148 CHECK(globalProxy->StrictEquals(globalProxy)); |
| 13149 |
| 13150 CHECK(global->Equals(global)); |
| 13151 CHECK(!global->Equals(globalProxy)); |
| 13152 CHECK(!globalProxy->Equals(global)); |
| 13153 CHECK(globalProxy->Equals(globalProxy)); |
| 13154 } |
| 13155 |
| 13156 |
| 12830 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, | 13157 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, |
| 12831 const v8::AccessorInfo& info ) { | 13158 const v8::AccessorInfo& info ) { |
| 12832 return v8_str("42!"); | 13159 return v8_str("42!"); |
| 12833 } | 13160 } |
| 12834 | 13161 |
| 12835 | 13162 |
| 12836 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { | 13163 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { |
| 12837 v8::Handle<v8::Array> result = v8::Array::New(); | 13164 v8::Handle<v8::Array> result = v8::Array::New(); |
| 12838 result->Set(0, v8_str("universalAnswer")); | 13165 result->Set(0, v8_str("universalAnswer")); |
| 12839 return result; | 13166 return result; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 12862 v8::Handle<v8::Function> define_property = | 13189 v8::Handle<v8::Function> define_property = |
| 12863 CompileRun("(function() {" | 13190 CompileRun("(function() {" |
| 12864 " Object.defineProperty(" | 13191 " Object.defineProperty(" |
| 12865 " this," | 13192 " this," |
| 12866 " 1," | 13193 " 1," |
| 12867 " { configurable: true, enumerable: true, value: 3 });" | 13194 " { configurable: true, enumerable: true, value: 3 });" |
| 12868 "})").As<Function>(); | 13195 "})").As<Function>(); |
| 12869 context->DetachGlobal(); | 13196 context->DetachGlobal(); |
| 12870 define_property->Call(proxy, 0, NULL); | 13197 define_property->Call(proxy, 0, NULL); |
| 12871 } | 13198 } |
| OLD | NEW |