Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: test/cctest/test-api.cc

Issue 7701023: Added access check to Runtime_GetPrototype. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Allow JSProxy in GetPrototype, but only without access checks. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8natives.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14919 matching lines...) Expand 10 before | Expand all | Expand 10 after
14930 } 14930 }
14931 14931
14932 i::Isolate::Current()->heap()->CollectAllGarbage(true); 14932 i::Isolate::Current()->heap()->CollectAllGarbage(true);
14933 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); 14933 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache();
14934 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { 14934 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) {
14935 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); 14935 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache);
14936 CHECK_GT(elements, map_cache->NumberOfElements()); 14936 CHECK_GT(elements, map_cache->NumberOfElements());
14937 } 14937 }
14938 } 14938 }
14939 } 14939 }
14940
14941
14942 static bool BlockProtoNamedSecurityTestCallback(Local<v8::Object> global,
14943 Local<Value> name,
14944 v8::AccessType type,
14945 Local<Value> data) {
14946 // Only block read access to __proto__.
14947 if (type == v8::ACCESS_GET &&
14948 name->IsString() &&
14949 name->ToString()->Length() == 9 &&
14950 name->ToString()->Utf8Length() == 9) {
14951 char buffer[10];
14952 CHECK_EQ(10, name->ToString()->WriteUtf8(buffer));
14953 return strncmp(buffer, "__proto__", 9) != 0;
14954 }
14955
14956 return true;
14957 }
14958
14959
14960 THREADED_TEST(Regress93759) {
14961 HandleScope scope;
14962
14963 // Template for object with security check.
14964 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
14965 // We don't do indexing, so any callback can be used for that.
14966 no_proto_template->SetAccessCheckCallbacks(
14967 BlockProtoNamedSecurityTestCallback,
14968 IndexedSecurityTestCallback);
14969
14970 // Templates for objects with hidden prototypes and possibly security check.
14971 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New();
14972 hidden_proto_template->SetHiddenPrototype(true);
14973
14974 Local<FunctionTemplate> protected_hidden_proto_template =
14975 v8::FunctionTemplate::New();
14976 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
14977 BlockProtoNamedSecurityTestCallback,
14978 IndexedSecurityTestCallback);
14979 protected_hidden_proto_template->SetHiddenPrototype(true);
14980
14981 // Context for "foreign" objects used in test.
14982 Persistent<Context> context = v8::Context::New();
14983 context->Enter();
14984
14985 // Plain object, no security check.
14986 Local<Object> simple_object = Object::New();
14987
14988 // Object with explicit security check.
14989 Local<Object> protected_object =
14990 no_proto_template->NewInstance();
14991
14992 // JSGlobalProxy object, always have security check.
14993 Local<Object> proxy_object =
14994 context->Global();
14995
14996 // Global object, the prototype of proxy_object. No security checks.
14997 Local<Object> global_object =
14998 proxy_object->GetPrototype()->ToObject();
14999
15000 // Hidden prototype without security check.
15001 Local<Object> hidden_prototype =
15002 hidden_proto_template->GetFunction()->NewInstance();
15003 Local<Object> object_with_hidden =
15004 Object::New();
15005 object_with_hidden->SetPrototype(hidden_prototype);
15006
15007 // Hidden prototype with security check on the hidden prototype.
15008 Local<Object> protected_hidden_prototype =
15009 protected_hidden_proto_template->GetFunction()->NewInstance();
15010 Local<Object> object_with_protected_hidden =
15011 Object::New();
15012 object_with_protected_hidden->SetPrototype(protected_hidden_prototype);
15013
15014 context->Exit();
15015
15016 // Template for object for second context. Values to test are put on it as
15017 // properties.
15018 Local<ObjectTemplate> global_template = ObjectTemplate::New();
15019 global_template->Set(v8_str("simple"), simple_object);
15020 global_template->Set(v8_str("protected"), protected_object);
15021 global_template->Set(v8_str("global"), global_object);
15022 global_template->Set(v8_str("proxy"), proxy_object);
15023 global_template->Set(v8_str("hidden"), object_with_hidden);
15024 global_template->Set(v8_str("phidden"), object_with_protected_hidden);
15025
15026 LocalContext context2(NULL, global_template);
15027
15028 Local<Value> result1 = CompileRun("Object.getPrototypeOf(simple)");
15029 CHECK(result1->Equals(simple_object->GetPrototype()));
15030
15031 Local<Value> result2 = CompileRun("Object.getPrototypeOf(protected)");
15032 CHECK(result2->Equals(Undefined()));
15033
15034 Local<Value> result3 = CompileRun("Object.getPrototypeOf(global)");
15035 CHECK(result3->Equals(global_object->GetPrototype()));
15036
15037 Local<Value> result4 = CompileRun("Object.getPrototypeOf(proxy)");
15038 CHECK(result4->Equals(Undefined()));
15039
15040 Local<Value> result5 = CompileRun("Object.getPrototypeOf(hidden)");
15041 CHECK(result5->Equals(
15042 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
15043
15044 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
15045 CHECK(result6->Equals(Undefined()));
15046
15047 context.Dispose();
15048 }
OLDNEW
« no previous file with comments | « src/v8natives.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698