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

Side by Side Diff: test/cctest/test-access-checks.cc

Issue 2550423002: Propagate exceptions thrown by access check interceptors. (Closed)
Patch Set: propagate Created 4 years 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
« src/objects.cc ('K') | « src/objects.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "test/cctest/cctest.h" 7 #include "test/cctest/cctest.h"
8 8
9 namespace { 9 namespace {
10 10
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 void IndexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 96 void IndexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
97 CHECK(g_expect_interceptor_call); 97 CHECK(g_expect_interceptor_call);
98 v8::Isolate* isolate = info.GetIsolate(); 98 v8::Isolate* isolate = info.GetIsolate();
99 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 99 v8::Local<v8::Context> context = isolate->GetCurrentContext();
100 v8::Local<v8::Array> names = v8::Array::New(isolate, 1); 100 v8::Local<v8::Array> names = v8::Array::New(isolate, 1);
101 names->Set(context, 0, v8_str("7")).FromJust(); 101 names->Set(context, 0, v8_str("7")).FromJust();
102 info.GetReturnValue().Set(names); 102 info.GetReturnValue().Set(names);
103 } 103 }
104 104
105 void NamedGetterThrowsException(
106 v8::Local<v8::Name> property,
107 const v8::PropertyCallbackInfo<v8::Value>& info) {
108 info.GetIsolate()->ThrowException(v8_str("exception"));
109 }
110
111 void NamedSetterThrowsException(
112 v8::Local<v8::Name> property, v8::Local<v8::Value> value,
113 const v8::PropertyCallbackInfo<v8::Value>& info) {
114 info.GetIsolate()->ThrowException(v8_str("exception"));
115 }
116
117 void IndexedGetterThrowsException(
118 uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info) {
119 info.GetIsolate()->ThrowException(v8_str("exception"));
120 }
121
122 void IndexedSetterThrowsException(
123 uint32_t index, v8::Local<v8::Value> value,
124 const v8::PropertyCallbackInfo<v8::Value>& info) {
125 info.GetIsolate()->ThrowException(v8_str("exception"));
126 }
127
105 bool AccessCheck(v8::Local<v8::Context> accessing_context, 128 bool AccessCheck(v8::Local<v8::Context> accessing_context,
106 v8::Local<v8::Object> accessed_object, 129 v8::Local<v8::Object> accessed_object,
107 v8::Local<v8::Value> data) { 130 v8::Local<v8::Value> data) {
108 return false; 131 return false;
109 } 132 }
110 133
111 void GetCrossContextInt(v8::Local<v8::String> property, 134 void GetCrossContextInt(v8::Local<v8::String> property,
112 const v8::PropertyCallbackInfo<v8::Value>& info) { 135 const v8::PropertyCallbackInfo<v8::Value>& info) {
113 CHECK(!g_expect_interceptor_call); 136 CHECK(!g_expect_interceptor_call);
114 info.GetReturnValue().Set(g_cross_context_int); 137 info.GetReturnValue().Set(g_cross_context_int);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 197 }
175 198
176 // Intercepted properties are accessible, however. 199 // Intercepted properties are accessible, however.
177 ExpectInt32("this.other.cross_context_int", 23); 200 ExpectInt32("this.other.cross_context_int", 23);
178 CompileRunChecked(isolate, "this.other.cross_context_int = 42"); 201 CompileRunChecked(isolate, "this.other.cross_context_int = 42");
179 ExpectInt32("this.other[7]", 42); 202 ExpectInt32("this.other[7]", 42);
180 ExpectString("JSON.stringify(Object.getOwnPropertyNames(this.other))", 203 ExpectString("JSON.stringify(Object.getOwnPropertyNames(this.other))",
181 "[\"7\",\"cross_context_int\"]"); 204 "[\"7\",\"cross_context_int\"]");
182 } 205 }
183 206
207 void CheckCrossContextAccessWithException(
208 v8::Isolate* isolate, v8::Local<v8::Context> accessing_context,
209 v8::Local<v8::Object> accessed_object) {
210 v8::HandleScope handle_scope(isolate);
211 accessing_context->Global()
212 ->Set(accessing_context, v8_str("other"), accessed_object)
213 .FromJust();
214 v8::Context::Scope context_scope(accessing_context);
215
216 {
217 v8::TryCatch try_catch(isolate);
218 CompileRun("this.other.should_throw");
219 CHECK(try_catch.HasCaught());
220 CHECK(try_catch.Exception()->IsString());
221 CHECK(v8_str("exception")
222 ->Equals(accessing_context, try_catch.Exception())
223 .FromJust());
224 }
225
226 {
227 v8::TryCatch try_catch(isolate);
228 CompileRun("this.other.should_throw = 8");
229 CHECK(try_catch.HasCaught());
230 CHECK(try_catch.Exception()->IsString());
231 CHECK(v8_str("exception")
232 ->Equals(accessing_context, try_catch.Exception())
233 .FromJust());
234 }
235
236 {
237 v8::TryCatch try_catch(isolate);
238 CompileRun("this.other[42]");
239 CHECK(try_catch.HasCaught());
240 CHECK(try_catch.Exception()->IsString());
241 CHECK(v8_str("exception")
242 ->Equals(accessing_context, try_catch.Exception())
243 .FromJust());
244 }
245
246 {
247 v8::TryCatch try_catch(isolate);
248 CompileRun("this.other[42] = 8");
249 CHECK(try_catch.HasCaught());
250 CHECK(try_catch.Exception()->IsString());
251 CHECK(v8_str("exception")
252 ->Equals(accessing_context, try_catch.Exception())
253 .FromJust());
254 }
255 }
256
184 void Ctor(const v8::FunctionCallbackInfo<v8::Value>& info) { 257 void Ctor(const v8::FunctionCallbackInfo<v8::Value>& info) {
185 CHECK(info.IsConstructCall()); 258 CHECK(info.IsConstructCall());
186 } 259 }
187 260
188 } // namespace 261 } // namespace
189 262
190 TEST(AccessCheckWithInterceptor) { 263 TEST(AccessCheckWithInterceptor) {
191 v8::Isolate* isolate = CcTest::isolate(); 264 v8::Isolate* isolate = CcTest::isolate();
192 v8::HandleScope scope(isolate); 265 v8::HandleScope scope(isolate);
193 v8::Local<v8::ObjectTemplate> global_template = 266 v8::Local<v8::ObjectTemplate> global_template =
(...skipping 14 matching lines...) Expand all
208 v8::Local<v8::Context> context0 = 281 v8::Local<v8::Context> context0 =
209 v8::Context::New(isolate, nullptr, global_template); 282 v8::Context::New(isolate, nullptr, global_template);
210 CheckCanRunScriptInContext(isolate, context0); 283 CheckCanRunScriptInContext(isolate, context0);
211 284
212 // Create another context. 285 // Create another context.
213 v8::Local<v8::Context> context1 = 286 v8::Local<v8::Context> context1 =
214 v8::Context::New(isolate, nullptr, global_template); 287 v8::Context::New(isolate, nullptr, global_template);
215 CheckCrossContextAccess(isolate, context1, context0->Global()); 288 CheckCrossContextAccess(isolate, context1, context0->Global());
216 } 289 }
217 290
291 TEST(AccessCheckWithExceptionThrowingInterceptor) {
292 v8::Isolate* isolate = CcTest::isolate();
293 isolate->SetFailedAccessCheckCallbackFunction([](v8::Local<v8::Object> target,
294 v8::AccessType type,
295 v8::Local<v8::Value> data) {
296 CHECK(false); // This should never be called.
297 });
298
299 v8::HandleScope scope(isolate);
300 v8::Local<v8::ObjectTemplate> global_template =
301 v8::ObjectTemplate::New(isolate);
302 global_template->SetAccessCheckCallbackAndHandler(
303 AccessCheck, v8::NamedPropertyHandlerConfiguration(
304 NamedGetterThrowsException, NamedSetterThrowsException),
305 v8::IndexedPropertyHandlerConfiguration(IndexedGetterThrowsException,
306 IndexedSetterThrowsException));
307
308 // Create two contexts.
309 v8::Local<v8::Context> context0 =
310 v8::Context::New(isolate, nullptr, global_template);
311 v8::Local<v8::Context> context1 =
312 v8::Context::New(isolate, nullptr, global_template);
313
314 CheckCrossContextAccessWithException(isolate, context1, context0->Global());
315 }
316
218 TEST(NewRemoteContext) { 317 TEST(NewRemoteContext) {
219 v8::Isolate* isolate = CcTest::isolate(); 318 v8::Isolate* isolate = CcTest::isolate();
220 v8::HandleScope scope(isolate); 319 v8::HandleScope scope(isolate);
221 v8::Local<v8::ObjectTemplate> global_template = 320 v8::Local<v8::ObjectTemplate> global_template =
222 v8::ObjectTemplate::New(isolate); 321 v8::ObjectTemplate::New(isolate);
223 global_template->SetAccessCheckCallbackAndHandler( 322 global_template->SetAccessCheckCallbackAndHandler(
224 AccessCheck, 323 AccessCheck,
225 v8::NamedPropertyHandlerConfiguration( 324 v8::NamedPropertyHandlerConfiguration(
226 NamedGetter, NamedSetter, NamedQuery, NamedDeleter, NamedEnumerator), 325 NamedGetter, NamedSetter, NamedQuery, NamedDeleter, NamedEnumerator),
227 v8::IndexedPropertyHandlerConfiguration(IndexedGetter, IndexedSetter, 326 v8::IndexedPropertyHandlerConfiguration(IndexedGetter, IndexedSetter,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 IndexedEnumerator)); 395 IndexedEnumerator));
297 tmpl->SetNativeDataProperty( 396 tmpl->SetNativeDataProperty(
298 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(), 397 v8_str("all_can_read"), Return42, nullptr, v8::Local<v8::Value>(),
299 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ); 398 v8::None, v8::Local<v8::AccessorSignature>(), v8::ALL_CAN_READ);
300 399
301 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked(); 400 v8::Local<v8::Object> obj = tmpl->NewRemoteInstance().ToLocalChecked();
302 401
303 v8::Local<v8::Context> context = v8::Context::New(isolate); 402 v8::Local<v8::Context> context = v8::Context::New(isolate);
304 CheckCrossContextAccess(isolate, context, obj); 403 CheckCrossContextAccess(isolate, context, obj);
305 } 404 }
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698