| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 4809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4820 "x = makestr(31415);" | 4820 "x = makestr(31415);" |
| 4821 "x = makestr(23456);"); | 4821 "x = makestr(23456);"); |
| 4822 v8::Handle<Value> value = CompileRun( | 4822 v8::Handle<Value> value = CompileRun( |
| 4823 "var o = new constructor();" | 4823 "var o = new constructor();" |
| 4824 "o.__proto__ = new String(x);" | 4824 "o.__proto__ = new String(x);" |
| 4825 "o.hasOwnProperty('ostehaps');"); | 4825 "o.hasOwnProperty('ostehaps');"); |
| 4826 CHECK_EQ(false, value->BooleanValue()); | 4826 CHECK_EQ(false, value->BooleanValue()); |
| 4827 } | 4827 } |
| 4828 | 4828 |
| 4829 | 4829 |
| 4830 typedef v8::Handle<Value> (*NamedPropertyGetter)(Local<String> property, |
| 4831 const AccessorInfo& info); |
| 4832 |
| 4833 |
| 4834 static void CheckInterceptorLoadIC(NamedPropertyGetter getter, |
| 4835 const char* source, |
| 4836 int expected) { |
| 4837 v8::HandleScope scope; |
| 4838 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); |
| 4839 templ->SetNamedPropertyHandler(getter); |
| 4840 LocalContext context; |
| 4841 context->Global()->Set(v8_str("o"), templ->NewInstance()); |
| 4842 v8::Handle<Value> value = CompileRun(source); |
| 4843 CHECK_EQ(expected, value->Int32Value()); |
| 4844 } |
| 4845 |
| 4846 |
| 4830 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, | 4847 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, |
| 4831 const AccessorInfo& info) { | 4848 const AccessorInfo& info) { |
| 4832 ApiTestFuzzer::Fuzz(); | 4849 ApiTestFuzzer::Fuzz(); |
| 4833 CHECK(v8_str("x")->Equals(name)); | 4850 CHECK(v8_str("x")->Equals(name)); |
| 4834 return v8::Integer::New(42); | 4851 return v8::Integer::New(42); |
| 4835 } | 4852 } |
| 4836 | 4853 |
| 4837 | 4854 |
| 4838 // This test should hit the load IC for the interceptor case. | 4855 // This test should hit the load IC for the interceptor case. |
| 4839 THREADED_TEST(InterceptorLoadIC) { | 4856 THREADED_TEST(InterceptorLoadIC) { |
| 4840 v8::HandleScope scope; | 4857 CheckInterceptorLoadIC(InterceptorLoadICGetter, |
| 4841 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | |
| 4842 templ->SetNamedPropertyHandler(InterceptorLoadICGetter); | |
| 4843 LocalContext context; | |
| 4844 context->Global()->Set(v8_str("o"), templ->NewInstance()); | |
| 4845 v8::Handle<Value> value = CompileRun( | |
| 4846 "var result = 0;" | 4858 "var result = 0;" |
| 4847 "for (var i = 0; i < 1000; i++) {" | 4859 "for (var i = 0; i < 1000; i++) {" |
| 4848 " result = o.x;" | 4860 " result = o.x;" |
| 4849 "}"); | 4861 "}", |
| 4850 CHECK_EQ(42, value->Int32Value()); | 4862 42); |
| 4851 } | 4863 } |
| 4852 | 4864 |
| 4853 | 4865 |
| 4854 // Below go several tests which verify that JITing for various | 4866 // Below go several tests which verify that JITing for various |
| 4855 // configurations of interceptor and explicit fields works fine | 4867 // configurations of interceptor and explicit fields works fine |
| 4856 // (those cases are special cased to get better performance). | 4868 // (those cases are special cased to get better performance). |
| 4857 | 4869 |
| 4858 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, | 4870 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, |
| 4859 const AccessorInfo& info) { | 4871 const AccessorInfo& info) { |
| 4860 ApiTestFuzzer::Fuzz(); | 4872 ApiTestFuzzer::Fuzz(); |
| 4861 return v8_str("x")->Equals(name) | 4873 return v8_str("x")->Equals(name) |
| 4862 ? v8::Integer::New(42) : v8::Handle<v8::Value>(); | 4874 ? v8::Integer::New(42) : v8::Handle<v8::Value>(); |
| 4863 } | 4875 } |
| 4864 | 4876 |
| 4865 | 4877 |
| 4866 static void CheckInterceptorLoadIC(const char* source, int expected) { | |
| 4867 v8::HandleScope scope; | |
| 4868 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(); | |
| 4869 templ->SetNamedPropertyHandler(InterceptorLoadXICGetter); | |
| 4870 LocalContext context; | |
| 4871 context->Global()->Set(v8_str("o"), templ->NewInstance()); | |
| 4872 v8::Handle<Value> value = CompileRun(source); | |
| 4873 CHECK_EQ(expected, value->Int32Value()); | |
| 4874 } | |
| 4875 | |
| 4876 | |
| 4877 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | 4878 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { |
| 4878 CheckInterceptorLoadIC( | 4879 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 4879 "var result = 0;" | 4880 "var result = 0;" |
| 4880 "o.y = 239;" | 4881 "o.y = 239;" |
| 4881 "for (var i = 0; i < 1000; i++) {" | 4882 "for (var i = 0; i < 1000; i++) {" |
| 4882 " result = o.y;" | 4883 " result = o.y;" |
| 4883 "}", | 4884 "}", |
| 4884 239); | 4885 239); |
| 4885 } | 4886 } |
| 4886 | 4887 |
| 4887 | 4888 |
| 4888 THREADED_TEST(InterceptorLoadICWithSubstitutedProto) { | 4889 THREADED_TEST(InterceptorLoadICWithSubstitutedProto) { |
| 4889 CheckInterceptorLoadIC( | 4890 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 4890 "var result = 0;" | 4891 "var result = 0;" |
| 4891 "o.__proto__ = { 'y': 239 };" | 4892 "o.__proto__ = { 'y': 239 };" |
| 4892 "for (var i = 0; i < 1000; i++) {" | 4893 "for (var i = 0; i < 1000; i++) {" |
| 4893 " result = o.y + o.x;" | 4894 " result = o.y + o.x;" |
| 4894 "}", | 4895 "}", |
| 4895 239 + 42); | 4896 239 + 42); |
| 4896 } | 4897 } |
| 4897 | 4898 |
| 4898 | 4899 |
| 4899 THREADED_TEST(InterceptorLoadICWithPropertyOnProto) { | 4900 THREADED_TEST(InterceptorLoadICWithPropertyOnProto) { |
| 4900 CheckInterceptorLoadIC( | 4901 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 4901 "var result = 0;" | 4902 "var result = 0;" |
| 4902 "o.__proto__.y = 239;" | 4903 "o.__proto__.y = 239;" |
| 4903 "for (var i = 0; i < 1000; i++) {" | 4904 "for (var i = 0; i < 1000; i++) {" |
| 4904 " result = o.y + o.x;" | 4905 " result = o.y + o.x;" |
| 4905 "}", | 4906 "}", |
| 4906 239 + 42); | 4907 239 + 42); |
| 4907 } | 4908 } |
| 4908 | 4909 |
| 4909 | 4910 |
| 4910 THREADED_TEST(InterceptorLoadICUndefined) { | 4911 THREADED_TEST(InterceptorLoadICUndefined) { |
| 4911 CheckInterceptorLoadIC( | 4912 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 4912 "var result = 0;" | 4913 "var result = 0;" |
| 4913 "for (var i = 0; i < 1000; i++) {" | 4914 "for (var i = 0; i < 1000; i++) {" |
| 4914 " result = (o.y == undefined) ? 239 : 42;" | 4915 " result = (o.y == undefined) ? 239 : 42;" |
| 4915 "}", | 4916 "}", |
| 4916 239); | 4917 239); |
| 4917 } | 4918 } |
| 4918 | 4919 |
| 4919 | 4920 |
| 4920 THREADED_TEST(InterceptorLoadICWithOverride) { | 4921 THREADED_TEST(InterceptorLoadICWithOverride) { |
| 4921 CheckInterceptorLoadIC( | 4922 CheckInterceptorLoadIC(InterceptorLoadXICGetter, |
| 4922 "fst = new Object(); fst.__proto__ = o;" | 4923 "fst = new Object(); fst.__proto__ = o;" |
| 4923 "snd = new Object(); snd.__proto__ = fst;" | 4924 "snd = new Object(); snd.__proto__ = fst;" |
| 4924 "var result1 = 0;" | 4925 "var result1 = 0;" |
| 4925 "for (var i = 0; i < 1000; i++) {" | 4926 "for (var i = 0; i < 1000; i++) {" |
| 4926 " result1 = snd.x;" | 4927 " result1 = snd.x;" |
| 4927 "}" | 4928 "}" |
| 4928 "fst.x = 239;" | 4929 "fst.x = 239;" |
| 4929 "var result = 0;" | 4930 "var result = 0;" |
| 4930 "for (var i = 0; i < 1000; i++) {" | 4931 "for (var i = 0; i < 1000; i++) {" |
| 4931 " result = snd.x;" | 4932 " result = snd.x;" |
| 4932 "}" | 4933 "}" |
| 4933 "result + result1", | 4934 "result + result1", |
| 4934 239 + 42); | 4935 239 + 42); |
| 4935 } | 4936 } |
| 4936 | 4937 |
| 4937 | 4938 |
| 4939 static v8::Handle<Value> InterceptorLoadICGetter0(Local<String> name, |
| 4940 const AccessorInfo& info) { |
| 4941 ApiTestFuzzer::Fuzz(); |
| 4942 CHECK(v8_str("x")->Equals(name)); |
| 4943 return v8::Integer::New(0); |
| 4944 } |
| 4945 |
| 4946 |
| 4947 THREADED_TEST(InterceptorReturningZero) { |
| 4948 CheckInterceptorLoadIC(InterceptorLoadICGetter0, |
| 4949 "o.x == undefined ? 1 : 0", |
| 4950 0); |
| 4951 } |
| 4952 |
| 4953 |
| 4938 static v8::Handle<Value> InterceptorStoreICSetter( | 4954 static v8::Handle<Value> InterceptorStoreICSetter( |
| 4939 Local<String> key, Local<Value> value, const AccessorInfo&) { | 4955 Local<String> key, Local<Value> value, const AccessorInfo&) { |
| 4940 CHECK(v8_str("x")->Equals(key)); | 4956 CHECK(v8_str("x")->Equals(key)); |
| 4941 CHECK_EQ(42, value->Int32Value()); | 4957 CHECK_EQ(42, value->Int32Value()); |
| 4942 return value; | 4958 return value; |
| 4943 } | 4959 } |
| 4944 | 4960 |
| 4945 | 4961 |
| 4946 // This test should hit the store IC for the interceptor case. | 4962 // This test should hit the store IC for the interceptor case. |
| 4947 THREADED_TEST(InterceptorStoreIC) { | 4963 THREADED_TEST(InterceptorStoreIC) { |
| (...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6762 calling_context2->Exit(); | 6778 calling_context2->Exit(); |
| 6763 | 6779 |
| 6764 // Dispose the contexts to allow them to be garbage collected. | 6780 // Dispose the contexts to allow them to be garbage collected. |
| 6765 calling_context0.Dispose(); | 6781 calling_context0.Dispose(); |
| 6766 calling_context1.Dispose(); | 6782 calling_context1.Dispose(); |
| 6767 calling_context2.Dispose(); | 6783 calling_context2.Dispose(); |
| 6768 calling_context0.Clear(); | 6784 calling_context0.Clear(); |
| 6769 calling_context1.Clear(); | 6785 calling_context1.Clear(); |
| 6770 calling_context2.Clear(); | 6786 calling_context2.Clear(); |
| 6771 } | 6787 } |
| OLD | NEW |