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 14708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14719 env->Global()->Get(v8::String::New("foo"))); | 14719 env->Global()->Get(v8::String::New("foo"))); |
14720 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 14720 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( |
14721 env->Global()->Get(v8::String::New("bar"))); | 14721 env->Global()->Get(v8::String::New("bar"))); |
14722 CHECK_EQ(script->Id(), foo->GetScriptId()); | 14722 CHECK_EQ(script->Id(), foo->GetScriptId()); |
14723 CHECK_EQ(script->Id(), bar->GetScriptId()); | 14723 CHECK_EQ(script->Id(), bar->GetScriptId()); |
14724 } | 14724 } |
14725 | 14725 |
14726 | 14726 |
14727 static v8::Handle<Value> GetterWhichReturns42(Local<String> name, | 14727 static v8::Handle<Value> GetterWhichReturns42(Local<String> name, |
14728 const AccessorInfo& info) { | 14728 const AccessorInfo& info) { |
| 14729 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
| 14730 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
14729 return v8_num(42); | 14731 return v8_num(42); |
14730 } | 14732 } |
14731 | 14733 |
14732 | 14734 |
14733 static void SetterWhichSetsYOnThisTo23(Local<String> name, | 14735 static void SetterWhichSetsYOnThisTo23(Local<String> name, |
14734 Local<Value> value, | 14736 Local<Value> value, |
14735 const AccessorInfo& info) { | 14737 const AccessorInfo& info) { |
| 14738 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
| 14739 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
14736 info.This()->Set(v8_str("y"), v8_num(23)); | 14740 info.This()->Set(v8_str("y"), v8_num(23)); |
14737 } | 14741 } |
14738 | 14742 |
14739 | 14743 |
14740 Handle<Value> FooGetInterceptor(Local<String> name, | 14744 Handle<Value> FooGetInterceptor(Local<String> name, |
14741 const AccessorInfo& info) { | 14745 const AccessorInfo& info) { |
| 14746 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
| 14747 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
14742 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); | 14748 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); |
14743 return v8_num(42); | 14749 return v8_num(42); |
14744 } | 14750 } |
14745 | 14751 |
14746 | 14752 |
14747 Handle<Value> FooSetInterceptor(Local<String> name, | 14753 Handle<Value> FooSetInterceptor(Local<String> name, |
14748 Local<Value> value, | 14754 Local<Value> value, |
14749 const AccessorInfo& info) { | 14755 const AccessorInfo& info) { |
| 14756 CHECK(v8::Utils::OpenHandle(*info.This())->IsJSObject()); |
| 14757 CHECK(v8::Utils::OpenHandle(*info.Holder())->IsJSObject()); |
14750 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); | 14758 if (!name->Equals(v8_str("foo"))) return Handle<Value>(); |
14751 info.This()->Set(v8_str("y"), v8_num(23)); | 14759 info.This()->Set(v8_str("y"), v8_num(23)); |
14752 return v8_num(23); | 14760 return v8_num(23); |
14753 } | 14761 } |
14754 | 14762 |
14755 | 14763 |
14756 TEST(SetterOnConstructorPrototype) { | 14764 TEST(SetterOnConstructorPrototype) { |
14757 v8::HandleScope scope; | 14765 v8::HandleScope scope; |
14758 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 14766 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
14759 templ->SetAccessor(v8_str("x"), | 14767 templ->SetAccessor(v8_str("x"), |
(...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17061 CompileRun("function load(x) { return x.foo; }" | 17069 CompileRun("function load(x) { return x.foo; }" |
17062 "function store(x) { x.foo = void 0; }" | 17070 "function store(x) { x.foo = void 0; }" |
17063 "function keyed_load(x, key) { return x[key]; }" | 17071 "function keyed_load(x, key) { return x[key]; }" |
17064 // Second version of function has a different source (add void 0) | 17072 // Second version of function has a different source (add void 0) |
17065 // so that it does not share code with the first version. This | 17073 // so that it does not share code with the first version. This |
17066 // ensures that the ICs are monomorphic. | 17074 // ensures that the ICs are monomorphic. |
17067 "function load2(x) { void 0; return x.foo; }" | 17075 "function load2(x) { void 0; return x.foo; }" |
17068 "function store2(x) { void 0; x.foo = void 0; }" | 17076 "function store2(x) { void 0; x.foo = void 0; }" |
17069 "function keyed_load2(x, key) { void 0; return x[key]; }" | 17077 "function keyed_load2(x, key) { void 0; return x[key]; }" |
17070 | 17078 |
| 17079 "obj.y = void 0;" |
17071 "obj.__proto__ = null;" | 17080 "obj.__proto__ = null;" |
17072 "var subobj = {};" | 17081 "var subobj = {};" |
| 17082 "subobj.y = void 0;" |
17073 "subobj.__proto__ = obj;" | 17083 "subobj.__proto__ = obj;" |
17074 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" | 17084 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" |
17075 | 17085 |
17076 // Make the ICs monomorphic. | 17086 // Make the ICs monomorphic. |
17077 "load(obj); load(obj);" | 17087 "load(obj); load(obj);" |
17078 "load2(subobj); load2(subobj);" | 17088 "load2(subobj); load2(subobj);" |
| 17089 "store(obj); store(obj);" |
| 17090 "store2(subobj); store2(subobj);" |
| 17091 "keyed_load(obj, 'foo'); keyed_load(obj, 'foo');" |
| 17092 "keyed_load2(subobj, 'foo'); keyed_load2(subobj, 'foo');" |
| 17093 |
| 17094 // Actually test the shiny new ICs and better not crash. This |
| 17095 // serves as a regression test for issue 142088 as well. |
| 17096 "load(obj);" |
| 17097 "load2(subobj);" |
17079 "store(obj);" | 17098 "store(obj);" |
17080 "store2(subobj);" | 17099 "store2(subobj);" |
17081 "keyed_load(obj, 'foo'); keyed_load(obj, 'foo');" | 17100 "keyed_load(obj, 'foo');" |
17082 "keyed_load2(subobj, 'foo'); keyed_load2(subobj, 'foo');" | 17101 "keyed_load2(subobj, 'foo');" |
17083 | 17102 |
17084 // Delete the accessor. It better not be called any more now. | 17103 // Delete the accessor. It better not be called any more now. |
17085 "delete obj.foo;" | 17104 "delete obj.foo;" |
17086 "obj.y = void 0;" | 17105 "obj.y = void 0;" |
17087 "subobj.y = void 0;" | 17106 "subobj.y = void 0;" |
17088 | 17107 |
17089 "var load_result = load(obj);" | 17108 "var load_result = load(obj);" |
17090 "var load_result2 = load2(subobj);" | 17109 "var load_result2 = load2(subobj);" |
17091 "var keyed_load_result = keyed_load(obj, 'foo');" | 17110 "var keyed_load_result = keyed_load(obj, 'foo');" |
17092 "var keyed_load_result2 = keyed_load2(subobj, 'foo');" | 17111 "var keyed_load_result2 = keyed_load2(subobj, 'foo');" |
17093 "store(obj);" | 17112 "store(obj);" |
17094 "store2(subobj);" | 17113 "store2(subobj);" |
17095 "var y_from_obj = obj.y;" | 17114 "var y_from_obj = obj.y;" |
17096 "var y_from_subobj = subobj.y;"); | 17115 "var y_from_subobj = subobj.y;"); |
17097 CHECK(context->Global()->Get(v8_str("load_result"))->IsUndefined()); | 17116 CHECK(context->Global()->Get(v8_str("load_result"))->IsUndefined()); |
17098 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined()); | 17117 CHECK(context->Global()->Get(v8_str("load_result2"))->IsUndefined()); |
17099 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); | 17118 CHECK(context->Global()->Get(v8_str("keyed_load_result"))->IsUndefined()); |
17100 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); | 17119 CHECK(context->Global()->Get(v8_str("keyed_load_result2"))->IsUndefined()); |
17101 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); | 17120 CHECK(context->Global()->Get(v8_str("y_from_obj"))->IsUndefined()); |
17102 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); | 17121 CHECK(context->Global()->Get(v8_str("y_from_subobj"))->IsUndefined()); |
17103 } | 17122 } |
17104 | 17123 |
17105 | 17124 |
| 17125 THREADED_TEST(Regress142088) { |
| 17126 i::FLAG_allow_natives_syntax = true; |
| 17127 v8::HandleScope scope; |
| 17128 LocalContext context; |
| 17129 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 17130 templ->SetAccessor(v8_str("foo"), |
| 17131 GetterWhichReturns42, |
| 17132 SetterWhichSetsYOnThisTo23); |
| 17133 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 17134 |
| 17135 CompileRun("function load(x) { return x.foo; }" |
| 17136 "var o = Object.create(obj);" |
| 17137 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" |
| 17138 "load(o); load(o); load(o); load(o);"); |
| 17139 } |
| 17140 |
| 17141 |
17106 THREADED_TEST(Regress137496) { | 17142 THREADED_TEST(Regress137496) { |
17107 i::FLAG_expose_gc = true; | 17143 i::FLAG_expose_gc = true; |
17108 v8::HandleScope scope; | 17144 v8::HandleScope scope; |
17109 LocalContext context; | 17145 LocalContext context; |
17110 | 17146 |
17111 // Compile a try-finally clause where the finally block causes a GC | 17147 // Compile a try-finally clause where the finally block causes a GC |
17112 // while there still is a message pending for external reporting. | 17148 // while there still is a message pending for external reporting. |
17113 TryCatch try_catch; | 17149 TryCatch try_catch; |
17114 try_catch.SetVerbose(true); | 17150 try_catch.SetVerbose(true); |
17115 CompileRun("try { throw new Error(); } finally { gc(); }"); | 17151 CompileRun("try { throw new Error(); } finally { gc(); }"); |
17116 CHECK(try_catch.HasCaught()); | 17152 CHECK(try_catch.HasCaught()); |
17117 } | 17153 } |
OLD | NEW |