| 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 14775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14786 } | 14786 } |
| 14787 | 14787 |
| 14788 i::Isolate::Current()->heap()->CollectAllGarbage(true); | 14788 i::Isolate::Current()->heap()->CollectAllGarbage(true); |
| 14789 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); | 14789 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); |
| 14790 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { | 14790 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { |
| 14791 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); | 14791 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); |
| 14792 CHECK_GT(elements, map_cache->NumberOfElements()); | 14792 CHECK_GT(elements, map_cache->NumberOfElements()); |
| 14793 } | 14793 } |
| 14794 } | 14794 } |
| 14795 } | 14795 } |
| 14796 |
| 14797 |
| 14798 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global, |
| 14799 Local<Value> name, |
| 14800 v8::AccessType type, |
| 14801 Local<Value> data) { |
| 14802 // Only block read access to __proto__. |
| 14803 if (type == v8::ACCESS_GET && |
| 14804 name->IsString() && |
| 14805 name->ToString()->Length() == 9 && |
| 14806 name->ToString()->Utf8Length() == 9) { |
| 14807 char buffer[10]; |
| 14808 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer)); |
| 14809 return strncmp(buffer, "__proto__", 9) != 0; |
| 14810 } |
| 14811 |
| 14812 return true; |
| 14813 } |
| 14814 |
| 14815 |
| 14816 THREADED_TEST(Regress93759) { |
| 14817 HandleScope scope; |
| 14818 |
| 14819 // Template for object with security check. |
| 14820 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); |
| 14821 // We don't do indexing, so any callback can be used for that. |
| 14822 no_proto_template->SetAccessCheckCallbacks( |
| 14823 BlockProtoNamedSecurityTestCallback, |
| 14824 IndexedSecurityTestCallback); |
| 14825 |
| 14826 // Templates for objects with hidden prototypes and possibly security check. |
| 14827 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); |
| 14828 hidden_proto_template->SetHiddenPrototype(true); |
| 14829 |
| 14830 Local<FunctionTemplate> protected_hidden_proto_template = |
| 14831 v8::FunctionTemplate::New(); |
| 14832 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( |
| 14833 BlockProtoNamedSecurityTestCallback, |
| 14834 IndexedSecurityTestCallback); |
| 14835 protected_hidden_proto_template->SetHiddenPrototype(true); |
| 14836 |
| 14837 // Context for "foreign" objects used in test. |
| 14838 Persistent<Context> context = v8::Context::New(); |
| 14839 context->Enter(); |
| 14840 |
| 14841 // Plain object, no security check. |
| 14842 Local<Object> simple_object = Object::New(); |
| 14843 |
| 14844 // Object with explicit security check. |
| 14845 Local<Object> protected_object = |
| 14846 no_proto_template->NewInstance(); |
| 14847 |
| 14848 // JSGlobalProxy object, always have security check. |
| 14849 Local<Object> proxy_object = |
| 14850 context->Global(); |
| 14851 |
| 14852 // Global object, the prototype of proxy_object. No security checks. |
| 14853 Local<Object> global_object = |
| 14854 proxy_object->GetPrototype()->ToObject(); |
| 14855 |
| 14856 // Hidden prototype without security check. |
| 14857 Local<Object> hidden_prototype = |
| 14858 hidden_proto_template->GetFunction()->NewInstance(); |
| 14859 Local<Object> object_with_hidden = |
| 14860 Object::New(); |
| 14861 object_with_hidden->SetPrototype(hidden_prototype); |
| 14862 |
| 14863 // Hidden prototype with security check on the hidden prototype. |
| 14864 Local<Object> protected_hidden_prototype = |
| 14865 protected_hidden_proto_template->GetFunction()->NewInstance(); |
| 14866 Local<Object> object_with_protected_hidden = |
| 14867 Object::New(); |
| 14868 object_with_protected_hidden->SetPrototype(protected_hidden_prototype); |
| 14869 |
| 14870 context->Exit(); |
| 14871 |
| 14872 // Template for object for second context. Values to test are put on it as |
| 14873 // properties. |
| 14874 Local<ObjectTemplate> global_template = ObjectTemplate::New(); |
| 14875 global_template->Set(v8_str("simple"), simple_object); |
| 14876 global_template->Set(v8_str("protected"), protected_object); |
| 14877 global_template->Set(v8_str("global"), global_object); |
| 14878 global_template->Set(v8_str("proxy"), proxy_object); |
| 14879 global_template->Set(v8_str("hidden"), object_with_hidden); |
| 14880 global_template->Set(v8_str("phidden"), object_with_protected_hidden); |
| 14881 |
| 14882 LocalContext context2(NULL, global_template); |
| 14883 |
| 14884 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)"); |
| 14885 CHECK(result1->Equals(simple_object->GetPrototype())); |
| 14886 |
| 14887 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)"); |
| 14888 CHECK(result2->Equals(Undefined())); |
| 14889 |
| 14890 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)"); |
| 14891 CHECK(result3->Equals(global_object->GetPrototype())); |
| 14892 |
| 14893 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)"); |
| 14894 CHECK(result4->Equals(Undefined())); |
| 14895 |
| 14896 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)"); |
| 14897 CHECK(result5->Equals( |
| 14898 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); |
| 14899 |
| 14900 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); |
| 14901 CHECK(result6->Equals(Undefined())); |
| 14902 |
| 14903 context.Dispose(); |
| 14904 } |
| OLD | NEW |