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