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 |
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 Loading... | |
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 | |
jochen (gone - plz use gerrit)
2015/10/28 10:58:20
Nit. Keep two empty lives
vogelheim
2015/10/28 11:53:25
Done.
| |
102 static void GetIntValue(Local<String> property, | 122 static void GetIntValue(Local<String> property, |
103 const v8::PropertyCallbackInfo<v8::Value>& info) { | 123 const v8::PropertyCallbackInfo<v8::Value>& info) { |
104 ApiTestFuzzer::Fuzz(); | 124 ApiTestFuzzer::Fuzz(); |
105 int* value = | 125 int* value = |
106 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 126 static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value()); |
107 info.GetReturnValue().Set(v8_num(*value)); | 127 info.GetReturnValue().Set(v8_num(*value)); |
108 } | 128 } |
109 | 129 |
110 | 130 |
111 static void SetIntValue(Local<String> property, | 131 static void SetIntValue(Local<String> property, |
112 Local<Value> value, | 132 Local<Value> value, |
113 const v8::PropertyCallbackInfo<void>& info) { | 133 const v8::PropertyCallbackInfo<void>& info) { |
114 int* field = | 134 int* field = |
115 static_cast<int*>(v8::Handle<v8::External>::Cast(info.Data())->Value()); | 135 static_cast<int*>(v8::Local<v8::External>::Cast(info.Data())->Value()); |
116 *field = value->Int32Value(); | 136 *field = value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust(); |
117 } | 137 } |
118 | 138 |
119 int foo, bar, baz; | 139 int foo, bar, baz; |
120 | 140 |
121 THREADED_TEST(GlobalVariableAccess) { | 141 THREADED_TEST(GlobalVariableAccess) { |
122 foo = 0; | 142 foo = 0; |
123 bar = -4; | 143 bar = -4; |
124 baz = 10; | 144 baz = 10; |
125 v8::Isolate* isolate = CcTest::isolate(); | 145 v8::Isolate* isolate = CcTest::isolate(); |
126 v8::HandleScope scope(isolate); | 146 v8::HandleScope scope(isolate); |
127 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 147 v8::Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
128 templ->InstanceTemplate()->SetAccessor( | 148 templ->InstanceTemplate()->SetAccessor( |
129 v8_str("foo"), GetIntValue, SetIntValue, | 149 v8_str("foo"), GetIntValue, SetIntValue, |
130 v8::External::New(isolate, &foo)); | 150 v8::External::New(isolate, &foo)); |
131 templ->InstanceTemplate()->SetAccessor( | 151 templ->InstanceTemplate()->SetAccessor( |
132 v8_str("bar"), GetIntValue, SetIntValue, | 152 v8_str("bar"), GetIntValue, SetIntValue, |
133 v8::External::New(isolate, &bar)); | 153 v8::External::New(isolate, &bar)); |
134 templ->InstanceTemplate()->SetAccessor( | 154 templ->InstanceTemplate()->SetAccessor( |
135 v8_str("baz"), GetIntValue, SetIntValue, | 155 v8_str("baz"), GetIntValue, SetIntValue, |
136 v8::External::New(isolate, &baz)); | 156 v8::External::New(isolate, &baz)); |
137 LocalContext env(0, templ->InstanceTemplate()); | 157 LocalContext env(0, templ->InstanceTemplate()); |
138 v8_compile("foo = (++bar) + baz")->Run(); | 158 v8_compile("foo = (++bar) + baz")->Run(env.local()).ToLocalChecked(); |
139 CHECK_EQ(bar, -3); | 159 CHECK_EQ(bar, -3); |
140 CHECK_EQ(foo, 7); | 160 CHECK_EQ(foo, 7); |
141 } | 161 } |
142 | 162 |
143 | 163 |
144 static int x_register[2] = {0, 0}; | 164 static int x_register[2] = {0, 0}; |
145 static v8::Handle<v8::Object> x_receiver; | 165 static v8::Local<v8::Object> x_receiver; |
146 static v8::Handle<v8::Object> x_holder; | 166 static v8::Local<v8::Object> x_holder; |
147 | 167 |
148 template<class Info> | 168 template<class Info> |
149 static void XGetter(const Info& info, int offset) { | 169 static void XGetter(const Info& info, int offset) { |
150 ApiTestFuzzer::Fuzz(); | 170 ApiTestFuzzer::Fuzz(); |
151 v8::Isolate* isolate = CcTest::isolate(); | 171 v8::Isolate* isolate = CcTest::isolate(); |
152 CHECK_EQ(isolate, info.GetIsolate()); | 172 CHECK_EQ(isolate, info.GetIsolate()); |
153 CHECK(x_receiver->Equals(info.This())); | 173 CHECK( |
174 x_receiver->Equals(isolate->GetCurrentContext(), info.This()).FromJust()); | |
154 info.GetReturnValue().Set(v8_num(x_register[offset])); | 175 info.GetReturnValue().Set(v8_num(x_register[offset])); |
155 } | 176 } |
156 | 177 |
157 | 178 |
158 static void XGetter(Local<String> name, | 179 static void XGetter(Local<String> name, |
159 const v8::PropertyCallbackInfo<v8::Value>& info) { | 180 const v8::PropertyCallbackInfo<v8::Value>& info) { |
160 CHECK(x_holder->Equals(info.Holder())); | 181 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder()) |
182 .FromJust()); | |
161 XGetter(info, 0); | 183 XGetter(info, 0); |
162 } | 184 } |
163 | 185 |
164 | 186 |
165 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 187 static void XGetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
166 CHECK(x_receiver->Equals(info.Holder())); | 188 CHECK( |
189 x_receiver->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder()) | |
190 .FromJust()); | |
167 XGetter(info, 1); | 191 XGetter(info, 1); |
168 } | 192 } |
169 | 193 |
170 | 194 |
171 template<class Info> | 195 template<class Info> |
172 static void XSetter(Local<Value> value, const Info& info, int offset) { | 196 static void XSetter(Local<Value> value, const Info& info, int offset) { |
173 v8::Isolate* isolate = CcTest::isolate(); | 197 v8::Isolate* isolate = CcTest::isolate(); |
174 CHECK_EQ(isolate, info.GetIsolate()); | 198 CHECK_EQ(isolate, info.GetIsolate()); |
175 CHECK(x_holder->Equals(info.This())); | 199 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.This()) |
176 CHECK(x_holder->Equals(info.Holder())); | 200 .FromJust()); |
177 x_register[offset] = value->Int32Value(); | 201 CHECK(x_holder->Equals(info.GetIsolate()->GetCurrentContext(), info.Holder()) |
202 .FromJust()); | |
203 x_register[offset] = | |
204 value->Int32Value(info.GetIsolate()->GetCurrentContext()).FromJust(); | |
178 info.GetReturnValue().Set(v8_num(-1)); | 205 info.GetReturnValue().Set(v8_num(-1)); |
179 } | 206 } |
180 | 207 |
181 | 208 |
182 static void XSetter(Local<String> name, | 209 static void XSetter(Local<String> name, |
183 Local<Value> value, | 210 Local<Value> value, |
184 const v8::PropertyCallbackInfo<void>& info) { | 211 const v8::PropertyCallbackInfo<void>& info) { |
185 XSetter(value, info, 0); | 212 XSetter(value, info, 0); |
186 } | 213 } |
187 | 214 |
188 | 215 |
189 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { | 216 static void XSetter(const v8::FunctionCallbackInfo<v8::Value>& info) { |
190 CHECK_EQ(1, info.Length()); | 217 CHECK_EQ(1, info.Length()); |
191 XSetter(info[0], info, 1); | 218 XSetter(info[0], info, 1); |
192 } | 219 } |
193 | 220 |
194 | 221 |
195 THREADED_TEST(AccessorIC) { | 222 THREADED_TEST(AccessorIC) { |
196 LocalContext context; | 223 LocalContext context; |
197 v8::Isolate* isolate = context->GetIsolate(); | 224 v8::Isolate* isolate = context->GetIsolate(); |
198 v8::HandleScope scope(isolate); | 225 v8::HandleScope scope(isolate); |
199 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 226 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
200 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); | 227 obj->SetAccessor(v8_str("x0"), XGetter, XSetter); |
201 obj->SetAccessorProperty(v8_str("x1"), | 228 obj->SetAccessorProperty(v8_str("x1"), |
202 v8::FunctionTemplate::New(isolate, XGetter), | 229 v8::FunctionTemplate::New(isolate, XGetter), |
203 v8::FunctionTemplate::New(isolate, XSetter)); | 230 v8::FunctionTemplate::New(isolate, XSetter)); |
204 x_holder = obj->NewInstance(); | 231 x_holder = obj->NewInstance(context.local()).ToLocalChecked(); |
205 context->Global()->Set(v8_str("holder"), x_holder); | 232 CHECK(context->Global() |
233 ->Set(context.local(), v8_str("holder"), x_holder) | |
234 .FromJust()); | |
206 x_receiver = v8::Object::New(isolate); | 235 x_receiver = v8::Object::New(isolate); |
207 context->Global()->Set(v8_str("obj"), x_receiver); | 236 CHECK(context->Global() |
208 v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(CompileRun( | 237 ->Set(context.local(), v8_str("obj"), x_receiver) |
209 "obj.__proto__ = holder;" | 238 .FromJust()); |
210 "var result = [];" | 239 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( |
211 "var key_0 = 'x0';" | 240 CompileRun("obj.__proto__ = holder;" |
212 "var key_1 = 'x1';" | 241 "var result = [];" |
213 "for (var j = 0; j < 10; j++) {" | 242 "var key_0 = 'x0';" |
214 " var i = 4*j;" | 243 "var key_1 = 'x1';" |
215 " result.push(holder.x0 = i);" | 244 "for (var j = 0; j < 10; j++) {" |
216 " result.push(obj.x0);" | 245 " var i = 4*j;" |
217 " result.push(holder.x1 = i + 1);" | 246 " result.push(holder.x0 = i);" |
218 " result.push(obj.x1);" | 247 " result.push(obj.x0);" |
219 " result.push(holder[key_0] = i + 2);" | 248 " result.push(holder.x1 = i + 1);" |
220 " result.push(obj[key_0]);" | 249 " result.push(obj.x1);" |
221 " result.push(holder[key_1] = i + 3);" | 250 " result.push(holder[key_0] = i + 2);" |
222 " result.push(obj[key_1]);" | 251 " result.push(obj[key_0]);" |
223 "}" | 252 " result.push(holder[key_1] = i + 3);" |
224 "result")); | 253 " result.push(obj[key_1]);" |
254 "}" | |
255 "result")); | |
225 CHECK_EQ(80u, array->Length()); | 256 CHECK_EQ(80u, array->Length()); |
226 for (int i = 0; i < 80; i++) { | 257 for (int i = 0; i < 80; i++) { |
227 v8::Handle<Value> entry = array->Get(v8::Integer::New(isolate, i)); | 258 v8::Local<Value> entry = |
228 CHECK(v8::Integer::New(isolate, i / 2)->Equals(entry)); | 259 array->Get(context.local(), v8::Integer::New(isolate, i)) |
260 .ToLocalChecked(); | |
261 CHECK(v8::Integer::New(isolate, i / 2) | |
262 ->Equals(context.local(), entry) | |
263 .FromJust()); | |
229 } | 264 } |
230 } | 265 } |
231 | 266 |
232 | 267 |
233 template <int C> | 268 template <int C> |
234 static void HandleAllocatingGetter( | 269 static void HandleAllocatingGetter( |
235 Local<String> name, | 270 Local<String> name, |
236 const v8::PropertyCallbackInfo<v8::Value>& info) { | 271 const v8::PropertyCallbackInfo<v8::Value>& info) { |
237 ApiTestFuzzer::Fuzz(); | 272 ApiTestFuzzer::Fuzz(); |
238 for (int i = 0; i < C; i++) | 273 for (int i = 0; i < C; i++) { |
239 v8::String::NewFromUtf8(info.GetIsolate(), "foo"); | 274 v8::String::NewFromUtf8(info.GetIsolate(), "foo", |
240 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo")); | 275 v8::NewStringType::kNormal) |
276 .ToLocalChecked(); | |
277 } | |
278 info.GetReturnValue().Set(v8::String::NewFromUtf8(info.GetIsolate(), "foo", | |
279 v8::NewStringType::kNormal) | |
280 .ToLocalChecked()); | |
241 } | 281 } |
242 | 282 |
243 | 283 |
244 THREADED_TEST(HandleScopePop) { | 284 THREADED_TEST(HandleScopePop) { |
245 LocalContext context; | 285 LocalContext context; |
246 v8::Isolate* isolate = context->GetIsolate(); | 286 v8::Isolate* isolate = context->GetIsolate(); |
247 v8::HandleScope scope(isolate); | 287 v8::HandleScope scope(isolate); |
248 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 288 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
249 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); | 289 obj->SetAccessor(v8_str("one"), HandleAllocatingGetter<1>); |
250 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); | 290 obj->SetAccessor(v8_str("many"), HandleAllocatingGetter<1024>); |
251 v8::Handle<v8::Object> inst = obj->NewInstance(); | 291 v8::Local<v8::Object> inst = |
252 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 292 obj->NewInstance(context.local()).ToLocalChecked(); |
293 CHECK( | |
294 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust()); | |
253 int count_before = | 295 int count_before = |
254 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); | 296 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); |
255 { | 297 { |
256 v8::HandleScope scope(isolate); | 298 v8::HandleScope scope(isolate); |
257 CompileRun( | 299 CompileRun( |
258 "for (var i = 0; i < 1000; i++) {" | 300 "for (var i = 0; i < 1000; i++) {" |
259 " obj.one;" | 301 " obj.one;" |
260 " obj.many;" | 302 " obj.many;" |
261 "}"); | 303 "}"); |
262 } | 304 } |
263 int count_after = | 305 int count_after = |
264 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); | 306 i::HandleScope::NumberOfHandles(reinterpret_cast<i::Isolate*>(isolate)); |
265 CHECK_EQ(count_before, count_after); | 307 CHECK_EQ(count_before, count_after); |
266 } | 308 } |
267 | 309 |
268 static void CheckAccessorArgsCorrect( | 310 static void CheckAccessorArgsCorrect( |
269 Local<String> name, | 311 Local<String> name, |
270 const v8::PropertyCallbackInfo<v8::Value>& info) { | 312 const v8::PropertyCallbackInfo<v8::Value>& info) { |
271 CHECK(info.GetIsolate() == CcTest::isolate()); | 313 CHECK(info.GetIsolate() == CcTest::isolate()); |
272 CHECK(info.This() == info.Holder()); | 314 CHECK(info.This() == info.Holder()); |
273 CHECK( | 315 CHECK(info.Data() |
274 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 316 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data")) |
317 .FromJust()); | |
275 ApiTestFuzzer::Fuzz(); | 318 ApiTestFuzzer::Fuzz(); |
276 CHECK(info.GetIsolate() == CcTest::isolate()); | 319 CHECK(info.GetIsolate() == CcTest::isolate()); |
277 CHECK(info.This() == info.Holder()); | 320 CHECK(info.This() == info.Holder()); |
278 CHECK( | 321 CHECK(info.Data() |
279 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 322 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data")) |
323 .FromJust()); | |
280 CcTest::heap()->CollectAllGarbage(); | 324 CcTest::heap()->CollectAllGarbage(); |
281 CHECK(info.GetIsolate() == CcTest::isolate()); | 325 CHECK(info.GetIsolate() == CcTest::isolate()); |
282 CHECK(info.This() == info.Holder()); | 326 CHECK(info.This() == info.Holder()); |
283 CHECK( | 327 CHECK(info.Data() |
284 info.Data()->Equals(v8::String::NewFromUtf8(CcTest::isolate(), "data"))); | 328 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("data")) |
329 .FromJust()); | |
285 info.GetReturnValue().Set(17); | 330 info.GetReturnValue().Set(17); |
286 } | 331 } |
287 | 332 |
288 | 333 |
289 THREADED_TEST(DirectCall) { | 334 THREADED_TEST(DirectCall) { |
290 LocalContext context; | 335 LocalContext context; |
291 v8::Isolate* isolate = context->GetIsolate(); | 336 v8::Isolate* isolate = context->GetIsolate(); |
292 v8::HandleScope scope(isolate); | 337 v8::HandleScope scope(isolate); |
293 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 338 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
294 obj->SetAccessor(v8_str("xxx"), | 339 obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL, |
295 CheckAccessorArgsCorrect, | 340 v8_str("data")); |
296 NULL, | 341 v8::Local<v8::Object> inst = |
297 v8::String::NewFromUtf8(isolate, "data")); | 342 obj->NewInstance(context.local()).ToLocalChecked(); |
298 v8::Handle<v8::Object> inst = obj->NewInstance(); | 343 CHECK( |
299 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), | 344 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust()); |
300 inst); | 345 Local<Script> scr = |
301 Local<Script> scr = v8::Script::Compile( | 346 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++) { | 347 for (int i = 0; i < 10; i++) { |
304 Local<Value> result = scr->Run(); | 348 Local<Value> result = scr->Run(context.local()).ToLocalChecked(); |
305 CHECK(!result.IsEmpty()); | 349 CHECK(!result.IsEmpty()); |
306 CHECK_EQ(17, result->Int32Value()); | 350 CHECK_EQ(17, result->Int32Value(context.local()).FromJust()); |
307 } | 351 } |
308 } | 352 } |
309 | 353 |
310 static void EmptyGetter(Local<String> name, | 354 static void EmptyGetter(Local<String> name, |
311 const v8::PropertyCallbackInfo<v8::Value>& info) { | 355 const v8::PropertyCallbackInfo<v8::Value>& info) { |
312 CheckAccessorArgsCorrect(name, info); | 356 CheckAccessorArgsCorrect(name, info); |
313 ApiTestFuzzer::Fuzz(); | 357 ApiTestFuzzer::Fuzz(); |
314 CheckAccessorArgsCorrect(name, info); | 358 CheckAccessorArgsCorrect(name, info); |
315 info.GetReturnValue().Set(v8::Handle<v8::Value>()); | 359 info.GetReturnValue().Set(v8::Local<v8::Value>()); |
316 } | 360 } |
317 | 361 |
318 | 362 |
319 THREADED_TEST(EmptyResult) { | 363 THREADED_TEST(EmptyResult) { |
320 LocalContext context; | 364 LocalContext context; |
321 v8::Isolate* isolate = context->GetIsolate(); | 365 v8::Isolate* isolate = context->GetIsolate(); |
322 v8::HandleScope scope(isolate); | 366 v8::HandleScope scope(isolate); |
323 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 367 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
324 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, | 368 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data")); |
325 v8::String::NewFromUtf8(isolate, "data")); | 369 v8::Local<v8::Object> inst = |
326 v8::Handle<v8::Object> inst = obj->NewInstance(); | 370 obj->NewInstance(context.local()).ToLocalChecked(); |
327 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 371 CHECK( |
372 context->Global()->Set(context.local(), v8_str("obj"), inst).FromJust()); | |
328 Local<Script> scr = | 373 Local<Script> scr = |
329 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 374 v8::Script::Compile(context.local(), v8_str("obj.xxx")).ToLocalChecked(); |
330 for (int i = 0; i < 10; i++) { | 375 for (int i = 0; i < 10; i++) { |
331 Local<Value> result = scr->Run(); | 376 Local<Value> result = scr->Run(context.local()).ToLocalChecked(); |
332 CHECK(result == v8::Undefined(isolate)); | 377 CHECK(result == v8::Undefined(isolate)); |
333 } | 378 } |
334 } | 379 } |
335 | 380 |
336 | 381 |
337 THREADED_TEST(NoReuseRegress) { | 382 THREADED_TEST(NoReuseRegress) { |
338 // Check that the IC generated for the one test doesn't get reused | 383 // Check that the IC generated for the one test doesn't get reused |
339 // for the other. | 384 // for the other. |
340 v8::Isolate* isolate = CcTest::isolate(); | 385 v8::Isolate* isolate = CcTest::isolate(); |
341 v8::HandleScope scope(isolate); | 386 v8::HandleScope scope(isolate); |
342 { | 387 { |
343 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 388 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
344 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, | 389 obj->SetAccessor(v8_str("xxx"), EmptyGetter, NULL, v8_str("data")); |
345 v8::String::NewFromUtf8(isolate, "data")); | |
346 LocalContext context; | 390 LocalContext context; |
347 v8::Handle<v8::Object> inst = obj->NewInstance(); | 391 v8::Local<v8::Object> inst = |
348 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 392 obj->NewInstance(context.local()).ToLocalChecked(); |
349 Local<Script> scr = | 393 CHECK(context->Global() |
350 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 394 ->Set(context.local(), v8_str("obj"), inst) |
395 .FromJust()); | |
396 Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx")) | |
397 .ToLocalChecked(); | |
351 for (int i = 0; i < 2; i++) { | 398 for (int i = 0; i < 2; i++) { |
352 Local<Value> result = scr->Run(); | 399 Local<Value> result = scr->Run(context.local()).ToLocalChecked(); |
353 CHECK(result == v8::Undefined(isolate)); | 400 CHECK(result == v8::Undefined(isolate)); |
354 } | 401 } |
355 } | 402 } |
356 { | 403 { |
357 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 404 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
358 obj->SetAccessor(v8_str("xxx"), | 405 obj->SetAccessor(v8_str("xxx"), CheckAccessorArgsCorrect, NULL, |
359 CheckAccessorArgsCorrect, | 406 v8_str("data")); |
360 NULL, | |
361 v8::String::NewFromUtf8(isolate, "data")); | |
362 LocalContext context; | 407 LocalContext context; |
363 v8::Handle<v8::Object> inst = obj->NewInstance(); | 408 v8::Local<v8::Object> inst = |
364 context->Global()->Set(v8::String::NewFromUtf8(isolate, "obj"), inst); | 409 obj->NewInstance(context.local()).ToLocalChecked(); |
365 Local<Script> scr = | 410 CHECK(context->Global() |
366 v8::Script::Compile(v8::String::NewFromUtf8(isolate, "obj.xxx")); | 411 ->Set(context.local(), v8_str("obj"), inst) |
412 .FromJust()); | |
413 Local<Script> scr = v8::Script::Compile(context.local(), v8_str("obj.xxx")) | |
414 .ToLocalChecked(); | |
367 for (int i = 0; i < 10; i++) { | 415 for (int i = 0; i < 10; i++) { |
368 Local<Value> result = scr->Run(); | 416 Local<Value> result = scr->Run(context.local()).ToLocalChecked(); |
369 CHECK(!result.IsEmpty()); | 417 CHECK(!result.IsEmpty()); |
370 CHECK_EQ(17, result->Int32Value()); | 418 CHECK_EQ(17, result->Int32Value(context.local()).FromJust()); |
371 } | 419 } |
372 } | 420 } |
373 } | 421 } |
374 | 422 |
375 static void ThrowingGetAccessor( | 423 static void ThrowingGetAccessor( |
376 Local<String> name, | 424 Local<String> name, |
377 const v8::PropertyCallbackInfo<v8::Value>& info) { | 425 const v8::PropertyCallbackInfo<v8::Value>& info) { |
378 ApiTestFuzzer::Fuzz(); | 426 ApiTestFuzzer::Fuzz(); |
379 info.GetIsolate()->ThrowException(v8_str("g")); | 427 info.GetIsolate()->ThrowException(v8_str("g")); |
380 } | 428 } |
381 | 429 |
382 | 430 |
383 static void ThrowingSetAccessor(Local<String> name, | 431 static void ThrowingSetAccessor(Local<String> name, |
384 Local<Value> value, | 432 Local<Value> value, |
385 const v8::PropertyCallbackInfo<void>& info) { | 433 const v8::PropertyCallbackInfo<void>& info) { |
386 info.GetIsolate()->ThrowException(value); | 434 info.GetIsolate()->ThrowException(value); |
387 } | 435 } |
388 | 436 |
389 | 437 |
390 THREADED_TEST(Regress1054726) { | 438 THREADED_TEST(Regress1054726) { |
391 LocalContext env; | 439 LocalContext env; |
392 v8::Isolate* isolate = env->GetIsolate(); | 440 v8::Isolate* isolate = env->GetIsolate(); |
393 v8::HandleScope scope(isolate); | 441 v8::HandleScope scope(isolate); |
394 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 442 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
395 obj->SetAccessor(v8_str("x"), | 443 obj->SetAccessor(v8_str("x"), |
396 ThrowingGetAccessor, | 444 ThrowingGetAccessor, |
397 ThrowingSetAccessor, | 445 ThrowingSetAccessor, |
398 Local<Value>()); | 446 Local<Value>()); |
399 | 447 |
400 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 448 CHECK(env->Global() |
449 ->Set(env.local(), v8_str("obj"), | |
450 obj->NewInstance(env.local()).ToLocalChecked()) | |
451 .FromJust()); | |
401 | 452 |
402 // Use the throwing property setter/getter in a loop to force | 453 // Use the throwing property setter/getter in a loop to force |
403 // the accessor ICs to be initialized. | 454 // the accessor ICs to be initialized. |
404 v8::Handle<Value> result; | 455 v8::Local<Value> result; |
405 result = Script::Compile(v8_str( | 456 result = Script::Compile(env.local(), |
406 "var result = '';" | 457 v8_str("var result = '';" |
407 "for (var i = 0; i < 5; i++) {" | 458 "for (var i = 0; i < 5; i++) {" |
408 " try { obj.x; } catch (e) { result += e; }" | 459 " try { obj.x; } catch (e) { result += e; }" |
409 "}; result"))->Run(); | 460 "}; result")) |
410 CHECK(v8_str("ggggg")->Equals(result)); | 461 .ToLocalChecked() |
462 ->Run(env.local()) | |
463 .ToLocalChecked(); | |
464 CHECK(v8_str("ggggg")->Equals(env.local(), result).FromJust()); | |
411 | 465 |
412 result = Script::Compile(String::NewFromUtf8( | 466 result = |
413 isolate, | 467 Script::Compile(env.local(), |
414 "var result = '';" | 468 v8_str("var result = '';" |
415 "for (var i = 0; i < 5; i++) {" | 469 "for (var i = 0; i < 5; i++) {" |
416 " try { obj.x = i; } catch (e) { result += e; }" | 470 " try { obj.x = i; } catch (e) { result += e; }" |
417 "}; result"))->Run(); | 471 "}; result")) |
418 CHECK(v8_str("01234")->Equals(result)); | 472 .ToLocalChecked() |
473 ->Run(env.local()) | |
474 .ToLocalChecked(); | |
475 CHECK(v8_str("01234")->Equals(env.local(), result).FromJust()); | |
419 } | 476 } |
420 | 477 |
421 | 478 |
422 static void AllocGetter(Local<String> name, | 479 static void AllocGetter(Local<String> name, |
423 const v8::PropertyCallbackInfo<v8::Value>& info) { | 480 const v8::PropertyCallbackInfo<v8::Value>& info) { |
424 ApiTestFuzzer::Fuzz(); | 481 ApiTestFuzzer::Fuzz(); |
425 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000)); | 482 info.GetReturnValue().Set(v8::Array::New(info.GetIsolate(), 1000)); |
426 } | 483 } |
427 | 484 |
428 | 485 |
429 THREADED_TEST(Gc) { | 486 THREADED_TEST(Gc) { |
430 LocalContext env; | 487 LocalContext env; |
431 v8::Isolate* isolate = env->GetIsolate(); | 488 v8::Isolate* isolate = env->GetIsolate(); |
432 v8::HandleScope scope(isolate); | 489 v8::HandleScope scope(isolate); |
433 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 490 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
434 obj->SetAccessor(v8_str("xxx"), AllocGetter); | 491 obj->SetAccessor(v8_str("xxx"), AllocGetter); |
435 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 492 CHECK(env->Global() |
436 Script::Compile(String::NewFromUtf8( | 493 ->Set(env.local(), v8_str("obj"), |
437 isolate, | 494 obj->NewInstance(env.local()).ToLocalChecked()) |
438 "var last = [];" | 495 .FromJust()); |
439 "for (var i = 0; i < 2048; i++) {" | 496 Script::Compile(env.local(), v8_str("var last = [];" |
440 " var result = obj.xxx;" | 497 "for (var i = 0; i < 2048; i++) {" |
441 " result[0] = last;" | 498 " var result = obj.xxx;" |
442 " last = result;" | 499 " result[0] = last;" |
443 "}"))->Run(); | 500 " last = result;" |
501 "}")) | |
502 .ToLocalChecked() | |
503 ->Run(env.local()) | |
504 .ToLocalChecked(); | |
444 } | 505 } |
445 | 506 |
446 | 507 |
447 static void StackCheck(Local<String> name, | 508 static void StackCheck(Local<String> name, |
448 const v8::PropertyCallbackInfo<v8::Value>& info) { | 509 const v8::PropertyCallbackInfo<v8::Value>& info) { |
449 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); | 510 i::StackFrameIterator iter(reinterpret_cast<i::Isolate*>(info.GetIsolate())); |
450 for (int i = 0; !iter.done(); i++) { | 511 for (int i = 0; !iter.done(); i++) { |
451 i::StackFrame* frame = iter.frame(); | 512 i::StackFrame* frame = iter.frame(); |
452 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); | 513 CHECK(i != 0 || (frame->type() == i::StackFrame::EXIT)); |
453 i::Code* code = frame->LookupCode(); | 514 i::Code* code = frame->LookupCode(); |
454 CHECK(code->IsCode()); | 515 CHECK(code->IsCode()); |
455 i::Address pc = frame->pc(); | 516 i::Address pc = frame->pc(); |
456 CHECK(code->contains(pc)); | 517 CHECK(code->contains(pc)); |
457 iter.Advance(); | 518 iter.Advance(); |
458 } | 519 } |
459 } | 520 } |
460 | 521 |
461 | 522 |
462 THREADED_TEST(StackIteration) { | 523 THREADED_TEST(StackIteration) { |
463 LocalContext env; | 524 LocalContext env; |
464 v8::Isolate* isolate = env->GetIsolate(); | 525 v8::Isolate* isolate = env->GetIsolate(); |
465 v8::HandleScope scope(isolate); | 526 v8::HandleScope scope(isolate); |
466 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 527 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
467 i::StringStream::ClearMentionedObjectCache( | 528 i::StringStream::ClearMentionedObjectCache( |
468 reinterpret_cast<i::Isolate*>(isolate)); | 529 reinterpret_cast<i::Isolate*>(isolate)); |
469 obj->SetAccessor(v8_str("xxx"), StackCheck); | 530 obj->SetAccessor(v8_str("xxx"), StackCheck); |
470 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 531 CHECK(env->Global() |
471 Script::Compile(String::NewFromUtf8( | 532 ->Set(env.local(), v8_str("obj"), |
472 isolate, | 533 obj->NewInstance(env.local()).ToLocalChecked()) |
473 "function foo() {" | 534 .FromJust()); |
474 " return obj.xxx;" | 535 Script::Compile(env.local(), v8_str("function foo() {" |
475 "}" | 536 " return obj.xxx;" |
476 "for (var i = 0; i < 100; i++) {" | 537 "}" |
477 " foo();" | 538 "for (var i = 0; i < 100; i++) {" |
478 "}"))->Run(); | 539 " foo();" |
540 "}")) | |
541 .ToLocalChecked() | |
542 ->Run(env.local()) | |
543 .ToLocalChecked(); | |
479 } | 544 } |
480 | 545 |
481 | 546 |
482 static void AllocateHandles(Local<String> name, | 547 static void AllocateHandles(Local<String> name, |
483 const v8::PropertyCallbackInfo<v8::Value>& info) { | 548 const v8::PropertyCallbackInfo<v8::Value>& info) { |
484 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { | 549 for (int i = 0; i < i::kHandleBlockSize + 1; i++) { |
485 v8::Local<v8::Value>::New(info.GetIsolate(), name); | 550 v8::Local<v8::Value>::New(info.GetIsolate(), name); |
486 } | 551 } |
487 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100)); | 552 info.GetReturnValue().Set(v8::Integer::New(info.GetIsolate(), 100)); |
488 } | 553 } |
489 | 554 |
490 | 555 |
491 THREADED_TEST(HandleScopeSegment) { | 556 THREADED_TEST(HandleScopeSegment) { |
492 // Check that we can return values past popping of handle scope | 557 // Check that we can return values past popping of handle scope |
493 // segments. | 558 // segments. |
494 LocalContext env; | 559 LocalContext env; |
495 v8::Isolate* isolate = env->GetIsolate(); | 560 v8::Isolate* isolate = env->GetIsolate(); |
496 v8::HandleScope scope(isolate); | 561 v8::HandleScope scope(isolate); |
497 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 562 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
498 obj->SetAccessor(v8_str("xxx"), AllocateHandles); | 563 obj->SetAccessor(v8_str("xxx"), AllocateHandles); |
499 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 564 CHECK(env->Global() |
500 v8::Handle<v8::Value> result = Script::Compile(String::NewFromUtf8( | 565 ->Set(env.local(), v8_str("obj"), |
501 isolate, | 566 obj->NewInstance(env.local()).ToLocalChecked()) |
502 "var result;" | 567 .FromJust()); |
503 "for (var i = 0; i < 4; i++)" | 568 v8::Local<v8::Value> result = |
504 " result = obj.xxx;" | 569 Script::Compile(env.local(), v8_str("var result;" |
505 "result;"))->Run(); | 570 "for (var i = 0; i < 4; i++)" |
506 CHECK_EQ(100, result->Int32Value()); | 571 " result = obj.xxx;" |
572 "result;")) | |
573 .ToLocalChecked() | |
574 ->Run(env.local()) | |
575 .ToLocalChecked(); | |
576 CHECK_EQ(100, result->Int32Value(env.local()).FromJust()); | |
507 } | 577 } |
508 | 578 |
509 | 579 |
510 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 580 void JSONStringifyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
511 v8::Handle<v8::Array> array = v8::Array::New(info.GetIsolate(), 1); | 581 v8::Local<v8::Array> array = v8::Array::New(info.GetIsolate(), 1); |
512 array->Set(0, v8_str("regress")); | 582 CHECK(array->Set(info.GetIsolate()->GetCurrentContext(), 0, v8_str("regress")) |
583 .FromJust()); | |
513 info.GetReturnValue().Set(array); | 584 info.GetReturnValue().Set(array); |
514 } | 585 } |
515 | 586 |
516 | 587 |
517 void JSONStringifyGetter(Local<Name> name, | 588 void JSONStringifyGetter(Local<Name> name, |
518 const v8::PropertyCallbackInfo<v8::Value>& info) { | 589 const v8::PropertyCallbackInfo<v8::Value>& info) { |
519 info.GetReturnValue().Set(v8_str("crbug-161028")); | 590 info.GetReturnValue().Set(v8_str("crbug-161028")); |
520 } | 591 } |
521 | 592 |
522 | 593 |
523 THREADED_TEST(JSONStringifyNamedInterceptorObject) { | 594 THREADED_TEST(JSONStringifyNamedInterceptorObject) { |
524 LocalContext env; | 595 LocalContext env; |
525 v8::Isolate* isolate = env->GetIsolate(); | 596 v8::Isolate* isolate = env->GetIsolate(); |
526 v8::HandleScope scope(isolate); | 597 v8::HandleScope scope(isolate); |
527 | 598 |
528 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 599 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
529 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( | 600 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( |
530 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator)); | 601 JSONStringifyGetter, NULL, NULL, NULL, JSONStringifyEnumerator)); |
531 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 602 CHECK(env->Global() |
532 v8::Handle<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | 603 ->Set(env.local(), v8_str("obj"), |
533 CHECK(CompileRun("JSON.stringify(obj)")->Equals(expected)); | 604 obj->NewInstance(env.local()).ToLocalChecked()) |
605 .FromJust()); | |
606 v8::Local<v8::String> expected = v8_str("{\"regress\":\"crbug-161028\"}"); | |
607 CHECK(CompileRun("JSON.stringify(obj)") | |
608 ->Equals(env.local(), expected) | |
609 .FromJust()); | |
534 } | 610 } |
535 | 611 |
536 | 612 |
537 static v8::Local<v8::Context> expected_current_context; | 613 static v8::Local<v8::Context> expected_current_context; |
538 static v8::Local<v8::Context> expected_calling_context; | 614 static v8::Local<v8::Context> expected_calling_context; |
539 | 615 |
540 | 616 |
541 static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) { | 617 static void check_contexts(const v8::FunctionCallbackInfo<v8::Value>& info) { |
542 ApiTestFuzzer::Fuzz(); | 618 ApiTestFuzzer::Fuzz(); |
543 CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext()); | 619 CHECK(expected_current_context == info.GetIsolate()->GetCurrentContext()); |
544 CHECK(expected_calling_context == info.GetIsolate()->GetCallingContext()); | 620 CHECK(expected_calling_context == info.GetIsolate()->GetCallingContext()); |
545 } | 621 } |
546 | 622 |
547 | 623 |
548 THREADED_TEST(AccessorPropertyCrossContext) { | 624 THREADED_TEST(AccessorPropertyCrossContext) { |
549 LocalContext env; | 625 LocalContext env; |
550 v8::Isolate* isolate = env->GetIsolate(); | 626 v8::Isolate* isolate = env->GetIsolate(); |
551 v8::HandleScope scope(isolate); | 627 v8::HandleScope scope(isolate); |
552 v8::Handle<v8::Function> fun = v8::Function::New(isolate, check_contexts); | 628 v8::Local<v8::Function> fun = |
629 v8::Function::New(env.local(), check_contexts).ToLocalChecked(); | |
553 LocalContext switch_context; | 630 LocalContext switch_context; |
554 switch_context->Global()->Set(v8_str("fun"), fun); | 631 CHECK(switch_context->Global() |
632 ->Set(switch_context.local(), v8_str("fun"), fun) | |
633 .FromJust()); | |
555 v8::TryCatch try_catch(isolate); | 634 v8::TryCatch try_catch(isolate); |
556 expected_current_context = env.local(); | 635 expected_current_context = env.local(); |
557 expected_calling_context = switch_context.local(); | 636 expected_calling_context = switch_context.local(); |
558 CompileRun( | 637 CompileRun( |
559 "var o = Object.create(null, { n: { get:fun } });" | 638 "var o = Object.create(null, { n: { get:fun } });" |
560 "for (var i = 0; i < 10; i++) o.n;"); | 639 "for (var i = 0; i < 10; i++) o.n;"); |
561 CHECK(!try_catch.HasCaught()); | 640 CHECK(!try_catch.HasCaught()); |
562 } | 641 } |
563 | 642 |
564 | 643 |
(...skipping 25 matching lines...) Expand all Loading... | |
590 const v8::PropertyCallbackInfo<v8::Value>& info) { | 669 const v8::PropertyCallbackInfo<v8::Value>& info) { |
591 ApiTestFuzzer::Fuzz(); | 670 ApiTestFuzzer::Fuzz(); |
592 info.GetReturnValue().Set(v8_num(1)); | 671 info.GetReturnValue().Set(v8_num(1)); |
593 } | 672 } |
594 | 673 |
595 | 674 |
596 THREADED_TEST(Regress433458) { | 675 THREADED_TEST(Regress433458) { |
597 LocalContext env; | 676 LocalContext env; |
598 v8::Isolate* isolate = env->GetIsolate(); | 677 v8::Isolate* isolate = env->GetIsolate(); |
599 v8::HandleScope scope(isolate); | 678 v8::HandleScope scope(isolate); |
600 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 679 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
601 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(EmptyGetter)); | 680 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(EmptyGetter)); |
602 obj->SetNativeDataProperty(v8_str("prop"), OneProperty); | 681 obj->SetNativeDataProperty(v8_str("prop"), OneProperty); |
603 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 682 CHECK(env->Global() |
683 ->Set(env.local(), v8_str("obj"), | |
684 obj->NewInstance(env.local()).ToLocalChecked()) | |
685 .FromJust()); | |
604 CompileRun( | 686 CompileRun( |
605 "Object.defineProperty(obj, 'prop', { writable: false });" | 687 "Object.defineProperty(obj, 'prop', { writable: false });" |
606 "Object.defineProperty(obj, 'prop', { writable: true });"); | 688 "Object.defineProperty(obj, 'prop', { writable: true });"); |
607 } | 689 } |
608 | 690 |
609 | 691 |
610 static bool security_check_value = false; | 692 static bool security_check_value = false; |
611 | 693 |
612 | 694 |
613 static bool SecurityTestCallback(Local<v8::Context> accessing_context, | 695 static bool SecurityTestCallback(Local<v8::Context> accessing_context, |
614 Local<v8::Object> accessed_object) { | 696 Local<v8::Object> accessed_object) { |
615 return security_check_value; | 697 return security_check_value; |
616 } | 698 } |
617 | 699 |
618 | 700 |
619 TEST(PrototypeGetterAccessCheck) { | 701 TEST(PrototypeGetterAccessCheck) { |
620 i::FLAG_allow_natives_syntax = true; | 702 i::FLAG_allow_natives_syntax = true; |
621 LocalContext env; | 703 LocalContext env; |
622 v8::Isolate* isolate = env->GetIsolate(); | 704 v8::Isolate* isolate = env->GetIsolate(); |
623 v8::HandleScope scope(isolate); | 705 v8::HandleScope scope(isolate); |
624 auto fun_templ = v8::FunctionTemplate::New(isolate); | 706 auto fun_templ = v8::FunctionTemplate::New(isolate); |
625 auto getter_templ = v8::FunctionTemplate::New(isolate, handle_property); | 707 auto getter_templ = v8::FunctionTemplate::New(isolate, handle_property); |
626 getter_templ->SetAcceptAnyReceiver(false); | 708 getter_templ->SetAcceptAnyReceiver(false); |
627 fun_templ->InstanceTemplate()->SetAccessorProperty(v8_str("foo"), | 709 fun_templ->InstanceTemplate()->SetAccessorProperty(v8_str("foo"), |
628 getter_templ); | 710 getter_templ); |
629 auto obj_templ = v8::ObjectTemplate::New(isolate); | 711 auto obj_templ = v8::ObjectTemplate::New(isolate); |
630 obj_templ->SetAccessCheckCallback(SecurityTestCallback); | 712 obj_templ->SetAccessCheckCallback(SecurityTestCallback); |
631 env->Global()->Set(v8_str("Fun"), fun_templ->GetFunction()); | 713 CHECK(env->Global() |
632 env->Global()->Set(v8_str("obj"), obj_templ->NewInstance()); | 714 ->Set(env.local(), v8_str("Fun"), |
633 env->Global()->Set(v8_str("obj2"), obj_templ->NewInstance()); | 715 fun_templ->GetFunction(env.local()).ToLocalChecked()) |
716 .FromJust()); | |
717 CHECK(env->Global() | |
718 ->Set(env.local(), v8_str("obj"), | |
719 obj_templ->NewInstance(env.local()).ToLocalChecked()) | |
720 .FromJust()); | |
721 CHECK(env->Global() | |
722 ->Set(env.local(), v8_str("obj2"), | |
723 obj_templ->NewInstance(env.local()).ToLocalChecked()) | |
724 .FromJust()); | |
634 | 725 |
635 security_check_value = true; | 726 security_check_value = true; |
636 CompileRun("var proto = new Fun();"); | 727 CompileRun("var proto = new Fun();"); |
637 CompileRun("obj.__proto__ = proto;"); | 728 CompileRun("obj.__proto__ = proto;"); |
638 ExpectInt32("proto.foo", 907); | 729 ExpectInt32("proto.foo", 907); |
639 | 730 |
640 // Test direct. | 731 // Test direct. |
641 security_check_value = true; | 732 security_check_value = true; |
642 ExpectInt32("obj.foo", 907); | 733 ExpectInt32("obj.foo", 907); |
643 security_check_value = false; | 734 security_check_value = false; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 | 772 |
682 security_check_value = true; | 773 security_check_value = true; |
683 ExpectInt32("f()", 907); | 774 ExpectInt32("f()", 907); |
684 security_check_value = false; | 775 security_check_value = false; |
685 { | 776 { |
686 v8::TryCatch try_catch(isolate); | 777 v8::TryCatch try_catch(isolate); |
687 CompileRun("f();"); | 778 CompileRun("f();"); |
688 CHECK(try_catch.HasCaught()); | 779 CHECK(try_catch.HasCaught()); |
689 } | 780 } |
690 } | 781 } |
OLD | NEW |