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

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

Issue 151019: Changed the global object representation (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 5 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/x64/stub-cache-x64.cc ('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 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 6022 matching lines...) Expand 10 before | Expand all | Expand 10 after
6033 Local<ObjectTemplate> templ = ObjectTemplate::New(); 6033 Local<ObjectTemplate> templ = ObjectTemplate::New();
6034 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, 6034 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker,
6035 IndexedSetAccessBlocker); 6035 IndexedSetAccessBlocker);
6036 templ->Set(v8_str("x"), v8::True()); 6036 templ->Set(v8_str("x"), v8::True());
6037 Local<v8::Object> instance = templ->NewInstance(); 6037 Local<v8::Object> instance = templ->NewInstance();
6038 context->Global()->Set(v8_str("obj"), instance); 6038 context->Global()->Set(v8_str("obj"), instance);
6039 Local<Value> value = CompileRun("obj.x"); 6039 Local<Value> value = CompileRun("obj.x");
6040 CHECK(value->BooleanValue()); 6040 CHECK(value->BooleanValue());
6041 } 6041 }
6042 6042
6043
6043 static bool NamedGetAccessBlocker(Local<v8::Object> obj, 6044 static bool NamedGetAccessBlocker(Local<v8::Object> obj,
6044 Local<Value> name, 6045 Local<Value> name,
6045 v8::AccessType type, 6046 v8::AccessType type,
6046 Local<Value> data) { 6047 Local<Value> data) {
6047 return false; 6048 return false;
6048 } 6049 }
6049 6050
6050 6051
6051 static bool IndexedGetAccessBlocker(Local<v8::Object> obj, 6052 static bool IndexedGetAccessBlocker(Local<v8::Object> obj,
6052 uint32_t key, 6053 uint32_t key,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
6086 Local<Value> value_1 = CompileRun("obj_1.a"); 6087 Local<Value> value_1 = CompileRun("obj_1.a");
6087 CHECK(value_1->IsUndefined()); 6088 CHECK(value_1->IsUndefined());
6088 6089
6089 Local<v8::Object> instance_2 = templ->NewInstance(); 6090 Local<v8::Object> instance_2 = templ->NewInstance();
6090 context->Global()->Set(v8_str("obj_2"), instance_2); 6091 context->Global()->Set(v8_str("obj_2"), instance_2);
6091 6092
6092 Local<Value> value_2 = CompileRun("obj_2.a"); 6093 Local<Value> value_2 = CompileRun("obj_2.a");
6093 CHECK(value_2->IsUndefined()); 6094 CHECK(value_2->IsUndefined());
6094 } 6095 }
6095 6096
6097
6096 // This tests that access check information remains on the global 6098 // This tests that access check information remains on the global
6097 // object template when creating contexts. 6099 // object template when creating contexts.
6098 THREADED_TEST(AccessControlRepeatedContextCreation) { 6100 THREADED_TEST(AccessControlRepeatedContextCreation) {
6099 v8::HandleScope handle_scope; 6101 v8::HandleScope handle_scope;
6100 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 6102 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
6101 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker, 6103 global_template->SetAccessCheckCallbacks(NamedSetAccessBlocker,
6102 IndexedSetAccessBlocker); 6104 IndexedSetAccessBlocker);
6103 i::Handle<i::ObjectTemplateInfo> internal_template = 6105 i::Handle<i::ObjectTemplateInfo> internal_template =
6104 v8::Utils::OpenHandle(*global_template); 6106 v8::Utils::OpenHandle(*global_template);
6105 CHECK(!internal_template->constructor()->IsUndefined()); 6107 CHECK(!internal_template->constructor()->IsUndefined());
6106 i::Handle<i::FunctionTemplateInfo> constructor( 6108 i::Handle<i::FunctionTemplateInfo> constructor(
6107 i::FunctionTemplateInfo::cast(internal_template->constructor())); 6109 i::FunctionTemplateInfo::cast(internal_template->constructor()));
6108 CHECK(!constructor->access_check_info()->IsUndefined()); 6110 CHECK(!constructor->access_check_info()->IsUndefined());
6109 v8::Persistent<Context> context0 = Context::New(NULL, global_template); 6111 v8::Persistent<Context> context0 = Context::New(NULL, global_template);
6110 CHECK(!constructor->access_check_info()->IsUndefined()); 6112 CHECK(!constructor->access_check_info()->IsUndefined());
6111 } 6113 }
6112 6114
6113 6115
6116 THREADED_TEST(TurnOnAccessCheck) {
6117 v8::HandleScope handle_scope;
6118
6119 // Create an environment with access check to the global object disabled by
6120 // default.
6121 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
6122 global_template->SetAccessCheckCallbacks(NamedGetAccessBlocker,
6123 IndexedGetAccessBlocker,
6124 v8::Handle<v8::Value>(),
6125 false);
6126 v8::Persistent<Context> context = Context::New(NULL, global_template);
6127 Context::Scope context_scope(context);
6128
6129 // Set up a property and a number of functions.
6130 context->Global()->Set(v8_str("a"), v8_num(1));
6131 CompileRun("function f1() {return a;}"
6132 "function f2() {return a;}"
6133 "function g1() {return h();}"
6134 "function g2() {return h();}"
6135 "function h() {return 1;}");
6136 Local<Function> f1 =
6137 Local<Function>::Cast(context->Global()->Get(v8_str("f1")));
6138 Local<Function> f2 =
6139 Local<Function>::Cast(context->Global()->Get(v8_str("f2")));
6140 Local<Function> g1 =
6141 Local<Function>::Cast(context->Global()->Get(v8_str("g1")));
6142 Local<Function> g2 =
6143 Local<Function>::Cast(context->Global()->Get(v8_str("g2")));
6144 Local<Function> h =
6145 Local<Function>::Cast(context->Global()->Get(v8_str("h")));
6146
6147 // Get the global object.
6148 v8::Handle<v8::Object> global = context->Global();
6149
6150 // Call f1 one time and f2 a number of times. This will ensure that f1 still
6151 // uses the runtime system to retreive property a whereas f2 uses global load
6152 // inline cache is used.
Mads Ager (chromium) 2009/06/30 10:07:34 remove 'is used'
6153 CHECK(!f1->Call(global, 0, NULL)->IsUndefined());
Mads Ager (chromium) 2009/06/30 10:07:34 Maybe check that it is actually '1' in these cases
6154 for (int i = 0; i < 4; i++) {
6155 CHECK(!f2->Call(global, 0, NULL)->IsUndefined());
6156 }
6157
6158 // Same for g1 and g2.
6159 CHECK(!g1->Call(global, 0, NULL)->IsUndefined());
6160 for (int i = 0; i < 4; i++) {
6161 CHECK(!g2->Call(global, 0, NULL)->IsUndefined());
6162 }
6163
6164 // Detach the global and turn on access check.
6165 context->DetachGlobal();
6166 context->Global()->TurnOnAccessCheck();
6167
6168 // Failing access check to property get results in undefined.
6169 CHECK(f1->Call(global, 0, NULL)->IsUndefined());
6170 CHECK(f2->Call(global, 0, NULL)->IsUndefined());
6171
6172 // Failing access check to function call results in exception.
6173 CHECK(g1->Call(global, 0, NULL).IsEmpty());
6174 CHECK(g2->Call(global, 0, NULL).IsEmpty());
6175
6176 // No failing access check when just returning a constant.
6177 CHECK(h->Call(global, 0, NULL)->Equals(v8_num(1)));
6178 }
6179
6180
6114 // This test verifies that pre-compilation (aka preparsing) can be called 6181 // This test verifies that pre-compilation (aka preparsing) can be called
6115 // without initializing the whole VM. Thus we cannot run this test in a 6182 // without initializing the whole VM. Thus we cannot run this test in a
6116 // multi-threaded setup. 6183 // multi-threaded setup.
6117 TEST(PreCompile) { 6184 TEST(PreCompile) {
6118 // TODO(155): This test would break without the initialization of V8. This is 6185 // TODO(155): This test would break without the initialization of V8. This is
6119 // a workaround for now to make this test not fail. 6186 // a workaround for now to make this test not fail.
6120 v8::V8::Initialize(); 6187 v8::V8::Initialize();
6121 const char *script = "function foo(a) { return a+1; }"; 6188 const char *script = "function foo(a) { return a+1; }";
6122 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script)); 6189 v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script));
6123 CHECK_NE(sd->Length(), 0); 6190 CHECK_NE(sd->Length(), 0);
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
6950 calling_context2->Exit(); 7017 calling_context2->Exit();
6951 7018
6952 // Dispose the contexts to allow them to be garbage collected. 7019 // Dispose the contexts to allow them to be garbage collected.
6953 calling_context0.Dispose(); 7020 calling_context0.Dispose();
6954 calling_context1.Dispose(); 7021 calling_context1.Dispose();
6955 calling_context2.Dispose(); 7022 calling_context2.Dispose();
6956 calling_context0.Clear(); 7023 calling_context0.Clear();
6957 calling_context1.Clear(); 7024 calling_context1.Clear();
6958 calling_context2.Clear(); 7025 calling_context2.Clear();
6959 } 7026 }
OLDNEW
« no previous file with comments | « src/x64/stub-cache-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698