OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "include/v8.h" |
| 6 #include "test/unittests/test-utils.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace v8 { |
| 10 |
| 11 using AccessCheckTest = TestWithIsolate; |
| 12 |
| 13 namespace { |
| 14 |
| 15 bool AccessCheck(Local<Context> accessing_context, |
| 16 Local<Object> accessed_object, Local<Value> data) { |
| 17 return false; |
| 18 } |
| 19 |
| 20 MaybeLocal<Value> CompileRun(Isolate* isolate, const char* source) { |
| 21 Local<String> source_string = |
| 22 String::NewFromUtf8(isolate, source, NewStringType::kNormal) |
| 23 .ToLocalChecked(); |
| 24 Local<Context> context = isolate->GetCurrentContext(); |
| 25 Local<Script> script = |
| 26 Script::Compile(context, source_string).ToLocalChecked(); |
| 27 return script->Run(context); |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 32 TEST_F(AccessCheckTest, GetOwnPropertyDescriptor) { |
| 33 isolate()->SetFailedAccessCheckCallbackFunction( |
| 34 [](v8::Local<v8::Object> host, v8::AccessType type, |
| 35 v8::Local<v8::Value> data) {}); |
| 36 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate()); |
| 37 global_template->SetAccessCheckCallback(AccessCheck); |
| 38 |
| 39 Local<FunctionTemplate> getter_template = FunctionTemplate::New( |
| 40 isolate(), [](const FunctionCallbackInfo<Value>& info) { |
| 41 FAIL() << "This should never be called."; |
| 42 info.GetReturnValue().Set(42); |
| 43 }); |
| 44 getter_template->SetAcceptAnyReceiver(false); |
| 45 Local<FunctionTemplate> setter_template = FunctionTemplate::New( |
| 46 isolate(), [](const FunctionCallbackInfo<v8::Value>& info) { |
| 47 FAIL() << "This should never be called."; |
| 48 }); |
| 49 setter_template->SetAcceptAnyReceiver(false); |
| 50 global_template->SetAccessorProperty( |
| 51 String::NewFromUtf8(isolate(), "property", NewStringType::kNormal) |
| 52 .ToLocalChecked(), |
| 53 getter_template, setter_template); |
| 54 |
| 55 Local<Context> target_context = |
| 56 Context::New(isolate(), nullptr, global_template); |
| 57 Local<Context> accessing_context = |
| 58 Context::New(isolate(), nullptr, global_template); |
| 59 |
| 60 accessing_context->Global() |
| 61 ->Set(accessing_context, |
| 62 String::NewFromUtf8(isolate(), "other", NewStringType::kNormal) |
| 63 .ToLocalChecked(), |
| 64 target_context->Global()) |
| 65 .FromJust(); |
| 66 |
| 67 Context::Scope context_scope(accessing_context); |
| 68 Local<Value> result = |
| 69 CompileRun(isolate(), |
| 70 "Object.getOwnPropertyDescriptor(this, 'property')" |
| 71 " .get.call(other);") |
| 72 .ToLocalChecked(); |
| 73 EXPECT_TRUE(result->IsUndefined()); |
| 74 CompileRun(isolate(), |
| 75 "Object.getOwnPropertyDescriptor(this, 'property')" |
| 76 " .set.call(other, 42);"); |
| 77 } |
| 78 |
| 79 } // namespace v8 |
OLD | NEW |