OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/test-api.h" | 7 #include "test/cctest/test-api.h" |
8 | 8 |
9 #include "include/v8-util.h" | 9 #include "include/v8-util.h" |
10 #include "src/api.h" | 10 #include "src/api.h" |
(...skipping 3229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3240 | 3240 |
3241 // Reset. | 3241 // Reset. |
3242 CompileRun("delete obj.whatever;"); | 3242 CompileRun("delete obj.whatever;"); |
3243 ExpectInt32("f(obj)", 239); | 3243 ExpectInt32("f(obj)", 239); |
3244 ExpectInt32("f(outer)", 239); | 3244 ExpectInt32("f(outer)", 239); |
3245 | 3245 |
3246 CompileRun("outer.whatever = 4;"); | 3246 CompileRun("outer.whatever = 4;"); |
3247 ExpectInt32("f(obj)", 239); | 3247 ExpectInt32("f(obj)", 239); |
3248 ExpectInt32("f(outer)", 4); | 3248 ExpectInt32("f(outer)", 4); |
3249 } | 3249 } |
| 3250 |
| 3251 |
| 3252 namespace { |
| 3253 |
| 3254 void DatabaseGetter(Local<Name> name, |
| 3255 const v8::PropertyCallbackInfo<Value>& info) { |
| 3256 ApiTestFuzzer::Fuzz(); |
| 3257 auto context = info.GetIsolate()->GetCurrentContext(); |
| 3258 Local<v8::Object> db = info.Holder() |
| 3259 ->GetRealNamedProperty(context, v8_str("db")) |
| 3260 .ToLocalChecked() |
| 3261 .As<v8::Object>(); |
| 3262 if (!db->Has(context, name).FromJust()) return; |
| 3263 info.GetReturnValue().Set(db->Get(context, name).ToLocalChecked()); |
| 3264 } |
| 3265 |
| 3266 |
| 3267 void DatabaseSetter(Local<Name> name, Local<Value> value, |
| 3268 const v8::PropertyCallbackInfo<Value>& info) { |
| 3269 ApiTestFuzzer::Fuzz(); |
| 3270 auto context = info.GetIsolate()->GetCurrentContext(); |
| 3271 if (name->Equals(v8_str("db"))) return; |
| 3272 Local<v8::Object> db = info.Holder() |
| 3273 ->GetRealNamedProperty(context, v8_str("db")) |
| 3274 .ToLocalChecked() |
| 3275 .As<v8::Object>(); |
| 3276 db->Set(context, name, value).FromJust(); |
| 3277 info.GetReturnValue().Set(value); |
| 3278 } |
| 3279 } |
| 3280 |
| 3281 |
| 3282 THREADED_TEST(NonMaskingInterceptorGlobalEvalRegression) { |
| 3283 auto isolate = CcTest::isolate(); |
| 3284 v8::HandleScope handle_scope(isolate); |
| 3285 LocalContext context; |
| 3286 |
| 3287 auto interceptor_templ = v8::ObjectTemplate::New(isolate); |
| 3288 v8::NamedPropertyHandlerConfiguration conf(DatabaseGetter, DatabaseSetter); |
| 3289 conf.flags = v8::PropertyHandlerFlags::kNonMasking; |
| 3290 interceptor_templ->SetHandler(conf); |
| 3291 |
| 3292 context->Global()->Set(v8_str("intercepted_1"), |
| 3293 interceptor_templ->NewInstance()); |
| 3294 context->Global()->Set(v8_str("intercepted_2"), |
| 3295 interceptor_templ->NewInstance()); |
| 3296 |
| 3297 // Init dbs. |
| 3298 CompileRun( |
| 3299 "intercepted_1.db = {};" |
| 3300 "intercepted_2.db = {};"); |
| 3301 |
| 3302 ExpectInt32( |
| 3303 "var obj = intercepted_1;" |
| 3304 "obj.x = 4;" |
| 3305 "eval('obj.x');" |
| 3306 "eval('obj.x');" |
| 3307 "eval('obj.x');" |
| 3308 "obj = intercepted_2;" |
| 3309 "obj.x = 9;" |
| 3310 "eval('obj.x');", |
| 3311 9); |
| 3312 } |
OLD | NEW |