Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1803 CHECK(obj->Delete(prop_name)); | 1803 CHECK(obj->Delete(prop_name)); |
| 1804 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); | 1804 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); |
| 1805 | 1805 |
| 1806 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 1806 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
| 1807 | 1807 |
| 1808 CHECK(obj->DeleteHiddenValue(key)); | 1808 CHECK(obj->DeleteHiddenValue(key)); |
| 1809 CHECK(obj->GetHiddenValue(key).IsEmpty()); | 1809 CHECK(obj->GetHiddenValue(key).IsEmpty()); |
| 1810 } | 1810 } |
| 1811 | 1811 |
| 1812 | 1812 |
| 1813 THREADED_TEST(Regress97784) { | |
| 1814 // Regression test for crbug.com/97784 | |
| 1815 // Messing with the Object.prototype should not have effect on | |
| 1816 // hidden properties. | |
| 1817 v8::HandleScope scope; | |
| 1818 LocalContext env; | |
| 1819 | |
| 1820 v8::Local<v8::Object> obj = v8::Object::New(); | |
| 1821 v8::Local<v8::String> key = v8_str("hidden"); | |
| 1822 | |
| 1823 CompileRun( | |
| 1824 "set_called = false;" | |
| 1825 "Object.defineProperty(" | |
| 1826 " Object.prototype," | |
| 1827 " 'hidden'," | |
| 1828 " {get: function() { return 45; }," | |
| 1829 " set: function() { set_called = true; }})"); | |
| 1830 | |
| 1831 CHECK(obj->GetHiddenValue(key).IsEmpty()); | |
| 1832 // Make sure that the getter and setter from Object.prototype is not invoked. | |
| 1833 // If it did we would have full access to the hidden properties in | |
| 1834 // the accessor. | |
| 1835 CHECK(obj->SetHiddenValue(key, v8::Integer::New(42))); | |
| 1836 ExpectFalse("set_called"); | |
| 1837 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); | |
|
Lasse Reichstein
2011/09/26 13:02:21
Should we prevent people from doing SetHiddenValue
Rico
2011/09/26 13:09:48
As discussed offline, we should, but the real long
| |
| 1838 } | |
| 1839 | |
| 1840 | |
| 1813 static bool interceptor_for_hidden_properties_called; | 1841 static bool interceptor_for_hidden_properties_called; |
| 1814 static v8::Handle<Value> InterceptorForHiddenProperties( | 1842 static v8::Handle<Value> InterceptorForHiddenProperties( |
| 1815 Local<String> name, const AccessorInfo& info) { | 1843 Local<String> name, const AccessorInfo& info) { |
| 1816 interceptor_for_hidden_properties_called = true; | 1844 interceptor_for_hidden_properties_called = true; |
| 1817 return v8::Handle<Value>(); | 1845 return v8::Handle<Value>(); |
| 1818 } | 1846 } |
| 1819 | 1847 |
| 1820 | 1848 |
| 1821 THREADED_TEST(HiddenPropertiesWithInterceptors) { | 1849 THREADED_TEST(HiddenPropertiesWithInterceptors) { |
| 1822 v8::HandleScope scope; | 1850 v8::HandleScope scope; |
| (...skipping 13386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15209 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15237 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
| 15210 | 15238 |
| 15211 // TODO(1547): Make the following also return "i". | 15239 // TODO(1547): Make the following also return "i". |
| 15212 // Calling with environment record as base. | 15240 // Calling with environment record as base. |
| 15213 TestReceiver(o, context->Global(), "func()"); | 15241 TestReceiver(o, context->Global(), "func()"); |
| 15214 // Calling with no base. | 15242 // Calling with no base. |
| 15215 TestReceiver(o, context->Global(), "(1,func)()"); | 15243 TestReceiver(o, context->Global(), "(1,func)()"); |
| 15216 | 15244 |
| 15217 foreign_context.Dispose(); | 15245 foreign_context.Dispose(); |
| 15218 } | 15246 } |
| OLD | NEW |