Line data Source code
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 2 : bool AccessCheck(Local<Context> accessing_context,
16 : Local<Object> accessed_object, Local<Value> data) {
17 2 : return false;
18 : }
19 :
20 2 : MaybeLocal<Value> CompileRun(Isolate* isolate, const char* source) {
21 : Local<String> source_string =
22 : String::NewFromUtf8(isolate, source, NewStringType::kNormal)
23 4 : .ToLocalChecked();
24 2 : Local<Context> context = isolate->GetCurrentContext();
25 : Local<Script> script =
26 2 : Script::Compile(context, source_string).ToLocalChecked();
27 2 : return script->Run(context);
28 : }
29 :
30 : } // namespace
31 :
32 13159 : TEST_F(AccessCheckTest, GetOwnPropertyDescriptor) {
33 : isolate()->SetFailedAccessCheckCallbackFunction(
34 : [](v8::Local<v8::Object> host, v8::AccessType type,
35 3 : v8::Local<v8::Value> data) {});
36 1 : Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate());
37 1 : global_template->SetAccessCheckCallback(AccessCheck);
38 :
39 : Local<FunctionTemplate> getter_template = FunctionTemplate::New(
40 0 : isolate(), [](const FunctionCallbackInfo<Value>& info) {
41 0 : FAIL() << "This should never be called.";
42 : info.GetReturnValue().Set(42);
43 1 : });
44 1 : getter_template->SetAcceptAnyReceiver(false);
45 : Local<FunctionTemplate> setter_template = FunctionTemplate::New(
46 0 : isolate(), [](const FunctionCallbackInfo<v8::Value>& info) {
47 0 : FAIL() << "This should never be called.";
48 1 : });
49 1 : setter_template->SetAcceptAnyReceiver(false);
50 : global_template->SetAccessorProperty(
51 : String::NewFromUtf8(isolate(), "property", NewStringType::kNormal)
52 : .ToLocalChecked(),
53 2 : getter_template, setter_template);
54 :
55 : Local<Context> target_context =
56 1 : Context::New(isolate(), nullptr, global_template);
57 : Local<Context> accessing_context =
58 1 : 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 4 : target_context->Global())
65 2 : .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 1 : .ToLocalChecked();
73 1 : EXPECT_TRUE(result->IsUndefined());
74 : CompileRun(isolate(),
75 : "Object.getOwnPropertyDescriptor(this, 'property')"
76 1 : " .set.call(other, 42);");
77 1 : }
78 :
79 7893 : } // namespace v8
|