LCOV - code coverage report
Current view: top level - test/unittests/api - access-check-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 30 30 100.0 %
Date: 2019-04-19 Functions: 7 12 58.3 %

          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           2 :       String::NewFromUtf8(isolate, source, NewStringType::kNormal)
      23           2 :           .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       15418 : 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           1 :       isolate(), [](const FunctionCallbackInfo<Value>& info) { FAIL(); });
      41           1 :   getter_template->SetAcceptAnyReceiver(false);
      42             :   Local<FunctionTemplate> setter_template = FunctionTemplate::New(
      43           1 :       isolate(), [](const FunctionCallbackInfo<v8::Value>& info) { FAIL(); });
      44           1 :   setter_template->SetAcceptAnyReceiver(false);
      45           1 :   global_template->SetAccessorProperty(
      46           1 :       String::NewFromUtf8(isolate(), "property", NewStringType::kNormal)
      47             :           .ToLocalChecked(),
      48           1 :       getter_template, setter_template);
      49             : 
      50             :   Local<Context> target_context =
      51           1 :       Context::New(isolate(), nullptr, global_template);
      52             :   Local<Context> accessing_context =
      53           1 :       Context::New(isolate(), nullptr, global_template);
      54             : 
      55           2 :   accessing_context->Global()
      56           2 :       ->Set(accessing_context,
      57           1 :             String::NewFromUtf8(isolate(), "other", NewStringType::kNormal)
      58             :                 .ToLocalChecked(),
      59           2 :             target_context->Global())
      60             :       .FromJust();
      61             : 
      62             :   Context::Scope context_scope(accessing_context);
      63             :   Local<Value> result =
      64           1 :       CompileRun(isolate(),
      65             :                  "Object.getOwnPropertyDescriptor(this, 'property')"
      66             :                  "    .get.call(other);")
      67             :           .ToLocalChecked();
      68           1 :   EXPECT_TRUE(result->IsUndefined());
      69             :   CompileRun(isolate(),
      70             :              "Object.getOwnPropertyDescriptor(this, 'property')"
      71           1 :              "    .set.call(other, 42);");
      72           1 : }
      73             : 
      74        9249 : }  // namespace v8

Generated by: LCOV version 1.10