OLD | NEW |
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 113 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
114 *field = value->Int32Value(); | 114 *field = value->Int32Value(); |
115 } | 115 } |
116 | 116 |
117 int foo, bar, baz; | 117 int foo, bar, baz; |
118 | 118 |
119 THREADED_TEST(GlobalVariableAccess) { | 119 THREADED_TEST(GlobalVariableAccess) { |
120 foo = 0; | 120 foo = 0; |
121 bar = -4; | 121 bar = -4; |
122 baz = 10; | 122 baz = 10; |
123 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 123 v8::HandleScope scope(CcTest::isolate()); |
124 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 124 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); |
125 templ->InstanceTemplate()->SetAccessor(v8_str("foo"), | 125 templ->InstanceTemplate()->SetAccessor(v8_str("foo"), |
126 GetIntValue, | 126 GetIntValue, |
127 SetIntValue, | 127 SetIntValue, |
128 v8::External::New(&foo)); | 128 v8::External::New(&foo)); |
129 templ->InstanceTemplate()->SetAccessor(v8_str("bar"), | 129 templ->InstanceTemplate()->SetAccessor(v8_str("bar"), |
130 GetIntValue, | 130 GetIntValue, |
131 SetIntValue, | 131 SetIntValue, |
132 v8::External::New(&bar)); | 132 v8::External::New(&bar)); |
133 templ->InstanceTemplate()->SetAccessor(v8_str("baz"), | 133 templ->InstanceTemplate()->SetAccessor(v8_str("baz"), |
134 GetIntValue, | 134 GetIntValue, |
135 SetIntValue, | 135 SetIntValue, |
136 v8::External::New(&baz)); | 136 v8::External::New(&baz)); |
137 LocalContext env(0, templ->InstanceTemplate()); | 137 LocalContext env(0, templ->InstanceTemplate()); |
138 v8_compile("foo = (++bar) + baz")->Run(); | 138 v8_compile("foo = (++bar) + baz")->Run(); |
139 CHECK_EQ(bar, -3); | 139 CHECK_EQ(bar, -3); |
140 CHECK_EQ(foo, 7); | 140 CHECK_EQ(foo, 7); |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 static int x_register[2] = {0, 0}; | 144 static int x_register[2] = {0, 0}; |
145 static v8::Handle<v8::Object> x_receiver; | 145 static v8::Handle<v8::Object> x_receiver; |
146 static v8::Handle<v8::Object> x_holder; | 146 static v8::Handle<v8::Object> x_holder; |
147 | 147 |
148 template<class Info> | 148 template<class Info> |
149 static void XGetter(const Info& info, int offset) { | 149 static void XGetter(const Info& info, int offset) { |
150 ApiTestFuzzer::Fuzz(); | 150 ApiTestFuzzer::Fuzz(); |
151 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 151 v8::Isolate* isolate = CcTest::isolate(); |
152 CHECK_EQ(isolate, info.GetIsolate()); | 152 CHECK_EQ(isolate, info.GetIsolate()); |
153 CHECK_EQ(x_receiver, info.This()); | 153 CHECK_EQ(x_receiver, info.This()); |
154 info.GetReturnValue().Set(v8_num(x_register[offset])); | 154 info.GetReturnValue().Set(v8_num(x_register[offset])); |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 static void XGetter(Local<String> name, | 158 static void XGetter(Local<String> name, |
159 const v8::PropertyCallbackInfo<v8::Value>& info) { | 159 const v8::PropertyCallbackInfo<v8::Value>& info) { |
160 CHECK_EQ(x_holder, info.Holder()); | 160 CHECK_EQ(x_holder, info.Holder()); |
161 XGetter(info, 0); | 161 XGetter(info, 0); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
166 CHECK_EQ(x_receiver, info.Holder()); | 166 CHECK_EQ(x_receiver, info.Holder()); |
167 XGetter(info, 1); | 167 XGetter(info, 1); |
168 } | 168 } |
169 | 169 |
170 | 170 |
171 template<class Info> | 171 template<class Info> |
172 static void XSetter(Local<Value> value, const Info& info, int offset) { | 172 static void XSetter(Local<Value> value, const Info& info, int offset) { |
173 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 173 v8::Isolate* isolate = CcTest::isolate(); |
174 CHECK_EQ(isolate, info.GetIsolate()); | 174 CHECK_EQ(isolate, info.GetIsolate()); |
175 CHECK_EQ(x_holder, info.This()); | 175 CHECK_EQ(x_holder, info.This()); |
176 CHECK_EQ(x_holder, info.Holder()); | 176 CHECK_EQ(x_holder, info.Holder()); |
177 x_register[offset] = value->Int32Value(); | 177 x_register[offset] = value->Int32Value(); |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 static void XSetter(Local<String> name, | 181 static void XSetter(Local<String> name, |
182 Local<Value> value, | 182 Local<Value> value, |
183 const v8::PropertyCallbackInfo<void>& info) { | 183 const v8::PropertyCallbackInfo<void>& info) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 " obj.many;" | 303 " obj.many;" |
304 "}"); | 304 "}"); |
305 } | 305 } |
306 int count_after = i::HandleScope::NumberOfHandles(isolate); | 306 int count_after = i::HandleScope::NumberOfHandles(isolate); |
307 CHECK_EQ(count_before, count_after); | 307 CHECK_EQ(count_before, count_after); |
308 } | 308 } |
309 | 309 |
310 static void CheckAccessorArgsCorrect( | 310 static void CheckAccessorArgsCorrect( |
311 Local<String> name, | 311 Local<String> name, |
312 const v8::PropertyCallbackInfo<v8::Value>& info) { | 312 const v8::PropertyCallbackInfo<v8::Value>& info) { |
313 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); | 313 CHECK(info.GetIsolate() == CcTest::isolate()); |
314 CHECK(info.This() == info.Holder()); | 314 CHECK(info.This() == info.Holder()); |
315 CHECK(info.Data()->Equals(v8::String::New("data"))); | 315 CHECK(info.Data()->Equals(v8::String::New("data"))); |
316 ApiTestFuzzer::Fuzz(); | 316 ApiTestFuzzer::Fuzz(); |
317 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); | 317 CHECK(info.GetIsolate() == CcTest::isolate()); |
318 CHECK(info.This() == info.Holder()); | 318 CHECK(info.This() == info.Holder()); |
319 CHECK(info.Data()->Equals(v8::String::New("data"))); | 319 CHECK(info.Data()->Equals(v8::String::New("data"))); |
320 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); | 320 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); |
321 CHECK(info.GetIsolate() == v8::Isolate::GetCurrent()); | 321 CHECK(info.GetIsolate() == CcTest::isolate()); |
322 CHECK(info.This() == info.Holder()); | 322 CHECK(info.This() == info.Holder()); |
323 CHECK(info.Data()->Equals(v8::String::New("data"))); | 323 CHECK(info.Data()->Equals(v8::String::New("data"))); |
324 info.GetReturnValue().Set(17); | 324 info.GetReturnValue().Set(17); |
325 } | 325 } |
326 | 326 |
327 | 327 |
328 THREADED_TEST(DirectCall) { | 328 THREADED_TEST(DirectCall) { |
329 LocalContext context; | 329 LocalContext context; |
330 v8::HandleScope scope(context->GetIsolate()); | 330 v8::HandleScope scope(context->GetIsolate()); |
331 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 331 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 for (int i = 0; i < 10; i++) { | 363 for (int i = 0; i < 10; i++) { |
364 Local<Value> result = scr->Run(); | 364 Local<Value> result = scr->Run(); |
365 CHECK(result == v8::Undefined()); | 365 CHECK(result == v8::Undefined()); |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 | 369 |
370 THREADED_TEST(NoReuseRegress) { | 370 THREADED_TEST(NoReuseRegress) { |
371 // Check that the IC generated for the one test doesn't get reused | 371 // Check that the IC generated for the one test doesn't get reused |
372 // for the other. | 372 // for the other. |
373 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 373 v8::HandleScope scope(CcTest::isolate()); |
374 { | 374 { |
375 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 375 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
376 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); | 376 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8::String::New("data")); |
377 LocalContext context; | 377 LocalContext context; |
378 v8::Handle<v8::Object> inst = obj->NewInstance(); | 378 v8::Handle<v8::Object> inst = obj->NewInstance(); |
379 context->Global()->Set(v8::String::New("obj"), inst); | 379 context->Global()->Set(v8::String::New("obj"), inst); |
380 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); | 380 Local<Script> scr = v8::Script::Compile(v8::String::New("obj.xxx")); |
381 for (int i = 0; i < 2; i++) { | 381 for (int i = 0; i < 2; i++) { |
382 Local<Value> result = scr->Run(); | 382 Local<Value> result = scr->Run(); |
383 CHECK(result == v8::Undefined()); | 383 CHECK(result == v8::Undefined()); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 v8::HandleScope scope(isolate); | 560 v8::HandleScope scope(isolate); |
561 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); | 561 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); |
562 LocalContext switch_context; | 562 LocalContext switch_context; |
563 switch_context->Global()->Set(v8_str("fun"), fun); | 563 switch_context->Global()->Set(v8_str("fun"), fun); |
564 v8::TryCatch try_catch; | 564 v8::TryCatch try_catch; |
565 CompileRun( | 565 CompileRun( |
566 "var o = Object.create(null, { n: { get:fun } });" | 566 "var o = Object.create(null, { n: { get:fun } });" |
567 "for (var i = 0; i < 10; i++) o.n;"); | 567 "for (var i = 0; i < 10; i++) o.n;"); |
568 CHECK(!try_catch.HasCaught()); | 568 CHECK(!try_catch.HasCaught()); |
569 } | 569 } |
OLD | NEW |