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 | |
4847 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, | 4830 static v8::Handle<Value> InterceptorLoadICGetter(Local<String> name, |
4848 const AccessorInfo& info) { | 4831 const AccessorInfo& info) { |
4849 ApiTestFuzzer::Fuzz(); | 4832 ApiTestFuzzer::Fuzz(); |
4850 CHECK(v8_str("x")->Equals(name)); | 4833 CHECK(v8_str("x")->Equals(name)); |
4851 return v8::Integer::New(42); | 4834 return v8::Integer::New(42); |
4852 } | 4835 } |
4853 | 4836 |
4854 | 4837 |
4855 // This test should hit the load IC for the interceptor case. | 4838 // This test should hit the load IC for the interceptor case. |
4856 THREADED_TEST(InterceptorLoadIC) { | 4839 THREADED_TEST(InterceptorLoadIC) { |
4857 CheckInterceptorLoadIC(InterceptorLoadICGetter, | 4840 v8::HandleScope scope; |
| 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( |
4858 "var result = 0;" | 4846 "var result = 0;" |
4859 "for (var i = 0; i < 1000; i++) {" | 4847 "for (var i = 0; i < 1000; i++) {" |
4860 " result = o.x;" | 4848 " result = o.x;" |
4861 "}", | 4849 "}"); |
4862 42); | 4850 CHECK_EQ(42, value->Int32Value()); |
4863 } | |
4864 | |
4865 | |
4866 // Below go several tests which verify that JITing for various | |
4867 // configurations of interceptor and explicit fields works fine | |
4868 // (those cases are special cased to get better performance). | |
4869 | |
4870 static v8::Handle<Value> InterceptorLoadXICGetter(Local<String> name, | |
4871 const AccessorInfo& info) { | |
4872 ApiTestFuzzer::Fuzz(); | |
4873 return v8_str("x")->Equals(name) | |
4874 ? v8::Integer::New(42) : v8::Handle<v8::Value>(); | |
4875 } | |
4876 | |
4877 | |
4878 THREADED_TEST(InterceptorLoadICWithFieldOnHolder) { | |
4879 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | |
4880 "var result = 0;" | |
4881 "o.y = 239;" | |
4882 "for (var i = 0; i < 1000; i++) {" | |
4883 " result = o.y;" | |
4884 "}", | |
4885 239); | |
4886 } | |
4887 | |
4888 | |
4889 THREADED_TEST(InterceptorLoadICWithSubstitutedProto) { | |
4890 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | |
4891 "var result = 0;" | |
4892 "o.__proto__ = { 'y': 239 };" | |
4893 "for (var i = 0; i < 1000; i++) {" | |
4894 " result = o.y + o.x;" | |
4895 "}", | |
4896 239 + 42); | |
4897 } | |
4898 | |
4899 | |
4900 THREADED_TEST(InterceptorLoadICWithPropertyOnProto) { | |
4901 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | |
4902 "var result = 0;" | |
4903 "o.__proto__.y = 239;" | |
4904 "for (var i = 0; i < 1000; i++) {" | |
4905 " result = o.y + o.x;" | |
4906 "}", | |
4907 239 + 42); | |
4908 } | |
4909 | |
4910 | |
4911 THREADED_TEST(InterceptorLoadICUndefined) { | |
4912 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | |
4913 "var result = 0;" | |
4914 "for (var i = 0; i < 1000; i++) {" | |
4915 " result = (o.y == undefined) ? 239 : 42;" | |
4916 "}", | |
4917 239); | |
4918 } | |
4919 | |
4920 | |
4921 THREADED_TEST(InterceptorLoadICWithOverride) { | |
4922 CheckInterceptorLoadIC(InterceptorLoadXICGetter, | |
4923 "fst = new Object(); fst.__proto__ = o;" | |
4924 "snd = new Object(); snd.__proto__ = fst;" | |
4925 "var result1 = 0;" | |
4926 "for (var i = 0; i < 1000; i++) {" | |
4927 " result1 = snd.x;" | |
4928 "}" | |
4929 "fst.x = 239;" | |
4930 "var result = 0;" | |
4931 "for (var i = 0; i < 1000; i++) {" | |
4932 " result = snd.x;" | |
4933 "}" | |
4934 "result + result1", | |
4935 239 + 42); | |
4936 } | |
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 } | 4851 } |
4952 | 4852 |
4953 | 4853 |
4954 static v8::Handle<Value> InterceptorStoreICSetter( | 4854 static v8::Handle<Value> InterceptorStoreICSetter( |
4955 Local<String> key, Local<Value> value, const AccessorInfo&) { | 4855 Local<String> key, Local<Value> value, const AccessorInfo&) { |
4956 CHECK(v8_str("x")->Equals(key)); | 4856 CHECK(v8_str("x")->Equals(key)); |
4957 CHECK_EQ(42, value->Int32Value()); | 4857 CHECK_EQ(42, value->Int32Value()); |
4958 return value; | 4858 return value; |
4959 } | 4859 } |
4960 | 4860 |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6778 calling_context2->Exit(); | 6678 calling_context2->Exit(); |
6779 | 6679 |
6780 // Dispose the contexts to allow them to be garbage collected. | 6680 // Dispose the contexts to allow them to be garbage collected. |
6781 calling_context0.Dispose(); | 6681 calling_context0.Dispose(); |
6782 calling_context1.Dispose(); | 6682 calling_context1.Dispose(); |
6783 calling_context2.Dispose(); | 6683 calling_context2.Dispose(); |
6784 calling_context0.Clear(); | 6684 calling_context0.Clear(); |
6785 calling_context1.Clear(); | 6685 calling_context1.Clear(); |
6786 calling_context2.Clear(); | 6686 calling_context2.Clear(); |
6787 } | 6687 } |
OLD | NEW |