LCOV - code coverage report
Current view: top level - test/cctest - test-unscopables-hidden-prototype.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 31 31 100.0 %
Date: 2019-01-20 Functions: 4 4 100.0 %

          Line data    Source code
       1             : // Copyright 2014 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 <stdlib.h>
       6             : 
       7             : #include "src/v8.h"
       8             : #include "test/cctest/cctest.h"
       9             : 
      10             : namespace {
      11             : 
      12             : 
      13          25 : static void Cleanup() {
      14             :   CompileRun(
      15             :       "delete object.x;"
      16             :       "delete hidden_prototype.x;"
      17             :       "delete object[Symbol.unscopables];"
      18             :       "delete hidden_prototype[Symbol.unscopables];");
      19          25 : }
      20             : 
      21             : 
      22       28342 : TEST(Unscopables) {
      23           5 :   LocalContext context;
      24           5 :   v8::Isolate* isolate = context->GetIsolate();
      25          10 :   v8::HandleScope handle_scope(isolate);
      26           5 :   v8::Local<v8::Context> current_context = isolate->GetCurrentContext();
      27             : 
      28           5 :   v8::Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
      29           5 :   v8::Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
      30             : 
      31           5 :   t1->SetHiddenPrototype(true);
      32             : 
      33             :   v8::Local<v8::Object> object = t0->GetFunction(current_context)
      34           5 :                                      .ToLocalChecked()
      35             :                                      ->NewInstance(current_context)
      36             :                                      .ToLocalChecked();
      37             :   v8::Local<v8::Object> hidden_prototype = t1->GetFunction(current_context)
      38           5 :                                                .ToLocalChecked()
      39             :                                                ->NewInstance(current_context)
      40             :                                                .ToLocalChecked();
      41             : 
      42          10 :   CHECK(object->SetPrototype(current_context, hidden_prototype).FromJust());
      43             : 
      44             :   context->Global()
      45          15 :       ->Set(current_context, v8_str("object"), object)
      46           5 :       .FromMaybe(false);
      47             :   context->Global()
      48          15 :       ->Set(current_context, v8_str("hidden_prototype"), hidden_prototype)
      49           5 :       .FromMaybe(false);
      50             : 
      51          10 :   CHECK_EQ(1, CompileRun("var result;"
      52             :                          "var x = 0;"
      53             :                          "object.x = 1;"
      54             :                          "with (object) {"
      55             :                          "  result = x;"
      56             :                          "}"
      57             :                          "result")
      58             :                   ->Int32Value(current_context)
      59             :                   .FromJust());
      60             : 
      61           5 :   Cleanup();
      62          10 :   CHECK_EQ(2, CompileRun("var result;"
      63             :                          "var x = 0;"
      64             :                          "hidden_prototype.x = 2;"
      65             :                          "with (object) {"
      66             :                          "  result = x;"
      67             :                          "}"
      68             :                          "result")
      69             :                   ->Int32Value(current_context)
      70             :                   .FromJust());
      71             : 
      72           5 :   Cleanup();
      73          10 :   CHECK_EQ(0, CompileRun("var result;"
      74             :                          "var x = 0;"
      75             :                          "object.x = 3;"
      76             :                          "object[Symbol.unscopables] = {x: true};"
      77             :                          "with (object) {"
      78             :                          "  result = x;"
      79             :                          "}"
      80             :                          "result")
      81             :                   ->Int32Value(current_context)
      82             :                   .FromJust());
      83             : 
      84           5 :   Cleanup();
      85          10 :   CHECK_EQ(0, CompileRun("var result;"
      86             :                          "var x = 0;"
      87             :                          "hidden_prototype.x = 4;"
      88             :                          "hidden_prototype[Symbol.unscopables] = {x: true};"
      89             :                          "with (object) {"
      90             :                          "  result = x;"
      91             :                          "}"
      92             :                          "result")
      93             :                   ->Int32Value(current_context)
      94             :                   .FromJust());
      95             : 
      96           5 :   Cleanup();
      97          10 :   CHECK_EQ(0, CompileRun("var result;"
      98             :                          "var x = 0;"
      99             :                          "object.x = 5;"
     100             :                          "hidden_prototype[Symbol.unscopables] = {x: true};"
     101             :                          "with (object) {"
     102             :                          "  result = x;"
     103             :                          "}"
     104             :                          "result;")
     105             :                   ->Int32Value(current_context)
     106             :                   .FromJust());
     107             : 
     108           5 :   Cleanup();
     109          10 :   CHECK_EQ(0, CompileRun("var result;"
     110             :                          "var x = 0;"
     111             :                          "hidden_prototype.x = 6;"
     112             :                          "object[Symbol.unscopables] = {x: true};"
     113             :                          "with (object) {"
     114             :                          "  result = x;"
     115             :                          "}"
     116             :                          "result")
     117             :                   ->Int32Value(current_context)
     118           5 :                   .FromJust());
     119           5 : }
     120             : 
     121       85011 : }  // namespace

Generated by: LCOV version 1.10