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

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

Issue 12716010: Added a version of the v8::HandleScope constructor with an Isolate and use that consistently. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed rest Created 7 years, 9 months 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 | Annotate | Revision Log
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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 using ::v8::Extension; 45 using ::v8::Extension;
46 46
47 static v8::Handle<Value> handle_property(Local<String> name, 47 static v8::Handle<Value> handle_property(Local<String> name,
48 const AccessorInfo&) { 48 const AccessorInfo&) {
49 ApiTestFuzzer::Fuzz(); 49 ApiTestFuzzer::Fuzz();
50 return v8_num(900); 50 return v8_num(900);
51 } 51 }
52 52
53 53
54 THREADED_TEST(PropertyHandler) { 54 THREADED_TEST(PropertyHandler) {
55 v8::HandleScope scope; 55 LocalContext env;
56 v8::HandleScope scope(env->GetIsolate());
56 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 57 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New();
57 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); 58 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property);
58 LocalContext env;
59 Local<Function> fun = fun_templ->GetFunction(); 59 Local<Function> fun = fun_templ->GetFunction();
60 env->Global()->Set(v8_str("Fun"), fun); 60 env->Global()->Set(v8_str("Fun"), fun);
61 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;"); 61 Local<Script> getter = v8_compile("var obj = new Fun(); obj.foo;");
62 CHECK_EQ(900, getter->Run()->Int32Value()); 62 CHECK_EQ(900, getter->Run()->Int32Value());
63 Local<Script> setter = v8_compile("obj.foo = 901;"); 63 Local<Script> setter = v8_compile("obj.foo = 901;");
64 CHECK_EQ(901, setter->Run()->Int32Value()); 64 CHECK_EQ(901, setter->Run()->Int32Value());
65 } 65 }
66 66
67 67
68 static v8::Handle<Value> GetIntValue(Local<String> property, 68 static v8::Handle<Value> GetIntValue(Local<String> property,
(...skipping 12 matching lines...) Expand all
81 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); 81 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value());
82 *field = value->Int32Value(); 82 *field = value->Int32Value();
83 } 83 }
84 84
85 int foo, bar, baz; 85 int foo, bar, baz;
86 86
87 THREADED_TEST(GlobalVariableAccess) { 87 THREADED_TEST(GlobalVariableAccess) {
88 foo = 0; 88 foo = 0;
89 bar = -4; 89 bar = -4;
90 baz = 10; 90 baz = 10;
91 v8::HandleScope scope; 91 v8::HandleScope scope(v8::Isolate::GetCurrent());
92 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 92 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New();
93 templ->InstanceTemplate()->SetAccessor(v8_str("foo"), 93 templ->InstanceTemplate()->SetAccessor(v8_str("foo"),
94 GetIntValue, 94 GetIntValue,
95 SetIntValue, 95 SetIntValue,
96 v8::External::New(&foo)); 96 v8::External::New(&foo));
97 templ->InstanceTemplate()->SetAccessor(v8_str("bar"), 97 templ->InstanceTemplate()->SetAccessor(v8_str("bar"),
98 GetIntValue, 98 GetIntValue,
99 SetIntValue, 99 SetIntValue,
100 v8::External::New(&bar)); 100 v8::External::New(&bar));
101 templ->InstanceTemplate()->SetAccessor(v8_str("baz"), 101 templ->InstanceTemplate()->SetAccessor(v8_str("baz"),
(...skipping 27 matching lines...) Expand all
129 const AccessorInfo& info) { 129 const AccessorInfo& info) {
130 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 130 v8::Isolate* isolate = v8::Isolate::GetCurrent();
131 CHECK_EQ(isolate, info.GetIsolate()); 131 CHECK_EQ(isolate, info.GetIsolate());
132 CHECK_EQ(x_holder, info.This()); 132 CHECK_EQ(x_holder, info.This());
133 CHECK_EQ(x_holder, info.Holder()); 133 CHECK_EQ(x_holder, info.Holder());
134 x_register = value->Int32Value(); 134 x_register = value->Int32Value();
135 } 135 }
136 136
137 137
138 THREADED_TEST(AccessorIC) { 138 THREADED_TEST(AccessorIC) {
139 v8::HandleScope scope; 139 LocalContext context;
140 v8::HandleScope scope(context->GetIsolate());
140 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 141 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
141 obj->SetAccessor(v8_str("x"), XGetter, XSetter); 142 obj->SetAccessor(v8_str("x"), XGetter, XSetter);
142 LocalContext context;
143 x_holder = obj->NewInstance(); 143 x_holder = obj->NewInstance();
144 context->Global()->Set(v8_str("holder"), x_holder); 144 context->Global()->Set(v8_str("holder"), x_holder);
145 x_receiver = v8::Object::New(); 145 x_receiver = v8::Object::New();
146 context->Global()->Set(v8_str("obj"), x_receiver); 146 context->Global()->Set(v8_str("obj"), x_receiver);
147 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( 147 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun(
148 "obj.__proto__ = holder;" 148 "obj.__proto__ = holder;"
149 "var result = [];" 149 "var result = [];"
150 "for (var i = 0; i < 10; i++) {" 150 "for (var i = 0; i < 10; i++) {"
151 " holder.x = i;" 151 " holder.x = i;"
152 " result.push(obj.x);" 152 " result.push(obj.x);"
153 "}" 153 "}"
154 "result")); 154 "result"));
155 CHECK_EQ(10, array->Length()); 155 CHECK_EQ(10, array->Length());
156 for (int i = 0; i < 10; i++) { 156 for (int i = 0; i < 10; i++) {
157 v8::Handle<Value> entry = array->Get(v8::Integer::New(i)); 157 v8::Handle<Value> entry = array->Get(v8::Integer::New(i));
158 CHECK_EQ(v8::Integer::New(i), entry); 158 CHECK_EQ(v8::Integer::New(i), entry);
159 } 159 }
160 } 160 }
161 161
162 162
163 static v8::Handle<Value> AccessorProhibitsOverwritingGetter( 163 static v8::Handle<Value> AccessorProhibitsOverwritingGetter(
164 Local<String> name, 164 Local<String> name,
165 const AccessorInfo& info) { 165 const AccessorInfo& info) {
166 ApiTestFuzzer::Fuzz(); 166 ApiTestFuzzer::Fuzz();
167 return v8::True(); 167 return v8::True();
168 } 168 }
169 169
170 170
171 THREADED_TEST(AccessorProhibitsOverwriting) { 171 THREADED_TEST(AccessorProhibitsOverwriting) {
172 v8::HandleScope scope;
173 LocalContext context; 172 LocalContext context;
173 v8::HandleScope scope(context->GetIsolate());
174 Local<ObjectTemplate> templ = ObjectTemplate::New(); 174 Local<ObjectTemplate> templ = ObjectTemplate::New();
175 templ->SetAccessor(v8_str("x"), 175 templ->SetAccessor(v8_str("x"),
176 AccessorProhibitsOverwritingGetter, 176 AccessorProhibitsOverwritingGetter,
177 0, 177 0,
178 v8::Handle<Value>(), 178 v8::Handle<Value>(),
179 v8::PROHIBITS_OVERWRITING, 179 v8::PROHIBITS_OVERWRITING,
180 v8::ReadOnly); 180 v8::ReadOnly);
181 Local<v8::Object> instance = templ->NewInstance(); 181 Local<v8::Object> instance = templ->NewInstance();
182 context->Global()->Set(v8_str("obj"), instance); 182 context->Global()->Set(v8_str("obj"), instance);
183 Local<Value> value = CompileRun( 183 Local<Value> value = CompileRun(
(...skipping 27 matching lines...) Expand all
211 static v8::Handle<Value> HandleAllocatingGetter(Local<String> name, 211 static v8::Handle<Value> HandleAllocatingGetter(Local<String> name,
212 const AccessorInfo& info) { 212 const AccessorInfo& info) {
213 ApiTestFuzzer::Fuzz(); 213 ApiTestFuzzer::Fuzz();
214 for (int i = 0; i < C; i++) 214 for (int i = 0; i < C; i++)
215 v8::String::New("foo"); 215 v8::String::New("foo");
216 return v8::String::New("foo"); 216 return v8::String::New("foo");
217 } 217 }
218 218
219 219
220 THREADED_TEST(HandleScopePop) { 220 THREADED_TEST(HandleScopePop) {
221 v8::HandleScope scope; 221 LocalContext context;
222 v8::HandleScope scope(context->GetIsolate());
222 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 223 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
223 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); 224 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>);
224 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); 225 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>);
225 LocalContext context;
226 v8::Handle<v8::Object> inst = obj->NewInstance(); 226 v8::Handle<v8::Object> inst = obj->NewInstance();
227 context->Global()->Set(v8::String::New("obj"), inst); 227 context->Global()->Set(v8::String::New("obj"), inst);
228 i::Isolate* isolate = i::Isolate::Current(); 228 i::Isolate* isolate = i::Isolate::Current();
229 int count_before = i::HandleScope::NumberOfHandles(isolate); 229 int count_before = i::HandleScope::NumberOfHandles(isolate);
230 { 230 {
231 v8::HandleScope scope; 231 v8::HandleScope scope(context->GetIsolate());
232 CompileRun( 232 CompileRun(
233 "for (var i = 0; i < 1000; i++) {" 233 "for (var i = 0; i < 1000; i++) {"
234 " obj.one;" 234 " obj.one;"
235 " obj.many;" 235 " obj.many;"
236 "}"); 236 "}");
237 } 237 }
238 int count_after = i::HandleScope::NumberOfHandles(isolate); 238 int count_after = i::HandleScope::NumberOfHandles(isolate);
239 CHECK_EQ(count_before, count_after); 239 CHECK_EQ(count_before, count_after);
240 } 240 }
241 241
242 static v8::Handle<Value> CheckAccessorArgsCorrect(Local<String> name, 242 static v8::Handle<Value> CheckAccessorArgsCorrect(Local<String> name,
243 const AccessorInfo& info) { 243 const AccessorInfo& info) {
244 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); 244 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
245 CHECK(info.This() == info.Holder()); 245 CHECK(info.This() == info.Holder());
246 CHECK(info.Data()->Equals(v8::String::New("data"))); 246 CHECK(info.Data()->Equals(v8::String::New("data")));
247 ApiTestFuzzer::Fuzz(); 247 ApiTestFuzzer::Fuzz();
248 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); 248 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
249 CHECK(info.This() == info.Holder()); 249 CHECK(info.This() == info.Holder());
250 CHECK(info.Data()->Equals(v8::String::New("data"))); 250 CHECK(info.Data()->Equals(v8::String::New("data")));
251 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); 251 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
252 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); 252 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent());
253 CHECK(info.This() == info.Holder()); 253 CHECK(info.This() == info.Holder());
254 CHECK(info.Data()->Equals(v8::String::New("data"))); 254 CHECK(info.Data()->Equals(v8::String::New("data")));
255 return v8::Integer::New(17); 255 return v8::Integer::New(17);
256 } 256 }
257 257
258 THREADED_TEST(DirectCall) { 258 THREADED_TEST(DirectCall) {
259 v8::HandleScope scope; 259 LocalContext context;
260 v8::HandleScope scope(context->GetIsolate());
260 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 261 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
261 obj->SetAccessor(v8_str("xxx"), 262 obj->SetAccessor(v8_str("xxx"),
262 CheckAccessorArgsCorrect, 263 CheckAccessorArgsCorrect,
263 NULL, 264 NULL,
264 v8::String::New("data")); 265 v8::String::New("data"));
265 LocalContext context;
266 v8::Handle<v8::Object> inst = obj->NewInstance(); 266 v8::Handle<v8::Object> inst = obj->NewInstance();
267 context->Global()->Set(v8::String::New("obj"), inst); 267 context->Global()->Set(v8::String::New("obj"), inst);
268 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 268 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
269 for (int i = 0; i < 10; i++) { 269 for (int i = 0; i < 10; i++) {
270 Local<Value> result = scr->Run(); 270 Local<Value> result = scr->Run();
271 CHECK(!result.IsEmpty()); 271 CHECK(!result.IsEmpty());
272 CHECK_EQ(17, result->Int32Value()); 272 CHECK_EQ(17, result->Int32Value());
273 } 273 }
274 } 274 }
275 275
276 static v8::Handle<Value> EmptyGetter(Local<String> name, 276 static v8::Handle<Value> EmptyGetter(Local<String> name,
277 const AccessorInfo& info) { 277 const AccessorInfo& info) {
278 CheckAccessorArgsCorrect(name, info); 278 CheckAccessorArgsCorrect(name, info);
279 ApiTestFuzzer::Fuzz(); 279 ApiTestFuzzer::Fuzz();
280 CheckAccessorArgsCorrect(name, info); 280 CheckAccessorArgsCorrect(name, info);
281 return v8::Handle<v8::Value>(); 281 return v8::Handle<v8::Value>();
282 } 282 }
283 283
284 THREADED_TEST(EmptyResult) { 284 THREADED_TEST(EmptyResult) {
285 v8::HandleScope scope; 285 LocalContext context;
286 v8::HandleScope scope(context->GetIsolate());
286 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 287 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
287 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); 288 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data"));
288 LocalContext context;
289 v8::Handle<v8::Object> inst = obj->NewInstance(); 289 v8::Handle<v8::Object> inst = obj->NewInstance();
290 context->Global()->Set(v8::String::New("obj"), inst); 290 context->Global()->Set(v8::String::New("obj"), inst);
291 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 291 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
292 for (int i = 0; i < 10; i++) { 292 for (int i = 0; i < 10; i++) {
293 Local<Value> result = scr->Run(); 293 Local<Value> result = scr->Run();
294 CHECK(result == v8::Undefined()); 294 CHECK(result == v8::Undefined());
295 } 295 }
296 } 296 }
297 297
298 298
299 THREADED_TEST(NoReuseRegress) { 299 THREADED_TEST(NoReuseRegress) {
300 // Check that the IC generated for the one test doesn't get reused 300 // Check that the IC generated for the one test doesn't get reused
301 // for the other. 301 // for the other.
302 v8::HandleScope scope; 302 v8::HandleScope scope(v8::Isolate::GetCurrent());
303 { 303 {
304 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 304 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
305 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); 305 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data"));
306 LocalContext context; 306 LocalContext context;
307 v8::Handle<v8::Object> inst = obj->NewInstance(); 307 v8::Handle<v8::Object> inst = obj->NewInstance();
308 context->Global()->Set(v8::String::New("obj"), inst); 308 context->Global()->Set(v8::String::New("obj"), inst);
309 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); 309 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx"));
310 for (int i = 0; i < 2; i++) { 310 for (int i = 0; i < 2; i++) {
311 Local<Value> result = scr->Run(); 311 Local<Value> result = scr->Run();
312 CHECK(result == v8::Undefined()); 312 CHECK(result == v8::Undefined());
(...skipping 25 matching lines...) Expand all
338 338
339 339
340 static void ThrowingSetAccessor(Local<String> name, 340 static void ThrowingSetAccessor(Local<String> name,
341 Local<Value> value, 341 Local<Value> value,
342 const AccessorInfo& info) { 342 const AccessorInfo& info) {
343 v8::ThrowException(value); 343 v8::ThrowException(value);
344 } 344 }
345 345
346 346
347 THREADED_TEST(Regress1054726) { 347 THREADED_TEST(Regress1054726) {
348 v8::HandleScope scope; 348 LocalContext env;
349 v8::HandleScope scope(env->GetIsolate());
349 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 350 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
350 obj->SetAccessor(v8_str("x"), 351 obj->SetAccessor(v8_str("x"),
351 ThrowingGetAccessor, 352 ThrowingGetAccessor,
352 ThrowingSetAccessor, 353 ThrowingSetAccessor,
353 Local<Value>()); 354 Local<Value>());
354 355
355 LocalContext env;
356 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 356 env->Global()->Set(v8_str("obj"), obj->NewInstance());
357 357
358 // Use the throwing property setter/getter in a loop to force 358 // Use the throwing property setter/getter in a loop to force
359 // the accessor ICs to be initialized. 359 // the accessor ICs to be initialized.
360 v8::Handle<Value> result; 360 v8::Handle<Value> result;
361 result = Script::Compile(v8_str( 361 result = Script::Compile(v8_str(
362 "var result = '';" 362 "var result = '';"
363 "for (var i = 0; i < 5; i++) {" 363 "for (var i = 0; i < 5; i++) {"
364 " try { obj.x; } catch (e) { result += e; }" 364 " try { obj.x; } catch (e) { result += e; }"
365 "}; result"))->Run(); 365 "}; result"))->Run();
366 CHECK_EQ(v8_str("ggggg"), result); 366 CHECK_EQ(v8_str("ggggg"), result);
367 367
368 result = Script::Compile(String::New( 368 result = Script::Compile(String::New(
369 "var result = '';" 369 "var result = '';"
370 "for (var i = 0; i < 5; i++) {" 370 "for (var i = 0; i < 5; i++) {"
371 " try { obj.x = i; } catch (e) { result += e; }" 371 " try { obj.x = i; } catch (e) { result += e; }"
372 "}; result"))->Run(); 372 "}; result"))->Run();
373 CHECK_EQ(v8_str("01234"), result); 373 CHECK_EQ(v8_str("01234"), result);
374 } 374 }
375 375
376 376
377 static v8::Handle<Value> AllocGetter(Local<String> name, 377 static v8::Handle<Value> AllocGetter(Local<String> name,
378 const AccessorInfo& info) { 378 const AccessorInfo& info) {
379 ApiTestFuzzer::Fuzz(); 379 ApiTestFuzzer::Fuzz();
380 return v8::Array::New(1000); 380 return v8::Array::New(1000);
381 } 381 }
382 382
383 383
384 THREADED_TEST(Gc) { 384 THREADED_TEST(Gc) {
385 v8::HandleScope scope; 385 LocalContext env;
386 v8::HandleScope scope(env->GetIsolate());
386 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 387 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
387 obj->SetAccessor(v8_str("xxx"), AllocGetter); 388 obj->SetAccessor(v8_str("xxx"), AllocGetter);
388 LocalContext env;
389 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 389 env->Global()->Set(v8_str("obj"), obj->NewInstance());
390 Script::Compile(String::New( 390 Script::Compile(String::New(
391 "var last = [];" 391 "var last = [];"
392 "for (var i = 0; i < 2048; i++) {" 392 "for (var i = 0; i < 2048; i++) {"
393 " var result = obj.xxx;" 393 " var result = obj.xxx;"
394 " result[0] = last;" 394 " result[0] = last;"
395 " last = result;" 395 " last = result;"
396 "}"))->Run(); 396 "}"))->Run();
397 } 397 }
398 398
399 399
400 static v8::Handle<Value> StackCheck(Local<String> name, 400 static v8::Handle<Value> StackCheck(Local<String> name,
401 const AccessorInfo& info) { 401 const AccessorInfo& info) {
402 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); 402 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate()));
403 for (int i = 0; !iter.done(); i++) { 403 for (int i = 0; !iter.done(); i++) {
404 i::StackFrame* frame = iter.frame(); 404 i::StackFrame* frame = iter.frame();
405 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); 405 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT));
406 i::Code* code = frame->LookupCode(); 406 i::Code* code = frame->LookupCode();
407 CHECK(code->IsCode()); 407 CHECK(code->IsCode());
408 i::Address pc = frame->pc(); 408 i::Address pc = frame->pc();
409 CHECK(code->contains(pc)); 409 CHECK(code->contains(pc));
410 iter.Advance(); 410 iter.Advance();
411 } 411 }
412 return v8::Undefined(); 412 return v8::Undefined();
413 } 413 }
414 414
415 415
416 THREADED_TEST(StackIteration) { 416 THREADED_TEST(StackIteration) {
417 v8::HandleScope scope; 417 LocalContext env;
418 v8::HandleScope scope(env->GetIsolate());
418 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 419 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
419 i::StringStream::ClearMentionedObjectCache(); 420 i::StringStream::ClearMentionedObjectCache();
420 obj->SetAccessor(v8_str("xxx"), StackCheck); 421 obj->SetAccessor(v8_str("xxx"), StackCheck);
421 LocalContext env;
422 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 422 env->Global()->Set(v8_str("obj"), obj->NewInstance());
423 Script::Compile(String::New( 423 Script::Compile(String::New(
424 "function foo() {" 424 "function foo() {"
425 " return obj.xxx;" 425 " return obj.xxx;"
426 "}" 426 "}"
427 "for (var i = 0; i < 100; i++) {" 427 "for (var i = 0; i < 100; i++) {"
428 " foo();" 428 " foo();"
429 "}"))->Run(); 429 "}"))->Run();
430 } 430 }
431 431
432 432
433 static v8::Handle<Value> AllocateHandles(Local<String> name, 433 static v8::Handle<Value> AllocateHandles(Local<String> name,
434 const AccessorInfo& info) { 434 const AccessorInfo& info) {
435 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { 435 for (int i = 0; i < i::kHandleBlockSize + 1; i++) {
436 v8::Local<v8::Value>::New(name); 436 v8::Local<v8::Value>::New(name);
437 } 437 }
438 return v8::Integer::New(100); 438 return v8::Integer::New(100);
439 } 439 }
440 440
441 441
442 THREADED_TEST(HandleScopeSegment) { 442 THREADED_TEST(HandleScopeSegment) {
443 // Check that we can return values past popping of handle scope 443 // Check that we can return values past popping of handle scope
444 // segments. 444 // segments.
445 v8::HandleScope scope; 445 LocalContext env;
446 v8::HandleScope scope(env->GetIsolate());
446 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 447 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
447 obj->SetAccessor(v8_str("xxx"), AllocateHandles); 448 obj->SetAccessor(v8_str("xxx"), AllocateHandles);
448 LocalContext env;
449 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 449 env->Global()->Set(v8_str("obj"), obj->NewInstance());
450 v8::Handle<v8::Value> result = Script::Compile(String::New( 450 v8::Handle<v8::Value> result = Script::Compile(String::New(
451 "var result;" 451 "var result;"
452 "for (var i = 0; i < 4; i++)" 452 "for (var i = 0; i < 4; i++)"
453 " result = obj.xxx;" 453 " result = obj.xxx;"
454 "result;"))->Run(); 454 "result;"))->Run();
455 CHECK_EQ(100, result->Int32Value()); 455 CHECK_EQ(100, result->Int32Value());
456 } 456 }
457 457
458 458
459 v8::Handle<v8::Array> JSONStringifyEnumerator(const AccessorInfo& info) { 459 v8::Handle<v8::Array> JSONStringifyEnumerator(const AccessorInfo& info) {
460 v8::Handle<v8::Array> array = v8::Array::New(1); 460 v8::Handle<v8::Array> array = v8::Array::New(1);
461 array->Set(0, v8_str("regress")); 461 array->Set(0, v8_str("regress"));
462 return array; 462 return array;
463 } 463 }
464 464
465 465
466 v8::Handle<v8::Value> JSONStringifyGetter(Local<String> name, 466 v8::Handle<v8::Value> JSONStringifyGetter(Local<String> name,
467 const AccessorInfo& info) { 467 const AccessorInfo& info) {
468 return v8_str("crbug-161028"); 468 return v8_str("crbug-161028");
469 } 469 }
470 470
471 471
472 THREADED_TEST(JSONStringifyNamedInterceptorObject) { 472 THREADED_TEST(JSONStringifyNamedInterceptorObject) {
473 v8::HandleScope scope;
474 LocalContext env; 473 LocalContext env;
474 v8::HandleScope scope(env->GetIsolate());
475 475
476 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); 476 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New();
477 obj->SetNamedPropertyHandler( 477 obj->SetNamedPropertyHandler(
478 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator); 478 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator);
479 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 479 env->Global()->Set(v8_str("obj"), obj->NewInstance());
480 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); 480 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}");
481 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); 481 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected));
482 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698