Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: test/cctest/test-accessors.cc

Issue 1420613008: Remove deprecated API usage from test-accessors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Two lines. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // TODO(jochen): Remove this after the setting is turned on globally.
29 #define V8_IMMINENT_DEPRECATION_WARNINGS
30
28 #include <stdlib.h> 31 #include <stdlib.h>
29 32
30 #include "src/v8.h" 33 #include "src/v8.h"
31 34
32 #include "src/api.h" 35 #include "src/api.h"
33 #include "src/frames-inl.h" 36 #include "src/frames-inl.h"
34 #include "src/string-stream.h" 37 #include "src/string-stream.h"
35 #include "test/cctest/cctest.h" 38 #include "test/cctest/cctest.h"
36 39
37 using ::v8::ObjectTemplate; 40 using ::v8::ObjectTemplate;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 74 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
72 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); 75 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property);
73 Local<v8::FunctionTemplate> getter_templ = 76 Local<v8::FunctionTemplate> getter_templ =
74 v8::FunctionTemplate::New(isolate, handle_property); 77 v8::FunctionTemplate::New(isolate, handle_property);
75 getter_templ->SetLength(0); 78 getter_templ->SetLength(0);
76 fun_templ-> 79 fun_templ->
77 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); 80 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ);
78 fun_templ->InstanceTemplate()-> 81 fun_templ->InstanceTemplate()->
79 SetNativeDataProperty(v8_str("instance_foo"), handle_property); 82 SetNativeDataProperty(v8_str("instance_foo"), handle_property);
80 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2); 83 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2);
81 Local<Function> fun = fun_templ->GetFunction(); 84 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
82 env->Global()->Set(v8_str("Fun"), fun); 85 CHECK(env->Global()->Set(env.local(), v8_str("Fun"), fun).FromJust());
83 Local<Script> getter; 86 Local<Script> getter;
84 Local<Script> setter; 87 Local<Script> setter;
85 // check function instance accessors 88 // check function instance accessors
86 getter = v8_compile("var obj = new Fun(); obj.instance_foo;"); 89 getter = v8_compile("var obj = new Fun(); obj.instance_foo;");
87 CHECK_EQ(900, getter->Run()->Int32Value()); 90 CHECK_EQ(900, getter->Run(env.local())
91 .ToLocalChecked()
92 ->Int32Value(env.local())
93 .FromJust());
88 setter = v8_compile("obj.instance_foo = 901;"); 94 setter = v8_compile("obj.instance_foo = 901;");
89 CHECK_EQ(901, setter->Run()->Int32Value()); 95 CHECK_EQ(901, setter->Run(env.local())
96 .ToLocalChecked()
97 ->Int32Value(env.local())
98 .FromJust());
90 getter = v8_compile("obj.bar;"); 99 getter = v8_compile("obj.bar;");
91 CHECK_EQ(907, getter->Run()->Int32Value()); 100 CHECK_EQ(907, getter->Run(env.local())
101 .ToLocalChecked()
102 ->Int32Value(env.local())
103 .FromJust());
92 setter = v8_compile("obj.bar = 908;"); 104 setter = v8_compile("obj.bar = 908;");
93 CHECK_EQ(908, setter->Run()->Int32Value()); 105 CHECK_EQ(908, setter->Run(env.local())
106 .ToLocalChecked()
107 ->Int32Value(env.local())
108 .FromJust());
94 // check function static accessors 109 // check function static accessors
95 getter = v8_compile("Fun.object_foo;"); 110 getter = v8_compile("Fun.object_foo;");
96 CHECK_EQ(902, getter->Run()->Int32Value()); 111 CHECK_EQ(902, getter->Run(env.local())
112 .ToLocalChecked()
113 ->Int32Value(env.local())
114 .FromJust());
97 setter = v8_compile("Fun.object_foo = 903;"); 115 setter = v8_compile("Fun.object_foo = 903;");
98 CHECK_EQ(903, setter->Run()->Int32Value()); 116 CHECK_EQ(903, setter->Run(env.local())
117 .ToLocalChecked()
118 ->Int32Value(env.local())
119 .FromJust());
99 } 120 }
100 121
101 122
102 static void GetIntValue(Local<String> property, 123 static void GetIntValue(Local<String> property,
103 const v8::PropertyCallbackInfo<v8::Value>& info) { 124 const v8::PropertyCallbackInfo<v8::Value>& info) {
104 ApiTestFuzzer::Fuzz(); 125 ApiTestFuzzer::Fuzz();
105 int* value = 126 int* value =
106 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 127 static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
107 info.GetReturnValue().Set(v8_num(*value)); 128 info.GetReturnValue().Set(v8_num(*value));
108 } 129 }
109 130
110 131
111 static void SetIntValue(Local<String> property, 132 static void SetIntValue(Local<String> property,
112 Local<Value> value, 133 Local<Value> value,
113 const v8::PropertyCallbackInfo<void>& info) { 134 const v8::PropertyCallbackInfo<void>& info) {
114 int* field = 135 int* field =
115 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 136 static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value());
116 *field = value->Int32Value(); 137 *field = value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust();
117 } 138 }
118 139
119 int foo, bar, baz; 140 int foo, bar, baz;
120 141
121 THREADED_TEST(GlobalVariableAccess) { 142 THREADED_TEST(GlobalVariableAccess) {
122 foo = 0; 143 foo = 0;
123 bar = -4; 144 bar = -4;
124 baz = 10; 145 baz = 10;
125 v8::Isolate* isolate = CcTest::isolate(); 146 v8::Isolate* isolate = CcTest::isolate();
126 v8::HandleScope scope(isolate); 147 v8::HandleScope scope(isolate);
127 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 148 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
128 templ->InstanceTemplate()->SetAccessor( 149 templ->InstanceTemplate()->SetAccessor(
129 v8_str("foo"), GetIntValue, SetIntValue, 150 v8_str("foo"), GetIntValue, SetIntValue,
130 v8::External::New(isolate, &foo)); 151 v8::External::New(isolate, &foo));
131 templ->InstanceTemplate()->SetAccessor( 152 templ->InstanceTemplate()->SetAccessor(
132 v8_str("bar"), GetIntValue, SetIntValue, 153 v8_str("bar"), GetIntValue, SetIntValue,
133 v8::External::New(isolate, &bar)); 154 v8::External::New(isolate, &bar));
134 templ->InstanceTemplate()->SetAccessor( 155 templ->InstanceTemplate()->SetAccessor(
135 v8_str("baz"), GetIntValue, SetIntValue, 156 v8_str("baz"), GetIntValue, SetIntValue,
136 v8::External::New(isolate, &baz)); 157 v8::External::New(isolate, &baz));
137 LocalContext env(0, templ->InstanceTemplate()); 158 LocalContext env(0, templ->InstanceTemplate());
138 v8_compile("foo = (++bar) + baz")->Run(); 159 v8_compile("foo = (++bar) + baz")->Run(env.local()).ToLocalChecked();
139 CHECK_EQ(bar, -3); 160 CHECK_EQ(bar, -3);
140 CHECK_EQ(foo, 7); 161 CHECK_EQ(foo, 7);
141 } 162 }
142 163
143 164
144 static int x_register[2] = {0, 0}; 165 static int x_register[2] = {0, 0};
145 static v8::Handle<v8::Object> x_receiver; 166 static v8::Local<v8::Object> x_receiver;
146 static v8::Handle<v8::Object> x_holder; 167 static v8::Local<v8::Object> x_holder;
147 168
148 template<class Info> 169 template<class Info>
149 static void XGetter(const Info& info, int offset) { 170 static void XGetter(const Info& info, int offset) {
150 ApiTestFuzzer::Fuzz(); 171 ApiTestFuzzer::Fuzz();
151 v8::Isolate* isolate = CcTest::isolate(); 172 v8::Isolate* isolate = CcTest::isolate();
152 CHECK_EQ(isolate, info.GetIsolate()); 173 CHECK_EQ(isolate, info.GetIsolate());
153 CHECK(x_receiver->Equals(info.This())); 174 CHECK(
175 x_receiver->Equals(isolate->GetCurrentContext(), info.This()).FromJust());
154 info.GetReturnValue().Set(v8_num(x_register[offset])); 176 info.GetReturnValue().Set(v8_num(x_register[offset]));
155 } 177 }
156 178
157 179
158 static void XGetter(Local<String> name, 180 static void XGetter(Local<String> name,
159 const v8::PropertyCallbackInfo<v8::Value>& info) { 181 const v8::PropertyCallbackInfo<v8::Value>& info) {
160 CHECK(x_holder->Equals(info.Holder())); 182 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
183 .FromJust());
161 XGetter(info, 0); 184 XGetter(info, 0);
162 } 185 }
163 186
164 187
165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { 188 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
166 CHECK(x_receiver->Equals(info.Holder())); 189 CHECK(
190 x_receiver->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
191 .FromJust());
167 XGetter(info, 1); 192 XGetter(info, 1);
168 } 193 }
169 194
170 195
171 template<class Info> 196 template<class Info>
172 static void XSetter(Local<Value> value, const Info& info, int offset) { 197 static void XSetter(Local<Value> value, const Info& info, int offset) {
173 v8::Isolate* isolate = CcTest::isolate(); 198 v8::Isolate* isolate = CcTest::isolate();
174 CHECK_EQ(isolate, info.GetIsolate()); 199 CHECK_EQ(isolate, info.GetIsolate());
175 CHECK(x_holder->Equals(info.This())); 200 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.This())
176 CHECK(x_holder->Equals(info.Holder())); 201 .FromJust());
177 x_register[offset] = value->Int32Value(); 202 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder())
203 .FromJust());
204 x_register[offset] =
205 value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust();
178 info.GetReturnValue().Set(v8_num(-1)); 206 info.GetReturnValue().Set(v8_num(-1));
179 } 207 }
180 208
181 209
182 static void XSetter(Local<String> name, 210 static void XSetter(Local<String> name,
183 Local<Value> value, 211 Local<Value> value,
184 const v8::PropertyCallbackInfo<void>& info) { 212 const v8::PropertyCallbackInfo<void>& info) {
185 XSetter(value, info, 0); 213 XSetter(value, info, 0);
186 } 214 }
187 215
188 216
189 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { 217 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) {
190 CHECK_EQ(1, info.Length()); 218 CHECK_EQ(1, info.Length());
191 XSetter(info[0], info, 1); 219 XSetter(info[0], info, 1);
192 } 220 }
193 221
194 222
195 THREADED_TEST(AccessorIC) { 223 THREADED_TEST(AccessorIC) {
196 LocalContext context; 224 LocalContext context;
197 v8::Isolate* isolate = context->GetIsolate(); 225 v8::Isolate* isolate = context->GetIsolate();
198 v8::HandleScope scope(isolate); 226 v8::HandleScope scope(isolate);
199 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 227 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
200 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); 228 obj->SetAccessor(v8_str("x0"), XGetter, XSetter);
201 obj->SetAccessorProperty(v8_str("x1"), 229 obj->SetAccessorProperty(v8_str("x1"),
202 v8::FunctionTemplate::New(isolate, XGetter), 230 v8::FunctionTemplate::New(isolate, XGetter),
203 v8::FunctionTemplate::New(isolate, XSetter)); 231 v8::FunctionTemplate::New(isolate, XSetter));
204 x_holder = obj->NewInstance(); 232 x_holder = obj->NewInstance(context.local()).ToLocalChecked();
205 context->Global()->Set(v8_str("holder"), x_holder); 233 CHECK(context->Global()
234 ->Set(context.local(), v8_str("holder"), x_holder)
235 .FromJust());
206 x_receiver = v8::Object::New(isolate); 236 x_receiver = v8::Object::New(isolate);
207 context->Global()->Set(v8_str("obj"), x_receiver); 237 CHECK(context->Global()
208 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( 238 ->Set(context.local(), v8_str("obj"), x_receiver)
209 "obj.__proto__ = holder;" 239 .FromJust());
210 "var result = [];" 240 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(
211 "var key_0 = 'x0';" 241 CompileRun("obj.__proto__ = holder;"
212 "var key_1 = 'x1';" 242 "var result = [];"
213 "for (var j = 0; j < 10; j++) {" 243 "var key_0 = 'x0';"
214 " var i = 4*j;" 244 "var key_1 = 'x1';"
215 " result.push(holder.x0 = i);" 245 "for (var j = 0; j < 10; j++) {"
216 " result.push(obj.x0);" 246 " var i = 4*j;"
217 " result.push(holder.x1 = i + 1);" 247 " result.push(holder.x0 = i);"
218 " result.push(obj.x1);" 248 " result.push(obj.x0);"
219 " result.push(holder[key_0] = i + 2);" 249 " result.push(holder.x1 = i + 1);"
220 " result.push(obj[key_0]);" 250 " result.push(obj.x1);"
221 " result.push(holder[key_1] = i + 3);" 251 " result.push(holder[key_0] = i + 2);"
222 " result.push(obj[key_1]);" 252 " result.push(obj[key_0]);"
223 "}" 253 " result.push(holder[key_1] = i + 3);"
224 "result")); 254 " result.push(obj[key_1]);"
255 "}"
256 "result"));
225 CHECK_EQ(80u, array->Length()); 257 CHECK_EQ(80u, array->Length());
226 for (int i = 0; i < 80; i++) { 258 for (int i = 0; i < 80; i++) {
227 v8::Handle<Value> entry = array->Get(v8::Integer::New(isolate, i)); 259 v8::Local<Value> entry =
228 CHECK(v8::Integer::New(isolate, i / 2)->Equals(entry)); 260 array->Get(context.local(), v8::Integer::New(isolate, i))
261 .ToLocalChecked();
262 CHECK(v8::Integer::New(isolate, i / 2)
263 ->Equals(context.local(), entry)
264 .FromJust());
229 } 265 }
230 } 266 }
231 267
232 268
233 template <int C> 269 template <int C>
234 static void HandleAllocatingGetter( 270 static void HandleAllocatingGetter(
235 Local<String> name, 271 Local<String> name,
236 const v8::PropertyCallbackInfo<v8::Value>& info) { 272 const v8::PropertyCallbackInfo<v8::Value>& info) {
237 ApiTestFuzzer::Fuzz(); 273 ApiTestFuzzer::Fuzz();
238 for (int i = 0; i < C; i++) 274 for (int i = 0; i < C; i++) {
239 v8::String::NewFromUtf8(info.GetIsolate(), "foo"); 275 v8::String::NewFromUtf8(info.GetIsolate(), "foo",
240 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo")); 276 v8::NewStringType::kNormal)
277 .ToLocalChecked();
278 }
279 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo",
280 v8::NewStringType::kNormal)
281 .ToLocalChecked());
241 } 282 }
242 283
243 284
244 THREADED_TEST(HandleScopePop) { 285 THREADED_TEST(HandleScopePop) {
245 LocalContext context; 286 LocalContext context;
246 v8::Isolate* isolate = context->GetIsolate(); 287 v8::Isolate* isolate = context->GetIsolate();
247 v8::HandleScope scope(isolate); 288 v8::HandleScope scope(isolate);
248 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 289 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
249 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); 290 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>);
250 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); 291 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>);
251 v8::Handle<v8::Object> inst = obj->NewInstance(); 292 v8::Local<v8::Object> inst =
252 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); 293 obj->NewInstance(context.local()).ToLocalChecked();
294 CHECK(
295 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
253 int count_before = 296 int count_before =
254 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); 297 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate));
255 { 298 {
256 v8::HandleScope scope(isolate); 299 v8::HandleScope scope(isolate);
257 CompileRun( 300 CompileRun(
258 "for (var i = 0; i < 1000; i++) {" 301 "for (var i = 0; i < 1000; i++) {"
259 " obj.one;" 302 " obj.one;"
260 " obj.many;" 303 " obj.many;"
261 "}"); 304 "}");
262 } 305 }
263 int count_after = 306 int count_after =
264 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); 307 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate));
265 CHECK_EQ(count_before, count_after); 308 CHECK_EQ(count_before, count_after);
266 } 309 }
267 310
268 static void CheckAccessorArgsCorrect( 311 static void CheckAccessorArgsCorrect(
269 Local<String> name, 312 Local<String> name,
270 const v8::PropertyCallbackInfo<v8::Value>& info) { 313 const v8::PropertyCallbackInfo<v8::Value>& info) {
271 CHECK(info.GetIsolate() == CcTest::isolate()); 314 CHECK(info.GetIsolate() == CcTest::isolate());
272 CHECK(info.This() == info.Holder()); 315 CHECK(info.This() == info.Holder());
273 CHECK( 316 CHECK(info.Data()
274 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); 317 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
318 .FromJust());
275 ApiTestFuzzer::Fuzz(); 319 ApiTestFuzzer::Fuzz();
276 CHECK(info.GetIsolate() == CcTest::isolate()); 320 CHECK(info.GetIsolate() == CcTest::isolate());
277 CHECK(info.This() == info.Holder()); 321 CHECK(info.This() == info.Holder());
278 CHECK( 322 CHECK(info.Data()
279 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); 323 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
324 .FromJust());
280 CcTest::heap()->CollectAllGarbage(); 325 CcTest::heap()->CollectAllGarbage();
281 CHECK(info.GetIsolate() == CcTest::isolate()); 326 CHECK(info.GetIsolate() == CcTest::isolate());
282 CHECK(info.This() == info.Holder()); 327 CHECK(info.This() == info.Holder());
283 CHECK( 328 CHECK(info.Data()
284 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); 329 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data"))
330 .FromJust());
285 info.GetReturnValue().Set(17); 331 info.GetReturnValue().Set(17);
286 } 332 }
287 333
288 334
289 THREADED_TEST(DirectCall) { 335 THREADED_TEST(DirectCall) {
290 LocalContext context; 336 LocalContext context;
291 v8::Isolate* isolate = context->GetIsolate(); 337 v8::Isolate* isolate = context->GetIsolate();
292 v8::HandleScope scope(isolate); 338 v8::HandleScope scope(isolate);
293 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 339 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
294 obj->SetAccessor(v8_str("xxx"), 340 obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL,
295 CheckAccessorArgsCorrect, 341 v8_str("data"));
296 NULL, 342 v8::Local<v8::Object> inst =
297 v8::String::NewFromUtf8(isolate, "data")); 343 obj->NewInstance(context.local()).ToLocalChecked();
298 v8::Handle<v8::Object> inst = obj->NewInstance(); 344 CHECK(
299 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), 345 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
300 inst); 346 Local<Script> scr =
301 Local<Script> scr = v8::Script::Compile( 347 v8::Script::Compile(context.local(), v8_str("obj.xxx")).ToLocalChecked();
302 v8::String::NewFromUtf8(isolate, "obj.xxx"));
303 for (int i = 0; i < 10; i++) { 348 for (int i = 0; i < 10; i++) {
304 Local<Value> result = scr->Run(); 349 Local<Value> result = scr->Run(context.local()).ToLocalChecked();
305 CHECK(!result.IsEmpty()); 350 CHECK(!result.IsEmpty());
306 CHECK_EQ(17, result->Int32Value()); 351 CHECK_EQ(17, result->Int32Value(context.local()).FromJust());
307 } 352 }
308 } 353 }
309 354
310 static void EmptyGetter(Local<String> name, 355 static void EmptyGetter(Local<String> name,
311 const v8::PropertyCallbackInfo<v8::Value>& info) { 356 const v8::PropertyCallbackInfo<v8::Value>& info) {
312 CheckAccessorArgsCorrect(name, info); 357 CheckAccessorArgsCorrect(name, info);
313 ApiTestFuzzer::Fuzz(); 358 ApiTestFuzzer::Fuzz();
314 CheckAccessorArgsCorrect(name, info); 359 CheckAccessorArgsCorrect(name, info);
315 info.GetReturnValue().Set(v8::Handle<v8::Value>()); 360 info.GetReturnValue().Set(v8::Local<v8::Value>());
316 } 361 }
317 362
318 363
319 THREADED_TEST(EmptyResult) { 364 THREADED_TEST(EmptyResult) {
320 LocalContext context; 365 LocalContext context;
321 v8::Isolate* isolate = context->GetIsolate(); 366 v8::Isolate* isolate = context->GetIsolate();
322 v8::HandleScope scope(isolate); 367 v8::HandleScope scope(isolate);
323 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 368 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
324 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, 369 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data"));
325 v8::String::NewFromUtf8(isolate, "data")); 370 v8::Local<v8::Object> inst =
326 v8::Handle<v8::Object> inst = obj->NewInstance(); 371 obj->NewInstance(context.local()).ToLocalChecked();
327 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); 372 CHECK(
373 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust());
328 Local<Script> scr = 374 Local<Script> scr =
329 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); 375 v8::Script::Compile(context.local(), v8_str("obj.xxx")).ToLocalChecked();
330 for (int i = 0; i < 10; i++) { 376 for (int i = 0; i < 10; i++) {
331 Local<Value> result = scr->Run(); 377 Local<Value> result = scr->Run(context.local()).ToLocalChecked();
332 CHECK(result == v8::Undefined(isolate)); 378 CHECK(result == v8::Undefined(isolate));
333 } 379 }
334 } 380 }
335 381
336 382
337 THREADED_TEST(NoReuseRegress) { 383 THREADED_TEST(NoReuseRegress) {
338 // Check that the IC generated for the one test doesn't get reused 384 // Check that the IC generated for the one test doesn't get reused
339 // for the other. 385 // for the other.
340 v8::Isolate* isolate = CcTest::isolate(); 386 v8::Isolate* isolate = CcTest::isolate();
341 v8::HandleScope scope(isolate); 387 v8::HandleScope scope(isolate);
342 { 388 {
343 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 389 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
344 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, 390 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data"));
345 v8::String::NewFromUtf8(isolate, "data"));
346 LocalContext context; 391 LocalContext context;
347 v8::Handle<v8::Object> inst = obj->NewInstance(); 392 v8::Local<v8::Object> inst =
348 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); 393 obj->NewInstance(context.local()).ToLocalChecked();
349 Local<Script> scr = 394 CHECK(context->Global()
350 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); 395 ->Set(context.local(), v8_str("obj"), inst)
396 .FromJust());
397 Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx"))
398 .ToLocalChecked();
351 for (int i = 0; i < 2; i++) { 399 for (int i = 0; i < 2; i++) {
352 Local<Value> result = scr->Run(); 400 Local<Value> result = scr->Run(context.local()).ToLocalChecked();
353 CHECK(result == v8::Undefined(isolate)); 401 CHECK(result == v8::Undefined(isolate));
354 } 402 }
355 } 403 }
356 { 404 {
357 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 405 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
358 obj->SetAccessor(v8_str("xxx"), 406 obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL,
359 CheckAccessorArgsCorrect, 407 v8_str("data"));
360 NULL,
361 v8::String::NewFromUtf8(isolate, "data"));
362 LocalContext context; 408 LocalContext context;
363 v8::Handle<v8::Object> inst = obj->NewInstance(); 409 v8::Local<v8::Object> inst =
364 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); 410 obj->NewInstance(context.local()).ToLocalChecked();
365 Local<Script> scr = 411 CHECK(context->Global()
366 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); 412 ->Set(context.local(), v8_str("obj"), inst)
413 .FromJust());
414 Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx"))
415 .ToLocalChecked();
367 for (int i = 0; i < 10; i++) { 416 for (int i = 0; i < 10; i++) {
368 Local<Value> result = scr->Run(); 417 Local<Value> result = scr->Run(context.local()).ToLocalChecked();
369 CHECK(!result.IsEmpty()); 418 CHECK(!result.IsEmpty());
370 CHECK_EQ(17, result->Int32Value()); 419 CHECK_EQ(17, result->Int32Value(context.local()).FromJust());
371 } 420 }
372 } 421 }
373 } 422 }
374 423
375 static void ThrowingGetAccessor( 424 static void ThrowingGetAccessor(
376 Local<String> name, 425 Local<String> name,
377 const v8::PropertyCallbackInfo<v8::Value>& info) { 426 const v8::PropertyCallbackInfo<v8::Value>& info) {
378 ApiTestFuzzer::Fuzz(); 427 ApiTestFuzzer::Fuzz();
379 info.GetIsolate()->ThrowException(v8_str("g")); 428 info.GetIsolate()->ThrowException(v8_str("g"));
380 } 429 }
381 430
382 431
383 static void ThrowingSetAccessor(Local<String> name, 432 static void ThrowingSetAccessor(Local<String> name,
384 Local<Value> value, 433 Local<Value> value,
385 const v8::PropertyCallbackInfo<void>& info) { 434 const v8::PropertyCallbackInfo<void>& info) {
386 info.GetIsolate()->ThrowException(value); 435 info.GetIsolate()->ThrowException(value);
387 } 436 }
388 437
389 438
390 THREADED_TEST(Regress1054726) { 439 THREADED_TEST(Regress1054726) {
391 LocalContext env; 440 LocalContext env;
392 v8::Isolate* isolate = env->GetIsolate(); 441 v8::Isolate* isolate = env->GetIsolate();
393 v8::HandleScope scope(isolate); 442 v8::HandleScope scope(isolate);
394 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 443 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
395 obj->SetAccessor(v8_str("x"), 444 obj->SetAccessor(v8_str("x"),
396 ThrowingGetAccessor, 445 ThrowingGetAccessor,
397 ThrowingSetAccessor, 446 ThrowingSetAccessor,
398 Local<Value>()); 447 Local<Value>());
399 448
400 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 449 CHECK(env->Global()
450 ->Set(env.local(), v8_str("obj"),
451 obj->NewInstance(env.local()).ToLocalChecked())
452 .FromJust());
401 453
402 // Use the throwing property setter/getter in a loop to force 454 // Use the throwing property setter/getter in a loop to force
403 // the accessor ICs to be initialized. 455 // the accessor ICs to be initialized.
404 v8::Handle<Value> result; 456 v8::Local<Value> result;
405 result = Script::Compile(v8_str( 457 result = Script::Compile(env.local(),
406 "var result = '';" 458 v8_str("var result = '';"
407 "for (var i = 0; i < 5; i++) {" 459 "for (var i = 0; i < 5; i++) {"
408 " try { obj.x; } catch (e) { result += e; }" 460 " try { obj.x; } catch (e) { result += e; }"
409 "}; result"))->Run(); 461 "}; result"))
410 CHECK(v8_str("ggggg")->Equals(result)); 462 .ToLocalChecked()
463 ->Run(env.local())
464 .ToLocalChecked();
465 CHECK(v8_str("ggggg")->Equals(env.local(), result).FromJust());
411 466
412 result = Script::Compile(String::NewFromUtf8( 467 result =
413 isolate, 468 Script::Compile(env.local(),
414 "var result = '';" 469 v8_str("var result = '';"
415 "for (var i = 0; i < 5; i++) {" 470 "for (var i = 0; i < 5; i++) {"
416 " try { obj.x = i; } catch (e) { result += e; }" 471 " try { obj.x = i; } catch (e) { result += e; }"
417 "}; result"))->Run(); 472 "}; result"))
418 CHECK(v8_str("01234")->Equals(result)); 473 .ToLocalChecked()
474 ->Run(env.local())
475 .ToLocalChecked();
476 CHECK(v8_str("01234")->Equals(env.local(), result).FromJust());
419 } 477 }
420 478
421 479
422 static void AllocGetter(Local<String> name, 480 static void AllocGetter(Local<String> name,
423 const v8::PropertyCallbackInfo<v8::Value>& info) { 481 const v8::PropertyCallbackInfo<v8::Value>& info) {
424 ApiTestFuzzer::Fuzz(); 482 ApiTestFuzzer::Fuzz();
425 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000)); 483 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000));
426 } 484 }
427 485
428 486
429 THREADED_TEST(Gc) { 487 THREADED_TEST(Gc) {
430 LocalContext env; 488 LocalContext env;
431 v8::Isolate* isolate = env->GetIsolate(); 489 v8::Isolate* isolate = env->GetIsolate();
432 v8::HandleScope scope(isolate); 490 v8::HandleScope scope(isolate);
433 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 491 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
434 obj->SetAccessor(v8_str("xxx"), AllocGetter); 492 obj->SetAccessor(v8_str("xxx"), AllocGetter);
435 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 493 CHECK(env->Global()
436 Script::Compile(String::NewFromUtf8( 494 ->Set(env.local(), v8_str("obj"),
437 isolate, 495 obj->NewInstance(env.local()).ToLocalChecked())
438 "var last = [];" 496 .FromJust());
439 "for (var i = 0; i < 2048; i++) {" 497 Script::Compile(env.local(), v8_str("var last = [];"
440 " var result = obj.xxx;" 498 "for (var i = 0; i < 2048; i++) {"
441 " result[0] = last;" 499 " var result = obj.xxx;"
442 " last = result;" 500 " result[0] = last;"
443 "}"))->Run(); 501 " last = result;"
502 "}"))
503 .ToLocalChecked()
504 ->Run(env.local())
505 .ToLocalChecked();
444 } 506 }
445 507
446 508
447 static void StackCheck(Local<String> name, 509 static void StackCheck(Local<String> name,
448 const v8::PropertyCallbackInfo<v8::Value>& info) { 510 const v8::PropertyCallbackInfo<v8::Value>& info) {
449 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); 511 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate()));
450 for (int i = 0; !iter.done(); i++) { 512 for (int i = 0; !iter.done(); i++) {
451 i::StackFrame* frame = iter.frame(); 513 i::StackFrame* frame = iter.frame();
452 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); 514 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT));
453 i::Code* code = frame->LookupCode(); 515 i::Code* code = frame->LookupCode();
454 CHECK(code->IsCode()); 516 CHECK(code->IsCode());
455 i::Address pc = frame->pc(); 517 i::Address pc = frame->pc();
456 CHECK(code->contains(pc)); 518 CHECK(code->contains(pc));
457 iter.Advance(); 519 iter.Advance();
458 } 520 }
459 } 521 }
460 522
461 523
462 THREADED_TEST(StackIteration) { 524 THREADED_TEST(StackIteration) {
463 LocalContext env; 525 LocalContext env;
464 v8::Isolate* isolate = env->GetIsolate(); 526 v8::Isolate* isolate = env->GetIsolate();
465 v8::HandleScope scope(isolate); 527 v8::HandleScope scope(isolate);
466 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 528 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
467 i::StringStream::ClearMentionedObjectCache( 529 i::StringStream::ClearMentionedObjectCache(
468 reinterpret_cast<i::Isolate*>(isolate)); 530 reinterpret_cast<i::Isolate*>(isolate));
469 obj->SetAccessor(v8_str("xxx"), StackCheck); 531 obj->SetAccessor(v8_str("xxx"), StackCheck);
470 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 532 CHECK(env->Global()
471 Script::Compile(String::NewFromUtf8( 533 ->Set(env.local(), v8_str("obj"),
472 isolate, 534 obj->NewInstance(env.local()).ToLocalChecked())
473 "function foo() {" 535 .FromJust());
474 " return obj.xxx;" 536 Script::Compile(env.local(), v8_str("function foo() {"
475 "}" 537 " return obj.xxx;"
476 "for (var i = 0; i < 100; i++) {" 538 "}"
477 " foo();" 539 "for (var i = 0; i < 100; i++) {"
478 "}"))->Run(); 540 " foo();"
541 "}"))
542 .ToLocalChecked()
543 ->Run(env.local())
544 .ToLocalChecked();
479 } 545 }
480 546
481 547
482 static void AllocateHandles(Local<String> name, 548 static void AllocateHandles(Local<String> name,
483 const v8::PropertyCallbackInfo<v8::Value>& info) { 549 const v8::PropertyCallbackInfo<v8::Value>& info) {
484 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { 550 for (int i = 0; i < i::kHandleBlockSize + 1; i++) {
485 v8::Local<v8::Value>::New(info.GetIsolate(), name); 551 v8::Local<v8::Value>::New(info.GetIsolate(), name);
486 } 552 }
487 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100)); 553 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100));
488 } 554 }
489 555
490 556
491 THREADED_TEST(HandleScopeSegment) { 557 THREADED_TEST(HandleScopeSegment) {
492 // Check that we can return values past popping of handle scope 558 // Check that we can return values past popping of handle scope
493 // segments. 559 // segments.
494 LocalContext env; 560 LocalContext env;
495 v8::Isolate* isolate = env->GetIsolate(); 561 v8::Isolate* isolate = env->GetIsolate();
496 v8::HandleScope scope(isolate); 562 v8::HandleScope scope(isolate);
497 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 563 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
498 obj->SetAccessor(v8_str("xxx"), AllocateHandles); 564 obj->SetAccessor(v8_str("xxx"), AllocateHandles);
499 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 565 CHECK(env->Global()
500 v8::Handle<v8::Value> result = Script::Compile(String::NewFromUtf8( 566 ->Set(env.local(), v8_str("obj"),
501 isolate, 567 obj->NewInstance(env.local()).ToLocalChecked())
502 "var result;" 568 .FromJust());
503 "for (var i = 0; i < 4; i++)" 569 v8::Local<v8::Value> result =
504 " result = obj.xxx;" 570 Script::Compile(env.local(), v8_str("var result;"
505 "result;"))->Run(); 571 "for (var i = 0; i < 4; i++)"
506 CHECK_EQ(100, result->Int32Value()); 572 " result = obj.xxx;"
573 "result;"))
574 .ToLocalChecked()
575 ->Run(env.local())
576 .ToLocalChecked();
577 CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
507 } 578 }
508 579
509 580
510 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 581 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
511 v8::Handle<v8::Array> array = v8::Array::New(info.GetIsolate(), 1); 582 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), 1);
512 array->Set(0, v8_str("regress")); 583 CHECK(array->Set(info.GetIsolate()->GetCurrentContext(), 0, v8_str("regress"))
584 .FromJust());
513 info.GetReturnValue().Set(array); 585 info.GetReturnValue().Set(array);
514 } 586 }
515 587
516 588
517 void JSONStringifyGetter(Local<Name> name, 589 void JSONStringifyGetter(Local<Name> name,
518 const v8::PropertyCallbackInfo<v8::Value>& info) { 590 const v8::PropertyCallbackInfo<v8::Value>& info) {
519 info.GetReturnValue().Set(v8_str("crbug-161028")); 591 info.GetReturnValue().Set(v8_str("crbug-161028"));
520 } 592 }
521 593
522 594
523 THREADED_TEST(JSONStringifyNamedInterceptorObject) { 595 THREADED_TEST(JSONStringifyNamedInterceptorObject) {
524 LocalContext env; 596 LocalContext env;
525 v8::Isolate* isolate = env->GetIsolate(); 597 v8::Isolate* isolate = env->GetIsolate();
526 v8::HandleScope scope(isolate); 598 v8::HandleScope scope(isolate);
527 599
528 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 600 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
529 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( 601 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(
530 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator)); 602 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator));
531 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 603 CHECK(env->Global()
532 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); 604 ->Set(env.local(), v8_str("obj"),
533 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); 605 obj->NewInstance(env.local()).ToLocalChecked())
606 .FromJust());
607 v8::Local<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
608 CHECK(CompileRun("JSON.stringify(obj)")
609 ->Equals(env.local(), expected)
610 .FromJust());
534 } 611 }
535 612
536 613
537 static v8::Local<v8::Context> expected_current_context; 614 static v8::Local<v8::Context> expected_current_context;
538 static v8::Local<v8::Context> expected_calling_context; 615 static v8::Local<v8::Context> expected_calling_context;
539 616
540 617
541 static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) { 618 static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) {
542 ApiTestFuzzer::Fuzz(); 619 ApiTestFuzzer::Fuzz();
543 CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext()); 620 CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext());
544 CHECK(expected_calling_context == info.GetIsolate()->GetCallingContext()); 621 CHECK(expected_calling_context == info.GetIsolate()->GetCallingContext());
545 } 622 }
546 623
547 624
548 THREADED_TEST(AccessorPropertyCrossContext) { 625 THREADED_TEST(AccessorPropertyCrossContext) {
549 LocalContext env; 626 LocalContext env;
550 v8::Isolate* isolate = env->GetIsolate(); 627 v8::Isolate* isolate = env->GetIsolate();
551 v8::HandleScope scope(isolate); 628 v8::HandleScope scope(isolate);
552 v8::Handle<v8::Function> fun = v8::Function::New(isolate, check_contexts); 629 v8::Local<v8::Function> fun =
630 v8::Function::New(env.local(), check_contexts).ToLocalChecked();
553 LocalContext switch_context; 631 LocalContext switch_context;
554 switch_context->Global()->Set(v8_str("fun"), fun); 632 CHECK(switch_context->Global()
633 ->Set(switch_context.local(), v8_str("fun"), fun)
634 .FromJust());
555 v8::TryCatch try_catch(isolate); 635 v8::TryCatch try_catch(isolate);
556 expected_current_context = env.local(); 636 expected_current_context = env.local();
557 expected_calling_context = switch_context.local(); 637 expected_calling_context = switch_context.local();
558 CompileRun( 638 CompileRun(
559 "var o = Object.create(null, { n: { get:fun } });" 639 "var o = Object.create(null, { n: { get:fun } });"
560 "for (var i = 0; i < 10; i++) o.n;"); 640 "for (var i = 0; i < 10; i++) o.n;");
561 CHECK(!try_catch.HasCaught()); 641 CHECK(!try_catch.HasCaught());
562 } 642 }
563 643
564 644
(...skipping 25 matching lines...) Expand all
590 const v8::PropertyCallbackInfo<v8::Value>& info) { 670 const v8::PropertyCallbackInfo<v8::Value>& info) {
591 ApiTestFuzzer::Fuzz(); 671 ApiTestFuzzer::Fuzz();
592 info.GetReturnValue().Set(v8_num(1)); 672 info.GetReturnValue().Set(v8_num(1));
593 } 673 }
594 674
595 675
596 THREADED_TEST(Regress433458) { 676 THREADED_TEST(Regress433458) {
597 LocalContext env; 677 LocalContext env;
598 v8::Isolate* isolate = env->GetIsolate(); 678 v8::Isolate* isolate = env->GetIsolate();
599 v8::HandleScope scope(isolate); 679 v8::HandleScope scope(isolate);
600 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 680 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
601 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(EmptyGetter)); 681 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(EmptyGetter));
602 obj->SetNativeDataProperty(v8_str("prop"), OneProperty); 682 obj->SetNativeDataProperty(v8_str("prop"), OneProperty);
603 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 683 CHECK(env->Global()
684 ->Set(env.local(), v8_str("obj"),
685 obj->NewInstance(env.local()).ToLocalChecked())
686 .FromJust());
604 CompileRun( 687 CompileRun(
605 "Object.defineProperty(obj, 'prop', { writable: false });" 688 "Object.defineProperty(obj, 'prop', { writable: false });"
606 "Object.defineProperty(obj, 'prop', { writable: true });"); 689 "Object.defineProperty(obj, 'prop', { writable: true });");
607 } 690 }
608 691
609 692
610 static bool security_check_value = false; 693 static bool security_check_value = false;
611 694
612 695
613 static bool SecurityTestCallback(Local<v8::Context> accessing_context, 696 static bool SecurityTestCallback(Local<v8::Context> accessing_context,
614 Local<v8::Object> accessed_object) { 697 Local<v8::Object> accessed_object) {
615 return security_check_value; 698 return security_check_value;
616 } 699 }
617 700
618 701
619 TEST(PrototypeGetterAccessCheck) { 702 TEST(PrototypeGetterAccessCheck) {
620 i::FLAG_allow_natives_syntax = true; 703 i::FLAG_allow_natives_syntax = true;
621 LocalContext env; 704 LocalContext env;
622 v8::Isolate* isolate = env->GetIsolate(); 705 v8::Isolate* isolate = env->GetIsolate();
623 v8::HandleScope scope(isolate); 706 v8::HandleScope scope(isolate);
624 auto fun_templ = v8::FunctionTemplate::New(isolate); 707 auto fun_templ = v8::FunctionTemplate::New(isolate);
625 auto getter_templ = v8::FunctionTemplate::New(isolate, handle_property); 708 auto getter_templ = v8::FunctionTemplate::New(isolate, handle_property);
626 getter_templ->SetAcceptAnyReceiver(false); 709 getter_templ->SetAcceptAnyReceiver(false);
627 fun_templ->InstanceTemplate()->SetAccessorProperty(v8_str("foo"), 710 fun_templ->InstanceTemplate()->SetAccessorProperty(v8_str("foo"),
628 getter_templ); 711 getter_templ);
629 auto obj_templ = v8::ObjectTemplate::New(isolate); 712 auto obj_templ = v8::ObjectTemplate::New(isolate);
630 obj_templ->SetAccessCheckCallback(SecurityTestCallback); 713 obj_templ->SetAccessCheckCallback(SecurityTestCallback);
631 env->Global()->Set(v8_str("Fun"), fun_templ->GetFunction()); 714 CHECK(env->Global()
632 env->Global()->Set(v8_str("obj"), obj_templ->NewInstance()); 715 ->Set(env.local(), v8_str("Fun"),
633 env->Global()->Set(v8_str("obj2"), obj_templ->NewInstance()); 716 fun_templ->GetFunction(env.local()).ToLocalChecked())
717 .FromJust());
718 CHECK(env->Global()
719 ->Set(env.local(), v8_str("obj"),
720 obj_templ->NewInstance(env.local()).ToLocalChecked())
721 .FromJust());
722 CHECK(env->Global()
723 ->Set(env.local(), v8_str("obj2"),
724 obj_templ->NewInstance(env.local()).ToLocalChecked())
725 .FromJust());
634 726
635 security_check_value = true; 727 security_check_value = true;
636 CompileRun("var proto = new Fun();"); 728 CompileRun("var proto = new Fun();");
637 CompileRun("obj.__proto__ = proto;"); 729 CompileRun("obj.__proto__ = proto;");
638 ExpectInt32("proto.foo", 907); 730 ExpectInt32("proto.foo", 907);
639 731
640 // Test direct. 732 // Test direct.
641 security_check_value = true; 733 security_check_value = true;
642 ExpectInt32("obj.foo", 907); 734 ExpectInt32("obj.foo", 907);
643 security_check_value = false; 735 security_check_value = false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 773
682 security_check_value = true; 774 security_check_value = true;
683 ExpectInt32("f()", 907); 775 ExpectInt32("f()", 907);
684 security_check_value = false; 776 security_check_value = false;
685 { 777 {
686 v8::TryCatch try_catch(isolate); 778 v8::TryCatch try_catch(isolate);
687 CompileRun("f();"); 779 CompileRun("f();");
688 CHECK(try_catch.HasCaught()); 780 CHECK(try_catch.HasCaught());
689 } 781 }
690 } 782 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698