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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) { | 59 static void handle_property(const v8::FunctionCallbackInfo<v8::Value>& info) { |
60 ApiTestFuzzer::Fuzz(); | 60 ApiTestFuzzer::Fuzz(); |
61 CHECK_EQ(0, info.Length()); | 61 CHECK_EQ(0, info.Length()); |
62 info.GetReturnValue().Set(v8_num(907)); | 62 info.GetReturnValue().Set(v8_num(907)); |
63 } | 63 } |
64 | 64 |
65 | 65 |
66 THREADED_TEST(PropertyHandler) { | 66 THREADED_TEST(PropertyHandler) { |
67 LocalContext env; | 67 LocalContext env; |
68 v8::HandleScope scope(env->GetIsolate()); | 68 v8::Isolate* isolate = env->GetIsolate(); |
69 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); | 69 v8::HandleScope scope(isolate); |
| 70 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
70 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); | 71 fun_templ->InstanceTemplate()->SetAccessor(v8_str("foo"), handle_property); |
71 Local<v8::FunctionTemplate> getter_templ = | 72 Local<v8::FunctionTemplate> getter_templ = |
72 v8::FunctionTemplate::New(handle_property); | 73 v8::FunctionTemplate::New(isolate, handle_property); |
73 getter_templ->SetLength(0); | 74 getter_templ->SetLength(0); |
74 fun_templ-> | 75 fun_templ-> |
75 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); | 76 InstanceTemplate()->SetAccessorProperty(v8_str("bar"), getter_templ); |
76 fun_templ->InstanceTemplate()-> | 77 fun_templ->InstanceTemplate()-> |
77 SetNativeDataProperty(v8_str("instance_foo"), handle_property); | 78 SetNativeDataProperty(v8_str("instance_foo"), handle_property); |
78 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2); | 79 fun_templ->SetNativeDataProperty(v8_str("object_foo"), handle_property_2); |
79 Local<Function> fun = fun_templ->GetFunction(); | 80 Local<Function> fun = fun_templ->GetFunction(); |
80 env->Global()->Set(v8_str("Fun"), fun); | 81 env->Global()->Set(v8_str("Fun"), fun); |
81 Local<Script> getter; | 82 Local<Script> getter; |
82 Local<Script> setter; | 83 Local<Script> setter; |
(...skipping 30 matching lines...) Expand all Loading... |
113 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 114 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); |
114 *field = value->Int32Value(); | 115 *field = value->Int32Value(); |
115 } | 116 } |
116 | 117 |
117 int foo, bar, baz; | 118 int foo, bar, baz; |
118 | 119 |
119 THREADED_TEST(GlobalVariableAccess) { | 120 THREADED_TEST(GlobalVariableAccess) { |
120 foo = 0; | 121 foo = 0; |
121 bar = -4; | 122 bar = -4; |
122 baz = 10; | 123 baz = 10; |
123 v8::HandleScope scope(CcTest::isolate()); | 124 v8::Isolate* isolate = CcTest::isolate(); |
124 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); | 125 v8::HandleScope scope(isolate); |
| 126 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
125 templ->InstanceTemplate()->SetAccessor( | 127 templ->InstanceTemplate()->SetAccessor( |
126 v8_str("foo"), GetIntValue, SetIntValue, | 128 v8_str("foo"), GetIntValue, SetIntValue, |
127 v8::External::New(CcTest::isolate(), &foo)); | 129 v8::External::New(isolate, &foo)); |
128 templ->InstanceTemplate()->SetAccessor( | 130 templ->InstanceTemplate()->SetAccessor( |
129 v8_str("bar"), GetIntValue, SetIntValue, | 131 v8_str("bar"), GetIntValue, SetIntValue, |
130 v8::External::New(CcTest::isolate(), &bar)); | 132 v8::External::New(isolate, &bar)); |
131 templ->InstanceTemplate()->SetAccessor( | 133 templ->InstanceTemplate()->SetAccessor( |
132 v8_str("baz"), GetIntValue, SetIntValue, | 134 v8_str("baz"), GetIntValue, SetIntValue, |
133 v8::External::New(CcTest::isolate(), &baz)); | 135 v8::External::New(isolate, &baz)); |
134 LocalContext env(0, templ->InstanceTemplate()); | 136 LocalContext env(0, templ->InstanceTemplate()); |
135 v8_compile("foo = (++bar) + baz")->Run(); | 137 v8_compile("foo = (++bar) + baz")->Run(); |
136 CHECK_EQ(bar, -3); | 138 CHECK_EQ(bar, -3); |
137 CHECK_EQ(foo, 7); | 139 CHECK_EQ(foo, 7); |
138 } | 140 } |
139 | 141 |
140 | 142 |
141 static int x_register[2] = {0, 0}; | 143 static int x_register[2] = {0, 0}; |
142 static v8::Handle<v8::Object> x_receiver; | 144 static v8::Handle<v8::Object> x_receiver; |
143 static v8::Handle<v8::Object> x_holder; | 145 static v8::Handle<v8::Object> x_holder; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 185 |
184 | 186 |
185 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 187 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
186 CHECK_EQ(1, info.Length()); | 188 CHECK_EQ(1, info.Length()); |
187 XSetter(info[0], info, 1); | 189 XSetter(info[0], info, 1); |
188 } | 190 } |
189 | 191 |
190 | 192 |
191 THREADED_TEST(AccessorIC) { | 193 THREADED_TEST(AccessorIC) { |
192 LocalContext context; | 194 LocalContext context; |
193 v8::HandleScope scope(context->GetIsolate()); | 195 v8::Isolate* isolate = context->GetIsolate(); |
| 196 v8::HandleScope scope(isolate); |
194 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); | 197 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(); |
195 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); | 198 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); |
196 obj->SetAccessorProperty(v8_str("x1"), | 199 obj->SetAccessorProperty(v8_str("x1"), |
197 v8::FunctionTemplate::New(XGetter), | 200 v8::FunctionTemplate::New(isolate, XGetter), |
198 v8::FunctionTemplate::New(XSetter)); | 201 v8::FunctionTemplate::New(isolate, XSetter)); |
199 x_holder = obj->NewInstance(); | 202 x_holder = obj->NewInstance(); |
200 context->Global()->Set(v8_str("holder"), x_holder); | 203 context->Global()->Set(v8_str("holder"), x_holder); |
201 x_receiver = v8::Object::New(); | 204 x_receiver = v8::Object::New(); |
202 context->Global()->Set(v8_str("obj"), x_receiver); | 205 context->Global()->Set(v8_str("obj"), x_receiver); |
203 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( | 206 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( |
204 "obj.__proto__ = holder;" | 207 "obj.__proto__ = holder;" |
205 "var result = [];" | 208 "var result = [];" |
206 "var key_0 = 'x0';" | 209 "var key_0 = 'x0';" |
207 "var key_1 = 'x1';" | 210 "var key_1 = 'x1';" |
208 "for (var j = 0; j < 10; j++) {" | 211 "for (var j = 0; j < 10; j++) {" |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 v8::HandleScope scope(isolate); | 578 v8::HandleScope scope(isolate); |
576 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); | 579 v8::Handle<v8::Function> fun = v8::Function::New(isolate, handle_property); |
577 LocalContext switch_context; | 580 LocalContext switch_context; |
578 switch_context->Global()->Set(v8_str("fun"), fun); | 581 switch_context->Global()->Set(v8_str("fun"), fun); |
579 v8::TryCatch try_catch; | 582 v8::TryCatch try_catch; |
580 CompileRun( | 583 CompileRun( |
581 "var o = Object.create(null, { n: { get:fun } });" | 584 "var o = Object.create(null, { n: { get:fun } });" |
582 "for (var i = 0; i < 10; i++) o.n;"); | 585 "for (var i = 0; i < 10; i++) o.n;"); |
583 CHECK(!try_catch.HasCaught()); | 586 CHECK(!try_catch.HasCaught()); |
584 } | 587 } |
OLD | NEW |