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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 #include "test/cctest/heap-tester.h" | 53 #include "test/cctest/heap-tester.h" |
54 | 54 |
55 static const bool kLogThreading = false; | 55 static const bool kLogThreading = false; |
56 | 56 |
57 using ::v8::Boolean; | 57 using ::v8::Boolean; |
58 using ::v8::BooleanObject; | 58 using ::v8::BooleanObject; |
59 using ::v8::Context; | 59 using ::v8::Context; |
60 using ::v8::Extension; | 60 using ::v8::Extension; |
61 using ::v8::Function; | 61 using ::v8::Function; |
62 using ::v8::FunctionTemplate; | 62 using ::v8::FunctionTemplate; |
63 using ::v8::Handle; | |
64 using ::v8::HandleScope; | 63 using ::v8::HandleScope; |
65 using ::v8::Local; | 64 using ::v8::Local; |
66 using ::v8::Maybe; | 65 using ::v8::Maybe; |
67 using ::v8::Message; | 66 using ::v8::Message; |
68 using ::v8::MessageCallback; | 67 using ::v8::MessageCallback; |
69 using ::v8::Name; | 68 using ::v8::Name; |
70 using ::v8::None; | 69 using ::v8::None; |
71 using ::v8::Object; | 70 using ::v8::Object; |
72 using ::v8::ObjectTemplate; | 71 using ::v8::ObjectTemplate; |
73 using ::v8::Persistent; | 72 using ::v8::Persistent; |
(...skipping 13 matching lines...) Expand all Loading... | |
87 static void Test##Name(); \ | 86 static void Test##Name(); \ |
88 TEST(Name##WithProfiler) { \ | 87 TEST(Name##WithProfiler) { \ |
89 RunWithProfiler(&Test##Name); \ | 88 RunWithProfiler(&Test##Name); \ |
90 } \ | 89 } \ |
91 THREADED_TEST(Name) | 90 THREADED_TEST(Name) |
92 | 91 |
93 | 92 |
94 void RunWithProfiler(void (*test)()) { | 93 void RunWithProfiler(void (*test)()) { |
95 LocalContext env; | 94 LocalContext env; |
96 v8::HandleScope scope(env->GetIsolate()); | 95 v8::HandleScope scope(env->GetIsolate()); |
97 v8::Local<v8::String> profile_name = | 96 v8::Local<v8::String> profile_name = v8_str("my_profile1"); |
98 v8::String::NewFromUtf8(env->GetIsolate(), "my_profile1"); | |
99 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); | 97 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); |
100 | 98 |
101 cpu_profiler->StartProfiling(profile_name); | 99 cpu_profiler->StartProfiling(profile_name); |
102 (*test)(); | 100 (*test)(); |
103 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles(); | 101 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles(); |
104 } | 102 } |
105 | 103 |
106 | 104 |
107 static int signature_callback_count; | 105 static int signature_callback_count; |
108 static Local<Value> signature_expected_receiver; | 106 static Local<Value> signature_expected_receiver; |
109 static void IncrementingSignatureCallback( | 107 static void IncrementingSignatureCallback( |
110 const v8::FunctionCallbackInfo<v8::Value>& args) { | 108 const v8::FunctionCallbackInfo<v8::Value>& args) { |
111 ApiTestFuzzer::Fuzz(); | 109 ApiTestFuzzer::Fuzz(); |
112 signature_callback_count++; | 110 signature_callback_count++; |
113 CHECK(signature_expected_receiver->Equals(args.Holder())); | 111 CHECK(signature_expected_receiver->Equals( |
114 CHECK(signature_expected_receiver->Equals(args.This())); | 112 args.GetIsolate()->GetCurrentContext(), |
115 v8::Handle<v8::Array> result = | 113 args.Holder()) |
114 .FromJust()); | |
115 CHECK(signature_expected_receiver->Equals( | |
116 args.GetIsolate()->GetCurrentContext(), | |
117 args.This()) | |
118 .FromJust()); | |
119 v8::Local<v8::Array> result = | |
116 v8::Array::New(args.GetIsolate(), args.Length()); | 120 v8::Array::New(args.GetIsolate(), args.Length()); |
117 for (int i = 0; i < args.Length(); i++) | 121 for (int i = 0; i < args.Length(); i++) { |
118 result->Set(v8::Integer::New(args.GetIsolate(), i), args[i]); | 122 CHECK(result->Set(args.GetIsolate()->GetCurrentContext(), |
123 v8::Integer::New(args.GetIsolate(), i), args[i]) | |
124 .FromJust()); | |
125 } | |
119 args.GetReturnValue().Set(result); | 126 args.GetReturnValue().Set(result); |
120 } | 127 } |
121 | 128 |
122 | 129 |
123 static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) { | 130 static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) { |
124 info.GetReturnValue().Set(42); | 131 info.GetReturnValue().Set(42); |
125 } | 132 } |
126 | 133 |
127 | 134 |
128 // Tests that call v8::V8::Dispose() cannot be threaded. | 135 // Tests that call v8::V8::Dispose() cannot be threaded. |
(...skipping 18 matching lines...) Expand all Loading... | |
147 Local<Context> local_env; | 154 Local<Context> local_env; |
148 { | 155 { |
149 LocalContext env; | 156 LocalContext env; |
150 local_env = env.local(); | 157 local_env = env.local(); |
151 } | 158 } |
152 | 159 |
153 // Local context should still be live. | 160 // Local context should still be live. |
154 CHECK(!local_env.IsEmpty()); | 161 CHECK(!local_env.IsEmpty()); |
155 local_env->Enter(); | 162 local_env->Enter(); |
156 | 163 |
157 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); | 164 v8::Local<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); |
158 CHECK(!undef.IsEmpty()); | 165 CHECK(!undef.IsEmpty()); |
159 CHECK(undef->IsUndefined()); | 166 CHECK(undef->IsUndefined()); |
160 | 167 |
161 const char* source = "1 + 2 + 3"; | 168 const char* source = "1 + 2 + 3"; |
162 Local<Script> script = v8_compile(source); | 169 Local<Script> script = v8_compile(source); |
163 CHECK_EQ(6, script->Run()->Int32Value()); | 170 CHECK_EQ(6, v8_run_int32value(script)); |
164 | 171 |
165 local_env->Exit(); | 172 local_env->Exit(); |
166 } | 173 } |
167 | 174 |
168 | 175 |
169 THREADED_TEST(IsolateOfContext) { | 176 THREADED_TEST(IsolateOfContext) { |
170 v8::HandleScope scope(CcTest::isolate()); | 177 v8::HandleScope scope(CcTest::isolate()); |
171 v8::Handle<Context> env = Context::New(CcTest::isolate()); | 178 v8::Local<Context> env = Context::New(CcTest::isolate()); |
172 | 179 |
173 CHECK(!env->GetIsolate()->InContext()); | 180 CHECK(!env->GetIsolate()->InContext()); |
174 CHECK(env->GetIsolate() == CcTest::isolate()); | 181 CHECK(env->GetIsolate() == CcTest::isolate()); |
175 env->Enter(); | 182 env->Enter(); |
176 CHECK(env->GetIsolate()->InContext()); | 183 CHECK(env->GetIsolate()->InContext()); |
177 CHECK(env->GetIsolate() == CcTest::isolate()); | 184 CHECK(env->GetIsolate() == CcTest::isolate()); |
178 env->Exit(); | 185 env->Exit(); |
179 CHECK(!env->GetIsolate()->InContext()); | 186 CHECK(!env->GetIsolate()->InContext()); |
180 CHECK(env->GetIsolate() == CcTest::isolate()); | 187 CHECK(env->GetIsolate() == CcTest::isolate()); |
181 } | 188 } |
(...skipping 10 matching lines...) Expand all Loading... | |
192 signature_callback_count = 0; | 199 signature_callback_count = 0; |
193 signature_expected_receiver = receiver; | 200 signature_expected_receiver = receiver; |
194 bool expected_to_throw = receiver.IsEmpty(); | 201 bool expected_to_throw = receiver.IsEmpty(); |
195 v8::TryCatch try_catch(isolate); | 202 v8::TryCatch try_catch(isolate); |
196 CompileRun(source.start()); | 203 CompileRun(source.start()); |
197 CHECK_EQ(expected_to_throw, try_catch.HasCaught()); | 204 CHECK_EQ(expected_to_throw, try_catch.HasCaught()); |
198 if (!expected_to_throw) { | 205 if (!expected_to_throw) { |
199 CHECK_EQ(10, signature_callback_count); | 206 CHECK_EQ(10, signature_callback_count); |
200 } else { | 207 } else { |
201 CHECK(v8_str("TypeError: Illegal invocation") | 208 CHECK(v8_str("TypeError: Illegal invocation") |
202 ->Equals(try_catch.Exception()->ToString(isolate))); | 209 ->Equals(isolate->GetCurrentContext(), |
210 try_catch.Exception() | |
211 ->ToString(isolate->GetCurrentContext()) | |
212 .ToLocalChecked()) | |
213 .FromJust()); | |
203 } | 214 } |
204 } | 215 } |
205 | 216 |
206 | 217 |
207 THREADED_TEST(ReceiverSignature) { | 218 THREADED_TEST(ReceiverSignature) { |
208 LocalContext env; | 219 LocalContext env; |
209 v8::Isolate* isolate = env->GetIsolate(); | 220 v8::Isolate* isolate = env->GetIsolate(); |
210 v8::HandleScope scope(isolate); | 221 v8::HandleScope scope(isolate); |
211 // Setup templates. | 222 // Setup templates. |
212 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); | 223 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
213 v8::Handle<v8::Signature> sig = v8::Signature::New(isolate, fun); | 224 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun); |
214 v8::Handle<v8::FunctionTemplate> callback_sig = | 225 v8::Local<v8::FunctionTemplate> callback_sig = v8::FunctionTemplate::New( |
215 v8::FunctionTemplate::New( | 226 isolate, IncrementingSignatureCallback, Local<Value>(), sig); |
216 isolate, IncrementingSignatureCallback, Local<Value>(), sig); | 227 v8::Local<v8::FunctionTemplate> callback = |
217 v8::Handle<v8::FunctionTemplate> callback = | |
218 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback); | 228 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback); |
219 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate); | 229 v8::Local<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate); |
220 sub_fun->Inherit(fun); | 230 sub_fun->Inherit(fun); |
221 v8::Handle<v8::FunctionTemplate> unrel_fun = | 231 v8::Local<v8::FunctionTemplate> unrel_fun = |
222 v8::FunctionTemplate::New(isolate); | 232 v8::FunctionTemplate::New(isolate); |
223 // Install properties. | 233 // Install properties. |
224 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); | 234 v8::Local<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); |
225 fun_proto->Set(v8_str("prop_sig"), callback_sig); | 235 fun_proto->Set(v8_str("prop_sig"), callback_sig); |
226 fun_proto->Set(v8_str("prop"), callback); | 236 fun_proto->Set(v8_str("prop"), callback); |
227 fun_proto->SetAccessorProperty( | 237 fun_proto->SetAccessorProperty( |
228 v8_str("accessor_sig"), callback_sig, callback_sig); | 238 v8_str("accessor_sig"), callback_sig, callback_sig); |
229 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); | 239 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); |
230 // Instantiate templates. | 240 // Instantiate templates. |
231 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); | 241 Local<Value> fun_instance = |
232 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance(); | 242 fun->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked(); |
243 Local<Value> sub_fun_instance = | |
244 sub_fun->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked(); | |
233 // Setup global variables. | 245 // Setup global variables. |
234 env->Global()->Set(v8_str("Fun"), fun->GetFunction()); | 246 CHECK(env->Global() |
235 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); | 247 ->Set(env.local(), v8_str("Fun"), |
236 env->Global()->Set(v8_str("fun_instance"), fun_instance); | 248 fun->GetFunction(env.local()).ToLocalChecked()) |
237 env->Global()->Set(v8_str("sub_fun_instance"), sub_fun_instance); | 249 .FromJust()); |
250 CHECK(env->Global() | |
251 ->Set(env.local(), v8_str("UnrelFun"), | |
252 unrel_fun->GetFunction(env.local()).ToLocalChecked()) | |
253 .FromJust()); | |
254 CHECK(env->Global() | |
255 ->Set(env.local(), v8_str("fun_instance"), fun_instance) | |
256 .FromJust()); | |
257 CHECK(env->Global() | |
258 ->Set(env.local(), v8_str("sub_fun_instance"), sub_fun_instance) | |
259 .FromJust()); | |
238 CompileRun( | 260 CompileRun( |
239 "var accessor_sig_key = 'accessor_sig';" | 261 "var accessor_sig_key = 'accessor_sig';" |
240 "var accessor_key = 'accessor';" | 262 "var accessor_key = 'accessor';" |
241 "var prop_sig_key = 'prop_sig';" | 263 "var prop_sig_key = 'prop_sig';" |
242 "var prop_key = 'prop';" | 264 "var prop_key = 'prop';" |
243 "" | 265 "" |
244 "function copy_props(obj) {" | 266 "function copy_props(obj) {" |
245 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];" | 267 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];" |
246 " var source = Fun.prototype;" | 268 " var source = Fun.prototype;" |
247 " for (var i in keys) {" | 269 " for (var i in keys) {" |
(...skipping 28 matching lines...) Expand all Loading... | |
276 TestSignature("test_object.accessor_sig = 1;", test_object, isolate); | 298 TestSignature("test_object.accessor_sig = 1;", test_object, isolate); |
277 TestSignature("test_object[accessor_sig_key] = 1;", test_object, isolate); | 299 TestSignature("test_object[accessor_sig_key] = 1;", test_object, isolate); |
278 } | 300 } |
279 } | 301 } |
280 | 302 |
281 | 303 |
282 THREADED_TEST(HulIgennem) { | 304 THREADED_TEST(HulIgennem) { |
283 LocalContext env; | 305 LocalContext env; |
284 v8::Isolate* isolate = env->GetIsolate(); | 306 v8::Isolate* isolate = env->GetIsolate(); |
285 v8::HandleScope scope(isolate); | 307 v8::HandleScope scope(isolate); |
286 v8::Handle<v8::Primitive> undef = v8::Undefined(isolate); | 308 v8::Local<v8::Primitive> undef = v8::Undefined(isolate); |
287 Local<String> undef_str = undef->ToString(isolate); | 309 Local<String> undef_str = undef->ToString(env.local()).ToLocalChecked(); |
288 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1); | 310 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1); |
289 undef_str->WriteUtf8(value); | 311 undef_str->WriteUtf8(value); |
290 CHECK_EQ(0, strcmp(value, "undefined")); | 312 CHECK_EQ(0, strcmp(value, "undefined")); |
291 i::DeleteArray(value); | 313 i::DeleteArray(value); |
292 } | 314 } |
293 | 315 |
294 | 316 |
295 THREADED_TEST(Access) { | 317 THREADED_TEST(Access) { |
296 LocalContext env; | 318 LocalContext env; |
297 v8::Isolate* isolate = env->GetIsolate(); | 319 v8::Isolate* isolate = env->GetIsolate(); |
298 v8::HandleScope scope(isolate); | 320 v8::HandleScope scope(isolate); |
299 Local<v8::Object> obj = v8::Object::New(isolate); | 321 Local<v8::Object> obj = v8::Object::New(isolate); |
300 Local<Value> foo_before = obj->Get(v8_str("foo")); | 322 Local<Value> foo_before = |
323 obj->Get(env.local(), v8_str("foo")).ToLocalChecked(); | |
301 CHECK(foo_before->IsUndefined()); | 324 CHECK(foo_before->IsUndefined()); |
302 Local<String> bar_str = v8_str("bar"); | 325 Local<String> bar_str = v8_str("bar"); |
303 obj->Set(v8_str("foo"), bar_str); | 326 CHECK(obj->Set(env.local(), v8_str("foo"), bar_str).FromJust()); |
304 Local<Value> foo_after = obj->Get(v8_str("foo")); | 327 Local<Value> foo_after = |
328 obj->Get(env.local(), v8_str("foo")).ToLocalChecked(); | |
305 CHECK(!foo_after->IsUndefined()); | 329 CHECK(!foo_after->IsUndefined()); |
306 CHECK(foo_after->IsString()); | 330 CHECK(foo_after->IsString()); |
307 CHECK(bar_str->Equals(foo_after)); | 331 CHECK(bar_str->Equals(env.local(), foo_after).FromJust()); |
308 } | 332 } |
309 | 333 |
310 | 334 |
311 THREADED_TEST(AccessElement) { | 335 THREADED_TEST(AccessElement) { |
312 LocalContext env; | 336 LocalContext env; |
313 v8::HandleScope scope(env->GetIsolate()); | 337 v8::HandleScope scope(env->GetIsolate()); |
314 Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); | 338 Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); |
315 Local<Value> before = obj->Get(1); | 339 Local<Value> before = obj->Get(env.local(), 1).ToLocalChecked(); |
316 CHECK(before->IsUndefined()); | 340 CHECK(before->IsUndefined()); |
317 Local<String> bar_str = v8_str("bar"); | 341 Local<String> bar_str = v8_str("bar"); |
318 obj->Set(1, bar_str); | 342 CHECK(obj->Set(env.local(), 1, bar_str).FromJust()); |
319 Local<Value> after = obj->Get(1); | 343 Local<Value> after = obj->Get(env.local(), 1).ToLocalChecked(); |
320 CHECK(!after->IsUndefined()); | 344 CHECK(!after->IsUndefined()); |
321 CHECK(after->IsString()); | 345 CHECK(after->IsString()); |
322 CHECK(bar_str->Equals(after)); | 346 CHECK(bar_str->Equals(env.local(), after).FromJust()); |
323 | 347 |
324 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); | 348 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); |
325 CHECK(v8_str("a")->Equals(value->Get(0))); | 349 CHECK(v8_str("a") |
326 CHECK(v8_str("b")->Equals(value->Get(1))); | 350 ->Equals(env.local(), value->Get(env.local(), 0).ToLocalChecked()) |
351 .FromJust()); | |
352 CHECK(v8_str("b") | |
353 ->Equals(env.local(), value->Get(env.local(), 1).ToLocalChecked()) | |
354 .FromJust()); | |
327 } | 355 } |
328 | 356 |
329 | 357 |
330 THREADED_TEST(Script) { | 358 THREADED_TEST(Script) { |
331 LocalContext env; | 359 LocalContext env; |
332 v8::HandleScope scope(env->GetIsolate()); | 360 v8::HandleScope scope(env->GetIsolate()); |
333 const char* source = "1 + 2 + 3"; | 361 const char* source = "1 + 2 + 3"; |
334 Local<Script> script = v8_compile(source); | 362 Local<Script> script = v8_compile(source); |
335 CHECK_EQ(6, script->Run()->Int32Value()); | 363 CHECK_EQ(6, v8_run_int32value(script)); |
336 } | 364 } |
337 | 365 |
338 | 366 |
339 class TestResource: public String::ExternalStringResource { | 367 class TestResource: public String::ExternalStringResource { |
340 public: | 368 public: |
341 explicit TestResource(uint16_t* data, int* counter = NULL, | 369 explicit TestResource(uint16_t* data, int* counter = NULL, |
342 bool owning_data = true) | 370 bool owning_data = true) |
343 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) { | 371 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) { |
344 while (data[length_]) ++length_; | 372 while (data[length_]) ++length_; |
345 } | 373 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 | 424 |
397 | 425 |
398 THREADED_TEST(ScriptUsingStringResource) { | 426 THREADED_TEST(ScriptUsingStringResource) { |
399 int dispose_count = 0; | 427 int dispose_count = 0; |
400 const char* c_source = "1 + 2 * 3"; | 428 const char* c_source = "1 + 2 * 3"; |
401 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); | 429 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); |
402 { | 430 { |
403 LocalContext env; | 431 LocalContext env; |
404 v8::HandleScope scope(env->GetIsolate()); | 432 v8::HandleScope scope(env->GetIsolate()); |
405 TestResource* resource = new TestResource(two_byte_source, &dispose_count); | 433 TestResource* resource = new TestResource(two_byte_source, &dispose_count); |
406 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 434 Local<String> source = |
435 String::NewExternalTwoByte(env->GetIsolate(), resource) | |
436 .ToLocalChecked(); | |
407 Local<Script> script = v8_compile(source); | 437 Local<Script> script = v8_compile(source); |
408 Local<Value> value = script->Run(); | 438 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
409 CHECK(value->IsNumber()); | 439 CHECK(value->IsNumber()); |
410 CHECK_EQ(7, value->Int32Value()); | 440 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
411 CHECK(source->IsExternal()); | 441 CHECK(source->IsExternal()); |
412 CHECK_EQ(resource, | 442 CHECK_EQ(resource, |
413 static_cast<TestResource*>(source->GetExternalStringResource())); | 443 static_cast<TestResource*>(source->GetExternalStringResource())); |
414 String::Encoding encoding = String::UNKNOWN_ENCODING; | 444 String::Encoding encoding = String::UNKNOWN_ENCODING; |
415 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 445 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
416 source->GetExternalStringResourceBase(&encoding)); | 446 source->GetExternalStringResourceBase(&encoding)); |
417 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); | 447 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); |
418 CcTest::heap()->CollectAllGarbage(); | 448 CcTest::heap()->CollectAllGarbage(); |
419 CHECK_EQ(0, dispose_count); | 449 CHECK_EQ(0, dispose_count); |
420 } | 450 } |
421 CcTest::i_isolate()->compilation_cache()->Clear(); | 451 CcTest::i_isolate()->compilation_cache()->Clear(); |
422 CcTest::heap()->CollectAllAvailableGarbage(); | 452 CcTest::heap()->CollectAllAvailableGarbage(); |
423 CHECK_EQ(1, dispose_count); | 453 CHECK_EQ(1, dispose_count); |
424 } | 454 } |
425 | 455 |
426 | 456 |
427 THREADED_TEST(ScriptUsingOneByteStringResource) { | 457 THREADED_TEST(ScriptUsingOneByteStringResource) { |
428 int dispose_count = 0; | 458 int dispose_count = 0; |
429 const char* c_source = "1 + 2 * 3"; | 459 const char* c_source = "1 + 2 * 3"; |
430 { | 460 { |
431 LocalContext env; | 461 LocalContext env; |
432 v8::HandleScope scope(env->GetIsolate()); | 462 v8::HandleScope scope(env->GetIsolate()); |
433 TestOneByteResource* resource = | 463 TestOneByteResource* resource = |
434 new TestOneByteResource(i::StrDup(c_source), &dispose_count); | 464 new TestOneByteResource(i::StrDup(c_source), &dispose_count); |
435 Local<String> source = String::NewExternal(env->GetIsolate(), resource); | 465 Local<String> source = |
466 String::NewExternalOneByte(env->GetIsolate(), resource) | |
467 .ToLocalChecked(); | |
436 CHECK(source->IsExternalOneByte()); | 468 CHECK(source->IsExternalOneByte()); |
437 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 469 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
438 source->GetExternalOneByteStringResource()); | 470 source->GetExternalOneByteStringResource()); |
439 String::Encoding encoding = String::UNKNOWN_ENCODING; | 471 String::Encoding encoding = String::UNKNOWN_ENCODING; |
440 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), | 472 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), |
441 source->GetExternalStringResourceBase(&encoding)); | 473 source->GetExternalStringResourceBase(&encoding)); |
442 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 474 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
443 Local<Script> script = v8_compile(source); | 475 Local<Script> script = v8_compile(source); |
444 Local<Value> value = script->Run(); | 476 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
445 CHECK(value->IsNumber()); | 477 CHECK(value->IsNumber()); |
446 CHECK_EQ(7, value->Int32Value()); | 478 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
447 CcTest::heap()->CollectAllGarbage(); | 479 CcTest::heap()->CollectAllGarbage(); |
448 CHECK_EQ(0, dispose_count); | 480 CHECK_EQ(0, dispose_count); |
449 } | 481 } |
450 CcTest::i_isolate()->compilation_cache()->Clear(); | 482 CcTest::i_isolate()->compilation_cache()->Clear(); |
451 CcTest::heap()->CollectAllAvailableGarbage(); | 483 CcTest::heap()->CollectAllAvailableGarbage(); |
452 CHECK_EQ(1, dispose_count); | 484 CHECK_EQ(1, dispose_count); |
453 } | 485 } |
454 | 486 |
455 | 487 |
456 THREADED_TEST(ScriptMakingExternalString) { | 488 THREADED_TEST(ScriptMakingExternalString) { |
457 int dispose_count = 0; | 489 int dispose_count = 0; |
458 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 490 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
459 { | 491 { |
460 LocalContext env; | 492 LocalContext env; |
461 v8::HandleScope scope(env->GetIsolate()); | 493 v8::HandleScope scope(env->GetIsolate()); |
462 Local<String> source = | 494 Local<String> source = |
463 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); | 495 String::NewFromTwoByte(env->GetIsolate(), two_byte_source, |
496 v8::NewStringType::kNormal) | |
497 .ToLocalChecked(); | |
464 // Trigger GCs so that the newly allocated string moves to old gen. | 498 // Trigger GCs so that the newly allocated string moves to old gen. |
465 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 499 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
466 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 500 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
467 CHECK_EQ(source->IsExternal(), false); | 501 CHECK_EQ(source->IsExternal(), false); |
468 CHECK_EQ(source->IsExternalOneByte(), false); | 502 CHECK_EQ(source->IsExternalOneByte(), false); |
469 String::Encoding encoding = String::UNKNOWN_ENCODING; | 503 String::Encoding encoding = String::UNKNOWN_ENCODING; |
470 CHECK(!source->GetExternalStringResourceBase(&encoding)); | 504 CHECK(!source->GetExternalStringResourceBase(&encoding)); |
471 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); | 505 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); |
472 bool success = source->MakeExternal(new TestResource(two_byte_source, | 506 bool success = source->MakeExternal(new TestResource(two_byte_source, |
473 &dispose_count)); | 507 &dispose_count)); |
474 CHECK(success); | 508 CHECK(success); |
475 Local<Script> script = v8_compile(source); | 509 Local<Script> script = v8_compile(source); |
476 Local<Value> value = script->Run(); | 510 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
477 CHECK(value->IsNumber()); | 511 CHECK(value->IsNumber()); |
478 CHECK_EQ(7, value->Int32Value()); | 512 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
479 CcTest::heap()->CollectAllGarbage(); | 513 CcTest::heap()->CollectAllGarbage(); |
480 CHECK_EQ(0, dispose_count); | 514 CHECK_EQ(0, dispose_count); |
481 } | 515 } |
482 CcTest::i_isolate()->compilation_cache()->Clear(); | 516 CcTest::i_isolate()->compilation_cache()->Clear(); |
483 CcTest::heap()->CollectAllGarbage(); | 517 CcTest::heap()->CollectAllGarbage(); |
484 CHECK_EQ(1, dispose_count); | 518 CHECK_EQ(1, dispose_count); |
485 } | 519 } |
486 | 520 |
487 | 521 |
488 THREADED_TEST(ScriptMakingExternalOneByteString) { | 522 THREADED_TEST(ScriptMakingExternalOneByteString) { |
489 int dispose_count = 0; | 523 int dispose_count = 0; |
490 const char* c_source = "1 + 2 * 3"; | 524 const char* c_source = "1 + 2 * 3"; |
491 { | 525 { |
492 LocalContext env; | 526 LocalContext env; |
493 v8::HandleScope scope(env->GetIsolate()); | 527 v8::HandleScope scope(env->GetIsolate()); |
494 Local<String> source = v8_str(c_source); | 528 Local<String> source = v8_str(c_source); |
495 // Trigger GCs so that the newly allocated string moves to old gen. | 529 // Trigger GCs so that the newly allocated string moves to old gen. |
496 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
497 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 531 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
498 bool success = source->MakeExternal( | 532 bool success = source->MakeExternal( |
499 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); | 533 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); |
500 CHECK(success); | 534 CHECK(success); |
501 Local<Script> script = v8_compile(source); | 535 Local<Script> script = v8_compile(source); |
502 Local<Value> value = script->Run(); | 536 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
503 CHECK(value->IsNumber()); | 537 CHECK(value->IsNumber()); |
504 CHECK_EQ(7, value->Int32Value()); | 538 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
505 CcTest::heap()->CollectAllGarbage(); | 539 CcTest::heap()->CollectAllGarbage(); |
506 CHECK_EQ(0, dispose_count); | 540 CHECK_EQ(0, dispose_count); |
507 } | 541 } |
508 CcTest::i_isolate()->compilation_cache()->Clear(); | 542 CcTest::i_isolate()->compilation_cache()->Clear(); |
509 CcTest::heap()->CollectAllGarbage(); | 543 CcTest::heap()->CollectAllGarbage(); |
510 CHECK_EQ(1, dispose_count); | 544 CHECK_EQ(1, dispose_count); |
511 } | 545 } |
512 | 546 |
513 | 547 |
514 TEST(MakingExternalStringConditions) { | 548 TEST(MakingExternalStringConditions) { |
515 LocalContext env; | 549 LocalContext env; |
516 v8::HandleScope scope(env->GetIsolate()); | 550 v8::HandleScope scope(env->GetIsolate()); |
517 | 551 |
518 // Free some space in the new space so that we can check freshness. | 552 // Free some space in the new space so that we can check freshness. |
519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 553 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
520 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 554 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
521 | 555 |
522 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); | 556 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); |
523 Local<String> small_string = | 557 Local<String> small_string = |
524 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 558 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, |
559 v8::NewStringType::kNormal) | |
560 .ToLocalChecked(); | |
525 i::DeleteArray(two_byte_string); | 561 i::DeleteArray(two_byte_string); |
526 | 562 |
527 // We should refuse to externalize small strings. | 563 // We should refuse to externalize small strings. |
528 CHECK(!small_string->CanMakeExternal()); | 564 CHECK(!small_string->CanMakeExternal()); |
529 // Trigger GCs so that the newly allocated string moves to old gen. | 565 // Trigger GCs so that the newly allocated string moves to old gen. |
530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
531 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
532 // Old space strings should be accepted. | 568 // Old space strings should be accepted. |
533 CHECK(small_string->CanMakeExternal()); | 569 CHECK(small_string->CanMakeExternal()); |
534 | 570 |
535 two_byte_string = AsciiToTwoByteString("small string 2"); | 571 two_byte_string = AsciiToTwoByteString("small string 2"); |
536 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 572 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string, |
573 v8::NewStringType::kNormal) | |
574 .ToLocalChecked(); | |
537 i::DeleteArray(two_byte_string); | 575 i::DeleteArray(two_byte_string); |
538 | 576 |
539 const int buf_size = 10 * 1024; | 577 const int buf_size = 10 * 1024; |
540 char* buf = i::NewArray<char>(buf_size); | 578 char* buf = i::NewArray<char>(buf_size); |
541 memset(buf, 'a', buf_size); | 579 memset(buf, 'a', buf_size); |
542 buf[buf_size - 1] = '\0'; | 580 buf[buf_size - 1] = '\0'; |
543 | 581 |
544 two_byte_string = AsciiToTwoByteString(buf); | 582 two_byte_string = AsciiToTwoByteString(buf); |
545 Local<String> large_string = | 583 Local<String> large_string = |
546 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 584 String::NewFromTwoByte(env->GetIsolate(), two_byte_string, |
585 v8::NewStringType::kNormal) | |
586 .ToLocalChecked(); | |
547 i::DeleteArray(buf); | 587 i::DeleteArray(buf); |
548 i::DeleteArray(two_byte_string); | 588 i::DeleteArray(two_byte_string); |
549 // Large strings should be immediately accepted. | 589 // Large strings should be immediately accepted. |
550 CHECK(large_string->CanMakeExternal()); | 590 CHECK(large_string->CanMakeExternal()); |
551 } | 591 } |
552 | 592 |
553 | 593 |
554 TEST(MakingExternalOneByteStringConditions) { | 594 TEST(MakingExternalOneByteStringConditions) { |
555 LocalContext env; | 595 LocalContext env; |
556 v8::HandleScope scope(env->GetIsolate()); | 596 v8::HandleScope scope(env->GetIsolate()); |
557 | 597 |
558 // Free some space in the new space so that we can check freshness. | 598 // Free some space in the new space so that we can check freshness. |
559 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 599 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
560 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 600 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
561 | 601 |
562 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); | 602 Local<String> small_string = v8_str("s1"); |
563 // We should refuse to externalize small strings. | 603 // We should refuse to externalize small strings. |
564 CHECK(!small_string->CanMakeExternal()); | 604 CHECK(!small_string->CanMakeExternal()); |
565 // Trigger GCs so that the newly allocated string moves to old gen. | 605 // Trigger GCs so that the newly allocated string moves to old gen. |
566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 606 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 607 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
568 // Old space strings should be accepted. | 608 // Old space strings should be accepted. |
569 CHECK(small_string->CanMakeExternal()); | 609 CHECK(small_string->CanMakeExternal()); |
570 | 610 |
571 const int buf_size = 10 * 1024; | 611 const int buf_size = 10 * 1024; |
572 char* buf = i::NewArray<char>(buf_size); | 612 char* buf = i::NewArray<char>(buf_size); |
573 memset(buf, 'a', buf_size); | 613 memset(buf, 'a', buf_size); |
574 buf[buf_size - 1] = '\0'; | 614 buf[buf_size - 1] = '\0'; |
575 Local<String> large_string = String::NewFromUtf8(env->GetIsolate(), buf); | 615 Local<String> large_string = v8_str(buf); |
576 i::DeleteArray(buf); | 616 i::DeleteArray(buf); |
577 // Large strings should be immediately accepted. | 617 // Large strings should be immediately accepted. |
578 CHECK(large_string->CanMakeExternal()); | 618 CHECK(large_string->CanMakeExternal()); |
579 } | 619 } |
580 | 620 |
581 | 621 |
582 TEST(MakingExternalUnalignedOneByteString) { | 622 TEST(MakingExternalUnalignedOneByteString) { |
583 LocalContext env; | 623 LocalContext env; |
584 v8::HandleScope scope(env->GetIsolate()); | 624 v8::HandleScope scope(env->GetIsolate()); |
585 | 625 |
(...skipping 25 matching lines...) Expand all Loading... | |
611 CcTest::heap()->CollectAllGarbage(); | 651 CcTest::heap()->CollectAllGarbage(); |
612 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); | 652 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); |
613 } | 653 } |
614 | 654 |
615 | 655 |
616 THREADED_TEST(UsingExternalString) { | 656 THREADED_TEST(UsingExternalString) { |
617 i::Factory* factory = CcTest::i_isolate()->factory(); | 657 i::Factory* factory = CcTest::i_isolate()->factory(); |
618 { | 658 { |
619 v8::HandleScope scope(CcTest::isolate()); | 659 v8::HandleScope scope(CcTest::isolate()); |
620 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 660 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
621 Local<String> string = String::NewExternal( | 661 Local<String> string = |
622 CcTest::isolate(), new TestResource(two_byte_string)); | 662 String::NewExternalTwoByte(CcTest::isolate(), |
663 new TestResource(two_byte_string)) | |
664 .ToLocalChecked(); | |
623 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 665 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
624 // Trigger GCs so that the newly allocated string moves to old gen. | 666 // Trigger GCs so that the newly allocated string moves to old gen. |
625 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 667 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
626 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 668 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
627 i::Handle<i::String> isymbol = | 669 i::Handle<i::String> isymbol = |
628 factory->InternalizeString(istring); | 670 factory->InternalizeString(istring); |
629 CHECK(isymbol->IsInternalizedString()); | 671 CHECK(isymbol->IsInternalizedString()); |
630 } | 672 } |
631 CcTest::heap()->CollectAllGarbage(); | 673 CcTest::heap()->CollectAllGarbage(); |
632 CcTest::heap()->CollectAllGarbage(); | 674 CcTest::heap()->CollectAllGarbage(); |
633 } | 675 } |
634 | 676 |
635 | 677 |
636 THREADED_TEST(UsingExternalOneByteString) { | 678 THREADED_TEST(UsingExternalOneByteString) { |
637 i::Factory* factory = CcTest::i_isolate()->factory(); | 679 i::Factory* factory = CcTest::i_isolate()->factory(); |
638 { | 680 { |
639 v8::HandleScope scope(CcTest::isolate()); | 681 v8::HandleScope scope(CcTest::isolate()); |
640 const char* one_byte_string = "test string"; | 682 const char* one_byte_string = "test string"; |
641 Local<String> string = String::NewExternal( | 683 Local<String> string = |
642 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); | 684 String::NewExternalOneByte( |
685 CcTest::isolate(), | |
686 new TestOneByteResource(i::StrDup(one_byte_string))) | |
687 .ToLocalChecked(); | |
643 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 688 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
644 // Trigger GCs so that the newly allocated string moves to old gen. | 689 // Trigger GCs so that the newly allocated string moves to old gen. |
645 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 690 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
646 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 691 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
647 i::Handle<i::String> isymbol = | 692 i::Handle<i::String> isymbol = |
648 factory->InternalizeString(istring); | 693 factory->InternalizeString(istring); |
649 CHECK(isymbol->IsInternalizedString()); | 694 CHECK(isymbol->IsInternalizedString()); |
650 } | 695 } |
651 CcTest::heap()->CollectAllGarbage(); | 696 CcTest::heap()->CollectAllGarbage(); |
652 CcTest::heap()->CollectAllGarbage(); | 697 CcTest::heap()->CollectAllGarbage(); |
(...skipping 24 matching lines...) Expand all Loading... | |
677 int length_; | 722 int length_; |
678 }; | 723 }; |
679 | 724 |
680 | 725 |
681 THREADED_TEST(NewExternalForVeryLongString) { | 726 THREADED_TEST(NewExternalForVeryLongString) { |
682 auto isolate = CcTest::isolate(); | 727 auto isolate = CcTest::isolate(); |
683 { | 728 { |
684 v8::HandleScope scope(isolate); | 729 v8::HandleScope scope(isolate); |
685 v8::TryCatch try_catch(isolate); | 730 v8::TryCatch try_catch(isolate); |
686 RandomLengthOneByteResource r(1 << 30); | 731 RandomLengthOneByteResource r(1 << 30); |
687 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); | 732 v8::MaybeLocal<v8::String> maybe_str = |
688 CHECK(str.IsEmpty()); | 733 v8::String::NewExternalOneByte(isolate, &r); |
734 CHECK(maybe_str.IsEmpty()); | |
689 CHECK(!try_catch.HasCaught()); | 735 CHECK(!try_catch.HasCaught()); |
690 } | 736 } |
691 | 737 |
692 { | 738 { |
693 v8::HandleScope scope(isolate); | 739 v8::HandleScope scope(isolate); |
694 v8::TryCatch try_catch(isolate); | 740 v8::TryCatch try_catch(isolate); |
695 RandomLengthResource r(1 << 30); | 741 RandomLengthResource r(1 << 30); |
696 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); | 742 v8::MaybeLocal<v8::String> maybe_str = |
697 CHECK(str.IsEmpty()); | 743 v8::String::NewExternalTwoByte(isolate, &r); |
744 CHECK(maybe_str.IsEmpty()); | |
698 CHECK(!try_catch.HasCaught()); | 745 CHECK(!try_catch.HasCaught()); |
699 } | 746 } |
700 } | 747 } |
701 | 748 |
702 | 749 |
703 THREADED_TEST(ScavengeExternalString) { | 750 THREADED_TEST(ScavengeExternalString) { |
704 i::FLAG_stress_compaction = false; | 751 i::FLAG_stress_compaction = false; |
705 i::FLAG_gc_global = false; | 752 i::FLAG_gc_global = false; |
706 int dispose_count = 0; | 753 int dispose_count = 0; |
707 bool in_new_space = false; | 754 bool in_new_space = false; |
708 { | 755 { |
709 v8::HandleScope scope(CcTest::isolate()); | 756 v8::HandleScope scope(CcTest::isolate()); |
710 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 757 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
711 Local<String> string = String::NewExternal( | 758 Local<String> string = |
712 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); | 759 String::NewExternalTwoByte( |
760 CcTest::isolate(), | |
761 new TestResource(two_byte_string, &dispose_count)) | |
762 .ToLocalChecked(); | |
713 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 763 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
714 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 764 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
715 in_new_space = CcTest::heap()->InNewSpace(*istring); | 765 in_new_space = CcTest::heap()->InNewSpace(*istring); |
716 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); | 766 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
717 CHECK_EQ(0, dispose_count); | 767 CHECK_EQ(0, dispose_count); |
718 } | 768 } |
719 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); | 769 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
720 CHECK_EQ(1, dispose_count); | 770 CHECK_EQ(1, dispose_count); |
721 } | 771 } |
722 | 772 |
723 | 773 |
724 THREADED_TEST(ScavengeExternalOneByteString) { | 774 THREADED_TEST(ScavengeExternalOneByteString) { |
725 i::FLAG_stress_compaction = false; | 775 i::FLAG_stress_compaction = false; |
726 i::FLAG_gc_global = false; | 776 i::FLAG_gc_global = false; |
727 int dispose_count = 0; | 777 int dispose_count = 0; |
728 bool in_new_space = false; | 778 bool in_new_space = false; |
729 { | 779 { |
730 v8::HandleScope scope(CcTest::isolate()); | 780 v8::HandleScope scope(CcTest::isolate()); |
731 const char* one_byte_string = "test string"; | 781 const char* one_byte_string = "test string"; |
732 Local<String> string = String::NewExternal( | 782 Local<String> string = |
733 CcTest::isolate(), | 783 String::NewExternalOneByte( |
734 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); | 784 CcTest::isolate(), |
785 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)) | |
786 .ToLocalChecked(); | |
735 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 787 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
736 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 788 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
737 in_new_space = CcTest::heap()->InNewSpace(*istring); | 789 in_new_space = CcTest::heap()->InNewSpace(*istring); |
738 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); | 790 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); |
739 CHECK_EQ(0, dispose_count); | 791 CHECK_EQ(0, dispose_count); |
740 } | 792 } |
741 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); | 793 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); |
742 CHECK_EQ(1, dispose_count); | 794 CHECK_EQ(1, dispose_count); |
743 } | 795 } |
744 | 796 |
(...skipping 23 matching lines...) Expand all Loading... | |
768 TEST(ExternalStringWithDisposeHandling) { | 820 TEST(ExternalStringWithDisposeHandling) { |
769 const char* c_source = "1 + 2 * 3"; | 821 const char* c_source = "1 + 2 * 3"; |
770 | 822 |
771 // Use a stack allocated external string resource allocated object. | 823 // Use a stack allocated external string resource allocated object. |
772 TestOneByteResourceWithDisposeControl::dispose_count = 0; | 824 TestOneByteResourceWithDisposeControl::dispose_count = 0; |
773 TestOneByteResourceWithDisposeControl::dispose_calls = 0; | 825 TestOneByteResourceWithDisposeControl::dispose_calls = 0; |
774 TestOneByteResourceWithDisposeControl res_stack(i::StrDup(c_source), false); | 826 TestOneByteResourceWithDisposeControl res_stack(i::StrDup(c_source), false); |
775 { | 827 { |
776 LocalContext env; | 828 LocalContext env; |
777 v8::HandleScope scope(env->GetIsolate()); | 829 v8::HandleScope scope(env->GetIsolate()); |
778 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); | 830 Local<String> source = |
831 String::NewExternalOneByte(env->GetIsolate(), &res_stack) | |
832 .ToLocalChecked(); | |
779 Local<Script> script = v8_compile(source); | 833 Local<Script> script = v8_compile(source); |
780 Local<Value> value = script->Run(); | 834 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
781 CHECK(value->IsNumber()); | 835 CHECK(value->IsNumber()); |
782 CHECK_EQ(7, value->Int32Value()); | 836 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
783 CcTest::heap()->CollectAllAvailableGarbage(); | 837 CcTest::heap()->CollectAllAvailableGarbage(); |
784 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 838 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
785 } | 839 } |
786 CcTest::i_isolate()->compilation_cache()->Clear(); | 840 CcTest::i_isolate()->compilation_cache()->Clear(); |
787 CcTest::heap()->CollectAllAvailableGarbage(); | 841 CcTest::heap()->CollectAllAvailableGarbage(); |
788 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); | 842 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); |
789 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 843 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
790 | 844 |
791 // Use a heap allocated external string resource allocated object. | 845 // Use a heap allocated external string resource allocated object. |
792 TestOneByteResourceWithDisposeControl::dispose_count = 0; | 846 TestOneByteResourceWithDisposeControl::dispose_count = 0; |
793 TestOneByteResourceWithDisposeControl::dispose_calls = 0; | 847 TestOneByteResourceWithDisposeControl::dispose_calls = 0; |
794 TestOneByteResource* res_heap = | 848 TestOneByteResource* res_heap = |
795 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true); | 849 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true); |
796 { | 850 { |
797 LocalContext env; | 851 LocalContext env; |
798 v8::HandleScope scope(env->GetIsolate()); | 852 v8::HandleScope scope(env->GetIsolate()); |
799 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); | 853 Local<String> source = |
854 String::NewExternalOneByte(env->GetIsolate(), res_heap) | |
855 .ToLocalChecked(); | |
800 Local<Script> script = v8_compile(source); | 856 Local<Script> script = v8_compile(source); |
801 Local<Value> value = script->Run(); | 857 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
802 CHECK(value->IsNumber()); | 858 CHECK(value->IsNumber()); |
803 CHECK_EQ(7, value->Int32Value()); | 859 CHECK_EQ(7, value->Int32Value(env.local()).FromJust()); |
804 CcTest::heap()->CollectAllAvailableGarbage(); | 860 CcTest::heap()->CollectAllAvailableGarbage(); |
805 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); | 861 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); |
806 } | 862 } |
807 CcTest::i_isolate()->compilation_cache()->Clear(); | 863 CcTest::i_isolate()->compilation_cache()->Clear(); |
808 CcTest::heap()->CollectAllAvailableGarbage(); | 864 CcTest::heap()->CollectAllAvailableGarbage(); |
809 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); | 865 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); |
810 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count); | 866 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count); |
811 } | 867 } |
812 | 868 |
813 | 869 |
814 THREADED_TEST(StringConcat) { | 870 THREADED_TEST(StringConcat) { |
815 { | 871 { |
816 LocalContext env; | 872 LocalContext env; |
817 v8::HandleScope scope(env->GetIsolate()); | 873 v8::HandleScope scope(env->GetIsolate()); |
818 const char* one_byte_string_1 = "function a_times_t"; | 874 const char* one_byte_string_1 = "function a_times_t"; |
819 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; | 875 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; |
820 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; | 876 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; |
821 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; | 877 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; |
822 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 878 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
823 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 879 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
824 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; | 880 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; |
825 Local<String> left = v8_str(one_byte_string_1); | 881 Local<String> left = v8_str(one_byte_string_1); |
826 | 882 |
827 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); | 883 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); |
828 Local<String> right = | 884 Local<String> right = |
829 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); | 885 String::NewFromTwoByte(env->GetIsolate(), two_byte_source, |
886 v8::NewStringType::kNormal) | |
887 .ToLocalChecked(); | |
830 i::DeleteArray(two_byte_source); | 888 i::DeleteArray(two_byte_source); |
831 | 889 |
832 Local<String> source = String::Concat(left, right); | 890 Local<String> source = String::Concat(left, right); |
833 right = String::NewExternal( | 891 right = String::NewExternalOneByte( |
834 env->GetIsolate(), | 892 env->GetIsolate(), |
835 new TestOneByteResource(i::StrDup(one_byte_extern_1))); | 893 new TestOneByteResource(i::StrDup(one_byte_extern_1))) |
894 .ToLocalChecked(); | |
836 source = String::Concat(source, right); | 895 source = String::Concat(source, right); |
837 right = String::NewExternal( | 896 right = String::NewExternalTwoByte( |
838 env->GetIsolate(), | 897 env->GetIsolate(), |
839 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); | 898 new TestResource(AsciiToTwoByteString(two_byte_extern_1))) |
899 .ToLocalChecked(); | |
840 source = String::Concat(source, right); | 900 source = String::Concat(source, right); |
841 right = v8_str(one_byte_string_2); | 901 right = v8_str(one_byte_string_2); |
842 source = String::Concat(source, right); | 902 source = String::Concat(source, right); |
843 | 903 |
844 two_byte_source = AsciiToTwoByteString(two_byte_string_2); | 904 two_byte_source = AsciiToTwoByteString(two_byte_string_2); |
845 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); | 905 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source, |
906 v8::NewStringType::kNormal) | |
907 .ToLocalChecked(); | |
846 i::DeleteArray(two_byte_source); | 908 i::DeleteArray(two_byte_source); |
847 | 909 |
848 source = String::Concat(source, right); | 910 source = String::Concat(source, right); |
849 right = String::NewExternal( | 911 right = String::NewExternalTwoByte( |
850 env->GetIsolate(), | 912 env->GetIsolate(), |
851 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); | 913 new TestResource(AsciiToTwoByteString(two_byte_extern_2))) |
914 .ToLocalChecked(); | |
852 source = String::Concat(source, right); | 915 source = String::Concat(source, right); |
853 Local<Script> script = v8_compile(source); | 916 Local<Script> script = v8_compile(source); |
854 Local<Value> value = script->Run(); | 917 Local<Value> value = script->Run(env.local()).ToLocalChecked(); |
855 CHECK(value->IsNumber()); | 918 CHECK(value->IsNumber()); |
856 CHECK_EQ(68, value->Int32Value()); | 919 CHECK_EQ(68, value->Int32Value(env.local()).FromJust()); |
857 } | 920 } |
858 CcTest::i_isolate()->compilation_cache()->Clear(); | 921 CcTest::i_isolate()->compilation_cache()->Clear(); |
859 CcTest::heap()->CollectAllGarbage(); | 922 CcTest::heap()->CollectAllGarbage(); |
860 CcTest::heap()->CollectAllGarbage(); | 923 CcTest::heap()->CollectAllGarbage(); |
861 } | 924 } |
862 | 925 |
863 | 926 |
864 THREADED_TEST(GlobalProperties) { | 927 THREADED_TEST(GlobalProperties) { |
865 LocalContext env; | 928 LocalContext env; |
866 v8::HandleScope scope(env->GetIsolate()); | 929 v8::HandleScope scope(env->GetIsolate()); |
867 v8::Handle<v8::Object> global = env->Global(); | 930 v8::Local<v8::Object> global = env->Global(); |
868 global->Set(v8_str("pi"), v8_num(3.1415926)); | 931 CHECK(global->Set(env.local(), v8_str("pi"), v8_num(3.1415926)).FromJust()); |
869 Local<Value> pi = global->Get(v8_str("pi")); | 932 Local<Value> pi = global->Get(env.local(), v8_str("pi")).ToLocalChecked(); |
870 CHECK_EQ(3.1415926, pi->NumberValue()); | 933 CHECK_EQ(3.1415926, pi->NumberValue(env.local()).FromJust()); |
871 } | 934 } |
872 | 935 |
873 | 936 |
874 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info, | 937 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info, |
875 i::Address callback) { | 938 i::Address callback) { |
876 ApiTestFuzzer::Fuzz(); | 939 ApiTestFuzzer::Fuzz(); |
877 CheckReturnValue(info, callback); | 940 CheckReturnValue(info, callback); |
878 info.GetReturnValue().Set(v8_str("bad value")); | 941 info.GetReturnValue().Set(v8_str("bad value")); |
879 info.GetReturnValue().Set(v8_num(102)); | 942 info.GetReturnValue().Set(v8_num(102)); |
880 } | 943 } |
881 | 944 |
882 | 945 |
883 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { | 946 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { |
884 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback)); | 947 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback)); |
885 } | 948 } |
886 | 949 |
887 | 950 |
888 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { | 951 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { |
889 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2)); | 952 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2)); |
890 } | 953 } |
891 | 954 |
892 static void construct_callback( | 955 static void construct_callback( |
893 const v8::FunctionCallbackInfo<Value>& info) { | 956 const v8::FunctionCallbackInfo<Value>& info) { |
894 ApiTestFuzzer::Fuzz(); | 957 ApiTestFuzzer::Fuzz(); |
895 CheckReturnValue(info, FUNCTION_ADDR(construct_callback)); | 958 CheckReturnValue(info, FUNCTION_ADDR(construct_callback)); |
896 info.This()->Set(v8_str("x"), v8_num(1)); | 959 CHECK( |
897 info.This()->Set(v8_str("y"), v8_num(2)); | 960 info.This() |
961 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("x"), v8_num(1)) | |
962 .FromJust()); | |
963 CHECK( | |
964 info.This() | |
965 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(2)) | |
966 .FromJust()); | |
898 info.GetReturnValue().Set(v8_str("bad value")); | 967 info.GetReturnValue().Set(v8_str("bad value")); |
899 info.GetReturnValue().Set(info.This()); | 968 info.GetReturnValue().Set(info.This()); |
900 } | 969 } |
901 | 970 |
902 | 971 |
903 static void Return239Callback( | 972 static void Return239Callback( |
904 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { | 973 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { |
905 ApiTestFuzzer::Fuzz(); | 974 ApiTestFuzzer::Fuzz(); |
906 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); | 975 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); |
907 info.GetReturnValue().Set(v8_str("bad value")); | 976 info.GetReturnValue().Set(v8_str("bad value")); |
908 info.GetReturnValue().Set(v8_num(239)); | 977 info.GetReturnValue().Set(v8_num(239)); |
909 } | 978 } |
910 | 979 |
911 | 980 |
912 template<typename Handler> | 981 template<typename Handler> |
913 static void TestFunctionTemplateInitializer(Handler handler, | 982 static void TestFunctionTemplateInitializer(Handler handler, |
914 Handler handler_2) { | 983 Handler handler_2) { |
915 // Test constructor calls. | 984 // Test constructor calls. |
916 { | 985 { |
917 LocalContext env; | 986 LocalContext env; |
918 v8::Isolate* isolate = env->GetIsolate(); | 987 v8::Isolate* isolate = env->GetIsolate(); |
919 v8::HandleScope scope(isolate); | 988 v8::HandleScope scope(isolate); |
920 | 989 |
921 Local<v8::FunctionTemplate> fun_templ = | 990 Local<v8::FunctionTemplate> fun_templ = |
922 v8::FunctionTemplate::New(isolate, handler); | 991 v8::FunctionTemplate::New(isolate, handler); |
923 Local<Function> fun = fun_templ->GetFunction(); | 992 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
924 env->Global()->Set(v8_str("obj"), fun); | 993 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
925 Local<Script> script = v8_compile("obj()"); | 994 Local<Script> script = v8_compile("obj()"); |
926 for (int i = 0; i < 30; i++) { | 995 for (int i = 0; i < 30; i++) { |
927 CHECK_EQ(102, script->Run()->Int32Value()); | 996 CHECK_EQ(102, v8_run_int32value(script)); |
928 } | 997 } |
929 } | 998 } |
930 // Use SetCallHandler to initialize a function template, should work like | 999 // Use SetCallHandler to initialize a function template, should work like |
931 // the previous one. | 1000 // the previous one. |
932 { | 1001 { |
933 LocalContext env; | 1002 LocalContext env; |
934 v8::Isolate* isolate = env->GetIsolate(); | 1003 v8::Isolate* isolate = env->GetIsolate(); |
935 v8::HandleScope scope(isolate); | 1004 v8::HandleScope scope(isolate); |
936 | 1005 |
937 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); | 1006 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); |
938 fun_templ->SetCallHandler(handler_2); | 1007 fun_templ->SetCallHandler(handler_2); |
939 Local<Function> fun = fun_templ->GetFunction(); | 1008 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
940 env->Global()->Set(v8_str("obj"), fun); | 1009 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
941 Local<Script> script = v8_compile("obj()"); | 1010 Local<Script> script = v8_compile("obj()"); |
942 for (int i = 0; i < 30; i++) { | 1011 for (int i = 0; i < 30; i++) { |
943 CHECK_EQ(102, script->Run()->Int32Value()); | 1012 CHECK_EQ(102, v8_run_int32value(script)); |
944 } | 1013 } |
945 } | 1014 } |
946 } | 1015 } |
947 | 1016 |
948 | 1017 |
949 template<typename Constructor, typename Accessor> | 1018 template<typename Constructor, typename Accessor> |
950 static void TestFunctionTemplateAccessor(Constructor constructor, | 1019 static void TestFunctionTemplateAccessor(Constructor constructor, |
951 Accessor accessor) { | 1020 Accessor accessor) { |
952 LocalContext env; | 1021 LocalContext env; |
953 v8::HandleScope scope(env->GetIsolate()); | 1022 v8::HandleScope scope(env->GetIsolate()); |
954 | 1023 |
955 Local<v8::FunctionTemplate> fun_templ = | 1024 Local<v8::FunctionTemplate> fun_templ = |
956 v8::FunctionTemplate::New(env->GetIsolate(), constructor); | 1025 v8::FunctionTemplate::New(env->GetIsolate(), constructor); |
957 fun_templ->SetClassName(v8_str("funky")); | 1026 fun_templ->SetClassName(v8_str("funky")); |
958 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); | 1027 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); |
959 Local<Function> fun = fun_templ->GetFunction(); | 1028 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
960 env->Global()->Set(v8_str("obj"), fun); | 1029 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
961 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 1030 Local<Value> result = |
962 CHECK(v8_str("[object funky]")->Equals(result)); | 1031 v8_compile("(new obj()).toString()")->Run(env.local()).ToLocalChecked(); |
1032 CHECK(v8_str("[object funky]")->Equals(env.local(), result).FromJust()); | |
963 CompileRun("var obj_instance = new obj();"); | 1033 CompileRun("var obj_instance = new obj();"); |
964 Local<Script> script; | 1034 Local<Script> script; |
965 script = v8_compile("obj_instance.x"); | 1035 script = v8_compile("obj_instance.x"); |
966 for (int i = 0; i < 30; i++) { | 1036 for (int i = 0; i < 30; i++) { |
967 CHECK_EQ(1, script->Run()->Int32Value()); | 1037 CHECK_EQ(1, v8_run_int32value(script)); |
968 } | 1038 } |
969 script = v8_compile("obj_instance.m"); | 1039 script = v8_compile("obj_instance.m"); |
970 for (int i = 0; i < 30; i++) { | 1040 for (int i = 0; i < 30; i++) { |
971 CHECK_EQ(239, script->Run()->Int32Value()); | 1041 CHECK_EQ(239, v8_run_int32value(script)); |
972 } | 1042 } |
973 } | 1043 } |
974 | 1044 |
975 | 1045 |
976 THREADED_PROFILED_TEST(FunctionTemplate) { | 1046 THREADED_PROFILED_TEST(FunctionTemplate) { |
977 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); | 1047 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); |
978 TestFunctionTemplateAccessor(construct_callback, Return239Callback); | 1048 TestFunctionTemplateAccessor(construct_callback, Return239Callback); |
979 } | 1049 } |
980 | 1050 |
981 | 1051 |
982 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { | 1052 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
983 ApiTestFuzzer::Fuzz(); | 1053 ApiTestFuzzer::Fuzz(); |
984 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); | 1054 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); |
985 info.GetReturnValue().Set(v8_num(51423 + info.Length())); | 1055 info.GetReturnValue().Set(v8_num(51423 + info.Length())); |
986 } | 1056 } |
987 | 1057 |
988 | 1058 |
989 template<typename Callback> | 1059 template<typename Callback> |
990 static void TestSimpleCallback(Callback callback) { | 1060 static void TestSimpleCallback(Callback callback) { |
991 LocalContext env; | 1061 LocalContext env; |
992 v8::Isolate* isolate = env->GetIsolate(); | 1062 v8::Isolate* isolate = env->GetIsolate(); |
993 v8::HandleScope scope(isolate); | 1063 v8::HandleScope scope(isolate); |
994 | 1064 |
995 v8::Handle<v8::ObjectTemplate> object_template = | 1065 v8::Local<v8::ObjectTemplate> object_template = |
996 v8::ObjectTemplate::New(isolate); | 1066 v8::ObjectTemplate::New(isolate); |
997 object_template->Set(isolate, "callback", | 1067 object_template->Set(isolate, "callback", |
998 v8::FunctionTemplate::New(isolate, callback)); | 1068 v8::FunctionTemplate::New(isolate, callback)); |
999 v8::Local<v8::Object> object = object_template->NewInstance(); | 1069 v8::Local<v8::Object> object = |
1000 (*env)->Global()->Set(v8_str("callback_object"), object); | 1070 object_template->NewInstance(env.local()).ToLocalChecked(); |
1001 v8::Handle<v8::Script> script; | 1071 CHECK((*env) |
1072 ->Global() | |
1073 ->Set(env.local(), v8_str("callback_object"), object) | |
1074 .FromJust()); | |
1075 v8::Local<v8::Script> script; | |
1002 script = v8_compile("callback_object.callback(17)"); | 1076 script = v8_compile("callback_object.callback(17)"); |
1003 for (int i = 0; i < 30; i++) { | 1077 for (int i = 0; i < 30; i++) { |
1004 CHECK_EQ(51424, script->Run()->Int32Value()); | 1078 CHECK_EQ(51424, v8_run_int32value(script)); |
1005 } | 1079 } |
1006 script = v8_compile("callback_object.callback(17, 24)"); | 1080 script = v8_compile("callback_object.callback(17, 24)"); |
1007 for (int i = 0; i < 30; i++) { | 1081 for (int i = 0; i < 30; i++) { |
1008 CHECK_EQ(51425, script->Run()->Int32Value()); | 1082 CHECK_EQ(51425, v8_run_int32value(script)); |
1009 } | 1083 } |
1010 } | 1084 } |
1011 | 1085 |
1012 | 1086 |
1013 THREADED_PROFILED_TEST(SimpleCallback) { | 1087 THREADED_PROFILED_TEST(SimpleCallback) { |
1014 TestSimpleCallback(SimpleCallback); | 1088 TestSimpleCallback(SimpleCallback); |
1015 } | 1089 } |
1016 | 1090 |
1017 | 1091 |
1018 template<typename T> | 1092 template<typename T> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 break; | 1153 break; |
1080 case kEmptyStringReturnValue: | 1154 case kEmptyStringReturnValue: |
1081 info.GetReturnValue().SetEmptyString(); | 1155 info.GetReturnValue().SetEmptyString(); |
1082 break; | 1156 break; |
1083 } | 1157 } |
1084 } | 1158 } |
1085 | 1159 |
1086 template<> | 1160 template<> |
1087 void FastReturnValueCallback<Object>( | 1161 void FastReturnValueCallback<Object>( |
1088 const v8::FunctionCallbackInfo<v8::Value>& info) { | 1162 const v8::FunctionCallbackInfo<v8::Value>& info) { |
1089 v8::Handle<v8::Object> object; | 1163 v8::Local<v8::Object> object; |
1090 if (!fast_return_value_object_is_empty) { | 1164 if (!fast_return_value_object_is_empty) { |
1091 object = Object::New(info.GetIsolate()); | 1165 object = Object::New(info.GetIsolate()); |
1092 } | 1166 } |
1093 info.GetReturnValue().Set(object); | 1167 info.GetReturnValue().Set(object); |
1094 } | 1168 } |
1095 | 1169 |
1096 template<typename T> | 1170 template <typename T> |
1097 Handle<Value> TestFastReturnValues() { | 1171 Local<Value> TestFastReturnValues() { |
1098 LocalContext env; | 1172 LocalContext env; |
1099 v8::Isolate* isolate = env->GetIsolate(); | 1173 v8::Isolate* isolate = env->GetIsolate(); |
1100 v8::EscapableHandleScope scope(isolate); | 1174 v8::EscapableHandleScope scope(isolate); |
1101 v8::Handle<v8::ObjectTemplate> object_template = | 1175 v8::Local<v8::ObjectTemplate> object_template = |
1102 v8::ObjectTemplate::New(isolate); | 1176 v8::ObjectTemplate::New(isolate); |
1103 v8::FunctionCallback callback = &FastReturnValueCallback<T>; | 1177 v8::FunctionCallback callback = &FastReturnValueCallback<T>; |
1104 object_template->Set(isolate, "callback", | 1178 object_template->Set(isolate, "callback", |
1105 v8::FunctionTemplate::New(isolate, callback)); | 1179 v8::FunctionTemplate::New(isolate, callback)); |
1106 v8::Local<v8::Object> object = object_template->NewInstance(); | 1180 v8::Local<v8::Object> object = |
1107 (*env)->Global()->Set(v8_str("callback_object"), object); | 1181 object_template->NewInstance(env.local()).ToLocalChecked(); |
1182 CHECK((*env) | |
1183 ->Global() | |
1184 ->Set(env.local(), v8_str("callback_object"), object) | |
1185 .FromJust()); | |
1108 return scope.Escape(CompileRun("callback_object.callback()")); | 1186 return scope.Escape(CompileRun("callback_object.callback()")); |
1109 } | 1187 } |
1110 | 1188 |
1111 | 1189 |
1112 THREADED_PROFILED_TEST(FastReturnValues) { | 1190 THREADED_PROFILED_TEST(FastReturnValues) { |
1113 LocalContext env; | 1191 LocalContext env; |
1114 v8::Isolate* isolate = env->GetIsolate(); | 1192 v8::Isolate* isolate = env->GetIsolate(); |
1115 v8::HandleScope scope(isolate); | 1193 v8::HandleScope scope(isolate); |
1116 v8::Handle<v8::Value> value; | 1194 v8::Local<v8::Value> value; |
1117 // check int32_t and uint32_t | 1195 // check int32_t and uint32_t |
1118 int32_t int_values[] = { | 1196 int32_t int_values[] = { |
1119 0, 234, -723, | 1197 0, 234, -723, |
1120 i::Smi::kMinValue, i::Smi::kMaxValue | 1198 i::Smi::kMinValue, i::Smi::kMaxValue |
1121 }; | 1199 }; |
1122 for (size_t i = 0; i < arraysize(int_values); i++) { | 1200 for (size_t i = 0; i < arraysize(int_values); i++) { |
1123 for (int modifier = -1; modifier <= 1; modifier++) { | 1201 for (int modifier = -1; modifier <= 1; modifier++) { |
1124 int int_value = int_values[i] + modifier; | 1202 int int_value = int_values[i] + modifier; |
1125 // check int32_t | 1203 // check int32_t |
1126 fast_return_value_int32 = int_value; | 1204 fast_return_value_int32 = int_value; |
1127 value = TestFastReturnValues<int32_t>(); | 1205 value = TestFastReturnValues<int32_t>(); |
1128 CHECK(value->IsInt32()); | 1206 CHECK(value->IsInt32()); |
1129 CHECK(fast_return_value_int32 == value->Int32Value()); | 1207 CHECK_EQ(fast_return_value_int32, |
1208 value->Int32Value(env.local()).FromJust()); | |
1130 // check uint32_t | 1209 // check uint32_t |
1131 fast_return_value_uint32 = static_cast<uint32_t>(int_value); | 1210 fast_return_value_uint32 = static_cast<uint32_t>(int_value); |
1132 value = TestFastReturnValues<uint32_t>(); | 1211 value = TestFastReturnValues<uint32_t>(); |
1133 CHECK(value->IsUint32()); | 1212 CHECK(value->IsUint32()); |
1134 CHECK(fast_return_value_uint32 == value->Uint32Value()); | 1213 CHECK_EQ(fast_return_value_uint32, |
1214 value->Uint32Value(env.local()).FromJust()); | |
1135 } | 1215 } |
1136 } | 1216 } |
1137 // check double | 1217 // check double |
1138 value = TestFastReturnValues<double>(); | 1218 value = TestFastReturnValues<double>(); |
1139 CHECK(value->IsNumber()); | 1219 CHECK(value->IsNumber()); |
1140 CHECK_EQ(kFastReturnValueDouble, value->ToNumber(isolate)->Value()); | 1220 CHECK_EQ(kFastReturnValueDouble, |
1221 value->ToNumber(env.local()).ToLocalChecked()->Value()); | |
1141 // check bool values | 1222 // check bool values |
1142 for (int i = 0; i < 2; i++) { | 1223 for (int i = 0; i < 2; i++) { |
1143 fast_return_value_bool = i == 0; | 1224 fast_return_value_bool = i == 0; |
1144 value = TestFastReturnValues<bool>(); | 1225 value = TestFastReturnValues<bool>(); |
1145 CHECK(value->IsBoolean()); | 1226 CHECK(value->IsBoolean()); |
1146 CHECK_EQ(fast_return_value_bool, value->ToBoolean(isolate)->Value()); | 1227 CHECK_EQ(fast_return_value_bool, |
1228 value->ToBoolean(env.local()).ToLocalChecked()->Value()); | |
1147 } | 1229 } |
1148 // check oddballs | 1230 // check oddballs |
1149 ReturnValueOddball oddballs[] = { | 1231 ReturnValueOddball oddballs[] = { |
1150 kNullReturnValue, | 1232 kNullReturnValue, |
1151 kUndefinedReturnValue, | 1233 kUndefinedReturnValue, |
1152 kEmptyStringReturnValue | 1234 kEmptyStringReturnValue |
1153 }; | 1235 }; |
1154 for (size_t i = 0; i < arraysize(oddballs); i++) { | 1236 for (size_t i = 0; i < arraysize(oddballs); i++) { |
1155 fast_return_value_void = oddballs[i]; | 1237 fast_return_value_void = oddballs[i]; |
1156 value = TestFastReturnValues<void>(); | 1238 value = TestFastReturnValues<void>(); |
(...skipping 19 matching lines...) Expand all Loading... | |
1176 CHECK(value->IsUndefined()); | 1258 CHECK(value->IsUndefined()); |
1177 } | 1259 } |
1178 | 1260 |
1179 | 1261 |
1180 THREADED_TEST(FunctionTemplateSetLength) { | 1262 THREADED_TEST(FunctionTemplateSetLength) { |
1181 LocalContext env; | 1263 LocalContext env; |
1182 v8::Isolate* isolate = env->GetIsolate(); | 1264 v8::Isolate* isolate = env->GetIsolate(); |
1183 v8::HandleScope scope(isolate); | 1265 v8::HandleScope scope(isolate); |
1184 { | 1266 { |
1185 Local<v8::FunctionTemplate> fun_templ = | 1267 Local<v8::FunctionTemplate> fun_templ = |
1186 v8::FunctionTemplate::New(isolate, | 1268 v8::FunctionTemplate::New(isolate, handle_callback, Local<v8::Value>(), |
1187 handle_callback, | 1269 Local<v8::Signature>(), 23); |
1188 Handle<v8::Value>(), | 1270 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
1189 Handle<v8::Signature>(), | 1271 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
1190 23); | |
1191 Local<Function> fun = fun_templ->GetFunction(); | |
1192 env->Global()->Set(v8_str("obj"), fun); | |
1193 Local<Script> script = v8_compile("obj.length"); | 1272 Local<Script> script = v8_compile("obj.length"); |
1194 CHECK_EQ(23, script->Run()->Int32Value()); | 1273 CHECK_EQ(23, v8_run_int32value(script)); |
1195 } | 1274 } |
1196 { | 1275 { |
1197 Local<v8::FunctionTemplate> fun_templ = | 1276 Local<v8::FunctionTemplate> fun_templ = |
1198 v8::FunctionTemplate::New(isolate, handle_callback); | 1277 v8::FunctionTemplate::New(isolate, handle_callback); |
1199 fun_templ->SetLength(22); | 1278 fun_templ->SetLength(22); |
1200 Local<Function> fun = fun_templ->GetFunction(); | 1279 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
1201 env->Global()->Set(v8_str("obj"), fun); | 1280 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
1202 Local<Script> script = v8_compile("obj.length"); | 1281 Local<Script> script = v8_compile("obj.length"); |
1203 CHECK_EQ(22, script->Run()->Int32Value()); | 1282 CHECK_EQ(22, v8_run_int32value(script)); |
1204 } | 1283 } |
1205 { | 1284 { |
1206 // Without setting length it defaults to 0. | 1285 // Without setting length it defaults to 0. |
1207 Local<v8::FunctionTemplate> fun_templ = | 1286 Local<v8::FunctionTemplate> fun_templ = |
1208 v8::FunctionTemplate::New(isolate, handle_callback); | 1287 v8::FunctionTemplate::New(isolate, handle_callback); |
1209 Local<Function> fun = fun_templ->GetFunction(); | 1288 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
1210 env->Global()->Set(v8_str("obj"), fun); | 1289 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust()); |
1211 Local<Script> script = v8_compile("obj.length"); | 1290 Local<Script> script = v8_compile("obj.length"); |
1212 CHECK_EQ(0, script->Run()->Int32Value()); | 1291 CHECK_EQ(0, v8_run_int32value(script)); |
1213 } | 1292 } |
1214 } | 1293 } |
1215 | 1294 |
1216 | 1295 |
1217 static void* expected_ptr; | 1296 static void* expected_ptr; |
1218 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1297 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
1219 void* ptr = v8::External::Cast(*args.Data())->Value(); | 1298 void* ptr = v8::External::Cast(*args.Data())->Value(); |
1220 CHECK_EQ(expected_ptr, ptr); | 1299 CHECK_EQ(expected_ptr, ptr); |
1221 args.GetReturnValue().Set(true); | 1300 args.GetReturnValue().Set(true); |
1222 } | 1301 } |
1223 | 1302 |
1224 | 1303 |
1225 static void TestExternalPointerWrapping() { | 1304 static void TestExternalPointerWrapping() { |
1226 LocalContext env; | 1305 LocalContext env; |
1227 v8::Isolate* isolate = env->GetIsolate(); | 1306 v8::Isolate* isolate = env->GetIsolate(); |
1228 v8::HandleScope scope(isolate); | 1307 v8::HandleScope scope(isolate); |
1229 | 1308 |
1230 v8::Handle<v8::Value> data = | 1309 v8::Local<v8::Value> data = v8::External::New(isolate, expected_ptr); |
1231 v8::External::New(isolate, expected_ptr); | |
1232 | 1310 |
1233 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 1311 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
1234 obj->Set(v8_str("func"), | 1312 CHECK(obj->Set(env.local(), v8_str("func"), |
1235 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction()); | 1313 v8::FunctionTemplate::New(isolate, callback, data) |
1236 env->Global()->Set(v8_str("obj"), obj); | 1314 ->GetFunction(env.local()) |
1315 .ToLocalChecked()) | |
1316 .FromJust()); | |
1317 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust()); | |
1237 | 1318 |
1238 CHECK(CompileRun( | 1319 CHECK(CompileRun("function foo() {\n" |
1239 "function foo() {\n" | 1320 " for (var i = 0; i < 13; i++) obj.func();\n" |
1240 " for (var i = 0; i < 13; i++) obj.func();\n" | 1321 "}\n" |
1241 "}\n" | 1322 "foo(), true") |
1242 "foo(), true")->BooleanValue()); | 1323 ->BooleanValue(env.local()) |
1324 .FromJust()); | |
1243 } | 1325 } |
1244 | 1326 |
1245 | 1327 |
1246 THREADED_TEST(ExternalWrap) { | 1328 THREADED_TEST(ExternalWrap) { |
1247 // Check heap allocated object. | 1329 // Check heap allocated object. |
1248 int* ptr = new int; | 1330 int* ptr = new int; |
1249 expected_ptr = ptr; | 1331 expected_ptr = ptr; |
1250 TestExternalPointerWrapping(); | 1332 TestExternalPointerWrapping(); |
1251 delete ptr; | 1333 delete ptr; |
1252 | 1334 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1292 THREADED_TEST(FindInstanceInPrototypeChain) { | 1374 THREADED_TEST(FindInstanceInPrototypeChain) { |
1293 LocalContext env; | 1375 LocalContext env; |
1294 v8::Isolate* isolate = env->GetIsolate(); | 1376 v8::Isolate* isolate = env->GetIsolate(); |
1295 v8::HandleScope scope(isolate); | 1377 v8::HandleScope scope(isolate); |
1296 | 1378 |
1297 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate); | 1379 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate); |
1298 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate); | 1380 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate); |
1299 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate); | 1381 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate); |
1300 derived->Inherit(base); | 1382 derived->Inherit(base); |
1301 | 1383 |
1302 Local<v8::Function> base_function = base->GetFunction(); | 1384 Local<v8::Function> base_function = |
1303 Local<v8::Function> derived_function = derived->GetFunction(); | 1385 base->GetFunction(env.local()).ToLocalChecked(); |
1304 Local<v8::Function> other_function = other->GetFunction(); | 1386 Local<v8::Function> derived_function = |
1387 derived->GetFunction(env.local()).ToLocalChecked(); | |
1388 Local<v8::Function> other_function = | |
1389 other->GetFunction(env.local()).ToLocalChecked(); | |
1305 | 1390 |
1306 Local<v8::Object> base_instance = base_function->NewInstance(); | 1391 Local<v8::Object> base_instance = |
1307 Local<v8::Object> derived_instance = derived_function->NewInstance(); | 1392 base_function->NewInstance(env.local()).ToLocalChecked(); |
1308 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); | 1393 Local<v8::Object> derived_instance = |
1309 Local<v8::Object> other_instance = other_function->NewInstance(); | 1394 derived_function->NewInstance(env.local()).ToLocalChecked(); |
1310 derived_instance2->Set(v8_str("__proto__"), derived_instance); | 1395 Local<v8::Object> derived_instance2 = |
1311 other_instance->Set(v8_str("__proto__"), derived_instance2); | 1396 derived_function->NewInstance(env.local()).ToLocalChecked(); |
1397 Local<v8::Object> other_instance = | |
1398 other_function->NewInstance(env.local()).ToLocalChecked(); | |
1399 CHECK( | |
1400 derived_instance2->Set(env.local(), v8_str("__proto__"), derived_instance) | |
1401 .FromJust()); | |
1402 CHECK(other_instance->Set(env.local(), v8_str("__proto__"), derived_instance2) | |
1403 .FromJust()); | |
1312 | 1404 |
1313 // base_instance is only an instance of base. | 1405 // base_instance is only an instance of base. |
1314 CHECK( | 1406 CHECK(base_instance->Equals(env.local(), |
1315 base_instance->Equals(base_instance->FindInstanceInPrototypeChain(base))); | 1407 base_instance->FindInstanceInPrototypeChain(base)) |
1408 .FromJust()); | |
1316 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty()); | 1409 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty()); |
1317 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty()); | 1410 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty()); |
1318 | 1411 |
1319 // derived_instance is an instance of base and derived. | 1412 // derived_instance is an instance of base and derived. |
1320 CHECK(derived_instance->Equals( | 1413 CHECK(derived_instance->Equals(env.local(), |
1321 derived_instance->FindInstanceInPrototypeChain(base))); | 1414 derived_instance->FindInstanceInPrototypeChain( |
1322 CHECK(derived_instance->Equals( | 1415 base)) |
1323 derived_instance->FindInstanceInPrototypeChain(derived))); | 1416 .FromJust()); |
1417 CHECK(derived_instance->Equals(env.local(), | |
1418 derived_instance->FindInstanceInPrototypeChain( | |
1419 derived)) | |
1420 .FromJust()); | |
1324 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty()); | 1421 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty()); |
1325 | 1422 |
1326 // other_instance is an instance of other and its immediate | 1423 // other_instance is an instance of other and its immediate |
1327 // prototype derived_instance2 is an instance of base and derived. | 1424 // prototype derived_instance2 is an instance of base and derived. |
1328 // Note, derived_instance is an instance of base and derived too, | 1425 // Note, derived_instance is an instance of base and derived too, |
1329 // but it comes after derived_instance2 in the prototype chain of | 1426 // but it comes after derived_instance2 in the prototype chain of |
1330 // other_instance. | 1427 // other_instance. |
1331 CHECK(derived_instance2->Equals( | 1428 CHECK(derived_instance2->Equals( |
1332 other_instance->FindInstanceInPrototypeChain(base))); | 1429 env.local(), |
1333 CHECK(derived_instance2->Equals( | 1430 other_instance->FindInstanceInPrototypeChain(base)) |
1334 other_instance->FindInstanceInPrototypeChain(derived))); | 1431 .FromJust()); |
1432 CHECK(derived_instance2->Equals(env.local(), | |
1433 other_instance->FindInstanceInPrototypeChain( | |
1434 derived)) | |
1435 .FromJust()); | |
1335 CHECK(other_instance->Equals( | 1436 CHECK(other_instance->Equals( |
1336 other_instance->FindInstanceInPrototypeChain(other))); | 1437 env.local(), |
1438 other_instance->FindInstanceInPrototypeChain(other)) | |
1439 .FromJust()); | |
1337 } | 1440 } |
1338 | 1441 |
1339 | 1442 |
1340 THREADED_TEST(TinyInteger) { | 1443 THREADED_TEST(TinyInteger) { |
1341 LocalContext env; | 1444 LocalContext env; |
1342 v8::Isolate* isolate = env->GetIsolate(); | 1445 v8::Isolate* isolate = env->GetIsolate(); |
1343 v8::HandleScope scope(isolate); | 1446 v8::HandleScope scope(isolate); |
1344 | 1447 |
1345 int32_t value = 239; | 1448 int32_t value = 239; |
1346 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); | 1449 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1456 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); | 1559 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
1457 | 1560 |
1458 value_obj = v8::Integer::NewFromUnsigned(isolate, value); | 1561 value_obj = v8::Integer::NewFromUnsigned(isolate, value); |
1459 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); | 1562 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
1460 } | 1563 } |
1461 | 1564 |
1462 | 1565 |
1463 THREADED_TEST(IsNativeError) { | 1566 THREADED_TEST(IsNativeError) { |
1464 LocalContext env; | 1567 LocalContext env; |
1465 v8::HandleScope scope(env->GetIsolate()); | 1568 v8::HandleScope scope(env->GetIsolate()); |
1466 v8::Handle<Value> syntax_error = CompileRun( | 1569 v8::Local<Value> syntax_error = CompileRun( |
1467 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); | 1570 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); |
1468 CHECK(syntax_error->IsNativeError()); | 1571 CHECK(syntax_error->IsNativeError()); |
1469 v8::Handle<Value> not_error = CompileRun("{a:42}"); | 1572 v8::Local<Value> not_error = CompileRun("{a:42}"); |
1470 CHECK(!not_error->IsNativeError()); | 1573 CHECK(!not_error->IsNativeError()); |
1471 v8::Handle<Value> not_object = CompileRun("42"); | 1574 v8::Local<Value> not_object = CompileRun("42"); |
1472 CHECK(!not_object->IsNativeError()); | 1575 CHECK(!not_object->IsNativeError()); |
1473 } | 1576 } |
1474 | 1577 |
1475 | 1578 |
1476 THREADED_TEST(IsGeneratorFunctionOrObject) { | 1579 THREADED_TEST(IsGeneratorFunctionOrObject) { |
1477 LocalContext env; | 1580 LocalContext env; |
1478 v8::HandleScope scope(env->GetIsolate()); | 1581 v8::HandleScope scope(env->GetIsolate()); |
1479 | 1582 |
1480 CompileRun("function *gen() { yield 1; }\nfunction func() {}"); | 1583 CompileRun("function *gen() { yield 1; }\nfunction func() {}"); |
1481 v8::Handle<Value> gen = CompileRun("gen"); | 1584 v8::Local<Value> gen = CompileRun("gen"); |
1482 v8::Handle<Value> genObj = CompileRun("gen()"); | 1585 v8::Local<Value> genObj = CompileRun("gen()"); |
1483 v8::Handle<Value> object = CompileRun("{a:42}"); | 1586 v8::Local<Value> object = CompileRun("{a:42}"); |
1484 v8::Handle<Value> func = CompileRun("func"); | 1587 v8::Local<Value> func = CompileRun("func"); |
1485 | 1588 |
1486 CHECK(gen->IsGeneratorFunction()); | 1589 CHECK(gen->IsGeneratorFunction()); |
1487 CHECK(gen->IsFunction()); | 1590 CHECK(gen->IsFunction()); |
1488 CHECK(!gen->IsGeneratorObject()); | 1591 CHECK(!gen->IsGeneratorObject()); |
1489 | 1592 |
1490 CHECK(!genObj->IsGeneratorFunction()); | 1593 CHECK(!genObj->IsGeneratorFunction()); |
1491 CHECK(!genObj->IsFunction()); | 1594 CHECK(!genObj->IsFunction()); |
1492 CHECK(genObj->IsGeneratorObject()); | 1595 CHECK(genObj->IsGeneratorObject()); |
1493 | 1596 |
1494 CHECK(!object->IsGeneratorFunction()); | 1597 CHECK(!object->IsGeneratorFunction()); |
1495 CHECK(!object->IsFunction()); | 1598 CHECK(!object->IsFunction()); |
1496 CHECK(!object->IsGeneratorObject()); | 1599 CHECK(!object->IsGeneratorObject()); |
1497 | 1600 |
1498 CHECK(!func->IsGeneratorFunction()); | 1601 CHECK(!func->IsGeneratorFunction()); |
1499 CHECK(func->IsFunction()); | 1602 CHECK(func->IsFunction()); |
1500 CHECK(!func->IsGeneratorObject()); | 1603 CHECK(!func->IsGeneratorObject()); |
1501 } | 1604 } |
1502 | 1605 |
1503 | 1606 |
1504 THREADED_TEST(ArgumentsObject) { | 1607 THREADED_TEST(ArgumentsObject) { |
1505 LocalContext env; | 1608 LocalContext env; |
1506 v8::HandleScope scope(env->GetIsolate()); | 1609 v8::HandleScope scope(env->GetIsolate()); |
1507 v8::Handle<Value> arguments_object = | 1610 v8::Local<Value> arguments_object = |
1508 CompileRun("var out = 0; (function(){ out = arguments; })(1,2,3); out;"); | 1611 CompileRun("var out = 0; (function(){ out = arguments; })(1,2,3); out;"); |
1509 CHECK(arguments_object->IsArgumentsObject()); | 1612 CHECK(arguments_object->IsArgumentsObject()); |
1510 v8::Handle<Value> array = CompileRun("[1,2,3]"); | 1613 v8::Local<Value> array = CompileRun("[1,2,3]"); |
1511 CHECK(!array->IsArgumentsObject()); | 1614 CHECK(!array->IsArgumentsObject()); |
1512 v8::Handle<Value> object = CompileRun("{a:42}"); | 1615 v8::Local<Value> object = CompileRun("{a:42}"); |
1513 CHECK(!object->IsArgumentsObject()); | 1616 CHECK(!object->IsArgumentsObject()); |
1514 } | 1617 } |
1515 | 1618 |
1516 | 1619 |
1517 THREADED_TEST(IsMapOrSet) { | 1620 THREADED_TEST(IsMapOrSet) { |
1518 LocalContext env; | 1621 LocalContext env; |
1519 v8::HandleScope scope(env->GetIsolate()); | 1622 v8::HandleScope scope(env->GetIsolate()); |
1520 v8::Handle<Value> map = CompileRun("new Map()"); | 1623 v8::Local<Value> map = CompileRun("new Map()"); |
1521 v8::Handle<Value> set = CompileRun("new Set()"); | 1624 v8::Local<Value> set = CompileRun("new Set()"); |
1522 v8::Handle<Value> weak_map = CompileRun("new WeakMap()"); | 1625 v8::Local<Value> weak_map = CompileRun("new WeakMap()"); |
1523 v8::Handle<Value> weak_set = CompileRun("new WeakSet()"); | 1626 v8::Local<Value> weak_set = CompileRun("new WeakSet()"); |
1524 CHECK(map->IsMap()); | 1627 CHECK(map->IsMap()); |
1525 CHECK(set->IsSet()); | 1628 CHECK(set->IsSet()); |
1526 CHECK(weak_map->IsWeakMap()); | 1629 CHECK(weak_map->IsWeakMap()); |
1527 CHECK(weak_set->IsWeakSet()); | 1630 CHECK(weak_set->IsWeakSet()); |
1528 | 1631 |
1529 CHECK(!map->IsSet()); | 1632 CHECK(!map->IsSet()); |
1530 CHECK(!map->IsWeakMap()); | 1633 CHECK(!map->IsWeakMap()); |
1531 CHECK(!map->IsWeakSet()); | 1634 CHECK(!map->IsWeakSet()); |
1532 | 1635 |
1533 CHECK(!set->IsMap()); | 1636 CHECK(!set->IsMap()); |
1534 CHECK(!set->IsWeakMap()); | 1637 CHECK(!set->IsWeakMap()); |
1535 CHECK(!set->IsWeakSet()); | 1638 CHECK(!set->IsWeakSet()); |
1536 | 1639 |
1537 CHECK(!weak_map->IsMap()); | 1640 CHECK(!weak_map->IsMap()); |
1538 CHECK(!weak_map->IsSet()); | 1641 CHECK(!weak_map->IsSet()); |
1539 CHECK(!weak_map->IsWeakSet()); | 1642 CHECK(!weak_map->IsWeakSet()); |
1540 | 1643 |
1541 CHECK(!weak_set->IsMap()); | 1644 CHECK(!weak_set->IsMap()); |
1542 CHECK(!weak_set->IsSet()); | 1645 CHECK(!weak_set->IsSet()); |
1543 CHECK(!weak_set->IsWeakMap()); | 1646 CHECK(!weak_set->IsWeakMap()); |
1544 | 1647 |
1545 v8::Handle<Value> object = CompileRun("{a:42}"); | 1648 v8::Local<Value> object = CompileRun("{a:42}"); |
1546 CHECK(!object->IsMap()); | 1649 CHECK(!object->IsMap()); |
1547 CHECK(!object->IsSet()); | 1650 CHECK(!object->IsSet()); |
1548 CHECK(!object->IsWeakMap()); | 1651 CHECK(!object->IsWeakMap()); |
1549 CHECK(!object->IsWeakSet()); | 1652 CHECK(!object->IsWeakSet()); |
1550 } | 1653 } |
1551 | 1654 |
1552 | 1655 |
1553 THREADED_TEST(StringObject) { | 1656 THREADED_TEST(StringObject) { |
1554 LocalContext env; | 1657 LocalContext env; |
1555 v8::HandleScope scope(env->GetIsolate()); | 1658 v8::HandleScope scope(env->GetIsolate()); |
1556 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); | 1659 v8::Local<Value> boxed_string = CompileRun("new String(\"test\")"); |
1557 CHECK(boxed_string->IsStringObject()); | 1660 CHECK(boxed_string->IsStringObject()); |
1558 v8::Handle<Value> unboxed_string = CompileRun("\"test\""); | 1661 v8::Local<Value> unboxed_string = CompileRun("\"test\""); |
1559 CHECK(!unboxed_string->IsStringObject()); | 1662 CHECK(!unboxed_string->IsStringObject()); |
1560 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)"); | 1663 v8::Local<Value> boxed_not_string = CompileRun("new Number(42)"); |
1561 CHECK(!boxed_not_string->IsStringObject()); | 1664 CHECK(!boxed_not_string->IsStringObject()); |
1562 v8::Handle<Value> not_object = CompileRun("0"); | 1665 v8::Local<Value> not_object = CompileRun("0"); |
1563 CHECK(!not_object->IsStringObject()); | 1666 CHECK(!not_object->IsStringObject()); |
1564 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>(); | 1667 v8::Local<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>(); |
1565 CHECK(!as_boxed.IsEmpty()); | 1668 CHECK(!as_boxed.IsEmpty()); |
1566 Local<v8::String> the_string = as_boxed->ValueOf(); | 1669 Local<v8::String> the_string = as_boxed->ValueOf(); |
1567 CHECK(!the_string.IsEmpty()); | 1670 CHECK(!the_string.IsEmpty()); |
1568 ExpectObject("\"test\"", the_string); | 1671 ExpectObject("\"test\"", the_string); |
1569 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string); | 1672 v8::Local<v8::Value> new_boxed_string = v8::StringObject::New(the_string); |
1570 CHECK(new_boxed_string->IsStringObject()); | 1673 CHECK(new_boxed_string->IsStringObject()); |
1571 as_boxed = new_boxed_string.As<v8::StringObject>(); | 1674 as_boxed = new_boxed_string.As<v8::StringObject>(); |
1572 the_string = as_boxed->ValueOf(); | 1675 the_string = as_boxed->ValueOf(); |
1573 CHECK(!the_string.IsEmpty()); | 1676 CHECK(!the_string.IsEmpty()); |
1574 ExpectObject("\"test\"", the_string); | 1677 ExpectObject("\"test\"", the_string); |
1575 } | 1678 } |
1576 | 1679 |
1577 | 1680 |
1578 TEST(StringObjectDelete) { | 1681 TEST(StringObjectDelete) { |
1579 LocalContext context; | 1682 LocalContext context; |
1580 v8::HandleScope scope(context->GetIsolate()); | 1683 v8::HandleScope scope(context->GetIsolate()); |
1581 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); | 1684 v8::Local<Value> boxed_string = CompileRun("new String(\"test\")"); |
1582 CHECK(boxed_string->IsStringObject()); | 1685 CHECK(boxed_string->IsStringObject()); |
1583 v8::Handle<v8::Object> str_obj = boxed_string.As<v8::Object>(); | 1686 v8::Local<v8::Object> str_obj = boxed_string.As<v8::Object>(); |
1584 CHECK(!str_obj->Delete(2)); | 1687 CHECK(!str_obj->Delete(context.local(), 2).FromJust()); |
1585 CHECK(!str_obj->Delete(v8_num(2))); | 1688 CHECK(!str_obj->Delete(context.local(), v8_num(2)).FromJust()); |
1586 } | 1689 } |
1587 | 1690 |
1588 | 1691 |
1589 THREADED_TEST(NumberObject) { | 1692 THREADED_TEST(NumberObject) { |
1590 LocalContext env; | 1693 LocalContext env; |
1591 v8::HandleScope scope(env->GetIsolate()); | 1694 v8::HandleScope scope(env->GetIsolate()); |
1592 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); | 1695 v8::Local<Value> boxed_number = CompileRun("new Number(42)"); |
1593 CHECK(boxed_number->IsNumberObject()); | 1696 CHECK(boxed_number->IsNumberObject()); |
1594 v8::Handle<Value> unboxed_number = CompileRun("42"); | 1697 v8::Local<Value> unboxed_number = CompileRun("42"); |
1595 CHECK(!unboxed_number->IsNumberObject()); | 1698 CHECK(!unboxed_number->IsNumberObject()); |
1596 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); | 1699 v8::Local<Value> boxed_not_number = CompileRun("new Boolean(false)"); |
1597 CHECK(!boxed_not_number->IsNumberObject()); | 1700 CHECK(!boxed_not_number->IsNumberObject()); |
1598 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); | 1701 v8::Local<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); |
1599 CHECK(!as_boxed.IsEmpty()); | 1702 CHECK(!as_boxed.IsEmpty()); |
1600 double the_number = as_boxed->ValueOf(); | 1703 double the_number = as_boxed->ValueOf(); |
1601 CHECK_EQ(42.0, the_number); | 1704 CHECK_EQ(42.0, the_number); |
1602 v8::Handle<v8::Value> new_boxed_number = | 1705 v8::Local<v8::Value> new_boxed_number = |
1603 v8::NumberObject::New(env->GetIsolate(), 43); | 1706 v8::NumberObject::New(env->GetIsolate(), 43); |
1604 CHECK(new_boxed_number->IsNumberObject()); | 1707 CHECK(new_boxed_number->IsNumberObject()); |
1605 as_boxed = new_boxed_number.As<v8::NumberObject>(); | 1708 as_boxed = new_boxed_number.As<v8::NumberObject>(); |
1606 the_number = as_boxed->ValueOf(); | 1709 the_number = as_boxed->ValueOf(); |
1607 CHECK_EQ(43.0, the_number); | 1710 CHECK_EQ(43.0, the_number); |
1608 } | 1711 } |
1609 | 1712 |
1610 | 1713 |
1611 THREADED_TEST(BooleanObject) { | 1714 THREADED_TEST(BooleanObject) { |
1612 LocalContext env; | 1715 LocalContext env; |
1613 v8::HandleScope scope(env->GetIsolate()); | 1716 v8::HandleScope scope(env->GetIsolate()); |
1614 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)"); | 1717 v8::Local<Value> boxed_boolean = CompileRun("new Boolean(true)"); |
1615 CHECK(boxed_boolean->IsBooleanObject()); | 1718 CHECK(boxed_boolean->IsBooleanObject()); |
1616 v8::Handle<Value> unboxed_boolean = CompileRun("true"); | 1719 v8::Local<Value> unboxed_boolean = CompileRun("true"); |
1617 CHECK(!unboxed_boolean->IsBooleanObject()); | 1720 CHECK(!unboxed_boolean->IsBooleanObject()); |
1618 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)"); | 1721 v8::Local<Value> boxed_not_boolean = CompileRun("new Number(42)"); |
1619 CHECK(!boxed_not_boolean->IsBooleanObject()); | 1722 CHECK(!boxed_not_boolean->IsBooleanObject()); |
1620 v8::Handle<v8::BooleanObject> as_boxed = | 1723 v8::Local<v8::BooleanObject> as_boxed = boxed_boolean.As<v8::BooleanObject>(); |
1621 boxed_boolean.As<v8::BooleanObject>(); | |
1622 CHECK(!as_boxed.IsEmpty()); | 1724 CHECK(!as_boxed.IsEmpty()); |
1623 bool the_boolean = as_boxed->ValueOf(); | 1725 bool the_boolean = as_boxed->ValueOf(); |
1624 CHECK_EQ(true, the_boolean); | 1726 CHECK_EQ(true, the_boolean); |
1625 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true); | 1727 v8::Local<v8::Value> boxed_true = v8::BooleanObject::New(true); |
1626 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false); | 1728 v8::Local<v8::Value> boxed_false = v8::BooleanObject::New(false); |
1627 CHECK(boxed_true->IsBooleanObject()); | 1729 CHECK(boxed_true->IsBooleanObject()); |
1628 CHECK(boxed_false->IsBooleanObject()); | 1730 CHECK(boxed_false->IsBooleanObject()); |
1629 as_boxed = boxed_true.As<v8::BooleanObject>(); | 1731 as_boxed = boxed_true.As<v8::BooleanObject>(); |
1630 CHECK_EQ(true, as_boxed->ValueOf()); | 1732 CHECK_EQ(true, as_boxed->ValueOf()); |
1631 as_boxed = boxed_false.As<v8::BooleanObject>(); | 1733 as_boxed = boxed_false.As<v8::BooleanObject>(); |
1632 CHECK_EQ(false, as_boxed->ValueOf()); | 1734 CHECK_EQ(false, as_boxed->ValueOf()); |
1633 } | 1735 } |
1634 | 1736 |
1635 | 1737 |
1636 THREADED_TEST(PrimitiveAndWrappedBooleans) { | 1738 THREADED_TEST(PrimitiveAndWrappedBooleans) { |
1637 LocalContext env; | 1739 LocalContext env; |
1638 v8::HandleScope scope(env->GetIsolate()); | 1740 v8::HandleScope scope(env->GetIsolate()); |
1639 | 1741 |
1640 Local<Value> primitive_false = Boolean::New(env->GetIsolate(), false); | 1742 Local<Value> primitive_false = Boolean::New(env->GetIsolate(), false); |
1641 CHECK(primitive_false->IsBoolean()); | 1743 CHECK(primitive_false->IsBoolean()); |
1642 CHECK(!primitive_false->IsBooleanObject()); | 1744 CHECK(!primitive_false->IsBooleanObject()); |
1643 CHECK(!primitive_false->BooleanValue()); | 1745 CHECK(!primitive_false->BooleanValue(env.local()).FromJust()); |
1644 CHECK(!primitive_false->IsTrue()); | 1746 CHECK(!primitive_false->IsTrue()); |
1645 CHECK(primitive_false->IsFalse()); | 1747 CHECK(primitive_false->IsFalse()); |
1646 | 1748 |
1647 Local<Value> false_value = BooleanObject::New(false); | 1749 Local<Value> false_value = BooleanObject::New(false); |
1648 CHECK(!false_value->IsBoolean()); | 1750 CHECK(!false_value->IsBoolean()); |
1649 CHECK(false_value->IsBooleanObject()); | 1751 CHECK(false_value->IsBooleanObject()); |
1650 CHECK(false_value->BooleanValue()); | 1752 CHECK(false_value->BooleanValue(env.local()).FromJust()); |
1651 CHECK(!false_value->IsTrue()); | 1753 CHECK(!false_value->IsTrue()); |
1652 CHECK(!false_value->IsFalse()); | 1754 CHECK(!false_value->IsFalse()); |
1653 | 1755 |
1654 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>(); | 1756 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>(); |
1655 CHECK(!false_boolean_object->IsBoolean()); | 1757 CHECK(!false_boolean_object->IsBoolean()); |
1656 CHECK(false_boolean_object->IsBooleanObject()); | 1758 CHECK(false_boolean_object->IsBooleanObject()); |
1657 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted. | 1759 CHECK(false_boolean_object->BooleanValue(env.local()).FromJust()); |
1658 // CHECK(false_boolean_object->BooleanValue()); | |
1659 CHECK(!false_boolean_object->ValueOf()); | 1760 CHECK(!false_boolean_object->ValueOf()); |
1660 CHECK(!false_boolean_object->IsTrue()); | 1761 CHECK(!false_boolean_object->IsTrue()); |
1661 CHECK(!false_boolean_object->IsFalse()); | 1762 CHECK(!false_boolean_object->IsFalse()); |
1662 | 1763 |
1663 Local<Value> primitive_true = Boolean::New(env->GetIsolate(), true); | 1764 Local<Value> primitive_true = Boolean::New(env->GetIsolate(), true); |
1664 CHECK(primitive_true->IsBoolean()); | 1765 CHECK(primitive_true->IsBoolean()); |
1665 CHECK(!primitive_true->IsBooleanObject()); | 1766 CHECK(!primitive_true->IsBooleanObject()); |
1666 CHECK(primitive_true->BooleanValue()); | 1767 CHECK(primitive_true->BooleanValue(env.local()).FromJust()); |
1667 CHECK(primitive_true->IsTrue()); | 1768 CHECK(primitive_true->IsTrue()); |
1668 CHECK(!primitive_true->IsFalse()); | 1769 CHECK(!primitive_true->IsFalse()); |
1669 | 1770 |
1670 Local<Value> true_value = BooleanObject::New(true); | 1771 Local<Value> true_value = BooleanObject::New(true); |
1671 CHECK(!true_value->IsBoolean()); | 1772 CHECK(!true_value->IsBoolean()); |
1672 CHECK(true_value->IsBooleanObject()); | 1773 CHECK(true_value->IsBooleanObject()); |
1673 CHECK(true_value->BooleanValue()); | 1774 CHECK(true_value->BooleanValue(env.local()).FromJust()); |
1674 CHECK(!true_value->IsTrue()); | 1775 CHECK(!true_value->IsTrue()); |
1675 CHECK(!true_value->IsFalse()); | 1776 CHECK(!true_value->IsFalse()); |
1676 | 1777 |
1677 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>(); | 1778 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>(); |
1678 CHECK(!true_boolean_object->IsBoolean()); | 1779 CHECK(!true_boolean_object->IsBoolean()); |
1679 CHECK(true_boolean_object->IsBooleanObject()); | 1780 CHECK(true_boolean_object->IsBooleanObject()); |
1680 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted. | 1781 CHECK(true_boolean_object->BooleanValue(env.local()).FromJust()); |
1681 // CHECK(true_boolean_object->BooleanValue()); | |
1682 CHECK(true_boolean_object->ValueOf()); | 1782 CHECK(true_boolean_object->ValueOf()); |
1683 CHECK(!true_boolean_object->IsTrue()); | 1783 CHECK(!true_boolean_object->IsTrue()); |
1684 CHECK(!true_boolean_object->IsFalse()); | 1784 CHECK(!true_boolean_object->IsFalse()); |
1685 } | 1785 } |
1686 | 1786 |
1687 | 1787 |
1688 THREADED_TEST(Number) { | 1788 THREADED_TEST(Number) { |
1689 LocalContext env; | 1789 LocalContext env; |
1690 v8::HandleScope scope(env->GetIsolate()); | 1790 v8::HandleScope scope(env->GetIsolate()); |
1691 double PI = 3.1415926; | 1791 double PI = 3.1415926; |
1692 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI); | 1792 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI); |
1693 CHECK_EQ(PI, pi_obj->NumberValue()); | 1793 CHECK_EQ(PI, pi_obj->NumberValue(env.local()).FromJust()); |
1694 } | 1794 } |
1695 | 1795 |
1696 | 1796 |
1697 THREADED_TEST(ToNumber) { | 1797 THREADED_TEST(ToNumber) { |
1698 LocalContext env; | 1798 LocalContext env; |
1699 v8::Isolate* isolate = CcTest::isolate(); | 1799 v8::Isolate* isolate = CcTest::isolate(); |
1700 v8::HandleScope scope(isolate); | 1800 v8::HandleScope scope(isolate); |
1701 Local<String> str = v8_str("3.1415926"); | 1801 Local<String> str = v8_str("3.1415926"); |
1702 CHECK_EQ(3.1415926, str->NumberValue()); | 1802 CHECK_EQ(3.1415926, str->NumberValue(env.local()).FromJust()); |
1703 v8::Handle<v8::Boolean> t = v8::True(isolate); | 1803 v8::Local<v8::Boolean> t = v8::True(isolate); |
1704 CHECK_EQ(1.0, t->NumberValue()); | 1804 CHECK_EQ(1.0, t->NumberValue(env.local()).FromJust()); |
1705 v8::Handle<v8::Boolean> f = v8::False(isolate); | 1805 v8::Local<v8::Boolean> f = v8::False(isolate); |
1706 CHECK_EQ(0.0, f->NumberValue()); | 1806 CHECK_EQ(0.0, f->NumberValue(env.local()).FromJust()); |
1707 } | 1807 } |
1708 | 1808 |
1709 | 1809 |
1710 THREADED_TEST(Date) { | 1810 THREADED_TEST(Date) { |
1711 LocalContext env; | 1811 LocalContext env; |
1712 v8::HandleScope scope(env->GetIsolate()); | 1812 v8::HandleScope scope(env->GetIsolate()); |
1713 double PI = 3.1415926; | 1813 double PI = 3.1415926; |
1714 Local<Value> date = v8::Date::New(env->GetIsolate(), PI); | 1814 Local<Value> date = v8::Date::New(env.local(), PI).ToLocalChecked(); |
1715 CHECK_EQ(3.0, date->NumberValue()); | 1815 CHECK_EQ(3.0, date->NumberValue(env.local()).FromJust()); |
1716 date.As<v8::Date>()->Set(v8_str("property"), | 1816 CHECK(date.As<v8::Date>() |
1717 v8::Integer::New(env->GetIsolate(), 42)); | 1817 ->Set(env.local(), v8_str("property"), |
1718 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); | 1818 v8::Integer::New(env->GetIsolate(), 42)) |
1819 .FromJust()); | |
1820 CHECK_EQ(42, date.As<v8::Date>() | |
1821 ->Get(env.local(), v8_str("property")) | |
1822 .ToLocalChecked() | |
1823 ->Int32Value(env.local()) | |
1824 .FromJust()); | |
1719 } | 1825 } |
1720 | 1826 |
1721 | 1827 |
1722 THREADED_TEST(Boolean) { | 1828 THREADED_TEST(Boolean) { |
1723 LocalContext env; | 1829 LocalContext env; |
1724 v8::Isolate* isolate = env->GetIsolate(); | 1830 v8::Isolate* isolate = env->GetIsolate(); |
1725 v8::HandleScope scope(isolate); | 1831 v8::HandleScope scope(isolate); |
1726 v8::Handle<v8::Boolean> t = v8::True(isolate); | 1832 v8::Local<v8::Boolean> t = v8::True(isolate); |
1727 CHECK(t->Value()); | 1833 CHECK(t->Value()); |
1728 v8::Handle<v8::Boolean> f = v8::False(isolate); | 1834 v8::Local<v8::Boolean> f = v8::False(isolate); |
1729 CHECK(!f->Value()); | 1835 CHECK(!f->Value()); |
1730 v8::Handle<v8::Primitive> u = v8::Undefined(isolate); | 1836 v8::Local<v8::Primitive> u = v8::Undefined(isolate); |
1731 CHECK(!u->BooleanValue()); | 1837 CHECK(!u->BooleanValue(env.local()).FromJust()); |
1732 v8::Handle<v8::Primitive> n = v8::Null(isolate); | 1838 v8::Local<v8::Primitive> n = v8::Null(isolate); |
1733 CHECK(!n->BooleanValue()); | 1839 CHECK(!n->BooleanValue(env.local()).FromJust()); |
1734 v8::Handle<String> str1 = v8_str(""); | 1840 v8::Local<String> str1 = v8_str(""); |
1735 CHECK(!str1->BooleanValue()); | 1841 CHECK(!str1->BooleanValue(env.local()).FromJust()); |
1736 v8::Handle<String> str2 = v8_str("x"); | 1842 v8::Local<String> str2 = v8_str("x"); |
1737 CHECK(str2->BooleanValue()); | 1843 CHECK(str2->BooleanValue(env.local()).FromJust()); |
1738 CHECK(!v8::Number::New(isolate, 0)->BooleanValue()); | 1844 CHECK(!v8::Number::New(isolate, 0)->BooleanValue(env.local()).FromJust()); |
1739 CHECK(v8::Number::New(isolate, -1)->BooleanValue()); | 1845 CHECK(v8::Number::New(isolate, -1)->BooleanValue(env.local()).FromJust()); |
1740 CHECK(v8::Number::New(isolate, 1)->BooleanValue()); | 1846 CHECK(v8::Number::New(isolate, 1)->BooleanValue(env.local()).FromJust()); |
1741 CHECK(v8::Number::New(isolate, 42)->BooleanValue()); | 1847 CHECK(v8::Number::New(isolate, 42)->BooleanValue(env.local()).FromJust()); |
1742 CHECK(!v8_compile("NaN")->Run()->BooleanValue()); | 1848 CHECK(!v8_compile("NaN") |
1849 ->Run(env.local()) | |
1850 .ToLocalChecked() | |
1851 ->BooleanValue(env.local()) | |
1852 .FromJust()); | |
1743 } | 1853 } |
1744 | 1854 |
1745 | 1855 |
1746 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1856 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) { |
1747 ApiTestFuzzer::Fuzz(); | 1857 ApiTestFuzzer::Fuzz(); |
1748 args.GetReturnValue().Set(v8_num(13.4)); | 1858 args.GetReturnValue().Set(v8_num(13.4)); |
1749 } | 1859 } |
1750 | 1860 |
1751 | 1861 |
1752 static void GetM(Local<String> name, | 1862 static void GetM(Local<String> name, |
1753 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1863 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1754 ApiTestFuzzer::Fuzz(); | 1864 ApiTestFuzzer::Fuzz(); |
1755 info.GetReturnValue().Set(v8_num(876)); | 1865 info.GetReturnValue().Set(v8_num(876)); |
1756 } | 1866 } |
1757 | 1867 |
1758 | 1868 |
1759 THREADED_TEST(GlobalPrototype) { | 1869 THREADED_TEST(GlobalPrototype) { |
1760 v8::Isolate* isolate = CcTest::isolate(); | 1870 v8::Isolate* isolate = CcTest::isolate(); |
1761 v8::HandleScope scope(isolate); | 1871 v8::HandleScope scope(isolate); |
1762 v8::Handle<v8::FunctionTemplate> func_templ = | 1872 v8::Local<v8::FunctionTemplate> func_templ = |
1763 v8::FunctionTemplate::New(isolate); | 1873 v8::FunctionTemplate::New(isolate); |
1764 func_templ->PrototypeTemplate()->Set( | 1874 func_templ->PrototypeTemplate()->Set( |
1765 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler)); | 1875 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler)); |
1766 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); | 1876 v8::Local<ObjectTemplate> templ = func_templ->InstanceTemplate(); |
1767 templ->Set(isolate, "x", v8_num(200)); | 1877 templ->Set(isolate, "x", v8_num(200)); |
1768 templ->SetAccessor(v8_str("m"), GetM); | 1878 templ->SetAccessor(v8_str("m"), GetM); |
1769 LocalContext env(0, templ); | 1879 LocalContext env(0, templ); |
1770 v8::Handle<Script> script(v8_compile("dummy()")); | 1880 v8::Local<Script> script(v8_compile("dummy()")); |
1771 v8::Handle<Value> result(script->Run()); | 1881 v8::Local<Value> result(script->Run(env.local()).ToLocalChecked()); |
1772 CHECK_EQ(13.4, result->NumberValue()); | 1882 CHECK_EQ(13.4, result->NumberValue(env.local()).FromJust()); |
1773 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); | 1883 CHECK_EQ(200, v8_run_int32value(v8_compile("x"))); |
1774 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); | 1884 CHECK_EQ(876, v8_run_int32value(v8_compile("m"))); |
1775 } | 1885 } |
1776 | 1886 |
1777 | 1887 |
1778 THREADED_TEST(ObjectTemplate) { | 1888 THREADED_TEST(ObjectTemplate) { |
1779 v8::Isolate* isolate = CcTest::isolate(); | 1889 v8::Isolate* isolate = CcTest::isolate(); |
1780 v8::HandleScope scope(isolate); | 1890 v8::HandleScope scope(isolate); |
1781 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); | 1891 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); |
1782 v8::Local<v8::String> class_name = | 1892 v8::Local<v8::String> class_name = v8_str("the_class_name"); |
1783 v8::String::NewFromUtf8(isolate, "the_class_name"); | |
1784 fun->SetClassName(class_name); | 1893 fun->SetClassName(class_name); |
1785 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun); | 1894 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun); |
1786 templ1->Set(isolate, "x", v8_num(10)); | 1895 templ1->Set(isolate, "x", v8_num(10)); |
1787 templ1->Set(isolate, "y", v8_num(13)); | 1896 templ1->Set(isolate, "y", v8_num(13)); |
1788 LocalContext env; | 1897 LocalContext env; |
1789 Local<v8::Object> instance1 = templ1->NewInstance(); | 1898 Local<v8::Object> instance1 = |
1899 templ1->NewInstance(env.local()).ToLocalChecked(); | |
1790 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); | 1900 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); |
1791 env->Global()->Set(v8_str("p"), instance1); | 1901 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust()); |
1792 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); | 1902 CHECK(v8_compile("(p.x == 10)") |
1793 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); | 1903 ->Run(env.local()) |
1904 .ToLocalChecked() | |
1905 ->BooleanValue(env.local()) | |
1906 .FromJust()); | |
1907 CHECK(v8_compile("(p.y == 13)") | |
1908 ->Run(env.local()) | |
1909 .ToLocalChecked() | |
1910 ->BooleanValue(env.local()) | |
1911 .FromJust()); | |
1794 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); | 1912 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); |
1795 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); | 1913 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); |
1796 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); | 1914 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); |
1797 templ2->Set(isolate, "a", v8_num(12)); | 1915 templ2->Set(isolate, "a", v8_num(12)); |
1798 templ2->Set(isolate, "b", templ1); | 1916 templ2->Set(isolate, "b", templ1); |
1799 Local<v8::Object> instance2 = templ2->NewInstance(); | 1917 Local<v8::Object> instance2 = |
1800 env->Global()->Set(v8_str("q"), instance2); | 1918 templ2->NewInstance(env.local()).ToLocalChecked(); |
1801 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); | 1919 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust()); |
1802 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); | 1920 CHECK(v8_compile("(q.nirk == 123)") |
1803 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); | 1921 ->Run(env.local()) |
1804 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); | 1922 .ToLocalChecked() |
1923 ->BooleanValue(env.local()) | |
1924 .FromJust()); | |
1925 CHECK(v8_compile("(q.a == 12)") | |
1926 ->Run(env.local()) | |
1927 .ToLocalChecked() | |
1928 ->BooleanValue(env.local()) | |
1929 .FromJust()); | |
1930 CHECK(v8_compile("(q.b.x == 10)") | |
1931 ->Run(env.local()) | |
1932 .ToLocalChecked() | |
1933 ->BooleanValue(env.local()) | |
1934 .FromJust()); | |
1935 CHECK(v8_compile("(q.b.y == 13)") | |
1936 ->Run(env.local()) | |
1937 .ToLocalChecked() | |
1938 ->BooleanValue(env.local()) | |
1939 .FromJust()); | |
1805 } | 1940 } |
1806 | 1941 |
1807 | 1942 |
1808 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { | 1943 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { |
1809 ApiTestFuzzer::Fuzz(); | 1944 ApiTestFuzzer::Fuzz(); |
1810 args.GetReturnValue().Set(v8_num(17.2)); | 1945 args.GetReturnValue().Set(v8_num(17.2)); |
1811 } | 1946 } |
1812 | 1947 |
1813 | 1948 |
1814 static void GetKnurd(Local<String> property, | 1949 static void GetKnurd(Local<String> property, |
1815 const v8::PropertyCallbackInfo<v8::Value>& info) { | 1950 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1816 ApiTestFuzzer::Fuzz(); | 1951 ApiTestFuzzer::Fuzz(); |
1817 info.GetReturnValue().Set(v8_num(15.2)); | 1952 info.GetReturnValue().Set(v8_num(15.2)); |
1818 } | 1953 } |
1819 | 1954 |
1820 | 1955 |
1821 THREADED_TEST(DescriptorInheritance) { | 1956 THREADED_TEST(DescriptorInheritance) { |
1822 v8::Isolate* isolate = CcTest::isolate(); | 1957 v8::Isolate* isolate = CcTest::isolate(); |
1823 v8::HandleScope scope(isolate); | 1958 v8::HandleScope scope(isolate); |
1824 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate); | 1959 v8::Local<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate); |
1825 super->PrototypeTemplate()->Set(isolate, "flabby", | 1960 super->PrototypeTemplate()->Set(isolate, "flabby", |
1826 v8::FunctionTemplate::New(isolate, | 1961 v8::FunctionTemplate::New(isolate, |
1827 GetFlabby)); | 1962 GetFlabby)); |
1828 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14)); | 1963 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14)); |
1829 | 1964 |
1830 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); | 1965 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); |
1831 | 1966 |
1832 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate); | 1967 v8::Local<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate); |
1833 base1->Inherit(super); | 1968 base1->Inherit(super); |
1834 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1)); | 1969 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1)); |
1835 | 1970 |
1836 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate); | 1971 v8::Local<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate); |
1837 base2->Inherit(super); | 1972 base2->Inherit(super); |
1838 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1)); | 1973 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1)); |
1839 | 1974 |
1840 LocalContext env; | 1975 LocalContext env; |
1841 | 1976 |
1842 env->Global()->Set(v8_str("s"), super->GetFunction()); | 1977 CHECK(env->Global() |
1843 env->Global()->Set(v8_str("base1"), base1->GetFunction()); | 1978 ->Set(env.local(), v8_str("s"), |
1844 env->Global()->Set(v8_str("base2"), base2->GetFunction()); | 1979 super->GetFunction(env.local()).ToLocalChecked()) |
1980 .FromJust()); | |
1981 CHECK(env->Global() | |
1982 ->Set(env.local(), v8_str("base1"), | |
1983 base1->GetFunction(env.local()).ToLocalChecked()) | |
1984 .FromJust()); | |
1985 CHECK(env->Global() | |
1986 ->Set(env.local(), v8_str("base2"), | |
1987 base2->GetFunction(env.local()).ToLocalChecked()) | |
1988 .FromJust()); | |
1845 | 1989 |
1846 // Checks right __proto__ chain. | 1990 // Checks right __proto__ chain. |
1847 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); | 1991 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype") |
1848 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); | 1992 ->BooleanValue(env.local()) |
1993 .FromJust()); | |
1994 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype") | |
1995 ->BooleanValue(env.local()) | |
1996 .FromJust()); | |
1849 | 1997 |
1850 CHECK(v8_compile("s.prototype.PI == 3.14")->Run()->BooleanValue()); | 1998 CHECK(v8_compile("s.prototype.PI == 3.14") |
1999 ->Run(env.local()) | |
2000 .ToLocalChecked() | |
2001 ->BooleanValue(env.local()) | |
2002 .FromJust()); | |
1851 | 2003 |
1852 // Instance accessor should not be visible on function object or its prototype | 2004 // Instance accessor should not be visible on function object or its prototype |
1853 CHECK(CompileRun("s.knurd == undefined")->BooleanValue()); | 2005 CHECK( |
1854 CHECK(CompileRun("s.prototype.knurd == undefined")->BooleanValue()); | 2006 CompileRun("s.knurd == undefined")->BooleanValue(env.local()).FromJust()); |
1855 CHECK(CompileRun("base1.prototype.knurd == undefined")->BooleanValue()); | 2007 CHECK(CompileRun("s.prototype.knurd == undefined") |
2008 ->BooleanValue(env.local()) | |
2009 .FromJust()); | |
2010 CHECK(CompileRun("base1.prototype.knurd == undefined") | |
2011 ->BooleanValue(env.local()) | |
2012 .FromJust()); | |
1856 | 2013 |
1857 env->Global()->Set(v8_str("obj"), | 2014 CHECK(env->Global() |
1858 base1->GetFunction()->NewInstance()); | 2015 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local()) |
1859 CHECK_EQ(17.2, v8_compile("obj.flabby()")->Run()->NumberValue()); | 2016 .ToLocalChecked() |
1860 CHECK(v8_compile("'flabby' in obj")->Run()->BooleanValue()); | 2017 ->NewInstance(env.local()) |
1861 CHECK_EQ(15.2, v8_compile("obj.knurd")->Run()->NumberValue()); | 2018 .ToLocalChecked()) |
1862 CHECK(v8_compile("'knurd' in obj")->Run()->BooleanValue()); | 2019 .FromJust()); |
1863 CHECK_EQ(20.1, v8_compile("obj.v1")->Run()->NumberValue()); | 2020 CHECK_EQ(17.2, v8_compile("obj.flabby()") |
2021 ->Run(env.local()) | |
2022 .ToLocalChecked() | |
2023 ->NumberValue(env.local()) | |
2024 .FromJust()); | |
2025 CHECK(v8_compile("'flabby' in obj") | |
2026 ->Run(env.local()) | |
2027 .ToLocalChecked() | |
2028 ->BooleanValue(env.local()) | |
2029 .FromJust()); | |
2030 CHECK_EQ(15.2, v8_compile("obj.knurd") | |
2031 ->Run(env.local()) | |
2032 .ToLocalChecked() | |
2033 ->NumberValue(env.local()) | |
2034 .FromJust()); | |
2035 CHECK(v8_compile("'knurd' in obj") | |
2036 ->Run(env.local()) | |
2037 .ToLocalChecked() | |
2038 ->BooleanValue(env.local()) | |
2039 .FromJust()); | |
2040 CHECK_EQ(20.1, v8_compile("obj.v1") | |
2041 ->Run(env.local()) | |
2042 .ToLocalChecked() | |
2043 ->NumberValue(env.local()) | |
2044 .FromJust()); | |
1864 | 2045 |
1865 env->Global()->Set(v8_str("obj2"), | 2046 CHECK(env->Global() |
1866 base2->GetFunction()->NewInstance()); | 2047 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local()) |
1867 CHECK_EQ(17.2, v8_compile("obj2.flabby()")->Run()->NumberValue()); | 2048 .ToLocalChecked() |
1868 CHECK(v8_compile("'flabby' in obj2")->Run()->BooleanValue()); | 2049 ->NewInstance(env.local()) |
1869 CHECK_EQ(15.2, v8_compile("obj2.knurd")->Run()->NumberValue()); | 2050 .ToLocalChecked()) |
1870 CHECK(v8_compile("'knurd' in obj2")->Run()->BooleanValue()); | 2051 .FromJust()); |
1871 CHECK_EQ(10.1, v8_compile("obj2.v2")->Run()->NumberValue()); | 2052 CHECK_EQ(17.2, v8_compile("obj2.flabby()") |
2053 ->Run(env.local()) | |
2054 .ToLocalChecked() | |
2055 ->NumberValue(env.local()) | |
2056 .FromJust()); | |
2057 CHECK(v8_compile("'flabby' in obj2") | |
2058 ->Run(env.local()) | |
2059 .ToLocalChecked() | |
2060 ->BooleanValue(env.local()) | |
2061 .FromJust()); | |
2062 CHECK_EQ(15.2, v8_compile("obj2.knurd") | |
2063 ->Run(env.local()) | |
2064 .ToLocalChecked() | |
2065 ->NumberValue(env.local()) | |
2066 .FromJust()); | |
2067 CHECK(v8_compile("'knurd' in obj2") | |
2068 ->Run(env.local()) | |
2069 .ToLocalChecked() | |
2070 ->BooleanValue(env.local()) | |
2071 .FromJust()); | |
2072 CHECK_EQ(10.1, v8_compile("obj2.v2") | |
2073 ->Run(env.local()) | |
2074 .ToLocalChecked() | |
2075 ->NumberValue(env.local()) | |
2076 .FromJust()); | |
1872 | 2077 |
1873 // base1 and base2 cannot cross reference to each's prototype | 2078 // base1 and base2 cannot cross reference to each's prototype |
1874 CHECK(v8_compile("obj.v2")->Run()->IsUndefined()); | 2079 CHECK(v8_compile("obj.v2")->Run(env.local()).ToLocalChecked()->IsUndefined()); |
1875 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined()); | 2080 CHECK( |
2081 v8_compile("obj2.v1")->Run(env.local()).ToLocalChecked()->IsUndefined()); | |
1876 } | 2082 } |
1877 | 2083 |
1878 | 2084 |
1879 // Helper functions for Interceptor/Accessor interaction tests | 2085 // Helper functions for Interceptor/Accessor interaction tests |
1880 | 2086 |
1881 void SimpleAccessorGetter(Local<String> name, | 2087 void SimpleAccessorGetter(Local<String> name, |
1882 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2088 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1883 Handle<Object> self = Handle<Object>::Cast(info.This()); | 2089 Local<Object> self = Local<Object>::Cast(info.This()); |
1884 info.GetReturnValue().Set( | 2090 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(), |
1885 self->Get(String::Concat(v8_str("accessor_"), name))); | 2091 String::Concat(v8_str("accessor_"), name)) |
2092 .ToLocalChecked()); | |
1886 } | 2093 } |
1887 | 2094 |
1888 void SimpleAccessorSetter(Local<String> name, Local<Value> value, | 2095 void SimpleAccessorSetter(Local<String> name, Local<Value> value, |
1889 const v8::PropertyCallbackInfo<void>& info) { | 2096 const v8::PropertyCallbackInfo<void>& info) { |
1890 Handle<Object> self = Handle<Object>::Cast(info.This()); | 2097 Local<Object> self = Local<Object>::Cast(info.This()); |
1891 self->Set(String::Concat(v8_str("accessor_"), name), value); | 2098 CHECK(self->Set(info.GetIsolate()->GetCurrentContext(), |
2099 String::Concat(v8_str("accessor_"), name), value) | |
2100 .FromJust()); | |
1892 } | 2101 } |
1893 | 2102 |
1894 void SymbolAccessorGetter(Local<Name> name, | 2103 void SymbolAccessorGetter(Local<Name> name, |
1895 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2104 const v8::PropertyCallbackInfo<v8::Value>& info) { |
1896 CHECK(name->IsSymbol()); | 2105 CHECK(name->IsSymbol()); |
1897 Local<Symbol> sym = Local<Symbol>::Cast(name); | 2106 Local<Symbol> sym = Local<Symbol>::Cast(name); |
1898 if (sym->Name()->IsUndefined()) | 2107 if (sym->Name()->IsUndefined()) |
1899 return; | 2108 return; |
1900 SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info); | 2109 SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info); |
1901 } | 2110 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1937 i::Handle<i::String> name(v8::Utils::OpenHandle(*v8_str("length"))); | 2146 i::Handle<i::String> name(v8::Utils::OpenHandle(*v8_str("length"))); |
1938 i::LookupIterator it(a, name, i::LookupIterator::OWN_SKIP_INTERCEPTOR); | 2147 i::LookupIterator it(a, name, i::LookupIterator::OWN_SKIP_INTERCEPTOR); |
1939 CHECK_EQ(i::LookupIterator::ACCESSOR, it.state()); | 2148 CHECK_EQ(i::LookupIterator::ACCESSOR, it.state()); |
1940 CHECK(it.GetAccessors()->IsExecutableAccessorInfo()); | 2149 CHECK(it.GetAccessors()->IsExecutableAccessorInfo()); |
1941 } | 2150 } |
1942 | 2151 |
1943 | 2152 |
1944 THREADED_TEST(UndefinedIsNotEnumerable) { | 2153 THREADED_TEST(UndefinedIsNotEnumerable) { |
1945 LocalContext env; | 2154 LocalContext env; |
1946 v8::HandleScope scope(env->GetIsolate()); | 2155 v8::HandleScope scope(env->GetIsolate()); |
1947 v8::Handle<Value> result = CompileRun("this.propertyIsEnumerable(undefined)"); | 2156 v8::Local<Value> result = CompileRun("this.propertyIsEnumerable(undefined)"); |
1948 CHECK(result->IsFalse()); | 2157 CHECK(result->IsFalse()); |
1949 } | 2158 } |
1950 | 2159 |
1951 | 2160 |
1952 v8::Handle<Script> call_recursively_script; | 2161 v8::Local<Script> call_recursively_script; |
1953 static const int kTargetRecursionDepth = 150; // near maximum | 2162 static const int kTargetRecursionDepth = 150; // near maximum |
1954 | 2163 |
1955 | 2164 |
1956 static void CallScriptRecursivelyCall( | 2165 static void CallScriptRecursivelyCall( |
1957 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2166 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1958 ApiTestFuzzer::Fuzz(); | 2167 ApiTestFuzzer::Fuzz(); |
1959 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); | 2168 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
2169 int depth = args.This() | |
2170 ->Get(context, v8_str("depth")) | |
2171 .ToLocalChecked() | |
2172 ->Int32Value(context) | |
2173 .FromJust(); | |
1960 if (depth == kTargetRecursionDepth) return; | 2174 if (depth == kTargetRecursionDepth) return; |
1961 args.This()->Set(v8_str("depth"), | 2175 CHECK(args.This() |
1962 v8::Integer::New(args.GetIsolate(), depth + 1)); | 2176 ->Set(context, v8_str("depth"), |
1963 args.GetReturnValue().Set(call_recursively_script->Run()); | 2177 v8::Integer::New(args.GetIsolate(), depth + 1)) |
2178 .FromJust()); | |
2179 args.GetReturnValue().Set( | |
2180 call_recursively_script->Run(context).ToLocalChecked()); | |
1964 } | 2181 } |
1965 | 2182 |
1966 | 2183 |
1967 static void CallFunctionRecursivelyCall( | 2184 static void CallFunctionRecursivelyCall( |
1968 const v8::FunctionCallbackInfo<v8::Value>& args) { | 2185 const v8::FunctionCallbackInfo<v8::Value>& args) { |
1969 ApiTestFuzzer::Fuzz(); | 2186 ApiTestFuzzer::Fuzz(); |
1970 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); | 2187 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
2188 int depth = args.This() | |
2189 ->Get(context, v8_str("depth")) | |
2190 .ToLocalChecked() | |
2191 ->Int32Value(context) | |
2192 .FromJust(); | |
1971 if (depth == kTargetRecursionDepth) { | 2193 if (depth == kTargetRecursionDepth) { |
1972 printf("[depth = %d]\n", depth); | 2194 printf("[depth = %d]\n", depth); |
1973 return; | 2195 return; |
1974 } | 2196 } |
1975 args.This()->Set(v8_str("depth"), | 2197 CHECK(args.This() |
1976 v8::Integer::New(args.GetIsolate(), depth + 1)); | 2198 ->Set(context, v8_str("depth"), |
1977 v8::Handle<Value> function = | 2199 v8::Integer::New(args.GetIsolate(), depth + 1)) |
1978 args.This()->Get(v8_str("callFunctionRecursively")); | 2200 .FromJust()); |
1979 args.GetReturnValue().Set( | 2201 v8::Local<Value> function = |
1980 function.As<Function>()->Call(args.This(), 0, NULL)); | 2202 args.This() |
2203 ->Get(context, v8_str("callFunctionRecursively")) | |
2204 .ToLocalChecked(); | |
2205 args.GetReturnValue().Set(function.As<Function>() | |
2206 ->Call(context, args.This(), 0, NULL) | |
2207 .ToLocalChecked()); | |
1981 } | 2208 } |
1982 | 2209 |
1983 | 2210 |
1984 THREADED_TEST(DeepCrossLanguageRecursion) { | 2211 THREADED_TEST(DeepCrossLanguageRecursion) { |
1985 v8::Isolate* isolate = CcTest::isolate(); | 2212 v8::Isolate* isolate = CcTest::isolate(); |
1986 v8::HandleScope scope(isolate); | 2213 v8::HandleScope scope(isolate); |
1987 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); | 2214 v8::Local<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
1988 global->Set(v8_str("callScriptRecursively"), | 2215 global->Set(v8_str("callScriptRecursively"), |
1989 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); | 2216 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); |
1990 global->Set(v8_str("callFunctionRecursively"), | 2217 global->Set(v8_str("callFunctionRecursively"), |
1991 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); | 2218 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); |
1992 LocalContext env(NULL, global); | 2219 LocalContext env(NULL, global); |
1993 | 2220 |
1994 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2221 CHECK(env->Global() |
2222 ->Set(env.local(), v8_str("depth"), v8::Integer::New(isolate, 0)) | |
2223 .FromJust()); | |
1995 call_recursively_script = v8_compile("callScriptRecursively()"); | 2224 call_recursively_script = v8_compile("callScriptRecursively()"); |
1996 call_recursively_script->Run(); | 2225 call_recursively_script->Run(env.local()).ToLocalChecked(); |
1997 call_recursively_script = v8::Handle<Script>(); | 2226 call_recursively_script = v8::Local<Script>(); |
1998 | 2227 |
1999 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); | 2228 CHECK(env->Global() |
2229 ->Set(env.local(), v8_str("depth"), v8::Integer::New(isolate, 0)) | |
2230 .FromJust()); | |
2000 CompileRun("callFunctionRecursively()"); | 2231 CompileRun("callFunctionRecursively()"); |
2001 } | 2232 } |
2002 | 2233 |
2003 | 2234 |
2004 static void ThrowingPropertyHandlerGet( | 2235 static void ThrowingPropertyHandlerGet( |
2005 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { | 2236 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { |
2006 // Since this interceptor is used on "with" objects, the runtime will look up | 2237 // Since this interceptor is used on "with" objects, the runtime will look up |
2007 // @@unscopables. Punt. | 2238 // @@unscopables. Punt. |
2008 if (key->IsSymbol()) return; | 2239 if (key->IsSymbol()) return; |
2009 ApiTestFuzzer::Fuzz(); | 2240 ApiTestFuzzer::Fuzz(); |
2010 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); | 2241 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); |
2011 } | 2242 } |
2012 | 2243 |
2013 | 2244 |
2014 static void ThrowingPropertyHandlerSet( | 2245 static void ThrowingPropertyHandlerSet( |
2015 Local<Name> key, Local<Value>, | 2246 Local<Name> key, Local<Value>, |
2016 const v8::PropertyCallbackInfo<v8::Value>& info) { | 2247 const v8::PropertyCallbackInfo<v8::Value>& info) { |
2017 info.GetIsolate()->ThrowException(key); | 2248 info.GetIsolate()->ThrowException(key); |
2018 info.GetReturnValue().SetUndefined(); // not the same as empty handle | 2249 info.GetReturnValue().SetUndefined(); // not the same as empty handle |
2019 } | 2250 } |
2020 | 2251 |
2021 | 2252 |
2022 THREADED_TEST(CallbackExceptionRegression) { | 2253 THREADED_TEST(CallbackExceptionRegression) { |
2023 v8::Isolate* isolate = CcTest::isolate(); | 2254 v8::Isolate* isolate = CcTest::isolate(); |
2024 v8::HandleScope scope(isolate); | 2255 v8::HandleScope scope(isolate); |
2025 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 2256 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
2026 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( | 2257 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( |
2027 ThrowingPropertyHandlerGet, ThrowingPropertyHandlerSet)); | 2258 ThrowingPropertyHandlerGet, ThrowingPropertyHandlerSet)); |
2028 LocalContext env; | 2259 LocalContext env; |
2029 env->Global()->Set(v8_str("obj"), obj->NewInstance()); | 2260 CHECK(env->Global() |
2030 v8::Handle<Value> otto = | 2261 ->Set(env.local(), v8_str("obj"), |
2262 obj->NewInstance(env.local()).ToLocalChecked()) | |
2263 .FromJust()); | |
2264 v8::Local<Value> otto = | |
2031 CompileRun("try { with (obj) { otto; } } catch (e) { e; }"); | 2265 CompileRun("try { with (obj) { otto; } } catch (e) { e; }"); |
2032 CHECK(v8_str("otto")->Equals(otto)); | 2266 CHECK(v8_str("otto")->Equals(env.local(), otto).FromJust()); |
2033 v8::Handle<Value> netto = | 2267 v8::Local<Value> netto = |
2034 CompileRun("try { with (obj) { netto = 4; } } catch (e) { e; }"); | 2268 CompileRun("try { with (obj) { netto = 4; } } catch (e) { e; }"); |
2035 CHECK(v8_str("netto")->Equals(netto)); | 2269 CHECK(v8_str("netto")->Equals(env.local(), netto).FromJust()); |
2036 } | 2270 } |
2037 | 2271 |
2038 | 2272 |
2039 THREADED_TEST(FunctionPrototype) { | 2273 THREADED_TEST(FunctionPrototype) { |
2040 v8::Isolate* isolate = CcTest::isolate(); | 2274 v8::Isolate* isolate = CcTest::isolate(); |
2041 v8::HandleScope scope(isolate); | 2275 v8::HandleScope scope(isolate); |
2042 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); | 2276 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); |
2043 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); | 2277 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); |
2044 LocalContext env; | 2278 LocalContext env; |
2045 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); | 2279 CHECK(env->Global() |
2280 ->Set(env.local(), v8_str("Foo"), | |
2281 Foo->GetFunction(env.local()).ToLocalChecked()) | |
2282 .FromJust()); | |
2046 Local<Script> script = v8_compile("Foo.prototype.plak"); | 2283 Local<Script> script = v8_compile("Foo.prototype.plak"); |
2047 CHECK_EQ(script->Run()->Int32Value(), 321); | 2284 CHECK_EQ(v8_run_int32value(script), 321); |
2048 } | 2285 } |
2049 | 2286 |
2050 | 2287 |
2051 THREADED_TEST(InternalFields) { | 2288 THREADED_TEST(InternalFields) { |
2052 LocalContext env; | 2289 LocalContext env; |
2053 v8::Isolate* isolate = env->GetIsolate(); | 2290 v8::Isolate* isolate = env->GetIsolate(); |
2054 v8::HandleScope scope(isolate); | 2291 v8::HandleScope scope(isolate); |
2055 | 2292 |
2056 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 2293 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
2057 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 2294 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
2058 instance_templ->SetInternalFieldCount(1); | 2295 instance_templ->SetInternalFieldCount(1); |
2059 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 2296 Local<v8::Object> obj = templ->GetFunction(env.local()) |
2297 .ToLocalChecked() | |
2298 ->NewInstance(env.local()) | |
2299 .ToLocalChecked(); | |
2060 CHECK_EQ(1, obj->InternalFieldCount()); | 2300 CHECK_EQ(1, obj->InternalFieldCount()); |
2061 CHECK(obj->GetInternalField(0)->IsUndefined()); | 2301 CHECK(obj->GetInternalField(0)->IsUndefined()); |
2062 obj->SetInternalField(0, v8_num(17)); | 2302 obj->SetInternalField(0, v8_num(17)); |
2063 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); | 2303 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value(env.local()).FromJust()); |
2064 } | 2304 } |
2065 | 2305 |
2066 | 2306 |
2067 THREADED_TEST(GlobalObjectInternalFields) { | 2307 THREADED_TEST(GlobalObjectInternalFields) { |
2068 v8::Isolate* isolate = CcTest::isolate(); | 2308 v8::Isolate* isolate = CcTest::isolate(); |
2069 v8::HandleScope scope(isolate); | 2309 v8::HandleScope scope(isolate); |
2070 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); | 2310 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); |
2071 global_template->SetInternalFieldCount(1); | 2311 global_template->SetInternalFieldCount(1); |
2072 LocalContext env(NULL, global_template); | 2312 LocalContext env(NULL, global_template); |
2073 v8::Handle<v8::Object> global_proxy = env->Global(); | 2313 v8::Local<v8::Object> global_proxy = env->Global(); |
2074 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); | 2314 v8::Local<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); |
2075 CHECK_EQ(1, global->InternalFieldCount()); | 2315 CHECK_EQ(1, global->InternalFieldCount()); |
2076 CHECK(global->GetInternalField(0)->IsUndefined()); | 2316 CHECK(global->GetInternalField(0)->IsUndefined()); |
2077 global->SetInternalField(0, v8_num(17)); | 2317 global->SetInternalField(0, v8_num(17)); |
2078 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); | 2318 CHECK_EQ(17, global->GetInternalField(0)->Int32Value(env.local()).FromJust()); |
2079 } | 2319 } |
2080 | 2320 |
2081 | 2321 |
2082 THREADED_TEST(GlobalObjectHasRealIndexedProperty) { | 2322 THREADED_TEST(GlobalObjectHasRealIndexedProperty) { |
2083 LocalContext env; | 2323 LocalContext env; |
2084 v8::HandleScope scope(CcTest::isolate()); | 2324 v8::HandleScope scope(CcTest::isolate()); |
2085 | 2325 |
2086 v8::Local<v8::Object> global = env->Global(); | 2326 v8::Local<v8::Object> global = env->Global(); |
2087 global->Set(0, v8::String::NewFromUtf8(CcTest::isolate(), "value")); | 2327 CHECK(global->Set(env.local(), 0, v8_str("value")).FromJust()); |
2088 CHECK(global->HasRealIndexedProperty(0)); | 2328 CHECK(global->HasRealIndexedProperty(env.local(), 0).FromJust()); |
2089 } | 2329 } |
2090 | 2330 |
2091 | 2331 |
2092 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, | 2332 static void CheckAlignedPointerInInternalField(Local<v8::Object> obj, |
2093 void* value) { | 2333 void* value) { |
2094 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); | 2334 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); |
2095 obj->SetAlignedPointerInInternalField(0, value); | 2335 obj->SetAlignedPointerInInternalField(0, value); |
2096 CcTest::heap()->CollectAllGarbage(); | 2336 CcTest::heap()->CollectAllGarbage(); |
2097 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); | 2337 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); |
2098 } | 2338 } |
2099 | 2339 |
2100 | 2340 |
2101 THREADED_TEST(InternalFieldsAlignedPointers) { | 2341 THREADED_TEST(InternalFieldsAlignedPointers) { |
2102 LocalContext env; | 2342 LocalContext env; |
2103 v8::Isolate* isolate = env->GetIsolate(); | 2343 v8::Isolate* isolate = env->GetIsolate(); |
2104 v8::HandleScope scope(isolate); | 2344 v8::HandleScope scope(isolate); |
2105 | 2345 |
2106 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 2346 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
2107 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 2347 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
2108 instance_templ->SetInternalFieldCount(1); | 2348 instance_templ->SetInternalFieldCount(1); |
2109 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 2349 Local<v8::Object> obj = templ->GetFunction(env.local()) |
2350 .ToLocalChecked() | |
2351 ->NewInstance(env.local()) | |
2352 .ToLocalChecked(); | |
2110 CHECK_EQ(1, obj->InternalFieldCount()); | 2353 CHECK_EQ(1, obj->InternalFieldCount()); |
2111 | 2354 |
2112 CheckAlignedPointerInInternalField(obj, NULL); | 2355 CheckAlignedPointerInInternalField(obj, NULL); |
2113 | 2356 |
2114 int* heap_allocated = new int[100]; | 2357 int* heap_allocated = new int[100]; |
2115 CheckAlignedPointerInInternalField(obj, heap_allocated); | 2358 CheckAlignedPointerInInternalField(obj, heap_allocated); |
2116 delete[] heap_allocated; | 2359 delete[] heap_allocated; |
2117 | 2360 |
2118 int stack_allocated[100]; | 2361 int stack_allocated[100]; |
2119 CheckAlignedPointerInInternalField(obj, stack_allocated); | 2362 CheckAlignedPointerInInternalField(obj, stack_allocated); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2162 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); | 2405 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); |
2163 } | 2406 } |
2164 CcTest::heap()->CollectAllGarbage(); | 2407 CcTest::heap()->CollectAllGarbage(); |
2165 for (int i = 0; i < 100; i++) { | 2408 for (int i = 0; i < 100; i++) { |
2166 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); | 2409 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); |
2167 } | 2410 } |
2168 } | 2411 } |
2169 | 2412 |
2170 | 2413 |
2171 static void CheckEmbedderData(LocalContext* env, int index, | 2414 static void CheckEmbedderData(LocalContext* env, int index, |
2172 v8::Handle<Value> data) { | 2415 v8::Local<Value> data) { |
2173 (*env)->SetEmbedderData(index, data); | 2416 (*env)->SetEmbedderData(index, data); |
2174 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); | 2417 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); |
2175 } | 2418 } |
2176 | 2419 |
2177 | 2420 |
2178 THREADED_TEST(EmbedderData) { | 2421 THREADED_TEST(EmbedderData) { |
2179 LocalContext env; | 2422 LocalContext env; |
2180 v8::Isolate* isolate = env->GetIsolate(); | 2423 v8::Isolate* isolate = env->GetIsolate(); |
2181 v8::HandleScope scope(isolate); | 2424 v8::HandleScope scope(isolate); |
2182 | 2425 |
2183 CheckEmbedderData( | 2426 CheckEmbedderData(&env, 3, v8_str("The quick brown fox jumps")); |
2184 &env, 3, v8::String::NewFromUtf8(isolate, "The quick brown fox jumps")); | 2427 CheckEmbedderData(&env, 2, v8_str("over the lazy dog.")); |
2185 CheckEmbedderData(&env, 2, | |
2186 v8::String::NewFromUtf8(isolate, "over the lazy dog.")); | |
2187 CheckEmbedderData(&env, 1, v8::Number::New(isolate, 1.2345)); | 2428 CheckEmbedderData(&env, 1, v8::Number::New(isolate, 1.2345)); |
2188 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true)); | 2429 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true)); |
2189 } | 2430 } |
2190 | 2431 |
2191 | 2432 |
2433 // TODO(vogelheim): Does this test even make sense in a post-deprecation world? | |
2434 /* | |
2192 THREADED_TEST(GetIsolate) { | 2435 THREADED_TEST(GetIsolate) { |
2193 LocalContext env; | 2436 LocalContext env; |
2194 v8::Isolate* isolate = env->GetIsolate(); | 2437 v8::Isolate* isolate = env->GetIsolate(); |
2195 v8::HandleScope scope(isolate); | 2438 v8::HandleScope scope(isolate); |
2196 Local<v8::Object> obj = v8::Object::New(isolate); | 2439 Local<v8::Object> obj = v8::Object::New(isolate); |
2197 CHECK_EQ(isolate, obj->GetIsolate()); | 2440 CHECK_EQ(isolate, obj->GetIsolate()); |
2198 CHECK_EQ(isolate, CcTest::global()->GetIsolate()); | 2441 CHECK_EQ(isolate, CcTest::global()->GetIsolate()); |
2199 } | 2442 } |
2443 */ | |
2200 | 2444 |
2201 | 2445 |
2202 THREADED_TEST(IdentityHash) { | 2446 THREADED_TEST(IdentityHash) { |
2203 LocalContext env; | 2447 LocalContext env; |
2204 v8::Isolate* isolate = env->GetIsolate(); | 2448 v8::Isolate* isolate = env->GetIsolate(); |
2205 v8::HandleScope scope(isolate); | 2449 v8::HandleScope scope(isolate); |
2206 | 2450 |
2207 // Ensure that the test starts with an fresh heap to test whether the hash | 2451 // Ensure that the test starts with an fresh heap to test whether the hash |
2208 // code is based on the address. | 2452 // code is based on the address. |
2209 CcTest::heap()->CollectAllGarbage(); | 2453 CcTest::heap()->CollectAllGarbage(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2242 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); | 2486 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); |
2243 } | 2487 } |
2244 } | 2488 } |
2245 | 2489 |
2246 | 2490 |
2247 void GlobalProxyIdentityHash(bool set_in_js) { | 2491 void GlobalProxyIdentityHash(bool set_in_js) { |
2248 LocalContext env; | 2492 LocalContext env; |
2249 v8::Isolate* isolate = env->GetIsolate(); | 2493 v8::Isolate* isolate = env->GetIsolate(); |
2250 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 2494 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
2251 v8::HandleScope scope(isolate); | 2495 v8::HandleScope scope(isolate); |
2252 Handle<Object> global_proxy = env->Global(); | 2496 Local<Object> global_proxy = env->Global(); |
2253 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy); | 2497 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy); |
2254 env->Global()->Set(v8_str("global"), global_proxy); | 2498 CHECK(env->Global() |
2499 ->Set(env.local(), v8_str("global"), global_proxy) | |
2500 .FromJust()); | |
2255 i::Handle<i::Object> original_hash; | 2501 i::Handle<i::Object> original_hash; |
2256 if (set_in_js) { | 2502 if (set_in_js) { |
2257 CompileRun("var m = new Set(); m.add(global);"); | 2503 CompileRun("var m = new Set(); m.add(global);"); |
2258 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate); | 2504 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate); |
2259 } else { | 2505 } else { |
2260 original_hash = i::Handle<i::Object>( | 2506 original_hash = i::Handle<i::Object>( |
2261 i::Object::GetOrCreateHash(i_isolate, i_global_proxy)); | 2507 i::Object::GetOrCreateHash(i_isolate, i_global_proxy)); |
2262 } | 2508 } |
2263 CHECK(original_hash->IsSmi()); | 2509 CHECK(original_hash->IsSmi()); |
2264 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value(); | 2510 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value(); |
2265 // Hash should be retained after being detached. | 2511 // Hash should be retained after being detached. |
2266 env->DetachGlobal(); | 2512 env->DetachGlobal(); |
2267 int hash2 = global_proxy->GetIdentityHash(); | 2513 int hash2 = global_proxy->GetIdentityHash(); |
2268 CHECK_EQ(hash1, hash2); | 2514 CHECK_EQ(hash1, hash2); |
2269 { | 2515 { |
2270 // Re-attach global proxy to a new context, hash should stay the same. | 2516 // Re-attach global proxy to a new context, hash should stay the same. |
2271 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy); | 2517 LocalContext env2(NULL, Local<ObjectTemplate>(), global_proxy); |
2272 int hash3 = global_proxy->GetIdentityHash(); | 2518 int hash3 = global_proxy->GetIdentityHash(); |
2273 CHECK_EQ(hash1, hash3); | 2519 CHECK_EQ(hash1, hash3); |
2274 } | 2520 } |
2275 } | 2521 } |
2276 | 2522 |
2277 | 2523 |
2278 THREADED_TEST(GlobalProxyIdentityHash) { | 2524 THREADED_TEST(GlobalProxyIdentityHash) { |
2279 GlobalProxyIdentityHash(true); | 2525 GlobalProxyIdentityHash(true); |
2280 GlobalProxyIdentityHash(false); | 2526 GlobalProxyIdentityHash(false); |
2281 } | 2527 } |
2282 | 2528 |
2283 | 2529 |
2284 TEST(SymbolIdentityHash) { | 2530 TEST(SymbolIdentityHash) { |
2285 LocalContext env; | 2531 LocalContext env; |
2286 v8::Isolate* isolate = env->GetIsolate(); | 2532 v8::Isolate* isolate = env->GetIsolate(); |
2287 v8::HandleScope scope(isolate); | 2533 v8::HandleScope scope(isolate); |
2288 | 2534 |
2289 { | 2535 { |
2290 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); | 2536 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); |
2291 int hash = symbol->GetIdentityHash(); | 2537 int hash = symbol->GetIdentityHash(); |
2292 int hash1 = symbol->GetIdentityHash(); | 2538 int hash1 = symbol->GetIdentityHash(); |
2293 CHECK_EQ(hash, hash1); | 2539 CHECK_EQ(hash, hash1); |
2294 CcTest::heap()->CollectAllGarbage(); | 2540 CcTest::heap()->CollectAllGarbage(); |
2295 int hash3 = symbol->GetIdentityHash(); | 2541 int hash3 = symbol->GetIdentityHash(); |
2296 CHECK_EQ(hash, hash3); | 2542 CHECK_EQ(hash, hash3); |
2297 } | 2543 } |
2298 | 2544 |
2299 { | 2545 { |
2300 v8::Handle<v8::Symbol> js_symbol = | 2546 v8::Local<v8::Symbol> js_symbol = |
2301 CompileRun("Symbol('foo')").As<v8::Symbol>(); | 2547 CompileRun("Symbol('foo')").As<v8::Symbol>(); |
2302 int hash = js_symbol->GetIdentityHash(); | 2548 int hash = js_symbol->GetIdentityHash(); |
2303 int hash1 = js_symbol->GetIdentityHash(); | 2549 int hash1 = js_symbol->GetIdentityHash(); |
2304 CHECK_EQ(hash, hash1); | 2550 CHECK_EQ(hash, hash1); |
2305 CcTest::heap()->CollectAllGarbage(); | 2551 CcTest::heap()->CollectAllGarbage(); |
2306 int hash3 = js_symbol->GetIdentityHash(); | 2552 int hash3 = js_symbol->GetIdentityHash(); |
2307 CHECK_EQ(hash, hash3); | 2553 CHECK_EQ(hash, hash3); |
2308 } | 2554 } |
2309 } | 2555 } |
2310 | 2556 |
2311 | 2557 |
2312 TEST(StringIdentityHash) { | 2558 TEST(StringIdentityHash) { |
2313 LocalContext env; | 2559 LocalContext env; |
2314 v8::Isolate* isolate = env->GetIsolate(); | 2560 v8::Isolate* isolate = env->GetIsolate(); |
2315 v8::HandleScope scope(isolate); | 2561 v8::HandleScope scope(isolate); |
2316 | 2562 |
2317 Local<v8::String> str = v8::String::NewFromUtf8(isolate, "str1"); | 2563 Local<v8::String> str = v8_str("str1"); |
2318 int hash = str->GetIdentityHash(); | 2564 int hash = str->GetIdentityHash(); |
2319 int hash1 = str->GetIdentityHash(); | 2565 int hash1 = str->GetIdentityHash(); |
2320 CHECK_EQ(hash, hash1); | 2566 CHECK_EQ(hash, hash1); |
2321 CcTest::heap()->CollectAllGarbage(); | 2567 CcTest::heap()->CollectAllGarbage(); |
2322 int hash3 = str->GetIdentityHash(); | 2568 int hash3 = str->GetIdentityHash(); |
2323 CHECK_EQ(hash, hash3); | 2569 CHECK_EQ(hash, hash3); |
2324 | 2570 |
2325 Local<v8::String> str2 = v8::String::NewFromUtf8(isolate, "str1"); | 2571 Local<v8::String> str2 = v8_str("str1"); |
2326 int hash4 = str2->GetIdentityHash(); | 2572 int hash4 = str2->GetIdentityHash(); |
2327 CHECK_EQ(hash, hash4); | 2573 CHECK_EQ(hash, hash4); |
2328 } | 2574 } |
2329 | 2575 |
2330 | 2576 |
2331 THREADED_TEST(SymbolProperties) { | 2577 THREADED_TEST(SymbolProperties) { |
2332 LocalContext env; | 2578 LocalContext env; |
2333 v8::Isolate* isolate = env->GetIsolate(); | 2579 v8::Isolate* isolate = env->GetIsolate(); |
2334 v8::HandleScope scope(isolate); | 2580 v8::HandleScope scope(isolate); |
2335 | 2581 |
2336 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 2582 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
2337 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); | 2583 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
2338 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, v8_str("my-symbol")); | 2584 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, v8_str("my-symbol")); |
2339 v8::Local<v8::Symbol> sym3 = v8::Symbol::New(isolate, v8_str("sym3")); | 2585 v8::Local<v8::Symbol> sym3 = v8::Symbol::New(isolate, v8_str("sym3")); |
2340 | 2586 |
2341 CcTest::heap()->CollectAllGarbage(); | 2587 CcTest::heap()->CollectAllGarbage(); |
2342 | 2588 |
2343 // Check basic symbol functionality. | 2589 // Check basic symbol functionality. |
2344 CHECK(sym1->IsSymbol()); | 2590 CHECK(sym1->IsSymbol()); |
2345 CHECK(sym2->IsSymbol()); | 2591 CHECK(sym2->IsSymbol()); |
2346 CHECK(!obj->IsSymbol()); | 2592 CHECK(!obj->IsSymbol()); |
2347 | 2593 |
2348 CHECK(sym1->Equals(sym1)); | 2594 CHECK(sym1->Equals(env.local(), sym1).FromJust()); |
2349 CHECK(sym2->Equals(sym2)); | 2595 CHECK(sym2->Equals(env.local(), sym2).FromJust()); |
2350 CHECK(!sym1->Equals(sym2)); | 2596 CHECK(!sym1->Equals(env.local(), sym2).FromJust()); |
2351 CHECK(!sym2->Equals(sym1)); | 2597 CHECK(!sym2->Equals(env.local(), sym1).FromJust()); |
2352 CHECK(sym1->StrictEquals(sym1)); | 2598 CHECK(sym1->StrictEquals(sym1)); |
2353 CHECK(sym2->StrictEquals(sym2)); | 2599 CHECK(sym2->StrictEquals(sym2)); |
2354 CHECK(!sym1->StrictEquals(sym2)); | 2600 CHECK(!sym1->StrictEquals(sym2)); |
2355 CHECK(!sym2->StrictEquals(sym1)); | 2601 CHECK(!sym2->StrictEquals(sym1)); |
2356 | 2602 |
2357 CHECK(sym2->Name()->Equals(v8_str("my-symbol"))); | 2603 CHECK(sym2->Name()->Equals(env.local(), v8_str("my-symbol")).FromJust()); |
2358 | 2604 |
2359 v8::Local<v8::Value> sym_val = sym2; | 2605 v8::Local<v8::Value> sym_val = sym2; |
2360 CHECK(sym_val->IsSymbol()); | 2606 CHECK(sym_val->IsSymbol()); |
2361 CHECK(sym_val->Equals(sym2)); | 2607 CHECK(sym_val->Equals(env.local(), sym2).FromJust()); |
2362 CHECK(sym_val->StrictEquals(sym2)); | 2608 CHECK(sym_val->StrictEquals(sym2)); |
2363 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2)); | 2609 CHECK(v8::Symbol::Cast(*sym_val)->Equals(env.local(), sym2).FromJust()); |
2364 | 2610 |
2365 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2); | 2611 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2); |
2366 CHECK(sym_obj->IsSymbolObject()); | 2612 CHECK(sym_obj->IsSymbolObject()); |
2367 CHECK(!sym2->IsSymbolObject()); | 2613 CHECK(!sym2->IsSymbolObject()); |
2368 CHECK(!obj->IsSymbolObject()); | 2614 CHECK(!obj->IsSymbolObject()); |
2369 CHECK(sym_obj->Equals(sym2)); | 2615 CHECK(sym_obj->Equals(env.local(), sym2).FromJust()); |
2370 CHECK(!sym_obj->StrictEquals(sym2)); | 2616 CHECK(!sym_obj->StrictEquals(sym2)); |
2371 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj)); | 2617 CHECK(v8::SymbolObject::Cast(*sym_obj) |
2372 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2)); | 2618 ->Equals(env.local(), sym_obj) |
2619 .FromJust()); | |
2620 CHECK(v8::SymbolObject::Cast(*sym_obj) | |
2621 ->ValueOf() | |
2622 ->Equals(env.local(), sym2) | |
2623 .FromJust()); | |
2373 | 2624 |
2374 // Make sure delete of a non-existent symbol property works. | 2625 // Make sure delete of a non-existent symbol property works. |
2375 CHECK(obj->Delete(sym1)); | 2626 CHECK(obj->Delete(env.local(), sym1).FromJust()); |
2376 CHECK(!obj->Has(sym1)); | 2627 CHECK(!obj->Has(env.local(), sym1).FromJust()); |
2377 | 2628 |
2378 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 1503))); | 2629 CHECK( |
2379 CHECK(obj->Has(sym1)); | 2630 obj->Set(env.local(), sym1, v8::Integer::New(isolate, 1503)).FromJust()); |
2380 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); | 2631 CHECK(obj->Has(env.local(), sym1).FromJust()); |
2381 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 2002))); | 2632 CHECK_EQ(1503, obj->Get(env.local(), sym1) |
2382 CHECK(obj->Has(sym1)); | 2633 .ToLocalChecked() |
2383 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2634 ->Int32Value(env.local()) |
2384 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); | 2635 .FromJust()); |
2636 CHECK( | |
2637 obj->Set(env.local(), sym1, v8::Integer::New(isolate, 2002)).FromJust()); | |
2638 CHECK(obj->Has(env.local(), sym1).FromJust()); | |
2639 CHECK_EQ(2002, obj->Get(env.local(), sym1) | |
2640 .ToLocalChecked() | |
2641 ->Int32Value(env.local()) | |
2642 .FromJust()); | |
2643 CHECK_EQ(v8::None, obj->GetPropertyAttributes(env.local(), sym1).FromJust()); | |
2385 | 2644 |
2386 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); | 2645 CHECK_EQ(0u, |
2387 unsigned num_props = obj->GetPropertyNames()->Length(); | 2646 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
2388 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), | 2647 unsigned num_props = |
2389 v8::Integer::New(isolate, 20))); | 2648 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length(); |
2390 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2649 CHECK(obj->Set(env.local(), v8_str("bla"), v8::Integer::New(isolate, 20)) |
2391 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); | 2650 .FromJust()); |
2651 CHECK_EQ(1u, | |
2652 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2653 CHECK_EQ(num_props + 1, | |
2654 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2392 | 2655 |
2393 CcTest::heap()->CollectAllGarbage(); | 2656 CcTest::heap()->CollectAllGarbage(); |
2394 | 2657 |
2395 CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter, SymbolAccessorSetter)); | 2658 CHECK(obj->SetAccessor(env.local(), sym3, SymbolAccessorGetter, |
2396 CHECK(obj->Get(sym3)->IsUndefined()); | 2659 SymbolAccessorSetter) |
2397 CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42))); | 2660 .FromJust()); |
2398 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); | 2661 CHECK(obj->Get(env.local(), sym3).ToLocalChecked()->IsUndefined()); |
2399 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) | 2662 CHECK(obj->Set(env.local(), sym3, v8::Integer::New(isolate, 42)).FromJust()); |
2400 ->Equals(v8::Integer::New(isolate, 42))); | 2663 CHECK(obj->Get(env.local(), sym3) |
2664 .ToLocalChecked() | |
2665 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2666 .FromJust()); | |
2667 CHECK(obj->Get(env.local(), v8_str("accessor_sym3")) | |
2668 .ToLocalChecked() | |
2669 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2670 .FromJust()); | |
2401 | 2671 |
2402 // Add another property and delete it afterwards to force the object in | 2672 // Add another property and delete it afterwards to force the object in |
2403 // slow case. | 2673 // slow case. |
2404 CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008))); | 2674 CHECK( |
2405 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2675 obj->Set(env.local(), sym2, v8::Integer::New(isolate, 2008)).FromJust()); |
2406 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); | 2676 CHECK_EQ(2002, obj->Get(env.local(), sym1) |
2407 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2677 .ToLocalChecked() |
2408 CHECK_EQ(2u, obj->GetOwnPropertyNames()->Length()); | 2678 ->Int32Value(env.local()) |
2679 .FromJust()); | |
2680 CHECK_EQ(2008, obj->Get(env.local(), sym2) | |
2681 .ToLocalChecked() | |
2682 ->Int32Value(env.local()) | |
2683 .FromJust()); | |
2684 CHECK_EQ(2002, obj->Get(env.local(), sym1) | |
2685 .ToLocalChecked() | |
2686 ->Int32Value(env.local()) | |
2687 .FromJust()); | |
2688 CHECK_EQ(2u, | |
2689 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2409 | 2690 |
2410 CHECK(obj->Has(sym1)); | 2691 CHECK(obj->Has(env.local(), sym1).FromJust()); |
2411 CHECK(obj->Has(sym2)); | 2692 CHECK(obj->Has(env.local(), sym2).FromJust()); |
2412 CHECK(obj->Has(sym3)); | 2693 CHECK(obj->Has(env.local(), sym3).FromJust()); |
2413 CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); | 2694 CHECK(obj->Has(env.local(), v8_str("accessor_sym3")).FromJust()); |
2414 CHECK(obj->Delete(sym2)); | 2695 CHECK(obj->Delete(env.local(), sym2).FromJust()); |
2415 CHECK(obj->Has(sym1)); | 2696 CHECK(obj->Has(env.local(), sym1).FromJust()); |
2416 CHECK(!obj->Has(sym2)); | 2697 CHECK(!obj->Has(env.local(), sym2).FromJust()); |
2417 CHECK(obj->Has(sym3)); | 2698 CHECK(obj->Has(env.local(), sym3).FromJust()); |
2418 CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); | 2699 CHECK(obj->Has(env.local(), v8_str("accessor_sym3")).FromJust()); |
2419 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); | 2700 CHECK_EQ(2002, obj->Get(env.local(), sym1) |
2420 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); | 2701 .ToLocalChecked() |
2421 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) | 2702 ->Int32Value(env.local()) |
2422 ->Equals(v8::Integer::New(isolate, 42))); | 2703 .FromJust()); |
2423 CHECK_EQ(2u, obj->GetOwnPropertyNames()->Length()); | 2704 CHECK(obj->Get(env.local(), sym3) |
2705 .ToLocalChecked() | |
2706 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2707 .FromJust()); | |
2708 CHECK(obj->Get(env.local(), v8_str("accessor_sym3")) | |
2709 .ToLocalChecked() | |
2710 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2711 .FromJust()); | |
2712 CHECK_EQ(2u, | |
2713 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2424 | 2714 |
2425 // Symbol properties are inherited. | 2715 // Symbol properties are inherited. |
2426 v8::Local<v8::Object> child = v8::Object::New(isolate); | 2716 v8::Local<v8::Object> child = v8::Object::New(isolate); |
2427 child->SetPrototype(obj); | 2717 CHECK(child->SetPrototype(env.local(), obj).FromJust()); |
2428 CHECK(child->Has(sym1)); | 2718 CHECK(child->Has(env.local(), sym1).FromJust()); |
2429 CHECK_EQ(2002, child->Get(sym1)->Int32Value()); | 2719 CHECK_EQ(2002, child->Get(env.local(), sym1) |
2430 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); | 2720 .ToLocalChecked() |
2431 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) | 2721 ->Int32Value(env.local()) |
2432 ->Equals(v8::Integer::New(isolate, 42))); | 2722 .FromJust()); |
2433 CHECK_EQ(0u, child->GetOwnPropertyNames()->Length()); | 2723 CHECK(obj->Get(env.local(), sym3) |
2724 .ToLocalChecked() | |
2725 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2726 .FromJust()); | |
2727 CHECK(obj->Get(env.local(), v8_str("accessor_sym3")) | |
2728 .ToLocalChecked() | |
2729 ->Equals(env.local(), v8::Integer::New(isolate, 42)) | |
2730 .FromJust()); | |
2731 CHECK_EQ(0u, | |
2732 child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2434 } | 2733 } |
2435 | 2734 |
2436 | 2735 |
2437 THREADED_TEST(SymbolTemplateProperties) { | 2736 THREADED_TEST(SymbolTemplateProperties) { |
2438 LocalContext env; | 2737 LocalContext env; |
2439 v8::Isolate* isolate = env->GetIsolate(); | 2738 v8::Isolate* isolate = env->GetIsolate(); |
2440 v8::HandleScope scope(isolate); | 2739 v8::HandleScope scope(isolate); |
2441 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate); | 2740 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate); |
2442 v8::Local<v8::Name> name = v8::Symbol::New(isolate); | 2741 v8::Local<v8::Name> name = v8::Symbol::New(isolate); |
2443 CHECK(!name.IsEmpty()); | 2742 CHECK(!name.IsEmpty()); |
2444 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate)); | 2743 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate)); |
2445 v8::Local<v8::Object> new_instance = foo->InstanceTemplate()->NewInstance(); | 2744 v8::Local<v8::Object> new_instance = |
2745 foo->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked(); | |
2446 CHECK(!new_instance.IsEmpty()); | 2746 CHECK(!new_instance.IsEmpty()); |
2447 CHECK(new_instance->Has(name)); | 2747 CHECK(new_instance->Has(env.local(), name).FromJust()); |
2448 } | 2748 } |
2449 | 2749 |
2450 | 2750 |
2451 THREADED_TEST(PrivateProperties) { | 2751 THREADED_TEST(PrivateProperties) { |
2452 LocalContext env; | 2752 LocalContext env; |
2453 v8::Isolate* isolate = env->GetIsolate(); | 2753 v8::Isolate* isolate = env->GetIsolate(); |
2454 v8::HandleScope scope(isolate); | 2754 v8::HandleScope scope(isolate); |
2455 | 2755 |
2456 v8::Local<v8::Object> obj = v8::Object::New(isolate); | 2756 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
2457 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); | 2757 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); |
2458 v8::Local<v8::Private> priv2 = | 2758 v8::Local<v8::Private> priv2 = |
2459 v8::Private::New(isolate, v8_str("my-private")); | 2759 v8::Private::New(isolate, v8_str("my-private")); |
2460 | 2760 |
2461 CcTest::heap()->CollectAllGarbage(); | 2761 CcTest::heap()->CollectAllGarbage(); |
2462 | 2762 |
2463 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); | 2763 CHECK(priv2->Name() |
2764 ->Equals(env.local(), | |
2765 v8::String::NewFromUtf8(isolate, "my-private", | |
2766 v8::NewStringType::kNormal) | |
2767 .ToLocalChecked()) | |
2768 .FromJust()); | |
2464 | 2769 |
2465 // Make sure delete of a non-existent private symbol property works. | 2770 // Make sure delete of a non-existent private symbol property works. |
2466 obj->DeletePrivate(env.local(), priv1).FromJust(); | 2771 obj->DeletePrivate(env.local(), priv1).FromJust(); |
2467 CHECK(!obj->HasPrivate(env.local(), priv1).FromJust()); | 2772 CHECK(!obj->HasPrivate(env.local(), priv1).FromJust()); |
2468 | 2773 |
2469 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503)) | 2774 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503)) |
2470 .FromJust()); | 2775 .FromJust()); |
2471 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); | 2776 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); |
2472 CHECK_EQ(1503, | 2777 CHECK_EQ(1503, obj->GetPrivate(env.local(), priv1) |
2473 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); | 2778 .ToLocalChecked() |
2779 ->Int32Value(env.local()) | |
2780 .FromJust()); | |
2474 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002)) | 2781 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002)) |
2475 .FromJust()); | 2782 .FromJust()); |
2476 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); | 2783 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); |
2477 CHECK_EQ(2002, | 2784 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1) |
2478 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); | 2785 .ToLocalChecked() |
2786 ->Int32Value(env.local()) | |
2787 .FromJust()); | |
2479 | 2788 |
2480 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); | 2789 CHECK_EQ(0u, |
2481 unsigned num_props = obj->GetPropertyNames()->Length(); | 2790 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); |
2482 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), | 2791 unsigned num_props = |
2483 v8::Integer::New(isolate, 20))); | 2792 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length(); |
2484 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2793 CHECK(obj->Set(env.local(), v8::String::NewFromUtf8( |
2485 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); | 2794 isolate, "bla", v8::NewStringType::kNormal) |
2795 .ToLocalChecked(), | |
2796 v8::Integer::New(isolate, 20)) | |
2797 .FromJust()); | |
2798 CHECK_EQ(1u, | |
2799 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2800 CHECK_EQ(num_props + 1, | |
2801 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2486 | 2802 |
2487 CcTest::heap()->CollectAllGarbage(); | 2803 CcTest::heap()->CollectAllGarbage(); |
2488 | 2804 |
2489 // Add another property and delete it afterwards to force the object in | 2805 // Add another property and delete it afterwards to force the object in |
2490 // slow case. | 2806 // slow case. |
2491 CHECK(obj->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008)) | 2807 CHECK(obj->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008)) |
2492 .FromJust()); | 2808 .FromJust()); |
2493 CHECK_EQ(2002, | 2809 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1) |
2494 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); | 2810 .ToLocalChecked() |
2495 CHECK_EQ(2008, | 2811 ->Int32Value(env.local()) |
2496 obj->GetPrivate(env.local(), priv2).ToLocalChecked()->Int32Value()); | 2812 .FromJust()); |
2497 CHECK_EQ(2002, | 2813 CHECK_EQ(2008, obj->GetPrivate(env.local(), priv2) |
2498 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); | 2814 .ToLocalChecked() |
2499 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2815 ->Int32Value(env.local()) |
2816 .FromJust()); | |
2817 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1) | |
2818 .ToLocalChecked() | |
2819 ->Int32Value(env.local()) | |
2820 .FromJust()); | |
2821 CHECK_EQ(1u, | |
2822 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2500 | 2823 |
2501 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); | 2824 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); |
2502 CHECK(obj->HasPrivate(env.local(), priv2).FromJust()); | 2825 CHECK(obj->HasPrivate(env.local(), priv2).FromJust()); |
2503 CHECK(obj->DeletePrivate(env.local(), priv2).FromJust()); | 2826 CHECK(obj->DeletePrivate(env.local(), priv2).FromJust()); |
2504 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); | 2827 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); |
2505 CHECK(!obj->HasPrivate(env.local(), priv2).FromJust()); | 2828 CHECK(!obj->HasPrivate(env.local(), priv2).FromJust()); |
2506 CHECK_EQ(2002, | 2829 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1) |
2507 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); | 2830 .ToLocalChecked() |
2508 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); | 2831 ->Int32Value(env.local()) |
2832 .FromJust()); | |
2833 CHECK_EQ(1u, | |
2834 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2509 | 2835 |
2510 // Private properties are not inherited (for the time being). | 2836 // Private properties are not inherited (for the time being). |
2511 v8::Local<v8::Object> child = v8::Object::New(isolate); | 2837 v8::Local<v8::Object> child = v8::Object::New(isolate); |
2512 child->SetPrototype(obj); | 2838 CHECK(child->SetPrototype(env.local(), obj).FromJust()); |
2513 CHECK(!child->HasPrivate(env.local(), priv1).FromJust()); | 2839 CHECK(!child->HasPrivate(env.local(), priv1).FromJust()); |
2514 CHECK_EQ(0u, child->GetOwnPropertyNames()->Length()); | 2840 CHECK_EQ(0u, |
2841 child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length()); | |
2515 } | 2842 } |
2516 | 2843 |
2517 | 2844 |
2518 THREADED_TEST(GlobalSymbols) { | 2845 THREADED_TEST(GlobalSymbols) { |
2519 LocalContext env; | 2846 LocalContext env; |
2520 v8::Isolate* isolate = env->GetIsolate(); | 2847 v8::Isolate* isolate = env->GetIsolate(); |
2521 v8::HandleScope scope(isolate); | 2848 v8::HandleScope scope(isolate); |
2522 | 2849 |
2523 v8::Local<String> name = v8_str("my-symbol"); | 2850 v8::Local<String> name = v8_str("my-symbol"); |
2524 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name); | 2851 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name); |
2525 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name); | 2852 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name); |
2526 CHECK(glob2->SameValue(glob)); | 2853 CHECK(glob2->SameValue(glob)); |
2527 | 2854 |
2528 v8::Local<v8::Symbol> glob_api = v8::Symbol::ForApi(isolate, name); | 2855 v8::Local<v8::Symbol> glob_api = v8::Symbol::ForApi(isolate, name); |
2529 v8::Local<v8::Symbol> glob_api2 = v8::Symbol::ForApi(isolate, name); | 2856 v8::Local<v8::Symbol> glob_api2 = v8::Symbol::ForApi(isolate, name); |
2530 CHECK(glob_api2->SameValue(glob_api)); | 2857 CHECK(glob_api2->SameValue(glob_api)); |
2531 CHECK(!glob_api->SameValue(glob)); | 2858 CHECK(!glob_api->SameValue(glob)); |
2532 | 2859 |
2533 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name); | 2860 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name); |
2534 CHECK(!sym->SameValue(glob)); | 2861 CHECK(!sym->SameValue(glob)); |
2535 | 2862 |
2536 CompileRun("var sym2 = Symbol.for('my-symbol')"); | 2863 CompileRun("var sym2 = Symbol.for('my-symbol')"); |
2537 v8::Local<Value> sym2 = env->Global()->Get(v8_str("sym2")); | 2864 v8::Local<Value> sym2 = |
2865 env->Global()->Get(env.local(), v8_str("sym2")).ToLocalChecked(); | |
2538 CHECK(sym2->SameValue(glob)); | 2866 CHECK(sym2->SameValue(glob)); |
2539 CHECK(!sym2->SameValue(glob_api)); | 2867 CHECK(!sym2->SameValue(glob_api)); |
2540 } | 2868 } |
2541 | 2869 |
2542 | 2870 |
2543 static void CheckWellKnownSymbol(v8::Local<v8::Symbol>(*getter)(v8::Isolate*), | 2871 static void CheckWellKnownSymbol(v8::Local<v8::Symbol>(*getter)(v8::Isolate*), |
2544 const char* name) { | 2872 const char* name) { |
2545 LocalContext env; | 2873 LocalContext env; |
2546 v8::Isolate* isolate = env->GetIsolate(); | 2874 v8::Isolate* isolate = env->GetIsolate(); |
2547 v8::HandleScope scope(isolate); | 2875 v8::HandleScope scope(isolate); |
2548 | 2876 |
2549 v8::Local<v8::Symbol> symbol = getter(isolate); | 2877 v8::Local<v8::Symbol> symbol = getter(isolate); |
2550 std::string script = std::string("var sym = ") + name; | 2878 std::string script = std::string("var sym = ") + name; |
2551 CompileRun(script.c_str()); | 2879 CompileRun(script.c_str()); |
2552 v8::Local<Value> value = env->Global()->Get(v8_str("sym")); | 2880 v8::Local<Value> value = |
2881 env->Global()->Get(env.local(), v8_str("sym")).ToLocalChecked(); | |
2553 | 2882 |
2554 CHECK(!value.IsEmpty()); | 2883 CHECK(!value.IsEmpty()); |
2555 CHECK(!symbol.IsEmpty()); | 2884 CHECK(!symbol.IsEmpty()); |
2556 CHECK(value->SameValue(symbol)); | 2885 CHECK(value->SameValue(symbol)); |
2557 } | 2886 } |
2558 | 2887 |
2559 | 2888 |
2560 THREADED_TEST(WellKnownSymbols) { | 2889 THREADED_TEST(WellKnownSymbols) { |
2561 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator"); | 2890 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator"); |
2562 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables"); | 2891 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables"); |
(...skipping 12 matching lines...) Expand all Loading... | |
2575 CHECK(obj->SetPrivate(env.local(), glob, v8::Integer::New(isolate, 3)) | 2904 CHECK(obj->SetPrivate(env.local(), glob, v8::Integer::New(isolate, 3)) |
2576 .FromJust()); | 2905 .FromJust()); |
2577 | 2906 |
2578 v8::Local<v8::Private> glob2 = v8::Private::ForApi(isolate, name); | 2907 v8::Local<v8::Private> glob2 = v8::Private::ForApi(isolate, name); |
2579 CHECK(obj->HasPrivate(env.local(), glob2).FromJust()); | 2908 CHECK(obj->HasPrivate(env.local(), glob2).FromJust()); |
2580 | 2909 |
2581 v8::Local<v8::Private> priv = v8::Private::New(isolate, name); | 2910 v8::Local<v8::Private> priv = v8::Private::New(isolate, name); |
2582 CHECK(!obj->HasPrivate(env.local(), priv).FromJust()); | 2911 CHECK(!obj->HasPrivate(env.local(), priv).FromJust()); |
2583 | 2912 |
2584 CompileRun("var intern = %CreatePrivateSymbol('my-private')"); | 2913 CompileRun("var intern = %CreatePrivateSymbol('my-private')"); |
2585 v8::Local<Value> intern = env->Global()->Get(v8_str("intern")); | 2914 v8::Local<Value> intern = |
2586 CHECK(!obj->Has(intern)); | 2915 env->Global()->Get(env.local(), v8_str("intern")).ToLocalChecked(); |
2916 CHECK(!obj->Has(env.local(), intern).FromJust()); | |
2587 } | 2917 } |
2588 | 2918 |
2589 | 2919 |
2590 class ScopedArrayBufferContents { | 2920 class ScopedArrayBufferContents { |
2591 public: | 2921 public: |
2592 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents) | 2922 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents) |
2593 : contents_(contents) {} | 2923 : contents_(contents) {} |
2594 ~ScopedArrayBufferContents() { free(contents_.Data()); } | 2924 ~ScopedArrayBufferContents() { free(contents_.Data()); } |
2595 void* Data() const { return contents_.Data(); } | 2925 void* Data() const { return contents_.Data(); } |
2596 size_t ByteLength() const { return contents_.ByteLength(); } | 2926 size_t ByteLength() const { return contents_.ByteLength(); } |
2597 | 2927 |
2598 private: | 2928 private: |
2599 const v8::ArrayBuffer::Contents contents_; | 2929 const v8::ArrayBuffer::Contents contents_; |
2600 }; | 2930 }; |
2601 | 2931 |
2602 template <typename T> | 2932 template <typename T> |
2603 static void CheckInternalFieldsAreZero(v8::Handle<T> value) { | 2933 static void CheckInternalFieldsAreZero(v8::Local<T> value) { |
2604 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount()); | 2934 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount()); |
2605 for (int i = 0; i < value->InternalFieldCount(); i++) { | 2935 for (int i = 0; i < value->InternalFieldCount(); i++) { |
2606 CHECK_EQ(0, value->GetInternalField(i)->Int32Value()); | 2936 CHECK_EQ(0, value->GetInternalField(i) |
2937 ->Int32Value(CcTest::isolate()->GetCurrentContext()) | |
2938 .FromJust()); | |
2607 } | 2939 } |
2608 } | 2940 } |
2609 | 2941 |
2610 | 2942 |
2611 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { | 2943 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { |
2612 LocalContext env; | 2944 LocalContext env; |
2613 v8::Isolate* isolate = env->GetIsolate(); | 2945 v8::Isolate* isolate = env->GetIsolate(); |
2614 v8::HandleScope handle_scope(isolate); | 2946 v8::HandleScope handle_scope(isolate); |
2615 | 2947 |
2616 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); | 2948 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); |
2617 CheckInternalFieldsAreZero(ab); | 2949 CheckInternalFieldsAreZero(ab); |
2618 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); | 2950 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); |
2619 CHECK(!ab->IsExternal()); | 2951 CHECK(!ab->IsExternal()); |
2620 CcTest::heap()->CollectAllGarbage(); | 2952 CcTest::heap()->CollectAllGarbage(); |
2621 | 2953 |
2622 ScopedArrayBufferContents ab_contents(ab->Externalize()); | 2954 ScopedArrayBufferContents ab_contents(ab->Externalize()); |
2623 CHECK(ab->IsExternal()); | 2955 CHECK(ab->IsExternal()); |
2624 | 2956 |
2625 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); | 2957 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
2626 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); | 2958 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); |
2627 DCHECK(data != NULL); | 2959 DCHECK(data != NULL); |
2628 env->Global()->Set(v8_str("ab"), ab); | 2960 CHECK(env->Global()->Set(env.local(), v8_str("ab"), ab).FromJust()); |
2629 | 2961 |
2630 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); | 2962 v8::Local<v8::Value> result = CompileRun("ab.byteLength"); |
2631 CHECK_EQ(1024, result->Int32Value()); | 2963 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust()); |
2632 | 2964 |
2633 result = CompileRun( | 2965 result = CompileRun( |
2634 "var u8 = new Uint8Array(ab);" | 2966 "var u8 = new Uint8Array(ab);" |
2635 "u8[0] = 0xFF;" | 2967 "u8[0] = 0xFF;" |
2636 "u8[1] = 0xAA;" | 2968 "u8[1] = 0xAA;" |
2637 "u8.length"); | 2969 "u8.length"); |
2638 CHECK_EQ(1024, result->Int32Value()); | 2970 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust()); |
2639 CHECK_EQ(0xFF, data[0]); | 2971 CHECK_EQ(0xFF, data[0]); |
2640 CHECK_EQ(0xAA, data[1]); | 2972 CHECK_EQ(0xAA, data[1]); |
2641 data[0] = 0xCC; | 2973 data[0] = 0xCC; |
2642 data[1] = 0x11; | 2974 data[1] = 0x11; |
2643 result = CompileRun("u8[0] + u8[1]"); | 2975 result = CompileRun("u8[0] + u8[1]"); |
2644 CHECK_EQ(0xDD, result->Int32Value()); | 2976 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
2645 } | 2977 } |
2646 | 2978 |
2647 | 2979 |
2648 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { | 2980 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { |
2649 LocalContext env; | 2981 LocalContext env; |
2650 v8::Isolate* isolate = env->GetIsolate(); | 2982 v8::Isolate* isolate = env->GetIsolate(); |
2651 v8::HandleScope handle_scope(isolate); | 2983 v8::HandleScope handle_scope(isolate); |
2652 | 2984 |
2653 | 2985 |
2654 v8::Local<v8::Value> result = CompileRun( | 2986 v8::Local<v8::Value> result = CompileRun( |
2655 "var ab1 = new ArrayBuffer(2);" | 2987 "var ab1 = new ArrayBuffer(2);" |
2656 "var u8_a = new Uint8Array(ab1);" | 2988 "var u8_a = new Uint8Array(ab1);" |
2657 "u8_a[0] = 0xAA;" | 2989 "u8_a[0] = 0xAA;" |
2658 "u8_a[1] = 0xFF; u8_a.buffer"); | 2990 "u8_a[1] = 0xFF; u8_a.buffer"); |
2659 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); | 2991 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); |
2660 CheckInternalFieldsAreZero(ab1); | 2992 CheckInternalFieldsAreZero(ab1); |
2661 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); | 2993 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
2662 CHECK(!ab1->IsExternal()); | 2994 CHECK(!ab1->IsExternal()); |
2663 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); | 2995 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); |
2664 CHECK(ab1->IsExternal()); | 2996 CHECK(ab1->IsExternal()); |
2665 | 2997 |
2666 result = CompileRun("ab1.byteLength"); | 2998 result = CompileRun("ab1.byteLength"); |
2667 CHECK_EQ(2, result->Int32Value()); | 2999 CHECK_EQ(2, result->Int32Value(env.local()).FromJust()); |
2668 result = CompileRun("u8_a[0]"); | 3000 result = CompileRun("u8_a[0]"); |
2669 CHECK_EQ(0xAA, result->Int32Value()); | 3001 CHECK_EQ(0xAA, result->Int32Value(env.local()).FromJust()); |
2670 result = CompileRun("u8_a[1]"); | 3002 result = CompileRun("u8_a[1]"); |
2671 CHECK_EQ(0xFF, result->Int32Value()); | 3003 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust()); |
2672 result = CompileRun( | 3004 result = CompileRun( |
2673 "var u8_b = new Uint8Array(ab1);" | 3005 "var u8_b = new Uint8Array(ab1);" |
2674 "u8_b[0] = 0xBB;" | 3006 "u8_b[0] = 0xBB;" |
2675 "u8_a[0]"); | 3007 "u8_a[0]"); |
2676 CHECK_EQ(0xBB, result->Int32Value()); | 3008 CHECK_EQ(0xBB, result->Int32Value(env.local()).FromJust()); |
2677 result = CompileRun("u8_b[1]"); | 3009 result = CompileRun("u8_b[1]"); |
2678 CHECK_EQ(0xFF, result->Int32Value()); | 3010 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust()); |
2679 | 3011 |
2680 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); | 3012 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); |
2681 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); | 3013 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); |
2682 CHECK_EQ(0xBB, ab1_data[0]); | 3014 CHECK_EQ(0xBB, ab1_data[0]); |
2683 CHECK_EQ(0xFF, ab1_data[1]); | 3015 CHECK_EQ(0xFF, ab1_data[1]); |
2684 ab1_data[0] = 0xCC; | 3016 ab1_data[0] = 0xCC; |
2685 ab1_data[1] = 0x11; | 3017 ab1_data[1] = 0x11; |
2686 result = CompileRun("u8_a[0] + u8_a[1]"); | 3018 result = CompileRun("u8_a[0] + u8_a[1]"); |
2687 CHECK_EQ(0xDD, result->Int32Value()); | 3019 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
2688 } | 3020 } |
2689 | 3021 |
2690 | 3022 |
2691 THREADED_TEST(ArrayBuffer_External) { | 3023 THREADED_TEST(ArrayBuffer_External) { |
2692 LocalContext env; | 3024 LocalContext env; |
2693 v8::Isolate* isolate = env->GetIsolate(); | 3025 v8::Isolate* isolate = env->GetIsolate(); |
2694 v8::HandleScope handle_scope(isolate); | 3026 v8::HandleScope handle_scope(isolate); |
2695 | 3027 |
2696 i::ScopedVector<uint8_t> my_data(100); | 3028 i::ScopedVector<uint8_t> my_data(100); |
2697 memset(my_data.start(), 0, 100); | 3029 memset(my_data.start(), 0, 100); |
2698 Local<v8::ArrayBuffer> ab3 = | 3030 Local<v8::ArrayBuffer> ab3 = |
2699 v8::ArrayBuffer::New(isolate, my_data.start(), 100); | 3031 v8::ArrayBuffer::New(isolate, my_data.start(), 100); |
2700 CheckInternalFieldsAreZero(ab3); | 3032 CheckInternalFieldsAreZero(ab3); |
2701 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); | 3033 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); |
2702 CHECK(ab3->IsExternal()); | 3034 CHECK(ab3->IsExternal()); |
2703 | 3035 |
2704 env->Global()->Set(v8_str("ab3"), ab3); | 3036 CHECK(env->Global()->Set(env.local(), v8_str("ab3"), ab3).FromJust()); |
2705 | 3037 |
2706 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); | 3038 v8::Local<v8::Value> result = CompileRun("ab3.byteLength"); |
2707 CHECK_EQ(100, result->Int32Value()); | 3039 CHECK_EQ(100, result->Int32Value(env.local()).FromJust()); |
2708 | 3040 |
2709 result = CompileRun( | 3041 result = CompileRun( |
2710 "var u8_b = new Uint8Array(ab3);" | 3042 "var u8_b = new Uint8Array(ab3);" |
2711 "u8_b[0] = 0xBB;" | 3043 "u8_b[0] = 0xBB;" |
2712 "u8_b[1] = 0xCC;" | 3044 "u8_b[1] = 0xCC;" |
2713 "u8_b.length"); | 3045 "u8_b.length"); |
2714 CHECK_EQ(100, result->Int32Value()); | 3046 CHECK_EQ(100, result->Int32Value(env.local()).FromJust()); |
2715 CHECK_EQ(0xBB, my_data[0]); | 3047 CHECK_EQ(0xBB, my_data[0]); |
2716 CHECK_EQ(0xCC, my_data[1]); | 3048 CHECK_EQ(0xCC, my_data[1]); |
2717 my_data[0] = 0xCC; | 3049 my_data[0] = 0xCC; |
2718 my_data[1] = 0x11; | 3050 my_data[1] = 0x11; |
2719 result = CompileRun("u8_b[0] + u8_b[1]"); | 3051 result = CompileRun("u8_b[0] + u8_b[1]"); |
2720 CHECK_EQ(0xDD, result->Int32Value()); | 3052 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
2721 } | 3053 } |
2722 | 3054 |
2723 | 3055 |
2724 THREADED_TEST(ArrayBuffer_DisableNeuter) { | 3056 THREADED_TEST(ArrayBuffer_DisableNeuter) { |
2725 LocalContext env; | 3057 LocalContext env; |
2726 v8::Isolate* isolate = env->GetIsolate(); | 3058 v8::Isolate* isolate = env->GetIsolate(); |
2727 v8::HandleScope handle_scope(isolate); | 3059 v8::HandleScope handle_scope(isolate); |
2728 | 3060 |
2729 i::ScopedVector<uint8_t> my_data(100); | 3061 i::ScopedVector<uint8_t> my_data(100); |
2730 memset(my_data.start(), 0, 100); | 3062 memset(my_data.start(), 0, 100); |
2731 Local<v8::ArrayBuffer> ab = | 3063 Local<v8::ArrayBuffer> ab = |
2732 v8::ArrayBuffer::New(isolate, my_data.start(), 100); | 3064 v8::ArrayBuffer::New(isolate, my_data.start(), 100); |
2733 CHECK(ab->IsNeuterable()); | 3065 CHECK(ab->IsNeuterable()); |
2734 | 3066 |
2735 i::Handle<i::JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); | 3067 i::Handle<i::JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); |
2736 buf->set_is_neuterable(false); | 3068 buf->set_is_neuterable(false); |
2737 | 3069 |
2738 CHECK(!ab->IsNeuterable()); | 3070 CHECK(!ab->IsNeuterable()); |
2739 } | 3071 } |
2740 | 3072 |
2741 | 3073 |
2742 static void CheckDataViewIsNeutered(v8::Handle<v8::DataView> dv) { | 3074 static void CheckDataViewIsNeutered(v8::Local<v8::DataView> dv) { |
2743 CHECK_EQ(0, static_cast<int>(dv->ByteLength())); | 3075 CHECK_EQ(0, static_cast<int>(dv->ByteLength())); |
2744 CHECK_EQ(0, static_cast<int>(dv->ByteOffset())); | 3076 CHECK_EQ(0, static_cast<int>(dv->ByteOffset())); |
2745 } | 3077 } |
2746 | 3078 |
2747 | 3079 |
2748 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) { | 3080 static void CheckIsNeutered(v8::Local<v8::TypedArray> ta) { |
2749 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); | 3081 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); |
2750 CHECK_EQ(0, static_cast<int>(ta->Length())); | 3082 CHECK_EQ(0, static_cast<int>(ta->Length())); |
2751 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); | 3083 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); |
2752 } | 3084 } |
2753 | 3085 |
2754 | 3086 |
2755 static void CheckIsTypedArrayVarNeutered(const char* name) { | 3087 static void CheckIsTypedArrayVarNeutered(const char* name) { |
2756 i::ScopedVector<char> source(1024); | 3088 i::ScopedVector<char> source(1024); |
2757 i::SNPrintF(source, | 3089 i::SNPrintF(source, |
2758 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0", | 3090 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0", |
2759 name, name, name); | 3091 name, name, name); |
2760 CHECK(CompileRun(source.start())->IsTrue()); | 3092 CHECK(CompileRun(source.start())->IsTrue()); |
2761 v8::Handle<v8::TypedArray> ta = | 3093 v8::Local<v8::TypedArray> ta = |
2762 v8::Handle<v8::TypedArray>::Cast(CompileRun(name)); | 3094 v8::Local<v8::TypedArray>::Cast(CompileRun(name)); |
2763 CheckIsNeutered(ta); | 3095 CheckIsNeutered(ta); |
2764 } | 3096 } |
2765 | 3097 |
2766 | 3098 |
2767 template <typename TypedArray, int kElementSize> | 3099 template <typename TypedArray, int kElementSize> |
2768 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, | 3100 static Local<TypedArray> CreateAndCheck(Local<v8::ArrayBuffer> ab, |
2769 int byteOffset, int length) { | 3101 int byteOffset, int length) { |
2770 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); | 3102 v8::Local<TypedArray> ta = TypedArray::New(ab, byteOffset, length); |
2771 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); | 3103 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); |
2772 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); | 3104 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); |
2773 CHECK_EQ(length, static_cast<int>(ta->Length())); | 3105 CHECK_EQ(length, static_cast<int>(ta->Length())); |
2774 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); | 3106 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); |
2775 return ta; | 3107 return ta; |
2776 } | 3108 } |
2777 | 3109 |
2778 | 3110 |
2779 THREADED_TEST(ArrayBuffer_NeuteringApi) { | 3111 THREADED_TEST(ArrayBuffer_NeuteringApi) { |
2780 LocalContext env; | 3112 LocalContext env; |
2781 v8::Isolate* isolate = env->GetIsolate(); | 3113 v8::Isolate* isolate = env->GetIsolate(); |
2782 v8::HandleScope handle_scope(isolate); | 3114 v8::HandleScope handle_scope(isolate); |
2783 | 3115 |
2784 v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, 1024); | 3116 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, 1024); |
2785 | 3117 |
2786 v8::Handle<v8::Uint8Array> u8a = | 3118 v8::Local<v8::Uint8Array> u8a = |
2787 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023); | 3119 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023); |
2788 v8::Handle<v8::Uint8ClampedArray> u8c = | 3120 v8::Local<v8::Uint8ClampedArray> u8c = |
2789 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023); | 3121 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023); |
2790 v8::Handle<v8::Int8Array> i8a = | 3122 v8::Local<v8::Int8Array> i8a = |
2791 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023); | 3123 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023); |
2792 | 3124 |
2793 v8::Handle<v8::Uint16Array> u16a = | 3125 v8::Local<v8::Uint16Array> u16a = |
2794 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511); | 3126 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511); |
2795 v8::Handle<v8::Int16Array> i16a = | 3127 v8::Local<v8::Int16Array> i16a = |
2796 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511); | 3128 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511); |
2797 | 3129 |
2798 v8::Handle<v8::Uint32Array> u32a = | 3130 v8::Local<v8::Uint32Array> u32a = |
2799 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); | 3131 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); |
2800 v8::Handle<v8::Int32Array> i32a = | 3132 v8::Local<v8::Int32Array> i32a = |
2801 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); | 3133 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); |
2802 | 3134 |
2803 v8::Handle<v8::Float32Array> f32a = | 3135 v8::Local<v8::Float32Array> f32a = |
2804 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); | 3136 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); |
2805 v8::Handle<v8::Float64Array> f64a = | 3137 v8::Local<v8::Float64Array> f64a = |
2806 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); | 3138 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); |
2807 | 3139 |
2808 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023); | 3140 v8::Local<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023); |
2809 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); | 3141 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); |
2810 CHECK_EQ(1, static_cast<int>(dv->ByteOffset())); | 3142 CHECK_EQ(1, static_cast<int>(dv->ByteOffset())); |
2811 CHECK_EQ(1023, static_cast<int>(dv->ByteLength())); | 3143 CHECK_EQ(1023, static_cast<int>(dv->ByteLength())); |
2812 | 3144 |
2813 ScopedArrayBufferContents contents(buffer->Externalize()); | 3145 ScopedArrayBufferContents contents(buffer->Externalize()); |
2814 buffer->Neuter(); | 3146 buffer->Neuter(); |
2815 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); | 3147 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); |
2816 CheckIsNeutered(u8a); | 3148 CheckIsNeutered(u8a); |
2817 CheckIsNeutered(u8c); | 3149 CheckIsNeutered(u8c); |
2818 CheckIsNeutered(i8a); | 3150 CheckIsNeutered(i8a); |
(...skipping 18 matching lines...) Expand all Loading... | |
2837 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" | 3169 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" |
2838 "var i8a = new Int8Array(ab, 1, 1023);" | 3170 "var i8a = new Int8Array(ab, 1, 1023);" |
2839 "var u16a = new Uint16Array(ab, 2, 511);" | 3171 "var u16a = new Uint16Array(ab, 2, 511);" |
2840 "var i16a = new Int16Array(ab, 2, 511);" | 3172 "var i16a = new Int16Array(ab, 2, 511);" |
2841 "var u32a = new Uint32Array(ab, 4, 255);" | 3173 "var u32a = new Uint32Array(ab, 4, 255);" |
2842 "var i32a = new Int32Array(ab, 4, 255);" | 3174 "var i32a = new Int32Array(ab, 4, 255);" |
2843 "var f32a = new Float32Array(ab, 4, 255);" | 3175 "var f32a = new Float32Array(ab, 4, 255);" |
2844 "var f64a = new Float64Array(ab, 8, 127);" | 3176 "var f64a = new Float64Array(ab, 8, 127);" |
2845 "var dv = new DataView(ab, 1, 1023);"); | 3177 "var dv = new DataView(ab, 1, 1023);"); |
2846 | 3178 |
2847 v8::Handle<v8::ArrayBuffer> ab = | 3179 v8::Local<v8::ArrayBuffer> ab = |
2848 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); | 3180 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); |
2849 | 3181 |
2850 v8::Handle<v8::DataView> dv = | 3182 v8::Local<v8::DataView> dv = v8::Local<v8::DataView>::Cast(CompileRun("dv")); |
2851 v8::Handle<v8::DataView>::Cast(CompileRun("dv")); | |
2852 | 3183 |
2853 ScopedArrayBufferContents contents(ab->Externalize()); | 3184 ScopedArrayBufferContents contents(ab->Externalize()); |
2854 ab->Neuter(); | 3185 ab->Neuter(); |
2855 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); | 3186 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); |
2856 CHECK_EQ(0, CompileRun("ab.byteLength")->Int32Value()); | 3187 CHECK_EQ(0, v8_run_int32value(v8_compile("ab.byteLength"))); |
2857 | 3188 |
2858 CheckIsTypedArrayVarNeutered("u8a"); | 3189 CheckIsTypedArrayVarNeutered("u8a"); |
2859 CheckIsTypedArrayVarNeutered("u8c"); | 3190 CheckIsTypedArrayVarNeutered("u8c"); |
2860 CheckIsTypedArrayVarNeutered("i8a"); | 3191 CheckIsTypedArrayVarNeutered("i8a"); |
2861 CheckIsTypedArrayVarNeutered("u16a"); | 3192 CheckIsTypedArrayVarNeutered("u16a"); |
2862 CheckIsTypedArrayVarNeutered("i16a"); | 3193 CheckIsTypedArrayVarNeutered("i16a"); |
2863 CheckIsTypedArrayVarNeutered("u32a"); | 3194 CheckIsTypedArrayVarNeutered("u32a"); |
2864 CheckIsTypedArrayVarNeutered("i32a"); | 3195 CheckIsTypedArrayVarNeutered("i32a"); |
2865 CheckIsTypedArrayVarNeutered("f32a"); | 3196 CheckIsTypedArrayVarNeutered("f32a"); |
2866 CheckIsTypedArrayVarNeutered("f64a"); | 3197 CheckIsTypedArrayVarNeutered("f64a"); |
(...skipping 28 matching lines...) Expand all Loading... | |
2895 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); | 3226 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); |
2896 CHECK(!ab->IsExternal()); | 3227 CHECK(!ab->IsExternal()); |
2897 CcTest::heap()->CollectAllGarbage(); | 3228 CcTest::heap()->CollectAllGarbage(); |
2898 | 3229 |
2899 ScopedSharedArrayBufferContents ab_contents(ab->Externalize()); | 3230 ScopedSharedArrayBufferContents ab_contents(ab->Externalize()); |
2900 CHECK(ab->IsExternal()); | 3231 CHECK(ab->IsExternal()); |
2901 | 3232 |
2902 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); | 3233 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); |
2903 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); | 3234 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); |
2904 DCHECK(data != NULL); | 3235 DCHECK(data != NULL); |
2905 env->Global()->Set(v8_str("ab"), ab); | 3236 CHECK(env->Global()->Set(env.local(), v8_str("ab"), ab).FromJust()); |
2906 | 3237 |
2907 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); | 3238 v8::Local<v8::Value> result = CompileRun("ab.byteLength"); |
2908 CHECK_EQ(1024, result->Int32Value()); | 3239 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust()); |
2909 | 3240 |
2910 result = CompileRun( | 3241 result = CompileRun( |
2911 "var u8 = new Uint8Array(ab);" | 3242 "var u8 = new Uint8Array(ab);" |
2912 "u8[0] = 0xFF;" | 3243 "u8[0] = 0xFF;" |
2913 "u8[1] = 0xAA;" | 3244 "u8[1] = 0xAA;" |
2914 "u8.length"); | 3245 "u8.length"); |
2915 CHECK_EQ(1024, result->Int32Value()); | 3246 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust()); |
2916 CHECK_EQ(0xFF, data[0]); | 3247 CHECK_EQ(0xFF, data[0]); |
2917 CHECK_EQ(0xAA, data[1]); | 3248 CHECK_EQ(0xAA, data[1]); |
2918 data[0] = 0xCC; | 3249 data[0] = 0xCC; |
2919 data[1] = 0x11; | 3250 data[1] = 0x11; |
2920 result = CompileRun("u8[0] + u8[1]"); | 3251 result = CompileRun("u8[0] + u8[1]"); |
2921 CHECK_EQ(0xDD, result->Int32Value()); | 3252 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
2922 } | 3253 } |
2923 | 3254 |
2924 | 3255 |
2925 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) { | 3256 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) { |
2926 i::FLAG_harmony_sharedarraybuffer = true; | 3257 i::FLAG_harmony_sharedarraybuffer = true; |
2927 LocalContext env; | 3258 LocalContext env; |
2928 v8::Isolate* isolate = env->GetIsolate(); | 3259 v8::Isolate* isolate = env->GetIsolate(); |
2929 v8::HandleScope handle_scope(isolate); | 3260 v8::HandleScope handle_scope(isolate); |
2930 | 3261 |
2931 | 3262 |
2932 v8::Local<v8::Value> result = CompileRun( | 3263 v8::Local<v8::Value> result = CompileRun( |
2933 "var ab1 = new SharedArrayBuffer(2);" | 3264 "var ab1 = new SharedArrayBuffer(2);" |
2934 "var u8_a = new Uint8Array(ab1);" | 3265 "var u8_a = new Uint8Array(ab1);" |
2935 "u8_a[0] = 0xAA;" | 3266 "u8_a[0] = 0xAA;" |
2936 "u8_a[1] = 0xFF; u8_a.buffer"); | 3267 "u8_a[1] = 0xFF; u8_a.buffer"); |
2937 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result); | 3268 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result); |
2938 CheckInternalFieldsAreZero(ab1); | 3269 CheckInternalFieldsAreZero(ab1); |
2939 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); | 3270 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); |
2940 CHECK(!ab1->IsExternal()); | 3271 CHECK(!ab1->IsExternal()); |
2941 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize()); | 3272 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize()); |
2942 CHECK(ab1->IsExternal()); | 3273 CHECK(ab1->IsExternal()); |
2943 | 3274 |
2944 result = CompileRun("ab1.byteLength"); | 3275 result = CompileRun("ab1.byteLength"); |
2945 CHECK_EQ(2, result->Int32Value()); | 3276 CHECK_EQ(2, result->Int32Value(env.local()).FromJust()); |
2946 result = CompileRun("u8_a[0]"); | 3277 result = CompileRun("u8_a[0]"); |
2947 CHECK_EQ(0xAA, result->Int32Value()); | 3278 CHECK_EQ(0xAA, result->Int32Value(env.local()).FromJust()); |
2948 result = CompileRun("u8_a[1]"); | 3279 result = CompileRun("u8_a[1]"); |
2949 CHECK_EQ(0xFF, result->Int32Value()); | 3280 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust()); |
2950 result = CompileRun( | 3281 result = CompileRun( |
2951 "var u8_b = new Uint8Array(ab1);" | 3282 "var u8_b = new Uint8Array(ab1);" |
2952 "u8_b[0] = 0xBB;" | 3283 "u8_b[0] = 0xBB;" |
2953 "u8_a[0]"); | 3284 "u8_a[0]"); |
2954 CHECK_EQ(0xBB, result->Int32Value()); | 3285 CHECK_EQ(0xBB, result->Int32Value(env.local()).FromJust()); |
2955 result = CompileRun("u8_b[1]"); | 3286 result = CompileRun("u8_b[1]"); |
2956 CHECK_EQ(0xFF, result->Int32Value()); | 3287 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust()); |
2957 | 3288 |
2958 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); | 3289 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); |
2959 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); | 3290 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); |
2960 CHECK_EQ(0xBB, ab1_data[0]); | 3291 CHECK_EQ(0xBB, ab1_data[0]); |
2961 CHECK_EQ(0xFF, ab1_data[1]); | 3292 CHECK_EQ(0xFF, ab1_data[1]); |
2962 ab1_data[0] = 0xCC; | 3293 ab1_data[0] = 0xCC; |
2963 ab1_data[1] = 0x11; | 3294 ab1_data[1] = 0x11; |
2964 result = CompileRun("u8_a[0] + u8_a[1]"); | 3295 result = CompileRun("u8_a[0] + u8_a[1]"); |
2965 CHECK_EQ(0xDD, result->Int32Value()); | 3296 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
2966 } | 3297 } |
2967 | 3298 |
2968 | 3299 |
2969 THREADED_TEST(SharedArrayBuffer_External) { | 3300 THREADED_TEST(SharedArrayBuffer_External) { |
2970 i::FLAG_harmony_sharedarraybuffer = true; | 3301 i::FLAG_harmony_sharedarraybuffer = true; |
2971 LocalContext env; | 3302 LocalContext env; |
2972 v8::Isolate* isolate = env->GetIsolate(); | 3303 v8::Isolate* isolate = env->GetIsolate(); |
2973 v8::HandleScope handle_scope(isolate); | 3304 v8::HandleScope handle_scope(isolate); |
2974 | 3305 |
2975 i::ScopedVector<uint8_t> my_data(100); | 3306 i::ScopedVector<uint8_t> my_data(100); |
2976 memset(my_data.start(), 0, 100); | 3307 memset(my_data.start(), 0, 100); |
2977 Local<v8::SharedArrayBuffer> ab3 = | 3308 Local<v8::SharedArrayBuffer> ab3 = |
2978 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100); | 3309 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100); |
2979 CheckInternalFieldsAreZero(ab3); | 3310 CheckInternalFieldsAreZero(ab3); |
2980 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); | 3311 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); |
2981 CHECK(ab3->IsExternal()); | 3312 CHECK(ab3->IsExternal()); |
2982 | 3313 |
2983 env->Global()->Set(v8_str("ab3"), ab3); | 3314 CHECK(env->Global()->Set(env.local(), v8_str("ab3"), ab3).FromJust()); |
2984 | 3315 |
2985 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); | 3316 v8::Local<v8::Value> result = CompileRun("ab3.byteLength"); |
2986 CHECK_EQ(100, result->Int32Value()); | 3317 CHECK_EQ(100, result->Int32Value(env.local()).FromJust()); |
2987 | 3318 |
2988 result = CompileRun( | 3319 result = CompileRun( |
2989 "var u8_b = new Uint8Array(ab3);" | 3320 "var u8_b = new Uint8Array(ab3);" |
2990 "u8_b[0] = 0xBB;" | 3321 "u8_b[0] = 0xBB;" |
2991 "u8_b[1] = 0xCC;" | 3322 "u8_b[1] = 0xCC;" |
2992 "u8_b.length"); | 3323 "u8_b.length"); |
2993 CHECK_EQ(100, result->Int32Value()); | 3324 CHECK_EQ(100, result->Int32Value(env.local()).FromJust()); |
2994 CHECK_EQ(0xBB, my_data[0]); | 3325 CHECK_EQ(0xBB, my_data[0]); |
2995 CHECK_EQ(0xCC, my_data[1]); | 3326 CHECK_EQ(0xCC, my_data[1]); |
2996 my_data[0] = 0xCC; | 3327 my_data[0] = 0xCC; |
2997 my_data[1] = 0x11; | 3328 my_data[1] = 0x11; |
2998 result = CompileRun("u8_b[0] + u8_b[1]"); | 3329 result = CompileRun("u8_b[0] + u8_b[1]"); |
2999 CHECK_EQ(0xDD, result->Int32Value()); | 3330 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust()); |
3000 } | 3331 } |
3001 | 3332 |
3002 | 3333 |
3003 THREADED_TEST(HiddenProperties) { | 3334 THREADED_TEST(HiddenProperties) { |
3004 LocalContext env; | 3335 LocalContext env; |
3005 v8::Isolate* isolate = env->GetIsolate(); | 3336 v8::Isolate* isolate = env->GetIsolate(); |
3006 v8::HandleScope scope(isolate); | 3337 v8::HandleScope scope(isolate); |
3007 | 3338 |
3008 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); | 3339 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); |
3009 v8::Local<v8::Private> key = | 3340 v8::Local<v8::Private> key = |
3010 v8::Private::ForApi(isolate, v8_str("api-test::hidden-key")); | 3341 v8::Private::ForApi(isolate, v8_str("api-test::hidden-key")); |
3011 v8::Local<v8::String> empty = v8_str(""); | 3342 v8::Local<v8::String> empty = v8_str(""); |
3012 v8::Local<v8::String> prop_name = v8_str("prop_name"); | 3343 v8::Local<v8::String> prop_name = v8_str("prop_name"); |
3013 | 3344 |
3014 CcTest::heap()->CollectAllGarbage(); | 3345 CcTest::heap()->CollectAllGarbage(); |
3015 | 3346 |
3016 // Make sure delete of a non-existent hidden value works | 3347 // Make sure delete of a non-existent hidden value works |
3017 obj->DeletePrivate(env.local(), key).FromJust(); | 3348 obj->DeletePrivate(env.local(), key).FromJust(); |
3018 | 3349 |
3019 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 1503)) | 3350 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 1503)) |
3020 .FromJust()); | 3351 .FromJust()); |
3021 CHECK_EQ(1503, | 3352 CHECK_EQ(1503, obj->GetPrivate(env.local(), key) |
3022 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3353 .ToLocalChecked() |
3354 ->Int32Value(env.local()) | |
3355 .FromJust()); | |
3023 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) | 3356 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) |
3024 .FromJust()); | 3357 .FromJust()); |
3025 CHECK_EQ(2002, | 3358 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) |
3026 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3359 .ToLocalChecked() |
3360 ->Int32Value(env.local()) | |
3361 .FromJust()); | |
3027 | 3362 |
3028 CcTest::heap()->CollectAllGarbage(); | 3363 CcTest::heap()->CollectAllGarbage(); |
3029 | 3364 |
3030 // Make sure we do not find the hidden property. | 3365 // Make sure we do not find the hidden property. |
3031 CHECK(!obj->Has(empty)); | 3366 CHECK(!obj->Has(env.local(), empty).FromJust()); |
3032 CHECK_EQ(2002, | 3367 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) |
3033 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3368 .ToLocalChecked() |
3034 CHECK(obj->Get(empty)->IsUndefined()); | 3369 ->Int32Value(env.local()) |
3035 CHECK_EQ(2002, | 3370 .FromJust()); |
3036 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3371 CHECK(obj->Get(env.local(), empty).ToLocalChecked()->IsUndefined()); |
3037 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); | 3372 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) |
3038 CHECK_EQ(2002, | 3373 .ToLocalChecked() |
3039 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3374 ->Int32Value(env.local()) |
3040 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); | 3375 .FromJust()); |
3376 CHECK( | |
3377 obj->Set(env.local(), empty, v8::Integer::New(isolate, 2003)).FromJust()); | |
3378 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) | |
3379 .ToLocalChecked() | |
3380 ->Int32Value(env.local()) | |
3381 .FromJust()); | |
3382 CHECK_EQ(2003, obj->Get(env.local(), empty) | |
3383 .ToLocalChecked() | |
3384 ->Int32Value(env.local()) | |
3385 .FromJust()); | |
3041 | 3386 |
3042 CcTest::heap()->CollectAllGarbage(); | 3387 CcTest::heap()->CollectAllGarbage(); |
3043 | 3388 |
3044 // Add another property and delete it afterwards to force the object in | 3389 // Add another property and delete it afterwards to force the object in |
3045 // slow case. | 3390 // slow case. |
3046 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); | 3391 CHECK(obj->Set(env.local(), prop_name, v8::Integer::New(isolate, 2008)) |
3047 CHECK_EQ(2002, | 3392 .FromJust()); |
3048 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3393 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) |
3049 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); | 3394 .ToLocalChecked() |
3050 CHECK_EQ(2002, | 3395 ->Int32Value(env.local()) |
3051 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3396 .FromJust()); |
3052 CHECK(obj->Delete(prop_name)); | 3397 CHECK_EQ(2008, obj->Get(env.local(), prop_name) |
3053 CHECK_EQ(2002, | 3398 .ToLocalChecked() |
3054 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3399 ->Int32Value(env.local()) |
3400 .FromJust()); | |
3401 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) | |
3402 .ToLocalChecked() | |
3403 ->Int32Value(env.local()) | |
3404 .FromJust()); | |
3405 CHECK(obj->Delete(env.local(), prop_name).FromJust()); | |
3406 CHECK_EQ(2002, obj->GetPrivate(env.local(), key) | |
3407 .ToLocalChecked() | |
3408 ->Int32Value(env.local()) | |
3409 .FromJust()); | |
3055 | 3410 |
3056 CcTest::heap()->CollectAllGarbage(); | 3411 CcTest::heap()->CollectAllGarbage(); |
3057 | 3412 |
3058 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) | 3413 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) |
3059 .FromJust()); | 3414 .FromJust()); |
3060 CHECK(obj->DeletePrivate(env.local(), key).FromJust()); | 3415 CHECK(obj->DeletePrivate(env.local(), key).FromJust()); |
3061 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); | 3416 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); |
3062 } | 3417 } |
3063 | 3418 |
3064 | 3419 |
(...skipping 17 matching lines...) Expand all Loading... | |
3082 " set: function() { set_called = true; }})"); | 3437 " set: function() { set_called = true; }})"); |
3083 | 3438 |
3084 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); | 3439 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); |
3085 // Make sure that the getter and setter from Object.prototype is not invoked. | 3440 // Make sure that the getter and setter from Object.prototype is not invoked. |
3086 // If it did we would have full access to the hidden properties in | 3441 // If it did we would have full access to the hidden properties in |
3087 // the accessor. | 3442 // the accessor. |
3088 CHECK( | 3443 CHECK( |
3089 obj->SetPrivate(env.local(), key, v8::Integer::New(env->GetIsolate(), 42)) | 3444 obj->SetPrivate(env.local(), key, v8::Integer::New(env->GetIsolate(), 42)) |
3090 .FromJust()); | 3445 .FromJust()); |
3091 ExpectFalse("set_called"); | 3446 ExpectFalse("set_called"); |
3092 CHECK_EQ(42, | 3447 CHECK_EQ(42, obj->GetPrivate(env.local(), key) |
3093 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); | 3448 .ToLocalChecked() |
3449 ->Int32Value(env.local()) | |
3450 .FromJust()); | |
3094 } | 3451 } |
3095 | 3452 |
3096 | 3453 |
3097 THREADED_TEST(External) { | 3454 THREADED_TEST(External) { |
3098 v8::HandleScope scope(CcTest::isolate()); | 3455 v8::HandleScope scope(CcTest::isolate()); |
3099 int x = 3; | 3456 int x = 3; |
3100 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); | 3457 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); |
3101 LocalContext env; | 3458 LocalContext env; |
3102 env->Global()->Set(v8_str("ext"), ext); | 3459 CHECK(env->Global()->Set(env.local(), v8_str("ext"), ext).FromJust()); |
3103 Local<Value> reext_obj = CompileRun("this.ext"); | 3460 Local<Value> reext_obj = CompileRun("this.ext"); |
3104 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); | 3461 v8::Local<v8::External> reext = reext_obj.As<v8::External>(); |
3105 int* ptr = static_cast<int*>(reext->Value()); | 3462 int* ptr = static_cast<int*>(reext->Value()); |
3106 CHECK_EQ(x, 3); | 3463 CHECK_EQ(x, 3); |
3107 *ptr = 10; | 3464 *ptr = 10; |
3108 CHECK_EQ(x, 10); | 3465 CHECK_EQ(x, 10); |
3109 | 3466 |
3110 // Make sure unaligned pointers are wrapped properly. | 3467 // Make sure unaligned pointers are wrapped properly. |
3111 char* data = i::StrDup("0123456789"); | 3468 char* data = i::StrDup("0123456789"); |
3112 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); | 3469 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); |
3113 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); | 3470 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); |
3114 Local<v8::Value> two = v8::External::New(CcTest::isolate(), &data[2]); | 3471 Local<v8::Value> two = v8::External::New(CcTest::isolate(), &data[2]); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3390 | 3747 |
3391 namespace { | 3748 namespace { |
3392 | 3749 |
3393 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); } | 3750 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); } |
3394 | 3751 |
3395 | 3752 |
3396 Local<v8::Object> NewObjectForIntKey( | 3753 Local<v8::Object> NewObjectForIntKey( |
3397 v8::Isolate* isolate, const v8::Global<v8::ObjectTemplate>& templ, | 3754 v8::Isolate* isolate, const v8::Global<v8::ObjectTemplate>& templ, |
3398 int key) { | 3755 int key) { |
3399 auto local = Local<v8::ObjectTemplate>::New(isolate, templ); | 3756 auto local = Local<v8::ObjectTemplate>::New(isolate, templ); |
3400 auto obj = local->NewInstance(); | 3757 auto obj = local->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); |
3401 obj->SetAlignedPointerInInternalField(0, IntKeyToVoidPointer(key)); | 3758 obj->SetAlignedPointerInInternalField(0, IntKeyToVoidPointer(key)); |
3402 return obj; | 3759 return obj; |
3403 } | 3760 } |
3404 | 3761 |
3405 | 3762 |
3406 template <typename K, typename V> | 3763 template <typename K, typename V> |
3407 class PhantomStdMapTraits : public v8::StdMapTraits<K, V> { | 3764 class PhantomStdMapTraits : public v8::StdMapTraits<K, V> { |
3408 public: | 3765 public: |
3409 typedef typename v8::GlobalValueMap<K, V, PhantomStdMapTraits<K, V>> MapType; | 3766 typedef typename v8::GlobalValueMap<K, V, PhantomStdMapTraits<K, V>> MapType; |
3410 static const v8::PersistentContainerCallbackType kCallbackType = | 3767 static const v8::PersistentContainerCallbackType kCallbackType = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3461 int initial_handle_count = global_handles->global_handles_count(); | 3818 int initial_handle_count = global_handles->global_handles_count(); |
3462 CHECK_EQ(0, static_cast<int>(map.Size())); | 3819 CHECK_EQ(0, static_cast<int>(map.Size())); |
3463 { | 3820 { |
3464 HandleScope scope(isolate); | 3821 HandleScope scope(isolate); |
3465 Local<v8::Object> obj = map.Get(7); | 3822 Local<v8::Object> obj = map.Get(7); |
3466 CHECK(obj.IsEmpty()); | 3823 CHECK(obj.IsEmpty()); |
3467 Local<v8::Object> expected = v8::Object::New(isolate); | 3824 Local<v8::Object> expected = v8::Object::New(isolate); |
3468 map.Set(7, expected); | 3825 map.Set(7, expected); |
3469 CHECK_EQ(1, static_cast<int>(map.Size())); | 3826 CHECK_EQ(1, static_cast<int>(map.Size())); |
3470 obj = map.Get(7); | 3827 obj = map.Get(7); |
3471 CHECK(expected->Equals(obj)); | 3828 CHECK(expected->Equals(env.local(), obj).FromJust()); |
3472 { | 3829 { |
3473 typename Map::PersistentValueReference ref = map.GetReference(7); | 3830 typename Map::PersistentValueReference ref = map.GetReference(7); |
3474 CHECK(expected->Equals(ref.NewLocal(isolate))); | 3831 CHECK(expected->Equals(ref.NewLocal(isolate))); |
3475 } | 3832 } |
3476 v8::Global<v8::Object> removed = map.Remove(7); | 3833 v8::Global<v8::Object> removed = map.Remove(7); |
3477 CHECK_EQ(0, static_cast<int>(map.Size())); | 3834 CHECK_EQ(0, static_cast<int>(map.Size())); |
3478 CHECK(expected == removed); | 3835 CHECK(expected == removed); |
3479 removed = map.Remove(7); | 3836 removed = map.Remove(7); |
3480 CHECK(removed.IsEmpty()); | 3837 CHECK(removed.IsEmpty()); |
3481 map.Set(8, expected); | 3838 map.Set(8, expected); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3546 | 3903 |
3547 vector.Append(obj1); | 3904 vector.Append(obj1); |
3548 vector.Append(obj2); | 3905 vector.Append(obj2); |
3549 vector.Append(obj1); | 3906 vector.Append(obj1); |
3550 vector.Append(obj3.Pass()); | 3907 vector.Append(obj3.Pass()); |
3551 vector.Append(obj1); | 3908 vector.Append(obj1); |
3552 | 3909 |
3553 CHECK(!vector.IsEmpty()); | 3910 CHECK(!vector.IsEmpty()); |
3554 CHECK_EQ(5, static_cast<int>(vector.Size())); | 3911 CHECK_EQ(5, static_cast<int>(vector.Size())); |
3555 CHECK(obj3.IsEmpty()); | 3912 CHECK(obj3.IsEmpty()); |
3556 CHECK(obj1->Equals(vector.Get(0))); | 3913 CHECK(obj1->Equals(env.local(), vector.Get(0)).FromJust()); |
3557 CHECK(obj1->Equals(vector.Get(2))); | 3914 CHECK(obj1->Equals(env.local(), vector.Get(2)).FromJust()); |
3558 CHECK(obj1->Equals(vector.Get(4))); | 3915 CHECK(obj1->Equals(env.local(), vector.Get(4)).FromJust()); |
3559 CHECK(obj2->Equals(vector.Get(1))); | 3916 CHECK(obj2->Equals(env.local(), vector.Get(1)).FromJust()); |
3560 | 3917 |
3561 CHECK_EQ(5 + handle_count, global_handles->global_handles_count()); | 3918 CHECK_EQ(5 + handle_count, global_handles->global_handles_count()); |
3562 | 3919 |
3563 vector.Clear(); | 3920 vector.Clear(); |
3564 CHECK(vector.IsEmpty()); | 3921 CHECK(vector.IsEmpty()); |
3565 CHECK_EQ(0, static_cast<int>(vector.Size())); | 3922 CHECK_EQ(0, static_cast<int>(vector.Size())); |
3566 CHECK_EQ(handle_count, global_handles->global_handles_count()); | 3923 CHECK_EQ(handle_count, global_handles->global_handles_count()); |
3567 } | 3924 } |
3568 | 3925 |
3569 | 3926 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3700 v8::WeakCallbackType::kParameter); | 4057 v8::WeakCallbackType::kParameter); |
3701 } | 4058 } |
3702 | 4059 |
3703 WeakCallCounterAndPersistent<Value> root(&counter); | 4060 WeakCallCounterAndPersistent<Value> root(&counter); |
3704 root.handle.Reset(iso, g1s1.handle); // make a root. | 4061 root.handle.Reset(iso, g1s1.handle); // make a root. |
3705 | 4062 |
3706 // Connect group 1 and 2, make a cycle. | 4063 // Connect group 1 and 2, make a cycle. |
3707 { | 4064 { |
3708 HandleScope scope(iso); | 4065 HandleScope scope(iso); |
3709 CHECK(Local<Object>::New(iso, g1s2.handle.As<Object>()) | 4066 CHECK(Local<Object>::New(iso, g1s2.handle.As<Object>()) |
3710 ->Set(0, Local<Value>::New(iso, g2s2.handle))); | 4067 ->Set(env.local(), 0, Local<Value>::New(iso, g2s2.handle)) |
4068 .FromJust()); | |
3711 CHECK(Local<Object>::New(iso, g2s1.handle.As<Object>()) | 4069 CHECK(Local<Object>::New(iso, g2s1.handle.As<Object>()) |
3712 ->Set(0, Local<Value>::New(iso, g1s1.handle))); | 4070 ->Set(env.local(), 0, Local<Value>::New(iso, g1s1.handle)) |
4071 .FromJust()); | |
3713 } | 4072 } |
3714 | 4073 |
3715 { | 4074 { |
3716 UniqueId id1 = MakeUniqueId(g1s1.handle); | 4075 UniqueId id1 = MakeUniqueId(g1s1.handle); |
3717 UniqueId id2 = MakeUniqueId(g2s2.handle); | 4076 UniqueId id2 = MakeUniqueId(g2s2.handle); |
3718 iso->SetObjectGroupId(g1s1.handle, id1); | 4077 iso->SetObjectGroupId(g1s1.handle, id1); |
3719 iso->SetObjectGroupId(g1s2.handle, id1); | 4078 iso->SetObjectGroupId(g1s2.handle, id1); |
3720 iso->SetReferenceFromGroup(id1, g1c1.handle); | 4079 iso->SetReferenceFromGroup(id1, g1c1.handle); |
3721 iso->SetObjectGroupId(g2s1.handle, id2); | 4080 iso->SetObjectGroupId(g2s1.handle, id2); |
3722 iso->SetObjectGroupId(g2s2.handle, id2); | 4081 iso->SetObjectGroupId(g2s2.handle, id2); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3776 WeakCallCounterAndPersistent<Object> g1s1(&counter); | 4135 WeakCallCounterAndPersistent<Object> g1s1(&counter); |
3777 WeakCallCounterAndPersistent<String> g1s2(&counter); | 4136 WeakCallCounterAndPersistent<String> g1s2(&counter); |
3778 WeakCallCounterAndPersistent<String> g1c1(&counter); | 4137 WeakCallCounterAndPersistent<String> g1c1(&counter); |
3779 WeakCallCounterAndPersistent<Object> g2s1(&counter); | 4138 WeakCallCounterAndPersistent<Object> g2s1(&counter); |
3780 WeakCallCounterAndPersistent<String> g2s2(&counter); | 4139 WeakCallCounterAndPersistent<String> g2s2(&counter); |
3781 WeakCallCounterAndPersistent<String> g2c1(&counter); | 4140 WeakCallCounterAndPersistent<String> g2c1(&counter); |
3782 | 4141 |
3783 { | 4142 { |
3784 HandleScope scope(iso); | 4143 HandleScope scope(iso); |
3785 g1s1.handle.Reset(iso, Object::New(iso)); | 4144 g1s1.handle.Reset(iso, Object::New(iso)); |
3786 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1")); | 4145 g1s2.handle.Reset(iso, v8_str("foo1")); |
3787 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2")); | 4146 g1c1.handle.Reset(iso, v8_str("foo2")); |
3788 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback, | 4147 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback, |
3789 v8::WeakCallbackType::kParameter); | 4148 v8::WeakCallbackType::kParameter); |
3790 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback, | 4149 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback, |
3791 v8::WeakCallbackType::kParameter); | 4150 v8::WeakCallbackType::kParameter); |
3792 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback, | 4151 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback, |
3793 v8::WeakCallbackType::kParameter); | 4152 v8::WeakCallbackType::kParameter); |
3794 | 4153 |
3795 g2s1.handle.Reset(iso, Object::New(iso)); | 4154 g2s1.handle.Reset(iso, Object::New(iso)); |
3796 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3")); | 4155 g2s2.handle.Reset(iso, v8_str("foo3")); |
3797 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4")); | 4156 g2c1.handle.Reset(iso, v8_str("foo4")); |
3798 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback, | 4157 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback, |
3799 v8::WeakCallbackType::kParameter); | 4158 v8::WeakCallbackType::kParameter); |
3800 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback, | 4159 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback, |
3801 v8::WeakCallbackType::kParameter); | 4160 v8::WeakCallbackType::kParameter); |
3802 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback, | 4161 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback, |
3803 v8::WeakCallbackType::kParameter); | 4162 v8::WeakCallbackType::kParameter); |
3804 } | 4163 } |
3805 | 4164 |
3806 WeakCallCounterAndPersistent<Value> root(&counter); | 4165 WeakCallCounterAndPersistent<Value> root(&counter); |
3807 root.handle.Reset(iso, g1s1.handle); // make a root. | 4166 root.handle.Reset(iso, g1s1.handle); // make a root. |
3808 | 4167 |
3809 // Connect group 1 and 2, make a cycle. | 4168 // Connect group 1 and 2, make a cycle. |
3810 { | 4169 { |
3811 HandleScope scope(iso); | 4170 HandleScope scope(iso); |
3812 CHECK(Local<Object>::New(iso, g1s1.handle) | 4171 CHECK(Local<Object>::New(iso, g1s1.handle) |
3813 ->Set(0, Local<Object>::New(iso, g2s1.handle))); | 4172 ->Set(env.local(), 0, Local<Object>::New(iso, g2s1.handle)) |
4173 .FromJust()); | |
3814 CHECK(Local<Object>::New(iso, g2s1.handle) | 4174 CHECK(Local<Object>::New(iso, g2s1.handle) |
3815 ->Set(0, Local<Object>::New(iso, g1s1.handle))); | 4175 ->Set(env.local(), 0, Local<Object>::New(iso, g1s1.handle)) |
4176 .FromJust()); | |
3816 } | 4177 } |
3817 | 4178 |
3818 { | 4179 { |
3819 UniqueId id1 = MakeUniqueId(g1s1.handle); | 4180 UniqueId id1 = MakeUniqueId(g1s1.handle); |
3820 UniqueId id2 = MakeUniqueId(g2s2.handle); | 4181 UniqueId id2 = MakeUniqueId(g2s2.handle); |
3821 iso->SetObjectGroupId(g1s1.handle, id1); | 4182 iso->SetObjectGroupId(g1s1.handle, id1); |
3822 iso->SetObjectGroupId(g1s2.handle, id1); | 4183 iso->SetObjectGroupId(g1s2.handle, id1); |
3823 iso->SetReference(g1s1.handle, g1c1.handle); | 4184 iso->SetReference(g1s1.handle, g1c1.handle); |
3824 iso->SetObjectGroupId(g2s1.handle, id2); | 4185 iso->SetObjectGroupId(g2s1.handle, id2); |
3825 iso->SetObjectGroupId(g2s2.handle, id2); | 4186 iso->SetObjectGroupId(g2s2.handle, id2); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4041 HandleScope handle_scope(iso); | 4402 HandleScope handle_scope(iso); |
4042 g1s1.handle.MarkPartiallyDependent(); | 4403 g1s1.handle.MarkPartiallyDependent(); |
4043 g1s2.handle.MarkPartiallyDependent(); | 4404 g1s2.handle.MarkPartiallyDependent(); |
4044 g2s1.handle.MarkPartiallyDependent(); | 4405 g2s1.handle.MarkPartiallyDependent(); |
4045 g2s2.handle.MarkPartiallyDependent(); | 4406 g2s2.handle.MarkPartiallyDependent(); |
4046 g3s1.handle.MarkPartiallyDependent(); | 4407 g3s1.handle.MarkPartiallyDependent(); |
4047 g3s2.handle.MarkPartiallyDependent(); | 4408 g3s2.handle.MarkPartiallyDependent(); |
4048 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); | 4409 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); |
4049 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); | 4410 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); |
4050 Local<Object>::New(iso, g1s1.handle.As<Object>()) | 4411 Local<Object>::New(iso, g1s1.handle.As<Object>()) |
4051 ->Set(v8_str("x"), Local<Value>::New(iso, g2s1.handle)); | 4412 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g2s1.handle)) |
4413 .FromJust(); | |
4052 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); | 4414 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); |
4053 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); | 4415 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); |
4054 Local<Object>::New(iso, g2s1.handle.As<Object>()) | 4416 Local<Object>::New(iso, g2s1.handle.As<Object>()) |
4055 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); | 4417 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g3s1.handle)) |
4418 .FromJust(); | |
4056 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); | 4419 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); |
4057 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); | 4420 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); |
4058 Local<Object>::New(iso, g3s1.handle.As<Object>()) | 4421 Local<Object>::New(iso, g3s1.handle.As<Object>()) |
4059 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); | 4422 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g1s1.handle)) |
4423 .FromJust(); | |
4060 } | 4424 } |
4061 | 4425 |
4062 v8::internal::Heap* heap = | 4426 v8::internal::Heap* heap = |
4063 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); | 4427 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); |
4064 heap->CollectAllGarbage(); | 4428 heap->CollectAllGarbage(); |
4065 | 4429 |
4066 // All objects should be alive. | 4430 // All objects should be alive. |
4067 CHECK_EQ(0, counter.NumberOfWeakCalls()); | 4431 CHECK_EQ(0, counter.NumberOfWeakCalls()); |
4068 | 4432 |
4069 // Weaken the root. | 4433 // Weaken the root. |
4070 root.handle.SetWeak(&root, &WeakPointerCallback, | 4434 root.handle.SetWeak(&root, &WeakPointerCallback, |
4071 v8::WeakCallbackType::kParameter); | 4435 v8::WeakCallbackType::kParameter); |
4072 root.handle.MarkPartiallyDependent(); | 4436 root.handle.MarkPartiallyDependent(); |
4073 | 4437 |
4074 // Groups are deleted, rebuild groups. | 4438 // Groups are deleted, rebuild groups. |
4075 { | 4439 { |
4076 HandleScope handle_scope(iso); | 4440 HandleScope handle_scope(iso); |
4077 g1s1.handle.MarkPartiallyDependent(); | 4441 g1s1.handle.MarkPartiallyDependent(); |
4078 g1s2.handle.MarkPartiallyDependent(); | 4442 g1s2.handle.MarkPartiallyDependent(); |
4079 g2s1.handle.MarkPartiallyDependent(); | 4443 g2s1.handle.MarkPartiallyDependent(); |
4080 g2s2.handle.MarkPartiallyDependent(); | 4444 g2s2.handle.MarkPartiallyDependent(); |
4081 g3s1.handle.MarkPartiallyDependent(); | 4445 g3s1.handle.MarkPartiallyDependent(); |
4082 g3s2.handle.MarkPartiallyDependent(); | 4446 g3s2.handle.MarkPartiallyDependent(); |
4083 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); | 4447 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); |
4084 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); | 4448 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); |
4085 Local<Object>::New(iso, g1s1.handle.As<Object>()) | 4449 Local<Object>::New(iso, g1s1.handle.As<Object>()) |
4086 ->Set(v8_str("x"), Local<Value>::New(iso, g2s1.handle)); | 4450 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g2s1.handle)) |
4451 .FromJust(); | |
4087 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); | 4452 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); |
4088 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); | 4453 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); |
4089 Local<Object>::New(iso, g2s1.handle.As<Object>()) | 4454 Local<Object>::New(iso, g2s1.handle.As<Object>()) |
4090 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); | 4455 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g3s1.handle)) |
4456 .FromJust(); | |
4091 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); | 4457 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); |
4092 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); | 4458 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); |
4093 Local<Object>::New(iso, g3s1.handle.As<Object>()) | 4459 Local<Object>::New(iso, g3s1.handle.As<Object>()) |
4094 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); | 4460 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g1s1.handle)) |
4461 .FromJust(); | |
4095 } | 4462 } |
4096 | 4463 |
4097 heap->CollectAllGarbage(); | 4464 heap->CollectAllGarbage(); |
4098 | 4465 |
4099 // All objects should be gone. 7 global handles in total. | 4466 // All objects should be gone. 7 global handles in total. |
4100 CHECK_EQ(7, counter.NumberOfWeakCalls()); | 4467 CHECK_EQ(7, counter.NumberOfWeakCalls()); |
4101 } | 4468 } |
4102 | 4469 |
4103 | 4470 |
4104 THREADED_TEST(ScriptException) { | 4471 THREADED_TEST(ScriptException) { |
4105 LocalContext env; | 4472 LocalContext env; |
4106 v8::HandleScope scope(env->GetIsolate()); | 4473 v8::HandleScope scope(env->GetIsolate()); |
4107 Local<Script> script = v8_compile("throw 'panama!';"); | 4474 Local<Script> script = v8_compile("throw 'panama!';"); |
4108 v8::TryCatch try_catch(env->GetIsolate()); | 4475 v8::TryCatch try_catch(env->GetIsolate()); |
4109 Local<Value> result = script->Run(); | 4476 v8::MaybeLocal<Value> result = script->Run(env.local()); |
4110 CHECK(result.IsEmpty()); | 4477 CHECK(result.IsEmpty()); |
4111 CHECK(try_catch.HasCaught()); | 4478 CHECK(try_catch.HasCaught()); |
4112 String::Utf8Value exception_value(try_catch.Exception()); | 4479 String::Utf8Value exception_value(try_catch.Exception()); |
4113 CHECK_EQ(0, strcmp(*exception_value, "panama!")); | 4480 CHECK_EQ(0, strcmp(*exception_value, "panama!")); |
4114 } | 4481 } |
4115 | 4482 |
4116 | 4483 |
4117 TEST(TryCatchCustomException) { | 4484 TEST(TryCatchCustomException) { |
4118 LocalContext env; | 4485 LocalContext env; |
4119 v8::Isolate* isolate = env->GetIsolate(); | 4486 v8::Isolate* isolate = env->GetIsolate(); |
4120 v8::HandleScope scope(isolate); | 4487 v8::HandleScope scope(isolate); |
4121 v8::TryCatch try_catch(isolate); | 4488 v8::TryCatch try_catch(isolate); |
4122 CompileRun( | 4489 CompileRun( |
4123 "function CustomError() { this.a = 'b'; }" | 4490 "function CustomError() { this.a = 'b'; }" |
4124 "(function f() { throw new CustomError(); })();"); | 4491 "(function f() { throw new CustomError(); })();"); |
4125 CHECK(try_catch.HasCaught()); | 4492 CHECK(try_catch.HasCaught()); |
4126 CHECK(try_catch.Exception() | 4493 CHECK(try_catch.Exception() |
4127 ->ToObject(isolate) | 4494 ->ToObject(env.local()) |
4128 ->Get(v8_str("a")) | 4495 .ToLocalChecked() |
4129 ->Equals(v8_str("b"))); | 4496 ->Get(env.local(), v8_str("a")) |
4497 .ToLocalChecked() | |
4498 ->Equals(env.local(), v8_str("b")) | |
4499 .FromJust()); | |
4130 } | 4500 } |
4131 | 4501 |
4132 | 4502 |
4133 bool message_received; | 4503 bool message_received; |
4134 | 4504 |
4135 | 4505 |
4136 static void check_message_0(v8::Handle<v8::Message> message, | 4506 static void check_message_0(v8::Local<v8::Message> message, |
4137 v8::Handle<Value> data) { | 4507 v8::Local<Value> data) { |
4138 CHECK_EQ(5.76, data->NumberValue()); | 4508 CHECK_EQ(5.76, data->NumberValue(CcTest::isolate()->GetCurrentContext()) |
4139 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); | 4509 .FromJust()); |
4510 CHECK_EQ(6.75, message->GetScriptOrigin() | |
4511 .ResourceName() | |
4512 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4513 .FromJust()); | |
4140 CHECK(!message->IsSharedCrossOrigin()); | 4514 CHECK(!message->IsSharedCrossOrigin()); |
4141 message_received = true; | 4515 message_received = true; |
4142 } | 4516 } |
4143 | 4517 |
4144 | 4518 |
4145 THREADED_TEST(MessageHandler0) { | 4519 THREADED_TEST(MessageHandler0) { |
4146 message_received = false; | 4520 message_received = false; |
4147 v8::HandleScope scope(CcTest::isolate()); | 4521 v8::HandleScope scope(CcTest::isolate()); |
4148 CHECK(!message_received); | 4522 CHECK(!message_received); |
4149 LocalContext context; | 4523 LocalContext context; |
4150 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); | 4524 CcTest::isolate()->AddMessageListener(check_message_0, v8_num(5.76)); |
4151 v8::Handle<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75"); | 4525 v8::Local<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75"); |
4152 script->Run(); | 4526 CHECK(script->Run(context.local()).IsEmpty()); |
4153 CHECK(message_received); | 4527 CHECK(message_received); |
4154 // clear out the message listener | 4528 // clear out the message listener |
4155 v8::V8::RemoveMessageListeners(check_message_0); | 4529 CcTest::isolate()->RemoveMessageListeners(check_message_0); |
4156 } | 4530 } |
4157 | 4531 |
4158 | 4532 |
4159 static void check_message_1(v8::Handle<v8::Message> message, | 4533 static void check_message_1(v8::Local<v8::Message> message, |
4160 v8::Handle<Value> data) { | 4534 v8::Local<Value> data) { |
4161 CHECK(data->IsNumber()); | 4535 CHECK(data->IsNumber()); |
4162 CHECK_EQ(1337, data->Int32Value()); | 4536 CHECK_EQ(1337, |
4537 data->Int32Value(CcTest::isolate()->GetCurrentContext()).FromJust()); | |
4163 CHECK(!message->IsSharedCrossOrigin()); | 4538 CHECK(!message->IsSharedCrossOrigin()); |
4164 message_received = true; | 4539 message_received = true; |
4165 } | 4540 } |
4166 | 4541 |
4167 | 4542 |
4168 TEST(MessageHandler1) { | 4543 TEST(MessageHandler1) { |
4169 message_received = false; | 4544 message_received = false; |
4170 v8::HandleScope scope(CcTest::isolate()); | 4545 v8::HandleScope scope(CcTest::isolate()); |
4171 CHECK(!message_received); | 4546 CHECK(!message_received); |
4172 v8::V8::AddMessageListener(check_message_1); | 4547 CcTest::isolate()->AddMessageListener(check_message_1); |
4173 LocalContext context; | 4548 LocalContext context; |
4174 CompileRun("throw 1337;"); | 4549 CompileRun("throw 1337;"); |
4175 CHECK(message_received); | 4550 CHECK(message_received); |
4176 // clear out the message listener | 4551 // clear out the message listener |
4177 v8::V8::RemoveMessageListeners(check_message_1); | 4552 CcTest::isolate()->RemoveMessageListeners(check_message_1); |
4178 } | 4553 } |
4179 | 4554 |
4180 | 4555 |
4181 static void check_message_2(v8::Handle<v8::Message> message, | 4556 static void check_message_2(v8::Local<v8::Message> message, |
4182 v8::Handle<Value> data) { | 4557 v8::Local<Value> data) { |
4183 LocalContext context; | 4558 LocalContext context; |
4184 CHECK(data->IsObject()); | 4559 CHECK(data->IsObject()); |
4185 v8::Local<v8::Value> hidden_property = | 4560 v8::Local<v8::Value> hidden_property = |
4186 v8::Object::Cast(*data) | 4561 v8::Object::Cast(*data) |
4187 ->GetPrivate( | 4562 ->GetPrivate( |
4188 context.local(), | 4563 context.local(), |
4189 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key"))) | 4564 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key"))) |
4190 .ToLocalChecked(); | 4565 .ToLocalChecked(); |
4191 CHECK(v8_str("hidden value")->Equals(hidden_property)); | 4566 CHECK(v8_str("hidden value") |
4567 ->Equals(context.local(), hidden_property) | |
4568 .FromJust()); | |
4192 CHECK(!message->IsSharedCrossOrigin()); | 4569 CHECK(!message->IsSharedCrossOrigin()); |
4193 message_received = true; | 4570 message_received = true; |
4194 } | 4571 } |
4195 | 4572 |
4196 | 4573 |
4197 TEST(MessageHandler2) { | 4574 TEST(MessageHandler2) { |
4198 message_received = false; | 4575 message_received = false; |
4199 v8::HandleScope scope(CcTest::isolate()); | 4576 v8::HandleScope scope(CcTest::isolate()); |
4200 CHECK(!message_received); | 4577 CHECK(!message_received); |
4201 v8::V8::AddMessageListener(check_message_2); | 4578 CcTest::isolate()->AddMessageListener(check_message_2); |
4202 LocalContext context; | 4579 LocalContext context; |
4203 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); | 4580 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); |
4204 v8::Object::Cast(*error) | 4581 v8::Object::Cast(*error) |
4205 ->SetPrivate(context.local(), | 4582 ->SetPrivate(context.local(), |
4206 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")), | 4583 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")), |
4207 v8_str("hidden value")) | 4584 v8_str("hidden value")) |
4208 .FromJust(); | 4585 .FromJust(); |
4209 context->Global()->Set(v8_str("error"), error); | 4586 CHECK(context->Global() |
4587 ->Set(context.local(), v8_str("error"), error) | |
4588 .FromJust()); | |
4210 CompileRun("throw error;"); | 4589 CompileRun("throw error;"); |
4211 CHECK(message_received); | 4590 CHECK(message_received); |
4212 // clear out the message listener | 4591 // clear out the message listener |
4213 v8::V8::RemoveMessageListeners(check_message_2); | 4592 CcTest::isolate()->RemoveMessageListeners(check_message_2); |
4214 } | 4593 } |
4215 | 4594 |
4216 | 4595 |
4217 static void check_message_3(v8::Handle<v8::Message> message, | 4596 static void check_message_3(v8::Local<v8::Message> message, |
4218 v8::Handle<Value> data) { | 4597 v8::Local<Value> data) { |
4219 CHECK(message->IsSharedCrossOrigin()); | 4598 CHECK(message->IsSharedCrossOrigin()); |
4220 CHECK(message->GetScriptOrigin().Options().IsSharedCrossOrigin()); | 4599 CHECK(message->GetScriptOrigin().Options().IsSharedCrossOrigin()); |
4221 CHECK(message->GetScriptOrigin().Options().IsEmbedderDebugScript()); | 4600 CHECK(message->GetScriptOrigin().Options().IsEmbedderDebugScript()); |
4222 CHECK(message->GetScriptOrigin().Options().IsOpaque()); | 4601 CHECK(message->GetScriptOrigin().Options().IsOpaque()); |
4223 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); | 4602 CHECK_EQ(6.75, message->GetScriptOrigin() |
4224 CHECK_EQ(7.40, message->GetScriptOrigin().SourceMapUrl()->NumberValue()); | 4603 .ResourceName() |
4604 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4605 .FromJust()); | |
4606 CHECK_EQ(7.40, message->GetScriptOrigin() | |
4607 .SourceMapUrl() | |
4608 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4609 .FromJust()); | |
4225 message_received = true; | 4610 message_received = true; |
4226 } | 4611 } |
4227 | 4612 |
4228 | 4613 |
4229 TEST(MessageHandler3) { | 4614 TEST(MessageHandler3) { |
4230 message_received = false; | 4615 message_received = false; |
4231 v8::Isolate* isolate = CcTest::isolate(); | 4616 v8::Isolate* isolate = CcTest::isolate(); |
4232 v8::HandleScope scope(isolate); | 4617 v8::HandleScope scope(isolate); |
4233 CHECK(!message_received); | 4618 CHECK(!message_received); |
4234 v8::V8::AddMessageListener(check_message_3); | 4619 isolate->AddMessageListener(check_message_3); |
4235 LocalContext context; | 4620 LocalContext context; |
4236 v8::ScriptOrigin origin = v8::ScriptOrigin( | 4621 v8::ScriptOrigin origin = v8::ScriptOrigin( |
4237 v8_str("6.75"), v8::Integer::New(isolate, 1), | 4622 v8_str("6.75"), v8::Integer::New(isolate, 1), |
4238 v8::Integer::New(isolate, 2), v8::True(isolate), Handle<v8::Integer>(), | 4623 v8::Integer::New(isolate, 2), v8::True(isolate), Local<v8::Integer>(), |
4239 v8::True(isolate), v8_str("7.40"), v8::True(isolate)); | 4624 v8::True(isolate), v8_str("7.40"), v8::True(isolate)); |
4240 v8::Handle<v8::Script> script = | 4625 v8::Local<v8::Script> script = |
4241 Script::Compile(v8_str("throw 'error'"), &origin); | 4626 Script::Compile(context.local(), v8_str("throw 'error'"), &origin) |
4242 script->Run(); | 4627 .ToLocalChecked(); |
4628 CHECK(script->Run(context.local()).IsEmpty()); | |
4243 CHECK(message_received); | 4629 CHECK(message_received); |
4244 // clear out the message listener | 4630 // clear out the message listener |
4245 v8::V8::RemoveMessageListeners(check_message_3); | 4631 isolate->RemoveMessageListeners(check_message_3); |
4246 } | 4632 } |
4247 | 4633 |
4248 | 4634 |
4249 static void check_message_4(v8::Handle<v8::Message> message, | 4635 static void check_message_4(v8::Local<v8::Message> message, |
4250 v8::Handle<Value> data) { | 4636 v8::Local<Value> data) { |
4251 CHECK(!message->IsSharedCrossOrigin()); | 4637 CHECK(!message->IsSharedCrossOrigin()); |
4252 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); | 4638 CHECK_EQ(6.75, message->GetScriptOrigin() |
4639 .ResourceName() | |
4640 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4641 .FromJust()); | |
4253 message_received = true; | 4642 message_received = true; |
4254 } | 4643 } |
4255 | 4644 |
4256 | 4645 |
4257 TEST(MessageHandler4) { | 4646 TEST(MessageHandler4) { |
4258 message_received = false; | 4647 message_received = false; |
4259 v8::Isolate* isolate = CcTest::isolate(); | 4648 v8::Isolate* isolate = CcTest::isolate(); |
4260 v8::HandleScope scope(isolate); | 4649 v8::HandleScope scope(isolate); |
4261 CHECK(!message_received); | 4650 CHECK(!message_received); |
4262 v8::V8::AddMessageListener(check_message_4); | 4651 isolate->AddMessageListener(check_message_4); |
4263 LocalContext context; | 4652 LocalContext context; |
4264 v8::ScriptOrigin origin = | 4653 v8::ScriptOrigin origin = |
4265 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), | 4654 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), |
4266 v8::Integer::New(isolate, 2), v8::False(isolate)); | 4655 v8::Integer::New(isolate, 2), v8::False(isolate)); |
4267 v8::Handle<v8::Script> script = | 4656 v8::Local<v8::Script> script = |
4268 Script::Compile(v8_str("throw 'error'"), &origin); | 4657 Script::Compile(context.local(), v8_str("throw 'error'"), &origin) |
4269 script->Run(); | 4658 .ToLocalChecked(); |
4659 CHECK(script->Run(context.local()).IsEmpty()); | |
4270 CHECK(message_received); | 4660 CHECK(message_received); |
4271 // clear out the message listener | 4661 // clear out the message listener |
4272 v8::V8::RemoveMessageListeners(check_message_4); | 4662 isolate->RemoveMessageListeners(check_message_4); |
4273 } | 4663 } |
4274 | 4664 |
4275 | 4665 |
4276 static void check_message_5a(v8::Handle<v8::Message> message, | 4666 static void check_message_5a(v8::Local<v8::Message> message, |
4277 v8::Handle<Value> data) { | 4667 v8::Local<Value> data) { |
4278 CHECK(message->IsSharedCrossOrigin()); | 4668 CHECK(message->IsSharedCrossOrigin()); |
4279 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); | 4669 CHECK_EQ(6.75, message->GetScriptOrigin() |
4670 .ResourceName() | |
4671 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4672 .FromJust()); | |
4280 message_received = true; | 4673 message_received = true; |
4281 } | 4674 } |
4282 | 4675 |
4283 | 4676 |
4284 static void check_message_5b(v8::Handle<v8::Message> message, | 4677 static void check_message_5b(v8::Local<v8::Message> message, |
4285 v8::Handle<Value> data) { | 4678 v8::Local<Value> data) { |
4286 CHECK(!message->IsSharedCrossOrigin()); | 4679 CHECK(!message->IsSharedCrossOrigin()); |
4287 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); | 4680 CHECK_EQ(6.75, message->GetScriptOrigin() |
4681 .ResourceName() | |
4682 ->NumberValue(CcTest::isolate()->GetCurrentContext()) | |
4683 .FromJust()); | |
4288 message_received = true; | 4684 message_received = true; |
4289 } | 4685 } |
4290 | 4686 |
4291 | 4687 |
4292 TEST(MessageHandler5) { | 4688 TEST(MessageHandler5) { |
4293 message_received = false; | 4689 message_received = false; |
4294 v8::Isolate* isolate = CcTest::isolate(); | 4690 v8::Isolate* isolate = CcTest::isolate(); |
4295 v8::HandleScope scope(isolate); | 4691 v8::HandleScope scope(isolate); |
4296 CHECK(!message_received); | 4692 CHECK(!message_received); |
4297 v8::V8::AddMessageListener(check_message_5a); | 4693 isolate->AddMessageListener(check_message_5a); |
4298 LocalContext context; | 4694 LocalContext context; |
4299 v8::ScriptOrigin origin1 = | 4695 v8::ScriptOrigin origin1 = |
4300 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), | 4696 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), |
4301 v8::Integer::New(isolate, 2), v8::True(isolate)); | 4697 v8::Integer::New(isolate, 2), v8::True(isolate)); |
4302 v8::Handle<v8::Script> script = | 4698 v8::Local<v8::Script> script = |
4303 Script::Compile(v8_str("throw 'error'"), &origin1); | 4699 Script::Compile(context.local(), v8_str("throw 'error'"), &origin1) |
4304 script->Run(); | 4700 .ToLocalChecked(); |
4701 CHECK(script->Run(context.local()).IsEmpty()); | |
4305 CHECK(message_received); | 4702 CHECK(message_received); |
4306 // clear out the message listener | 4703 // clear out the message listener |
4307 v8::V8::RemoveMessageListeners(check_message_5a); | 4704 isolate->RemoveMessageListeners(check_message_5a); |
4308 | 4705 |
4309 message_received = false; | 4706 message_received = false; |
4310 v8::V8::AddMessageListener(check_message_5b); | 4707 isolate->AddMessageListener(check_message_5b); |
4311 v8::ScriptOrigin origin2 = | 4708 v8::ScriptOrigin origin2 = |
4312 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), | 4709 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), |
4313 v8::Integer::New(isolate, 2), v8::False(isolate)); | 4710 v8::Integer::New(isolate, 2), v8::False(isolate)); |
4314 script = Script::Compile(v8_str("throw 'error'"), &origin2); | 4711 script = Script::Compile(context.local(), v8_str("throw 'error'"), &origin2) |
4315 script->Run(); | 4712 .ToLocalChecked(); |
4713 CHECK(script->Run(context.local()).IsEmpty()); | |
4316 CHECK(message_received); | 4714 CHECK(message_received); |
4317 // clear out the message listener | 4715 // clear out the message listener |
4318 v8::V8::RemoveMessageListeners(check_message_5b); | 4716 isolate->RemoveMessageListeners(check_message_5b); |
4319 } | 4717 } |
4320 | 4718 |
4321 | 4719 |
4322 TEST(NativeWeakMap) { | 4720 TEST(NativeWeakMap) { |
4323 v8::Isolate* isolate = CcTest::isolate(); | 4721 v8::Isolate* isolate = CcTest::isolate(); |
4324 HandleScope scope(isolate); | 4722 HandleScope scope(isolate); |
4325 Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate)); | 4723 Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate)); |
4326 CHECK(!weak_map.IsEmpty()); | 4724 CHECK(!weak_map.IsEmpty()); |
4327 | 4725 |
4328 LocalContext env; | 4726 LocalContext env; |
4329 Local<Object> value = v8::Object::New(isolate); | 4727 Local<Object> value = v8::Object::New(isolate); |
4330 | 4728 |
4331 Local<Object> local1 = v8::Object::New(isolate); | 4729 Local<Object> local1 = v8::Object::New(isolate); |
4332 CHECK(!weak_map->Has(local1)); | 4730 CHECK(!weak_map->Has(local1)); |
4333 CHECK(weak_map->Get(local1)->IsUndefined()); | 4731 CHECK(weak_map->Get(local1)->IsUndefined()); |
4334 weak_map->Set(local1, value); | 4732 weak_map->Set(local1, value); |
4335 CHECK(weak_map->Has(local1)); | 4733 CHECK(weak_map->Has(local1)); |
4336 CHECK(value->Equals(weak_map->Get(local1))); | 4734 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust()); |
4337 | 4735 |
4338 WeakCallCounter counter(1234); | 4736 WeakCallCounter counter(1234); |
4339 WeakCallCounterAndPersistent<Value> o1(&counter); | 4737 WeakCallCounterAndPersistent<Value> o1(&counter); |
4340 WeakCallCounterAndPersistent<Value> o2(&counter); | 4738 WeakCallCounterAndPersistent<Value> o2(&counter); |
4341 WeakCallCounterAndPersistent<Value> s1(&counter); | 4739 WeakCallCounterAndPersistent<Value> s1(&counter); |
4342 { | 4740 { |
4343 HandleScope scope(isolate); | 4741 HandleScope scope(isolate); |
4344 Local<v8::Object> obj1 = v8::Object::New(isolate); | 4742 Local<v8::Object> obj1 = v8::Object::New(isolate); |
4345 Local<v8::Object> obj2 = v8::Object::New(isolate); | 4743 Local<v8::Object> obj2 = v8::Object::New(isolate); |
4346 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); | 4744 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); |
4347 | 4745 |
4348 weak_map->Set(obj1, value); | 4746 weak_map->Set(obj1, value); |
4349 weak_map->Set(obj2, value); | 4747 weak_map->Set(obj2, value); |
4350 weak_map->Set(sym1, value); | 4748 weak_map->Set(sym1, value); |
4351 | 4749 |
4352 o1.handle.Reset(isolate, obj1); | 4750 o1.handle.Reset(isolate, obj1); |
4353 o2.handle.Reset(isolate, obj2); | 4751 o2.handle.Reset(isolate, obj2); |
4354 s1.handle.Reset(isolate, sym1); | 4752 s1.handle.Reset(isolate, sym1); |
4355 | 4753 |
4356 CHECK(weak_map->Has(local1)); | 4754 CHECK(weak_map->Has(local1)); |
4357 CHECK(weak_map->Has(obj1)); | 4755 CHECK(weak_map->Has(obj1)); |
4358 CHECK(weak_map->Has(obj2)); | 4756 CHECK(weak_map->Has(obj2)); |
4359 CHECK(weak_map->Has(sym1)); | 4757 CHECK(weak_map->Has(sym1)); |
4360 | 4758 |
4361 CHECK(value->Equals(weak_map->Get(local1))); | 4759 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust()); |
4362 CHECK(value->Equals(weak_map->Get(obj1))); | 4760 CHECK(value->Equals(env.local(), weak_map->Get(obj1)).FromJust()); |
4363 CHECK(value->Equals(weak_map->Get(obj2))); | 4761 CHECK(value->Equals(env.local(), weak_map->Get(obj2)).FromJust()); |
4364 CHECK(value->Equals(weak_map->Get(sym1))); | 4762 CHECK(value->Equals(env.local(), weak_map->Get(sym1)).FromJust()); |
4365 } | 4763 } |
4366 CcTest::heap()->CollectAllGarbage(); | 4764 CcTest::heap()->CollectAllGarbage(); |
4367 { | 4765 { |
4368 HandleScope scope(isolate); | 4766 HandleScope scope(isolate); |
4369 CHECK(value->Equals(weak_map->Get(local1))); | 4767 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust()); |
4370 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); | 4768 CHECK(value->Equals(env.local(), |
4371 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); | 4769 weak_map->Get(Local<Value>::New(isolate, o1.handle))) |
4372 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); | 4770 .FromJust()); |
4771 CHECK(value->Equals(env.local(), | |
4772 weak_map->Get(Local<Value>::New(isolate, o2.handle))) | |
4773 .FromJust()); | |
4774 CHECK(value->Equals(env.local(), | |
4775 weak_map->Get(Local<Value>::New(isolate, s1.handle))) | |
4776 .FromJust()); | |
4373 } | 4777 } |
4374 | 4778 |
4375 o1.handle.SetWeak(&o1, &WeakPointerCallback, | 4779 o1.handle.SetWeak(&o1, &WeakPointerCallback, |
4376 v8::WeakCallbackType::kParameter); | 4780 v8::WeakCallbackType::kParameter); |
4377 o2.handle.SetWeak(&o2, &WeakPointerCallback, | 4781 o2.handle.SetWeak(&o2, &WeakPointerCallback, |
4378 v8::WeakCallbackType::kParameter); | 4782 v8::WeakCallbackType::kParameter); |
4379 s1.handle.SetWeak(&s1, &WeakPointerCallback, | 4783 s1.handle.SetWeak(&s1, &WeakPointerCallback, |
4380 v8::WeakCallbackType::kParameter); | 4784 v8::WeakCallbackType::kParameter); |
4381 | 4785 |
4382 CcTest::heap()->CollectAllGarbage(); | 4786 CcTest::heap()->CollectAllGarbage(); |
4383 CHECK_EQ(3, counter.NumberOfWeakCalls()); | 4787 CHECK_EQ(3, counter.NumberOfWeakCalls()); |
4384 | 4788 |
4385 CHECK(o1.handle.IsEmpty()); | 4789 CHECK(o1.handle.IsEmpty()); |
4386 CHECK(o2.handle.IsEmpty()); | 4790 CHECK(o2.handle.IsEmpty()); |
4387 CHECK(s1.handle.IsEmpty()); | 4791 CHECK(s1.handle.IsEmpty()); |
4388 | 4792 |
4389 CHECK(value->Equals(weak_map->Get(local1))); | 4793 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust()); |
4390 CHECK(weak_map->Delete(local1)); | 4794 CHECK(weak_map->Delete(local1)); |
4391 CHECK(!weak_map->Has(local1)); | 4795 CHECK(!weak_map->Has(local1)); |
4392 CHECK(weak_map->Get(local1)->IsUndefined()); | 4796 CHECK(weak_map->Get(local1)->IsUndefined()); |
4393 } | 4797 } |
4394 | 4798 |
4395 | 4799 |
4396 THREADED_TEST(GetSetProperty) { | 4800 THREADED_TEST(GetSetProperty) { |
4397 LocalContext context; | 4801 LocalContext context; |
4398 v8::Isolate* isolate = context->GetIsolate(); | 4802 v8::Isolate* isolate = context->GetIsolate(); |
4399 v8::HandleScope scope(isolate); | 4803 v8::HandleScope scope(isolate); |
4400 context->Global()->Set(v8_str("foo"), v8_num(14)); | 4804 CHECK(context->Global() |
4401 context->Global()->Set(v8_str("12"), v8_num(92)); | 4805 ->Set(context.local(), v8_str("foo"), v8_num(14)) |
4402 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); | 4806 .FromJust()); |
4403 context->Global()->Set(v8_num(13), v8_num(56)); | 4807 CHECK(context->Global() |
4808 ->Set(context.local(), v8_str("12"), v8_num(92)) | |
4809 .FromJust()); | |
4810 CHECK(context->Global() | |
4811 ->Set(context.local(), v8::Integer::New(isolate, 16), v8_num(32)) | |
4812 .FromJust()); | |
4813 CHECK(context->Global() | |
4814 ->Set(context.local(), v8_num(13), v8_num(56)) | |
4815 .FromJust()); | |
4404 Local<Value> foo = CompileRun("this.foo"); | 4816 Local<Value> foo = CompileRun("this.foo"); |
4405 CHECK_EQ(14, foo->Int32Value()); | 4817 CHECK_EQ(14, foo->Int32Value(context.local()).FromJust()); |
4406 Local<Value> twelve = CompileRun("this[12]"); | 4818 Local<Value> twelve = CompileRun("this[12]"); |
4407 CHECK_EQ(92, twelve->Int32Value()); | 4819 CHECK_EQ(92, twelve->Int32Value(context.local()).FromJust()); |
4408 Local<Value> sixteen = CompileRun("this[16]"); | 4820 Local<Value> sixteen = CompileRun("this[16]"); |
4409 CHECK_EQ(32, sixteen->Int32Value()); | 4821 CHECK_EQ(32, sixteen->Int32Value(context.local()).FromJust()); |
4410 Local<Value> thirteen = CompileRun("this[13]"); | 4822 Local<Value> thirteen = CompileRun("this[13]"); |
4411 CHECK_EQ(56, thirteen->Int32Value()); | 4823 CHECK_EQ(56, thirteen->Int32Value(context.local()).FromJust()); |
4412 CHECK_EQ(92, | 4824 CHECK_EQ(92, context->Global() |
4413 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value()); | 4825 ->Get(context.local(), v8::Integer::New(isolate, 12)) |
4414 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); | 4826 .ToLocalChecked() |
4415 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); | 4827 ->Int32Value(context.local()) |
4416 CHECK_EQ(32, | 4828 .FromJust()); |
4417 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value()); | 4829 CHECK_EQ(92, context->Global() |
4418 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); | 4830 ->Get(context.local(), v8_str("12")) |
4419 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); | 4831 .ToLocalChecked() |
4420 CHECK_EQ(56, | 4832 ->Int32Value(context.local()) |
4421 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value()); | 4833 .FromJust()); |
4422 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); | 4834 CHECK_EQ(92, context->Global() |
4423 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); | 4835 ->Get(context.local(), v8_num(12)) |
4836 .ToLocalChecked() | |
4837 ->Int32Value(context.local()) | |
4838 .FromJust()); | |
4839 CHECK_EQ(32, context->Global() | |
4840 ->Get(context.local(), v8::Integer::New(isolate, 16)) | |
4841 .ToLocalChecked() | |
4842 ->Int32Value(context.local()) | |
4843 .FromJust()); | |
4844 CHECK_EQ(32, context->Global() | |
4845 ->Get(context.local(), v8_str("16")) | |
4846 .ToLocalChecked() | |
4847 ->Int32Value(context.local()) | |
4848 .FromJust()); | |
4849 CHECK_EQ(32, context->Global() | |
4850 ->Get(context.local(), v8_num(16)) | |
4851 .ToLocalChecked() | |
4852 ->Int32Value(context.local()) | |
4853 .FromJust()); | |
4854 CHECK_EQ(56, context->Global() | |
4855 ->Get(context.local(), v8::Integer::New(isolate, 13)) | |
4856 .ToLocalChecked() | |
4857 ->Int32Value(context.local()) | |
4858 .FromJust()); | |
4859 CHECK_EQ(56, context->Global() | |
4860 ->Get(context.local(), v8_str("13")) | |
4861 .ToLocalChecked() | |
4862 ->Int32Value(context.local()) | |
4863 .FromJust()); | |
4864 CHECK_EQ(56, context->Global() | |
4865 ->Get(context.local(), v8_num(13)) | |
4866 .ToLocalChecked() | |
4867 ->Int32Value(context.local()) | |
4868 .FromJust()); | |
4424 } | 4869 } |
4425 | 4870 |
4426 | 4871 |
4427 THREADED_TEST(PropertyAttributes) { | 4872 THREADED_TEST(PropertyAttributes) { |
4428 LocalContext context; | 4873 LocalContext context; |
4429 v8::HandleScope scope(context->GetIsolate()); | 4874 v8::HandleScope scope(context->GetIsolate()); |
4430 // none | 4875 // none |
4431 Local<String> prop = v8_str("none"); | 4876 Local<String> prop = v8_str("none"); |
4432 context->Global()->Set(prop, v8_num(7)); | 4877 CHECK(context->Global()->Set(context.local(), prop, v8_num(7)).FromJust()); |
4433 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); | 4878 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(), |
4879 prop).FromJust()); | |
4434 // read-only | 4880 // read-only |
4435 prop = v8_str("read_only"); | 4881 prop = v8_str("read_only"); |
4436 context->Global()->ForceSet(prop, v8_num(7), v8::ReadOnly); | 4882 context->Global()->ForceSet(context.local(), prop, v8_num(7), |
4437 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4883 v8::ReadOnly).FromJust(); |
4438 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); | 4884 CHECK_EQ(7, context->Global()->Get(context.local(), |
4885 prop).ToLocalChecked()->Int32Value(context.local()).FromJust()); | |
4886 CHECK_EQ(v8::ReadOnly, | |
4887 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust()); | |
4439 CompileRun("read_only = 9"); | 4888 CompileRun("read_only = 9"); |
4440 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4889 CHECK_EQ(7, context->Global()->Get(context.local(), |
4441 context->Global()->Set(prop, v8_num(10)); | 4890 prop).ToLocalChecked()->Int32Value(context.local()).FromJust()); |
4442 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); | 4891 CHECK(context->Global()->Set(context.local(), prop, v8_num(10)).FromJust()); |
4892 CHECK_EQ(7, context->Global()->Get(context.local(), | |
4893 prop).ToLocalChecked()->Int32Value(context.local()).FromJust()); | |
4443 // dont-delete | 4894 // dont-delete |
4444 prop = v8_str("dont_delete"); | 4895 prop = v8_str("dont_delete"); |
4445 context->Global()->ForceSet(prop, v8_num(13), v8::DontDelete); | 4896 context->Global()->ForceSet(context.local(), prop, v8_num(13), |
4446 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); | 4897 v8::DontDelete).FromJust(); |
4898 CHECK_EQ(13, context->Global()->Get(context.local(), | |
4899 prop).ToLocalChecked()->Int32Value(context.local()).FromJust()); | |
4447 CompileRun("delete dont_delete"); | 4900 CompileRun("delete dont_delete"); |
4448 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); | 4901 CHECK_EQ(13, context->Global()->Get(context.local(), |
4449 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); | 4902 prop).ToLocalChecked()->Int32Value(context.local()).FromJust()); |
4903 CHECK_EQ(v8::DontDelete, | |
4904 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust()); | |
4450 // dont-enum | 4905 // dont-enum |
4451 prop = v8_str("dont_enum"); | 4906 prop = v8_str("dont_enum"); |
4452 context->Global()->ForceSet(prop, v8_num(28), v8::DontEnum); | 4907 context->Global()->ForceSet(prop, v8_num(28), v8::DontEnum); |
4453 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); | 4908 CHECK_EQ(v8::DontEnum, |
4909 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust()); | |
4454 // absent | 4910 // absent |
4455 prop = v8_str("absent"); | 4911 prop = v8_str("absent"); |
4456 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); | 4912 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(), |
4913 prop).FromJust()); | |
4457 Local<Value> fake_prop = v8_num(1); | 4914 Local<Value> fake_prop = v8_num(1); |
4458 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(fake_prop)); | 4915 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(), |
4916 fake_prop).FromJust()); | |
4459 // exception | 4917 // exception |
4460 TryCatch try_catch(context->GetIsolate()); | 4918 TryCatch try_catch(context->GetIsolate()); |
4461 Local<Value> exception = | 4919 Local<Value> exception = |
4462 CompileRun("({ toString: function() { throw 'exception';} })"); | 4920 CompileRun("({ toString: function() { throw 'exception';} })"); |
4463 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(exception)); | 4921 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(), |
4922 exception).FromJust()); | |
4464 CHECK(try_catch.HasCaught()); | 4923 CHECK(try_catch.HasCaught()); |
4465 String::Utf8Value exception_value(try_catch.Exception()); | 4924 String::Utf8Value exception_value(try_catch.Exception()); |
4466 CHECK_EQ(0, strcmp("exception", *exception_value)); | 4925 CHECK_EQ(0, strcmp("exception", *exception_value)); |
4467 try_catch.Reset(); | 4926 try_catch.Reset(); |
4468 } | 4927 } |
4469 | 4928 |
4470 | 4929 |
4471 THREADED_TEST(Array) { | 4930 THREADED_TEST(Array) { |
4472 LocalContext context; | 4931 LocalContext context; |
4473 v8::HandleScope scope(context->GetIsolate()); | 4932 v8::HandleScope scope(context->GetIsolate()); |
4474 Local<v8::Array> array = v8::Array::New(context->GetIsolate()); | 4933 Local<v8::Array> array = v8::Array::New(context->GetIsolate()); |
4475 CHECK_EQ(0u, array->Length()); | 4934 CHECK_EQ(0u, array->Length()); |
4476 CHECK(array->Get(0)->IsUndefined()); | 4935 CHECK(array->Get(context.local(), 0).ToLocalChecked()->IsUndefined()); |
4477 CHECK(!array->Has(0)); | 4936 CHECK(!array->Has(context.local(), 0).FromJust()); |
4478 CHECK(array->Get(100)->IsUndefined()); | 4937 CHECK(array->Get(context.local(), 100).ToLocalChecked()->IsUndefined()); |
4479 CHECK(!array->Has(100)); | 4938 CHECK(!array->Has(context.local(), 100).FromJust()); |
4480 array->Set(2, v8_num(7)); | 4939 CHECK(array->Set(context.local(), 2, v8_num(7)).FromJust()); |
4481 CHECK_EQ(3u, array->Length()); | 4940 CHECK_EQ(3u, array->Length()); |
4482 CHECK(!array->Has(0)); | 4941 CHECK(!array->Has(context.local(), 0).FromJust()); |
4483 CHECK(!array->Has(1)); | 4942 CHECK(!array->Has(context.local(), 1).FromJust()); |
4484 CHECK(array->Has(2)); | 4943 CHECK(array->Has(context.local(), 2).FromJust()); |
4485 CHECK_EQ(7, array->Get(2)->Int32Value()); | 4944 CHECK_EQ(7, array->Get(context.local(), 2) |
4945 .ToLocalChecked() | |
4946 ->Int32Value(context.local()) | |
4947 .FromJust()); | |
4486 Local<Value> obj = CompileRun("[1, 2, 3]"); | 4948 Local<Value> obj = CompileRun("[1, 2, 3]"); |
4487 Local<v8::Array> arr = obj.As<v8::Array>(); | 4949 Local<v8::Array> arr = obj.As<v8::Array>(); |
4488 CHECK_EQ(3u, arr->Length()); | 4950 CHECK_EQ(3u, arr->Length()); |
4489 CHECK_EQ(1, arr->Get(0)->Int32Value()); | 4951 CHECK_EQ(1, arr->Get(context.local(), 0) |
4490 CHECK_EQ(2, arr->Get(1)->Int32Value()); | 4952 .ToLocalChecked() |
4491 CHECK_EQ(3, arr->Get(2)->Int32Value()); | 4953 ->Int32Value(context.local()) |
4954 .FromJust()); | |
4955 CHECK_EQ(2, arr->Get(context.local(), 1) | |
4956 .ToLocalChecked() | |
4957 ->Int32Value(context.local()) | |
4958 .FromJust()); | |
4959 CHECK_EQ(3, arr->Get(context.local(), 2) | |
4960 .ToLocalChecked() | |
4961 ->Int32Value(context.local()) | |
4962 .FromJust()); | |
4492 array = v8::Array::New(context->GetIsolate(), 27); | 4963 array = v8::Array::New(context->GetIsolate(), 27); |
4493 CHECK_EQ(27u, array->Length()); | 4964 CHECK_EQ(27u, array->Length()); |
4494 array = v8::Array::New(context->GetIsolate(), -27); | 4965 array = v8::Array::New(context->GetIsolate(), -27); |
4495 CHECK_EQ(0u, array->Length()); | 4966 CHECK_EQ(0u, array->Length()); |
4496 } | 4967 } |
4497 | 4968 |
4498 | 4969 |
4499 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) { | 4970 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) { |
4500 v8::EscapableHandleScope scope(args.GetIsolate()); | 4971 v8::EscapableHandleScope scope(args.GetIsolate()); |
4501 ApiTestFuzzer::Fuzz(); | 4972 ApiTestFuzzer::Fuzz(); |
4502 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); | 4973 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); |
4503 for (int i = 0; i < args.Length(); i++) result->Set(i, args[i]); | 4974 for (int i = 0; i < args.Length(); i++) { |
4975 CHECK(result->Set(CcTest::isolate()->GetCurrentContext(), i, args[i]) | |
4976 .FromJust()); | |
4977 } | |
4504 args.GetReturnValue().Set(scope.Escape(result)); | 4978 args.GetReturnValue().Set(scope.Escape(result)); |
4505 } | 4979 } |
4506 | 4980 |
4507 | 4981 |
4508 THREADED_TEST(Vector) { | 4982 THREADED_TEST(Vector) { |
4509 v8::Isolate* isolate = CcTest::isolate(); | 4983 v8::Isolate* isolate = CcTest::isolate(); |
4510 v8::HandleScope scope(isolate); | 4984 v8::HandleScope scope(isolate); |
4511 Local<ObjectTemplate> global = ObjectTemplate::New(isolate); | 4985 Local<ObjectTemplate> global = ObjectTemplate::New(isolate); |
4512 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); | 4986 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); |
4513 LocalContext context(0, global); | 4987 LocalContext context(0, global); |
4514 | 4988 |
4515 const char* fun = "f()"; | 4989 const char* fun = "f()"; |
4516 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); | 4990 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); |
4517 CHECK_EQ(0u, a0->Length()); | 4991 CHECK_EQ(0u, a0->Length()); |
4518 | 4992 |
4519 const char* fun2 = "f(11)"; | 4993 const char* fun2 = "f(11)"; |
4520 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); | 4994 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); |
4521 CHECK_EQ(1u, a1->Length()); | 4995 CHECK_EQ(1u, a1->Length()); |
4522 CHECK_EQ(11, a1->Get(0)->Int32Value()); | 4996 CHECK_EQ(11, a1->Get(context.local(), 0) |
4997 .ToLocalChecked() | |
4998 ->Int32Value(context.local()) | |
4999 .FromJust()); | |
4523 | 5000 |
4524 const char* fun3 = "f(12, 13)"; | 5001 const char* fun3 = "f(12, 13)"; |
4525 Local<v8::Array> a2 = CompileRun(fun3).As<v8::Array>(); | 5002 Local<v8::Array> a2 = CompileRun(fun3).As<v8::Array>(); |
4526 CHECK_EQ(2u, a2->Length()); | 5003 CHECK_EQ(2u, a2->Length()); |
4527 CHECK_EQ(12, a2->Get(0)->Int32Value()); | 5004 CHECK_EQ(12, a2->Get(context.local(), 0) |
4528 CHECK_EQ(13, a2->Get(1)->Int32Value()); | 5005 .ToLocalChecked() |
5006 ->Int32Value(context.local()) | |
5007 .FromJust()); | |
5008 CHECK_EQ(13, a2->Get(context.local(), 1) | |
5009 .ToLocalChecked() | |
5010 ->Int32Value(context.local()) | |
5011 .FromJust()); | |
4529 | 5012 |
4530 const char* fun4 = "f(14, 15, 16)"; | 5013 const char* fun4 = "f(14, 15, 16)"; |
4531 Local<v8::Array> a3 = CompileRun(fun4).As<v8::Array>(); | 5014 Local<v8::Array> a3 = CompileRun(fun4).As<v8::Array>(); |
4532 CHECK_EQ(3u, a3->Length()); | 5015 CHECK_EQ(3u, a3->Length()); |
4533 CHECK_EQ(14, a3->Get(0)->Int32Value()); | 5016 CHECK_EQ(14, a3->Get(context.local(), 0) |
4534 CHECK_EQ(15, a3->Get(1)->Int32Value()); | 5017 .ToLocalChecked() |
4535 CHECK_EQ(16, a3->Get(2)->Int32Value()); | 5018 ->Int32Value(context.local()) |
5019 .FromJust()); | |
5020 CHECK_EQ(15, a3->Get(context.local(), 1) | |
5021 .ToLocalChecked() | |
5022 ->Int32Value(context.local()) | |
5023 .FromJust()); | |
5024 CHECK_EQ(16, a3->Get(context.local(), 2) | |
5025 .ToLocalChecked() | |
5026 ->Int32Value(context.local()) | |
5027 .FromJust()); | |
4536 | 5028 |
4537 const char* fun5 = "f(17, 18, 19, 20)"; | 5029 const char* fun5 = "f(17, 18, 19, 20)"; |
4538 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>(); | 5030 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>(); |
4539 CHECK_EQ(4u, a4->Length()); | 5031 CHECK_EQ(4u, a4->Length()); |
4540 CHECK_EQ(17, a4->Get(0)->Int32Value()); | 5032 CHECK_EQ(17, a4->Get(context.local(), 0) |
4541 CHECK_EQ(18, a4->Get(1)->Int32Value()); | 5033 .ToLocalChecked() |
4542 CHECK_EQ(19, a4->Get(2)->Int32Value()); | 5034 ->Int32Value(context.local()) |
4543 CHECK_EQ(20, a4->Get(3)->Int32Value()); | 5035 .FromJust()); |
5036 CHECK_EQ(18, a4->Get(context.local(), 1) | |
5037 .ToLocalChecked() | |
5038 ->Int32Value(context.local()) | |
5039 .FromJust()); | |
5040 CHECK_EQ(19, a4->Get(context.local(), 2) | |
5041 .ToLocalChecked() | |
5042 ->Int32Value(context.local()) | |
5043 .FromJust()); | |
5044 CHECK_EQ(20, a4->Get(context.local(), 3) | |
5045 .ToLocalChecked() | |
5046 ->Int32Value(context.local()) | |
5047 .FromJust()); | |
4544 } | 5048 } |
4545 | 5049 |
4546 | 5050 |
4547 THREADED_TEST(FunctionCall) { | 5051 THREADED_TEST(FunctionCall) { |
4548 LocalContext context; | 5052 LocalContext context; |
4549 v8::Isolate* isolate = context->GetIsolate(); | 5053 v8::Isolate* isolate = context->GetIsolate(); |
4550 v8::HandleScope scope(isolate); | 5054 v8::HandleScope scope(isolate); |
4551 CompileRun( | 5055 CompileRun( |
4552 "function Foo() {" | 5056 "function Foo() {" |
4553 " var result = [];" | 5057 " var result = [];" |
4554 " for (var i = 0; i < arguments.length; i++) {" | 5058 " for (var i = 0; i < arguments.length; i++) {" |
4555 " result.push(arguments[i]);" | 5059 " result.push(arguments[i]);" |
4556 " }" | 5060 " }" |
4557 " return result;" | 5061 " return result;" |
4558 "}" | 5062 "}" |
4559 "function ReturnThisSloppy() {" | 5063 "function ReturnThisSloppy() {" |
4560 " return this;" | 5064 " return this;" |
4561 "}" | 5065 "}" |
4562 "function ReturnThisStrict() {" | 5066 "function ReturnThisStrict() {" |
4563 " 'use strict';" | 5067 " 'use strict';" |
4564 " return this;" | 5068 " return this;" |
4565 "}"); | 5069 "}"); |
4566 Local<Function> Foo = | 5070 Local<Function> Foo = Local<Function>::Cast( |
4567 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); | 5071 context->Global()->Get(context.local(), v8_str("Foo")).ToLocalChecked()); |
4568 Local<Function> ReturnThisSloppy = | 5072 Local<Function> ReturnThisSloppy = Local<Function>::Cast( |
4569 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisSloppy"))); | 5073 context->Global() |
4570 Local<Function> ReturnThisStrict = | 5074 ->Get(context.local(), v8_str("ReturnThisSloppy")) |
4571 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict"))); | 5075 .ToLocalChecked()); |
5076 Local<Function> ReturnThisStrict = Local<Function>::Cast( | |
5077 context->Global() | |
5078 ->Get(context.local(), v8_str("ReturnThisStrict")) | |
5079 .ToLocalChecked()); | |
4572 | 5080 |
4573 v8::Handle<Value>* args0 = NULL; | 5081 v8::Local<Value>* args0 = NULL; |
4574 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0)); | 5082 Local<v8::Array> a0 = Local<v8::Array>::Cast( |
5083 Foo->Call(context.local(), Foo, 0, args0).ToLocalChecked()); | |
4575 CHECK_EQ(0u, a0->Length()); | 5084 CHECK_EQ(0u, a0->Length()); |
4576 | 5085 |
4577 v8::Handle<Value> args1[] = {v8_num(1.1)}; | 5086 v8::Local<Value> args1[] = {v8_num(1.1)}; |
4578 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1)); | 5087 Local<v8::Array> a1 = Local<v8::Array>::Cast( |
5088 Foo->Call(context.local(), Foo, 1, args1).ToLocalChecked()); | |
4579 CHECK_EQ(1u, a1->Length()); | 5089 CHECK_EQ(1u, a1->Length()); |
4580 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5090 CHECK_EQ(1.1, a1->Get(context.local(), v8::Integer::New(isolate, 0)) |
5091 .ToLocalChecked() | |
5092 ->NumberValue(context.local()) | |
5093 .FromJust()); | |
4581 | 5094 |
4582 v8::Handle<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; | 5095 v8::Local<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; |
4583 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->Call(Foo, 2, args2)); | 5096 Local<v8::Array> a2 = Local<v8::Array>::Cast( |
5097 Foo->Call(context.local(), Foo, 2, args2).ToLocalChecked()); | |
4584 CHECK_EQ(2u, a2->Length()); | 5098 CHECK_EQ(2u, a2->Length()); |
4585 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5099 CHECK_EQ(2.2, a2->Get(context.local(), v8::Integer::New(isolate, 0)) |
4586 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5100 .ToLocalChecked() |
5101 ->NumberValue(context.local()) | |
5102 .FromJust()); | |
5103 CHECK_EQ(3.3, a2->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5104 .ToLocalChecked() | |
5105 ->NumberValue(context.local()) | |
5106 .FromJust()); | |
4587 | 5107 |
4588 v8::Handle<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; | 5108 v8::Local<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; |
4589 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->Call(Foo, 3, args3)); | 5109 Local<v8::Array> a3 = Local<v8::Array>::Cast( |
5110 Foo->Call(context.local(), Foo, 3, args3).ToLocalChecked()); | |
4590 CHECK_EQ(3u, a3->Length()); | 5111 CHECK_EQ(3u, a3->Length()); |
4591 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5112 CHECK_EQ(4.4, a3->Get(context.local(), v8::Integer::New(isolate, 0)) |
4592 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5113 .ToLocalChecked() |
4593 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 5114 ->NumberValue(context.local()) |
5115 .FromJust()); | |
5116 CHECK_EQ(5.5, a3->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5117 .ToLocalChecked() | |
5118 ->NumberValue(context.local()) | |
5119 .FromJust()); | |
5120 CHECK_EQ(6.6, a3->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5121 .ToLocalChecked() | |
5122 ->NumberValue(context.local()) | |
5123 .FromJust()); | |
4594 | 5124 |
4595 v8::Handle<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), | 5125 v8::Local<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), |
4596 v8_num(10.11)}; | 5126 v8_num(10.11)}; |
4597 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4)); | 5127 Local<v8::Array> a4 = Local<v8::Array>::Cast( |
5128 Foo->Call(context.local(), Foo, 4, args4).ToLocalChecked()); | |
4598 CHECK_EQ(4u, a4->Length()); | 5129 CHECK_EQ(4u, a4->Length()); |
4599 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5130 CHECK_EQ(7.7, a4->Get(context.local(), v8::Integer::New(isolate, 0)) |
4600 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5131 .ToLocalChecked() |
4601 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 5132 ->NumberValue(context.local()) |
4602 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); | 5133 .FromJust()); |
5134 CHECK_EQ(8.8, a4->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5135 .ToLocalChecked() | |
5136 ->NumberValue(context.local()) | |
5137 .FromJust()); | |
5138 CHECK_EQ(9.9, a4->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5139 .ToLocalChecked() | |
5140 ->NumberValue(context.local()) | |
5141 .FromJust()); | |
5142 CHECK_EQ(10.11, a4->Get(context.local(), v8::Integer::New(isolate, 3)) | |
5143 .ToLocalChecked() | |
5144 ->NumberValue(context.local()) | |
5145 .FromJust()); | |
4603 | 5146 |
4604 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL); | 5147 Local<v8::Value> r1 = |
5148 ReturnThisSloppy->Call(context.local(), v8::Undefined(isolate), 0, NULL) | |
5149 .ToLocalChecked(); | |
4605 CHECK(r1->StrictEquals(context->Global())); | 5150 CHECK(r1->StrictEquals(context->Global())); |
4606 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL); | 5151 Local<v8::Value> r2 = |
5152 ReturnThisSloppy->Call(context.local(), v8::Null(isolate), 0, NULL) | |
5153 .ToLocalChecked(); | |
4607 CHECK(r2->StrictEquals(context->Global())); | 5154 CHECK(r2->StrictEquals(context->Global())); |
4608 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL); | 5155 Local<v8::Value> r3 = |
5156 ReturnThisSloppy->Call(context.local(), v8_num(42), 0, NULL) | |
5157 .ToLocalChecked(); | |
4609 CHECK(r3->IsNumberObject()); | 5158 CHECK(r3->IsNumberObject()); |
4610 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf()); | 5159 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf()); |
4611 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL); | 5160 Local<v8::Value> r4 = |
5161 ReturnThisSloppy->Call(context.local(), v8_str("hello"), 0, NULL) | |
5162 .ToLocalChecked(); | |
4612 CHECK(r4->IsStringObject()); | 5163 CHECK(r4->IsStringObject()); |
4613 CHECK(r4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello"))); | 5164 CHECK(r4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello"))); |
4614 Local<v8::Value> r5 = ReturnThisSloppy->Call(v8::True(isolate), 0, NULL); | 5165 Local<v8::Value> r5 = |
5166 ReturnThisSloppy->Call(context.local(), v8::True(isolate), 0, NULL) | |
5167 .ToLocalChecked(); | |
4615 CHECK(r5->IsBooleanObject()); | 5168 CHECK(r5->IsBooleanObject()); |
4616 CHECK(r5.As<v8::BooleanObject>()->ValueOf()); | 5169 CHECK(r5.As<v8::BooleanObject>()->ValueOf()); |
4617 | 5170 |
4618 Local<v8::Value> r6 = ReturnThisStrict->Call(v8::Undefined(isolate), 0, NULL); | 5171 Local<v8::Value> r6 = |
5172 ReturnThisStrict->Call(context.local(), v8::Undefined(isolate), 0, NULL) | |
5173 .ToLocalChecked(); | |
4619 CHECK(r6->IsUndefined()); | 5174 CHECK(r6->IsUndefined()); |
4620 Local<v8::Value> r7 = ReturnThisStrict->Call(v8::Null(isolate), 0, NULL); | 5175 Local<v8::Value> r7 = |
5176 ReturnThisStrict->Call(context.local(), v8::Null(isolate), 0, NULL) | |
5177 .ToLocalChecked(); | |
4621 CHECK(r7->IsNull()); | 5178 CHECK(r7->IsNull()); |
4622 Local<v8::Value> r8 = ReturnThisStrict->Call(v8_num(42), 0, NULL); | 5179 Local<v8::Value> r8 = |
5180 ReturnThisStrict->Call(context.local(), v8_num(42), 0, NULL) | |
5181 .ToLocalChecked(); | |
4623 CHECK(r8->StrictEquals(v8_num(42))); | 5182 CHECK(r8->StrictEquals(v8_num(42))); |
4624 Local<v8::Value> r9 = ReturnThisStrict->Call(v8_str("hello"), 0, NULL); | 5183 Local<v8::Value> r9 = |
5184 ReturnThisStrict->Call(context.local(), v8_str("hello"), 0, NULL) | |
5185 .ToLocalChecked(); | |
4625 CHECK(r9->StrictEquals(v8_str("hello"))); | 5186 CHECK(r9->StrictEquals(v8_str("hello"))); |
4626 Local<v8::Value> r10 = ReturnThisStrict->Call(v8::True(isolate), 0, NULL); | 5187 Local<v8::Value> r10 = |
5188 ReturnThisStrict->Call(context.local(), v8::True(isolate), 0, NULL) | |
5189 .ToLocalChecked(); | |
4627 CHECK(r10->StrictEquals(v8::True(isolate))); | 5190 CHECK(r10->StrictEquals(v8::True(isolate))); |
4628 } | 5191 } |
4629 | 5192 |
4630 | 5193 |
4631 THREADED_TEST(ConstructCall) { | 5194 THREADED_TEST(ConstructCall) { |
4632 LocalContext context; | 5195 LocalContext context; |
4633 v8::Isolate* isolate = context->GetIsolate(); | 5196 v8::Isolate* isolate = context->GetIsolate(); |
4634 v8::HandleScope scope(isolate); | 5197 v8::HandleScope scope(isolate); |
4635 CompileRun( | 5198 CompileRun( |
4636 "function Foo() {" | 5199 "function Foo() {" |
4637 " var result = [];" | 5200 " var result = [];" |
4638 " for (var i = 0; i < arguments.length; i++) {" | 5201 " for (var i = 0; i < arguments.length; i++) {" |
4639 " result.push(arguments[i]);" | 5202 " result.push(arguments[i]);" |
4640 " }" | 5203 " }" |
4641 " return result;" | 5204 " return result;" |
4642 "}"); | 5205 "}"); |
4643 Local<Function> Foo = | 5206 Local<Function> Foo = Local<Function>::Cast( |
4644 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); | 5207 context->Global()->Get(context.local(), v8_str("Foo")).ToLocalChecked()); |
4645 | 5208 |
4646 v8::Handle<Value>* args0 = NULL; | 5209 v8::Local<Value>* args0 = NULL; |
4647 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); | 5210 Local<v8::Array> a0 = Local<v8::Array>::Cast( |
5211 Foo->NewInstance(context.local(), 0, args0).ToLocalChecked()); | |
4648 CHECK_EQ(0u, a0->Length()); | 5212 CHECK_EQ(0u, a0->Length()); |
4649 | 5213 |
4650 v8::Handle<Value> args1[] = {v8_num(1.1)}; | 5214 v8::Local<Value> args1[] = {v8_num(1.1)}; |
4651 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); | 5215 Local<v8::Array> a1 = Local<v8::Array>::Cast( |
5216 Foo->NewInstance(context.local(), 1, args1).ToLocalChecked()); | |
4652 CHECK_EQ(1u, a1->Length()); | 5217 CHECK_EQ(1u, a1->Length()); |
4653 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5218 CHECK_EQ(1.1, a1->Get(context.local(), v8::Integer::New(isolate, 0)) |
5219 .ToLocalChecked() | |
5220 ->NumberValue(context.local()) | |
5221 .FromJust()); | |
4654 | 5222 |
4655 v8::Handle<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; | 5223 v8::Local<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; |
4656 Local<v8::Array> a2 = Local<v8::Array>::Cast(Foo->NewInstance(2, args2)); | 5224 Local<v8::Array> a2 = Local<v8::Array>::Cast( |
5225 Foo->NewInstance(context.local(), 2, args2).ToLocalChecked()); | |
4657 CHECK_EQ(2u, a2->Length()); | 5226 CHECK_EQ(2u, a2->Length()); |
4658 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5227 CHECK_EQ(2.2, a2->Get(context.local(), v8::Integer::New(isolate, 0)) |
4659 CHECK_EQ(3.3, a2->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5228 .ToLocalChecked() |
5229 ->NumberValue(context.local()) | |
5230 .FromJust()); | |
5231 CHECK_EQ(3.3, a2->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5232 .ToLocalChecked() | |
5233 ->NumberValue(context.local()) | |
5234 .FromJust()); | |
4660 | 5235 |
4661 v8::Handle<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; | 5236 v8::Local<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; |
4662 Local<v8::Array> a3 = Local<v8::Array>::Cast(Foo->NewInstance(3, args3)); | 5237 Local<v8::Array> a3 = Local<v8::Array>::Cast( |
5238 Foo->NewInstance(context.local(), 3, args3).ToLocalChecked()); | |
4663 CHECK_EQ(3u, a3->Length()); | 5239 CHECK_EQ(3u, a3->Length()); |
4664 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5240 CHECK_EQ(4.4, a3->Get(context.local(), v8::Integer::New(isolate, 0)) |
4665 CHECK_EQ(5.5, a3->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5241 .ToLocalChecked() |
4666 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 5242 ->NumberValue(context.local()) |
5243 .FromJust()); | |
5244 CHECK_EQ(5.5, a3->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5245 .ToLocalChecked() | |
5246 ->NumberValue(context.local()) | |
5247 .FromJust()); | |
5248 CHECK_EQ(6.6, a3->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5249 .ToLocalChecked() | |
5250 ->NumberValue(context.local()) | |
5251 .FromJust()); | |
4667 | 5252 |
4668 v8::Handle<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), | 5253 v8::Local<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), |
4669 v8_num(10.11)}; | 5254 v8_num(10.11)}; |
4670 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); | 5255 Local<v8::Array> a4 = Local<v8::Array>::Cast( |
5256 Foo->NewInstance(context.local(), 4, args4).ToLocalChecked()); | |
4671 CHECK_EQ(4u, a4->Length()); | 5257 CHECK_EQ(4u, a4->Length()); |
4672 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); | 5258 CHECK_EQ(7.7, a4->Get(context.local(), v8::Integer::New(isolate, 0)) |
4673 CHECK_EQ(8.8, a4->Get(v8::Integer::New(isolate, 1))->NumberValue()); | 5259 .ToLocalChecked() |
4674 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); | 5260 ->NumberValue(context.local()) |
4675 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); | 5261 .FromJust()); |
5262 CHECK_EQ(8.8, a4->Get(context.local(), v8::Integer::New(isolate, 1)) | |
5263 .ToLocalChecked() | |
5264 ->NumberValue(context.local()) | |
5265 .FromJust()); | |
5266 CHECK_EQ(9.9, a4->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5267 .ToLocalChecked() | |
5268 ->NumberValue(context.local()) | |
5269 .FromJust()); | |
5270 CHECK_EQ(10.11, a4->Get(context.local(), v8::Integer::New(isolate, 3)) | |
5271 .ToLocalChecked() | |
5272 ->NumberValue(context.local()) | |
5273 .FromJust()); | |
4676 } | 5274 } |
4677 | 5275 |
4678 | 5276 |
4679 static void CheckUncle(v8::TryCatch* try_catch) { | |
4680 CHECK(try_catch->HasCaught()); | |
4681 String::Utf8Value str_value(try_catch->Exception()); | |
4682 CHECK_EQ(0, strcmp(*str_value, "uncle?")); | |
4683 try_catch->Reset(); | |
4684 } | |
4685 | |
4686 | |
4687 THREADED_TEST(ConversionNumber) { | 5277 THREADED_TEST(ConversionNumber) { |
4688 LocalContext env; | 5278 LocalContext env; |
4689 v8::Isolate* isolate = env->GetIsolate(); | 5279 v8::Isolate* isolate = env->GetIsolate(); |
4690 v8::HandleScope scope(isolate); | 5280 v8::HandleScope scope(isolate); |
4691 // Very large number. | 5281 // Very large number. |
4692 CompileRun("var obj = Math.pow(2,32) * 1237;"); | 5282 CompileRun("var obj = Math.pow(2,32) * 1237;"); |
4693 Local<Value> obj = env->Global()->Get(v8_str("obj")); | 5283 Local<Value> obj = |
4694 CHECK_EQ(5312874545152.0, obj->ToNumber(isolate)->Value()); | 5284 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4695 CHECK_EQ(0, obj->ToInt32(isolate)->Value()); | 5285 CHECK_EQ(5312874545152.0, |
5286 obj->ToNumber(env.local()).ToLocalChecked()->Value()); | |
5287 CHECK_EQ(0, obj->ToInt32(env.local()).ToLocalChecked()->Value()); | |
4696 CHECK(0u == | 5288 CHECK(0u == |
4697 obj->ToUint32(isolate)->Value()); // NOLINT - no CHECK_EQ for unsigned. | 5289 obj->ToUint32(env.local()) |
5290 .ToLocalChecked() | |
5291 ->Value()); // NOLINT - no CHECK_EQ for unsigned. | |
4698 // Large number. | 5292 // Large number. |
4699 CompileRun("var obj = -1234567890123;"); | 5293 CompileRun("var obj = -1234567890123;"); |
4700 obj = env->Global()->Get(v8_str("obj")); | 5294 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4701 CHECK_EQ(-1234567890123.0, obj->ToNumber(isolate)->Value()); | 5295 CHECK_EQ(-1234567890123.0, |
4702 CHECK_EQ(-1912276171, obj->ToInt32(isolate)->Value()); | 5296 obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4703 CHECK(2382691125u == obj->ToUint32(isolate)->Value()); // NOLINT | 5297 CHECK_EQ(-1912276171, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
5298 CHECK(2382691125u == | |
5299 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT | |
4704 // Small positive integer. | 5300 // Small positive integer. |
4705 CompileRun("var obj = 42;"); | 5301 CompileRun("var obj = 42;"); |
4706 obj = env->Global()->Get(v8_str("obj")); | 5302 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4707 CHECK_EQ(42.0, obj->ToNumber(isolate)->Value()); | 5303 CHECK_EQ(42.0, obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4708 CHECK_EQ(42, obj->ToInt32(isolate)->Value()); | 5304 CHECK_EQ(42, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
4709 CHECK(42u == obj->ToUint32(isolate)->Value()); // NOLINT | 5305 CHECK(42u == obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT |
4710 // Negative integer. | 5306 // Negative integer. |
4711 CompileRun("var obj = -37;"); | 5307 CompileRun("var obj = -37;"); |
4712 obj = env->Global()->Get(v8_str("obj")); | 5308 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4713 CHECK_EQ(-37.0, obj->ToNumber(isolate)->Value()); | 5309 CHECK_EQ(-37.0, obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4714 CHECK_EQ(-37, obj->ToInt32(isolate)->Value()); | 5310 CHECK_EQ(-37, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
4715 CHECK(4294967259u == obj->ToUint32(isolate)->Value()); // NOLINT | 5311 CHECK(4294967259u == |
5312 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT | |
4716 // Positive non-int32 integer. | 5313 // Positive non-int32 integer. |
4717 CompileRun("var obj = 0x81234567;"); | 5314 CompileRun("var obj = 0x81234567;"); |
4718 obj = env->Global()->Get(v8_str("obj")); | 5315 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4719 CHECK_EQ(2166572391.0, obj->ToNumber(isolate)->Value()); | 5316 CHECK_EQ(2166572391.0, obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4720 CHECK_EQ(-2128394905, obj->ToInt32(isolate)->Value()); | 5317 CHECK_EQ(-2128394905, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
4721 CHECK(2166572391u == obj->ToUint32(isolate)->Value()); // NOLINT | 5318 CHECK(2166572391u == |
5319 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT | |
4722 // Fraction. | 5320 // Fraction. |
4723 CompileRun("var obj = 42.3;"); | 5321 CompileRun("var obj = 42.3;"); |
4724 obj = env->Global()->Get(v8_str("obj")); | 5322 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4725 CHECK_EQ(42.3, obj->ToNumber(isolate)->Value()); | 5323 CHECK_EQ(42.3, obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4726 CHECK_EQ(42, obj->ToInt32(isolate)->Value()); | 5324 CHECK_EQ(42, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
4727 CHECK(42u == obj->ToUint32(isolate)->Value()); // NOLINT | 5325 CHECK(42u == obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT |
4728 // Large negative fraction. | 5326 // Large negative fraction. |
4729 CompileRun("var obj = -5726623061.75;"); | 5327 CompileRun("var obj = -5726623061.75;"); |
4730 obj = env->Global()->Get(v8_str("obj")); | 5328 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4731 CHECK_EQ(-5726623061.75, obj->ToNumber(isolate)->Value()); | 5329 CHECK_EQ(-5726623061.75, |
4732 CHECK_EQ(-1431655765, obj->ToInt32(isolate)->Value()); | 5330 obj->ToNumber(env.local()).ToLocalChecked()->Value()); |
4733 CHECK(2863311531u == obj->ToUint32(isolate)->Value()); // NOLINT | 5331 CHECK_EQ(-1431655765, obj->ToInt32(env.local()).ToLocalChecked()->Value()); |
5332 CHECK(2863311531u == | |
5333 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT | |
4734 } | 5334 } |
4735 | 5335 |
4736 | 5336 |
4737 THREADED_TEST(isNumberType) { | 5337 THREADED_TEST(isNumberType) { |
4738 LocalContext env; | 5338 LocalContext env; |
4739 v8::HandleScope scope(env->GetIsolate()); | 5339 v8::HandleScope scope(env->GetIsolate()); |
4740 // Very large number. | 5340 // Very large number. |
4741 CompileRun("var obj = Math.pow(2,32) * 1237;"); | 5341 CompileRun("var obj = Math.pow(2,32) * 1237;"); |
4742 Local<Value> obj = env->Global()->Get(v8_str("obj")); | 5342 Local<Value> obj = |
5343 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); | |
4743 CHECK(!obj->IsInt32()); | 5344 CHECK(!obj->IsInt32()); |
4744 CHECK(!obj->IsUint32()); | 5345 CHECK(!obj->IsUint32()); |
4745 // Large negative number. | 5346 // Large negative number. |
4746 CompileRun("var obj = -1234567890123;"); | 5347 CompileRun("var obj = -1234567890123;"); |
4747 obj = env->Global()->Get(v8_str("obj")); | 5348 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4748 CHECK(!obj->IsInt32()); | 5349 CHECK(!obj->IsInt32()); |
4749 CHECK(!obj->IsUint32()); | 5350 CHECK(!obj->IsUint32()); |
4750 // Small positive integer. | 5351 // Small positive integer. |
4751 CompileRun("var obj = 42;"); | 5352 CompileRun("var obj = 42;"); |
4752 obj = env->Global()->Get(v8_str("obj")); | 5353 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4753 CHECK(obj->IsInt32()); | 5354 CHECK(obj->IsInt32()); |
4754 CHECK(obj->IsUint32()); | 5355 CHECK(obj->IsUint32()); |
4755 // Negative integer. | 5356 // Negative integer. |
4756 CompileRun("var obj = -37;"); | 5357 CompileRun("var obj = -37;"); |
4757 obj = env->Global()->Get(v8_str("obj")); | 5358 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4758 CHECK(obj->IsInt32()); | 5359 CHECK(obj->IsInt32()); |
4759 CHECK(!obj->IsUint32()); | 5360 CHECK(!obj->IsUint32()); |
4760 // Positive non-int32 integer. | 5361 // Positive non-int32 integer. |
4761 CompileRun("var obj = 0x81234567;"); | 5362 CompileRun("var obj = 0x81234567;"); |
4762 obj = env->Global()->Get(v8_str("obj")); | 5363 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4763 CHECK(!obj->IsInt32()); | 5364 CHECK(!obj->IsInt32()); |
4764 CHECK(obj->IsUint32()); | 5365 CHECK(obj->IsUint32()); |
4765 // Fraction. | 5366 // Fraction. |
4766 CompileRun("var obj = 42.3;"); | 5367 CompileRun("var obj = 42.3;"); |
4767 obj = env->Global()->Get(v8_str("obj")); | 5368 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4768 CHECK(!obj->IsInt32()); | 5369 CHECK(!obj->IsInt32()); |
4769 CHECK(!obj->IsUint32()); | 5370 CHECK(!obj->IsUint32()); |
4770 // Large negative fraction. | 5371 // Large negative fraction. |
4771 CompileRun("var obj = -5726623061.75;"); | 5372 CompileRun("var obj = -5726623061.75;"); |
4772 obj = env->Global()->Get(v8_str("obj")); | 5373 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4773 CHECK(!obj->IsInt32()); | 5374 CHECK(!obj->IsInt32()); |
4774 CHECK(!obj->IsUint32()); | 5375 CHECK(!obj->IsUint32()); |
4775 // Positive zero | 5376 // Positive zero |
4776 CompileRun("var obj = 0.0;"); | 5377 CompileRun("var obj = 0.0;"); |
4777 obj = env->Global()->Get(v8_str("obj")); | 5378 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4778 CHECK(obj->IsInt32()); | 5379 CHECK(obj->IsInt32()); |
4779 CHECK(obj->IsUint32()); | 5380 CHECK(obj->IsUint32()); |
4780 // Positive zero | 5381 // Positive zero |
4781 CompileRun("var obj = -0.0;"); | 5382 CompileRun("var obj = -0.0;"); |
4782 obj = env->Global()->Get(v8_str("obj")); | 5383 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); |
4783 CHECK(!obj->IsInt32()); | 5384 CHECK(!obj->IsInt32()); |
4784 CHECK(!obj->IsUint32()); | 5385 CHECK(!obj->IsUint32()); |
4785 } | 5386 } |
4786 | 5387 |
4787 | 5388 |
5389 static void CheckUncle(v8::TryCatch* try_catch) { | |
5390 CHECK(try_catch->HasCaught()); | |
5391 String::Utf8Value str_value(try_catch->Exception()); | |
5392 CHECK_EQ(0, strcmp(*str_value, "uncle?")); | |
5393 try_catch->Reset(); | |
5394 } | |
5395 | |
5396 | |
4788 THREADED_TEST(ConversionException) { | 5397 THREADED_TEST(ConversionException) { |
4789 LocalContext env; | 5398 LocalContext env; |
4790 v8::Isolate* isolate = env->GetIsolate(); | 5399 v8::Isolate* isolate = env->GetIsolate(); |
4791 v8::HandleScope scope(isolate); | 5400 v8::HandleScope scope(isolate); |
4792 CompileRun( | 5401 CompileRun( |
4793 "function TestClass() { };" | 5402 "function TestClass() { };" |
4794 "TestClass.prototype.toString = function () { throw 'uncle?'; };" | 5403 "TestClass.prototype.toString = function () { throw 'uncle?'; };" |
4795 "var obj = new TestClass();"); | 5404 "var obj = new TestClass();"); |
4796 Local<Value> obj = env->Global()->Get(v8_str("obj")); | 5405 Local<Value> obj = |
5406 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked(); | |
4797 | 5407 |
4798 v8::TryCatch try_catch(isolate); | 5408 v8::TryCatch try_catch(isolate); |
4799 | 5409 |
4800 Local<Value> to_string_result = obj->ToString(isolate); | 5410 CHECK(obj->ToString(env.local()).IsEmpty()); |
4801 CHECK(to_string_result.IsEmpty()); | |
4802 CheckUncle(&try_catch); | 5411 CheckUncle(&try_catch); |
4803 | 5412 |
4804 Local<Value> to_number_result = obj->ToNumber(isolate); | 5413 CHECK(obj->ToNumber(env.local()).IsEmpty()); |
4805 CHECK(to_number_result.IsEmpty()); | |
4806 CheckUncle(&try_catch); | 5414 CheckUncle(&try_catch); |
4807 | 5415 |
4808 Local<Value> to_integer_result = obj->ToInteger(isolate); | 5416 CHECK(obj->ToInteger(env.local()).IsEmpty()); |
4809 CHECK(to_integer_result.IsEmpty()); | |
4810 CheckUncle(&try_catch); | 5417 CheckUncle(&try_catch); |
4811 | 5418 |
4812 Local<Value> to_uint32_result = obj->ToUint32(isolate); | 5419 CHECK(obj->ToUint32(env.local()).IsEmpty()); |
4813 CHECK(to_uint32_result.IsEmpty()); | |
4814 CheckUncle(&try_catch); | 5420 CheckUncle(&try_catch); |
4815 | 5421 |
4816 Local<Value> to_int32_result = obj->ToInt32(isolate); | 5422 CHECK(obj->ToInt32(env.local()).IsEmpty()); |
4817 CHECK(to_int32_result.IsEmpty()); | |
4818 CheckUncle(&try_catch); | 5423 CheckUncle(&try_catch); |
4819 | 5424 |
4820 Local<Value> to_object_result = v8::Undefined(isolate)->ToObject(isolate); | 5425 CHECK(v8::Undefined(isolate)->ToObject(env.local()).IsEmpty()); |
4821 CHECK(to_object_result.IsEmpty()); | |
4822 CHECK(try_catch.HasCaught()); | 5426 CHECK(try_catch.HasCaught()); |
4823 try_catch.Reset(); | 5427 try_catch.Reset(); |
4824 | 5428 |
4825 int32_t int32_value = obj->Int32Value(); | 5429 CHECK(obj->Int32Value(env.local()).IsNothing()); |
4826 CHECK_EQ(0, int32_value); | |
4827 CheckUncle(&try_catch); | 5430 CheckUncle(&try_catch); |
4828 | 5431 |
4829 uint32_t uint32_value = obj->Uint32Value(); | 5432 CHECK(obj->Uint32Value(env.local()).IsNothing()); |
4830 CHECK_EQ(0u, uint32_value); | |
4831 CheckUncle(&try_catch); | 5433 CheckUncle(&try_catch); |
4832 | 5434 |
4833 double number_value = obj->NumberValue(); | 5435 CHECK(obj->NumberValue(env.local()).IsNothing()); |
4834 CHECK(std::isnan(number_value)); | |
4835 CheckUncle(&try_catch); | 5436 CheckUncle(&try_catch); |
4836 | 5437 |
4837 int64_t integer_value = obj->IntegerValue(); | 5438 CHECK(obj->IntegerValue(env.local()).IsNothing()); |
4838 CHECK_EQ(0, integer_value); | |
4839 CheckUncle(&try_catch); | 5439 CheckUncle(&try_catch); |
4840 } | 5440 } |
4841 | 5441 |
4842 | 5442 |
4843 void ThrowFromC(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5443 void ThrowFromC(const v8::FunctionCallbackInfo<v8::Value>& args) { |
4844 ApiTestFuzzer::Fuzz(); | 5444 ApiTestFuzzer::Fuzz(); |
4845 args.GetIsolate()->ThrowException(v8_str("konto")); | 5445 args.GetIsolate()->ThrowException(v8_str("konto")); |
4846 } | 5446 } |
4847 | 5447 |
4848 | 5448 |
4849 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5449 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { |
4850 if (args.Length() < 1) { | 5450 if (args.Length() < 1) { |
4851 args.GetReturnValue().Set(false); | 5451 args.GetReturnValue().Set(false); |
4852 return; | 5452 return; |
4853 } | 5453 } |
4854 v8::HandleScope scope(args.GetIsolate()); | 5454 v8::HandleScope scope(args.GetIsolate()); |
4855 v8::TryCatch try_catch(args.GetIsolate()); | 5455 v8::TryCatch try_catch(args.GetIsolate()); |
4856 Local<Value> result = CompileRun(args[0]->ToString(args.GetIsolate())); | 5456 Local<Value> result = |
5457 CompileRun(args[0] | |
5458 ->ToString(args.GetIsolate()->GetCurrentContext()) | |
5459 .ToLocalChecked()); | |
4857 CHECK(!try_catch.HasCaught() || result.IsEmpty()); | 5460 CHECK(!try_catch.HasCaught() || result.IsEmpty()); |
4858 args.GetReturnValue().Set(try_catch.HasCaught()); | 5461 args.GetReturnValue().Set(try_catch.HasCaught()); |
4859 } | 5462 } |
4860 | 5463 |
4861 | 5464 |
4862 THREADED_TEST(APICatch) { | 5465 THREADED_TEST(APICatch) { |
4863 v8::Isolate* isolate = CcTest::isolate(); | 5466 v8::Isolate* isolate = CcTest::isolate(); |
4864 v8::HandleScope scope(isolate); | 5467 v8::HandleScope scope(isolate); |
4865 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5468 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4866 templ->Set(v8_str("ThrowFromC"), | 5469 templ->Set(v8_str("ThrowFromC"), |
4867 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5470 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4868 LocalContext context(0, templ); | 5471 LocalContext context(0, templ); |
4869 CompileRun( | 5472 CompileRun( |
4870 "var thrown = false;" | 5473 "var thrown = false;" |
4871 "try {" | 5474 "try {" |
4872 " ThrowFromC();" | 5475 " ThrowFromC();" |
4873 "} catch (e) {" | 5476 "} catch (e) {" |
4874 " thrown = true;" | 5477 " thrown = true;" |
4875 "}"); | 5478 "}"); |
4876 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); | 5479 Local<Value> thrown = context->Global() |
4877 CHECK(thrown->BooleanValue()); | 5480 ->Get(context.local(), v8_str("thrown")) |
5481 .ToLocalChecked(); | |
5482 CHECK(thrown->BooleanValue(context.local()).FromJust()); | |
4878 } | 5483 } |
4879 | 5484 |
4880 | 5485 |
4881 THREADED_TEST(APIThrowTryCatch) { | 5486 THREADED_TEST(APIThrowTryCatch) { |
4882 v8::Isolate* isolate = CcTest::isolate(); | 5487 v8::Isolate* isolate = CcTest::isolate(); |
4883 v8::HandleScope scope(isolate); | 5488 v8::HandleScope scope(isolate); |
4884 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5489 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4885 templ->Set(v8_str("ThrowFromC"), | 5490 templ->Set(v8_str("ThrowFromC"), |
4886 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5491 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
4887 LocalContext context(0, templ); | 5492 LocalContext context(0, templ); |
(...skipping 21 matching lines...) Expand all Loading... | |
4909 " try {" | 5514 " try {" |
4910 " CCatcher('throw 7;');" | 5515 " CCatcher('throw 7;');" |
4911 " } finally {" | 5516 " } finally {" |
4912 " }" | 5517 " }" |
4913 "} catch (e) {" | 5518 "} catch (e) {" |
4914 "}"); | 5519 "}"); |
4915 CHECK(result->IsTrue()); | 5520 CHECK(result->IsTrue()); |
4916 } | 5521 } |
4917 | 5522 |
4918 | 5523 |
4919 static void check_reference_error_message(v8::Handle<v8::Message> message, | 5524 static void check_reference_error_message(v8::Local<v8::Message> message, |
4920 v8::Handle<v8::Value> data) { | 5525 v8::Local<v8::Value> data) { |
4921 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; | 5526 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; |
4922 CHECK(message->Get()->Equals(v8_str(reference_error))); | 5527 CHECK(message->Get() |
5528 ->Equals(CcTest::isolate()->GetCurrentContext(), | |
5529 v8_str(reference_error)) | |
5530 .FromJust()); | |
4923 } | 5531 } |
4924 | 5532 |
4925 | 5533 |
4926 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5534 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { |
4927 ApiTestFuzzer::Fuzz(); | 5535 ApiTestFuzzer::Fuzz(); |
4928 CHECK(false); | 5536 CHECK(false); |
4929 } | 5537 } |
4930 | 5538 |
4931 | 5539 |
4932 // Test that overwritten methods are not invoked on uncaught exception | 5540 // Test that overwritten methods are not invoked on uncaught exception |
4933 // formatting. However, they are invoked when performing normal error | 5541 // formatting. However, they are invoked when performing normal error |
4934 // string conversions. | 5542 // string conversions. |
4935 TEST(APIThrowMessageOverwrittenToString) { | 5543 TEST(APIThrowMessageOverwrittenToString) { |
4936 v8::Isolate* isolate = CcTest::isolate(); | 5544 v8::Isolate* isolate = CcTest::isolate(); |
4937 v8::HandleScope scope(isolate); | 5545 v8::HandleScope scope(isolate); |
4938 v8::V8::AddMessageListener(check_reference_error_message); | 5546 isolate->AddMessageListener(check_reference_error_message); |
4939 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5547 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
4940 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); | 5548 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); |
4941 LocalContext context(NULL, templ); | 5549 LocalContext context(NULL, templ); |
4942 CompileRun("asdf;"); | 5550 CompileRun("asdf;"); |
4943 CompileRun( | 5551 CompileRun( |
4944 "var limit = {};" | 5552 "var limit = {};" |
4945 "limit.valueOf = fail;" | 5553 "limit.valueOf = fail;" |
4946 "Error.stackTraceLimit = limit;"); | 5554 "Error.stackTraceLimit = limit;"); |
4947 CompileRun("asdf"); | 5555 CompileRun("asdf"); |
4948 CompileRun("Array.prototype.pop = fail;"); | 5556 CompileRun("Array.prototype.pop = fail;"); |
4949 CompileRun("Object.prototype.hasOwnProperty = fail;"); | 5557 CompileRun("Object.prototype.hasOwnProperty = fail;"); |
4950 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); | 5558 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); |
4951 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); | 5559 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); |
4952 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }"); | 5560 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }"); |
4953 CompileRun( | 5561 CompileRun( |
4954 "ReferenceError.prototype.toString =" | 5562 "ReferenceError.prototype.toString =" |
4955 " function() { return 'Whoops' }"); | 5563 " function() { return 'Whoops' }"); |
4956 CompileRun("asdf;"); | 5564 CompileRun("asdf;"); |
4957 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); | 5565 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); |
4958 CompileRun("asdf;"); | 5566 CompileRun("asdf;"); |
4959 CompileRun("ReferenceError.prototype.constructor = void 0;"); | 5567 CompileRun("ReferenceError.prototype.constructor = void 0;"); |
4960 CompileRun("asdf;"); | 5568 CompileRun("asdf;"); |
4961 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); | 5569 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); |
4962 CompileRun("asdf;"); | 5570 CompileRun("asdf;"); |
4963 CompileRun("ReferenceError.prototype = new Object();"); | 5571 CompileRun("ReferenceError.prototype = new Object();"); |
4964 CompileRun("asdf;"); | 5572 CompileRun("asdf;"); |
4965 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); | 5573 v8::Local<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); |
4966 CHECK(string->Equals(v8_str("Whoops"))); | 5574 CHECK(string->Equals(context.local(), v8_str("Whoops")).FromJust()); |
4967 CompileRun( | 5575 CompileRun( |
4968 "ReferenceError.prototype.constructor = new Object();" | 5576 "ReferenceError.prototype.constructor = new Object();" |
4969 "ReferenceError.prototype.constructor.name = 1;" | 5577 "ReferenceError.prototype.constructor.name = 1;" |
4970 "Number.prototype.toString = function() { return 'Whoops'; };" | 5578 "Number.prototype.toString = function() { return 'Whoops'; };" |
4971 "ReferenceError.prototype.toString = Object.prototype.toString;"); | 5579 "ReferenceError.prototype.toString = Object.prototype.toString;"); |
4972 CompileRun("asdf;"); | 5580 CompileRun("asdf;"); |
4973 v8::V8::RemoveMessageListeners(check_reference_error_message); | 5581 isolate->RemoveMessageListeners(check_reference_error_message); |
4974 } | 5582 } |
4975 | 5583 |
4976 | 5584 |
4977 static void check_custom_error_tostring(v8::Handle<v8::Message> message, | 5585 static void check_custom_error_tostring(v8::Local<v8::Message> message, |
4978 v8::Handle<v8::Value> data) { | 5586 v8::Local<v8::Value> data) { |
4979 const char* uncaught_error = "Uncaught MyError toString"; | 5587 const char* uncaught_error = "Uncaught MyError toString"; |
4980 CHECK(message->Get()->Equals(v8_str(uncaught_error))); | 5588 CHECK(message->Get() |
5589 ->Equals(CcTest::isolate()->GetCurrentContext(), | |
5590 v8_str(uncaught_error)) | |
5591 .FromJust()); | |
4981 } | 5592 } |
4982 | 5593 |
4983 | 5594 |
4984 TEST(CustomErrorToString) { | 5595 TEST(CustomErrorToString) { |
4985 LocalContext context; | 5596 LocalContext context; |
4986 v8::HandleScope scope(context->GetIsolate()); | 5597 v8::HandleScope scope(context->GetIsolate()); |
4987 v8::V8::AddMessageListener(check_custom_error_tostring); | 5598 context->GetIsolate()->AddMessageListener(check_custom_error_tostring); |
4988 CompileRun( | 5599 CompileRun( |
4989 "function MyError(name, message) { " | 5600 "function MyError(name, message) { " |
4990 " this.name = name; " | 5601 " this.name = name; " |
4991 " this.message = message; " | 5602 " this.message = message; " |
4992 "} " | 5603 "} " |
4993 "MyError.prototype = Object.create(Error.prototype); " | 5604 "MyError.prototype = Object.create(Error.prototype); " |
4994 "MyError.prototype.toString = function() { " | 5605 "MyError.prototype.toString = function() { " |
4995 " return 'MyError toString'; " | 5606 " return 'MyError toString'; " |
4996 "}; " | 5607 "}; " |
4997 "throw new MyError('my name', 'my message'); "); | 5608 "throw new MyError('my name', 'my message'); "); |
4998 v8::V8::RemoveMessageListeners(check_custom_error_tostring); | 5609 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring); |
4999 } | 5610 } |
5000 | 5611 |
5001 | 5612 |
5002 static void check_custom_error_message(v8::Handle<v8::Message> message, | 5613 static void check_custom_error_message(v8::Local<v8::Message> message, |
5003 v8::Handle<v8::Value> data) { | 5614 v8::Local<v8::Value> data) { |
5004 const char* uncaught_error = "Uncaught MyError: my message"; | 5615 const char* uncaught_error = "Uncaught MyError: my message"; |
5005 printf("%s\n", *v8::String::Utf8Value(message->Get())); | 5616 printf("%s\n", *v8::String::Utf8Value(message->Get())); |
5006 CHECK(message->Get()->Equals(v8_str(uncaught_error))); | 5617 CHECK(message->Get() |
5618 ->Equals(CcTest::isolate()->GetCurrentContext(), | |
5619 v8_str(uncaught_error)) | |
5620 .FromJust()); | |
5007 } | 5621 } |
5008 | 5622 |
5009 | 5623 |
5010 TEST(CustomErrorMessage) { | 5624 TEST(CustomErrorMessage) { |
5011 LocalContext context; | 5625 LocalContext context; |
5012 v8::HandleScope scope(context->GetIsolate()); | 5626 v8::HandleScope scope(context->GetIsolate()); |
5013 v8::V8::AddMessageListener(check_custom_error_message); | 5627 context->GetIsolate()->AddMessageListener(check_custom_error_message); |
5014 | 5628 |
5015 // Handlebars. | 5629 // Handlebars. |
5016 CompileRun( | 5630 CompileRun( |
5017 "function MyError(msg) { " | 5631 "function MyError(msg) { " |
5018 " this.name = 'MyError'; " | 5632 " this.name = 'MyError'; " |
5019 " this.message = msg; " | 5633 " this.message = msg; " |
5020 "} " | 5634 "} " |
5021 "MyError.prototype = new Error(); " | 5635 "MyError.prototype = new Error(); " |
5022 "throw new MyError('my message'); "); | 5636 "throw new MyError('my message'); "); |
5023 | 5637 |
(...skipping 15 matching lines...) Expand all Loading... | |
5039 | 5653 |
5040 // Object.create. | 5654 // Object.create. |
5041 CompileRun( | 5655 CompileRun( |
5042 "function MyError(msg) { " | 5656 "function MyError(msg) { " |
5043 " this.name = 'MyError'; " | 5657 " this.name = 'MyError'; " |
5044 " this.message = msg; " | 5658 " this.message = msg; " |
5045 "} " | 5659 "} " |
5046 "MyError.prototype = Object.create(Error.prototype); " | 5660 "MyError.prototype = Object.create(Error.prototype); " |
5047 "throw new MyError('my message'); "); | 5661 "throw new MyError('my message'); "); |
5048 | 5662 |
5049 v8::V8::RemoveMessageListeners(check_custom_error_message); | 5663 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message); |
5050 } | 5664 } |
5051 | 5665 |
5052 | 5666 |
5053 static void check_custom_rethrowing_message(v8::Handle<v8::Message> message, | 5667 static void check_custom_rethrowing_message(v8::Local<v8::Message> message, |
5054 v8::Handle<v8::Value> data) { | 5668 v8::Local<v8::Value> data) { |
5055 const char* uncaught_error = "Uncaught exception"; | 5669 const char* uncaught_error = "Uncaught exception"; |
5056 CHECK(message->Get()->Equals(v8_str(uncaught_error))); | 5670 CHECK(message->Get() |
5671 ->Equals(CcTest::isolate()->GetCurrentContext(), | |
5672 v8_str(uncaught_error)) | |
5673 .FromJust()); | |
5057 } | 5674 } |
5058 | 5675 |
5059 | 5676 |
5060 TEST(CustomErrorRethrowsOnToString) { | 5677 TEST(CustomErrorRethrowsOnToString) { |
5061 LocalContext context; | 5678 LocalContext context; |
5062 v8::HandleScope scope(context->GetIsolate()); | 5679 v8::HandleScope scope(context->GetIsolate()); |
5063 v8::V8::AddMessageListener(check_custom_rethrowing_message); | 5680 context->GetIsolate()->AddMessageListener(check_custom_rethrowing_message); |
5064 | 5681 |
5065 CompileRun( | 5682 CompileRun( |
5066 "var e = { toString: function() { throw e; } };" | 5683 "var e = { toString: function() { throw e; } };" |
5067 "try { throw e; } finally {}"); | 5684 "try { throw e; } finally {}"); |
5068 | 5685 |
5069 v8::V8::RemoveMessageListeners(check_custom_rethrowing_message); | 5686 context->GetIsolate()->RemoveMessageListeners( |
5687 check_custom_rethrowing_message); | |
5070 } | 5688 } |
5071 | 5689 |
5072 | 5690 |
5073 static void receive_message(v8::Handle<v8::Message> message, | 5691 static void receive_message(v8::Local<v8::Message> message, |
5074 v8::Handle<v8::Value> data) { | 5692 v8::Local<v8::Value> data) { |
5075 message->Get(); | 5693 message->Get(); |
5076 message_received = true; | 5694 message_received = true; |
5077 } | 5695 } |
5078 | 5696 |
5079 | 5697 |
5080 TEST(APIThrowMessage) { | 5698 TEST(APIThrowMessage) { |
5081 message_received = false; | 5699 message_received = false; |
5082 v8::Isolate* isolate = CcTest::isolate(); | 5700 v8::Isolate* isolate = CcTest::isolate(); |
5083 v8::HandleScope scope(isolate); | 5701 v8::HandleScope scope(isolate); |
5084 v8::V8::AddMessageListener(receive_message); | 5702 isolate->AddMessageListener(receive_message); |
5085 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5703 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5086 templ->Set(v8_str("ThrowFromC"), | 5704 templ->Set(v8_str("ThrowFromC"), |
5087 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5705 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
5088 LocalContext context(0, templ); | 5706 LocalContext context(0, templ); |
5089 CompileRun("ThrowFromC();"); | 5707 CompileRun("ThrowFromC();"); |
5090 CHECK(message_received); | 5708 CHECK(message_received); |
5091 v8::V8::RemoveMessageListeners(receive_message); | 5709 isolate->RemoveMessageListeners(receive_message); |
5092 } | 5710 } |
5093 | 5711 |
5094 | 5712 |
5095 TEST(APIThrowMessageAndVerboseTryCatch) { | 5713 TEST(APIThrowMessageAndVerboseTryCatch) { |
5096 message_received = false; | 5714 message_received = false; |
5097 v8::Isolate* isolate = CcTest::isolate(); | 5715 v8::Isolate* isolate = CcTest::isolate(); |
5098 v8::HandleScope scope(isolate); | 5716 v8::HandleScope scope(isolate); |
5099 v8::V8::AddMessageListener(receive_message); | 5717 isolate->AddMessageListener(receive_message); |
5100 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5718 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5101 templ->Set(v8_str("ThrowFromC"), | 5719 templ->Set(v8_str("ThrowFromC"), |
5102 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5720 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
5103 LocalContext context(0, templ); | 5721 LocalContext context(0, templ); |
5104 v8::TryCatch try_catch(isolate); | 5722 v8::TryCatch try_catch(isolate); |
5105 try_catch.SetVerbose(true); | 5723 try_catch.SetVerbose(true); |
5106 Local<Value> result = CompileRun("ThrowFromC();"); | 5724 Local<Value> result = CompileRun("ThrowFromC();"); |
5107 CHECK(try_catch.HasCaught()); | 5725 CHECK(try_catch.HasCaught()); |
5108 CHECK(result.IsEmpty()); | 5726 CHECK(result.IsEmpty()); |
5109 CHECK(message_received); | 5727 CHECK(message_received); |
5110 v8::V8::RemoveMessageListeners(receive_message); | 5728 isolate->RemoveMessageListeners(receive_message); |
5111 } | 5729 } |
5112 | 5730 |
5113 | 5731 |
5114 TEST(APIStackOverflowAndVerboseTryCatch) { | 5732 TEST(APIStackOverflowAndVerboseTryCatch) { |
5115 message_received = false; | 5733 message_received = false; |
5116 LocalContext context; | 5734 LocalContext context; |
5117 v8::HandleScope scope(context->GetIsolate()); | 5735 v8::HandleScope scope(context->GetIsolate()); |
5118 v8::V8::AddMessageListener(receive_message); | 5736 context->GetIsolate()->AddMessageListener(receive_message); |
5119 v8::TryCatch try_catch(context->GetIsolate()); | 5737 v8::TryCatch try_catch(context->GetIsolate()); |
5120 try_catch.SetVerbose(true); | 5738 try_catch.SetVerbose(true); |
5121 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); | 5739 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); |
5122 CHECK(try_catch.HasCaught()); | 5740 CHECK(try_catch.HasCaught()); |
5123 CHECK(result.IsEmpty()); | 5741 CHECK(result.IsEmpty()); |
5124 CHECK(message_received); | 5742 CHECK(message_received); |
5125 v8::V8::RemoveMessageListeners(receive_message); | 5743 context->GetIsolate()->RemoveMessageListeners(receive_message); |
5126 } | 5744 } |
5127 | 5745 |
5128 | 5746 |
5129 THREADED_TEST(ExternalScriptException) { | 5747 THREADED_TEST(ExternalScriptException) { |
5130 v8::Isolate* isolate = CcTest::isolate(); | 5748 v8::Isolate* isolate = CcTest::isolate(); |
5131 v8::HandleScope scope(isolate); | 5749 v8::HandleScope scope(isolate); |
5132 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5750 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5133 templ->Set(v8_str("ThrowFromC"), | 5751 templ->Set(v8_str("ThrowFromC"), |
5134 v8::FunctionTemplate::New(isolate, ThrowFromC)); | 5752 v8::FunctionTemplate::New(isolate, ThrowFromC)); |
5135 LocalContext context(0, templ); | 5753 LocalContext context(0, templ); |
5136 | 5754 |
5137 v8::TryCatch try_catch(isolate); | 5755 v8::TryCatch try_catch(isolate); |
5138 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';"); | 5756 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';"); |
5139 CHECK(result.IsEmpty()); | 5757 CHECK(result.IsEmpty()); |
5140 CHECK(try_catch.HasCaught()); | 5758 CHECK(try_catch.HasCaught()); |
5141 String::Utf8Value exception_value(try_catch.Exception()); | 5759 String::Utf8Value exception_value(try_catch.Exception()); |
5142 CHECK_EQ(0, strcmp("konto", *exception_value)); | 5760 CHECK_EQ(0, strcmp("konto", *exception_value)); |
5143 } | 5761 } |
5144 | 5762 |
5145 | 5763 |
5146 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5764 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5147 ApiTestFuzzer::Fuzz(); | 5765 ApiTestFuzzer::Fuzz(); |
5148 CHECK_EQ(4, args.Length()); | 5766 CHECK_EQ(4, args.Length()); |
5149 int count = args[0]->Int32Value(); | 5767 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
5150 int cInterval = args[2]->Int32Value(); | 5768 int count = args[0]->Int32Value(context).FromJust(); |
5769 int cInterval = args[2]->Int32Value(context).FromJust(); | |
5151 if (count == 0) { | 5770 if (count == 0) { |
5152 args.GetIsolate()->ThrowException(v8_str("FromC")); | 5771 args.GetIsolate()->ThrowException(v8_str("FromC")); |
5153 return; | 5772 return; |
5154 } else { | 5773 } else { |
5155 Local<v8::Object> global = args.GetIsolate()->GetCurrentContext()->Global(); | 5774 Local<v8::Object> global = context->Global(); |
5156 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); | 5775 Local<Value> fun = |
5157 v8::Handle<Value> argv[] = {v8_num(count - 1), args[1], args[2], args[3]}; | 5776 global->Get(context, v8_str("JSThrowCountDown")).ToLocalChecked(); |
5777 v8::Local<Value> argv[] = {v8_num(count - 1), args[1], args[2], args[3]}; | |
5158 if (count % cInterval == 0) { | 5778 if (count % cInterval == 0) { |
5159 v8::TryCatch try_catch(args.GetIsolate()); | 5779 v8::TryCatch try_catch(args.GetIsolate()); |
5160 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); | 5780 Local<Value> result = fun.As<Function>() |
5161 int expected = args[3]->Int32Value(); | 5781 ->Call(context, global, 4, argv) |
5782 .FromMaybe(Local<Value>()); | |
5783 int expected = args[3]->Int32Value(context).FromJust(); | |
5162 if (try_catch.HasCaught()) { | 5784 if (try_catch.HasCaught()) { |
5163 CHECK_EQ(expected, count); | 5785 CHECK_EQ(expected, count); |
5164 CHECK(result.IsEmpty()); | 5786 CHECK(result.IsEmpty()); |
5165 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); | 5787 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); |
5166 } else { | 5788 } else { |
5167 CHECK_NE(expected, count); | 5789 CHECK_NE(expected, count); |
5168 } | 5790 } |
5169 args.GetReturnValue().Set(result); | 5791 args.GetReturnValue().Set(result); |
5170 return; | 5792 return; |
5171 } else { | 5793 } else { |
5172 args.GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv)); | 5794 args.GetReturnValue().Set(fun.As<Function>() |
5795 ->Call(context, global, 4, argv) | |
5796 .FromMaybe(v8::Local<v8::Value>())); | |
5173 return; | 5797 return; |
5174 } | 5798 } |
5175 } | 5799 } |
5176 } | 5800 } |
5177 | 5801 |
5178 | 5802 |
5179 void JSCheck(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5803 void JSCheck(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5180 ApiTestFuzzer::Fuzz(); | 5804 ApiTestFuzzer::Fuzz(); |
5181 CHECK_EQ(3, args.Length()); | 5805 CHECK_EQ(3, args.Length()); |
5182 bool equality = args[0]->BooleanValue(); | 5806 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
5183 int count = args[1]->Int32Value(); | 5807 bool equality = args[0]->BooleanValue(context).FromJust(); |
5184 int expected = args[2]->Int32Value(); | 5808 int count = args[1]->Int32Value(context).FromJust(); |
5809 int expected = args[2]->Int32Value(context).FromJust(); | |
5185 if (equality) { | 5810 if (equality) { |
5186 CHECK_EQ(count, expected); | 5811 CHECK_EQ(count, expected); |
5187 } else { | 5812 } else { |
5188 CHECK_NE(count, expected); | 5813 CHECK_NE(count, expected); |
5189 } | 5814 } |
5190 } | 5815 } |
5191 | 5816 |
5192 | 5817 |
5193 THREADED_TEST(EvalInTryFinally) { | 5818 THREADED_TEST(EvalInTryFinally) { |
5194 LocalContext context; | 5819 LocalContext context; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5245 " expected);" | 5870 " expected);" |
5246 " check(false, count, expected);" | 5871 " check(false, count, expected);" |
5247 " return value;" | 5872 " return value;" |
5248 " } catch (e) {" | 5873 " } catch (e) {" |
5249 " check(true, count, expected);" | 5874 " check(true, count, expected);" |
5250 " }" | 5875 " }" |
5251 " } else {" | 5876 " } else {" |
5252 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);" | 5877 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);" |
5253 " }" | 5878 " }" |
5254 "}"); | 5879 "}"); |
5255 Local<Function> fun = | 5880 Local<Function> fun = Local<Function>::Cast( |
5256 Local<Function>::Cast(context->Global()->Get(v8_str("JSThrowCountDown"))); | 5881 context->Global() |
5882 ->Get(context.local(), v8_str("JSThrowCountDown")) | |
5883 .ToLocalChecked()); | |
5257 | 5884 |
5258 const int argc = 4; | 5885 const int argc = 4; |
5259 // count jsInterval cInterval expected | 5886 // count jsInterval cInterval expected |
5260 | 5887 |
5261 // *JS[4] *C[3] @JS[2] C[1] JS[0] | 5888 // *JS[4] *C[3] @JS[2] C[1] JS[0] |
5262 v8::Handle<Value> a0[argc] = {v8_num(4), v8_num(2), v8_num(3), v8_num(2)}; | 5889 v8::Local<Value> a0[argc] = {v8_num(4), v8_num(2), v8_num(3), v8_num(2)}; |
5263 fun->Call(fun, argc, a0); | 5890 fun->Call(context.local(), fun, argc, a0).ToLocalChecked(); |
5264 | 5891 |
5265 // JS[5] *C[4] JS[3] @C[2] JS[1] C[0] | 5892 // JS[5] *C[4] JS[3] @C[2] JS[1] C[0] |
5266 v8::Handle<Value> a1[argc] = {v8_num(5), v8_num(6), v8_num(1), v8_num(2)}; | 5893 v8::Local<Value> a1[argc] = {v8_num(5), v8_num(6), v8_num(1), v8_num(2)}; |
5267 fun->Call(fun, argc, a1); | 5894 fun->Call(context.local(), fun, argc, a1).ToLocalChecked(); |
5268 | 5895 |
5269 // JS[6] @C[5] JS[4] C[3] JS[2] C[1] JS[0] | 5896 // JS[6] @C[5] JS[4] C[3] JS[2] C[1] JS[0] |
5270 v8::Handle<Value> a2[argc] = {v8_num(6), v8_num(7), v8_num(5), v8_num(5)}; | 5897 v8::Local<Value> a2[argc] = {v8_num(6), v8_num(7), v8_num(5), v8_num(5)}; |
5271 fun->Call(fun, argc, a2); | 5898 fun->Call(context.local(), fun, argc, a2).ToLocalChecked(); |
5272 | 5899 |
5273 // @JS[6] C[5] JS[4] C[3] JS[2] C[1] JS[0] | 5900 // @JS[6] C[5] JS[4] C[3] JS[2] C[1] JS[0] |
5274 v8::Handle<Value> a3[argc] = {v8_num(6), v8_num(6), v8_num(7), v8_num(6)}; | 5901 v8::Local<Value> a3[argc] = {v8_num(6), v8_num(6), v8_num(7), v8_num(6)}; |
5275 fun->Call(fun, argc, a3); | 5902 fun->Call(context.local(), fun, argc, a3).ToLocalChecked(); |
5276 | 5903 |
5277 // JS[6] *C[5] @JS[4] C[3] JS[2] C[1] JS[0] | 5904 // JS[6] *C[5] @JS[4] C[3] JS[2] C[1] JS[0] |
5278 v8::Handle<Value> a4[argc] = {v8_num(6), v8_num(4), v8_num(5), v8_num(4)}; | 5905 v8::Local<Value> a4[argc] = {v8_num(6), v8_num(4), v8_num(5), v8_num(4)}; |
5279 fun->Call(fun, argc, a4); | 5906 fun->Call(context.local(), fun, argc, a4).ToLocalChecked(); |
5280 | 5907 |
5281 // JS[6] C[5] *JS[4] @C[3] JS[2] C[1] JS[0] | 5908 // JS[6] C[5] *JS[4] @C[3] JS[2] C[1] JS[0] |
5282 v8::Handle<Value> a5[argc] = {v8_num(6), v8_num(4), v8_num(3), v8_num(3)}; | 5909 v8::Local<Value> a5[argc] = {v8_num(6), v8_num(4), v8_num(3), v8_num(3)}; |
5283 fun->Call(fun, argc, a5); | 5910 fun->Call(context.local(), fun, argc, a5).ToLocalChecked(); |
5284 } | 5911 } |
5285 | 5912 |
5286 | 5913 |
5287 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { | 5914 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5288 ApiTestFuzzer::Fuzz(); | 5915 ApiTestFuzzer::Fuzz(); |
5289 CHECK_EQ(1, args.Length()); | 5916 CHECK_EQ(1, args.Length()); |
5290 args.GetIsolate()->ThrowException(args[0]); | 5917 args.GetIsolate()->ThrowException(args[0]); |
5291 } | 5918 } |
5292 | 5919 |
5293 | 5920 |
5294 THREADED_TEST(ThrowValues) { | 5921 THREADED_TEST(ThrowValues) { |
5295 v8::Isolate* isolate = CcTest::isolate(); | 5922 v8::Isolate* isolate = CcTest::isolate(); |
5296 v8::HandleScope scope(isolate); | 5923 v8::HandleScope scope(isolate); |
5297 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 5924 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5298 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); | 5925 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); |
5299 LocalContext context(0, templ); | 5926 LocalContext context(0, templ); |
5300 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 5927 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast( |
5301 "function Run(obj) {" | 5928 CompileRun("function Run(obj) {" |
5302 " try {" | 5929 " try {" |
5303 " Throw(obj);" | 5930 " Throw(obj);" |
5304 " } catch (e) {" | 5931 " } catch (e) {" |
5305 " return e;" | 5932 " return e;" |
5306 " }" | 5933 " }" |
5307 " return 'no exception';" | 5934 " return 'no exception';" |
5308 "}" | 5935 "}" |
5309 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); | 5936 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); |
5310 CHECK_EQ(5u, result->Length()); | 5937 CHECK_EQ(5u, result->Length()); |
5311 CHECK(result->Get(v8::Integer::New(isolate, 0))->IsString()); | 5938 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 0)) |
5312 CHECK(result->Get(v8::Integer::New(isolate, 1))->IsNumber()); | 5939 .ToLocalChecked() |
5313 CHECK_EQ(1, result->Get(v8::Integer::New(isolate, 1))->Int32Value()); | 5940 ->IsString()); |
5314 CHECK(result->Get(v8::Integer::New(isolate, 2))->IsNumber()); | 5941 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 1)) |
5315 CHECK_EQ(0, result->Get(v8::Integer::New(isolate, 2))->Int32Value()); | 5942 .ToLocalChecked() |
5316 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); | 5943 ->IsNumber()); |
5317 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); | 5944 CHECK_EQ(1, result->Get(context.local(), v8::Integer::New(isolate, 1)) |
5945 .ToLocalChecked() | |
5946 ->Int32Value(context.local()) | |
5947 .FromJust()); | |
5948 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5949 .ToLocalChecked() | |
5950 ->IsNumber()); | |
5951 CHECK_EQ(0, result->Get(context.local(), v8::Integer::New(isolate, 2)) | |
5952 .ToLocalChecked() | |
5953 ->Int32Value(context.local()) | |
5954 .FromJust()); | |
5955 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 3)) | |
5956 .ToLocalChecked() | |
5957 ->IsNull()); | |
5958 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 4)) | |
5959 .ToLocalChecked() | |
5960 ->IsUndefined()); | |
5318 } | 5961 } |
5319 | 5962 |
5320 | 5963 |
5321 THREADED_TEST(CatchZero) { | 5964 THREADED_TEST(CatchZero) { |
5322 LocalContext context; | 5965 LocalContext context; |
5323 v8::HandleScope scope(context->GetIsolate()); | 5966 v8::HandleScope scope(context->GetIsolate()); |
5324 v8::TryCatch try_catch(context->GetIsolate()); | 5967 v8::TryCatch try_catch(context->GetIsolate()); |
5325 CHECK(!try_catch.HasCaught()); | 5968 CHECK(!try_catch.HasCaught()); |
5326 CompileRun("throw 10"); | 5969 CompileRun("throw 10"); |
5327 CHECK(try_catch.HasCaught()); | 5970 CHECK(try_catch.HasCaught()); |
5328 CHECK_EQ(10, try_catch.Exception()->Int32Value()); | 5971 CHECK_EQ(10, try_catch.Exception()->Int32Value(context.local()).FromJust()); |
5329 try_catch.Reset(); | 5972 try_catch.Reset(); |
5330 CHECK(!try_catch.HasCaught()); | 5973 CHECK(!try_catch.HasCaught()); |
5331 CompileRun("throw 0"); | 5974 CompileRun("throw 0"); |
5332 CHECK(try_catch.HasCaught()); | 5975 CHECK(try_catch.HasCaught()); |
5333 CHECK_EQ(0, try_catch.Exception()->Int32Value()); | 5976 CHECK_EQ(0, try_catch.Exception()->Int32Value(context.local()).FromJust()); |
5334 } | 5977 } |
5335 | 5978 |
5336 | 5979 |
5337 THREADED_TEST(CatchExceptionFromWith) { | 5980 THREADED_TEST(CatchExceptionFromWith) { |
5338 LocalContext context; | 5981 LocalContext context; |
5339 v8::HandleScope scope(context->GetIsolate()); | 5982 v8::HandleScope scope(context->GetIsolate()); |
5340 v8::TryCatch try_catch(context->GetIsolate()); | 5983 v8::TryCatch try_catch(context->GetIsolate()); |
5341 CHECK(!try_catch.HasCaught()); | 5984 CHECK(!try_catch.HasCaught()); |
5342 CompileRun("var o = {}; with (o) { throw 42; }"); | 5985 CompileRun("var o = {}; with (o) { throw 42; }"); |
5343 CHECK(try_catch.HasCaught()); | 5986 CHECK(try_catch.HasCaught()); |
(...skipping 13 matching lines...) Expand all Loading... | |
5357 | 6000 |
5358 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 6001 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { |
5359 v8::TryCatch try_catch(args.GetIsolate()); | 6002 v8::TryCatch try_catch(args.GetIsolate()); |
5360 } | 6003 } |
5361 | 6004 |
5362 | 6005 |
5363 THREADED_TEST(TryCatchAndFinally) { | 6006 THREADED_TEST(TryCatchAndFinally) { |
5364 LocalContext context; | 6007 LocalContext context; |
5365 v8::Isolate* isolate = context->GetIsolate(); | 6008 v8::Isolate* isolate = context->GetIsolate(); |
5366 v8::HandleScope scope(isolate); | 6009 v8::HandleScope scope(isolate); |
5367 context->Global()->Set( | 6010 CHECK(context->Global() |
5368 v8_str("native_with_try_catch"), | 6011 ->Set(context.local(), v8_str("native_with_try_catch"), |
5369 v8::FunctionTemplate::New(isolate, WithTryCatch)->GetFunction()); | 6012 v8::FunctionTemplate::New(isolate, WithTryCatch) |
6013 ->GetFunction(context.local()) | |
6014 .ToLocalChecked()) | |
6015 .FromJust()); | |
5370 v8::TryCatch try_catch(isolate); | 6016 v8::TryCatch try_catch(isolate); |
5371 CHECK(!try_catch.HasCaught()); | 6017 CHECK(!try_catch.HasCaught()); |
5372 CompileRun( | 6018 CompileRun( |
5373 "try {\n" | 6019 "try {\n" |
5374 " throw new Error('a');\n" | 6020 " throw new Error('a');\n" |
5375 "} finally {\n" | 6021 "} finally {\n" |
5376 " native_with_try_catch();\n" | 6022 " native_with_try_catch();\n" |
5377 "}\n"); | 6023 "}\n"); |
5378 CHECK(try_catch.HasCaught()); | 6024 CHECK(try_catch.HasCaught()); |
5379 } | 6025 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5423 v8::TryCatch try_catch(context->GetIsolate()); | 6069 v8::TryCatch try_catch(context->GetIsolate()); |
5424 TryCatchNested2Helper(5); | 6070 TryCatchNested2Helper(5); |
5425 CHECK(try_catch.HasCaught()); | 6071 CHECK(try_catch.HasCaught()); |
5426 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2")); | 6072 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2")); |
5427 } | 6073 } |
5428 } | 6074 } |
5429 | 6075 |
5430 | 6076 |
5431 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { | 6077 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { |
5432 CHECK(try_catch->HasCaught()); | 6078 CHECK(try_catch->HasCaught()); |
5433 Handle<Message> message = try_catch->Message(); | 6079 Local<Message> message = try_catch->Message(); |
5434 Handle<Value> resource = message->GetScriptOrigin().ResourceName(); | 6080 Local<Value> resource = message->GetScriptOrigin().ResourceName(); |
5435 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); | 6081 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); |
5436 CHECK_EQ(0, | 6082 CHECK_EQ(0, |
5437 strcmp(*v8::String::Utf8Value(message->Get()), "Uncaught Error: a")); | 6083 strcmp(*v8::String::Utf8Value(message->Get()), "Uncaught Error: a")); |
5438 CHECK_EQ(1, message->GetLineNumber()); | 6084 CHECK_EQ(1, message->GetLineNumber(CcTest::isolate()->GetCurrentContext()) |
5439 CHECK_EQ(0, message->GetStartColumn()); | 6085 .FromJust()); |
6086 CHECK_EQ(0, message->GetStartColumn(CcTest::isolate()->GetCurrentContext()) | |
6087 .FromJust()); | |
5440 } | 6088 } |
5441 | 6089 |
5442 | 6090 |
5443 void TryCatchMixedNestingHelper( | 6091 void TryCatchMixedNestingHelper( |
5444 const v8::FunctionCallbackInfo<v8::Value>& args) { | 6092 const v8::FunctionCallbackInfo<v8::Value>& args) { |
5445 ApiTestFuzzer::Fuzz(); | 6093 ApiTestFuzzer::Fuzz(); |
5446 v8::TryCatch try_catch(args.GetIsolate()); | 6094 v8::TryCatch try_catch(args.GetIsolate()); |
5447 CompileRunWithOrigin("throw new Error('a');\n", "inner", 0, 0); | 6095 CompileRunWithOrigin("throw new Error('a');\n", "inner", 0, 0); |
5448 CHECK(try_catch.HasCaught()); | 6096 CHECK(try_catch.HasCaught()); |
5449 TryCatchMixedNestingCheck(&try_catch); | 6097 TryCatchMixedNestingCheck(&try_catch); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5515 CompileRun("TryCatchNativeResetHelper();"); | 6163 CompileRun("TryCatchNativeResetHelper();"); |
5516 CHECK(!try_catch.HasCaught()); | 6164 CHECK(!try_catch.HasCaught()); |
5517 } | 6165 } |
5518 | 6166 |
5519 | 6167 |
5520 THREADED_TEST(Equality) { | 6168 THREADED_TEST(Equality) { |
5521 LocalContext context; | 6169 LocalContext context; |
5522 v8::Isolate* isolate = context->GetIsolate(); | 6170 v8::Isolate* isolate = context->GetIsolate(); |
5523 v8::HandleScope scope(context->GetIsolate()); | 6171 v8::HandleScope scope(context->GetIsolate()); |
5524 // Check that equality works at all before relying on CHECK_EQ | 6172 // Check that equality works at all before relying on CHECK_EQ |
5525 CHECK(v8_str("a")->Equals(v8_str("a"))); | 6173 CHECK(v8_str("a")->Equals(context.local(), v8_str("a")).FromJust()); |
5526 CHECK(!v8_str("a")->Equals(v8_str("b"))); | 6174 CHECK(!v8_str("a")->Equals(context.local(), v8_str("b")).FromJust()); |
5527 | 6175 |
5528 CHECK(v8_str("a")->Equals(v8_str("a"))); | 6176 CHECK(v8_str("a")->Equals(context.local(), v8_str("a")).FromJust()); |
5529 CHECK(!v8_str("a")->Equals(v8_str("b"))); | 6177 CHECK(!v8_str("a")->Equals(context.local(), v8_str("b")).FromJust()); |
5530 CHECK(v8_num(1)->Equals(v8_num(1))); | 6178 CHECK(v8_num(1)->Equals(context.local(), v8_num(1)).FromJust()); |
5531 CHECK(v8_num(1.00)->Equals(v8_num(1))); | 6179 CHECK(v8_num(1.00)->Equals(context.local(), v8_num(1)).FromJust()); |
5532 CHECK(!v8_num(1)->Equals(v8_num(2))); | 6180 CHECK(!v8_num(1)->Equals(context.local(), v8_num(2)).FromJust()); |
5533 | 6181 |
5534 // Assume String is not internalized. | 6182 // Assume String is not internalized. |
5535 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); | 6183 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); |
5536 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); | 6184 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); |
5537 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); | 6185 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); |
5538 CHECK(v8_num(1)->StrictEquals(v8_num(1))); | 6186 CHECK(v8_num(1)->StrictEquals(v8_num(1))); |
5539 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); | 6187 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); |
5540 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); | 6188 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); |
5541 Local<Value> not_a_number = v8_num(std::numeric_limits<double>::quiet_NaN()); | 6189 Local<Value> not_a_number = v8_num(std::numeric_limits<double>::quiet_NaN()); |
5542 CHECK(!not_a_number->StrictEquals(not_a_number)); | 6190 CHECK(!not_a_number->StrictEquals(not_a_number)); |
5543 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); | 6191 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); |
5544 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); | 6192 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); |
5545 | 6193 |
5546 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 6194 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
5547 v8::Persistent<v8::Object> alias(isolate, obj); | 6195 v8::Persistent<v8::Object> alias(isolate, obj); |
5548 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); | 6196 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); |
5549 alias.Reset(); | 6197 alias.Reset(); |
5550 | 6198 |
5551 CHECK(v8_str("a")->SameValue(v8_str("a"))); | 6199 CHECK(v8_str("a")->SameValue(v8_str("a"))); |
5552 CHECK(!v8_str("a")->SameValue(v8_str("b"))); | 6200 CHECK(!v8_str("a")->SameValue(v8_str("b"))); |
5553 CHECK(!v8_str("5")->SameValue(v8_num(5))); | 6201 CHECK(!v8_str("5")->SameValue(v8_num(5))); |
5554 CHECK(v8_num(1)->SameValue(v8_num(1))); | 6202 CHECK(v8_num(1)->SameValue(v8_num(1))); |
5555 CHECK(!v8_num(1)->SameValue(v8_num(2))); | 6203 CHECK(!v8_num(1)->SameValue(v8_num(2))); |
5556 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); | 6204 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); |
5557 CHECK(not_a_number->SameValue(not_a_number)); | 6205 CHECK(not_a_number->SameValue(not_a_number)); |
5558 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); | 6206 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); |
5559 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); | 6207 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); |
5560 } | 6208 } |
5561 | 6209 |
5562 | 6210 |
5563 THREADED_TEST(MultiRun) { | 6211 THREADED_TEST(MultiRun) { |
5564 LocalContext context; | 6212 LocalContext context; |
5565 v8::HandleScope scope(context->GetIsolate()); | 6213 v8::HandleScope scope(context->GetIsolate()); |
5566 Local<Script> script = v8_compile("x"); | 6214 Local<Script> script = v8_compile("x"); |
5567 for (int i = 0; i < 10; i++) script->Run(); | 6215 for (int i = 0; i < 10; i++) { |
6216 script->Run(context.local()).IsEmpty(); | |
6217 } | |
5568 } | 6218 } |
5569 | 6219 |
5570 | 6220 |
5571 static void GetXValue(Local<String> name, | 6221 static void GetXValue(Local<Name> name, |
5572 const v8::PropertyCallbackInfo<v8::Value>& info) { | 6222 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5573 ApiTestFuzzer::Fuzz(); | 6223 ApiTestFuzzer::Fuzz(); |
5574 CHECK(info.Data()->Equals(v8_str("donut"))); | 6224 CHECK(info.Data() |
5575 CHECK(name->Equals(v8_str("x"))); | 6225 ->Equals(CcTest::isolate()->GetCurrentContext(), v8_str("donut")) |
6226 .FromJust()); | |
6227 CHECK(name->Equals(CcTest::isolate()->GetCurrentContext(), v8_str("x")) | |
6228 .FromJust()); | |
5576 info.GetReturnValue().Set(name); | 6229 info.GetReturnValue().Set(name); |
5577 } | 6230 } |
5578 | 6231 |
5579 | 6232 |
5580 THREADED_TEST(SimplePropertyRead) { | 6233 THREADED_TEST(SimplePropertyRead) { |
5581 LocalContext context; | 6234 LocalContext context; |
5582 v8::Isolate* isolate = context->GetIsolate(); | 6235 v8::Isolate* isolate = context->GetIsolate(); |
5583 v8::HandleScope scope(isolate); | 6236 v8::HandleScope scope(isolate); |
5584 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6237 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5585 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 6238 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5586 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6239 CHECK(context->Global() |
6240 ->Set(context.local(), v8_str("obj"), | |
6241 templ->NewInstance(context.local()).ToLocalChecked()) | |
6242 .FromJust()); | |
5587 Local<Script> script = v8_compile("obj.x"); | 6243 Local<Script> script = v8_compile("obj.x"); |
5588 for (int i = 0; i < 10; i++) { | 6244 for (int i = 0; i < 10; i++) { |
5589 Local<Value> result = script->Run(); | 6245 Local<Value> result = script->Run(context.local()).ToLocalChecked(); |
5590 CHECK(result->Equals(v8_str("x"))); | 6246 CHECK(result->Equals(context.local(), v8_str("x")).FromJust()); |
5591 } | 6247 } |
5592 } | 6248 } |
5593 | 6249 |
5594 | 6250 |
5595 THREADED_TEST(DefinePropertyOnAPIAccessor) { | 6251 THREADED_TEST(DefinePropertyOnAPIAccessor) { |
5596 LocalContext context; | 6252 LocalContext context; |
5597 v8::Isolate* isolate = context->GetIsolate(); | 6253 v8::Isolate* isolate = context->GetIsolate(); |
5598 v8::HandleScope scope(isolate); | 6254 v8::HandleScope scope(isolate); |
5599 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6255 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5600 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 6256 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5601 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6257 CHECK(context->Global() |
6258 ->Set(context.local(), v8_str("obj"), | |
6259 templ->NewInstance(context.local()).ToLocalChecked()) | |
6260 .FromJust()); | |
5602 | 6261 |
5603 // Uses getOwnPropertyDescriptor to check the configurable status | 6262 // Uses getOwnPropertyDescriptor to check the configurable status |
5604 Local<Script> script_desc = v8_compile( | 6263 Local<Script> script_desc = v8_compile( |
5605 "var prop = Object.getOwnPropertyDescriptor( " | 6264 "var prop = Object.getOwnPropertyDescriptor( " |
5606 "obj, 'x');" | 6265 "obj, 'x');" |
5607 "prop.configurable;"); | 6266 "prop.configurable;"); |
5608 Local<Value> result = script_desc->Run(); | 6267 Local<Value> result = script_desc->Run(context.local()).ToLocalChecked(); |
5609 CHECK_EQ(result->BooleanValue(), true); | 6268 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true); |
5610 | 6269 |
5611 // Redefine get - but still configurable | 6270 // Redefine get - but still configurable |
5612 Local<Script> script_define = v8_compile( | 6271 Local<Script> script_define = v8_compile( |
5613 "var desc = { get: function(){return 42; }," | 6272 "var desc = { get: function(){return 42; }," |
5614 " configurable: true };" | 6273 " configurable: true };" |
5615 "Object.defineProperty(obj, 'x', desc);" | 6274 "Object.defineProperty(obj, 'x', desc);" |
5616 "obj.x"); | 6275 "obj.x"); |
5617 result = script_define->Run(); | 6276 result = script_define->Run(context.local()).ToLocalChecked(); |
5618 CHECK(result->Equals(v8_num(42))); | 6277 CHECK(result->Equals(context.local(), v8_num(42)).FromJust()); |
5619 | 6278 |
5620 // Check that the accessor is still configurable | 6279 // Check that the accessor is still configurable |
5621 result = script_desc->Run(); | 6280 result = script_desc->Run(context.local()).ToLocalChecked(); |
5622 CHECK_EQ(result->BooleanValue(), true); | 6281 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true); |
5623 | 6282 |
5624 // Redefine to a non-configurable | 6283 // Redefine to a non-configurable |
5625 script_define = v8_compile( | 6284 script_define = v8_compile( |
5626 "var desc = { get: function(){return 43; }," | 6285 "var desc = { get: function(){return 43; }," |
5627 " configurable: false };" | 6286 " configurable: false };" |
5628 "Object.defineProperty(obj, 'x', desc);" | 6287 "Object.defineProperty(obj, 'x', desc);" |
5629 "obj.x"); | 6288 "obj.x"); |
5630 result = script_define->Run(); | 6289 result = script_define->Run(context.local()).ToLocalChecked(); |
5631 CHECK(result->Equals(v8_num(43))); | 6290 CHECK(result->Equals(context.local(), v8_num(43)).FromJust()); |
5632 result = script_desc->Run(); | 6291 result = script_desc->Run(context.local()).ToLocalChecked(); |
5633 CHECK_EQ(result->BooleanValue(), false); | 6292 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), false); |
5634 | 6293 |
5635 // Make sure that it is not possible to redefine again | 6294 // Make sure that it is not possible to redefine again |
5636 v8::TryCatch try_catch(isolate); | 6295 v8::TryCatch try_catch(isolate); |
5637 result = script_define->Run(); | 6296 CHECK(script_define->Run(context.local()).IsEmpty()); |
5638 CHECK(try_catch.HasCaught()); | 6297 CHECK(try_catch.HasCaught()); |
5639 String::Utf8Value exception_value(try_catch.Exception()); | 6298 String::Utf8Value exception_value(try_catch.Exception()); |
5640 CHECK_EQ(0, | 6299 CHECK_EQ(0, |
5641 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); | 6300 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); |
5642 } | 6301 } |
5643 | 6302 |
5644 | 6303 |
5645 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { | 6304 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { |
5646 v8::Isolate* isolate = CcTest::isolate(); | 6305 v8::Isolate* isolate = CcTest::isolate(); |
5647 v8::HandleScope scope(isolate); | 6306 v8::HandleScope scope(isolate); |
5648 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6307 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5649 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); | 6308 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); |
5650 LocalContext context; | 6309 LocalContext context; |
5651 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6310 CHECK(context->Global() |
6311 ->Set(context.local(), v8_str("obj"), | |
6312 templ->NewInstance(context.local()).ToLocalChecked()) | |
6313 .FromJust()); | |
5652 | 6314 |
5653 Local<Script> script_desc = v8_compile( | 6315 Local<Script> script_desc = v8_compile( |
5654 "var prop =" | 6316 "var prop =" |
5655 "Object.getOwnPropertyDescriptor( " | 6317 "Object.getOwnPropertyDescriptor( " |
5656 "obj, 'x');" | 6318 "obj, 'x');" |
5657 "prop.configurable;"); | 6319 "prop.configurable;"); |
5658 Local<Value> result = script_desc->Run(); | 6320 Local<Value> result = script_desc->Run(context.local()).ToLocalChecked(); |
5659 CHECK_EQ(result->BooleanValue(), true); | 6321 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true); |
5660 | 6322 |
5661 Local<Script> script_define = v8_compile( | 6323 Local<Script> script_define = v8_compile( |
5662 "var desc = {get: function(){return 42; }," | 6324 "var desc = {get: function(){return 42; }," |
5663 " configurable: true };" | 6325 " configurable: true };" |
5664 "Object.defineProperty(obj, 'x', desc);" | 6326 "Object.defineProperty(obj, 'x', desc);" |
5665 "obj.x"); | 6327 "obj.x"); |
5666 result = script_define->Run(); | 6328 result = script_define->Run(context.local()).ToLocalChecked(); |
5667 CHECK(result->Equals(v8_num(42))); | 6329 CHECK(result->Equals(context.local(), v8_num(42)).FromJust()); |
5668 | 6330 |
5669 | 6331 result = script_desc->Run(context.local()).ToLocalChecked(); |
5670 result = script_desc->Run(); | 6332 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true); |
5671 CHECK_EQ(result->BooleanValue(), true); | |
5672 | |
5673 | 6333 |
5674 script_define = v8_compile( | 6334 script_define = v8_compile( |
5675 "var desc = {get: function(){return 43; }," | 6335 "var desc = {get: function(){return 43; }," |
5676 " configurable: false };" | 6336 " configurable: false };" |
5677 "Object.defineProperty(obj, 'x', desc);" | 6337 "Object.defineProperty(obj, 'x', desc);" |
5678 "obj.x"); | 6338 "obj.x"); |
5679 result = script_define->Run(); | 6339 result = script_define->Run(context.local()).ToLocalChecked(); |
5680 CHECK(result->Equals(v8_num(43))); | 6340 CHECK(result->Equals(context.local(), v8_num(43)).FromJust()); |
5681 result = script_desc->Run(); | |
5682 | 6341 |
5683 CHECK_EQ(result->BooleanValue(), false); | 6342 result = script_desc->Run(context.local()).ToLocalChecked(); |
6343 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), false); | |
5684 | 6344 |
5685 v8::TryCatch try_catch(isolate); | 6345 v8::TryCatch try_catch(isolate); |
5686 result = script_define->Run(); | 6346 CHECK(script_define->Run(context.local()).IsEmpty()); |
5687 CHECK(try_catch.HasCaught()); | 6347 CHECK(try_catch.HasCaught()); |
5688 String::Utf8Value exception_value(try_catch.Exception()); | 6348 String::Utf8Value exception_value(try_catch.Exception()); |
5689 CHECK_EQ(0, | 6349 CHECK_EQ(0, |
5690 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); | 6350 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); |
5691 } | 6351 } |
5692 | 6352 |
5693 | 6353 |
5694 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, | 6354 static v8::Local<v8::Object> GetGlobalProperty(LocalContext* context, |
5695 char const* name) { | 6355 char const* name) { |
5696 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); | 6356 return v8::Local<v8::Object>::Cast( |
6357 (*context) | |
6358 ->Global() | |
6359 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(name)) | |
6360 .ToLocalChecked()); | |
5697 } | 6361 } |
5698 | 6362 |
5699 | 6363 |
5700 THREADED_TEST(DefineAPIAccessorOnObject) { | 6364 THREADED_TEST(DefineAPIAccessorOnObject) { |
5701 v8::Isolate* isolate = CcTest::isolate(); | 6365 v8::Isolate* isolate = CcTest::isolate(); |
5702 v8::HandleScope scope(isolate); | 6366 v8::HandleScope scope(isolate); |
5703 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6367 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5704 LocalContext context; | 6368 LocalContext context; |
5705 | 6369 |
5706 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 6370 CHECK(context->Global() |
6371 ->Set(context.local(), v8_str("obj1"), | |
6372 templ->NewInstance(context.local()).ToLocalChecked()) | |
6373 .FromJust()); | |
5707 CompileRun("var obj2 = {};"); | 6374 CompileRun("var obj2 = {};"); |
5708 | 6375 |
5709 CHECK(CompileRun("obj1.x")->IsUndefined()); | 6376 CHECK(CompileRun("obj1.x")->IsUndefined()); |
5710 CHECK(CompileRun("obj2.x")->IsUndefined()); | 6377 CHECK(CompileRun("obj2.x")->IsUndefined()); |
5711 | 6378 |
5712 CHECK(GetGlobalProperty(&context, "obj1") | 6379 CHECK(GetGlobalProperty(&context, "obj1") |
5713 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6380 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
6381 v8_str("donut")) | |
6382 .FromJust()); | |
5714 | 6383 |
5715 ExpectString("obj1.x", "x"); | 6384 ExpectString("obj1.x", "x"); |
5716 CHECK(CompileRun("obj2.x")->IsUndefined()); | 6385 CHECK(CompileRun("obj2.x")->IsUndefined()); |
5717 | 6386 |
5718 CHECK(GetGlobalProperty(&context, "obj2") | 6387 CHECK(GetGlobalProperty(&context, "obj2") |
5719 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6388 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
6389 v8_str("donut")) | |
6390 .FromJust()); | |
5720 | 6391 |
5721 ExpectString("obj1.x", "x"); | 6392 ExpectString("obj1.x", "x"); |
5722 ExpectString("obj2.x", "x"); | 6393 ExpectString("obj2.x", "x"); |
5723 | 6394 |
5724 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); | 6395 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); |
5725 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); | 6396 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); |
5726 | 6397 |
5727 CompileRun( | 6398 CompileRun( |
5728 "Object.defineProperty(obj1, 'x'," | 6399 "Object.defineProperty(obj1, 'x'," |
5729 "{ get: function() { return 'y'; }, configurable: true })"); | 6400 "{ get: function() { return 'y'; }, configurable: true })"); |
5730 | 6401 |
5731 ExpectString("obj1.x", "y"); | 6402 ExpectString("obj1.x", "y"); |
5732 ExpectString("obj2.x", "x"); | 6403 ExpectString("obj2.x", "x"); |
5733 | 6404 |
5734 CompileRun( | 6405 CompileRun( |
5735 "Object.defineProperty(obj2, 'x'," | 6406 "Object.defineProperty(obj2, 'x'," |
5736 "{ get: function() { return 'y'; }, configurable: true })"); | 6407 "{ get: function() { return 'y'; }, configurable: true })"); |
5737 | 6408 |
5738 ExpectString("obj1.x", "y"); | 6409 ExpectString("obj1.x", "y"); |
5739 ExpectString("obj2.x", "y"); | 6410 ExpectString("obj2.x", "y"); |
5740 | 6411 |
5741 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); | 6412 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); |
5742 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); | 6413 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); |
5743 | 6414 |
5744 CHECK(GetGlobalProperty(&context, "obj1") | 6415 CHECK(GetGlobalProperty(&context, "obj1") |
5745 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6416 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
6417 v8_str("donut")) | |
6418 .FromJust()); | |
5746 CHECK(GetGlobalProperty(&context, "obj2") | 6419 CHECK(GetGlobalProperty(&context, "obj2") |
5747 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6420 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
6421 v8_str("donut")) | |
6422 .FromJust()); | |
5748 | 6423 |
5749 ExpectString("obj1.x", "x"); | 6424 ExpectString("obj1.x", "x"); |
5750 ExpectString("obj2.x", "x"); | 6425 ExpectString("obj2.x", "x"); |
5751 | 6426 |
5752 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); | 6427 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); |
5753 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); | 6428 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); |
5754 | 6429 |
5755 // Define getters/setters, but now make them not configurable. | 6430 // Define getters/setters, but now make them not configurable. |
5756 CompileRun( | 6431 CompileRun( |
5757 "Object.defineProperty(obj1, 'x'," | 6432 "Object.defineProperty(obj1, 'x'," |
5758 "{ get: function() { return 'z'; }, configurable: false })"); | 6433 "{ get: function() { return 'z'; }, configurable: false })"); |
5759 CompileRun( | 6434 CompileRun( |
5760 "Object.defineProperty(obj2, 'x'," | 6435 "Object.defineProperty(obj2, 'x'," |
5761 "{ get: function() { return 'z'; }, configurable: false })"); | 6436 "{ get: function() { return 'z'; }, configurable: false })"); |
5762 | |
5763 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); | 6437 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); |
5764 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); | 6438 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); |
5765 | 6439 |
5766 ExpectString("obj1.x", "z"); | 6440 ExpectString("obj1.x", "z"); |
5767 ExpectString("obj2.x", "z"); | 6441 ExpectString("obj2.x", "z"); |
5768 | 6442 |
5769 CHECK(!GetGlobalProperty(&context, "obj1") | 6443 CHECK(GetGlobalProperty(&context, "obj1") |
5770 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6444 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
5771 CHECK(!GetGlobalProperty(&context, "obj2") | 6445 v8_str("donut")) |
5772 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6446 .IsNothing()); |
6447 CHECK(GetGlobalProperty(&context, "obj2") | |
6448 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, | |
6449 v8_str("donut")) | |
6450 .IsNothing()); | |
5773 | 6451 |
5774 ExpectString("obj1.x", "z"); | 6452 ExpectString("obj1.x", "z"); |
5775 ExpectString("obj2.x", "z"); | 6453 ExpectString("obj2.x", "z"); |
5776 } | 6454 } |
5777 | 6455 |
5778 | 6456 |
5779 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { | 6457 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { |
5780 v8::Isolate* isolate = CcTest::isolate(); | 6458 v8::Isolate* isolate = CcTest::isolate(); |
5781 v8::HandleScope scope(isolate); | 6459 v8::HandleScope scope(isolate); |
5782 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6460 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5783 LocalContext context; | 6461 LocalContext context; |
5784 | 6462 |
5785 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 6463 CHECK(context->Global() |
6464 ->Set(context.local(), v8_str("obj1"), | |
6465 templ->NewInstance(context.local()).ToLocalChecked()) | |
6466 .FromJust()); | |
5786 CompileRun("var obj2 = {};"); | 6467 CompileRun("var obj2 = {};"); |
5787 | 6468 |
5788 CHECK(GetGlobalProperty(&context, "obj1") | 6469 CHECK(GetGlobalProperty(&context, "obj1") |
5789 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"), | 6470 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
5790 v8::DEFAULT, v8::DontDelete)); | 6471 v8_str("donut"), v8::DEFAULT, v8::DontDelete) |
6472 .FromJust()); | |
5791 CHECK(GetGlobalProperty(&context, "obj2") | 6473 CHECK(GetGlobalProperty(&context, "obj2") |
5792 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"), | 6474 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
5793 v8::DEFAULT, v8::DontDelete)); | 6475 v8_str("donut"), v8::DEFAULT, v8::DontDelete) |
6476 .FromJust()); | |
5794 | 6477 |
5795 ExpectString("obj1.x", "x"); | 6478 ExpectString("obj1.x", "x"); |
5796 ExpectString("obj2.x", "x"); | 6479 ExpectString("obj2.x", "x"); |
5797 | 6480 |
5798 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); | 6481 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); |
5799 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); | 6482 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); |
5800 | 6483 |
5801 CHECK(!GetGlobalProperty(&context, "obj1") | 6484 CHECK(GetGlobalProperty(&context, "obj1") |
5802 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6485 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, |
5803 CHECK(!GetGlobalProperty(&context, "obj2") | 6486 v8_str("donut")) |
5804 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); | 6487 .IsNothing()); |
6488 CHECK(GetGlobalProperty(&context, "obj2") | |
6489 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL, | |
6490 v8_str("donut")) | |
6491 .IsNothing()); | |
5805 | 6492 |
5806 { | 6493 { |
5807 v8::TryCatch try_catch(isolate); | 6494 v8::TryCatch try_catch(isolate); |
5808 CompileRun( | 6495 CompileRun( |
5809 "Object.defineProperty(obj1, 'x'," | 6496 "Object.defineProperty(obj1, 'x'," |
5810 "{get: function() { return 'func'; }})"); | 6497 "{get: function() { return 'func'; }})"); |
5811 CHECK(try_catch.HasCaught()); | 6498 CHECK(try_catch.HasCaught()); |
5812 String::Utf8Value exception_value(try_catch.Exception()); | 6499 String::Utf8Value exception_value(try_catch.Exception()); |
5813 CHECK_EQ( | 6500 CHECK_EQ( |
5814 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); | 6501 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); |
5815 } | 6502 } |
5816 { | 6503 { |
5817 v8::TryCatch try_catch(isolate); | 6504 v8::TryCatch try_catch(isolate); |
5818 CompileRun( | 6505 CompileRun( |
5819 "Object.defineProperty(obj2, 'x'," | 6506 "Object.defineProperty(obj2, 'x'," |
5820 "{get: function() { return 'func'; }})"); | 6507 "{get: function() { return 'func'; }})"); |
5821 CHECK(try_catch.HasCaught()); | 6508 CHECK(try_catch.HasCaught()); |
5822 String::Utf8Value exception_value(try_catch.Exception()); | 6509 String::Utf8Value exception_value(try_catch.Exception()); |
5823 CHECK_EQ( | 6510 CHECK_EQ( |
5824 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); | 6511 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); |
5825 } | 6512 } |
5826 } | 6513 } |
5827 | 6514 |
5828 | 6515 |
5829 static void Get239Value(Local<String> name, | 6516 static void Get239Value(Local<Name> name, |
5830 const v8::PropertyCallbackInfo<v8::Value>& info) { | 6517 const v8::PropertyCallbackInfo<v8::Value>& info) { |
5831 ApiTestFuzzer::Fuzz(); | 6518 ApiTestFuzzer::Fuzz(); |
5832 CHECK(info.Data()->Equals(v8_str("donut"))); | 6519 CHECK(info.Data() |
5833 CHECK(name->Equals(v8_str("239"))); | 6520 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("donut")) |
6521 .FromJust()); | |
6522 CHECK(name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("239")) | |
6523 .FromJust()); | |
5834 info.GetReturnValue().Set(name); | 6524 info.GetReturnValue().Set(name); |
5835 } | 6525 } |
5836 | 6526 |
5837 | 6527 |
5838 THREADED_TEST(ElementAPIAccessor) { | 6528 THREADED_TEST(ElementAPIAccessor) { |
5839 v8::Isolate* isolate = CcTest::isolate(); | 6529 v8::Isolate* isolate = CcTest::isolate(); |
5840 v8::HandleScope scope(isolate); | 6530 v8::HandleScope scope(isolate); |
5841 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6531 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5842 LocalContext context; | 6532 LocalContext context; |
5843 | 6533 |
5844 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); | 6534 CHECK(context->Global() |
6535 ->Set(context.local(), v8_str("obj1"), | |
6536 templ->NewInstance(context.local()).ToLocalChecked()) | |
6537 .FromJust()); | |
5845 CompileRun("var obj2 = {};"); | 6538 CompileRun("var obj2 = {};"); |
5846 | 6539 |
5847 CHECK(GetGlobalProperty(&context, "obj1") | 6540 CHECK(GetGlobalProperty(&context, "obj1") |
5848 ->SetAccessor(v8_str("239"), Get239Value, NULL, v8_str("donut"))); | 6541 ->SetAccessor(context.local(), v8_str("239"), Get239Value, NULL, |
6542 v8_str("donut")) | |
6543 .FromJust()); | |
5849 CHECK(GetGlobalProperty(&context, "obj2") | 6544 CHECK(GetGlobalProperty(&context, "obj2") |
5850 ->SetAccessor(v8_str("239"), Get239Value, NULL, v8_str("donut"))); | 6545 ->SetAccessor(context.local(), v8_str("239"), Get239Value, NULL, |
6546 v8_str("donut")) | |
6547 .FromJust()); | |
5851 | 6548 |
5852 ExpectString("obj1[239]", "239"); | 6549 ExpectString("obj1[239]", "239"); |
5853 ExpectString("obj2[239]", "239"); | 6550 ExpectString("obj2[239]", "239"); |
5854 ExpectString("obj1['239']", "239"); | 6551 ExpectString("obj1['239']", "239"); |
5855 ExpectString("obj2['239']", "239"); | 6552 ExpectString("obj2['239']", "239"); |
5856 } | 6553 } |
5857 | 6554 |
5858 | 6555 |
5859 v8::Persistent<Value> xValue; | 6556 v8::Persistent<Value> xValue; |
5860 | 6557 |
5861 | 6558 |
5862 static void SetXValue(Local<String> name, Local<Value> value, | 6559 static void SetXValue(Local<Name> name, Local<Value> value, |
5863 const v8::PropertyCallbackInfo<void>& info) { | 6560 const v8::PropertyCallbackInfo<void>& info) { |
5864 CHECK(value->Equals(v8_num(4))); | 6561 Local<Context> context = info.GetIsolate()->GetCurrentContext(); |
5865 CHECK(info.Data()->Equals(v8_str("donut"))); | 6562 CHECK(value->Equals(context, v8_num(4)).FromJust()); |
5866 CHECK(name->Equals(v8_str("x"))); | 6563 CHECK(info.Data()->Equals(context, v8_str("donut")).FromJust()); |
6564 CHECK(name->Equals(context, v8_str("x")).FromJust()); | |
5867 CHECK(xValue.IsEmpty()); | 6565 CHECK(xValue.IsEmpty()); |
5868 xValue.Reset(info.GetIsolate(), value); | 6566 xValue.Reset(info.GetIsolate(), value); |
5869 } | 6567 } |
5870 | 6568 |
5871 | 6569 |
5872 THREADED_TEST(SimplePropertyWrite) { | 6570 THREADED_TEST(SimplePropertyWrite) { |
5873 v8::Isolate* isolate = CcTest::isolate(); | 6571 v8::Isolate* isolate = CcTest::isolate(); |
5874 v8::HandleScope scope(isolate); | 6572 v8::HandleScope scope(isolate); |
5875 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6573 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5876 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); | 6574 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); |
5877 LocalContext context; | 6575 LocalContext context; |
5878 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6576 CHECK(context->Global() |
6577 ->Set(context.local(), v8_str("obj"), | |
6578 templ->NewInstance(context.local()).ToLocalChecked()) | |
6579 .FromJust()); | |
5879 Local<Script> script = v8_compile("obj.x = 4"); | 6580 Local<Script> script = v8_compile("obj.x = 4"); |
5880 for (int i = 0; i < 10; i++) { | 6581 for (int i = 0; i < 10; i++) { |
5881 CHECK(xValue.IsEmpty()); | 6582 CHECK(xValue.IsEmpty()); |
5882 script->Run(); | 6583 script->Run(context.local()).ToLocalChecked(); |
5883 CHECK(v8_num(4)->Equals(Local<Value>::New(CcTest::isolate(), xValue))); | 6584 CHECK(v8_num(4) |
6585 ->Equals(context.local(), | |
6586 Local<Value>::New(CcTest::isolate(), xValue)) | |
6587 .FromJust()); | |
5884 xValue.Reset(); | 6588 xValue.Reset(); |
5885 } | 6589 } |
5886 } | 6590 } |
5887 | 6591 |
5888 | 6592 |
5889 THREADED_TEST(SetterOnly) { | 6593 THREADED_TEST(SetterOnly) { |
5890 v8::Isolate* isolate = CcTest::isolate(); | 6594 v8::Isolate* isolate = CcTest::isolate(); |
5891 v8::HandleScope scope(isolate); | 6595 v8::HandleScope scope(isolate); |
5892 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6596 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5893 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); | 6597 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); |
5894 LocalContext context; | 6598 LocalContext context; |
5895 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6599 CHECK(context->Global() |
6600 ->Set(context.local(), v8_str("obj"), | |
6601 templ->NewInstance(context.local()).ToLocalChecked()) | |
6602 .FromJust()); | |
5896 Local<Script> script = v8_compile("obj.x = 4; obj.x"); | 6603 Local<Script> script = v8_compile("obj.x = 4; obj.x"); |
5897 for (int i = 0; i < 10; i++) { | 6604 for (int i = 0; i < 10; i++) { |
5898 CHECK(xValue.IsEmpty()); | 6605 CHECK(xValue.IsEmpty()); |
5899 script->Run(); | 6606 script->Run(context.local()).ToLocalChecked(); |
5900 CHECK(v8_num(4)->Equals(Local<Value>::New(CcTest::isolate(), xValue))); | 6607 CHECK(v8_num(4) |
6608 ->Equals(context.local(), | |
6609 Local<Value>::New(CcTest::isolate(), xValue)) | |
6610 .FromJust()); | |
5901 xValue.Reset(); | 6611 xValue.Reset(); |
5902 } | 6612 } |
5903 } | 6613 } |
5904 | 6614 |
5905 | 6615 |
5906 THREADED_TEST(NoAccessors) { | 6616 THREADED_TEST(NoAccessors) { |
5907 v8::Isolate* isolate = CcTest::isolate(); | 6617 v8::Isolate* isolate = CcTest::isolate(); |
5908 v8::HandleScope scope(isolate); | 6618 v8::HandleScope scope(isolate); |
5909 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6619 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5910 templ->SetAccessor(v8_str("x"), static_cast<v8::AccessorGetterCallback>(NULL), | 6620 templ->SetAccessor(v8_str("x"), static_cast<v8::AccessorGetterCallback>(NULL), |
5911 NULL, v8_str("donut")); | 6621 NULL, v8_str("donut")); |
5912 LocalContext context; | 6622 LocalContext context; |
5913 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 6623 CHECK(context->Global() |
6624 ->Set(context.local(), v8_str("obj"), | |
6625 templ->NewInstance(context.local()).ToLocalChecked()) | |
6626 .FromJust()); | |
5914 Local<Script> script = v8_compile("obj.x = 4; obj.x"); | 6627 Local<Script> script = v8_compile("obj.x = 4; obj.x"); |
5915 for (int i = 0; i < 10; i++) { | 6628 for (int i = 0; i < 10; i++) { |
5916 script->Run(); | 6629 script->Run(context.local()).ToLocalChecked(); |
5917 } | 6630 } |
5918 } | 6631 } |
5919 | 6632 |
5920 | 6633 |
5921 THREADED_TEST(MultiContexts) { | 6634 THREADED_TEST(MultiContexts) { |
5922 v8::Isolate* isolate = CcTest::isolate(); | 6635 v8::Isolate* isolate = CcTest::isolate(); |
5923 v8::HandleScope scope(isolate); | 6636 v8::HandleScope scope(isolate); |
5924 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 6637 v8::Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
5925 templ->Set(v8_str("dummy"), | 6638 templ->Set(v8_str("dummy"), |
5926 v8::FunctionTemplate::New(isolate, DummyCallHandler)); | 6639 v8::FunctionTemplate::New(isolate, DummyCallHandler)); |
5927 | 6640 |
5928 Local<String> password = v8_str("Password"); | 6641 Local<String> password = v8_str("Password"); |
5929 | 6642 |
5930 // Create an environment | 6643 // Create an environment |
5931 LocalContext context0(0, templ); | 6644 LocalContext context0(0, templ); |
5932 context0->SetSecurityToken(password); | 6645 context0->SetSecurityToken(password); |
5933 v8::Handle<v8::Object> global0 = context0->Global(); | 6646 v8::Local<v8::Object> global0 = context0->Global(); |
5934 global0->Set(v8_str("custom"), v8_num(1234)); | 6647 CHECK(global0->Set(context0.local(), v8_str("custom"), v8_num(1234)) |
5935 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); | 6648 .FromJust()); |
6649 CHECK_EQ(1234, global0->Get(context0.local(), v8_str("custom")) | |
6650 .ToLocalChecked() | |
6651 ->Int32Value(context0.local()) | |
6652 .FromJust()); | |
5936 | 6653 |
5937 // Create an independent environment | 6654 // Create an independent environment |
5938 LocalContext context1(0, templ); | 6655 LocalContext context1(0, templ); |
5939 context1->SetSecurityToken(password); | 6656 context1->SetSecurityToken(password); |
5940 v8::Handle<v8::Object> global1 = context1->Global(); | 6657 v8::Local<v8::Object> global1 = context1->Global(); |
5941 global1->Set(v8_str("custom"), v8_num(1234)); | 6658 CHECK(global1->Set(context1.local(), v8_str("custom"), v8_num(1234)) |
5942 CHECK(!global0->Equals(global1)); | 6659 .FromJust()); |
5943 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); | 6660 CHECK(!global0->Equals(context1.local(), global1).FromJust()); |
5944 CHECK_EQ(1234, global1->Get(v8_str("custom"))->Int32Value()); | 6661 CHECK_EQ(1234, global0->Get(context1.local(), v8_str("custom")) |
6662 .ToLocalChecked() | |
6663 ->Int32Value(context0.local()) | |
6664 .FromJust()); | |
6665 CHECK_EQ(1234, global1->Get(context1.local(), v8_str("custom")) | |
6666 .ToLocalChecked() | |
6667 ->Int32Value(context1.local()) | |
6668 .FromJust()); | |
5945 | 6669 |
5946 // Now create a new context with the old global | 6670 // Now create a new context with the old global |
5947 LocalContext context2(0, templ, global1); | 6671 LocalContext context2(0, templ, global1); |
5948 context2->SetSecurityToken(password); | 6672 context2->SetSecurityToken(password); |
5949 v8::Handle<v8::Object> global2 = context2->Global(); | 6673 v8::Local<v8::Object> global2 = context2->Global(); |
5950 CHECK(global1->Equals(global2)); | 6674 CHECK(global1->Equals(context2.local(), global2).FromJust()); |
5951 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value()); | 6675 CHECK_EQ(0, global1->Get(context2.local(), v8_str("custom")) |
5952 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value()); | 6676 .ToLocalChecked() |
6677 ->Int32Value(context1.local()) | |
6678 .FromJust()); | |
6679 CHECK_EQ(0, global2->Get(context2.local(), v8_str("custom")) | |
6680 .ToLocalChecked() | |
6681 ->Int32Value(context2.local()) | |
6682 .FromJust()); | |
5953 } | 6683 } |
5954 | 6684 |
5955 | 6685 |
5956 THREADED_TEST(FunctionPrototypeAcrossContexts) { | 6686 THREADED_TEST(FunctionPrototypeAcrossContexts) { |
5957 // Make sure that functions created by cloning boilerplates cannot | 6687 // Make sure that functions created by cloning boilerplates cannot |
5958 // communicate through their __proto__ field. | 6688 // communicate through their __proto__ field. |
5959 | 6689 |
5960 v8::HandleScope scope(CcTest::isolate()); | 6690 v8::HandleScope scope(CcTest::isolate()); |
5961 | 6691 |
5962 LocalContext env0; | 6692 LocalContext env0; |
5963 v8::Handle<v8::Object> global0 = env0->Global(); | 6693 v8::Local<v8::Object> global0 = env0->Global(); |
5964 v8::Handle<v8::Object> object0 = | 6694 v8::Local<v8::Object> object0 = global0->Get(env0.local(), v8_str("Object")) |
5965 global0->Get(v8_str("Object")).As<v8::Object>(); | 6695 .ToLocalChecked() |
5966 v8::Handle<v8::Object> tostring0 = | 6696 .As<v8::Object>(); |
5967 object0->Get(v8_str("toString")).As<v8::Object>(); | 6697 v8::Local<v8::Object> tostring0 = |
5968 v8::Handle<v8::Object> proto0 = | 6698 object0->Get(env0.local(), v8_str("toString")) |
5969 tostring0->Get(v8_str("__proto__")).As<v8::Object>(); | 6699 .ToLocalChecked() |
5970 proto0->Set(v8_str("custom"), v8_num(1234)); | 6700 .As<v8::Object>(); |
6701 v8::Local<v8::Object> proto0 = | |
6702 tostring0->Get(env0.local(), v8_str("__proto__")) | |
6703 .ToLocalChecked() | |
6704 .As<v8::Object>(); | |
6705 CHECK(proto0->Set(env0.local(), v8_str("custom"), v8_num(1234)).FromJust()); | |
5971 | 6706 |
5972 LocalContext env1; | 6707 LocalContext env1; |
5973 v8::Handle<v8::Object> global1 = env1->Global(); | 6708 v8::Local<v8::Object> global1 = env1->Global(); |
5974 v8::Handle<v8::Object> object1 = | 6709 v8::Local<v8::Object> object1 = global1->Get(env1.local(), v8_str("Object")) |
5975 global1->Get(v8_str("Object")).As<v8::Object>(); | 6710 .ToLocalChecked() |
5976 v8::Handle<v8::Object> tostring1 = | 6711 .As<v8::Object>(); |
5977 object1->Get(v8_str("toString")).As<v8::Object>(); | 6712 v8::Local<v8::Object> tostring1 = |
5978 v8::Handle<v8::Object> proto1 = | 6713 object1->Get(env1.local(), v8_str("toString")) |
5979 tostring1->Get(v8_str("__proto__")).As<v8::Object>(); | 6714 .ToLocalChecked() |
5980 CHECK(!proto1->Has(v8_str("custom"))); | 6715 .As<v8::Object>(); |
6716 v8::Local<v8::Object> proto1 = | |
6717 tostring1->Get(env1.local(), v8_str("__proto__")) | |
6718 .ToLocalChecked() | |
6719 .As<v8::Object>(); | |
6720 CHECK(!proto1->Has(env1.local(), v8_str("custom")).FromJust()); | |
5981 } | 6721 } |
5982 | 6722 |
5983 | 6723 |
5984 THREADED_TEST(Regress892105) { | 6724 THREADED_TEST(Regress892105) { |
5985 // Make sure that object and array literals created by cloning | 6725 // Make sure that object and array literals created by cloning |
5986 // boilerplates cannot communicate through their __proto__ | 6726 // boilerplates cannot communicate through their __proto__ |
5987 // field. This is rather difficult to check, but we try to add stuff | 6727 // field. This is rather difficult to check, but we try to add stuff |
5988 // to Object.prototype and Array.prototype and create a new | 6728 // to Object.prototype and Array.prototype and create a new |
5989 // environment. This should succeed. | 6729 // environment. This should succeed. |
5990 | 6730 |
5991 v8::HandleScope scope(CcTest::isolate()); | 6731 v8::HandleScope scope(CcTest::isolate()); |
5992 | 6732 |
5993 Local<String> source = v8_str( | 6733 Local<String> source = v8_str( |
5994 "Object.prototype.obj = 1234;" | 6734 "Object.prototype.obj = 1234;" |
5995 "Array.prototype.arr = 4567;" | 6735 "Array.prototype.arr = 4567;" |
5996 "8901"); | 6736 "8901"); |
5997 | 6737 |
5998 LocalContext env0; | 6738 LocalContext env0; |
5999 Local<Script> script0 = v8_compile(source); | 6739 Local<Script> script0 = v8_compile(source); |
6000 CHECK_EQ(8901.0, script0->Run()->NumberValue()); | 6740 CHECK_EQ(8901.0, script0->Run(env0.local()) |
6741 .ToLocalChecked() | |
6742 ->NumberValue(env0.local()) | |
6743 .FromJust()); | |
6001 | 6744 |
6002 LocalContext env1; | 6745 LocalContext env1; |
6003 Local<Script> script1 = v8_compile(source); | 6746 Local<Script> script1 = v8_compile(source); |
6004 CHECK_EQ(8901.0, script1->Run()->NumberValue()); | 6747 CHECK_EQ(8901.0, script1->Run(env1.local()) |
6748 .ToLocalChecked() | |
6749 ->NumberValue(env1.local()) | |
6750 .FromJust()); | |
6005 } | 6751 } |
6006 | 6752 |
6007 | 6753 |
6008 THREADED_TEST(UndetectableObject) { | 6754 THREADED_TEST(UndetectableObject) { |
6009 LocalContext env; | 6755 LocalContext env; |
6010 v8::HandleScope scope(env->GetIsolate()); | 6756 v8::HandleScope scope(env->GetIsolate()); |
6011 | 6757 |
6012 Local<v8::FunctionTemplate> desc = | 6758 Local<v8::FunctionTemplate> desc = |
6013 v8::FunctionTemplate::New(env->GetIsolate()); | 6759 v8::FunctionTemplate::New(env->GetIsolate()); |
6014 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6760 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
6015 | 6761 |
6016 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6762 Local<v8::Object> obj = desc->GetFunction(env.local()) |
6017 env->Global()->Set(v8_str("undetectable"), obj); | 6763 .ToLocalChecked() |
6764 ->NewInstance(env.local()) | |
6765 .ToLocalChecked(); | |
6766 CHECK( | |
6767 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust()); | |
6018 | 6768 |
6019 ExpectString("undetectable.toString()", "[object Object]"); | 6769 ExpectString("undetectable.toString()", "[object Object]"); |
6020 ExpectString("typeof undetectable", "undefined"); | 6770 ExpectString("typeof undetectable", "undefined"); |
6021 ExpectString("typeof(undetectable)", "undefined"); | 6771 ExpectString("typeof(undetectable)", "undefined"); |
6022 ExpectBoolean("typeof undetectable == 'undefined'", true); | 6772 ExpectBoolean("typeof undetectable == 'undefined'", true); |
6023 ExpectBoolean("typeof undetectable == 'object'", false); | 6773 ExpectBoolean("typeof undetectable == 'object'", false); |
6024 ExpectBoolean("if (undetectable) { true; } else { false; }", false); | 6774 ExpectBoolean("if (undetectable) { true; } else { false; }", false); |
6025 ExpectBoolean("!undetectable", true); | 6775 ExpectBoolean("!undetectable", true); |
6026 | 6776 |
6027 ExpectObject("true&&undetectable", obj); | 6777 ExpectObject("true&&undetectable", obj); |
(...skipping 22 matching lines...) Expand all Loading... | |
6050 | 6800 |
6051 | 6801 |
6052 THREADED_TEST(VoidLiteral) { | 6802 THREADED_TEST(VoidLiteral) { |
6053 LocalContext env; | 6803 LocalContext env; |
6054 v8::Isolate* isolate = env->GetIsolate(); | 6804 v8::Isolate* isolate = env->GetIsolate(); |
6055 v8::HandleScope scope(isolate); | 6805 v8::HandleScope scope(isolate); |
6056 | 6806 |
6057 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); | 6807 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
6058 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6808 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
6059 | 6809 |
6060 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6810 Local<v8::Object> obj = desc->GetFunction(env.local()) |
6061 env->Global()->Set(v8_str("undetectable"), obj); | 6811 .ToLocalChecked() |
6812 ->NewInstance(env.local()) | |
6813 .ToLocalChecked(); | |
6814 CHECK( | |
6815 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust()); | |
6062 | 6816 |
6063 ExpectBoolean("undefined == void 0", true); | 6817 ExpectBoolean("undefined == void 0", true); |
6064 ExpectBoolean("undetectable == void 0", true); | 6818 ExpectBoolean("undetectable == void 0", true); |
6065 ExpectBoolean("null == void 0", true); | 6819 ExpectBoolean("null == void 0", true); |
6066 ExpectBoolean("undefined === void 0", true); | 6820 ExpectBoolean("undefined === void 0", true); |
6067 ExpectBoolean("undetectable === void 0", false); | 6821 ExpectBoolean("undetectable === void 0", false); |
6068 ExpectBoolean("null === void 0", false); | 6822 ExpectBoolean("null === void 0", false); |
6069 | 6823 |
6070 ExpectBoolean("void 0 == undefined", true); | 6824 ExpectBoolean("void 0 == undefined", true); |
6071 ExpectBoolean("void 0 == undetectable", true); | 6825 ExpectBoolean("void 0 == undetectable", true); |
(...skipping 24 matching lines...) Expand all Loading... | |
6096 | 6850 |
6097 | 6851 |
6098 THREADED_TEST(ExtensibleOnUndetectable) { | 6852 THREADED_TEST(ExtensibleOnUndetectable) { |
6099 LocalContext env; | 6853 LocalContext env; |
6100 v8::Isolate* isolate = env->GetIsolate(); | 6854 v8::Isolate* isolate = env->GetIsolate(); |
6101 v8::HandleScope scope(isolate); | 6855 v8::HandleScope scope(isolate); |
6102 | 6856 |
6103 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); | 6857 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); |
6104 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable | 6858 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable |
6105 | 6859 |
6106 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); | 6860 Local<v8::Object> obj = desc->GetFunction(env.local()) |
6107 env->Global()->Set(v8_str("undetectable"), obj); | 6861 .ToLocalChecked() |
6862 ->NewInstance(env.local()) | |
6863 .ToLocalChecked(); | |
6864 CHECK( | |
6865 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust()); | |
6108 | 6866 |
6109 Local<String> source = v8_str( | 6867 Local<String> source = v8_str( |
6110 "undetectable.x = 42;" | 6868 "undetectable.x = 42;" |
6111 "undetectable.x"); | 6869 "undetectable.x"); |
6112 | 6870 |
6113 Local<Script> script = v8_compile(source); | 6871 Local<Script> script = v8_compile(source); |
6114 | 6872 |
6115 CHECK(v8::Integer::New(isolate, 42)->Equals(script->Run())); | 6873 CHECK(v8::Integer::New(isolate, 42) |
6874 ->Equals(env.local(), script->Run(env.local()).ToLocalChecked()) | |
6875 .FromJust()); | |
6116 | 6876 |
6117 ExpectBoolean("Object.isExtensible(undetectable)", true); | 6877 ExpectBoolean("Object.isExtensible(undetectable)", true); |
6118 | 6878 |
6119 source = v8_str("Object.preventExtensions(undetectable);"); | 6879 source = v8_str("Object.preventExtensions(undetectable);"); |
6120 script = v8_compile(source); | 6880 script = v8_compile(source); |
6121 script->Run(); | 6881 script->Run(env.local()).ToLocalChecked(); |
6122 ExpectBoolean("Object.isExtensible(undetectable)", false); | 6882 ExpectBoolean("Object.isExtensible(undetectable)", false); |
6123 | 6883 |
6124 source = v8_str("undetectable.y = 2000;"); | 6884 source = v8_str("undetectable.y = 2000;"); |
6125 script = v8_compile(source); | 6885 script = v8_compile(source); |
6126 script->Run(); | 6886 script->Run(env.local()).ToLocalChecked(); |
6127 ExpectBoolean("undetectable.y == undefined", true); | 6887 ExpectBoolean("undetectable.y == undefined", true); |
6128 } | 6888 } |
6129 | 6889 |
6130 | 6890 |
6131 // The point of this test is type checking. We run it only so compilers | 6891 // The point of this test is type checking. We run it only so compilers |
6132 // don't complain about an unused function. | 6892 // don't complain about an unused function. |
6133 TEST(PersistentHandles) { | 6893 TEST(PersistentHandles) { |
6134 LocalContext env; | 6894 LocalContext env; |
6135 v8::Isolate* isolate = CcTest::isolate(); | 6895 v8::Isolate* isolate = CcTest::isolate(); |
6136 v8::HandleScope scope(isolate); | 6896 v8::HandleScope scope(isolate); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6168 "function Foo() {" | 6928 "function Foo() {" |
6169 " return 4;" | 6929 " return 4;" |
6170 "}"; | 6930 "}"; |
6171 | 6931 |
6172 | 6932 |
6173 TEST(SimpleExtensions) { | 6933 TEST(SimpleExtensions) { |
6174 v8::HandleScope handle_scope(CcTest::isolate()); | 6934 v8::HandleScope handle_scope(CcTest::isolate()); |
6175 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); | 6935 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); |
6176 const char* extension_names[] = {"simpletest"}; | 6936 const char* extension_names[] = {"simpletest"}; |
6177 v8::ExtensionConfiguration extensions(1, extension_names); | 6937 v8::ExtensionConfiguration extensions(1, extension_names); |
6178 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 6938 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6179 Context::Scope lock(context); | 6939 Context::Scope lock(context); |
6180 v8::Handle<Value> result = CompileRun("Foo()"); | 6940 v8::Local<Value> result = CompileRun("Foo()"); |
6181 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); | 6941 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4)) |
6942 .FromJust()); | |
6182 } | 6943 } |
6183 | 6944 |
6184 | 6945 |
6185 static const char* kStackTraceFromExtensionSource = | 6946 static const char* kStackTraceFromExtensionSource = |
6186 "function foo() {" | 6947 "function foo() {" |
6187 " throw new Error();" | 6948 " throw new Error();" |
6188 "}" | 6949 "}" |
6189 "function bar() {" | 6950 "function bar() {" |
6190 " foo();" | 6951 " foo();" |
6191 "}"; | 6952 "}"; |
6192 | 6953 |
6193 | 6954 |
6194 TEST(StackTraceInExtension) { | 6955 TEST(StackTraceInExtension) { |
6195 v8::HandleScope handle_scope(CcTest::isolate()); | 6956 v8::HandleScope handle_scope(CcTest::isolate()); |
6196 v8::RegisterExtension( | 6957 v8::RegisterExtension( |
6197 new Extension("stacktracetest", kStackTraceFromExtensionSource)); | 6958 new Extension("stacktracetest", kStackTraceFromExtensionSource)); |
6198 const char* extension_names[] = {"stacktracetest"}; | 6959 const char* extension_names[] = {"stacktracetest"}; |
6199 v8::ExtensionConfiguration extensions(1, extension_names); | 6960 v8::ExtensionConfiguration extensions(1, extension_names); |
6200 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 6961 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6201 Context::Scope lock(context); | 6962 Context::Scope lock(context); |
6202 CompileRun( | 6963 CompileRun( |
6203 "function user() { bar(); }" | 6964 "function user() { bar(); }" |
6204 "var error;" | 6965 "var error;" |
6205 "try{ user(); } catch (e) { error = e; }"); | 6966 "try{ user(); } catch (e) { error = e; }"); |
6206 CHECK_EQ(-1, CompileRun("error.stack.indexOf('foo')")->Int32Value()); | 6967 CHECK_EQ(-1, v8_run_int32value(v8_compile("error.stack.indexOf('foo')"))); |
6207 CHECK_EQ(-1, CompileRun("error.stack.indexOf('bar')")->Int32Value()); | 6968 CHECK_EQ(-1, v8_run_int32value(v8_compile("error.stack.indexOf('bar')"))); |
6208 CHECK_NE(-1, CompileRun("error.stack.indexOf('user')")->Int32Value()); | 6969 CHECK_NE(-1, v8_run_int32value(v8_compile("error.stack.indexOf('user')"))); |
6209 } | 6970 } |
6210 | 6971 |
6211 | 6972 |
6212 TEST(NullExtensions) { | 6973 TEST(NullExtensions) { |
6213 v8::HandleScope handle_scope(CcTest::isolate()); | 6974 v8::HandleScope handle_scope(CcTest::isolate()); |
6214 v8::RegisterExtension(new Extension("nulltest", NULL)); | 6975 v8::RegisterExtension(new Extension("nulltest", NULL)); |
6215 const char* extension_names[] = {"nulltest"}; | 6976 const char* extension_names[] = {"nulltest"}; |
6216 v8::ExtensionConfiguration extensions(1, extension_names); | 6977 v8::ExtensionConfiguration extensions(1, extension_names); |
6217 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 6978 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6218 Context::Scope lock(context); | 6979 Context::Scope lock(context); |
6219 v8::Handle<Value> result = CompileRun("1+3"); | 6980 v8::Local<Value> result = CompileRun("1+3"); |
6220 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); | 6981 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4)) |
6982 .FromJust()); | |
6221 } | 6983 } |
6222 | 6984 |
6223 | 6985 |
6224 static const char* kEmbeddedExtensionSource = | 6986 static const char* kEmbeddedExtensionSource = |
6225 "function Ret54321(){return 54321;}~~@@$" | 6987 "function Ret54321(){return 54321;}~~@@$" |
6226 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; | 6988 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; |
6227 static const int kEmbeddedExtensionSourceValidLen = 34; | 6989 static const int kEmbeddedExtensionSourceValidLen = 34; |
6228 | 6990 |
6229 | 6991 |
6230 TEST(ExtensionMissingSourceLength) { | 6992 TEST(ExtensionMissingSourceLength) { |
6231 v8::HandleScope handle_scope(CcTest::isolate()); | 6993 v8::HandleScope handle_scope(CcTest::isolate()); |
6232 v8::RegisterExtension( | 6994 v8::RegisterExtension( |
6233 new Extension("srclentest_fail", kEmbeddedExtensionSource)); | 6995 new Extension("srclentest_fail", kEmbeddedExtensionSource)); |
6234 const char* extension_names[] = {"srclentest_fail"}; | 6996 const char* extension_names[] = {"srclentest_fail"}; |
6235 v8::ExtensionConfiguration extensions(1, extension_names); | 6997 v8::ExtensionConfiguration extensions(1, extension_names); |
6236 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 6998 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6237 CHECK(0 == *context); | 6999 CHECK(0 == *context); |
6238 } | 7000 } |
6239 | 7001 |
6240 | 7002 |
6241 TEST(ExtensionWithSourceLength) { | 7003 TEST(ExtensionWithSourceLength) { |
6242 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; | 7004 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; |
6243 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { | 7005 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { |
6244 v8::HandleScope handle_scope(CcTest::isolate()); | 7006 v8::HandleScope handle_scope(CcTest::isolate()); |
6245 i::ScopedVector<char> extension_name(32); | 7007 i::ScopedVector<char> extension_name(32); |
6246 i::SNPrintF(extension_name, "ext #%d", source_len); | 7008 i::SNPrintF(extension_name, "ext #%d", source_len); |
6247 v8::RegisterExtension(new Extension( | 7009 v8::RegisterExtension(new Extension( |
6248 extension_name.start(), kEmbeddedExtensionSource, 0, 0, source_len)); | 7010 extension_name.start(), kEmbeddedExtensionSource, 0, 0, source_len)); |
6249 const char* extension_names[1] = {extension_name.start()}; | 7011 const char* extension_names[1] = {extension_name.start()}; |
6250 v8::ExtensionConfiguration extensions(1, extension_names); | 7012 v8::ExtensionConfiguration extensions(1, extension_names); |
6251 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7013 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6252 if (source_len == kEmbeddedExtensionSourceValidLen) { | 7014 if (source_len == kEmbeddedExtensionSourceValidLen) { |
6253 Context::Scope lock(context); | 7015 Context::Scope lock(context); |
6254 v8::Handle<Value> result = CompileRun("Ret54321()"); | 7016 v8::Local<Value> result = CompileRun("Ret54321()"); |
6255 CHECK(v8::Integer::New(CcTest::isolate(), 54321)->Equals(result)); | 7017 CHECK(v8::Integer::New(CcTest::isolate(), 54321) |
7018 ->Equals(context, result) | |
7019 .FromJust()); | |
6256 } else { | 7020 } else { |
6257 // Anything but exactly the right length should fail to compile. | 7021 // Anything but exactly the right length should fail to compile. |
6258 CHECK(0 == *context); | 7022 CHECK(0 == *context); |
6259 } | 7023 } |
6260 } | 7024 } |
6261 } | 7025 } |
6262 | 7026 |
6263 | 7027 |
6264 static const char* kEvalExtensionSource1 = | 7028 static const char* kEvalExtensionSource1 = |
6265 "function UseEval1() {" | 7029 "function UseEval1() {" |
(...skipping 11 matching lines...) Expand all Loading... | |
6277 " this.UseEval2 = e;" | 7041 " this.UseEval2 = e;" |
6278 "})()"; | 7042 "})()"; |
6279 | 7043 |
6280 | 7044 |
6281 TEST(UseEvalFromExtension) { | 7045 TEST(UseEvalFromExtension) { |
6282 v8::HandleScope handle_scope(CcTest::isolate()); | 7046 v8::HandleScope handle_scope(CcTest::isolate()); |
6283 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); | 7047 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); |
6284 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); | 7048 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); |
6285 const char* extension_names[] = {"evaltest1", "evaltest2"}; | 7049 const char* extension_names[] = {"evaltest1", "evaltest2"}; |
6286 v8::ExtensionConfiguration extensions(2, extension_names); | 7050 v8::ExtensionConfiguration extensions(2, extension_names); |
6287 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7051 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6288 Context::Scope lock(context); | 7052 Context::Scope lock(context); |
6289 v8::Handle<Value> result = CompileRun("UseEval1()"); | 7053 v8::Local<Value> result = CompileRun("UseEval1()"); |
6290 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); | 7054 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42)) |
7055 .FromJust()); | |
6291 result = CompileRun("UseEval2()"); | 7056 result = CompileRun("UseEval2()"); |
6292 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); | 7057 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42)) |
7058 .FromJust()); | |
6293 } | 7059 } |
6294 | 7060 |
6295 | 7061 |
6296 static const char* kWithExtensionSource1 = | 7062 static const char* kWithExtensionSource1 = |
6297 "function UseWith1() {" | 7063 "function UseWith1() {" |
6298 " var x = 42;" | 7064 " var x = 42;" |
6299 " with({x:87}) { return x; }" | 7065 " with({x:87}) { return x; }" |
6300 "}"; | 7066 "}"; |
6301 | 7067 |
6302 | 7068 |
6303 static const char* kWithExtensionSource2 = | 7069 static const char* kWithExtensionSource2 = |
6304 "(function() {" | 7070 "(function() {" |
6305 " var x = 42;" | 7071 " var x = 42;" |
6306 " function e() {" | 7072 " function e() {" |
6307 " with ({x:87}) { return x; }" | 7073 " with ({x:87}) { return x; }" |
6308 " }" | 7074 " }" |
6309 " this.UseWith2 = e;" | 7075 " this.UseWith2 = e;" |
6310 "})()"; | 7076 "})()"; |
6311 | 7077 |
6312 | 7078 |
6313 TEST(UseWithFromExtension) { | 7079 TEST(UseWithFromExtension) { |
6314 v8::HandleScope handle_scope(CcTest::isolate()); | 7080 v8::HandleScope handle_scope(CcTest::isolate()); |
6315 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); | 7081 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); |
6316 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); | 7082 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); |
6317 const char* extension_names[] = {"withtest1", "withtest2"}; | 7083 const char* extension_names[] = {"withtest1", "withtest2"}; |
6318 v8::ExtensionConfiguration extensions(2, extension_names); | 7084 v8::ExtensionConfiguration extensions(2, extension_names); |
6319 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7085 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6320 Context::Scope lock(context); | 7086 Context::Scope lock(context); |
6321 v8::Handle<Value> result = CompileRun("UseWith1()"); | 7087 v8::Local<Value> result = CompileRun("UseWith1()"); |
6322 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 87))); | 7088 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 87)) |
7089 .FromJust()); | |
6323 result = CompileRun("UseWith2()"); | 7090 result = CompileRun("UseWith2()"); |
6324 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 87))); | 7091 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 87)) |
7092 .FromJust()); | |
6325 } | 7093 } |
6326 | 7094 |
6327 | 7095 |
6328 TEST(AutoExtensions) { | 7096 TEST(AutoExtensions) { |
6329 v8::HandleScope handle_scope(CcTest::isolate()); | 7097 v8::HandleScope handle_scope(CcTest::isolate()); |
6330 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 7098 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
6331 extension->set_auto_enable(true); | 7099 extension->set_auto_enable(true); |
6332 v8::RegisterExtension(extension); | 7100 v8::RegisterExtension(extension); |
6333 v8::Handle<Context> context = Context::New(CcTest::isolate()); | 7101 v8::Local<Context> context = Context::New(CcTest::isolate()); |
6334 Context::Scope lock(context); | 7102 Context::Scope lock(context); |
6335 v8::Handle<Value> result = CompileRun("Foo()"); | 7103 v8::Local<Value> result = CompileRun("Foo()"); |
6336 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); | 7104 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4)) |
7105 .FromJust()); | |
6337 } | 7106 } |
6338 | 7107 |
6339 | 7108 |
6340 static const char* kSyntaxErrorInExtensionSource = "["; | 7109 static const char* kSyntaxErrorInExtensionSource = "["; |
6341 | 7110 |
6342 | 7111 |
6343 // Test that a syntax error in an extension does not cause a fatal | 7112 // Test that a syntax error in an extension does not cause a fatal |
6344 // error but results in an empty context. | 7113 // error but results in an empty context. |
6345 TEST(SyntaxErrorExtensions) { | 7114 TEST(SyntaxErrorExtensions) { |
6346 v8::HandleScope handle_scope(CcTest::isolate()); | 7115 v8::HandleScope handle_scope(CcTest::isolate()); |
6347 v8::RegisterExtension( | 7116 v8::RegisterExtension( |
6348 new Extension("syntaxerror", kSyntaxErrorInExtensionSource)); | 7117 new Extension("syntaxerror", kSyntaxErrorInExtensionSource)); |
6349 const char* extension_names[] = {"syntaxerror"}; | 7118 const char* extension_names[] = {"syntaxerror"}; |
6350 v8::ExtensionConfiguration extensions(1, extension_names); | 7119 v8::ExtensionConfiguration extensions(1, extension_names); |
6351 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7120 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6352 CHECK(context.IsEmpty()); | 7121 CHECK(context.IsEmpty()); |
6353 } | 7122 } |
6354 | 7123 |
6355 | 7124 |
6356 static const char* kExceptionInExtensionSource = "throw 42"; | 7125 static const char* kExceptionInExtensionSource = "throw 42"; |
6357 | 7126 |
6358 | 7127 |
6359 // Test that an exception when installing an extension does not cause | 7128 // Test that an exception when installing an extension does not cause |
6360 // a fatal error but results in an empty context. | 7129 // a fatal error but results in an empty context. |
6361 TEST(ExceptionExtensions) { | 7130 TEST(ExceptionExtensions) { |
6362 v8::HandleScope handle_scope(CcTest::isolate()); | 7131 v8::HandleScope handle_scope(CcTest::isolate()); |
6363 v8::RegisterExtension( | 7132 v8::RegisterExtension( |
6364 new Extension("exception", kExceptionInExtensionSource)); | 7133 new Extension("exception", kExceptionInExtensionSource)); |
6365 const char* extension_names[] = {"exception"}; | 7134 const char* extension_names[] = {"exception"}; |
6366 v8::ExtensionConfiguration extensions(1, extension_names); | 7135 v8::ExtensionConfiguration extensions(1, extension_names); |
6367 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7136 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6368 CHECK(context.IsEmpty()); | 7137 CHECK(context.IsEmpty()); |
6369 } | 7138 } |
6370 | 7139 |
6371 | 7140 |
6372 static const char* kNativeCallInExtensionSource = | 7141 static const char* kNativeCallInExtensionSource = |
6373 "function call_runtime_last_index_of(x) {" | 7142 "function call_runtime_last_index_of(x) {" |
6374 " return %StringLastIndexOf(x, 'bob', 10);" | 7143 " return %StringLastIndexOf(x, 'bob', 10);" |
6375 "}"; | 7144 "}"; |
6376 | 7145 |
6377 | 7146 |
6378 static const char* kNativeCallTest = | 7147 static const char* kNativeCallTest = |
6379 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; | 7148 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; |
6380 | 7149 |
6381 // Test that a native runtime calls are supported in extensions. | 7150 // Test that a native runtime calls are supported in extensions. |
6382 TEST(NativeCallInExtensions) { | 7151 TEST(NativeCallInExtensions) { |
6383 v8::HandleScope handle_scope(CcTest::isolate()); | 7152 v8::HandleScope handle_scope(CcTest::isolate()); |
6384 v8::RegisterExtension( | 7153 v8::RegisterExtension( |
6385 new Extension("nativecall", kNativeCallInExtensionSource)); | 7154 new Extension("nativecall", kNativeCallInExtensionSource)); |
6386 const char* extension_names[] = {"nativecall"}; | 7155 const char* extension_names[] = {"nativecall"}; |
6387 v8::ExtensionConfiguration extensions(1, extension_names); | 7156 v8::ExtensionConfiguration extensions(1, extension_names); |
6388 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7157 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6389 Context::Scope lock(context); | 7158 Context::Scope lock(context); |
6390 v8::Handle<Value> result = CompileRun(kNativeCallTest); | 7159 v8::Local<Value> result = CompileRun(kNativeCallTest); |
6391 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 3))); | 7160 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 3)) |
7161 .FromJust()); | |
6392 } | 7162 } |
6393 | 7163 |
6394 | 7164 |
6395 class NativeFunctionExtension : public Extension { | 7165 class NativeFunctionExtension : public Extension { |
6396 public: | 7166 public: |
6397 NativeFunctionExtension(const char* name, const char* source, | 7167 NativeFunctionExtension(const char* name, const char* source, |
6398 v8::FunctionCallback fun = &Echo) | 7168 v8::FunctionCallback fun = &Echo) |
6399 : Extension(name, source), function_(fun) {} | 7169 : Extension(name, source), function_(fun) {} |
6400 | 7170 |
6401 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 7171 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
6402 v8::Isolate* isolate, v8::Handle<v8::String> name) { | 7172 v8::Isolate* isolate, v8::Local<v8::String> name) { |
6403 return v8::FunctionTemplate::New(isolate, function_); | 7173 return v8::FunctionTemplate::New(isolate, function_); |
6404 } | 7174 } |
6405 | 7175 |
6406 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7176 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { |
6407 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); | 7177 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); |
6408 } | 7178 } |
6409 | 7179 |
6410 private: | 7180 private: |
6411 v8::FunctionCallback function_; | 7181 v8::FunctionCallback function_; |
6412 }; | 7182 }; |
6413 | 7183 |
6414 | 7184 |
6415 TEST(NativeFunctionDeclaration) { | 7185 TEST(NativeFunctionDeclaration) { |
6416 v8::HandleScope handle_scope(CcTest::isolate()); | 7186 v8::HandleScope handle_scope(CcTest::isolate()); |
6417 const char* name = "nativedecl"; | 7187 const char* name = "nativedecl"; |
6418 v8::RegisterExtension( | 7188 v8::RegisterExtension( |
6419 new NativeFunctionExtension(name, "native function foo();")); | 7189 new NativeFunctionExtension(name, "native function foo();")); |
6420 const char* extension_names[] = {name}; | 7190 const char* extension_names[] = {name}; |
6421 v8::ExtensionConfiguration extensions(1, extension_names); | 7191 v8::ExtensionConfiguration extensions(1, extension_names); |
6422 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7192 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6423 Context::Scope lock(context); | 7193 Context::Scope lock(context); |
6424 v8::Handle<Value> result = CompileRun("foo(42);"); | 7194 v8::Local<Value> result = CompileRun("foo(42);"); |
6425 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); | 7195 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42)) |
7196 .FromJust()); | |
6426 } | 7197 } |
6427 | 7198 |
6428 | 7199 |
6429 TEST(NativeFunctionDeclarationError) { | 7200 TEST(NativeFunctionDeclarationError) { |
6430 v8::HandleScope handle_scope(CcTest::isolate()); | 7201 v8::HandleScope handle_scope(CcTest::isolate()); |
6431 const char* name = "nativedeclerr"; | 7202 const char* name = "nativedeclerr"; |
6432 // Syntax error in extension code. | 7203 // Syntax error in extension code. |
6433 v8::RegisterExtension( | 7204 v8::RegisterExtension( |
6434 new NativeFunctionExtension(name, "native\nfunction foo();")); | 7205 new NativeFunctionExtension(name, "native\nfunction foo();")); |
6435 const char* extension_names[] = {name}; | 7206 const char* extension_names[] = {name}; |
6436 v8::ExtensionConfiguration extensions(1, extension_names); | 7207 v8::ExtensionConfiguration extensions(1, extension_names); |
6437 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7208 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6438 CHECK(context.IsEmpty()); | 7209 CHECK(context.IsEmpty()); |
6439 } | 7210 } |
6440 | 7211 |
6441 | 7212 |
6442 TEST(NativeFunctionDeclarationErrorEscape) { | 7213 TEST(NativeFunctionDeclarationErrorEscape) { |
6443 v8::HandleScope handle_scope(CcTest::isolate()); | 7214 v8::HandleScope handle_scope(CcTest::isolate()); |
6444 const char* name = "nativedeclerresc"; | 7215 const char* name = "nativedeclerresc"; |
6445 // Syntax error in extension code - escape code in "native" means that | 7216 // Syntax error in extension code - escape code in "native" means that |
6446 // it's not treated as a keyword. | 7217 // it's not treated as a keyword. |
6447 v8::RegisterExtension( | 7218 v8::RegisterExtension( |
6448 new NativeFunctionExtension(name, "nativ\\u0065 function foo();")); | 7219 new NativeFunctionExtension(name, "nativ\\u0065 function foo();")); |
6449 const char* extension_names[] = {name}; | 7220 const char* extension_names[] = {name}; |
6450 v8::ExtensionConfiguration extensions(1, extension_names); | 7221 v8::ExtensionConfiguration extensions(1, extension_names); |
6451 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); | 7222 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions); |
6452 CHECK(context.IsEmpty()); | 7223 CHECK(context.IsEmpty()); |
6453 } | 7224 } |
6454 | 7225 |
6455 | 7226 |
6456 static void CheckDependencies(const char* name, const char* expected) { | 7227 static void CheckDependencies(const char* name, const char* expected) { |
6457 v8::HandleScope handle_scope(CcTest::isolate()); | 7228 v8::HandleScope handle_scope(CcTest::isolate()); |
6458 v8::ExtensionConfiguration config(1, &name); | 7229 v8::ExtensionConfiguration config(1, &name); |
6459 LocalContext context(&config); | 7230 LocalContext context(&config); |
6460 CHECK(String::NewFromUtf8(CcTest::isolate(), expected) | 7231 CHECK( |
6461 ->Equals(context->Global()->Get(v8_str("loaded")))); | 7232 v8_str(expected) |
7233 ->Equals(context.local(), context->Global() | |
7234 ->Get(context.local(), v8_str("loaded")) | |
7235 .ToLocalChecked()) | |
7236 .FromJust()); | |
6462 } | 7237 } |
6463 | 7238 |
6464 | 7239 |
6465 /* | 7240 /* |
6466 * Configuration: | 7241 * Configuration: |
6467 * | 7242 * |
6468 * /-- B <--\ | 7243 * /-- B <--\ |
6469 * A <- -- D <-- E | 7244 * A <- -- D <-- E |
6470 * \-- C <--/ | 7245 * \-- C <--/ |
6471 */ | 7246 */ |
6472 THREADED_TEST(ExtensionDependency) { | 7247 THREADED_TEST(ExtensionDependency) { |
6473 static const char* kEDeps[] = {"D"}; | 7248 static const char* kEDeps[] = {"D"}; |
6474 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps)); | 7249 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps)); |
6475 static const char* kDDeps[] = {"B", "C"}; | 7250 static const char* kDDeps[] = {"B", "C"}; |
6476 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps)); | 7251 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps)); |
6477 static const char* kBCDeps[] = {"A"}; | 7252 static const char* kBCDeps[] = {"A"}; |
6478 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps)); | 7253 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps)); |
6479 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps)); | 7254 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps)); |
6480 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';")); | 7255 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';")); |
6481 CheckDependencies("A", "undefinedA"); | 7256 CheckDependencies("A", "undefinedA"); |
6482 CheckDependencies("B", "undefinedAB"); | 7257 CheckDependencies("B", "undefinedAB"); |
6483 CheckDependencies("C", "undefinedAC"); | 7258 CheckDependencies("C", "undefinedAC"); |
6484 CheckDependencies("D", "undefinedABCD"); | 7259 CheckDependencies("D", "undefinedABCD"); |
6485 CheckDependencies("E", "undefinedABCDE"); | 7260 CheckDependencies("E", "undefinedABCDE"); |
6486 v8::HandleScope handle_scope(CcTest::isolate()); | 7261 v8::HandleScope handle_scope(CcTest::isolate()); |
6487 static const char* exts[2] = {"C", "E"}; | 7262 static const char* exts[2] = {"C", "E"}; |
6488 v8::ExtensionConfiguration config(2, exts); | 7263 v8::ExtensionConfiguration config(2, exts); |
6489 LocalContext context(&config); | 7264 LocalContext context(&config); |
6490 CHECK(v8_str("undefinedACBDE") | 7265 CHECK( |
6491 ->Equals(context->Global()->Get(v8_str("loaded")))); | 7266 v8_str("undefinedACBDE") |
7267 ->Equals(context.local(), context->Global() | |
7268 ->Get(context.local(), v8_str("loaded")) | |
7269 .ToLocalChecked()) | |
7270 .FromJust()); | |
6492 } | 7271 } |
6493 | 7272 |
6494 | 7273 |
6495 static const char* kExtensionTestScript = | 7274 static const char* kExtensionTestScript = |
6496 "native function A();" | 7275 "native function A();" |
6497 "native function B();" | 7276 "native function B();" |
6498 "native function C();" | 7277 "native function C();" |
6499 "function Foo(i) {" | 7278 "function Foo(i) {" |
6500 " if (i == 0) return A();" | 7279 " if (i == 0) return A();" |
6501 " if (i == 1) return B();" | 7280 " if (i == 1) return B();" |
6502 " if (i == 2) return C();" | 7281 " if (i == 2) return C();" |
6503 "}"; | 7282 "}"; |
6504 | 7283 |
6505 | 7284 |
6506 static void CallFun(const v8::FunctionCallbackInfo<v8::Value>& args) { | 7285 static void CallFun(const v8::FunctionCallbackInfo<v8::Value>& args) { |
6507 ApiTestFuzzer::Fuzz(); | 7286 ApiTestFuzzer::Fuzz(); |
6508 if (args.IsConstructCall()) { | 7287 if (args.IsConstructCall()) { |
6509 args.This()->Set(v8_str("data"), args.Data()); | 7288 CHECK(args.This() |
7289 ->Set(args.GetIsolate()->GetCurrentContext(), v8_str("data"), | |
7290 args.Data()) | |
7291 .FromJust()); | |
6510 args.GetReturnValue().SetNull(); | 7292 args.GetReturnValue().SetNull(); |
6511 return; | 7293 return; |
6512 } | 7294 } |
6513 args.GetReturnValue().Set(args.Data()); | 7295 args.GetReturnValue().Set(args.Data()); |
6514 } | 7296 } |
6515 | 7297 |
6516 | 7298 |
6517 class FunctionExtension : public Extension { | 7299 class FunctionExtension : public Extension { |
6518 public: | 7300 public: |
6519 FunctionExtension() : Extension("functiontest", kExtensionTestScript) {} | 7301 FunctionExtension() : Extension("functiontest", kExtensionTestScript) {} |
6520 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( | 7302 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
6521 v8::Isolate* isolate, v8::Handle<String> name); | 7303 v8::Isolate* isolate, v8::Local<String> name); |
6522 }; | 7304 }; |
6523 | 7305 |
6524 | 7306 |
6525 static int lookup_count = 0; | 7307 static int lookup_count = 0; |
6526 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( | 7308 v8::Local<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( |
6527 v8::Isolate* isolate, v8::Handle<String> name) { | 7309 v8::Isolate* isolate, v8::Local<String> name) { |
6528 lookup_count++; | 7310 lookup_count++; |
6529 if (name->Equals(v8_str("A"))) { | 7311 if (name->Equals(isolate->GetCurrentContext(), v8_str("A")).FromJust()) { |
6530 return v8::FunctionTemplate::New(isolate, CallFun, | 7312 return v8::FunctionTemplate::New(isolate, CallFun, |
6531 v8::Integer::New(isolate, 8)); | 7313 v8::Integer::New(isolate, 8)); |
6532 } else if (name->Equals(v8_str("B"))) { | 7314 } else if (name->Equals(isolate->GetCurrentContext(), v8_str("B")) |
7315 .FromJust()) { | |
6533 return v8::FunctionTemplate::New(isolate, CallFun, | 7316 return v8::FunctionTemplate::New(isolate, CallFun, |
6534 v8::Integer::New(isolate, 7)); | 7317 v8::Integer::New(isolate, 7)); |
6535 } else if (name->Equals(v8_str("C"))) { | 7318 } else if (name->Equals(isolate->GetCurrentContext(), v8_str("C")) |
7319 .FromJust()) { | |
6536 return v8::FunctionTemplate::New(isolate, CallFun, | 7320 return v8::FunctionTemplate::New(isolate, CallFun, |
6537 v8::Integer::New(isolate, 6)); | 7321 v8::Integer::New(isolate, 6)); |
6538 } else { | 7322 } else { |
6539 return v8::Handle<v8::FunctionTemplate>(); | 7323 return v8::Local<v8::FunctionTemplate>(); |
6540 } | 7324 } |
6541 } | 7325 } |
6542 | 7326 |
6543 | 7327 |
6544 THREADED_TEST(FunctionLookup) { | 7328 THREADED_TEST(FunctionLookup) { |
6545 v8::RegisterExtension(new FunctionExtension()); | 7329 v8::RegisterExtension(new FunctionExtension()); |
6546 v8::HandleScope handle_scope(CcTest::isolate()); | 7330 v8::HandleScope handle_scope(CcTest::isolate()); |
6547 static const char* exts[1] = {"functiontest"}; | 7331 static const char* exts[1] = {"functiontest"}; |
6548 v8::ExtensionConfiguration config(1, exts); | 7332 v8::ExtensionConfiguration config(1, exts); |
6549 LocalContext context(&config); | 7333 LocalContext context(&config); |
6550 CHECK_EQ(3, lookup_count); | 7334 CHECK_EQ(3, lookup_count); |
6551 CHECK(v8::Integer::New(CcTest::isolate(), 8)->Equals(CompileRun("Foo(0)"))); | 7335 CHECK(v8::Integer::New(CcTest::isolate(), 8) |
6552 CHECK(v8::Integer::New(CcTest::isolate(), 7)->Equals(CompileRun("Foo(1)"))); | 7336 ->Equals(context.local(), CompileRun("Foo(0)")) |
6553 CHECK(v8::Integer::New(CcTest::isolate(), 6)->Equals(CompileRun("Foo(2)"))); | 7337 .FromJust()); |
7338 CHECK(v8::Integer::New(CcTest::isolate(), 7) | |
7339 ->Equals(context.local(), CompileRun("Foo(1)")) | |
7340 .FromJust()); | |
7341 CHECK(v8::Integer::New(CcTest::isolate(), 6) | |
7342 ->Equals(context.local(), CompileRun("Foo(2)")) | |
7343 .FromJust()); | |
6554 } | 7344 } |
6555 | 7345 |
6556 | 7346 |
6557 THREADED_TEST(NativeFunctionConstructCall) { | 7347 THREADED_TEST(NativeFunctionConstructCall) { |
6558 v8::RegisterExtension(new FunctionExtension()); | 7348 v8::RegisterExtension(new FunctionExtension()); |
6559 v8::HandleScope handle_scope(CcTest::isolate()); | 7349 v8::HandleScope handle_scope(CcTest::isolate()); |
6560 static const char* exts[1] = {"functiontest"}; | 7350 static const char* exts[1] = {"functiontest"}; |
6561 v8::ExtensionConfiguration config(1, exts); | 7351 v8::ExtensionConfiguration config(1, exts); |
6562 LocalContext context(&config); | 7352 LocalContext context(&config); |
6563 for (int i = 0; i < 10; i++) { | 7353 for (int i = 0; i < 10; i++) { |
6564 // Run a few times to ensure that allocation of objects doesn't | 7354 // Run a few times to ensure that allocation of objects doesn't |
6565 // change behavior of a constructor function. | 7355 // change behavior of a constructor function. |
6566 CHECK(v8::Integer::New(CcTest::isolate(), 8) | 7356 CHECK(v8::Integer::New(CcTest::isolate(), 8) |
6567 ->Equals(CompileRun("(new A()).data"))); | 7357 ->Equals(context.local(), CompileRun("(new A()).data")) |
7358 .FromJust()); | |
6568 CHECK(v8::Integer::New(CcTest::isolate(), 7) | 7359 CHECK(v8::Integer::New(CcTest::isolate(), 7) |
6569 ->Equals(CompileRun("(new B()).data"))); | 7360 ->Equals(context.local(), CompileRun("(new B()).data")) |
7361 .FromJust()); | |
6570 CHECK(v8::Integer::New(CcTest::isolate(), 6) | 7362 CHECK(v8::Integer::New(CcTest::isolate(), 6) |
6571 ->Equals(CompileRun("(new C()).data"))); | 7363 ->Equals(context.local(), CompileRun("(new C()).data")) |
7364 .FromJust()); | |
6572 } | 7365 } |
6573 } | 7366 } |
6574 | 7367 |
6575 | 7368 |
6576 static const char* last_location; | 7369 static const char* last_location; |
6577 static const char* last_message; | 7370 static const char* last_message; |
6578 void StoringErrorCallback(const char* location, const char* message) { | 7371 void StoringErrorCallback(const char* location, const char* message) { |
6579 if (last_location == NULL) { | 7372 if (last_location == NULL) { |
6580 last_location = location; | 7373 last_location = location; |
6581 last_message = message; | 7374 last_message = message; |
6582 } | 7375 } |
6583 } | 7376 } |
6584 | 7377 |
6585 | 7378 |
6586 // ErrorReporting creates a circular extensions configuration and | 7379 // ErrorReporting creates a circular extensions configuration and |
6587 // tests that the fatal error handler gets called. This renders V8 | 7380 // tests that the fatal error handler gets called. This renders V8 |
6588 // unusable and therefore this test cannot be run in parallel. | 7381 // unusable and therefore this test cannot be run in parallel. |
6589 TEST(ErrorReporting) { | 7382 TEST(ErrorReporting) { |
6590 v8::V8::SetFatalErrorHandler(StoringErrorCallback); | 7383 CcTest::isolate()->SetFatalErrorHandler(StoringErrorCallback); |
6591 static const char* aDeps[] = {"B"}; | 7384 static const char* aDeps[] = {"B"}; |
6592 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); | 7385 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); |
6593 static const char* bDeps[] = {"A"}; | 7386 static const char* bDeps[] = {"A"}; |
6594 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); | 7387 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); |
6595 last_location = NULL; | 7388 last_location = NULL; |
6596 v8::ExtensionConfiguration config(1, bDeps); | 7389 v8::ExtensionConfiguration config(1, bDeps); |
6597 v8::Handle<Context> context = Context::New(CcTest::isolate(), &config); | 7390 v8::Local<Context> context = Context::New(CcTest::isolate(), &config); |
6598 CHECK(context.IsEmpty()); | 7391 CHECK(context.IsEmpty()); |
6599 CHECK(last_location); | 7392 CHECK(last_location); |
6600 } | 7393 } |
6601 | 7394 |
6602 | 7395 |
6603 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, | 7396 static void MissingScriptInfoMessageListener(v8::Local<v8::Message> message, |
6604 v8::Handle<Value> data) { | 7397 v8::Local<Value> data) { |
7398 v8::Isolate* isolate = CcTest::isolate(); | |
7399 Local<Context> context = isolate->GetCurrentContext(); | |
6605 CHECK(message->GetScriptOrigin().ResourceName()->IsUndefined()); | 7400 CHECK(message->GetScriptOrigin().ResourceName()->IsUndefined()); |
6606 CHECK(v8::Undefined(CcTest::isolate()) | 7401 CHECK(v8::Undefined(isolate) |
6607 ->Equals(message->GetScriptOrigin().ResourceName())); | 7402 ->Equals(context, message->GetScriptOrigin().ResourceName()) |
6608 message->GetLineNumber(); | 7403 .FromJust()); |
6609 message->GetSourceLine(); | 7404 message->GetLineNumber(context).FromJust(); |
7405 message->GetSourceLine(context).ToLocalChecked(); | |
6610 } | 7406 } |
6611 | 7407 |
6612 | 7408 |
6613 THREADED_TEST(ErrorWithMissingScriptInfo) { | 7409 THREADED_TEST(ErrorWithMissingScriptInfo) { |
6614 LocalContext context; | 7410 LocalContext context; |
6615 v8::HandleScope scope(context->GetIsolate()); | 7411 v8::HandleScope scope(context->GetIsolate()); |
6616 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); | 7412 context->GetIsolate()->AddMessageListener(MissingScriptInfoMessageListener); |
6617 CompileRun("throw Error()"); | 7413 CompileRun("throw Error()"); |
6618 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); | 7414 context->GetIsolate()->RemoveMessageListeners( |
7415 MissingScriptInfoMessageListener); | |
6619 } | 7416 } |
6620 | 7417 |
6621 | 7418 |
6622 struct FlagAndPersistent { | 7419 struct FlagAndPersistent { |
6623 bool flag; | 7420 bool flag; |
6624 v8::Global<v8::Object> handle; | 7421 v8::Global<v8::Object> handle; |
6625 }; | 7422 }; |
6626 | 7423 |
6627 | 7424 |
6628 static void SetFlag(const v8::WeakCallbackInfo<FlagAndPersistent>& data) { | 7425 static void SetFlag(const v8::WeakCallbackInfo<FlagAndPersistent>& data) { |
6629 data.GetParameter()->flag = true; | 7426 data.GetParameter()->flag = true; |
6630 data.GetParameter()->handle.Reset(); | 7427 data.GetParameter()->handle.Reset(); |
6631 } | 7428 } |
6632 | 7429 |
6633 | 7430 |
6634 static void IndependentWeakHandle(bool global_gc, bool interlinked) { | 7431 static void IndependentWeakHandle(bool global_gc, bool interlinked) { |
6635 v8::Isolate* iso = CcTest::isolate(); | 7432 v8::Isolate* iso = CcTest::isolate(); |
6636 v8::HandleScope scope(iso); | 7433 v8::HandleScope scope(iso); |
6637 v8::Handle<Context> context = Context::New(iso); | 7434 v8::Local<Context> context = Context::New(iso); |
6638 Context::Scope context_scope(context); | 7435 Context::Scope context_scope(context); |
6639 | 7436 |
6640 FlagAndPersistent object_a, object_b; | 7437 FlagAndPersistent object_a, object_b; |
6641 | 7438 |
6642 intptr_t big_heap_size; | 7439 intptr_t big_heap_size; |
6643 | 7440 |
6644 { | 7441 { |
6645 v8::HandleScope handle_scope(iso); | 7442 v8::HandleScope handle_scope(iso); |
6646 Local<Object> a(v8::Object::New(iso)); | 7443 Local<Object> a(v8::Object::New(iso)); |
6647 Local<Object> b(v8::Object::New(iso)); | 7444 Local<Object> b(v8::Object::New(iso)); |
6648 object_a.handle.Reset(iso, a); | 7445 object_a.handle.Reset(iso, a); |
6649 object_b.handle.Reset(iso, b); | 7446 object_b.handle.Reset(iso, b); |
6650 if (interlinked) { | 7447 if (interlinked) { |
6651 a->Set(v8_str("x"), b); | 7448 a->Set(context, v8_str("x"), b).FromJust(); |
6652 b->Set(v8_str("x"), a); | 7449 b->Set(context, v8_str("x"), a).FromJust(); |
6653 } | 7450 } |
6654 if (global_gc) { | 7451 if (global_gc) { |
6655 CcTest::heap()->CollectAllGarbage(); | 7452 CcTest::heap()->CollectAllGarbage(); |
6656 } else { | 7453 } else { |
6657 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 7454 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
6658 } | 7455 } |
6659 // We are relying on this creating a big flag array and reserving the space | 7456 // We are relying on this creating a big flag array and reserving the space |
6660 // up front. | 7457 // up front. |
6661 v8::Handle<Value> big_array = CompileRun("new Array(5000)"); | 7458 v8::Local<Value> big_array = CompileRun("new Array(5000)"); |
6662 a->Set(v8_str("y"), big_array); | 7459 a->Set(context, v8_str("y"), big_array).FromJust(); |
6663 big_heap_size = CcTest::heap()->SizeOfObjects(); | 7460 big_heap_size = CcTest::heap()->SizeOfObjects(); |
6664 } | 7461 } |
6665 | 7462 |
6666 object_a.flag = false; | 7463 object_a.flag = false; |
6667 object_b.flag = false; | 7464 object_b.flag = false; |
6668 object_a.handle.SetWeak(&object_a, &SetFlag, | 7465 object_a.handle.SetWeak(&object_a, &SetFlag, |
6669 v8::WeakCallbackType::kParameter); | 7466 v8::WeakCallbackType::kParameter); |
6670 object_b.handle.SetWeak(&object_b, &SetFlag, | 7467 object_b.handle.SetWeak(&object_b, &SetFlag, |
6671 v8::WeakCallbackType::kParameter); | 7468 v8::WeakCallbackType::kParameter); |
6672 CHECK(!object_b.handle.IsIndependent()); | 7469 CHECK(!object_b.handle.IsIndependent()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6719 private: | 7516 private: |
6720 int y_; | 7517 int y_; |
6721 int x_; | 7518 int x_; |
6722 }; | 7519 }; |
6723 | 7520 |
6724 | 7521 |
6725 void CheckInternalFields( | 7522 void CheckInternalFields( |
6726 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { | 7523 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { |
6727 v8::Persistent<v8::Object>* handle = data.GetParameter(); | 7524 v8::Persistent<v8::Object>* handle = data.GetParameter(); |
6728 handle->Reset(); | 7525 handle->Reset(); |
6729 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField1()); | 7526 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField(0)); |
6730 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField2()); | 7527 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField(1)); |
6731 CHECK_EQ(42, t1->x()); | 7528 CHECK_EQ(42, t1->x()); |
6732 CHECK_EQ(103, t2->x()); | 7529 CHECK_EQ(103, t2->x()); |
6733 t1->set_x(1729); | 7530 t1->set_x(1729); |
6734 t2->set_x(33550336); | 7531 t2->set_x(33550336); |
6735 } | 7532 } |
6736 | 7533 |
6737 | 7534 |
6738 void InternalFieldCallback(bool global_gc) { | 7535 void InternalFieldCallback(bool global_gc) { |
6739 LocalContext env; | 7536 LocalContext env; |
6740 v8::Isolate* isolate = env->GetIsolate(); | 7537 v8::Isolate* isolate = env->GetIsolate(); |
6741 v8::HandleScope scope(isolate); | 7538 v8::HandleScope scope(isolate); |
6742 | 7539 |
6743 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 7540 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
6744 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 7541 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
6745 Trivial* t1; | 7542 Trivial* t1; |
6746 Trivial2* t2; | 7543 Trivial2* t2; |
6747 instance_templ->SetInternalFieldCount(2); | 7544 instance_templ->SetInternalFieldCount(2); |
6748 { | 7545 { |
6749 v8::HandleScope scope(isolate); | 7546 v8::HandleScope scope(isolate); |
6750 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); | 7547 Local<v8::Object> obj = templ->GetFunction(env.local()) |
7548 .ToLocalChecked() | |
7549 ->NewInstance(env.local()) | |
7550 .ToLocalChecked(); | |
6751 v8::Persistent<v8::Object> handle(isolate, obj); | 7551 v8::Persistent<v8::Object> handle(isolate, obj); |
6752 CHECK_EQ(2, obj->InternalFieldCount()); | 7552 CHECK_EQ(2, obj->InternalFieldCount()); |
6753 CHECK(obj->GetInternalField(0)->IsUndefined()); | 7553 CHECK(obj->GetInternalField(0)->IsUndefined()); |
6754 t1 = new Trivial(42); | 7554 t1 = new Trivial(42); |
6755 t2 = new Trivial2(103, 9); | 7555 t2 = new Trivial2(103, 9); |
6756 | 7556 |
6757 obj->SetAlignedPointerInInternalField(0, t1); | 7557 obj->SetAlignedPointerInInternalField(0, t1); |
6758 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); | 7558 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); |
6759 CHECK_EQ(42, t1->x()); | 7559 CHECK_EQ(42, t1->x()); |
6760 | 7560 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6798 } | 7598 } |
6799 | 7599 |
6800 | 7600 |
6801 void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) { | 7601 void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) { |
6802 using v8::Context; | 7602 using v8::Context; |
6803 using v8::Local; | 7603 using v8::Local; |
6804 using v8::Object; | 7604 using v8::Object; |
6805 | 7605 |
6806 v8::Isolate* iso = CcTest::isolate(); | 7606 v8::Isolate* iso = CcTest::isolate(); |
6807 v8::HandleScope scope(iso); | 7607 v8::HandleScope scope(iso); |
6808 v8::Handle<Context> context = Context::New(iso); | 7608 v8::Local<Context> context = Context::New(iso); |
6809 Context::Scope context_scope(context); | 7609 Context::Scope context_scope(context); |
6810 | 7610 |
6811 FlagAndPersistent object_a, object_b; | 7611 FlagAndPersistent object_a, object_b; |
6812 | 7612 |
6813 { | 7613 { |
6814 v8::HandleScope handle_scope(iso); | 7614 v8::HandleScope handle_scope(iso); |
6815 Local<Object> a(v8::Object::New(iso)); | 7615 Local<Object> a(v8::Object::New(iso)); |
6816 Local<Object> b(v8::Object::New(iso)); | 7616 Local<Object> b(v8::Object::New(iso)); |
6817 object_a.handle.Reset(iso, a); | 7617 object_a.handle.Reset(iso, a); |
6818 object_b.handle.Reset(iso, b); | 7618 object_b.handle.Reset(iso, b); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6879 const v8::WeakCallbackInfo<FlagAndPersistent>& data) { | 7679 const v8::WeakCallbackInfo<FlagAndPersistent>& data) { |
6880 data.GetParameter()->handle.Reset(); | 7680 data.GetParameter()->handle.Reset(); |
6881 data.SetSecondPassCallback(ForceMarkSweep2); | 7681 data.SetSecondPassCallback(ForceMarkSweep2); |
6882 } | 7682 } |
6883 | 7683 |
6884 | 7684 |
6885 THREADED_TEST(GCFromWeakCallbacks) { | 7685 THREADED_TEST(GCFromWeakCallbacks) { |
6886 v8::Isolate* isolate = CcTest::isolate(); | 7686 v8::Isolate* isolate = CcTest::isolate(); |
6887 v8::Locker locker(CcTest::isolate()); | 7687 v8::Locker locker(CcTest::isolate()); |
6888 v8::HandleScope scope(isolate); | 7688 v8::HandleScope scope(isolate); |
6889 v8::Handle<Context> context = Context::New(isolate); | 7689 v8::Local<Context> context = Context::New(isolate); |
6890 Context::Scope context_scope(context); | 7690 Context::Scope context_scope(context); |
6891 | 7691 |
6892 static const int kNumberOfGCTypes = 2; | 7692 static const int kNumberOfGCTypes = 2; |
6893 typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback; | 7693 typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback; |
6894 Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1, | 7694 Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1, |
6895 &ForceMarkSweep1}; | 7695 &ForceMarkSweep1}; |
6896 | 7696 |
6897 typedef void (*GCInvoker)(); | 7697 typedef void (*GCInvoker)(); |
6898 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; | 7698 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; |
6899 | 7699 |
6900 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { | 7700 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { |
6901 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { | 7701 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { |
6902 FlagAndPersistent object; | 7702 FlagAndPersistent object; |
6903 { | 7703 { |
6904 v8::HandleScope handle_scope(isolate); | 7704 v8::HandleScope handle_scope(isolate); |
6905 object.handle.Reset(isolate, v8::Object::New(isolate)); | 7705 object.handle.Reset(isolate, v8::Object::New(isolate)); |
6906 } | 7706 } |
6907 object.flag = false; | 7707 object.flag = false; |
6908 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc], | 7708 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc], |
6909 v8::WeakCallbackType::kParameter); | 7709 v8::WeakCallbackType::kParameter); |
6910 object.handle.MarkIndependent(); | 7710 object.handle.MarkIndependent(); |
6911 invoke_gc[outer_gc](); | 7711 invoke_gc[outer_gc](); |
6912 EmptyMessageQueues(isolate); | 7712 EmptyMessageQueues(isolate); |
6913 CHECK(object.flag); | 7713 CHECK(object.flag); |
6914 } | 7714 } |
6915 } | 7715 } |
6916 } | 7716 } |
6917 | 7717 |
6918 | 7718 |
6919 v8::Handle<Function> args_fun; | 7719 v8::Local<Function> args_fun; |
6920 | 7720 |
6921 | 7721 |
6922 static void ArgumentsTestCallback( | 7722 static void ArgumentsTestCallback( |
6923 const v8::FunctionCallbackInfo<v8::Value>& args) { | 7723 const v8::FunctionCallbackInfo<v8::Value>& args) { |
6924 ApiTestFuzzer::Fuzz(); | 7724 ApiTestFuzzer::Fuzz(); |
6925 v8::Isolate* isolate = args.GetIsolate(); | 7725 v8::Isolate* isolate = args.GetIsolate(); |
6926 CHECK(args_fun->Equals(args.Callee())); | 7726 Local<Context> context = isolate->GetCurrentContext(); |
7727 CHECK(args_fun->Equals(context, args.Callee()).FromJust()); | |
6927 CHECK_EQ(3, args.Length()); | 7728 CHECK_EQ(3, args.Length()); |
6928 CHECK(v8::Integer::New(isolate, 1)->Equals(args[0])); | 7729 CHECK(v8::Integer::New(isolate, 1)->Equals(context, args[0]).FromJust()); |
6929 CHECK(v8::Integer::New(isolate, 2)->Equals(args[1])); | 7730 CHECK(v8::Integer::New(isolate, 2)->Equals(context, args[1]).FromJust()); |
6930 CHECK(v8::Integer::New(isolate, 3)->Equals(args[2])); | 7731 CHECK(v8::Integer::New(isolate, 3)->Equals(context, args[2]).FromJust()); |
6931 CHECK(v8::Undefined(isolate)->Equals(args[3])); | 7732 CHECK(v8::Undefined(isolate)->Equals(context, args[3]).FromJust()); |
6932 v8::HandleScope scope(args.GetIsolate()); | 7733 v8::HandleScope scope(args.GetIsolate()); |
6933 CcTest::heap()->CollectAllGarbage(); | 7734 CcTest::heap()->CollectAllGarbage(); |
6934 } | 7735 } |
6935 | 7736 |
6936 | 7737 |
6937 THREADED_TEST(Arguments) { | 7738 THREADED_TEST(Arguments) { |
6938 v8::Isolate* isolate = CcTest::isolate(); | 7739 v8::Isolate* isolate = CcTest::isolate(); |
6939 v8::HandleScope scope(isolate); | 7740 v8::HandleScope scope(isolate); |
6940 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); | 7741 v8::Local<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); |
6941 global->Set(v8_str("f"), | 7742 global->Set(v8_str("f"), |
6942 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); | 7743 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); |
6943 LocalContext context(NULL, global); | 7744 LocalContext context(NULL, global); |
6944 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); | 7745 args_fun = context->Global() |
6945 v8_compile("f(1, 2, 3)")->Run(); | 7746 ->Get(context.local(), v8_str("f")) |
7747 .ToLocalChecked() | |
7748 .As<Function>(); | |
7749 v8_compile("f(1, 2, 3)")->Run(context.local()).ToLocalChecked(); | |
6946 } | 7750 } |
6947 | 7751 |
6948 | 7752 |
6949 static int p_getter_count; | 7753 static int p_getter_count; |
6950 static int p_getter_count2; | 7754 static int p_getter_count2; |
6951 | 7755 |
6952 | 7756 |
6953 static void PGetter(Local<String> name, | 7757 static void PGetter(Local<Name> name, |
6954 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7758 const v8::PropertyCallbackInfo<v8::Value>& info) { |
6955 ApiTestFuzzer::Fuzz(); | 7759 ApiTestFuzzer::Fuzz(); |
6956 p_getter_count++; | 7760 p_getter_count++; |
6957 v8::Handle<v8::Object> global = | 7761 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
6958 info.GetIsolate()->GetCurrentContext()->Global(); | 7762 v8::Local<v8::Object> global = context->Global(); |
6959 CHECK(info.Holder()->Equals(global->Get(v8_str("o1")))); | 7763 CHECK( |
6960 if (name->Equals(v8_str("p1"))) { | 7764 info.Holder() |
6961 CHECK(info.This()->Equals(global->Get(v8_str("o1")))); | 7765 ->Equals(context, global->Get(context, v8_str("o1")).ToLocalChecked()) |
6962 } else if (name->Equals(v8_str("p2"))) { | 7766 .FromJust()); |
6963 CHECK(info.This()->Equals(global->Get(v8_str("o2")))); | 7767 if (name->Equals(context, v8_str("p1")).FromJust()) { |
6964 } else if (name->Equals(v8_str("p3"))) { | 7768 CHECK(info.This() |
6965 CHECK(info.This()->Equals(global->Get(v8_str("o3")))); | 7769 ->Equals(context, |
6966 } else if (name->Equals(v8_str("p4"))) { | 7770 global->Get(context, v8_str("o1")).ToLocalChecked()) |
6967 CHECK(info.This()->Equals(global->Get(v8_str("o4")))); | 7771 .FromJust()); |
7772 } else if (name->Equals(context, v8_str("p2")).FromJust()) { | |
7773 CHECK(info.This() | |
7774 ->Equals(context, | |
7775 global->Get(context, v8_str("o2")).ToLocalChecked()) | |
7776 .FromJust()); | |
7777 } else if (name->Equals(context, v8_str("p3")).FromJust()) { | |
7778 CHECK(info.This() | |
7779 ->Equals(context, | |
7780 global->Get(context, v8_str("o3")).ToLocalChecked()) | |
7781 .FromJust()); | |
7782 } else if (name->Equals(context, v8_str("p4")).FromJust()) { | |
7783 CHECK(info.This() | |
7784 ->Equals(context, | |
7785 global->Get(context, v8_str("o4")).ToLocalChecked()) | |
7786 .FromJust()); | |
6968 } | 7787 } |
6969 } | 7788 } |
6970 | 7789 |
6971 | 7790 |
6972 static void RunHolderTest(v8::Handle<v8::ObjectTemplate> obj) { | 7791 static void RunHolderTest(v8::Local<v8::ObjectTemplate> obj) { |
6973 ApiTestFuzzer::Fuzz(); | 7792 ApiTestFuzzer::Fuzz(); |
6974 LocalContext context; | 7793 LocalContext context; |
6975 context->Global()->Set(v8_str("o1"), obj->NewInstance()); | 7794 CHECK(context->Global() |
7795 ->Set(context.local(), v8_str("o1"), | |
7796 obj->NewInstance(context.local()).ToLocalChecked()) | |
7797 .FromJust()); | |
6976 CompileRun( | 7798 CompileRun( |
6977 "o1.__proto__ = { };" | 7799 "o1.__proto__ = { };" |
6978 "var o2 = { __proto__: o1 };" | 7800 "var o2 = { __proto__: o1 };" |
6979 "var o3 = { __proto__: o2 };" | 7801 "var o3 = { __proto__: o2 };" |
6980 "var o4 = { __proto__: o3 };" | 7802 "var o4 = { __proto__: o3 };" |
6981 "for (var i = 0; i < 10; i++) o4.p4;" | 7803 "for (var i = 0; i < 10; i++) o4.p4;" |
6982 "for (var i = 0; i < 10; i++) o3.p3;" | 7804 "for (var i = 0; i < 10; i++) o3.p3;" |
6983 "for (var i = 0; i < 10; i++) o2.p2;" | 7805 "for (var i = 0; i < 10; i++) o2.p2;" |
6984 "for (var i = 0; i < 10; i++) o1.p1;"); | 7806 "for (var i = 0; i < 10; i++) o1.p1;"); |
6985 } | 7807 } |
6986 | 7808 |
6987 | 7809 |
6988 static void PGetter2(Local<Name> name, | 7810 static void PGetter2(Local<Name> name, |
6989 const v8::PropertyCallbackInfo<v8::Value>& info) { | 7811 const v8::PropertyCallbackInfo<v8::Value>& info) { |
6990 ApiTestFuzzer::Fuzz(); | 7812 ApiTestFuzzer::Fuzz(); |
6991 p_getter_count2++; | 7813 p_getter_count2++; |
6992 v8::Handle<v8::Object> global = | 7814 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
6993 info.GetIsolate()->GetCurrentContext()->Global(); | 7815 v8::Local<v8::Object> global = context->Global(); |
6994 CHECK(info.Holder()->Equals(global->Get(v8_str("o1")))); | 7816 CHECK( |
6995 if (name->Equals(v8_str("p1"))) { | 7817 info.Holder() |
6996 CHECK(info.This()->Equals(global->Get(v8_str("o1")))); | 7818 ->Equals(context, global->Get(context, v8_str("o1")).ToLocalChecked()) |
6997 } else if (name->Equals(v8_str("p2"))) { | 7819 .FromJust()); |
6998 CHECK(info.This()->Equals(global->Get(v8_str("o2")))); | 7820 if (name->Equals(context, v8_str("p1")).FromJust()) { |
6999 } else if (name->Equals(v8_str("p3"))) { | 7821 CHECK(info.This() |
7000 CHECK(info.This()->Equals(global->Get(v8_str("o3")))); | 7822 ->Equals(context, |
7001 } else if (name->Equals(v8_str("p4"))) { | 7823 global->Get(context, v8_str("o1")).ToLocalChecked()) |
7002 CHECK(info.This()->Equals(global->Get(v8_str("o4")))); | 7824 .FromJust()); |
7825 } else if (name->Equals(context, v8_str("p2")).FromJust()) { | |
7826 CHECK(info.This() | |
7827 ->Equals(context, | |
7828 global->Get(context, v8_str("o2")).ToLocalChecked()) | |
7829 .FromJust()); | |
7830 } else if (name->Equals(context, v8_str("p3")).FromJust()) { | |
7831 CHECK(info.This() | |
7832 ->Equals(context, | |
7833 global->Get(context, v8_str("o3")).ToLocalChecked()) | |
7834 .FromJust()); | |
7835 } else if (name->Equals(context, v8_str("p4")).FromJust()) { | |
7836 CHECK(info.This() | |
7837 ->Equals(context, | |
7838 global->Get(context, v8_str("o4")).ToLocalChecked()) | |
7839 .FromJust()); | |
7003 } | 7840 } |
7004 } | 7841 } |
7005 | 7842 |
7006 | 7843 |
7007 THREADED_TEST(GetterHolders) { | 7844 THREADED_TEST(GetterHolders) { |
7008 v8::Isolate* isolate = CcTest::isolate(); | 7845 v8::Isolate* isolate = CcTest::isolate(); |
7009 v8::HandleScope scope(isolate); | 7846 v8::HandleScope scope(isolate); |
7010 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 7847 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7011 obj->SetAccessor(v8_str("p1"), PGetter); | 7848 obj->SetAccessor(v8_str("p1"), PGetter); |
7012 obj->SetAccessor(v8_str("p2"), PGetter); | 7849 obj->SetAccessor(v8_str("p2"), PGetter); |
7013 obj->SetAccessor(v8_str("p3"), PGetter); | 7850 obj->SetAccessor(v8_str("p3"), PGetter); |
7014 obj->SetAccessor(v8_str("p4"), PGetter); | 7851 obj->SetAccessor(v8_str("p4"), PGetter); |
7015 p_getter_count = 0; | 7852 p_getter_count = 0; |
7016 RunHolderTest(obj); | 7853 RunHolderTest(obj); |
7017 CHECK_EQ(40, p_getter_count); | 7854 CHECK_EQ(40, p_getter_count); |
7018 } | 7855 } |
7019 | 7856 |
7020 | 7857 |
7021 THREADED_TEST(PreInterceptorHolders) { | 7858 THREADED_TEST(PreInterceptorHolders) { |
7022 v8::Isolate* isolate = CcTest::isolate(); | 7859 v8::Isolate* isolate = CcTest::isolate(); |
7023 v8::HandleScope scope(isolate); | 7860 v8::HandleScope scope(isolate); |
7024 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 7861 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7025 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(PGetter2)); | 7862 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(PGetter2)); |
7026 p_getter_count2 = 0; | 7863 p_getter_count2 = 0; |
7027 RunHolderTest(obj); | 7864 RunHolderTest(obj); |
7028 CHECK_EQ(40, p_getter_count2); | 7865 CHECK_EQ(40, p_getter_count2); |
7029 } | 7866 } |
7030 | 7867 |
7031 | 7868 |
7032 THREADED_TEST(ObjectInstantiation) { | 7869 THREADED_TEST(ObjectInstantiation) { |
7033 v8::Isolate* isolate = CcTest::isolate(); | 7870 v8::Isolate* isolate = CcTest::isolate(); |
7034 v8::HandleScope scope(isolate); | 7871 v8::HandleScope scope(isolate); |
7035 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); | 7872 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); |
7036 templ->SetAccessor(v8_str("t"), PGetter2); | 7873 templ->SetAccessor(v8_str("t"), PGetter2); |
7037 LocalContext context; | 7874 LocalContext context; |
7038 context->Global()->Set(v8_str("o"), templ->NewInstance()); | 7875 CHECK(context->Global() |
7876 ->Set(context.local(), v8_str("o"), | |
7877 templ->NewInstance(context.local()).ToLocalChecked()) | |
7878 .FromJust()); | |
7039 for (int i = 0; i < 100; i++) { | 7879 for (int i = 0; i < 100; i++) { |
7040 v8::HandleScope inner_scope(CcTest::isolate()); | 7880 v8::HandleScope inner_scope(CcTest::isolate()); |
7041 v8::Handle<v8::Object> obj = templ->NewInstance(); | 7881 v8::Local<v8::Object> obj = |
7042 CHECK(!obj->Equals(context->Global()->Get(v8_str("o")))); | 7882 templ->NewInstance(context.local()).ToLocalChecked(); |
7043 context->Global()->Set(v8_str("o2"), obj); | 7883 CHECK(!obj->Equals(context.local(), context->Global() |
7044 v8::Handle<Value> value = | 7884 ->Get(context.local(), v8_str("o")) |
7045 CompileRun("o.__proto__ === o2.__proto__"); | 7885 .ToLocalChecked()) |
7046 CHECK(v8::True(isolate)->Equals(value)); | 7886 .FromJust()); |
7047 context->Global()->Set(v8_str("o"), obj); | 7887 CHECK( |
7888 context->Global()->Set(context.local(), v8_str("o2"), obj).FromJust()); | |
7889 v8::Local<Value> value = CompileRun("o.__proto__ === o2.__proto__"); | |
7890 CHECK(v8::True(isolate)->Equals(context.local(), value).FromJust()); | |
7891 CHECK(context->Global()->Set(context.local(), v8_str("o"), obj).FromJust()); | |
7048 } | 7892 } |
7049 } | 7893 } |
7050 | 7894 |
7051 | 7895 |
7052 static int StrCmp16(uint16_t* a, uint16_t* b) { | 7896 static int StrCmp16(uint16_t* a, uint16_t* b) { |
7053 while (true) { | 7897 while (true) { |
7054 if (*a == 0 && *b == 0) return 0; | 7898 if (*a == 0 && *b == 0) return 0; |
7055 if (*a != *b) return 0 + *a - *b; | 7899 if (*a != *b) return 0 + *a - *b; |
7056 a++; | 7900 a++; |
7057 b++; | 7901 b++; |
7058 } | 7902 } |
7059 } | 7903 } |
7060 | 7904 |
7061 | 7905 |
7062 static int StrNCmp16(uint16_t* a, uint16_t* b, int n) { | 7906 static int StrNCmp16(uint16_t* a, uint16_t* b, int n) { |
7063 while (true) { | 7907 while (true) { |
7064 if (n-- == 0) return 0; | 7908 if (n-- == 0) return 0; |
7065 if (*a == 0 && *b == 0) return 0; | 7909 if (*a == 0 && *b == 0) return 0; |
7066 if (*a != *b) return 0 + *a - *b; | 7910 if (*a != *b) return 0 + *a - *b; |
7067 a++; | 7911 a++; |
7068 b++; | 7912 b++; |
7069 } | 7913 } |
7070 } | 7914 } |
7071 | 7915 |
7072 | 7916 |
7073 int GetUtf8Length(Handle<String> str) { | 7917 int GetUtf8Length(Local<String> str) { |
7074 int len = str->Utf8Length(); | 7918 int len = str->Utf8Length(); |
7075 if (len < 0) { | 7919 if (len < 0) { |
7076 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str)); | 7920 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str)); |
7077 i::String::Flatten(istr); | 7921 i::String::Flatten(istr); |
7078 len = str->Utf8Length(); | 7922 len = str->Utf8Length(); |
7079 } | 7923 } |
7080 return len; | 7924 return len; |
7081 } | 7925 } |
7082 | 7926 |
7083 | 7927 |
7084 THREADED_TEST(StringWrite) { | 7928 THREADED_TEST(StringWrite) { |
7085 LocalContext context; | 7929 LocalContext context; |
7086 v8::HandleScope scope(context->GetIsolate()); | 7930 v8::HandleScope scope(context->GetIsolate()); |
7087 v8::Handle<String> str = v8_str("abcde"); | 7931 v8::Local<String> str = v8_str("abcde"); |
7088 // abc<Icelandic eth><Unicode snowman>. | 7932 // abc<Icelandic eth><Unicode snowman>. |
7089 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); | 7933 v8::Local<String> str2 = v8_str("abc\303\260\342\230\203"); |
7090 v8::Handle<String> str3 = v8::String::NewFromUtf8( | 7934 v8::Local<String> str3 = |
7091 context->GetIsolate(), "abc\0def", v8::String::kNormalString, 7); | 7935 v8::String::NewFromUtf8(context->GetIsolate(), "abc\0def", |
7936 v8::NewStringType::kNormal, 7) | |
7937 .ToLocalChecked(); | |
7092 // "ab" + lead surrogate + "cd" + trail surrogate + "ef" | 7938 // "ab" + lead surrogate + "cd" + trail surrogate + "ef" |
7093 uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 }; | 7939 uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 }; |
7094 v8::Handle<String> orphans_str = v8::String::NewFromTwoByte( | 7940 v8::Local<String> orphans_str = |
7095 context->GetIsolate(), orphans, v8::String::kNormalString, 8); | 7941 v8::String::NewFromTwoByte(context->GetIsolate(), orphans, |
7942 v8::NewStringType::kNormal, 8) | |
7943 .ToLocalChecked(); | |
7096 // single lead surrogate | 7944 // single lead surrogate |
7097 uint16_t lead[1] = { 0xd800 }; | 7945 uint16_t lead[1] = { 0xd800 }; |
7098 v8::Handle<String> lead_str = v8::String::NewFromTwoByte( | 7946 v8::Local<String> lead_str = |
7099 context->GetIsolate(), lead, v8::String::kNormalString, 1); | 7947 v8::String::NewFromTwoByte(context->GetIsolate(), lead, |
7948 v8::NewStringType::kNormal, 1) | |
7949 .ToLocalChecked(); | |
7100 // single trail surrogate | 7950 // single trail surrogate |
7101 uint16_t trail[1] = { 0xdc00 }; | 7951 uint16_t trail[1] = { 0xdc00 }; |
7102 v8::Handle<String> trail_str = v8::String::NewFromTwoByte( | 7952 v8::Local<String> trail_str = |
7103 context->GetIsolate(), trail, v8::String::kNormalString, 1); | 7953 v8::String::NewFromTwoByte(context->GetIsolate(), trail, |
7954 v8::NewStringType::kNormal, 1) | |
7955 .ToLocalChecked(); | |
7104 // surrogate pair | 7956 // surrogate pair |
7105 uint16_t pair[2] = { 0xd800, 0xdc00 }; | 7957 uint16_t pair[2] = { 0xd800, 0xdc00 }; |
7106 v8::Handle<String> pair_str = v8::String::NewFromTwoByte( | 7958 v8::Local<String> pair_str = |
7107 context->GetIsolate(), pair, v8::String::kNormalString, 2); | 7959 v8::String::NewFromTwoByte(context->GetIsolate(), pair, |
7960 v8::NewStringType::kNormal, 2) | |
7961 .ToLocalChecked(); | |
7108 const int kStride = 4; // Must match stride in for loops in JS below. | 7962 const int kStride = 4; // Must match stride in for loops in JS below. |
7109 CompileRun( | 7963 CompileRun( |
7110 "var left = '';" | 7964 "var left = '';" |
7111 "for (var i = 0; i < 0xd800; i += 4) {" | 7965 "for (var i = 0; i < 0xd800; i += 4) {" |
7112 " left = left + String.fromCharCode(i);" | 7966 " left = left + String.fromCharCode(i);" |
7113 "}"); | 7967 "}"); |
7114 CompileRun( | 7968 CompileRun( |
7115 "var right = '';" | 7969 "var right = '';" |
7116 "for (var i = 0; i < 0xd800; i += 4) {" | 7970 "for (var i = 0; i < 0xd800; i += 4) {" |
7117 " right = String.fromCharCode(i) + right;" | 7971 " right = String.fromCharCode(i) + right;" |
7118 "}"); | 7972 "}"); |
7119 v8::Handle<v8::Object> global = context->Global(); | 7973 v8::Local<v8::Object> global = context->Global(); |
7120 Handle<String> left_tree = global->Get(v8_str("left")).As<String>(); | 7974 Local<String> left_tree = global->Get(context.local(), v8_str("left")) |
7121 Handle<String> right_tree = global->Get(v8_str("right")).As<String>(); | 7975 .ToLocalChecked() |
7976 .As<String>(); | |
7977 Local<String> right_tree = global->Get(context.local(), v8_str("right")) | |
7978 .ToLocalChecked() | |
7979 .As<String>(); | |
7122 | 7980 |
7123 CHECK_EQ(5, str2->Length()); | 7981 CHECK_EQ(5, str2->Length()); |
7124 CHECK_EQ(0xd800 / kStride, left_tree->Length()); | 7982 CHECK_EQ(0xd800 / kStride, left_tree->Length()); |
7125 CHECK_EQ(0xd800 / kStride, right_tree->Length()); | 7983 CHECK_EQ(0xd800 / kStride, right_tree->Length()); |
7126 | 7984 |
7127 char buf[100]; | 7985 char buf[100]; |
7128 char utf8buf[0xd800 * 3]; | 7986 char utf8buf[0xd800 * 3]; |
7129 uint16_t wbuf[100]; | 7987 uint16_t wbuf[100]; |
7130 int len; | 7988 int len; |
7131 int charlen; | 7989 int charlen; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7387 CHECK_EQ(0, str->WriteUtf8(NULL, 0, 0, String::NO_NULL_TERMINATION)); | 8245 CHECK_EQ(0, str->WriteUtf8(NULL, 0, 0, String::NO_NULL_TERMINATION)); |
7388 CHECK_EQ(0, str->Write(NULL, 0, 0, String::NO_NULL_TERMINATION)); | 8246 CHECK_EQ(0, str->Write(NULL, 0, 0, String::NO_NULL_TERMINATION)); |
7389 } | 8247 } |
7390 | 8248 |
7391 | 8249 |
7392 static void Utf16Helper( | 8250 static void Utf16Helper( |
7393 LocalContext& context, // NOLINT | 8251 LocalContext& context, // NOLINT |
7394 const char* name, | 8252 const char* name, |
7395 const char* lengths_name, | 8253 const char* lengths_name, |
7396 int len) { | 8254 int len) { |
7397 Local<v8::Array> a = | 8255 Local<v8::Array> a = Local<v8::Array>::Cast( |
7398 Local<v8::Array>::Cast(context->Global()->Get(v8_str(name))); | 8256 context->Global()->Get(context.local(), v8_str(name)).ToLocalChecked()); |
7399 Local<v8::Array> alens = | 8257 Local<v8::Array> alens = |
7400 Local<v8::Array>::Cast(context->Global()->Get(v8_str(lengths_name))); | 8258 Local<v8::Array>::Cast(context->Global() |
8259 ->Get(context.local(), v8_str(lengths_name)) | |
8260 .ToLocalChecked()); | |
7401 for (int i = 0; i < len; i++) { | 8261 for (int i = 0; i < len; i++) { |
7402 Local<v8::String> string = | 8262 Local<v8::String> string = |
7403 Local<v8::String>::Cast(a->Get(i)); | 8263 Local<v8::String>::Cast(a->Get(context.local(), i).ToLocalChecked()); |
7404 Local<v8::Number> expected_len = | 8264 Local<v8::Number> expected_len = Local<v8::Number>::Cast( |
7405 Local<v8::Number>::Cast(alens->Get(i)); | 8265 alens->Get(context.local(), i).ToLocalChecked()); |
7406 int length = GetUtf8Length(string); | 8266 int length = GetUtf8Length(string); |
7407 CHECK_EQ(static_cast<int>(expected_len->Value()), length); | 8267 CHECK_EQ(static_cast<int>(expected_len->Value()), length); |
7408 } | 8268 } |
7409 } | 8269 } |
7410 | 8270 |
7411 | 8271 |
7412 THREADED_TEST(Utf16) { | 8272 THREADED_TEST(Utf16) { |
7413 LocalContext context; | 8273 LocalContext context; |
7414 v8::HandleScope scope(context->GetIsolate()); | 8274 v8::HandleScope scope(context->GetIsolate()); |
7415 CompileRun( | 8275 CompileRun( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7451 // The 'm's that end with 0xd8.. are 1, 4 and 7 | 8311 // The 'm's that end with 0xd8.. are 1, 4 and 7 |
7452 " if ((m % 3) == 1 && n >= 6) utf -= 2;" | 8312 " if ((m % 3) == 1 && n >= 6) utf -= 2;" |
7453 " a2lens.push(utf);" | 8313 " a2lens.push(utf);" |
7454 " }" | 8314 " }" |
7455 "}"); | 8315 "}"); |
7456 Utf16Helper(context, "a", "alens", 9); | 8316 Utf16Helper(context, "a", "alens", 9); |
7457 Utf16Helper(context, "a2", "a2lens", 81); | 8317 Utf16Helper(context, "a2", "a2lens", 81); |
7458 } | 8318 } |
7459 | 8319 |
7460 | 8320 |
7461 static bool SameSymbol(Handle<String> s1, Handle<String> s2) { | 8321 static bool SameSymbol(Local<String> s1, Local<String> s2) { |
7462 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1)); | 8322 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1)); |
7463 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2)); | 8323 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2)); |
7464 return *is1 == *is2; | 8324 return *is1 == *is2; |
7465 } | 8325 } |
7466 | 8326 |
7467 | 8327 |
7468 THREADED_TEST(Utf16Symbol) { | 8328 THREADED_TEST(Utf16Symbol) { |
7469 LocalContext context; | 8329 LocalContext context; |
7470 v8::HandleScope scope(context->GetIsolate()); | 8330 v8::HandleScope scope(context->GetIsolate()); |
7471 | 8331 |
7472 Handle<String> symbol1 = v8::String::NewFromUtf8( | 8332 Local<String> symbol1 = |
7473 context->GetIsolate(), "abc", v8::String::kInternalizedString); | 8333 v8::String::NewFromUtf8(context->GetIsolate(), "abc", |
7474 Handle<String> symbol2 = v8::String::NewFromUtf8( | 8334 v8::NewStringType::kInternalized) |
7475 context->GetIsolate(), "abc", v8::String::kInternalizedString); | 8335 .ToLocalChecked(); |
8336 Local<String> symbol2 = | |
8337 v8::String::NewFromUtf8(context->GetIsolate(), "abc", | |
8338 v8::NewStringType::kInternalized) | |
8339 .ToLocalChecked(); | |
7476 CHECK(SameSymbol(symbol1, symbol2)); | 8340 CHECK(SameSymbol(symbol1, symbol2)); |
7477 | 8341 |
7478 CompileRun( | 8342 CompileRun( |
7479 "var sym0 = 'benedictus';" | 8343 "var sym0 = 'benedictus';" |
7480 "var sym0b = 'S\303\270ren';" | 8344 "var sym0b = 'S\303\270ren';" |
7481 "var sym1 = '\355\240\201\355\260\207';" | 8345 "var sym1 = '\355\240\201\355\260\207';" |
7482 "var sym2 = '\360\220\220\210';" | 8346 "var sym2 = '\360\220\220\210';" |
7483 "var sym3 = 'x\355\240\201\355\260\207';" | 8347 "var sym3 = 'x\355\240\201\355\260\207';" |
7484 "var sym4 = 'x\360\220\220\210';" | 8348 "var sym4 = 'x\360\220\220\210';" |
7485 "if (sym1.length != 2) throw sym1;" | 8349 "if (sym1.length != 2) throw sym1;" |
7486 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);" | 8350 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);" |
7487 "if (sym2.length != 2) throw sym2;" | 8351 "if (sym2.length != 2) throw sym2;" |
7488 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);" | 8352 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);" |
7489 "if (sym3.length != 3) throw sym3;" | 8353 "if (sym3.length != 3) throw sym3;" |
7490 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);" | 8354 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);" |
7491 "if (sym4.length != 3) throw sym4;" | 8355 "if (sym4.length != 3) throw sym4;" |
7492 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);"); | 8356 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);"); |
7493 Handle<String> sym0 = v8::String::NewFromUtf8( | 8357 Local<String> sym0 = |
7494 context->GetIsolate(), "benedictus", v8::String::kInternalizedString); | 8358 v8::String::NewFromUtf8(context->GetIsolate(), "benedictus", |
7495 Handle<String> sym0b = v8::String::NewFromUtf8( | 8359 v8::NewStringType::kInternalized) |
7496 context->GetIsolate(), "S\303\270ren", v8::String::kInternalizedString); | 8360 .ToLocalChecked(); |
7497 Handle<String> sym1 = | 8361 Local<String> sym0b = |
8362 v8::String::NewFromUtf8(context->GetIsolate(), "S\303\270ren", | |
8363 v8::NewStringType::kInternalized) | |
8364 .ToLocalChecked(); | |
8365 Local<String> sym1 = | |
7498 v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207", | 8366 v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207", |
7499 v8::String::kInternalizedString); | 8367 v8::NewStringType::kInternalized) |
7500 Handle<String> sym2 = | 8368 .ToLocalChecked(); |
8369 Local<String> sym2 = | |
7501 v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210", | 8370 v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210", |
7502 v8::String::kInternalizedString); | 8371 v8::NewStringType::kInternalized) |
7503 Handle<String> sym3 = v8::String::NewFromUtf8( | 8372 .ToLocalChecked(); |
7504 context->GetIsolate(), "x\355\240\201\355\260\207", | 8373 Local<String> sym3 = v8::String::NewFromUtf8(context->GetIsolate(), |
7505 v8::String::kInternalizedString); | 8374 "x\355\240\201\355\260\207", |
7506 Handle<String> sym4 = | 8375 v8::NewStringType::kInternalized) |
8376 .ToLocalChecked(); | |
8377 Local<String> sym4 = | |
7507 v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210", | 8378 v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210", |
7508 v8::String::kInternalizedString); | 8379 v8::NewStringType::kInternalized) |
8380 .ToLocalChecked(); | |
7509 v8::Local<v8::Object> global = context->Global(); | 8381 v8::Local<v8::Object> global = context->Global(); |
7510 Local<Value> s0 = global->Get(v8_str("sym0")); | 8382 Local<Value> s0 = |
7511 Local<Value> s0b = global->Get(v8_str("sym0b")); | 8383 global->Get(context.local(), v8_str("sym0")).ToLocalChecked(); |
7512 Local<Value> s1 = global->Get(v8_str("sym1")); | 8384 Local<Value> s0b = |
7513 Local<Value> s2 = global->Get(v8_str("sym2")); | 8385 global->Get(context.local(), v8_str("sym0b")).ToLocalChecked(); |
7514 Local<Value> s3 = global->Get(v8_str("sym3")); | 8386 Local<Value> s1 = |
7515 Local<Value> s4 = global->Get(v8_str("sym4")); | 8387 global->Get(context.local(), v8_str("sym1")).ToLocalChecked(); |
7516 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); | 8388 Local<Value> s2 = |
7517 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); | 8389 global->Get(context.local(), v8_str("sym2")).ToLocalChecked(); |
7518 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); | 8390 Local<Value> s3 = |
7519 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); | 8391 global->Get(context.local(), v8_str("sym3")).ToLocalChecked(); |
7520 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); | 8392 Local<Value> s4 = |
7521 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); | 8393 global->Get(context.local(), v8_str("sym4")).ToLocalChecked(); |
8394 CHECK(SameSymbol(sym0, Local<String>::Cast(s0))); | |
8395 CHECK(SameSymbol(sym0b, Local<String>::Cast(s0b))); | |
8396 CHECK(SameSymbol(sym1, Local<String>::Cast(s1))); | |
8397 CHECK(SameSymbol(sym2, Local<String>::Cast(s2))); | |
8398 CHECK(SameSymbol(sym3, Local<String>::Cast(s3))); | |
8399 CHECK(SameSymbol(sym4, Local<String>::Cast(s4))); | |
7522 } | 8400 } |
7523 | 8401 |
7524 | 8402 |
7525 THREADED_TEST(Utf16MissingTrailing) { | 8403 THREADED_TEST(Utf16MissingTrailing) { |
7526 LocalContext context; | 8404 LocalContext context; |
7527 v8::HandleScope scope(context->GetIsolate()); | 8405 v8::HandleScope scope(context->GetIsolate()); |
7528 | 8406 |
7529 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` | 8407 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` |
7530 int size = 1024 * 64; | 8408 int size = 1024 * 64; |
7531 uint8_t* buffer = new uint8_t[size]; | 8409 uint8_t* buffer = new uint8_t[size]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7571 | 8449 |
7572 delete[] buffer; | 8450 delete[] buffer; |
7573 } | 8451 } |
7574 | 8452 |
7575 | 8453 |
7576 THREADED_TEST(ToArrayIndex) { | 8454 THREADED_TEST(ToArrayIndex) { |
7577 LocalContext context; | 8455 LocalContext context; |
7578 v8::Isolate* isolate = context->GetIsolate(); | 8456 v8::Isolate* isolate = context->GetIsolate(); |
7579 v8::HandleScope scope(isolate); | 8457 v8::HandleScope scope(isolate); |
7580 | 8458 |
7581 v8::Handle<String> str = v8_str("42"); | 8459 v8::Local<String> str = v8_str("42"); |
7582 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 8460 v8::MaybeLocal<v8::Uint32> index = str->ToArrayIndex(context.local()); |
7583 CHECK(!index.IsEmpty()); | 8461 CHECK(!index.IsEmpty()); |
7584 CHECK_EQ(42.0, index->Uint32Value()); | 8462 CHECK_EQ(42.0, |
8463 index.ToLocalChecked()->Uint32Value(context.local()).FromJust()); | |
7585 str = v8_str("42asdf"); | 8464 str = v8_str("42asdf"); |
7586 index = str->ToArrayIndex(); | 8465 index = str->ToArrayIndex(context.local()); |
7587 CHECK(index.IsEmpty()); | 8466 CHECK(index.IsEmpty()); |
7588 str = v8_str("-42"); | 8467 str = v8_str("-42"); |
7589 index = str->ToArrayIndex(); | 8468 index = str->ToArrayIndex(context.local()); |
7590 CHECK(index.IsEmpty()); | 8469 CHECK(index.IsEmpty()); |
7591 str = v8_str("4294967294"); | 8470 str = v8_str("4294967294"); |
7592 index = str->ToArrayIndex(); | 8471 index = str->ToArrayIndex(context.local()); |
7593 CHECK(!index.IsEmpty()); | 8472 CHECK(!index.IsEmpty()); |
7594 CHECK_EQ(4294967294.0, index->Uint32Value()); | 8473 CHECK_EQ(4294967294.0, |
7595 v8::Handle<v8::Number> num = v8::Number::New(isolate, 1); | 8474 index.ToLocalChecked()->Uint32Value(context.local()).FromJust()); |
7596 index = num->ToArrayIndex(); | 8475 v8::Local<v8::Number> num = v8::Number::New(isolate, 1); |
8476 index = num->ToArrayIndex(context.local()); | |
7597 CHECK(!index.IsEmpty()); | 8477 CHECK(!index.IsEmpty()); |
7598 CHECK_EQ(1.0, index->Uint32Value()); | 8478 CHECK_EQ(1.0, |
8479 index.ToLocalChecked()->Uint32Value(context.local()).FromJust()); | |
7599 num = v8::Number::New(isolate, -1); | 8480 num = v8::Number::New(isolate, -1); |
7600 index = num->ToArrayIndex(); | 8481 index = num->ToArrayIndex(context.local()); |
7601 CHECK(index.IsEmpty()); | 8482 CHECK(index.IsEmpty()); |
7602 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 8483 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
7603 index = obj->ToArrayIndex(); | 8484 index = obj->ToArrayIndex(context.local()); |
7604 CHECK(index.IsEmpty()); | 8485 CHECK(index.IsEmpty()); |
7605 } | 8486 } |
7606 | 8487 |
7607 | 8488 |
7608 THREADED_TEST(ErrorConstruction) { | 8489 THREADED_TEST(ErrorConstruction) { |
7609 LocalContext context; | 8490 LocalContext context; |
7610 v8::HandleScope scope(context->GetIsolate()); | 8491 v8::HandleScope scope(context->GetIsolate()); |
7611 | 8492 |
7612 v8::Handle<String> foo = v8_str("foo"); | 8493 v8::Local<String> foo = v8_str("foo"); |
7613 v8::Handle<String> message = v8_str("message"); | 8494 v8::Local<String> message = v8_str("message"); |
7614 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); | 8495 v8::Local<Value> range_error = v8::Exception::RangeError(foo); |
7615 CHECK(range_error->IsObject()); | 8496 CHECK(range_error->IsObject()); |
7616 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); | 8497 CHECK(range_error.As<v8::Object>() |
7617 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); | 8498 ->Get(context.local(), message) |
8499 .ToLocalChecked() | |
8500 ->Equals(context.local(), foo) | |
8501 .FromJust()); | |
8502 v8::Local<Value> reference_error = v8::Exception::ReferenceError(foo); | |
7618 CHECK(reference_error->IsObject()); | 8503 CHECK(reference_error->IsObject()); |
7619 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); | 8504 CHECK(reference_error.As<v8::Object>() |
7620 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); | 8505 ->Get(context.local(), message) |
8506 .ToLocalChecked() | |
8507 ->Equals(context.local(), foo) | |
8508 .FromJust()); | |
8509 v8::Local<Value> syntax_error = v8::Exception::SyntaxError(foo); | |
7621 CHECK(syntax_error->IsObject()); | 8510 CHECK(syntax_error->IsObject()); |
7622 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); | 8511 CHECK(syntax_error.As<v8::Object>() |
7623 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); | 8512 ->Get(context.local(), message) |
8513 .ToLocalChecked() | |
8514 ->Equals(context.local(), foo) | |
8515 .FromJust()); | |
8516 v8::Local<Value> type_error = v8::Exception::TypeError(foo); | |
7624 CHECK(type_error->IsObject()); | 8517 CHECK(type_error->IsObject()); |
7625 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); | 8518 CHECK(type_error.As<v8::Object>() |
7626 v8::Handle<Value> error = v8::Exception::Error(foo); | 8519 ->Get(context.local(), message) |
8520 .ToLocalChecked() | |
8521 ->Equals(context.local(), foo) | |
8522 .FromJust()); | |
8523 v8::Local<Value> error = v8::Exception::Error(foo); | |
7627 CHECK(error->IsObject()); | 8524 CHECK(error->IsObject()); |
7628 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); | 8525 CHECK(error.As<v8::Object>() |
8526 ->Get(context.local(), message) | |
8527 .ToLocalChecked() | |
8528 ->Equals(context.local(), foo) | |
8529 .FromJust()); | |
7629 } | 8530 } |
7630 | 8531 |
7631 | 8532 |
7632 static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) { | 8533 static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) { |
7633 ApiTestFuzzer::Fuzz(); | 8534 ApiTestFuzzer::Fuzz(); |
7634 v8::Handle<String> foo = v8_str("foo"); | 8535 v8::Local<String> foo = v8_str("foo"); |
7635 v8::Handle<String> message = v8_str("message"); | 8536 v8::Local<String> message = v8_str("message"); |
7636 v8::Handle<Value> error = v8::Exception::Error(foo); | 8537 v8::Local<Value> error = v8::Exception::Error(foo); |
7637 CHECK(error->IsObject()); | 8538 CHECK(error->IsObject()); |
7638 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); | 8539 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
8540 CHECK(error.As<v8::Object>() | |
8541 ->Get(context, message) | |
8542 .ToLocalChecked() | |
8543 ->Equals(context, foo) | |
8544 .FromJust()); | |
7639 info.GetIsolate()->ThrowException(error); | 8545 info.GetIsolate()->ThrowException(error); |
7640 info.GetReturnValue().SetUndefined(); | 8546 info.GetReturnValue().SetUndefined(); |
7641 } | 8547 } |
7642 | 8548 |
7643 | 8549 |
7644 THREADED_TEST(ExceptionCreateMessage) { | 8550 THREADED_TEST(ExceptionCreateMessage) { |
7645 LocalContext context; | 8551 LocalContext context; |
7646 v8::HandleScope scope(context->GetIsolate()); | 8552 v8::HandleScope scope(context->GetIsolate()); |
7647 v8::Handle<String> foo_str = v8_str("foo"); | 8553 v8::Local<String> foo_str = v8_str("foo"); |
7648 v8::Handle<String> message_str = v8_str("message"); | 8554 v8::Local<String> message_str = v8_str("message"); |
7649 | 8555 |
7650 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 8556 context->GetIsolate()->SetCaptureStackTraceForUncaughtExceptions(true); |
7651 | 8557 |
7652 Local<v8::FunctionTemplate> fun = | 8558 Local<v8::FunctionTemplate> fun = |
7653 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); | 8559 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); |
7654 v8::Local<v8::Object> global = context->Global(); | 8560 v8::Local<v8::Object> global = context->Global(); |
7655 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); | 8561 CHECK(global->Set(context.local(), v8_str("throwV8Exception"), |
8562 fun->GetFunction(context.local()).ToLocalChecked()) | |
8563 .FromJust()); | |
7656 | 8564 |
7657 TryCatch try_catch(context->GetIsolate()); | 8565 TryCatch try_catch(context->GetIsolate()); |
7658 CompileRun( | 8566 CompileRun( |
7659 "function f1() {\n" | 8567 "function f1() {\n" |
7660 " throwV8Exception();\n" | 8568 " throwV8Exception();\n" |
7661 "};\n" | 8569 "};\n" |
7662 "f1();"); | 8570 "f1();"); |
7663 CHECK(try_catch.HasCaught()); | 8571 CHECK(try_catch.HasCaught()); |
7664 | 8572 |
7665 v8::Handle<v8::Value> error = try_catch.Exception(); | 8573 v8::Local<v8::Value> error = try_catch.Exception(); |
7666 CHECK(error->IsObject()); | 8574 CHECK(error->IsObject()); |
7667 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); | 8575 CHECK(error.As<v8::Object>() |
8576 ->Get(context.local(), message_str) | |
8577 .ToLocalChecked() | |
8578 ->Equals(context.local(), foo_str) | |
8579 .FromJust()); | |
7668 | 8580 |
7669 v8::Handle<v8::Message> message = v8::Exception::CreateMessage(error); | 8581 v8::Local<v8::Message> message = v8::Exception::CreateMessage(error); |
7670 CHECK(!message.IsEmpty()); | 8582 CHECK(!message.IsEmpty()); |
7671 CHECK_EQ(2, message->GetLineNumber()); | 8583 CHECK_EQ(2, message->GetLineNumber(context.local()).FromJust()); |
7672 CHECK_EQ(2, message->GetStartColumn()); | 8584 CHECK_EQ(2, message->GetStartColumn(context.local()).FromJust()); |
7673 | 8585 |
7674 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); | 8586 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); |
7675 CHECK(!stackTrace.IsEmpty()); | 8587 CHECK(!stackTrace.IsEmpty()); |
7676 CHECK_EQ(2, stackTrace->GetFrameCount()); | 8588 CHECK_EQ(2, stackTrace->GetFrameCount()); |
7677 | 8589 |
7678 stackTrace = v8::Exception::GetStackTrace(error); | 8590 stackTrace = v8::Exception::GetStackTrace(error); |
7679 CHECK(!stackTrace.IsEmpty()); | 8591 CHECK(!stackTrace.IsEmpty()); |
7680 CHECK_EQ(2, stackTrace->GetFrameCount()); | 8592 CHECK_EQ(2, stackTrace->GetFrameCount()); |
7681 | 8593 |
7682 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 8594 context->GetIsolate()->SetCaptureStackTraceForUncaughtExceptions(false); |
7683 | 8595 |
7684 // Now check message location when SetCaptureStackTraceForUncaughtExceptions | 8596 // Now check message location when SetCaptureStackTraceForUncaughtExceptions |
7685 // is false. | 8597 // is false. |
7686 try_catch.Reset(); | 8598 try_catch.Reset(); |
7687 | 8599 |
7688 CompileRun( | 8600 CompileRun( |
7689 "function f2() {\n" | 8601 "function f2() {\n" |
7690 " return throwV8Exception();\n" | 8602 " return throwV8Exception();\n" |
7691 "};\n" | 8603 "};\n" |
7692 "f2();"); | 8604 "f2();"); |
7693 CHECK(try_catch.HasCaught()); | 8605 CHECK(try_catch.HasCaught()); |
7694 | 8606 |
7695 error = try_catch.Exception(); | 8607 error = try_catch.Exception(); |
7696 CHECK(error->IsObject()); | 8608 CHECK(error->IsObject()); |
7697 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); | 8609 CHECK(error.As<v8::Object>() |
8610 ->Get(context.local(), message_str) | |
8611 .ToLocalChecked() | |
8612 ->Equals(context.local(), foo_str) | |
8613 .FromJust()); | |
7698 | 8614 |
7699 message = v8::Exception::CreateMessage(error); | 8615 message = v8::Exception::CreateMessage(error); |
7700 CHECK(!message.IsEmpty()); | 8616 CHECK(!message.IsEmpty()); |
7701 CHECK_EQ(2, message->GetLineNumber()); | 8617 CHECK_EQ(2, message->GetLineNumber(context.local()).FromJust()); |
7702 CHECK_EQ(9, message->GetStartColumn()); | 8618 CHECK_EQ(9, message->GetStartColumn(context.local()).FromJust()); |
7703 | 8619 |
7704 // Should be empty stack trace. | 8620 // Should be empty stack trace. |
7705 stackTrace = message->GetStackTrace(); | 8621 stackTrace = message->GetStackTrace(); |
7706 CHECK(stackTrace.IsEmpty()); | 8622 CHECK(stackTrace.IsEmpty()); |
7707 CHECK(v8::Exception::GetStackTrace(error).IsEmpty()); | 8623 CHECK(v8::Exception::GetStackTrace(error).IsEmpty()); |
7708 } | 8624 } |
7709 | 8625 |
7710 | 8626 |
7711 THREADED_TEST(ExceptionCreateMessageLength) { | 8627 THREADED_TEST(ExceptionCreateMessageLength) { |
7712 LocalContext context; | 8628 LocalContext context; |
(...skipping 15 matching lines...) Expand all Loading... | |
7728 const v8::PropertyCallbackInfo<v8::Value>& info) { | 8644 const v8::PropertyCallbackInfo<v8::Value>& info) { |
7729 ApiTestFuzzer::Fuzz(); | 8645 ApiTestFuzzer::Fuzz(); |
7730 info.GetReturnValue().Set(v8_num(10)); | 8646 info.GetReturnValue().Set(v8_num(10)); |
7731 } | 8647 } |
7732 | 8648 |
7733 | 8649 |
7734 static void YSetter(Local<String> name, | 8650 static void YSetter(Local<String> name, |
7735 Local<Value> value, | 8651 Local<Value> value, |
7736 const v8::PropertyCallbackInfo<void>& info) { | 8652 const v8::PropertyCallbackInfo<void>& info) { |
7737 Local<Object> this_obj = Local<Object>::Cast(info.This()); | 8653 Local<Object> this_obj = Local<Object>::Cast(info.This()); |
7738 if (this_obj->Has(name)) this_obj->Delete(name); | 8654 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); |
7739 this_obj->Set(name, value); | 8655 if (this_obj->Has(context, name).FromJust()) |
8656 this_obj->Delete(context, name).FromJust(); | |
8657 CHECK(this_obj->Set(context, name, value).FromJust()); | |
7740 } | 8658 } |
7741 | 8659 |
7742 | 8660 |
7743 THREADED_TEST(DeleteAccessor) { | 8661 THREADED_TEST(DeleteAccessor) { |
7744 v8::Isolate* isolate = CcTest::isolate(); | 8662 v8::Isolate* isolate = CcTest::isolate(); |
7745 v8::HandleScope scope(isolate); | 8663 v8::HandleScope scope(isolate); |
7746 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); | 8664 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); |
7747 obj->SetAccessor(v8_str("y"), YGetter, YSetter); | 8665 obj->SetAccessor(v8_str("y"), YGetter, YSetter); |
7748 LocalContext context; | 8666 LocalContext context; |
7749 v8::Handle<v8::Object> holder = obj->NewInstance(); | 8667 v8::Local<v8::Object> holder = |
7750 context->Global()->Set(v8_str("holder"), holder); | 8668 obj->NewInstance(context.local()).ToLocalChecked(); |
7751 v8::Handle<Value> result = CompileRun( | 8669 CHECK(context->Global() |
7752 "holder.y = 11; holder.y = 12; holder.y"); | 8670 ->Set(context.local(), v8_str("holder"), holder) |
7753 CHECK_EQ(12u, result->Uint32Value()); | 8671 .FromJust()); |
8672 v8::Local<Value> result = | |
8673 CompileRun("holder.y = 11; holder.y = 12; holder.y"); | |
8674 CHECK_EQ(12u, result->Uint32Value(context.local()).FromJust()); | |
7754 } | 8675 } |
7755 | 8676 |
7756 | 8677 |
7757 THREADED_TEST(TypeSwitch) { | 8678 THREADED_TEST(TypeSwitch) { |
7758 v8::Isolate* isolate = CcTest::isolate(); | 8679 v8::Isolate* isolate = CcTest::isolate(); |
7759 v8::HandleScope scope(isolate); | 8680 v8::HandleScope scope(isolate); |
7760 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); | 8681 v8::Local<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); |
7761 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); | 8682 v8::Local<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); |
7762 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); | 8683 v8::Local<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); |
7763 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; | 8684 v8::Local<v8::FunctionTemplate> templs[3] = {templ1, templ2, templ3}; |
7764 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); | 8685 v8::Local<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); |
7765 LocalContext context; | 8686 LocalContext context; |
7766 v8::Handle<v8::Object> obj0 = v8::Object::New(isolate); | 8687 v8::Local<v8::Object> obj0 = v8::Object::New(isolate); |
7767 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); | 8688 v8::Local<v8::Object> obj1 = templ1->GetFunction(context.local()) |
7768 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); | 8689 .ToLocalChecked() |
7769 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); | 8690 ->NewInstance(context.local()) |
8691 .ToLocalChecked(); | |
8692 v8::Local<v8::Object> obj2 = templ2->GetFunction(context.local()) | |
8693 .ToLocalChecked() | |
8694 ->NewInstance(context.local()) | |
8695 .ToLocalChecked(); | |
8696 v8::Local<v8::Object> obj3 = templ3->GetFunction(context.local()) | |
8697 .ToLocalChecked() | |
8698 ->NewInstance(context.local()) | |
8699 .ToLocalChecked(); | |
7770 for (int i = 0; i < 10; i++) { | 8700 for (int i = 0; i < 10; i++) { |
7771 CHECK_EQ(0, type_switch->match(obj0)); | 8701 CHECK_EQ(0, type_switch->match(obj0)); |
7772 CHECK_EQ(1, type_switch->match(obj1)); | 8702 CHECK_EQ(1, type_switch->match(obj1)); |
7773 CHECK_EQ(2, type_switch->match(obj2)); | 8703 CHECK_EQ(2, type_switch->match(obj2)); |
7774 CHECK_EQ(3, type_switch->match(obj3)); | 8704 CHECK_EQ(3, type_switch->match(obj3)); |
7775 CHECK_EQ(3, type_switch->match(obj3)); | 8705 CHECK_EQ(3, type_switch->match(obj3)); |
7776 CHECK_EQ(2, type_switch->match(obj2)); | 8706 CHECK_EQ(2, type_switch->match(obj2)); |
7777 CHECK_EQ(1, type_switch->match(obj1)); | 8707 CHECK_EQ(1, type_switch->match(obj1)); |
7778 CHECK_EQ(0, type_switch->match(obj0)); | 8708 CHECK_EQ(0, type_switch->match(obj0)); |
7779 } | 8709 } |
7780 } | 8710 } |
7781 | 8711 |
7782 | 8712 |
7783 static int trouble_nesting = 0; | 8713 static int trouble_nesting = 0; |
7784 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 8714 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7785 ApiTestFuzzer::Fuzz(); | 8715 ApiTestFuzzer::Fuzz(); |
7786 trouble_nesting++; | 8716 trouble_nesting++; |
7787 | 8717 |
7788 // Call a JS function that throws an uncaught exception. | 8718 // Call a JS function that throws an uncaught exception. |
7789 Local<v8::Object> arg_this = | 8719 Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
7790 args.GetIsolate()->GetCurrentContext()->Global(); | 8720 Local<v8::Object> arg_this = context->Global(); |
7791 Local<Value> trouble_callee = (trouble_nesting == 3) ? | 8721 Local<Value> trouble_callee = |
7792 arg_this->Get(v8_str("trouble_callee")) : | 8722 (trouble_nesting == 3) |
7793 arg_this->Get(v8_str("trouble_caller")); | 8723 ? arg_this->Get(context, v8_str("trouble_callee")).ToLocalChecked() |
8724 : arg_this->Get(context, v8_str("trouble_caller")).ToLocalChecked(); | |
7794 CHECK(trouble_callee->IsFunction()); | 8725 CHECK(trouble_callee->IsFunction()); |
7795 args.GetReturnValue().Set( | 8726 args.GetReturnValue().Set(Function::Cast(*trouble_callee) |
7796 Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL)); | 8727 ->Call(context, arg_this, 0, NULL) |
8728 .FromMaybe(v8::Local<v8::Value>())); | |
7797 } | 8729 } |
7798 | 8730 |
7799 | 8731 |
7800 static int report_count = 0; | 8732 static int report_count = 0; |
7801 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, | 8733 static void ApiUncaughtExceptionTestListener(v8::Local<v8::Message>, |
7802 v8::Handle<Value>) { | 8734 v8::Local<Value>) { |
7803 report_count++; | 8735 report_count++; |
7804 } | 8736 } |
7805 | 8737 |
7806 | 8738 |
7807 // Counts uncaught exceptions, but other tests running in parallel | 8739 // Counts uncaught exceptions, but other tests running in parallel |
7808 // also have uncaught exceptions. | 8740 // also have uncaught exceptions. |
7809 TEST(ApiUncaughtException) { | 8741 TEST(ApiUncaughtException) { |
7810 report_count = 0; | 8742 report_count = 0; |
7811 LocalContext env; | 8743 LocalContext env; |
7812 v8::Isolate* isolate = env->GetIsolate(); | 8744 v8::Isolate* isolate = env->GetIsolate(); |
7813 v8::HandleScope scope(isolate); | 8745 v8::HandleScope scope(isolate); |
7814 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 8746 isolate->AddMessageListener(ApiUncaughtExceptionTestListener); |
7815 | 8747 |
7816 Local<v8::FunctionTemplate> fun = | 8748 Local<v8::FunctionTemplate> fun = |
7817 v8::FunctionTemplate::New(isolate, TroubleCallback); | 8749 v8::FunctionTemplate::New(isolate, TroubleCallback); |
7818 v8::Local<v8::Object> global = env->Global(); | 8750 v8::Local<v8::Object> global = env->Global(); |
7819 global->Set(v8_str("trouble"), fun->GetFunction()); | 8751 CHECK(global->Set(env.local(), v8_str("trouble"), |
8752 fun->GetFunction(env.local()).ToLocalChecked()) | |
8753 .FromJust()); | |
7820 | 8754 |
7821 CompileRun( | 8755 CompileRun( |
7822 "function trouble_callee() {" | 8756 "function trouble_callee() {" |
7823 " var x = null;" | 8757 " var x = null;" |
7824 " return x.foo;" | 8758 " return x.foo;" |
7825 "};" | 8759 "};" |
7826 "function trouble_caller() {" | 8760 "function trouble_caller() {" |
7827 " trouble();" | 8761 " trouble();" |
7828 "};"); | 8762 "};"); |
7829 Local<Value> trouble = global->Get(v8_str("trouble")); | 8763 Local<Value> trouble = |
8764 global->Get(env.local(), v8_str("trouble")).ToLocalChecked(); | |
7830 CHECK(trouble->IsFunction()); | 8765 CHECK(trouble->IsFunction()); |
7831 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); | 8766 Local<Value> trouble_callee = |
8767 global->Get(env.local(), v8_str("trouble_callee")).ToLocalChecked(); | |
7832 CHECK(trouble_callee->IsFunction()); | 8768 CHECK(trouble_callee->IsFunction()); |
7833 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); | 8769 Local<Value> trouble_caller = |
8770 global->Get(env.local(), v8_str("trouble_caller")).ToLocalChecked(); | |
7834 CHECK(trouble_caller->IsFunction()); | 8771 CHECK(trouble_caller->IsFunction()); |
7835 Function::Cast(*trouble_caller)->Call(global, 0, NULL); | 8772 Function::Cast(*trouble_caller) |
8773 ->Call(env.local(), global, 0, NULL) | |
8774 .FromMaybe(v8::Local<v8::Value>()); | |
7836 CHECK_EQ(1, report_count); | 8775 CHECK_EQ(1, report_count); |
7837 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | 8776 isolate->RemoveMessageListeners(ApiUncaughtExceptionTestListener); |
7838 } | 8777 } |
7839 | 8778 |
7840 | 8779 |
7841 TEST(ApiUncaughtExceptionInObjectObserve) { | 8780 TEST(ApiUncaughtExceptionInObjectObserve) { |
7842 v8::internal::FLAG_stack_size = 150; | 8781 v8::internal::FLAG_stack_size = 150; |
7843 report_count = 0; | 8782 report_count = 0; |
7844 LocalContext env; | 8783 LocalContext env; |
7845 v8::Isolate* isolate = env->GetIsolate(); | 8784 v8::Isolate* isolate = env->GetIsolate(); |
7846 v8::HandleScope scope(isolate); | 8785 v8::HandleScope scope(isolate); |
7847 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); | 8786 isolate->AddMessageListener(ApiUncaughtExceptionTestListener); |
7848 CompileRun( | 8787 CompileRun( |
7849 "var obj = {};" | 8788 "var obj = {};" |
7850 "var observe_count = 0;" | 8789 "var observe_count = 0;" |
7851 "function observer1() { ++observe_count; };" | 8790 "function observer1() { ++observe_count; };" |
7852 "function observer2() { ++observe_count; };" | 8791 "function observer2() { ++observe_count; };" |
7853 "function observer_throws() { throw new Error(); };" | 8792 "function observer_throws() { throw new Error(); };" |
7854 "function stack_overflow() { return (function f(x) { f(x+1); })(0); };" | 8793 "function stack_overflow() { return (function f(x) { f(x+1); })(0); };" |
7855 "Object.observe(obj, observer_throws.bind());" | 8794 "Object.observe(obj, observer_throws.bind());" |
7856 "Object.observe(obj, observer1);" | 8795 "Object.observe(obj, observer1);" |
7857 "Object.observe(obj, stack_overflow);" | 8796 "Object.observe(obj, stack_overflow);" |
7858 "Object.observe(obj, observer2);" | 8797 "Object.observe(obj, observer2);" |
7859 "Object.observe(obj, observer_throws.bind());" | 8798 "Object.observe(obj, observer_throws.bind());" |
7860 "obj.foo = 'bar';"); | 8799 "obj.foo = 'bar';"); |
7861 CHECK_EQ(3, report_count); | 8800 CHECK_EQ(3, report_count); |
7862 ExpectInt32("observe_count", 2); | 8801 ExpectInt32("observe_count", 2); |
7863 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | 8802 isolate->RemoveMessageListeners(ApiUncaughtExceptionTestListener); |
7864 } | 8803 } |
7865 | 8804 |
7866 | 8805 |
7867 static const char* script_resource_name = "ExceptionInNativeScript.js"; | 8806 static const char* script_resource_name = "ExceptionInNativeScript.js"; |
7868 static void ExceptionInNativeScriptTestListener(v8::Handle<v8::Message> message, | 8807 static void ExceptionInNativeScriptTestListener(v8::Local<v8::Message> message, |
7869 v8::Handle<Value>) { | 8808 v8::Local<Value>) { |
7870 v8::Handle<v8::Value> name_val = message->GetScriptOrigin().ResourceName(); | 8809 v8::Local<v8::Value> name_val = message->GetScriptOrigin().ResourceName(); |
7871 CHECK(!name_val.IsEmpty() && name_val->IsString()); | 8810 CHECK(!name_val.IsEmpty() && name_val->IsString()); |
7872 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); | 8811 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); |
7873 CHECK_EQ(0, strcmp(script_resource_name, *name)); | 8812 CHECK_EQ(0, strcmp(script_resource_name, *name)); |
7874 CHECK_EQ(3, message->GetLineNumber()); | 8813 v8::Local<v8::Context> context = |
7875 v8::String::Utf8Value source_line(message->GetSourceLine()); | 8814 v8::Isolate::GetCurrent()->GetCurrentContext(); |
8815 CHECK_EQ(3, message->GetLineNumber(context).FromJust()); | |
8816 v8::String::Utf8Value source_line( | |
8817 message->GetSourceLine(context).ToLocalChecked()); | |
7876 CHECK_EQ(0, strcmp(" new o.foo();", *source_line)); | 8818 CHECK_EQ(0, strcmp(" new o.foo();", *source_line)); |
7877 } | 8819 } |
7878 | 8820 |
7879 | 8821 |
7880 TEST(ExceptionInNativeScript) { | 8822 TEST(ExceptionInNativeScript) { |
7881 LocalContext env; | 8823 LocalContext env; |
7882 v8::Isolate* isolate = env->GetIsolate(); | 8824 v8::Isolate* isolate = env->GetIsolate(); |
7883 v8::HandleScope scope(isolate); | 8825 v8::HandleScope scope(isolate); |
7884 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); | 8826 isolate->AddMessageListener(ExceptionInNativeScriptTestListener); |
7885 | 8827 |
7886 Local<v8::FunctionTemplate> fun = | 8828 Local<v8::FunctionTemplate> fun = |
7887 v8::FunctionTemplate::New(isolate, TroubleCallback); | 8829 v8::FunctionTemplate::New(isolate, TroubleCallback); |
7888 v8::Local<v8::Object> global = env->Global(); | 8830 v8::Local<v8::Object> global = env->Global(); |
7889 global->Set(v8_str("trouble"), fun->GetFunction()); | 8831 CHECK(global->Set(env.local(), v8_str("trouble"), |
8832 fun->GetFunction(env.local()).ToLocalChecked()) | |
8833 .FromJust()); | |
7890 | 8834 |
7891 CompileRunWithOrigin( | 8835 CompileRunWithOrigin( |
7892 "function trouble() {\n" | 8836 "function trouble() {\n" |
7893 " var o = {};\n" | 8837 " var o = {};\n" |
7894 " new o.foo();\n" | 8838 " new o.foo();\n" |
7895 "};", | 8839 "};", |
7896 script_resource_name); | 8840 script_resource_name); |
7897 Local<Value> trouble = global->Get(v8_str("trouble")); | 8841 Local<Value> trouble = |
8842 global->Get(env.local(), v8_str("trouble")).ToLocalChecked(); | |
7898 CHECK(trouble->IsFunction()); | 8843 CHECK(trouble->IsFunction()); |
7899 Function::Cast(*trouble)->Call(global, 0, NULL); | 8844 CHECK(Function::Cast(*trouble)->Call(env.local(), global, 0, NULL).IsEmpty()); |
7900 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); | 8845 isolate->RemoveMessageListeners(ExceptionInNativeScriptTestListener); |
7901 } | 8846 } |
7902 | 8847 |
7903 | 8848 |
7904 TEST(CompilationErrorUsingTryCatchHandler) { | 8849 TEST(CompilationErrorUsingTryCatchHandler) { |
7905 LocalContext env; | 8850 LocalContext env; |
7906 v8::HandleScope scope(env->GetIsolate()); | 8851 v8::HandleScope scope(env->GetIsolate()); |
7907 v8::TryCatch try_catch(env->GetIsolate()); | 8852 v8::TryCatch try_catch(env->GetIsolate()); |
7908 v8_compile("This doesn't &*&@#$&*^ compile."); | 8853 v8_compile("This doesn't &*&@#$&*^ compile."); |
7909 CHECK(*try_catch.Exception()); | 8854 CHECK(*try_catch.Exception()); |
7910 CHECK(try_catch.HasCaught()); | 8855 CHECK(try_catch.HasCaught()); |
(...skipping 17 matching lines...) Expand all Loading... | |
7928 CompileRun( | 8873 CompileRun( |
7929 "(function()" | 8874 "(function()" |
7930 " { try { throw ''; } finally { throw 0; }" | 8875 " { try { throw ''; } finally { throw 0; }" |
7931 "})()"); | 8876 "})()"); |
7932 CHECK(try_catch.HasCaught()); | 8877 CHECK(try_catch.HasCaught()); |
7933 } | 8878 } |
7934 | 8879 |
7935 | 8880 |
7936 void CEvaluate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 8881 void CEvaluate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
7937 v8::HandleScope scope(args.GetIsolate()); | 8882 v8::HandleScope scope(args.GetIsolate()); |
7938 CompileRun(args[0]->ToString(args.GetIsolate())); | 8883 CompileRun(args[0] |
8884 ->ToString(args.GetIsolate()->GetCurrentContext()) | |
8885 .ToLocalChecked()); | |
7939 } | 8886 } |
7940 | 8887 |
7941 | 8888 |
7942 TEST(TryCatchFinallyStoresMessageUsingTryCatchHandler) { | 8889 TEST(TryCatchFinallyStoresMessageUsingTryCatchHandler) { |
7943 v8::Isolate* isolate = CcTest::isolate(); | 8890 v8::Isolate* isolate = CcTest::isolate(); |
7944 v8::HandleScope scope(isolate); | 8891 v8::HandleScope scope(isolate); |
7945 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 8892 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
7946 templ->Set(v8_str("CEvaluate"), | 8893 templ->Set(v8_str("CEvaluate"), |
7947 v8::FunctionTemplate::New(isolate, CEvaluate)); | 8894 v8::FunctionTemplate::New(isolate, CEvaluate)); |
7948 LocalContext context(0, templ); | 8895 LocalContext context(0, templ); |
(...skipping 25 matching lines...) Expand all Loading... | |
7974 Local<v8::Object> accessed_object) { | 8921 Local<v8::Object> accessed_object) { |
7975 printf("a\n"); | 8922 printf("a\n"); |
7976 return g_security_callback_result; | 8923 return g_security_callback_result; |
7977 } | 8924 } |
7978 | 8925 |
7979 | 8926 |
7980 // SecurityHandler can't be run twice | 8927 // SecurityHandler can't be run twice |
7981 TEST(SecurityHandler) { | 8928 TEST(SecurityHandler) { |
7982 v8::Isolate* isolate = CcTest::isolate(); | 8929 v8::Isolate* isolate = CcTest::isolate(); |
7983 v8::HandleScope scope0(isolate); | 8930 v8::HandleScope scope0(isolate); |
7984 v8::Handle<v8::ObjectTemplate> global_template = | 8931 v8::Local<v8::ObjectTemplate> global_template = |
7985 v8::ObjectTemplate::New(isolate); | 8932 v8::ObjectTemplate::New(isolate); |
7986 global_template->SetAccessCheckCallback(SecurityTestCallback); | 8933 global_template->SetAccessCheckCallback(SecurityTestCallback); |
7987 // Create an environment | 8934 // Create an environment |
7988 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template); | 8935 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
7989 context0->Enter(); | 8936 context0->Enter(); |
7990 | 8937 |
7991 v8::Handle<v8::Object> global0 = context0->Global(); | 8938 v8::Local<v8::Object> global0 = context0->Global(); |
7992 v8::Handle<Script> script0 = v8_compile("foo = 111"); | 8939 v8::Local<Script> script0 = v8_compile("foo = 111"); |
7993 script0->Run(); | 8940 script0->Run(context0).ToLocalChecked(); |
7994 global0->Set(v8_str("0"), v8_num(999)); | 8941 CHECK(global0->Set(context0, v8_str("0"), v8_num(999)).FromJust()); |
7995 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); | 8942 v8::Local<Value> foo0 = |
7996 CHECK_EQ(111, foo0->Int32Value()); | 8943 global0->Get(context0, v8_str("foo")).ToLocalChecked(); |
7997 v8::Handle<Value> z0 = global0->Get(v8_str("0")); | 8944 CHECK_EQ(111, foo0->Int32Value(context0).FromJust()); |
7998 CHECK_EQ(999, z0->Int32Value()); | 8945 v8::Local<Value> z0 = global0->Get(context0, v8_str("0")).ToLocalChecked(); |
8946 CHECK_EQ(999, z0->Int32Value(context0).FromJust()); | |
7999 | 8947 |
8000 // Create another environment, should fail security checks. | 8948 // Create another environment, should fail security checks. |
8001 v8::HandleScope scope1(isolate); | 8949 v8::HandleScope scope1(isolate); |
8002 | 8950 |
8003 v8::Handle<Context> context1 = | 8951 v8::Local<Context> context1 = Context::New(isolate, NULL, global_template); |
8004 Context::New(isolate, NULL, global_template); | |
8005 context1->Enter(); | 8952 context1->Enter(); |
8006 | 8953 |
8007 v8::Handle<v8::Object> global1 = context1->Global(); | 8954 v8::Local<v8::Object> global1 = context1->Global(); |
8008 global1->Set(v8_str("othercontext"), global0); | 8955 global1->Set(context1, v8_str("othercontext"), global0).FromJust(); |
8009 // This set will fail the security check. | 8956 // This set will fail the security check. |
8010 v8::Handle<Script> script1 = | 8957 v8::Local<Script> script1 = |
8011 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); | 8958 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); |
8012 script1->Run(); | 8959 CHECK(script1->Run(context1).IsEmpty()); |
8013 g_security_callback_result = true; | 8960 g_security_callback_result = true; |
8014 // This read will pass the security check. | 8961 // This read will pass the security check. |
8015 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); | 8962 v8::Local<Value> foo1 = |
8016 CHECK_EQ(111, foo1->Int32Value()); | 8963 global0->Get(context0, v8_str("foo")).ToLocalChecked(); |
8964 CHECK_EQ(111, foo1->Int32Value(context0).FromJust()); | |
8017 // This read will pass the security check. | 8965 // This read will pass the security check. |
8018 v8::Handle<Value> z1 = global0->Get(v8_str("0")); | 8966 v8::Local<Value> z1 = global0->Get(context0, v8_str("0")).ToLocalChecked(); |
8019 CHECK_EQ(999, z1->Int32Value()); | 8967 CHECK_EQ(999, z1->Int32Value(context0).FromJust()); |
8020 | 8968 |
8021 // Create another environment, should pass security checks. | 8969 // Create another environment, should pass security checks. |
8022 { | 8970 { |
8023 v8::HandleScope scope2(isolate); | 8971 v8::HandleScope scope2(isolate); |
8024 LocalContext context2; | 8972 LocalContext context2; |
8025 v8::Handle<v8::Object> global2 = context2->Global(); | 8973 v8::Local<v8::Object> global2 = context2->Global(); |
8026 global2->Set(v8_str("othercontext"), global0); | 8974 CHECK(global2->Set(context2.local(), v8_str("othercontext"), global0) |
8027 v8::Handle<Script> script2 = | 8975 .FromJust()); |
8976 v8::Local<Script> script2 = | |
8028 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); | 8977 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); |
8029 script2->Run(); | 8978 script2->Run(context2.local()).ToLocalChecked(); |
8030 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); | 8979 v8::Local<Value> foo2 = |
8031 CHECK_EQ(333, foo2->Int32Value()); | 8980 global0->Get(context2.local(), v8_str("foo")).ToLocalChecked(); |
8032 v8::Handle<Value> z2 = global0->Get(v8_str("0")); | 8981 CHECK_EQ(333, foo2->Int32Value(context2.local()).FromJust()); |
8033 CHECK_EQ(888, z2->Int32Value()); | 8982 v8::Local<Value> z2 = |
8983 global0->Get(context2.local(), v8_str("0")).ToLocalChecked(); | |
8984 CHECK_EQ(888, z2->Int32Value(context2.local()).FromJust()); | |
8034 } | 8985 } |
8035 | 8986 |
8036 context1->Exit(); | 8987 context1->Exit(); |
8037 context0->Exit(); | 8988 context0->Exit(); |
8038 } | 8989 } |
8039 | 8990 |
8040 | 8991 |
8041 THREADED_TEST(SecurityChecks) { | 8992 THREADED_TEST(SecurityChecks) { |
8042 LocalContext env1; | 8993 LocalContext env1; |
8043 v8::HandleScope handle_scope(env1->GetIsolate()); | 8994 v8::HandleScope handle_scope(env1->GetIsolate()); |
8044 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 8995 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8045 | 8996 |
8046 Local<Value> foo = v8_str("foo"); | 8997 Local<Value> foo = v8_str("foo"); |
8047 Local<Value> bar = v8_str("bar"); | 8998 Local<Value> bar = v8_str("bar"); |
8048 | 8999 |
8049 // Set to the same domain. | 9000 // Set to the same domain. |
8050 env1->SetSecurityToken(foo); | 9001 env1->SetSecurityToken(foo); |
8051 | 9002 |
8052 // Create a function in env1. | 9003 // Create a function in env1. |
8053 CompileRun("spy=function(){return spy;}"); | 9004 CompileRun("spy=function(){return spy;}"); |
8054 Local<Value> spy = env1->Global()->Get(v8_str("spy")); | 9005 Local<Value> spy = |
9006 env1->Global()->Get(env1.local(), v8_str("spy")).ToLocalChecked(); | |
8055 CHECK(spy->IsFunction()); | 9007 CHECK(spy->IsFunction()); |
8056 | 9008 |
8057 // Create another function accessing global objects. | 9009 // Create another function accessing global objects. |
8058 CompileRun("spy2=function(){return new this.Array();}"); | 9010 CompileRun("spy2=function(){return new this.Array();}"); |
8059 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2")); | 9011 Local<Value> spy2 = |
9012 env1->Global()->Get(env1.local(), v8_str("spy2")).ToLocalChecked(); | |
8060 CHECK(spy2->IsFunction()); | 9013 CHECK(spy2->IsFunction()); |
8061 | 9014 |
8062 // Switch to env2 in the same domain and invoke spy on env2. | 9015 // Switch to env2 in the same domain and invoke spy on env2. |
8063 { | 9016 { |
8064 env2->SetSecurityToken(foo); | 9017 env2->SetSecurityToken(foo); |
8065 // Enter env2 | 9018 // Enter env2 |
8066 Context::Scope scope_env2(env2); | 9019 Context::Scope scope_env2(env2); |
8067 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL); | 9020 Local<Value> result = Function::Cast(*spy) |
9021 ->Call(env2, env2->Global(), 0, NULL) | |
9022 .ToLocalChecked(); | |
8068 CHECK(result->IsFunction()); | 9023 CHECK(result->IsFunction()); |
8069 } | 9024 } |
8070 | 9025 |
8071 { | 9026 { |
8072 env2->SetSecurityToken(bar); | 9027 env2->SetSecurityToken(bar); |
8073 Context::Scope scope_env2(env2); | 9028 Context::Scope scope_env2(env2); |
8074 | 9029 |
8075 // Call cross_domain_call, it should throw an exception | 9030 // Call cross_domain_call, it should throw an exception |
8076 v8::TryCatch try_catch(env1->GetIsolate()); | 9031 v8::TryCatch try_catch(env1->GetIsolate()); |
8077 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); | 9032 CHECK(Function::Cast(*spy2)->Call(env2, env2->Global(), 0, NULL).IsEmpty()); |
8078 CHECK(try_catch.HasCaught()); | 9033 CHECK(try_catch.HasCaught()); |
8079 } | 9034 } |
8080 } | 9035 } |
8081 | 9036 |
8082 | 9037 |
8083 // Regression test case for issue 1183439. | 9038 // Regression test case for issue 1183439. |
8084 THREADED_TEST(SecurityChecksForPrototypeChain) { | 9039 THREADED_TEST(SecurityChecksForPrototypeChain) { |
8085 LocalContext current; | 9040 LocalContext current; |
8086 v8::HandleScope scope(current->GetIsolate()); | 9041 v8::HandleScope scope(current->GetIsolate()); |
8087 v8::Handle<Context> other = Context::New(current->GetIsolate()); | 9042 v8::Local<Context> other = Context::New(current->GetIsolate()); |
8088 | 9043 |
8089 // Change context to be able to get to the Object function in the | 9044 // Change context to be able to get to the Object function in the |
8090 // other context without hitting the security checks. | 9045 // other context without hitting the security checks. |
8091 v8::Local<Value> other_object; | 9046 v8::Local<Value> other_object; |
8092 { Context::Scope scope(other); | 9047 { Context::Scope scope(other); |
8093 other_object = other->Global()->Get(v8_str("Object")); | 9048 other_object = |
8094 other->Global()->Set(v8_num(42), v8_num(87)); | 9049 other->Global()->Get(other, v8_str("Object")).ToLocalChecked(); |
9050 CHECK(other->Global()->Set(other, v8_num(42), v8_num(87)).FromJust()); | |
8095 } | 9051 } |
8096 | 9052 |
8097 current->Global()->Set(v8_str("other"), other->Global()); | 9053 CHECK(current->Global() |
8098 CHECK(v8_compile("other")->Run()->Equals(other->Global())); | 9054 ->Set(current.local(), v8_str("other"), other->Global()) |
9055 .FromJust()); | |
9056 CHECK(v8_compile("other") | |
9057 ->Run(current.local()) | |
9058 .ToLocalChecked() | |
9059 ->Equals(current.local(), other->Global()) | |
9060 .FromJust()); | |
8099 | 9061 |
8100 // Make sure the security check fails here and we get an undefined | 9062 // Make sure the security check fails here and we get an undefined |
8101 // result instead of getting the Object function. Repeat in a loop | 9063 // result instead of getting the Object function. Repeat in a loop |
8102 // to make sure to exercise the IC code. | 9064 // to make sure to exercise the IC code. |
8103 v8::Local<Script> access_other0 = v8_compile("other.Object"); | 9065 v8::Local<Script> access_other0 = v8_compile("other.Object"); |
8104 v8::Local<Script> access_other1 = v8_compile("other[42]"); | 9066 v8::Local<Script> access_other1 = v8_compile("other[42]"); |
8105 for (int i = 0; i < 5; i++) { | 9067 for (int i = 0; i < 5; i++) { |
8106 CHECK(access_other0->Run().IsEmpty()); | 9068 CHECK(access_other0->Run(current.local()).IsEmpty()); |
8107 CHECK(access_other1->Run().IsEmpty()); | 9069 CHECK(access_other1->Run(current.local()).IsEmpty()); |
8108 } | 9070 } |
8109 | 9071 |
8110 // Create an object that has 'other' in its prototype chain and make | 9072 // Create an object that has 'other' in its prototype chain and make |
8111 // sure we cannot access the Object function indirectly through | 9073 // sure we cannot access the Object function indirectly through |
8112 // that. Repeat in a loop to make sure to exercise the IC code. | 9074 // that. Repeat in a loop to make sure to exercise the IC code. |
8113 v8_compile("function F() { };" | 9075 v8_compile( |
8114 "F.prototype = other;" | 9076 "function F() { };" |
8115 "var f = new F();")->Run(); | 9077 "F.prototype = other;" |
9078 "var f = new F();") | |
9079 ->Run(current.local()) | |
9080 .ToLocalChecked(); | |
8116 v8::Local<Script> access_f0 = v8_compile("f.Object"); | 9081 v8::Local<Script> access_f0 = v8_compile("f.Object"); |
8117 v8::Local<Script> access_f1 = v8_compile("f[42]"); | 9082 v8::Local<Script> access_f1 = v8_compile("f[42]"); |
8118 for (int j = 0; j < 5; j++) { | 9083 for (int j = 0; j < 5; j++) { |
8119 CHECK(access_f0->Run().IsEmpty()); | 9084 CHECK(access_f0->Run(current.local()).IsEmpty()); |
8120 CHECK(access_f1->Run().IsEmpty()); | 9085 CHECK(access_f1->Run(current.local()).IsEmpty()); |
8121 } | 9086 } |
8122 | 9087 |
8123 // Now it gets hairy: Set the prototype for the other global object | 9088 // Now it gets hairy: Set the prototype for the other global object |
8124 // to be the current global object. The prototype chain for 'f' now | 9089 // to be the current global object. The prototype chain for 'f' now |
8125 // goes through 'other' but ends up in the current global object. | 9090 // goes through 'other' but ends up in the current global object. |
8126 { Context::Scope scope(other); | 9091 { Context::Scope scope(other); |
8127 other->Global()->Set(v8_str("__proto__"), current->Global()); | 9092 CHECK(other->Global() |
9093 ->Set(other, v8_str("__proto__"), current->Global()) | |
9094 .FromJust()); | |
8128 } | 9095 } |
8129 // Set a named and an index property on the current global | 9096 // Set a named and an index property on the current global |
8130 // object. To force the lookup to go through the other global object, | 9097 // object. To force the lookup to go through the other global object, |
8131 // the properties must not exist in the other global object. | 9098 // the properties must not exist in the other global object. |
8132 current->Global()->Set(v8_str("foo"), v8_num(100)); | 9099 CHECK(current->Global() |
8133 current->Global()->Set(v8_num(99), v8_num(101)); | 9100 ->Set(current.local(), v8_str("foo"), v8_num(100)) |
9101 .FromJust()); | |
9102 CHECK(current->Global() | |
9103 ->Set(current.local(), v8_num(99), v8_num(101)) | |
9104 .FromJust()); | |
8134 // Try to read the properties from f and make sure that the access | 9105 // Try to read the properties from f and make sure that the access |
8135 // gets stopped by the security checks on the other global object. | 9106 // gets stopped by the security checks on the other global object. |
8136 Local<Script> access_f2 = v8_compile("f.foo"); | 9107 Local<Script> access_f2 = v8_compile("f.foo"); |
8137 Local<Script> access_f3 = v8_compile("f[99]"); | 9108 Local<Script> access_f3 = v8_compile("f[99]"); |
8138 for (int k = 0; k < 5; k++) { | 9109 for (int k = 0; k < 5; k++) { |
8139 CHECK(access_f2->Run().IsEmpty()); | 9110 CHECK(access_f2->Run(current.local()).IsEmpty()); |
8140 CHECK(access_f3->Run().IsEmpty()); | 9111 CHECK(access_f3->Run(current.local()).IsEmpty()); |
8141 } | 9112 } |
8142 } | 9113 } |
8143 | 9114 |
8144 | 9115 |
8145 static bool security_check_with_gc_called; | 9116 static bool security_check_with_gc_called; |
8146 | 9117 |
8147 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context, | 9118 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context, |
8148 Local<v8::Object> accessed_object) { | 9119 Local<v8::Object> accessed_object) { |
8149 CcTest::heap()->CollectAllGarbage(); | 9120 CcTest::heap()->CollectAllGarbage(); |
8150 security_check_with_gc_called = true; | 9121 security_check_with_gc_called = true; |
8151 return true; | 9122 return true; |
8152 } | 9123 } |
8153 | 9124 |
8154 | 9125 |
8155 TEST(SecurityTestGCAllowed) { | 9126 TEST(SecurityTestGCAllowed) { |
8156 v8::Isolate* isolate = CcTest::isolate(); | 9127 v8::Isolate* isolate = CcTest::isolate(); |
8157 v8::HandleScope handle_scope(isolate); | 9128 v8::HandleScope handle_scope(isolate); |
8158 v8::Handle<v8::ObjectTemplate> object_template = | 9129 v8::Local<v8::ObjectTemplate> object_template = |
8159 v8::ObjectTemplate::New(isolate); | 9130 v8::ObjectTemplate::New(isolate); |
8160 object_template->SetAccessCheckCallback(SecurityTestCallbackWithGC); | 9131 object_template->SetAccessCheckCallback(SecurityTestCallbackWithGC); |
8161 | 9132 |
8162 v8::Handle<Context> context = Context::New(isolate); | 9133 v8::Local<Context> context = Context::New(isolate); |
8163 v8::Context::Scope context_scope(context); | 9134 v8::Context::Scope context_scope(context); |
8164 | 9135 |
8165 context->Global()->Set(v8_str("obj"), object_template->NewInstance()); | 9136 CHECK(context->Global() |
9137 ->Set(context, v8_str("obj"), | |
9138 object_template->NewInstance(context).ToLocalChecked()) | |
9139 .FromJust()); | |
8166 | 9140 |
8167 security_check_with_gc_called = false; | 9141 security_check_with_gc_called = false; |
8168 CompileRun("obj[0] = new String(1002);"); | 9142 CompileRun("obj[0] = new String(1002);"); |
8169 CHECK(security_check_with_gc_called); | 9143 CHECK(security_check_with_gc_called); |
8170 | 9144 |
8171 security_check_with_gc_called = false; | 9145 security_check_with_gc_called = false; |
8172 CHECK(CompileRun("obj[0]")->ToString(isolate)->Equals(v8_str("1002"))); | 9146 CHECK(CompileRun("obj[0]") |
9147 ->ToString(context) | |
9148 .ToLocalChecked() | |
9149 ->Equals(context, v8_str("1002")) | |
9150 .FromJust()); | |
8173 CHECK(security_check_with_gc_called); | 9151 CHECK(security_check_with_gc_called); |
8174 } | 9152 } |
8175 | 9153 |
8176 | 9154 |
8177 THREADED_TEST(CrossDomainDelete) { | 9155 THREADED_TEST(CrossDomainDelete) { |
8178 LocalContext env1; | 9156 LocalContext env1; |
8179 v8::HandleScope handle_scope(env1->GetIsolate()); | 9157 v8::HandleScope handle_scope(env1->GetIsolate()); |
8180 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9158 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8181 | 9159 |
8182 Local<Value> foo = v8_str("foo"); | 9160 Local<Value> foo = v8_str("foo"); |
8183 Local<Value> bar = v8_str("bar"); | 9161 Local<Value> bar = v8_str("bar"); |
8184 | 9162 |
8185 // Set to the same domain. | 9163 // Set to the same domain. |
8186 env1->SetSecurityToken(foo); | 9164 env1->SetSecurityToken(foo); |
8187 env2->SetSecurityToken(foo); | 9165 env2->SetSecurityToken(foo); |
8188 | 9166 |
8189 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 9167 CHECK(env1->Global()->Set(env2, v8_str("prop"), v8_num(3)).FromJust()); |
jochen (gone - plz use gerrit)
2015/11/24 12:42:25
should be env1 here
vogelheim
2015/11/26 10:57:32
Done.
| |
8190 env2->Global()->Set(v8_str("env1"), env1->Global()); | 9168 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust()); |
8191 | 9169 |
8192 // Change env2 to a different domain and delete env1.prop. | 9170 // Change env2 to a different domain and delete env1.prop. |
8193 env2->SetSecurityToken(bar); | 9171 env2->SetSecurityToken(bar); |
8194 { | 9172 { |
8195 Context::Scope scope_env2(env2); | 9173 Context::Scope scope_env2(env2); |
8196 Local<Value> result = | 9174 Local<Value> result = |
8197 CompileRun("delete env1.prop"); | 9175 CompileRun("delete env1.prop"); |
8198 CHECK(result.IsEmpty()); | 9176 CHECK(result.IsEmpty()); |
8199 } | 9177 } |
8200 | 9178 |
8201 // Check that env1.prop still exists. | 9179 // Check that env1.prop still exists. |
8202 Local<Value> v = env1->Global()->Get(v8_str("prop")); | 9180 Local<Value> v = |
9181 env1->Global()->Get(env1.local(), v8_str("prop")).ToLocalChecked(); | |
8203 CHECK(v->IsNumber()); | 9182 CHECK(v->IsNumber()); |
8204 CHECK_EQ(3, v->Int32Value()); | 9183 CHECK_EQ(3, v->Int32Value(env1.local()).FromJust()); |
8205 } | 9184 } |
8206 | 9185 |
8207 | 9186 |
8208 THREADED_TEST(CrossDomainIsPropertyEnumerable) { | 9187 THREADED_TEST(CrossDomainIsPropertyEnumerable) { |
8209 LocalContext env1; | 9188 LocalContext env1; |
8210 v8::HandleScope handle_scope(env1->GetIsolate()); | 9189 v8::HandleScope handle_scope(env1->GetIsolate()); |
8211 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9190 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8212 | 9191 |
8213 Local<Value> foo = v8_str("foo"); | 9192 Local<Value> foo = v8_str("foo"); |
8214 Local<Value> bar = v8_str("bar"); | 9193 Local<Value> bar = v8_str("bar"); |
8215 | 9194 |
8216 // Set to the same domain. | 9195 // Set to the same domain. |
8217 env1->SetSecurityToken(foo); | 9196 env1->SetSecurityToken(foo); |
8218 env2->SetSecurityToken(foo); | 9197 env2->SetSecurityToken(foo); |
8219 | 9198 |
8220 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 9199 CHECK( |
8221 env2->Global()->Set(v8_str("env1"), env1->Global()); | 9200 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust()); |
9201 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust()); | |
8222 | 9202 |
8223 // env1.prop is enumerable in env2. | 9203 // env1.prop is enumerable in env2. |
8224 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); | 9204 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); |
8225 { | 9205 { |
8226 Context::Scope scope_env2(env2); | 9206 Context::Scope scope_env2(env2); |
8227 Local<Value> result = CompileRun(test); | 9207 Local<Value> result = CompileRun(test); |
8228 CHECK(result->IsTrue()); | 9208 CHECK(result->IsTrue()); |
8229 } | 9209 } |
8230 | 9210 |
8231 // Change env2 to a different domain and test again. | 9211 // Change env2 to a different domain and test again. |
8232 env2->SetSecurityToken(bar); | 9212 env2->SetSecurityToken(bar); |
8233 { | 9213 { |
8234 Context::Scope scope_env2(env2); | 9214 Context::Scope scope_env2(env2); |
8235 Local<Value> result = CompileRun(test); | 9215 Local<Value> result = CompileRun(test); |
8236 CHECK(result.IsEmpty()); | 9216 CHECK(result.IsEmpty()); |
8237 } | 9217 } |
8238 } | 9218 } |
8239 | 9219 |
8240 | 9220 |
8241 THREADED_TEST(CrossDomainFor) { | 9221 THREADED_TEST(CrossDomainFor) { |
8242 LocalContext env1; | 9222 LocalContext env1; |
8243 v8::HandleScope handle_scope(env1->GetIsolate()); | 9223 v8::HandleScope handle_scope(env1->GetIsolate()); |
8244 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9224 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8245 | 9225 |
8246 Local<Value> foo = v8_str("foo"); | 9226 Local<Value> foo = v8_str("foo"); |
8247 Local<Value> bar = v8_str("bar"); | 9227 Local<Value> bar = v8_str("bar"); |
8248 | 9228 |
8249 // Set to the same domain. | 9229 // Set to the same domain. |
8250 env1->SetSecurityToken(foo); | 9230 env1->SetSecurityToken(foo); |
8251 env2->SetSecurityToken(foo); | 9231 env2->SetSecurityToken(foo); |
8252 | 9232 |
8253 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 9233 CHECK( |
8254 env2->Global()->Set(v8_str("env1"), env1->Global()); | 9234 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust()); |
9235 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust()); | |
8255 | 9236 |
8256 // Change env2 to a different domain and set env1's global object | 9237 // Change env2 to a different domain and set env1's global object |
8257 // as the __proto__ of an object in env2 and enumerate properties | 9238 // as the __proto__ of an object in env2 and enumerate properties |
8258 // in for-in. It shouldn't enumerate properties on env1's global | 9239 // in for-in. It shouldn't enumerate properties on env1's global |
8259 // object. | 9240 // object. |
8260 env2->SetSecurityToken(bar); | 9241 env2->SetSecurityToken(bar); |
8261 { | 9242 { |
8262 Context::Scope scope_env2(env2); | 9243 Context::Scope scope_env2(env2); |
8263 Local<Value> result = CompileRun( | 9244 Local<Value> result = CompileRun( |
8264 "(function() {" | 9245 "(function() {" |
8265 " try {" | 9246 " try {" |
8266 " for (var p in env1) {" | 9247 " for (var p in env1) {" |
8267 " if (p == 'prop') return false;" | 9248 " if (p == 'prop') return false;" |
8268 " }" | 9249 " }" |
8269 " return true;" | 9250 " return true;" |
8270 " } catch (e) {" | 9251 " } catch (e) {" |
8271 " return false;" | 9252 " return false;" |
8272 " }" | 9253 " }" |
8273 "})()"); | 9254 "})()"); |
8274 CHECK(result->IsTrue()); | 9255 CHECK(result->IsTrue()); |
8275 } | 9256 } |
8276 } | 9257 } |
8277 | 9258 |
8278 | 9259 |
8279 THREADED_TEST(CrossDomainForInOnPrototype) { | 9260 THREADED_TEST(CrossDomainForInOnPrototype) { |
8280 LocalContext env1; | 9261 LocalContext env1; |
8281 v8::HandleScope handle_scope(env1->GetIsolate()); | 9262 v8::HandleScope handle_scope(env1->GetIsolate()); |
8282 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9263 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8283 | 9264 |
8284 Local<Value> foo = v8_str("foo"); | 9265 Local<Value> foo = v8_str("foo"); |
8285 Local<Value> bar = v8_str("bar"); | 9266 Local<Value> bar = v8_str("bar"); |
8286 | 9267 |
8287 // Set to the same domain. | 9268 // Set to the same domain. |
8288 env1->SetSecurityToken(foo); | 9269 env1->SetSecurityToken(foo); |
8289 env2->SetSecurityToken(foo); | 9270 env2->SetSecurityToken(foo); |
8290 | 9271 |
8291 env1->Global()->Set(v8_str("prop"), v8_num(3)); | 9272 CHECK( |
8292 env2->Global()->Set(v8_str("env1"), env1->Global()); | 9273 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust()); |
9274 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust()); | |
8293 | 9275 |
8294 // Change env2 to a different domain and set env1's global object | 9276 // Change env2 to a different domain and set env1's global object |
8295 // as the __proto__ of an object in env2 and enumerate properties | 9277 // as the __proto__ of an object in env2 and enumerate properties |
8296 // in for-in. It shouldn't enumerate properties on env1's global | 9278 // in for-in. It shouldn't enumerate properties on env1's global |
8297 // object. | 9279 // object. |
8298 env2->SetSecurityToken(bar); | 9280 env2->SetSecurityToken(bar); |
8299 { | 9281 { |
8300 Context::Scope scope_env2(env2); | 9282 Context::Scope scope_env2(env2); |
8301 Local<Value> result = CompileRun( | 9283 Local<Value> result = CompileRun( |
8302 "(function() {" | 9284 "(function() {" |
8303 " var obj = { '__proto__': env1 };" | 9285 " var obj = { '__proto__': env1 };" |
8304 " try {" | 9286 " try {" |
8305 " for (var p in obj) {" | 9287 " for (var p in obj) {" |
8306 " if (p == 'prop') return false;" | 9288 " if (p == 'prop') return false;" |
8307 " }" | 9289 " }" |
8308 " return false;" | 9290 " return false;" |
8309 " } catch (e) {" | 9291 " } catch (e) {" |
8310 " return true;" | 9292 " return true;" |
8311 " }" | 9293 " }" |
8312 "})()"); | 9294 "})()"); |
8313 CHECK(result->IsTrue()); | 9295 CHECK(result->IsTrue()); |
8314 } | 9296 } |
8315 } | 9297 } |
8316 | 9298 |
8317 | 9299 |
8318 TEST(ContextDetachGlobal) { | 9300 TEST(ContextDetachGlobal) { |
8319 LocalContext env1; | 9301 LocalContext env1; |
8320 v8::HandleScope handle_scope(env1->GetIsolate()); | 9302 v8::HandleScope handle_scope(env1->GetIsolate()); |
8321 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9303 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8322 | 9304 |
8323 Local<v8::Object> global1 = env1->Global(); | |
8324 | 9305 |
8325 Local<Value> foo = v8_str("foo"); | 9306 Local<Value> foo = v8_str("foo"); |
8326 | 9307 |
8327 // Set to the same domain. | 9308 // Set to the same domain. |
8328 env1->SetSecurityToken(foo); | 9309 env1->SetSecurityToken(foo); |
8329 env2->SetSecurityToken(foo); | 9310 env2->SetSecurityToken(foo); |
8330 | 9311 |
8331 // Enter env2 | 9312 // Enter env2 |
8332 env2->Enter(); | 9313 env2->Enter(); |
8333 | 9314 |
8334 // Create a function in env2 and add a reference to it in env1. | 9315 // Create a function in env2 and add a reference to it in env1. |
8335 Local<v8::Object> global2 = env2->Global(); | 9316 Local<v8::Object> global2 = env2->Global(); |
8336 global2->Set(v8_str("prop"), v8::Integer::New(env2->GetIsolate(), 1)); | 9317 CHECK(global2->Set(env2, v8_str("prop"), |
9318 v8::Integer::New(env2->GetIsolate(), 1)) | |
9319 .FromJust()); | |
8337 CompileRun("function getProp() {return prop;}"); | 9320 CompileRun("function getProp() {return prop;}"); |
8338 | 9321 |
8339 env1->Global()->Set(v8_str("getProp"), | 9322 CHECK(env1->Global() |
8340 global2->Get(v8_str("getProp"))); | 9323 ->Set(env1.local(), v8_str("getProp"), |
9324 global2->Get(env2, v8_str("getProp")).ToLocalChecked()) | |
9325 .FromJust()); | |
8341 | 9326 |
8342 // Detach env2's global, and reuse the global object of env2 | 9327 // Detach env2's global, and reuse the global object of env2 |
8343 env2->Exit(); | 9328 env2->Exit(); |
8344 env2->DetachGlobal(); | 9329 env2->DetachGlobal(); |
8345 | 9330 |
8346 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), | 9331 v8::Local<Context> env3 = Context::New( |
8347 0, | 9332 env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(), global2); |
8348 v8::Handle<v8::ObjectTemplate>(), | |
8349 global2); | |
8350 env3->SetSecurityToken(v8_str("bar")); | 9333 env3->SetSecurityToken(v8_str("bar")); |
9334 | |
8351 env3->Enter(); | 9335 env3->Enter(); |
8352 | |
8353 Local<v8::Object> global3 = env3->Global(); | 9336 Local<v8::Object> global3 = env3->Global(); |
8354 CHECK(global2->Equals(global3)); | 9337 CHECK(global2->Equals(env3, global3).FromJust()); |
8355 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); | 9338 CHECK(global3->Get(env3, v8_str("prop")).ToLocalChecked()->IsUndefined()); |
8356 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); | 9339 CHECK(global3->Get(env3, v8_str("getProp")).ToLocalChecked()->IsUndefined()); |
8357 global3->Set(v8_str("prop"), v8::Integer::New(env3->GetIsolate(), -1)); | 9340 CHECK(global3->Set(env3, v8_str("prop"), |
8358 global3->Set(v8_str("prop2"), v8::Integer::New(env3->GetIsolate(), 2)); | 9341 v8::Integer::New(env3->GetIsolate(), -1)) |
9342 .FromJust()); | |
9343 CHECK(global3->Set(env3, v8_str("prop2"), | |
9344 v8::Integer::New(env3->GetIsolate(), 2)) | |
9345 .FromJust()); | |
8359 env3->Exit(); | 9346 env3->Exit(); |
8360 | 9347 |
8361 // Call getProp in env1, and it should return the value 1 | 9348 // Call getProp in env1, and it should return the value 1 |
8362 { | 9349 { |
8363 Local<Value> get_prop = global1->Get(v8_str("getProp")); | 9350 Local<v8::Object> global1 = env1->Global(); |
9351 Local<Value> get_prop = | |
9352 global1->Get(env1.local(), v8_str("getProp")).ToLocalChecked(); | |
8364 CHECK(get_prop->IsFunction()); | 9353 CHECK(get_prop->IsFunction()); |
8365 v8::TryCatch try_catch(env1->GetIsolate()); | 9354 v8::TryCatch try_catch(env1->GetIsolate()); |
8366 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); | 9355 Local<Value> r = Function::Cast(*get_prop) |
9356 ->Call(env1.local(), global1, 0, NULL) | |
9357 .ToLocalChecked(); | |
8367 CHECK(!try_catch.HasCaught()); | 9358 CHECK(!try_catch.HasCaught()); |
8368 CHECK_EQ(1, r->Int32Value()); | 9359 CHECK_EQ(1, r->Int32Value(env1.local()).FromJust()); |
8369 } | 9360 } |
8370 | 9361 |
8371 // Check that env3 is not accessible from env1 | 9362 // Check that env3 is not accessible from env1 |
8372 { | 9363 { |
8373 Local<Value> r = global3->Get(v8_str("prop2")); | 9364 v8::MaybeLocal<Value> r = global3->Get(env1.local(), v8_str("prop2")); |
8374 CHECK(r.IsEmpty()); | 9365 CHECK(r.IsEmpty()); |
8375 } | 9366 } |
8376 } | 9367 } |
8377 | 9368 |
8378 | 9369 |
8379 TEST(DetachGlobal) { | 9370 TEST(DetachGlobal) { |
8380 LocalContext env1; | 9371 LocalContext env1; |
8381 v8::HandleScope scope(env1->GetIsolate()); | 9372 v8::HandleScope scope(env1->GetIsolate()); |
8382 | 9373 |
8383 // Create second environment. | 9374 // Create second environment. |
8384 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); | 9375 v8::Local<Context> env2 = Context::New(env1->GetIsolate()); |
8385 | 9376 |
8386 Local<Value> foo = v8_str("foo"); | 9377 Local<Value> foo = v8_str("foo"); |
8387 | 9378 |
8388 // Set same security token for env1 and env2. | 9379 // Set same security token for env1 and env2. |
8389 env1->SetSecurityToken(foo); | 9380 env1->SetSecurityToken(foo); |
8390 env2->SetSecurityToken(foo); | 9381 env2->SetSecurityToken(foo); |
8391 | 9382 |
8392 // Create a property on the global object in env2. | 9383 // Create a property on the global object in env2. |
8393 { | 9384 { |
8394 v8::Context::Scope scope(env2); | 9385 v8::Context::Scope scope(env2); |
8395 env2->Global()->Set(v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42)); | 9386 CHECK(env2->Global() |
9387 ->Set(env2, v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42)) | |
9388 .FromJust()); | |
8396 } | 9389 } |
8397 | 9390 |
8398 // Create a reference to env2 global from env1 global. | 9391 // Create a reference to env2 global from env1 global. |
8399 env1->Global()->Set(v8_str("other"), env2->Global()); | 9392 CHECK(env1->Global() |
9393 ->Set(env1.local(), v8_str("other"), env2->Global()) | |
9394 .FromJust()); | |
8400 | 9395 |
8401 // Check that we have access to other.p in env2 from env1. | 9396 // Check that we have access to other.p in env2 from env1. |
8402 Local<Value> result = CompileRun("other.p"); | 9397 Local<Value> result = CompileRun("other.p"); |
8403 CHECK(result->IsInt32()); | 9398 CHECK(result->IsInt32()); |
8404 CHECK_EQ(42, result->Int32Value()); | 9399 CHECK_EQ(42, result->Int32Value(env1.local()).FromJust()); |
8405 | 9400 |
8406 // Hold on to global from env2 and detach global from env2. | 9401 // Hold on to global from env2 and detach global from env2. |
8407 Local<v8::Object> global2 = env2->Global(); | 9402 Local<v8::Object> global2 = env2->Global(); |
8408 env2->DetachGlobal(); | 9403 env2->DetachGlobal(); |
8409 | 9404 |
8410 // Check that the global has been detached. No other.p property can | 9405 // Check that the global has been detached. No other.p property can |
8411 // be found. | 9406 // be found. |
8412 result = CompileRun("other.p"); | 9407 result = CompileRun("other.p"); |
8413 CHECK(result.IsEmpty()); | 9408 CHECK(result.IsEmpty()); |
8414 | 9409 |
8415 // Reuse global2 for env3. | 9410 // Reuse global2 for env3. |
8416 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), | 9411 v8::Local<Context> env3 = Context::New( |
8417 0, | 9412 env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(), global2); |
8418 v8::Handle<v8::ObjectTemplate>(), | 9413 CHECK(global2->Equals(env1.local(), env3->Global()).FromJust()); |
8419 global2); | |
8420 CHECK(global2->Equals(env3->Global())); | |
8421 | 9414 |
8422 // Start by using the same security token for env3 as for env1 and env2. | 9415 // Start by using the same security token for env3 as for env1 and env2. |
8423 env3->SetSecurityToken(foo); | 9416 env3->SetSecurityToken(foo); |
8424 | 9417 |
8425 // Create a property on the global object in env3. | 9418 // Create a property on the global object in env3. |
8426 { | 9419 { |
8427 v8::Context::Scope scope(env3); | 9420 v8::Context::Scope scope(env3); |
8428 env3->Global()->Set(v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24)); | 9421 CHECK(env3->Global() |
9422 ->Set(env3, v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24)) | |
9423 .FromJust()); | |
8429 } | 9424 } |
8430 | 9425 |
8431 // Check that other.p is now the property in env3 and that we have access. | 9426 // Check that other.p is now the property in env3 and that we have access. |
8432 result = CompileRun("other.p"); | 9427 result = CompileRun("other.p"); |
8433 CHECK(result->IsInt32()); | 9428 CHECK(result->IsInt32()); |
8434 CHECK_EQ(24, result->Int32Value()); | 9429 CHECK_EQ(24, result->Int32Value(env3).FromJust()); |
8435 | 9430 |
8436 // Change security token for env3 to something different from env1 and env2. | 9431 // Change security token for env3 to something different from env1 and env2. |
8437 env3->SetSecurityToken(v8_str("bar")); | 9432 env3->SetSecurityToken(v8_str("bar")); |
8438 | 9433 |
8439 // Check that we do not have access to other.p in env1. |other| is now | 9434 // Check that we do not have access to other.p in env1. |other| is now |
8440 // the global object for env3 which has a different security token, | 9435 // the global object for env3 which has a different security token, |
8441 // so access should be blocked. | 9436 // so access should be blocked. |
8442 result = CompileRun("other.p"); | 9437 result = CompileRun("other.p"); |
8443 CHECK(result.IsEmpty()); | 9438 CHECK(result.IsEmpty()); |
8444 } | 9439 } |
8445 | 9440 |
8446 | 9441 |
8447 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) { | 9442 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) { |
9443 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); | |
8448 info.GetReturnValue().Set( | 9444 info.GetReturnValue().Set( |
8449 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x"))); | 9445 context->Global()->Get(context, v8_str("x")).ToLocalChecked()); |
8450 } | 9446 } |
8451 | 9447 |
8452 | 9448 |
8453 TEST(DetachedAccesses) { | 9449 TEST(DetachedAccesses) { |
8454 LocalContext env1; | 9450 LocalContext env1; |
8455 v8::HandleScope scope(env1->GetIsolate()); | 9451 v8::HandleScope scope(env1->GetIsolate()); |
8456 | 9452 |
8457 // Create second environment. | 9453 // Create second environment. |
8458 Local<ObjectTemplate> inner_global_template = | 9454 Local<ObjectTemplate> inner_global_template = |
8459 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate(); | 9455 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate(); |
8460 inner_global_template ->SetAccessorProperty( | 9456 inner_global_template ->SetAccessorProperty( |
8461 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX)); | 9457 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX)); |
8462 v8::Local<Context> env2 = | 9458 v8::Local<Context> env2 = |
8463 Context::New(env1->GetIsolate(), NULL, inner_global_template); | 9459 Context::New(env1->GetIsolate(), NULL, inner_global_template); |
8464 | 9460 |
8465 Local<Value> foo = v8_str("foo"); | 9461 Local<Value> foo = v8_str("foo"); |
8466 | 9462 |
8467 // Set same security token for env1 and env2. | 9463 // Set same security token for env1 and env2. |
8468 env1->SetSecurityToken(foo); | 9464 env1->SetSecurityToken(foo); |
8469 env2->SetSecurityToken(foo); | 9465 env2->SetSecurityToken(foo); |
8470 | 9466 |
8471 env1->Global()->Set(v8_str("x"), v8_str("env1_x")); | 9467 CHECK(env1->Global() |
9468 ->Set(env1.local(), v8_str("x"), v8_str("env1_x")) | |
9469 .FromJust()); | |
8472 | 9470 |
8473 { | 9471 { |
8474 v8::Context::Scope scope(env2); | 9472 v8::Context::Scope scope(env2); |
8475 env2->Global()->Set(v8_str("x"), v8_str("env2_x")); | 9473 CHECK(env2->Global()->Set(env2, v8_str("x"), v8_str("env2_x")).FromJust()); |
8476 CompileRun( | 9474 CompileRun( |
8477 "function bound_x() { return x; }" | 9475 "function bound_x() { return x; }" |
8478 "function get_x() { return this.x; }" | 9476 "function get_x() { return this.x; }" |
8479 "function get_x_w() { return (function() {return this.x;})(); }"); | 9477 "function get_x_w() { return (function() {return this.x;})(); }"); |
8480 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x")); | 9478 // SHOULD BE env2 ??? |
jochen (gone - plz use gerrit)
2015/11/24 12:42:25
env1 is ok here
vogelheim
2015/11/26 10:57:32
Done.
| |
8481 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); | 9479 CHECK(env1->Global() |
8482 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); | 9480 ->Set(env1.local(), v8_str("bound_x"), CompileRun("bound_x")) |
8483 env1->Global()->Set( | 9481 .FromJust()); |
8484 v8_str("this_x"), | 9482 CHECK(env1->Global() |
8485 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")); | 9483 ->Set(env1.local(), v8_str("get_x"), CompileRun("get_x")) |
9484 .FromJust()); | |
9485 CHECK(env1->Global() | |
9486 ->Set(env1.local(), v8_str("get_x_w"), CompileRun("get_x_w")) | |
9487 .FromJust()); | |
9488 env1->Global() | |
9489 ->Set(env1.local(), v8_str("this_x"), | |
9490 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")) | |
9491 .FromJust(); | |
8486 } | 9492 } |
8487 | 9493 |
8488 Local<Object> env2_global = env2->Global(); | 9494 Local<Object> env2_global = env2->Global(); |
8489 env2->DetachGlobal(); | 9495 env2->DetachGlobal(); |
8490 | 9496 |
8491 Local<Value> result; | 9497 Local<Value> result; |
8492 result = CompileRun("bound_x()"); | 9498 result = CompileRun("bound_x()"); |
8493 CHECK(v8_str("env2_x")->Equals(result)); | 9499 CHECK(v8_str("env2_x")->Equals(env1.local(), result).FromJust()); |
8494 result = CompileRun("get_x()"); | 9500 result = CompileRun("get_x()"); |
8495 CHECK(result.IsEmpty()); | 9501 CHECK(result.IsEmpty()); |
8496 result = CompileRun("get_x_w()"); | 9502 result = CompileRun("get_x_w()"); |
8497 CHECK(result.IsEmpty()); | 9503 CHECK(result.IsEmpty()); |
8498 result = CompileRun("this_x()"); | 9504 result = CompileRun("this_x()"); |
8499 CHECK(v8_str("env2_x")->Equals(result)); | 9505 CHECK(v8_str("env2_x")->Equals(env1.local(), result).FromJust()); |
8500 | 9506 |
8501 // Reattach env2's proxy | 9507 // Reattach env2's proxy |
8502 env2 = Context::New(env1->GetIsolate(), | 9508 env2 = Context::New(env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(), |
8503 0, | |
8504 v8::Handle<v8::ObjectTemplate>(), | |
8505 env2_global); | 9509 env2_global); |
8506 env2->SetSecurityToken(foo); | 9510 env2->SetSecurityToken(foo); |
8507 { | 9511 { |
8508 v8::Context::Scope scope(env2); | 9512 v8::Context::Scope scope(env2); |
8509 env2->Global()->Set(v8_str("x"), v8_str("env3_x")); | 9513 CHECK(env2->Global()->Set(env2, v8_str("x"), v8_str("env3_x")).FromJust()); |
8510 env2->Global()->Set(v8_str("env1"), env1->Global()); | 9514 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust()); |
8511 result = CompileRun( | 9515 result = CompileRun( |
8512 "results = [];" | 9516 "results = [];" |
8513 "for (var i = 0; i < 4; i++ ) {" | 9517 "for (var i = 0; i < 4; i++ ) {" |
8514 " results.push(env1.bound_x());" | 9518 " results.push(env1.bound_x());" |
8515 " results.push(env1.get_x());" | 9519 " results.push(env1.get_x());" |
8516 " results.push(env1.get_x_w());" | 9520 " results.push(env1.get_x_w());" |
8517 " results.push(env1.this_x());" | 9521 " results.push(env1.this_x());" |
8518 "}" | 9522 "}" |
8519 "results"); | 9523 "results"); |
8520 Local<v8::Array> results = Local<v8::Array>::Cast(result); | 9524 Local<v8::Array> results = Local<v8::Array>::Cast(result); |
8521 CHECK_EQ(16u, results->Length()); | 9525 CHECK_EQ(16u, results->Length()); |
8522 for (int i = 0; i < 16; i += 4) { | 9526 for (int i = 0; i < 16; i += 4) { |
8523 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); | 9527 CHECK(v8_str("env2_x") |
8524 CHECK(v8_str("env1_x")->Equals(results->Get(i + 1))); | 9528 ->Equals(env2, results->Get(env2, i + 0).ToLocalChecked()) |
8525 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); | 9529 .FromJust()); |
8526 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); | 9530 CHECK(v8_str("env1_x") |
9531 ->Equals(env2, results->Get(env2, i + 1).ToLocalChecked()) | |
9532 .FromJust()); | |
9533 CHECK(v8_str("env3_x") | |
9534 ->Equals(env2, results->Get(env2, i + 2).ToLocalChecked()) | |
9535 .FromJust()); | |
9536 CHECK(v8_str("env2_x") | |
9537 ->Equals(env2, results->Get(env2, i + 3).ToLocalChecked()) | |
9538 .FromJust()); | |
8527 } | 9539 } |
8528 } | 9540 } |
8529 | 9541 |
8530 result = CompileRun( | 9542 result = CompileRun( |
8531 "results = [];" | 9543 "results = [];" |
8532 "for (var i = 0; i < 4; i++ ) {" | 9544 "for (var i = 0; i < 4; i++ ) {" |
8533 " results.push(bound_x());" | 9545 " results.push(bound_x());" |
8534 " results.push(get_x());" | 9546 " results.push(get_x());" |
8535 " results.push(get_x_w());" | 9547 " results.push(get_x_w());" |
8536 " results.push(this_x());" | 9548 " results.push(this_x());" |
8537 "}" | 9549 "}" |
8538 "results"); | 9550 "results"); |
8539 Local<v8::Array> results = Local<v8::Array>::Cast(result); | 9551 Local<v8::Array> results = Local<v8::Array>::Cast(result); |
8540 CHECK_EQ(16u, results->Length()); | 9552 CHECK_EQ(16u, results->Length()); |
8541 for (int i = 0; i < 16; i += 4) { | 9553 for (int i = 0; i < 16; i += 4) { |
8542 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); | 9554 CHECK(v8_str("env2_x") |
8543 CHECK(v8_str("env3_x")->Equals(results->Get(i + 1))); | 9555 ->Equals(env1.local(), |
8544 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); | 9556 results->Get(env1.local(), i + 0).ToLocalChecked()) |
8545 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); | 9557 .FromJust()); |
9558 CHECK(v8_str("env3_x") | |
9559 ->Equals(env1.local(), | |
9560 results->Get(env1.local(), i + 1).ToLocalChecked()) | |
9561 .FromJust()); | |
9562 CHECK(v8_str("env3_x") | |
9563 ->Equals(env1.local(), | |
9564 results->Get(env1.local(), i + 2).ToLocalChecked()) | |
9565 .FromJust()); | |
9566 CHECK(v8_str("env2_x") | |
9567 ->Equals(env1.local(), | |
9568 results->Get(env1.local(), i + 3).ToLocalChecked()) | |
9569 .FromJust()); | |
8546 } | 9570 } |
8547 | 9571 |
8548 result = CompileRun( | 9572 result = CompileRun( |
8549 "results = [];" | 9573 "results = [];" |
8550 "for (var i = 0; i < 4; i++ ) {" | 9574 "for (var i = 0; i < 4; i++ ) {" |
8551 " results.push(this.bound_x());" | 9575 " results.push(this.bound_x());" |
8552 " results.push(this.get_x());" | 9576 " results.push(this.get_x());" |
8553 " results.push(this.get_x_w());" | 9577 " results.push(this.get_x_w());" |
8554 " results.push(this.this_x());" | 9578 " results.push(this.this_x());" |
8555 "}" | 9579 "}" |
8556 "results"); | 9580 "results"); |
8557 results = Local<v8::Array>::Cast(result); | 9581 results = Local<v8::Array>::Cast(result); |
8558 CHECK_EQ(16u, results->Length()); | 9582 CHECK_EQ(16u, results->Length()); |
8559 for (int i = 0; i < 16; i += 4) { | 9583 for (int i = 0; i < 16; i += 4) { |
8560 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); | 9584 CHECK(v8_str("env2_x") |
8561 CHECK(v8_str("env1_x")->Equals(results->Get(i + 1))); | 9585 ->Equals(env1.local(), |
8562 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); | 9586 results->Get(env1.local(), i + 0).ToLocalChecked()) |
8563 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); | 9587 .FromJust()); |
9588 CHECK(v8_str("env1_x") | |
9589 ->Equals(env1.local(), | |
9590 results->Get(env1.local(), i + 1).ToLocalChecked()) | |
9591 .FromJust()); | |
9592 CHECK(v8_str("env3_x") | |
9593 ->Equals(env1.local(), | |
9594 results->Get(env1.local(), i + 2).ToLocalChecked()) | |
9595 .FromJust()); | |
9596 CHECK(v8_str("env2_x") | |
9597 ->Equals(env1.local(), | |
9598 results->Get(env1.local(), i + 3).ToLocalChecked()) | |
9599 .FromJust()); | |
8564 } | 9600 } |
8565 } | 9601 } |
8566 | 9602 |
8567 | 9603 |
8568 static bool allowed_access = false; | 9604 static bool allowed_access = false; |
8569 static bool AccessBlocker(Local<v8::Context> accessing_context, | 9605 static bool AccessBlocker(Local<v8::Context> accessing_context, |
8570 Local<v8::Object> accessed_object) { | 9606 Local<v8::Object> accessed_object) { |
8571 return CcTest::isolate()->GetCurrentContext()->Global()->Equals( | 9607 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
8572 accessed_object) || | 9608 return context->Global()->Equals(context, accessed_object).FromJust() || |
8573 allowed_access; | 9609 allowed_access; |
8574 } | 9610 } |
8575 | 9611 |
8576 | 9612 |
8577 static int g_echo_value = -1; | 9613 static int g_echo_value = -1; |
8578 | 9614 |
8579 | 9615 |
8580 static void EchoGetter( | 9616 static void EchoGetter( |
8581 Local<String> name, | 9617 Local<String> name, |
8582 const v8::PropertyCallbackInfo<v8::Value>& info) { | 9618 const v8::PropertyCallbackInfo<v8::Value>& info) { |
8583 info.GetReturnValue().Set(v8_num(g_echo_value)); | 9619 info.GetReturnValue().Set(v8_num(g_echo_value)); |
8584 } | 9620 } |
8585 | 9621 |
8586 | 9622 |
8587 static void EchoSetter(Local<String> name, | 9623 static void EchoSetter(Local<String> name, Local<Value> value, |
8588 Local<Value> value, | 9624 const v8::PropertyCallbackInfo<void>& args) { |
8589 const v8::PropertyCallbackInfo<void>&) { | |
8590 if (value->IsNumber()) | 9625 if (value->IsNumber()) |
8591 g_echo_value = value->Int32Value(); | 9626 g_echo_value = |
9627 value->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust(); | |
8592 } | 9628 } |
8593 | 9629 |
8594 | 9630 |
8595 static void UnreachableGetter( | 9631 static void UnreachableGetter( |
8596 Local<String> name, | 9632 Local<String> name, |
8597 const v8::PropertyCallbackInfo<v8::Value>& info) { | 9633 const v8::PropertyCallbackInfo<v8::Value>& info) { |
8598 CHECK(false); // This function should not be called.. | 9634 CHECK(false); // This function should not be called.. |
8599 } | 9635 } |
8600 | 9636 |
8601 | 9637 |
8602 static void UnreachableSetter(Local<String>, | 9638 static void UnreachableSetter(Local<String>, |
8603 Local<Value>, | 9639 Local<Value>, |
8604 const v8::PropertyCallbackInfo<void>&) { | 9640 const v8::PropertyCallbackInfo<void>&) { |
8605 CHECK(false); // This function should nto be called. | 9641 CHECK(false); // This function should nto be called. |
8606 } | 9642 } |
8607 | 9643 |
8608 | 9644 |
8609 static void UnreachableFunction( | 9645 static void UnreachableFunction( |
8610 const v8::FunctionCallbackInfo<v8::Value>& info) { | 9646 const v8::FunctionCallbackInfo<v8::Value>& info) { |
8611 CHECK(false); // This function should not be called.. | 9647 CHECK(false); // This function should not be called.. |
8612 } | 9648 } |
8613 | 9649 |
8614 | 9650 |
8615 TEST(AccessControl) { | 9651 TEST(AccessControl) { |
8616 v8::Isolate* isolate = CcTest::isolate(); | 9652 v8::Isolate* isolate = CcTest::isolate(); |
8617 v8::HandleScope handle_scope(isolate); | 9653 v8::HandleScope handle_scope(isolate); |
8618 v8::Handle<v8::ObjectTemplate> global_template = | 9654 v8::Local<v8::ObjectTemplate> global_template = |
8619 v8::ObjectTemplate::New(isolate); | 9655 v8::ObjectTemplate::New(isolate); |
8620 | 9656 |
8621 global_template->SetAccessCheckCallback(AccessBlocker); | 9657 global_template->SetAccessCheckCallback(AccessBlocker); |
8622 | 9658 |
8623 // Add an accessor accessible by cross-domain JS code. | 9659 // Add an accessor accessible by cross-domain JS code. |
8624 global_template->SetAccessor( | 9660 global_template->SetAccessor( |
8625 v8_str("accessible_prop"), | 9661 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Local<Value>(), |
8626 EchoGetter, EchoSetter, | |
8627 v8::Handle<Value>(), | |
8628 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 9662 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
8629 | 9663 |
8630 | 9664 |
8631 // Add an accessor that is not accessible by cross-domain JS code. | 9665 // Add an accessor that is not accessible by cross-domain JS code. |
8632 global_template->SetAccessor(v8_str("blocked_prop"), | 9666 global_template->SetAccessor(v8_str("blocked_prop"), UnreachableGetter, |
8633 UnreachableGetter, UnreachableSetter, | 9667 UnreachableSetter, v8::Local<Value>(), |
8634 v8::Handle<Value>(), | |
8635 v8::DEFAULT); | 9668 v8::DEFAULT); |
8636 | 9669 |
8637 global_template->SetAccessorProperty( | 9670 global_template->SetAccessorProperty( |
8638 v8_str("blocked_js_prop"), | 9671 v8_str("blocked_js_prop"), |
8639 v8::FunctionTemplate::New(isolate, UnreachableFunction), | 9672 v8::FunctionTemplate::New(isolate, UnreachableFunction), |
8640 v8::FunctionTemplate::New(isolate, UnreachableFunction), | 9673 v8::FunctionTemplate::New(isolate, UnreachableFunction), |
8641 v8::None, | 9674 v8::None, |
8642 v8::DEFAULT); | 9675 v8::DEFAULT); |
8643 | 9676 |
8644 // Create an environment | 9677 // Create an environment |
8645 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); | 9678 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
8646 context0->Enter(); | 9679 context0->Enter(); |
8647 | 9680 |
8648 v8::Handle<v8::Object> global0 = context0->Global(); | 9681 v8::Local<v8::Object> global0 = context0->Global(); |
8649 | 9682 |
8650 // Define a property with JS getter and setter. | 9683 // Define a property with JS getter and setter. |
8651 CompileRun( | 9684 CompileRun( |
8652 "function getter() { return 'getter'; };\n" | 9685 "function getter() { return 'getter'; };\n" |
8653 "function setter() { return 'setter'; }\n" | 9686 "function setter() { return 'setter'; }\n" |
8654 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); | 9687 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); |
8655 | 9688 |
8656 Local<Value> getter = global0->Get(v8_str("getter")); | 9689 Local<Value> getter = |
8657 Local<Value> setter = global0->Get(v8_str("setter")); | 9690 global0->Get(context0, v8_str("getter")).ToLocalChecked(); |
9691 Local<Value> setter = | |
9692 global0->Get(context0, v8_str("setter")).ToLocalChecked(); | |
8658 | 9693 |
8659 // And define normal element. | 9694 // And define normal element. |
8660 global0->Set(239, v8_str("239")); | 9695 CHECK(global0->Set(context0, 239, v8_str("239")).FromJust()); |
8661 | 9696 |
8662 // Define an element with JS getter and setter. | 9697 // Define an element with JS getter and setter. |
8663 CompileRun( | 9698 CompileRun( |
8664 "function el_getter() { return 'el_getter'; };\n" | 9699 "function el_getter() { return 'el_getter'; };\n" |
8665 "function el_setter() { return 'el_setter'; };\n" | 9700 "function el_setter() { return 'el_setter'; };\n" |
8666 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); | 9701 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); |
8667 | 9702 |
8668 Local<Value> el_getter = global0->Get(v8_str("el_getter")); | 9703 Local<Value> el_getter = |
8669 Local<Value> el_setter = global0->Get(v8_str("el_setter")); | 9704 global0->Get(context0, v8_str("el_getter")).ToLocalChecked(); |
9705 Local<Value> el_setter = | |
9706 global0->Get(context0, v8_str("el_setter")).ToLocalChecked(); | |
8670 | 9707 |
8671 v8::HandleScope scope1(isolate); | 9708 v8::HandleScope scope1(isolate); |
8672 | 9709 |
8673 v8::Local<Context> context1 = Context::New(isolate); | 9710 v8::Local<Context> context1 = Context::New(isolate); |
8674 context1->Enter(); | 9711 context1->Enter(); |
8675 | 9712 |
8676 v8::Handle<v8::Object> global1 = context1->Global(); | 9713 v8::Local<v8::Object> global1 = context1->Global(); |
8677 global1->Set(v8_str("other"), global0); | 9714 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust()); |
8678 | 9715 |
8679 // Access blocked property. | 9716 // Access blocked property. |
8680 CompileRun("other.blocked_prop = 1"); | 9717 CompileRun("other.blocked_prop = 1"); |
8681 | 9718 |
8682 CHECK(CompileRun("other.blocked_prop").IsEmpty()); | 9719 CHECK(CompileRun("other.blocked_prop").IsEmpty()); |
8683 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") | 9720 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") |
8684 .IsEmpty()); | 9721 .IsEmpty()); |
8685 CHECK( | 9722 CHECK( |
8686 CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')").IsEmpty()); | 9723 CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')").IsEmpty()); |
8687 | 9724 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8724 | 9761 |
8725 allowed_access = true; | 9762 allowed_access = true; |
8726 | 9763 |
8727 ExpectString("other[42]", "el_getter"); | 9764 ExpectString("other[42]", "el_getter"); |
8728 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter); | 9765 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter); |
8729 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter); | 9766 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter); |
8730 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value"); | 9767 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value"); |
8731 | 9768 |
8732 allowed_access = false; | 9769 allowed_access = false; |
8733 | 9770 |
8734 v8::Handle<Value> value; | 9771 v8::Local<Value> value; |
8735 | 9772 |
8736 // Access accessible property | 9773 // Access accessible property |
8737 value = CompileRun("other.accessible_prop = 3"); | 9774 value = CompileRun("other.accessible_prop = 3"); |
8738 CHECK(value->IsNumber()); | 9775 CHECK(value->IsNumber()); |
8739 CHECK_EQ(3, value->Int32Value()); | 9776 CHECK_EQ(3, value->Int32Value(context1).FromJust()); |
8740 CHECK_EQ(3, g_echo_value); | 9777 CHECK_EQ(3, g_echo_value); |
8741 | 9778 |
8742 value = CompileRun("other.accessible_prop"); | 9779 value = CompileRun("other.accessible_prop"); |
8743 CHECK(value->IsNumber()); | 9780 CHECK(value->IsNumber()); |
8744 CHECK_EQ(3, value->Int32Value()); | 9781 CHECK_EQ(3, value->Int32Value(context1).FromJust()); |
8745 | 9782 |
8746 value = CompileRun( | 9783 value = CompileRun( |
8747 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); | 9784 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); |
8748 CHECK(value->IsNumber()); | 9785 CHECK(value->IsNumber()); |
8749 CHECK_EQ(3, value->Int32Value()); | 9786 CHECK_EQ(3, value->Int32Value(context1).FromJust()); |
8750 | 9787 |
8751 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); | 9788 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); |
8752 CHECK(value->IsTrue()); | 9789 CHECK(value->IsTrue()); |
8753 | 9790 |
8754 // Enumeration doesn't enumerate accessors from inaccessible objects in | 9791 // Enumeration doesn't enumerate accessors from inaccessible objects in |
8755 // the prototype chain even if the accessors are in themselves accessible. | 9792 // the prototype chain even if the accessors are in themselves accessible. |
8756 value = CompileRun( | 9793 value = CompileRun( |
8757 "(function() {" | 9794 "(function() {" |
8758 " var obj = { '__proto__': other };" | 9795 " var obj = { '__proto__': other };" |
8759 " try {" | 9796 " try {" |
8760 " for (var p in obj) {" | 9797 " for (var p in obj) {" |
8761 " if (p == 'accessible_prop' ||" | 9798 " if (p == 'accessible_prop' ||" |
8762 " p == 'blocked_js_prop' ||" | 9799 " p == 'blocked_js_prop' ||" |
8763 " p == 'blocked_js_prop') {" | 9800 " p == 'blocked_js_prop') {" |
8764 " return false;" | 9801 " return false;" |
8765 " }" | 9802 " }" |
8766 " }" | 9803 " }" |
8767 " return false;" | 9804 " return false;" |
8768 " } catch (e) {" | 9805 " } catch (e) {" |
8769 " return true;" | 9806 " return true;" |
8770 " }" | 9807 " }" |
8771 "})()"); | 9808 "})()"); |
8772 CHECK(value->IsTrue()); | 9809 CHECK(value->IsTrue()); |
8773 | 9810 |
8774 // Test that preventExtensions fails on a non-accessible object even if that | 9811 // Test that preventExtensions fails on a non-accessible object even if that |
8775 // object is already non-extensible. | 9812 // object is already non-extensible. |
8776 global1->Set(v8_str("checked_object"), global_template->NewInstance()); | 9813 CHECK(global1->Set(context1, v8_str("checked_object"), |
9814 global_template->NewInstance(context1).ToLocalChecked()) | |
9815 .FromJust()); | |
8777 allowed_access = true; | 9816 allowed_access = true; |
8778 CompileRun("Object.preventExtensions(checked_object)"); | 9817 CompileRun("Object.preventExtensions(checked_object)"); |
8779 ExpectFalse("Object.isExtensible(checked_object)"); | 9818 ExpectFalse("Object.isExtensible(checked_object)"); |
8780 allowed_access = false; | 9819 allowed_access = false; |
8781 CHECK(CompileRun("Object.preventExtensions(checked_object)").IsEmpty()); | 9820 CHECK(CompileRun("Object.preventExtensions(checked_object)").IsEmpty()); |
8782 | 9821 |
8783 context1->Exit(); | 9822 context1->Exit(); |
8784 context0->Exit(); | 9823 context0->Exit(); |
8785 } | 9824 } |
8786 | 9825 |
8787 | 9826 |
8788 TEST(AccessControlES5) { | 9827 TEST(AccessControlES5) { |
8789 v8::Isolate* isolate = CcTest::isolate(); | 9828 v8::Isolate* isolate = CcTest::isolate(); |
8790 v8::HandleScope handle_scope(isolate); | 9829 v8::HandleScope handle_scope(isolate); |
8791 v8::Handle<v8::ObjectTemplate> global_template = | 9830 v8::Local<v8::ObjectTemplate> global_template = |
8792 v8::ObjectTemplate::New(isolate); | 9831 v8::ObjectTemplate::New(isolate); |
8793 | 9832 |
8794 global_template->SetAccessCheckCallback(AccessBlocker); | 9833 global_template->SetAccessCheckCallback(AccessBlocker); |
8795 | 9834 |
8796 // Add accessible accessor. | 9835 // Add accessible accessor. |
8797 global_template->SetAccessor( | 9836 global_template->SetAccessor( |
8798 v8_str("accessible_prop"), | 9837 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Local<Value>(), |
8799 EchoGetter, EchoSetter, | |
8800 v8::Handle<Value>(), | |
8801 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 9838 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
8802 | 9839 |
8803 | 9840 |
8804 // Add an accessor that is not accessible by cross-domain JS code. | 9841 // Add an accessor that is not accessible by cross-domain JS code. |
8805 global_template->SetAccessor(v8_str("blocked_prop"), | 9842 global_template->SetAccessor(v8_str("blocked_prop"), UnreachableGetter, |
8806 UnreachableGetter, UnreachableSetter, | 9843 UnreachableSetter, v8::Local<Value>(), |
8807 v8::Handle<Value>(), | |
8808 v8::DEFAULT); | 9844 v8::DEFAULT); |
8809 | 9845 |
8810 // Create an environment | 9846 // Create an environment |
8811 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); | 9847 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
8812 context0->Enter(); | 9848 context0->Enter(); |
8813 | 9849 |
8814 v8::Handle<v8::Object> global0 = context0->Global(); | 9850 v8::Local<v8::Object> global0 = context0->Global(); |
8815 | 9851 |
8816 v8::Local<Context> context1 = Context::New(isolate); | 9852 v8::Local<Context> context1 = Context::New(isolate); |
8817 context1->Enter(); | 9853 context1->Enter(); |
8818 v8::Handle<v8::Object> global1 = context1->Global(); | 9854 v8::Local<v8::Object> global1 = context1->Global(); |
8819 global1->Set(v8_str("other"), global0); | 9855 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust()); |
8820 | 9856 |
8821 // Regression test for issue 1154. | 9857 // Regression test for issue 1154. |
8822 CHECK(CompileRun("Object.keys(other).length == 0")->BooleanValue()); | 9858 CHECK(CompileRun("Object.keys(other).length == 0") |
9859 ->BooleanValue(context1) | |
9860 .FromJust()); | |
8823 CHECK(CompileRun("other.blocked_prop").IsEmpty()); | 9861 CHECK(CompileRun("other.blocked_prop").IsEmpty()); |
8824 | 9862 |
8825 // Regression test for issue 1027. | 9863 // Regression test for issue 1027. |
8826 CompileRun("Object.defineProperty(\n" | 9864 CompileRun("Object.defineProperty(\n" |
8827 " other, 'blocked_prop', {configurable: false})"); | 9865 " other, 'blocked_prop', {configurable: false})"); |
8828 CHECK(CompileRun("other.blocked_prop").IsEmpty()); | 9866 CHECK(CompileRun("other.blocked_prop").IsEmpty()); |
8829 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") | 9867 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") |
8830 .IsEmpty()); | 9868 .IsEmpty()); |
8831 | 9869 |
8832 // Regression test for issue 1171. | 9870 // Regression test for issue 1171. |
(...skipping 26 matching lines...) Expand all Loading... | |
8859 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, | 9897 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, |
8860 Local<v8::Object> global) { | 9898 Local<v8::Object> global) { |
8861 i::PrintF("Access blocked.\n"); | 9899 i::PrintF("Access blocked.\n"); |
8862 return false; | 9900 return false; |
8863 } | 9901 } |
8864 | 9902 |
8865 | 9903 |
8866 THREADED_TEST(AccessControlGetOwnPropertyNames) { | 9904 THREADED_TEST(AccessControlGetOwnPropertyNames) { |
8867 v8::Isolate* isolate = CcTest::isolate(); | 9905 v8::Isolate* isolate = CcTest::isolate(); |
8868 v8::HandleScope handle_scope(isolate); | 9906 v8::HandleScope handle_scope(isolate); |
8869 v8::Handle<v8::ObjectTemplate> obj_template = | 9907 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
8870 v8::ObjectTemplate::New(isolate); | |
8871 | 9908 |
8872 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 9909 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
8873 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 9910 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
8874 | 9911 |
8875 // Add an accessor accessible by cross-domain JS code. | 9912 // Add an accessor accessible by cross-domain JS code. |
8876 obj_template->SetAccessor( | 9913 obj_template->SetAccessor( |
8877 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Handle<Value>(), | 9914 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Local<Value>(), |
8878 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); | 9915 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); |
8879 | 9916 |
8880 // Create an environment | 9917 // Create an environment |
8881 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 9918 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
8882 context0->Enter(); | 9919 context0->Enter(); |
8883 | 9920 |
8884 v8::Handle<v8::Object> global0 = context0->Global(); | 9921 v8::Local<v8::Object> global0 = context0->Global(); |
8885 | 9922 |
8886 v8::HandleScope scope1(CcTest::isolate()); | 9923 v8::HandleScope scope1(CcTest::isolate()); |
8887 | 9924 |
8888 v8::Local<Context> context1 = Context::New(isolate); | 9925 v8::Local<Context> context1 = Context::New(isolate); |
8889 context1->Enter(); | 9926 context1->Enter(); |
8890 | 9927 |
8891 v8::Handle<v8::Object> global1 = context1->Global(); | 9928 v8::Local<v8::Object> global1 = context1->Global(); |
8892 global1->Set(v8_str("other"), global0); | 9929 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust()); |
8893 global1->Set(v8_str("object"), obj_template->NewInstance()); | 9930 CHECK(global1->Set(context1, v8_str("object"), |
9931 obj_template->NewInstance(context1).ToLocalChecked()) | |
9932 .FromJust()); | |
8894 | 9933 |
8895 v8::Handle<Value> value; | 9934 v8::Local<Value> value; |
8896 | 9935 |
8897 // Attempt to get the property names of the other global object and | 9936 // Attempt to get the property names of the other global object and |
8898 // of an object that requires access checks. Accessing the other | 9937 // of an object that requires access checks. Accessing the other |
8899 // global object should be blocked by access checks on the global | 9938 // global object should be blocked by access checks on the global |
8900 // proxy object. Accessing the object that requires access checks | 9939 // proxy object. Accessing the object that requires access checks |
8901 // is blocked by the access checks on the object itself. | 9940 // is blocked by the access checks on the object itself. |
8902 value = CompileRun( | 9941 value = CompileRun( |
8903 "var names = Object.getOwnPropertyNames(other);" | 9942 "var names = Object.getOwnPropertyNames(other);" |
8904 "names.length == 1 && names[0] == 'accessible_prop';"); | 9943 "names.length == 1 && names[0] == 'accessible_prop';"); |
8905 CHECK(value->BooleanValue()); | 9944 CHECK(value->BooleanValue(context1).FromJust()); |
8906 | 9945 |
8907 value = CompileRun( | 9946 value = CompileRun( |
8908 "var names = Object.getOwnPropertyNames(object);" | 9947 "var names = Object.getOwnPropertyNames(object);" |
8909 "names.length == 1 && names[0] == 'accessible_prop';"); | 9948 "names.length == 1 && names[0] == 'accessible_prop';"); |
8910 CHECK(value->BooleanValue()); | 9949 CHECK(value->BooleanValue(context1).FromJust()); |
8911 | 9950 |
8912 context1->Exit(); | 9951 context1->Exit(); |
8913 context0->Exit(); | 9952 context0->Exit(); |
8914 } | 9953 } |
8915 | 9954 |
8916 | 9955 |
8917 TEST(Regress470113) { | 9956 TEST(Regress470113) { |
8918 v8::Isolate* isolate = CcTest::isolate(); | 9957 v8::Isolate* isolate = CcTest::isolate(); |
8919 v8::HandleScope handle_scope(isolate); | 9958 v8::HandleScope handle_scope(isolate); |
8920 v8::Handle<v8::ObjectTemplate> obj_template = | 9959 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
8921 v8::ObjectTemplate::New(isolate); | |
8922 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 9960 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
8923 LocalContext env; | 9961 LocalContext env; |
8924 env->Global()->Set(v8_str("prohibited"), obj_template->NewInstance()); | 9962 CHECK(env->Global() |
9963 ->Set(env.local(), v8_str("prohibited"), | |
9964 obj_template->NewInstance(env.local()).ToLocalChecked()) | |
9965 .FromJust()); | |
8925 | 9966 |
8926 { | 9967 { |
8927 v8::TryCatch try_catch(isolate); | 9968 v8::TryCatch try_catch(isolate); |
8928 CompileRun( | 9969 CompileRun( |
8929 "'use strict';\n" | 9970 "'use strict';\n" |
8930 "class C extends Object {\n" | 9971 "class C extends Object {\n" |
8931 " m() { super.powned = 'Powned!'; }\n" | 9972 " m() { super.powned = 'Powned!'; }\n" |
8932 "}\n" | 9973 "}\n" |
8933 "let c = new C();\n" | 9974 "let c = new C();\n" |
8934 "c.m.call(prohibited)"); | 9975 "c.m.call(prohibited)"); |
8935 | 9976 |
8936 CHECK(try_catch.HasCaught()); | 9977 CHECK(try_catch.HasCaught()); |
8937 } | 9978 } |
8938 } | 9979 } |
8939 | 9980 |
8940 | 9981 |
8941 static void ConstTenGetter(Local<String> name, | 9982 static void ConstTenGetter(Local<String> name, |
8942 const v8::PropertyCallbackInfo<v8::Value>& info) { | 9983 const v8::PropertyCallbackInfo<v8::Value>& info) { |
8943 info.GetReturnValue().Set(v8_num(10)); | 9984 info.GetReturnValue().Set(v8_num(10)); |
8944 } | 9985 } |
8945 | 9986 |
8946 | 9987 |
8947 THREADED_TEST(CrossDomainAccessors) { | 9988 THREADED_TEST(CrossDomainAccessors) { |
8948 v8::Isolate* isolate = CcTest::isolate(); | 9989 v8::Isolate* isolate = CcTest::isolate(); |
8949 v8::HandleScope handle_scope(isolate); | 9990 v8::HandleScope handle_scope(isolate); |
8950 | 9991 |
8951 v8::Handle<v8::FunctionTemplate> func_template = | 9992 v8::Local<v8::FunctionTemplate> func_template = |
8952 v8::FunctionTemplate::New(isolate); | 9993 v8::FunctionTemplate::New(isolate); |
8953 | 9994 |
8954 v8::Handle<v8::ObjectTemplate> global_template = | 9995 v8::Local<v8::ObjectTemplate> global_template = |
8955 func_template->InstanceTemplate(); | 9996 func_template->InstanceTemplate(); |
8956 | 9997 |
8957 v8::Handle<v8::ObjectTemplate> proto_template = | 9998 v8::Local<v8::ObjectTemplate> proto_template = |
8958 func_template->PrototypeTemplate(); | 9999 func_template->PrototypeTemplate(); |
8959 | 10000 |
8960 // Add an accessor to proto that's accessible by cross-domain JS code. | 10001 // Add an accessor to proto that's accessible by cross-domain JS code. |
8961 proto_template->SetAccessor(v8_str("accessible"), | 10002 proto_template->SetAccessor(v8_str("accessible"), ConstTenGetter, 0, |
8962 ConstTenGetter, 0, | 10003 v8::Local<Value>(), v8::ALL_CAN_READ); |
8963 v8::Handle<Value>(), | |
8964 v8::ALL_CAN_READ); | |
8965 | 10004 |
8966 // Add an accessor that is not accessible by cross-domain JS code. | 10005 // Add an accessor that is not accessible by cross-domain JS code. |
8967 global_template->SetAccessor(v8_str("unreachable"), | 10006 global_template->SetAccessor(v8_str("unreachable"), UnreachableGetter, 0, |
8968 UnreachableGetter, 0, | 10007 v8::Local<Value>(), v8::DEFAULT); |
8969 v8::Handle<Value>(), | |
8970 v8::DEFAULT); | |
8971 | 10008 |
8972 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); | 10009 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); |
8973 context0->Enter(); | 10010 context0->Enter(); |
8974 | 10011 |
8975 Local<v8::Object> global = context0->Global(); | 10012 Local<v8::Object> global = context0->Global(); |
8976 // Add a normal property that shadows 'accessible' | 10013 // Add a normal property that shadows 'accessible' |
8977 global->Set(v8_str("accessible"), v8_num(11)); | 10014 CHECK(global->Set(context0, v8_str("accessible"), v8_num(11)).FromJust()); |
8978 | 10015 |
8979 // Enter a new context. | 10016 // Enter a new context. |
8980 v8::HandleScope scope1(CcTest::isolate()); | 10017 v8::HandleScope scope1(CcTest::isolate()); |
8981 v8::Local<Context> context1 = Context::New(isolate); | 10018 v8::Local<Context> context1 = Context::New(isolate); |
8982 context1->Enter(); | 10019 context1->Enter(); |
8983 | 10020 |
8984 v8::Handle<v8::Object> global1 = context1->Global(); | 10021 v8::Local<v8::Object> global1 = context1->Global(); |
8985 global1->Set(v8_str("other"), global); | 10022 CHECK(global1->Set(context1, v8_str("other"), global).FromJust()); |
8986 | 10023 |
8987 // Should return 10, instead of 11 | 10024 // Should return 10, instead of 11 |
8988 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); | 10025 v8::Local<Value> value = |
10026 v8_compile("other.accessible")->Run(context1).ToLocalChecked(); | |
8989 CHECK(value->IsNumber()); | 10027 CHECK(value->IsNumber()); |
8990 CHECK_EQ(10, value->Int32Value()); | 10028 CHECK_EQ(10, value->Int32Value(context1).FromJust()); |
8991 | 10029 |
8992 value = v8_compile("other.unreachable")->Run(); | 10030 v8::MaybeLocal<v8::Value> maybe_value = |
8993 CHECK(value.IsEmpty()); | 10031 v8_compile("other.unreachable")->Run(context1); |
10032 CHECK(maybe_value.IsEmpty()); | |
8994 | 10033 |
8995 context1->Exit(); | 10034 context1->Exit(); |
8996 context0->Exit(); | 10035 context0->Exit(); |
8997 } | 10036 } |
8998 | 10037 |
8999 | 10038 |
9000 static int access_count = 0; | 10039 static int access_count = 0; |
9001 | 10040 |
9002 static bool AccessCounter(Local<v8::Context> accessing_context, | 10041 static bool AccessCounter(Local<v8::Context> accessing_context, |
9003 Local<v8::Object> accessed_object) { | 10042 Local<v8::Object> accessed_object) { |
9004 access_count++; | 10043 access_count++; |
9005 return true; | 10044 return true; |
9006 } | 10045 } |
9007 | 10046 |
9008 | 10047 |
9009 // This one is too easily disturbed by other tests. | 10048 // This one is too easily disturbed by other tests. |
9010 TEST(AccessControlIC) { | 10049 TEST(AccessControlIC) { |
9011 access_count = 0; | 10050 access_count = 0; |
9012 | 10051 |
9013 v8::Isolate* isolate = CcTest::isolate(); | 10052 v8::Isolate* isolate = CcTest::isolate(); |
9014 v8::HandleScope handle_scope(isolate); | 10053 v8::HandleScope handle_scope(isolate); |
9015 | 10054 |
9016 // Create an environment. | 10055 // Create an environment. |
9017 v8::Local<Context> context0 = Context::New(isolate); | 10056 v8::Local<Context> context0 = Context::New(isolate); |
9018 context0->Enter(); | 10057 context0->Enter(); |
9019 | 10058 |
9020 // Create an object that requires access-check functions to be | 10059 // Create an object that requires access-check functions to be |
9021 // called for cross-domain access. | 10060 // called for cross-domain access. |
9022 v8::Handle<v8::ObjectTemplate> object_template = | 10061 v8::Local<v8::ObjectTemplate> object_template = |
9023 v8::ObjectTemplate::New(isolate); | 10062 v8::ObjectTemplate::New(isolate); |
9024 object_template->SetAccessCheckCallback(AccessCounter); | 10063 object_template->SetAccessCheckCallback(AccessCounter); |
9025 Local<v8::Object> object = object_template->NewInstance(); | 10064 Local<v8::Object> object = |
10065 object_template->NewInstance(context0).ToLocalChecked(); | |
9026 | 10066 |
9027 v8::HandleScope scope1(isolate); | 10067 v8::HandleScope scope1(isolate); |
9028 | 10068 |
9029 // Create another environment. | 10069 // Create another environment. |
9030 v8::Local<Context> context1 = Context::New(isolate); | 10070 v8::Local<Context> context1 = Context::New(isolate); |
9031 context1->Enter(); | 10071 context1->Enter(); |
9032 | 10072 |
9033 // Make easy access to the object from the other environment. | 10073 // Make easy access to the object from the other environment. |
9034 v8::Handle<v8::Object> global1 = context1->Global(); | 10074 v8::Local<v8::Object> global1 = context1->Global(); |
9035 global1->Set(v8_str("obj"), object); | 10075 CHECK(global1->Set(context1, v8_str("obj"), object).FromJust()); |
9036 | 10076 |
9037 v8::Handle<Value> value; | 10077 v8::Local<Value> value; |
9038 | 10078 |
9039 // Check that the named access-control function is called every time. | 10079 // Check that the named access-control function is called every time. |
9040 CompileRun("function testProp(obj) {" | 10080 CompileRun("function testProp(obj) {" |
9041 " for (var i = 0; i < 10; i++) obj.prop = 1;" | 10081 " for (var i = 0; i < 10; i++) obj.prop = 1;" |
9042 " for (var j = 0; j < 10; j++) obj.prop;" | 10082 " for (var j = 0; j < 10; j++) obj.prop;" |
9043 " return obj.prop" | 10083 " return obj.prop" |
9044 "}"); | 10084 "}"); |
9045 value = CompileRun("testProp(obj)"); | 10085 value = CompileRun("testProp(obj)"); |
9046 CHECK(value->IsNumber()); | 10086 CHECK(value->IsNumber()); |
9047 CHECK_EQ(1, value->Int32Value()); | 10087 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9048 CHECK_EQ(21, access_count); | 10088 CHECK_EQ(21, access_count); |
9049 | 10089 |
9050 // Check that the named access-control function is called every time. | 10090 // Check that the named access-control function is called every time. |
9051 CompileRun("var p = 'prop';" | 10091 CompileRun("var p = 'prop';" |
9052 "function testKeyed(obj) {" | 10092 "function testKeyed(obj) {" |
9053 " for (var i = 0; i < 10; i++) obj[p] = 1;" | 10093 " for (var i = 0; i < 10; i++) obj[p] = 1;" |
9054 " for (var j = 0; j < 10; j++) obj[p];" | 10094 " for (var j = 0; j < 10; j++) obj[p];" |
9055 " return obj[p];" | 10095 " return obj[p];" |
9056 "}"); | 10096 "}"); |
9057 // Use obj which requires access checks. No inline caching is used | 10097 // Use obj which requires access checks. No inline caching is used |
9058 // in that case. | 10098 // in that case. |
9059 value = CompileRun("testKeyed(obj)"); | 10099 value = CompileRun("testKeyed(obj)"); |
9060 CHECK(value->IsNumber()); | 10100 CHECK(value->IsNumber()); |
9061 CHECK_EQ(1, value->Int32Value()); | 10101 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9062 CHECK_EQ(42, access_count); | 10102 CHECK_EQ(42, access_count); |
9063 // Force the inline caches into generic state and try again. | 10103 // Force the inline caches into generic state and try again. |
9064 CompileRun("testKeyed({ a: 0 })"); | 10104 CompileRun("testKeyed({ a: 0 })"); |
9065 CompileRun("testKeyed({ b: 0 })"); | 10105 CompileRun("testKeyed({ b: 0 })"); |
9066 value = CompileRun("testKeyed(obj)"); | 10106 value = CompileRun("testKeyed(obj)"); |
9067 CHECK(value->IsNumber()); | 10107 CHECK(value->IsNumber()); |
9068 CHECK_EQ(1, value->Int32Value()); | 10108 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9069 CHECK_EQ(63, access_count); | 10109 CHECK_EQ(63, access_count); |
9070 | 10110 |
9071 // Check that the indexed access-control function is called every time. | 10111 // Check that the indexed access-control function is called every time. |
9072 access_count = 0; | 10112 access_count = 0; |
9073 | 10113 |
9074 CompileRun("function testIndexed(obj) {" | 10114 CompileRun("function testIndexed(obj) {" |
9075 " for (var i = 0; i < 10; i++) obj[0] = 1;" | 10115 " for (var i = 0; i < 10; i++) obj[0] = 1;" |
9076 " for (var j = 0; j < 10; j++) obj[0];" | 10116 " for (var j = 0; j < 10; j++) obj[0];" |
9077 " return obj[0]" | 10117 " return obj[0]" |
9078 "}"); | 10118 "}"); |
9079 value = CompileRun("testIndexed(obj)"); | 10119 value = CompileRun("testIndexed(obj)"); |
9080 CHECK(value->IsNumber()); | 10120 CHECK(value->IsNumber()); |
9081 CHECK_EQ(1, value->Int32Value()); | 10121 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9082 CHECK_EQ(21, access_count); | 10122 CHECK_EQ(21, access_count); |
9083 // Force the inline caches into generic state. | 10123 // Force the inline caches into generic state. |
9084 CompileRun("testIndexed(new Array(1))"); | 10124 CompileRun("testIndexed(new Array(1))"); |
9085 // Test that the indexed access check is called. | 10125 // Test that the indexed access check is called. |
9086 value = CompileRun("testIndexed(obj)"); | 10126 value = CompileRun("testIndexed(obj)"); |
9087 CHECK(value->IsNumber()); | 10127 CHECK(value->IsNumber()); |
9088 CHECK_EQ(1, value->Int32Value()); | 10128 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9089 CHECK_EQ(42, access_count); | 10129 CHECK_EQ(42, access_count); |
9090 | 10130 |
9091 access_count = 0; | 10131 access_count = 0; |
9092 // Check that the named access check is called when invoking | 10132 // Check that the named access check is called when invoking |
9093 // functions on an object that requires access checks. | 10133 // functions on an object that requires access checks. |
9094 CompileRun("obj.f = function() {}"); | 10134 CompileRun("obj.f = function() {}"); |
9095 CompileRun("function testCallNormal(obj) {" | 10135 CompileRun("function testCallNormal(obj) {" |
9096 " for (var i = 0; i < 10; i++) obj.f();" | 10136 " for (var i = 0; i < 10; i++) obj.f();" |
9097 "}"); | 10137 "}"); |
9098 CompileRun("testCallNormal(obj)"); | 10138 CompileRun("testCallNormal(obj)"); |
9099 printf("%i\n", access_count); | 10139 printf("%i\n", access_count); |
9100 CHECK_EQ(11, access_count); | 10140 CHECK_EQ(11, access_count); |
9101 | 10141 |
9102 // Force obj into slow case. | 10142 // Force obj into slow case. |
9103 value = CompileRun("delete obj.prop"); | 10143 value = CompileRun("delete obj.prop"); |
9104 CHECK(value->BooleanValue()); | 10144 CHECK(value->BooleanValue(context1).FromJust()); |
9105 // Force inline caches into dictionary probing mode. | 10145 // Force inline caches into dictionary probing mode. |
9106 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);"); | 10146 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);"); |
9107 // Test that the named access check is called. | 10147 // Test that the named access check is called. |
9108 value = CompileRun("testProp(obj);"); | 10148 value = CompileRun("testProp(obj);"); |
9109 CHECK(value->IsNumber()); | 10149 CHECK(value->IsNumber()); |
9110 CHECK_EQ(1, value->Int32Value()); | 10150 CHECK_EQ(1, value->Int32Value(context1).FromJust()); |
9111 CHECK_EQ(33, access_count); | 10151 CHECK_EQ(33, access_count); |
9112 | 10152 |
9113 // Force the call inline cache into dictionary probing mode. | 10153 // Force the call inline cache into dictionary probing mode. |
9114 CompileRun("o.f = function() {}; testCallNormal(o)"); | 10154 CompileRun("o.f = function() {}; testCallNormal(o)"); |
9115 // Test that the named access check is still called for each | 10155 // Test that the named access check is still called for each |
9116 // invocation of the function. | 10156 // invocation of the function. |
9117 value = CompileRun("testCallNormal(obj)"); | 10157 value = CompileRun("testCallNormal(obj)"); |
9118 CHECK_EQ(43, access_count); | 10158 CHECK_EQ(43, access_count); |
9119 | 10159 |
9120 context1->Exit(); | 10160 context1->Exit(); |
(...skipping 16 matching lines...) Expand all Loading... | |
9137 v8::Isolate* isolate = context->GetIsolate(); | 10177 v8::Isolate* isolate = context->GetIsolate(); |
9138 v8::HandleScope handle_scope(isolate); | 10178 v8::HandleScope handle_scope(isolate); |
9139 | 10179 |
9140 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10180 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
9141 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 10181 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
9142 | 10182 |
9143 instance->Set(v8_str("x"), v8_num(42)); | 10183 instance->Set(v8_str("x"), v8_num(42)); |
9144 instance->Set(v8_str("f"), | 10184 instance->Set(v8_str("f"), |
9145 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); | 10185 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); |
9146 | 10186 |
9147 Local<Value> o = t->GetFunction()->NewInstance(); | 10187 Local<Value> o = t->GetFunction(context.local()) |
10188 .ToLocalChecked() | |
10189 ->NewInstance(context.local()) | |
10190 .ToLocalChecked(); | |
9148 | 10191 |
9149 context->Global()->Set(v8_str("i"), o); | 10192 CHECK(context->Global()->Set(context.local(), v8_str("i"), o).FromJust()); |
9150 Local<Value> value = CompileRun("i.x"); | 10193 Local<Value> value = CompileRun("i.x"); |
9151 CHECK_EQ(42, value->Int32Value()); | 10194 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
9152 | 10195 |
9153 value = CompileRun("i.f()"); | 10196 value = CompileRun("i.f()"); |
9154 CHECK_EQ(12, value->Int32Value()); | 10197 CHECK_EQ(12, value->Int32Value(context.local()).FromJust()); |
9155 } | 10198 } |
9156 | 10199 |
9157 | 10200 |
9158 static void GlobalObjectInstancePropertiesGet( | 10201 static void GlobalObjectInstancePropertiesGet( |
9159 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) { | 10202 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) { |
9160 ApiTestFuzzer::Fuzz(); | 10203 ApiTestFuzzer::Fuzz(); |
9161 } | 10204 } |
9162 | 10205 |
9163 | 10206 |
9164 THREADED_TEST(GlobalObjectInstanceProperties) { | 10207 THREADED_TEST(GlobalObjectInstanceProperties) { |
(...skipping 27 matching lines...) Expand all Loading... | |
9192 "try { wrapper(true); } catch (e) { thrown = 1; };" | 10235 "try { wrapper(true); } catch (e) { thrown = 1; };" |
9193 "thrown"; | 10236 "thrown"; |
9194 | 10237 |
9195 { | 10238 { |
9196 LocalContext env(NULL, instance_template); | 10239 LocalContext env(NULL, instance_template); |
9197 // Hold on to the global object so it can be used again in another | 10240 // Hold on to the global object so it can be used again in another |
9198 // environment initialization. | 10241 // environment initialization. |
9199 global_object = env->Global(); | 10242 global_object = env->Global(); |
9200 | 10243 |
9201 Local<Value> value = CompileRun("x"); | 10244 Local<Value> value = CompileRun("x"); |
9202 CHECK_EQ(42, value->Int32Value()); | 10245 CHECK_EQ(42, value->Int32Value(env.local()).FromJust()); |
9203 value = CompileRun("f()"); | 10246 value = CompileRun("f()"); |
9204 CHECK_EQ(12, value->Int32Value()); | 10247 CHECK_EQ(12, value->Int32Value(env.local()).FromJust()); |
9205 value = CompileRun(script); | 10248 value = CompileRun(script); |
9206 CHECK_EQ(1, value->Int32Value()); | 10249 CHECK_EQ(1, value->Int32Value(env.local()).FromJust()); |
9207 } | 10250 } |
9208 | 10251 |
9209 { | 10252 { |
9210 // Create new environment reusing the global object. | 10253 // Create new environment reusing the global object. |
9211 LocalContext env(NULL, instance_template, global_object); | 10254 LocalContext env(NULL, instance_template, global_object); |
9212 Local<Value> value = CompileRun("x"); | 10255 Local<Value> value = CompileRun("x"); |
9213 CHECK_EQ(42, value->Int32Value()); | 10256 CHECK_EQ(42, value->Int32Value(env.local()).FromJust()); |
9214 value = CompileRun("f()"); | 10257 value = CompileRun("f()"); |
9215 CHECK_EQ(12, value->Int32Value()); | 10258 CHECK_EQ(12, value->Int32Value(env.local()).FromJust()); |
9216 value = CompileRun(script); | 10259 value = CompileRun(script); |
9217 CHECK_EQ(1, value->Int32Value()); | 10260 CHECK_EQ(1, value->Int32Value(env.local()).FromJust()); |
9218 } | 10261 } |
9219 } | 10262 } |
9220 | 10263 |
9221 | 10264 |
9222 THREADED_TEST(CallKnownGlobalReceiver) { | 10265 THREADED_TEST(CallKnownGlobalReceiver) { |
9223 v8::Isolate* isolate = CcTest::isolate(); | 10266 v8::Isolate* isolate = CcTest::isolate(); |
9224 v8::HandleScope handle_scope(isolate); | 10267 v8::HandleScope handle_scope(isolate); |
9225 | 10268 |
9226 Local<Value> global_object; | 10269 Local<Value> global_object; |
9227 | 10270 |
(...skipping 19 matching lines...) Expand all Loading... | |
9247 LocalContext env(NULL, instance_template); | 10290 LocalContext env(NULL, instance_template); |
9248 // Hold on to the global object so it can be used again in another | 10291 // Hold on to the global object so it can be used again in another |
9249 // environment initialization. | 10292 // environment initialization. |
9250 global_object = env->Global(); | 10293 global_object = env->Global(); |
9251 foo = CompileRun(script); | 10294 foo = CompileRun(script); |
9252 } | 10295 } |
9253 | 10296 |
9254 { | 10297 { |
9255 // Create new environment reusing the global object. | 10298 // Create new environment reusing the global object. |
9256 LocalContext env(NULL, instance_template, global_object); | 10299 LocalContext env(NULL, instance_template, global_object); |
9257 env->Global()->Set(v8_str("foo"), foo); | 10300 CHECK(env->Global()->Set(env.local(), v8_str("foo"), foo).FromJust()); |
9258 CompileRun("foo()"); | 10301 CompileRun("foo()"); |
9259 } | 10302 } |
9260 } | 10303 } |
9261 | 10304 |
9262 | 10305 |
9263 static void ShadowFunctionCallback( | 10306 static void ShadowFunctionCallback( |
9264 const v8::FunctionCallbackInfo<v8::Value>& args) { | 10307 const v8::FunctionCallbackInfo<v8::Value>& args) { |
9265 ApiTestFuzzer::Fuzz(); | 10308 ApiTestFuzzer::Fuzz(); |
9266 args.GetReturnValue().Set(v8_num(42)); | 10309 args.GetReturnValue().Set(v8_num(42)); |
9267 } | 10310 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9314 Local<ObjectTemplate> instance = t->InstanceTemplate(); | 10357 Local<ObjectTemplate> instance = t->InstanceTemplate(); |
9315 | 10358 |
9316 proto->Set(v8_str("f"), | 10359 proto->Set(v8_str("f"), |
9317 v8::FunctionTemplate::New(isolate, | 10360 v8::FunctionTemplate::New(isolate, |
9318 ShadowFunctionCallback, | 10361 ShadowFunctionCallback, |
9319 Local<Value>())); | 10362 Local<Value>())); |
9320 proto->Set(v8_str("x"), v8_num(12)); | 10363 proto->Set(v8_str("x"), v8_num(12)); |
9321 | 10364 |
9322 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); | 10365 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); |
9323 | 10366 |
9324 Local<Value> o = t->GetFunction()->NewInstance(); | 10367 Local<Value> o = t->GetFunction(context.local()) |
9325 context->Global()->Set(v8_str("__proto__"), o); | 10368 .ToLocalChecked() |
10369 ->NewInstance(context.local()) | |
10370 .ToLocalChecked(); | |
10371 CHECK(context->Global() | |
10372 ->Set(context.local(), v8_str("__proto__"), o) | |
10373 .FromJust()); | |
9326 | 10374 |
9327 Local<Value> value = | 10375 Local<Value> value = |
9328 CompileRun("this.propertyIsEnumerable(0)"); | 10376 CompileRun("this.propertyIsEnumerable(0)"); |
9329 CHECK(value->IsBoolean()); | 10377 CHECK(value->IsBoolean()); |
9330 CHECK(!value->BooleanValue()); | 10378 CHECK(!value->BooleanValue(context.local()).FromJust()); |
9331 | 10379 |
9332 value = CompileRun("x"); | 10380 value = CompileRun("x"); |
9333 CHECK_EQ(12, value->Int32Value()); | 10381 CHECK_EQ(12, value->Int32Value(context.local()).FromJust()); |
9334 | 10382 |
9335 value = CompileRun("f()"); | 10383 value = CompileRun("f()"); |
9336 CHECK_EQ(42, value->Int32Value()); | 10384 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
9337 | 10385 |
9338 CompileRun("y = 43"); | 10386 CompileRun("y = 43"); |
9339 CHECK_EQ(1, shadow_y_setter_call_count); | 10387 CHECK_EQ(1, shadow_y_setter_call_count); |
9340 value = CompileRun("y"); | 10388 value = CompileRun("y"); |
9341 CHECK_EQ(1, shadow_y_getter_call_count); | 10389 CHECK_EQ(1, shadow_y_getter_call_count); |
9342 CHECK_EQ(42, value->Int32Value()); | 10390 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
9343 } | 10391 } |
9344 | 10392 |
9345 | 10393 |
9346 THREADED_TEST(HiddenPrototype) { | 10394 THREADED_TEST(HiddenPrototype) { |
9347 LocalContext context; | 10395 LocalContext context; |
9348 v8::Isolate* isolate = context->GetIsolate(); | 10396 v8::Isolate* isolate = context->GetIsolate(); |
9349 v8::HandleScope handle_scope(isolate); | 10397 v8::HandleScope handle_scope(isolate); |
9350 | 10398 |
9351 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); | 10399 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); |
9352 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 10400 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
9353 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10401 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
9354 t1->SetHiddenPrototype(true); | 10402 t1->SetHiddenPrototype(true); |
9355 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); | 10403 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); |
9356 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); | 10404 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
9357 t2->SetHiddenPrototype(true); | 10405 t2->SetHiddenPrototype(true); |
9358 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); | 10406 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); |
9359 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); | 10407 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
9360 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); | 10408 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); |
9361 | 10409 |
9362 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); | 10410 Local<v8::Object> o0 = t0->GetFunction(context.local()) |
9363 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 10411 .ToLocalChecked() |
9364 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 10412 ->NewInstance(context.local()) |
9365 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); | 10413 .ToLocalChecked(); |
10414 Local<v8::Object> o1 = t1->GetFunction(context.local()) | |
10415 .ToLocalChecked() | |
10416 ->NewInstance(context.local()) | |
10417 .ToLocalChecked(); | |
10418 Local<v8::Object> o2 = t2->GetFunction(context.local()) | |
10419 .ToLocalChecked() | |
10420 ->NewInstance(context.local()) | |
10421 .ToLocalChecked(); | |
10422 Local<v8::Object> o3 = t3->GetFunction(context.local()) | |
10423 .ToLocalChecked() | |
10424 ->NewInstance(context.local()) | |
10425 .ToLocalChecked(); | |
9366 | 10426 |
9367 // Setting the prototype on an object skips hidden prototypes. | 10427 // Setting the prototype on an object skips hidden prototypes. |
9368 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10428 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) |
9369 o0->Set(v8_str("__proto__"), o1); | 10429 .ToLocalChecked() |
9370 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10430 ->Int32Value(context.local()) |
9371 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10431 .FromJust()); |
9372 o0->Set(v8_str("__proto__"), o2); | 10432 CHECK(o0->Set(context.local(), v8_str("__proto__"), o1).FromJust()); |
9373 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10433 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) |
9374 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10434 .ToLocalChecked() |
9375 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 10435 ->Int32Value(context.local()) |
9376 o0->Set(v8_str("__proto__"), o3); | 10436 .FromJust()); |
9377 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10437 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) |
9378 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10438 .ToLocalChecked() |
9379 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 10439 ->Int32Value(context.local()) |
9380 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); | 10440 .FromJust()); |
10441 CHECK(o0->Set(context.local(), v8_str("__proto__"), o2).FromJust()); | |
10442 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) | |
10443 .ToLocalChecked() | |
10444 ->Int32Value(context.local()) | |
10445 .FromJust()); | |
10446 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) | |
10447 .ToLocalChecked() | |
10448 ->Int32Value(context.local()) | |
10449 .FromJust()); | |
10450 CHECK_EQ(2, o0->Get(context.local(), v8_str("z")) | |
10451 .ToLocalChecked() | |
10452 ->Int32Value(context.local()) | |
10453 .FromJust()); | |
10454 CHECK(o0->Set(context.local(), v8_str("__proto__"), o3).FromJust()); | |
10455 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) | |
10456 .ToLocalChecked() | |
10457 ->Int32Value(context.local()) | |
10458 .FromJust()); | |
10459 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) | |
10460 .ToLocalChecked() | |
10461 ->Int32Value(context.local()) | |
10462 .FromJust()); | |
10463 CHECK_EQ(2, o0->Get(context.local(), v8_str("z")) | |
10464 .ToLocalChecked() | |
10465 ->Int32Value(context.local()) | |
10466 .FromJust()); | |
10467 CHECK_EQ(3, o0->Get(context.local(), v8_str("u")) | |
10468 .ToLocalChecked() | |
10469 ->Int32Value(context.local()) | |
10470 .FromJust()); | |
9381 | 10471 |
9382 // Getting the prototype of o0 should get the first visible one | 10472 // Getting the prototype of o0 should get the first visible one |
9383 // which is o3. Therefore, z should not be defined on the prototype | 10473 // which is o3. Therefore, z should not be defined on the prototype |
9384 // object. | 10474 // object. |
9385 Local<Value> proto = o0->Get(v8_str("__proto__")); | 10475 Local<Value> proto = |
10476 o0->Get(context.local(), v8_str("__proto__")).ToLocalChecked(); | |
9386 CHECK(proto->IsObject()); | 10477 CHECK(proto->IsObject()); |
9387 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); | 10478 CHECK(proto.As<v8::Object>() |
10479 ->Get(context.local(), v8_str("z")) | |
10480 .ToLocalChecked() | |
10481 ->IsUndefined()); | |
9388 } | 10482 } |
9389 | 10483 |
9390 | 10484 |
9391 THREADED_TEST(HiddenPrototypeSet) { | 10485 THREADED_TEST(HiddenPrototypeSet) { |
9392 LocalContext context; | 10486 LocalContext context; |
9393 v8::Isolate* isolate = context->GetIsolate(); | 10487 v8::Isolate* isolate = context->GetIsolate(); |
9394 v8::HandleScope handle_scope(isolate); | 10488 v8::HandleScope handle_scope(isolate); |
9395 | 10489 |
9396 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate); | 10490 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate); |
9397 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate); | 10491 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate); |
9398 ht->SetHiddenPrototype(true); | 10492 ht->SetHiddenPrototype(true); |
9399 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate); | 10493 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate); |
9400 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 10494 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
9401 | 10495 |
9402 Local<v8::Object> o = ot->GetFunction()->NewInstance(); | 10496 Local<v8::Object> o = ot->GetFunction(context.local()) |
9403 Local<v8::Object> h = ht->GetFunction()->NewInstance(); | 10497 .ToLocalChecked() |
9404 Local<v8::Object> p = pt->GetFunction()->NewInstance(); | 10498 ->NewInstance(context.local()) |
9405 o->Set(v8_str("__proto__"), h); | 10499 .ToLocalChecked(); |
9406 h->Set(v8_str("__proto__"), p); | 10500 Local<v8::Object> h = ht->GetFunction(context.local()) |
10501 .ToLocalChecked() | |
10502 ->NewInstance(context.local()) | |
10503 .ToLocalChecked(); | |
10504 Local<v8::Object> p = pt->GetFunction(context.local()) | |
10505 .ToLocalChecked() | |
10506 ->NewInstance(context.local()) | |
10507 .ToLocalChecked(); | |
10508 CHECK(o->Set(context.local(), v8_str("__proto__"), h).FromJust()); | |
10509 CHECK(h->Set(context.local(), v8_str("__proto__"), p).FromJust()); | |
9407 | 10510 |
9408 // Setting a property that exists on the hidden prototype goes there. | 10511 // Setting a property that exists on the hidden prototype goes there. |
9409 o->Set(v8_str("x"), v8_num(7)); | 10512 CHECK(o->Set(context.local(), v8_str("x"), v8_num(7)).FromJust()); |
9410 CHECK_EQ(7, o->Get(v8_str("x"))->Int32Value()); | 10513 CHECK_EQ(7, o->Get(context.local(), v8_str("x")) |
9411 CHECK_EQ(7, h->Get(v8_str("x"))->Int32Value()); | 10514 .ToLocalChecked() |
9412 CHECK(p->Get(v8_str("x"))->IsUndefined()); | 10515 ->Int32Value(context.local()) |
10516 .FromJust()); | |
10517 CHECK_EQ(7, h->Get(context.local(), v8_str("x")) | |
10518 .ToLocalChecked() | |
10519 ->Int32Value(context.local()) | |
10520 .FromJust()); | |
10521 CHECK(p->Get(context.local(), v8_str("x")).ToLocalChecked()->IsUndefined()); | |
9413 | 10522 |
9414 // Setting a new property should not be forwarded to the hidden prototype. | 10523 // Setting a new property should not be forwarded to the hidden prototype. |
9415 o->Set(v8_str("y"), v8_num(6)); | 10524 CHECK(o->Set(context.local(), v8_str("y"), v8_num(6)).FromJust()); |
9416 CHECK_EQ(6, o->Get(v8_str("y"))->Int32Value()); | 10525 CHECK_EQ(6, o->Get(context.local(), v8_str("y")) |
9417 CHECK(h->Get(v8_str("y"))->IsUndefined()); | 10526 .ToLocalChecked() |
9418 CHECK(p->Get(v8_str("y"))->IsUndefined()); | 10527 ->Int32Value(context.local()) |
10528 .FromJust()); | |
10529 CHECK(h->Get(context.local(), v8_str("y")).ToLocalChecked()->IsUndefined()); | |
10530 CHECK(p->Get(context.local(), v8_str("y")).ToLocalChecked()->IsUndefined()); | |
9419 | 10531 |
9420 // Setting a property that only exists on a prototype of the hidden prototype | 10532 // Setting a property that only exists on a prototype of the hidden prototype |
9421 // is treated normally again. | 10533 // is treated normally again. |
9422 p->Set(v8_str("z"), v8_num(8)); | 10534 CHECK(p->Set(context.local(), v8_str("z"), v8_num(8)).FromJust()); |
9423 CHECK_EQ(8, o->Get(v8_str("z"))->Int32Value()); | 10535 CHECK_EQ(8, o->Get(context.local(), v8_str("z")) |
9424 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); | 10536 .ToLocalChecked() |
9425 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); | 10537 ->Int32Value(context.local()) |
9426 o->Set(v8_str("z"), v8_num(9)); | 10538 .FromJust()); |
9427 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value()); | 10539 CHECK_EQ(8, h->Get(context.local(), v8_str("z")) |
9428 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); | 10540 .ToLocalChecked() |
9429 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); | 10541 ->Int32Value(context.local()) |
10542 .FromJust()); | |
10543 CHECK_EQ(8, p->Get(context.local(), v8_str("z")) | |
10544 .ToLocalChecked() | |
10545 ->Int32Value(context.local()) | |
10546 .FromJust()); | |
10547 CHECK(o->Set(context.local(), v8_str("z"), v8_num(9)).FromJust()); | |
10548 CHECK_EQ(9, o->Get(context.local(), v8_str("z")) | |
10549 .ToLocalChecked() | |
10550 ->Int32Value(context.local()) | |
10551 .FromJust()); | |
10552 CHECK_EQ(8, h->Get(context.local(), v8_str("z")) | |
10553 .ToLocalChecked() | |
10554 ->Int32Value(context.local()) | |
10555 .FromJust()); | |
10556 CHECK_EQ(8, p->Get(context.local(), v8_str("z")) | |
10557 .ToLocalChecked() | |
10558 ->Int32Value(context.local()) | |
10559 .FromJust()); | |
9430 } | 10560 } |
9431 | 10561 |
9432 | 10562 |
9433 // Regression test for issue 2457. | 10563 // Regression test for issue 2457. |
9434 THREADED_TEST(HiddenPrototypeIdentityHash) { | 10564 THREADED_TEST(HiddenPrototypeIdentityHash) { |
9435 LocalContext context; | 10565 LocalContext context; |
9436 v8::HandleScope handle_scope(context->GetIsolate()); | 10566 v8::HandleScope handle_scope(context->GetIsolate()); |
9437 | 10567 |
9438 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); | 10568 Local<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); |
9439 t->SetHiddenPrototype(true); | 10569 t->SetHiddenPrototype(true); |
9440 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); | 10570 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); |
9441 Handle<Object> p = t->GetFunction()->NewInstance(); | 10571 Local<Object> p = t->GetFunction(context.local()) |
9442 Handle<Object> o = Object::New(context->GetIsolate()); | 10572 .ToLocalChecked() |
9443 o->SetPrototype(p); | 10573 ->NewInstance(context.local()) |
10574 .ToLocalChecked(); | |
10575 Local<Object> o = Object::New(context->GetIsolate()); | |
10576 CHECK(o->SetPrototype(context.local(), p).FromJust()); | |
9444 | 10577 |
9445 int hash = o->GetIdentityHash(); | 10578 int hash = o->GetIdentityHash(); |
9446 USE(hash); | 10579 USE(hash); |
9447 o->Set(v8_str("foo"), v8_num(42)); | 10580 CHECK(o->Set(context.local(), v8_str("foo"), v8_num(42)).FromJust()); |
9448 DCHECK_EQ(hash, o->GetIdentityHash()); | 10581 DCHECK_EQ(hash, o->GetIdentityHash()); |
9449 } | 10582 } |
9450 | 10583 |
9451 | 10584 |
9452 THREADED_TEST(SetPrototype) { | 10585 THREADED_TEST(SetPrototype) { |
9453 LocalContext context; | 10586 LocalContext context; |
9454 v8::Isolate* isolate = context->GetIsolate(); | 10587 v8::Isolate* isolate = context->GetIsolate(); |
9455 v8::HandleScope handle_scope(isolate); | 10588 v8::HandleScope handle_scope(isolate); |
9456 | 10589 |
9457 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); | 10590 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); |
9458 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); | 10591 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); |
9459 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10592 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
9460 t1->SetHiddenPrototype(true); | 10593 t1->SetHiddenPrototype(true); |
9461 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); | 10594 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); |
9462 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); | 10595 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
9463 t2->SetHiddenPrototype(true); | 10596 t2->SetHiddenPrototype(true); |
9464 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); | 10597 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); |
9465 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); | 10598 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); |
9466 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); | 10599 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); |
9467 | 10600 |
9468 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); | 10601 Local<v8::Object> o0 = t0->GetFunction(context.local()) |
9469 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 10602 .ToLocalChecked() |
9470 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 10603 ->NewInstance(context.local()) |
9471 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); | 10604 .ToLocalChecked(); |
10605 Local<v8::Object> o1 = t1->GetFunction(context.local()) | |
10606 .ToLocalChecked() | |
10607 ->NewInstance(context.local()) | |
10608 .ToLocalChecked(); | |
10609 Local<v8::Object> o2 = t2->GetFunction(context.local()) | |
10610 .ToLocalChecked() | |
10611 ->NewInstance(context.local()) | |
10612 .ToLocalChecked(); | |
10613 Local<v8::Object> o3 = t3->GetFunction(context.local()) | |
10614 .ToLocalChecked() | |
10615 ->NewInstance(context.local()) | |
10616 .ToLocalChecked(); | |
9472 | 10617 |
9473 // Setting the prototype on an object does not skip hidden prototypes. | 10618 // Setting the prototype on an object does not skip hidden prototypes. |
9474 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10619 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) |
9475 CHECK(o0->SetPrototype(o1)); | 10620 .ToLocalChecked() |
9476 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10621 ->Int32Value(context.local()) |
9477 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10622 .FromJust()); |
9478 CHECK(o1->SetPrototype(o2)); | 10623 CHECK(o0->SetPrototype(context.local(), o1).FromJust()); |
9479 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10624 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) |
9480 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10625 .ToLocalChecked() |
9481 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 10626 ->Int32Value(context.local()) |
9482 CHECK(o2->SetPrototype(o3)); | 10627 .FromJust()); |
9483 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); | 10628 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) |
9484 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); | 10629 .ToLocalChecked() |
9485 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); | 10630 ->Int32Value(context.local()) |
9486 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); | 10631 .FromJust()); |
10632 CHECK(o1->SetPrototype(context.local(), o2).FromJust()); | |
10633 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) | |
10634 .ToLocalChecked() | |
10635 ->Int32Value(context.local()) | |
10636 .FromJust()); | |
10637 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) | |
10638 .ToLocalChecked() | |
10639 ->Int32Value(context.local()) | |
10640 .FromJust()); | |
10641 CHECK_EQ(2, o0->Get(context.local(), v8_str("z")) | |
10642 .ToLocalChecked() | |
10643 ->Int32Value(context.local()) | |
10644 .FromJust()); | |
10645 CHECK(o2->SetPrototype(context.local(), o3).FromJust()); | |
10646 CHECK_EQ(0, o0->Get(context.local(), v8_str("x")) | |
10647 .ToLocalChecked() | |
10648 ->Int32Value(context.local()) | |
10649 .FromJust()); | |
10650 CHECK_EQ(1, o0->Get(context.local(), v8_str("y")) | |
10651 .ToLocalChecked() | |
10652 ->Int32Value(context.local()) | |
10653 .FromJust()); | |
10654 CHECK_EQ(2, o0->Get(context.local(), v8_str("z")) | |
10655 .ToLocalChecked() | |
10656 ->Int32Value(context.local()) | |
10657 .FromJust()); | |
10658 CHECK_EQ(3, o0->Get(context.local(), v8_str("u")) | |
10659 .ToLocalChecked() | |
10660 ->Int32Value(context.local()) | |
10661 .FromJust()); | |
9487 | 10662 |
9488 // Getting the prototype of o0 should get the first visible one | 10663 // Getting the prototype of o0 should get the first visible one |
9489 // which is o3. Therefore, z should not be defined on the prototype | 10664 // which is o3. Therefore, z should not be defined on the prototype |
9490 // object. | 10665 // object. |
9491 Local<Value> proto = o0->Get(v8_str("__proto__")); | 10666 Local<Value> proto = |
10667 o0->Get(context.local(), v8_str("__proto__")).ToLocalChecked(); | |
9492 CHECK(proto->IsObject()); | 10668 CHECK(proto->IsObject()); |
9493 CHECK(proto.As<v8::Object>()->Equals(o3)); | 10669 CHECK(proto.As<v8::Object>()->Equals(context.local(), o3).FromJust()); |
9494 | 10670 |
9495 // However, Object::GetPrototype ignores hidden prototype. | 10671 // However, Object::GetPrototype ignores hidden prototype. |
9496 Local<Value> proto0 = o0->GetPrototype(); | 10672 Local<Value> proto0 = o0->GetPrototype(); |
9497 CHECK(proto0->IsObject()); | 10673 CHECK(proto0->IsObject()); |
9498 CHECK(proto0.As<v8::Object>()->Equals(o1)); | 10674 CHECK(proto0.As<v8::Object>()->Equals(context.local(), o1).FromJust()); |
9499 | 10675 |
9500 Local<Value> proto1 = o1->GetPrototype(); | 10676 Local<Value> proto1 = o1->GetPrototype(); |
9501 CHECK(proto1->IsObject()); | 10677 CHECK(proto1->IsObject()); |
9502 CHECK(proto1.As<v8::Object>()->Equals(o2)); | 10678 CHECK(proto1.As<v8::Object>()->Equals(context.local(), o2).FromJust()); |
9503 | 10679 |
9504 Local<Value> proto2 = o2->GetPrototype(); | 10680 Local<Value> proto2 = o2->GetPrototype(); |
9505 CHECK(proto2->IsObject()); | 10681 CHECK(proto2->IsObject()); |
9506 CHECK(proto2.As<v8::Object>()->Equals(o3)); | 10682 CHECK(proto2.As<v8::Object>()->Equals(context.local(), o3).FromJust()); |
9507 } | 10683 } |
9508 | 10684 |
9509 | 10685 |
9510 // Getting property names of an object with a prototype chain that | 10686 // Getting property names of an object with a prototype chain that |
9511 // triggers dictionary elements in GetOwnPropertyNames() shouldn't | 10687 // triggers dictionary elements in GetOwnPropertyNames() shouldn't |
9512 // crash the runtime. | 10688 // crash the runtime. |
9513 THREADED_TEST(Regress91517) { | 10689 THREADED_TEST(Regress91517) { |
9514 i::FLAG_allow_natives_syntax = true; | 10690 i::FLAG_allow_natives_syntax = true; |
9515 LocalContext context; | 10691 LocalContext context; |
9516 v8::Isolate* isolate = context->GetIsolate(); | 10692 v8::Isolate* isolate = context->GetIsolate(); |
(...skipping 13 matching lines...) Expand all Loading... | |
9530 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); | 10706 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); |
9531 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); | 10707 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); |
9532 | 10708 |
9533 // Force dictionary-based properties. | 10709 // Force dictionary-based properties. |
9534 i::ScopedVector<char> name_buf(1024); | 10710 i::ScopedVector<char> name_buf(1024); |
9535 for (int i = 1; i <= 1000; i++) { | 10711 for (int i = 1; i <= 1000; i++) { |
9536 i::SNPrintF(name_buf, "sdf%d", i); | 10712 i::SNPrintF(name_buf, "sdf%d", i); |
9537 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); | 10713 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); |
9538 } | 10714 } |
9539 | 10715 |
9540 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 10716 Local<v8::Object> o1 = t1->GetFunction(context.local()) |
9541 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 10717 .ToLocalChecked() |
9542 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); | 10718 ->NewInstance(context.local()) |
9543 Local<v8::Object> o4 = t4->GetFunction()->NewInstance(); | 10719 .ToLocalChecked(); |
10720 Local<v8::Object> o2 = t2->GetFunction(context.local()) | |
10721 .ToLocalChecked() | |
10722 ->NewInstance(context.local()) | |
10723 .ToLocalChecked(); | |
10724 Local<v8::Object> o3 = t3->GetFunction(context.local()) | |
10725 .ToLocalChecked() | |
10726 ->NewInstance(context.local()) | |
10727 .ToLocalChecked(); | |
10728 Local<v8::Object> o4 = t4->GetFunction(context.local()) | |
10729 .ToLocalChecked() | |
10730 ->NewInstance(context.local()) | |
10731 .ToLocalChecked(); | |
9544 | 10732 |
9545 // Create prototype chain of hidden prototypes. | 10733 // Create prototype chain of hidden prototypes. |
9546 CHECK(o4->SetPrototype(o3)); | 10734 CHECK(o4->SetPrototype(context.local(), o3).FromJust()); |
9547 CHECK(o3->SetPrototype(o2)); | 10735 CHECK(o3->SetPrototype(context.local(), o2).FromJust()); |
9548 CHECK(o2->SetPrototype(o1)); | 10736 CHECK(o2->SetPrototype(context.local(), o1).FromJust()); |
9549 | 10737 |
9550 // Call the runtime version of GetOwnPropertyNames() on the natively | 10738 // Call the runtime version of GetOwnPropertyNames() on the natively |
9551 // created object through JavaScript. | 10739 // created object through JavaScript. |
9552 context->Global()->Set(v8_str("obj"), o4); | 10740 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust()); |
9553 // PROPERTY_ATTRIBUTES_NONE = 0 | 10741 // PROPERTY_ATTRIBUTES_NONE = 0 |
9554 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); | 10742 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); |
9555 | 10743 |
9556 ExpectInt32("names.length", 1006); | 10744 ExpectInt32("names.length", 1006); |
9557 ExpectTrue("names.indexOf(\"baz\") >= 0"); | 10745 ExpectTrue("names.indexOf(\"baz\") >= 0"); |
9558 ExpectTrue("names.indexOf(\"boo\") >= 0"); | 10746 ExpectTrue("names.indexOf(\"boo\") >= 0"); |
9559 ExpectTrue("names.indexOf(\"foo\") >= 0"); | 10747 ExpectTrue("names.indexOf(\"foo\") >= 0"); |
9560 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); | 10748 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); |
9561 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); | 10749 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); |
9562 ExpectFalse("names[1005] == undefined"); | 10750 ExpectFalse("names[1005] == undefined"); |
(...skipping 14 matching lines...) Expand all Loading... | |
9577 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate(); | 10765 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate(); |
9578 i1->SetAccessor(v8_str("foo"), | 10766 i1->SetAccessor(v8_str("foo"), |
9579 SimpleAccessorGetter, SimpleAccessorSetter); | 10767 SimpleAccessorGetter, SimpleAccessorSetter); |
9580 i1->SetAccessor(v8_str("bar"), | 10768 i1->SetAccessor(v8_str("bar"), |
9581 SimpleAccessorGetter, SimpleAccessorSetter); | 10769 SimpleAccessorGetter, SimpleAccessorSetter); |
9582 i1->SetAccessor(v8_str("baz"), | 10770 i1->SetAccessor(v8_str("baz"), |
9583 SimpleAccessorGetter, SimpleAccessorSetter); | 10771 SimpleAccessorGetter, SimpleAccessorSetter); |
9584 i1->Set(v8_str("n1"), v8_num(1)); | 10772 i1->Set(v8_str("n1"), v8_num(1)); |
9585 i1->Set(v8_str("n2"), v8_num(2)); | 10773 i1->Set(v8_str("n2"), v8_num(2)); |
9586 | 10774 |
9587 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); | 10775 Local<v8::Object> o1 = t1->GetFunction(context.local()) |
10776 .ToLocalChecked() | |
10777 ->NewInstance(context.local()) | |
10778 .ToLocalChecked(); | |
9588 Local<v8::FunctionTemplate> t2 = | 10779 Local<v8::FunctionTemplate> t2 = |
9589 v8::FunctionTemplate::New(context->GetIsolate()); | 10780 v8::FunctionTemplate::New(context->GetIsolate()); |
9590 t2->SetHiddenPrototype(true); | 10781 t2->SetHiddenPrototype(true); |
9591 | 10782 |
9592 // Inherit from t1 and mark prototype as hidden. | 10783 // Inherit from t1 and mark prototype as hidden. |
9593 t2->Inherit(t1); | 10784 t2->Inherit(t1); |
9594 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4)); | 10785 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4)); |
9595 | 10786 |
9596 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); | 10787 Local<v8::Object> o2 = t2->GetFunction(context.local()) |
9597 CHECK(o2->SetPrototype(o1)); | 10788 .ToLocalChecked() |
10789 ->NewInstance(context.local()) | |
10790 .ToLocalChecked(); | |
10791 CHECK(o2->SetPrototype(context.local(), o1).FromJust()); | |
9598 | 10792 |
9599 v8::Local<v8::Symbol> sym = | 10793 v8::Local<v8::Symbol> sym = |
9600 v8::Symbol::New(context->GetIsolate(), v8_str("s1")); | 10794 v8::Symbol::New(context->GetIsolate(), v8_str("s1")); |
9601 o1->Set(sym, v8_num(3)); | 10795 CHECK(o1->Set(context.local(), sym, v8_num(3)).FromJust()); |
9602 o1->SetPrivate(context.local(), | 10796 o1->SetPrivate(context.local(), |
9603 v8::Private::New(context->GetIsolate(), v8_str("h1")), | 10797 v8::Private::New(context->GetIsolate(), v8_str("h1")), |
9604 v8::Integer::New(context->GetIsolate(), 2013)) | 10798 v8::Integer::New(context->GetIsolate(), 2013)) |
9605 .FromJust(); | 10799 .FromJust(); |
9606 | 10800 |
9607 // Call the runtime version of GetOwnPropertyNames() on | 10801 // Call the runtime version of GetOwnPropertyNames() on |
9608 // the natively created object through JavaScript. | 10802 // the natively created object through JavaScript. |
9609 context->Global()->Set(v8_str("obj"), o2); | 10803 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o2).FromJust()); |
9610 context->Global()->Set(v8_str("sym"), sym); | 10804 CHECK(context->Global()->Set(context.local(), v8_str("sym"), sym).FromJust()); |
9611 // PROPERTY_ATTRIBUTES_NONE = 0 | 10805 // PROPERTY_ATTRIBUTES_NONE = 0 |
9612 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); | 10806 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); |
9613 | 10807 |
9614 ExpectInt32("names.length", 7); | 10808 ExpectInt32("names.length", 7); |
9615 ExpectTrue("names.indexOf(\"foo\") >= 0"); | 10809 ExpectTrue("names.indexOf(\"foo\") >= 0"); |
9616 ExpectTrue("names.indexOf(\"bar\") >= 0"); | 10810 ExpectTrue("names.indexOf(\"bar\") >= 0"); |
9617 ExpectTrue("names.indexOf(\"baz\") >= 0"); | 10811 ExpectTrue("names.indexOf(\"baz\") >= 0"); |
9618 ExpectTrue("names.indexOf(\"n1\") >= 0"); | 10812 ExpectTrue("names.indexOf(\"n1\") >= 0"); |
9619 ExpectTrue("names.indexOf(\"n2\") >= 0"); | 10813 ExpectTrue("names.indexOf(\"n2\") >= 0"); |
9620 ExpectTrue("names.indexOf(sym) >= 0"); | 10814 ExpectTrue("names.indexOf(sym) >= 0"); |
9621 ExpectTrue("names.indexOf(\"mine\") >= 0"); | 10815 ExpectTrue("names.indexOf(\"mine\") >= 0"); |
9622 } | 10816 } |
9623 | 10817 |
9624 | 10818 |
9625 THREADED_TEST(FunctionReadOnlyPrototype) { | 10819 THREADED_TEST(FunctionReadOnlyPrototype) { |
9626 LocalContext context; | 10820 LocalContext context; |
9627 v8::Isolate* isolate = context->GetIsolate(); | 10821 v8::Isolate* isolate = context->GetIsolate(); |
9628 v8::HandleScope handle_scope(isolate); | 10822 v8::HandleScope handle_scope(isolate); |
9629 | 10823 |
9630 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10824 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
9631 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 10825 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
9632 t1->ReadOnlyPrototype(); | 10826 t1->ReadOnlyPrototype(); |
9633 context->Global()->Set(v8_str("func1"), t1->GetFunction()); | 10827 CHECK(context->Global() |
10828 ->Set(context.local(), v8_str("func1"), | |
10829 t1->GetFunction(context.local()).ToLocalChecked()) | |
10830 .FromJust()); | |
9634 // Configured value of ReadOnly flag. | 10831 // Configured value of ReadOnly flag. |
9635 CHECK(CompileRun( | 10832 CHECK( |
9636 "(function() {" | 10833 CompileRun( |
9637 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" | 10834 "(function() {" |
9638 " return (descriptor['writable'] == false);" | 10835 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" |
9639 "})()")->BooleanValue()); | 10836 " return (descriptor['writable'] == false);" |
9640 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); | 10837 "})()") |
9641 CHECK_EQ(42, | 10838 ->BooleanValue(context.local()) |
9642 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); | 10839 .FromJust()); |
10840 CHECK_EQ( | |
10841 42, | |
10842 CompileRun("func1.prototype.x")->Int32Value(context.local()).FromJust()); | |
10843 CHECK_EQ(42, CompileRun("func1.prototype = {}; func1.prototype.x") | |
10844 ->Int32Value(context.local()) | |
10845 .FromJust()); | |
9643 | 10846 |
9644 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); | 10847 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); |
9645 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 10848 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
9646 context->Global()->Set(v8_str("func2"), t2->GetFunction()); | 10849 CHECK(context->Global() |
10850 ->Set(context.local(), v8_str("func2"), | |
10851 t2->GetFunction(context.local()).ToLocalChecked()) | |
10852 .FromJust()); | |
9647 // Default value of ReadOnly flag. | 10853 // Default value of ReadOnly flag. |
9648 CHECK(CompileRun( | 10854 CHECK( |
9649 "(function() {" | 10855 CompileRun( |
9650 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" | 10856 "(function() {" |
9651 " return (descriptor['writable'] == true);" | 10857 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" |
9652 "})()")->BooleanValue()); | 10858 " return (descriptor['writable'] == true);" |
9653 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); | 10859 "})()") |
10860 ->BooleanValue(context.local()) | |
10861 .FromJust()); | |
10862 CHECK_EQ( | |
10863 42, | |
10864 CompileRun("func2.prototype.x")->Int32Value(context.local()).FromJust()); | |
9654 } | 10865 } |
9655 | 10866 |
9656 | 10867 |
9657 THREADED_TEST(SetPrototypeThrows) { | 10868 THREADED_TEST(SetPrototypeThrows) { |
9658 LocalContext context; | 10869 LocalContext context; |
9659 v8::Isolate* isolate = context->GetIsolate(); | 10870 v8::Isolate* isolate = context->GetIsolate(); |
9660 v8::HandleScope handle_scope(isolate); | 10871 v8::HandleScope handle_scope(isolate); |
9661 | 10872 |
9662 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 10873 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
9663 | 10874 |
9664 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); | 10875 Local<v8::Object> o0 = t->GetFunction(context.local()) |
9665 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); | 10876 .ToLocalChecked() |
10877 ->NewInstance(context.local()) | |
10878 .ToLocalChecked(); | |
10879 Local<v8::Object> o1 = t->GetFunction(context.local()) | |
10880 .ToLocalChecked() | |
10881 ->NewInstance(context.local()) | |
10882 .ToLocalChecked(); | |
9666 | 10883 |
9667 CHECK(o0->SetPrototype(o1)); | 10884 CHECK(o0->SetPrototype(context.local(), o1).FromJust()); |
9668 // If setting the prototype leads to the cycle, SetPrototype should | 10885 // If setting the prototype leads to the cycle, SetPrototype should |
9669 // return false and keep VM in sane state. | 10886 // return false and keep VM in sane state. |
9670 v8::TryCatch try_catch(isolate); | 10887 v8::TryCatch try_catch(isolate); |
9671 CHECK(!o1->SetPrototype(o0)); | 10888 CHECK(o1->SetPrototype(context.local(), o0).IsNothing()); |
9672 CHECK(!try_catch.HasCaught()); | 10889 CHECK(!try_catch.HasCaught()); |
9673 DCHECK(!CcTest::i_isolate()->has_pending_exception()); | 10890 DCHECK(!CcTest::i_isolate()->has_pending_exception()); |
9674 | 10891 |
9675 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); | 10892 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()") |
10893 ->Int32Value(context.local()) | |
10894 .FromJust()); | |
9676 } | 10895 } |
9677 | 10896 |
9678 | 10897 |
9679 THREADED_TEST(FunctionRemovePrototype) { | 10898 THREADED_TEST(FunctionRemovePrototype) { |
9680 LocalContext context; | 10899 LocalContext context; |
9681 v8::Isolate* isolate = context->GetIsolate(); | 10900 v8::Isolate* isolate = context->GetIsolate(); |
9682 v8::HandleScope handle_scope(isolate); | 10901 v8::HandleScope handle_scope(isolate); |
9683 | 10902 |
9684 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); | 10903 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); |
9685 t1->RemovePrototype(); | 10904 t1->RemovePrototype(); |
9686 Local<v8::Function> fun = t1->GetFunction(); | 10905 Local<v8::Function> fun = t1->GetFunction(context.local()).ToLocalChecked(); |
9687 context->Global()->Set(v8_str("fun"), fun); | 10906 CHECK(context->Global()->Set(context.local(), v8_str("fun"), fun).FromJust()); |
9688 CHECK(!CompileRun("'prototype' in fun")->BooleanValue()); | 10907 CHECK(!CompileRun("'prototype' in fun") |
10908 ->BooleanValue(context.local()) | |
10909 .FromJust()); | |
9689 | 10910 |
9690 v8::TryCatch try_catch(isolate); | 10911 v8::TryCatch try_catch(isolate); |
9691 CompileRun("new fun()"); | 10912 CompileRun("new fun()"); |
9692 CHECK(try_catch.HasCaught()); | 10913 CHECK(try_catch.HasCaught()); |
9693 | 10914 |
9694 try_catch.Reset(); | 10915 try_catch.Reset(); |
9695 fun->NewInstance(); | 10916 CHECK(fun->NewInstance(context.local()).IsEmpty()); |
9696 CHECK(try_catch.HasCaught()); | 10917 CHECK(try_catch.HasCaught()); |
9697 } | 10918 } |
9698 | 10919 |
9699 | 10920 |
9700 THREADED_TEST(GetterSetterExceptions) { | 10921 THREADED_TEST(GetterSetterExceptions) { |
9701 LocalContext context; | 10922 LocalContext context; |
9702 v8::Isolate* isolate = context->GetIsolate(); | 10923 v8::Isolate* isolate = context->GetIsolate(); |
9703 v8::HandleScope handle_scope(isolate); | 10924 v8::HandleScope handle_scope(isolate); |
9704 CompileRun( | 10925 CompileRun( |
9705 "function Foo() { };" | 10926 "function Foo() { };" |
9706 "function Throw() { throw 5; };" | 10927 "function Throw() { throw 5; };" |
9707 "var x = { };" | 10928 "var x = { };" |
9708 "x.__defineSetter__('set', Throw);" | 10929 "x.__defineSetter__('set', Throw);" |
9709 "x.__defineGetter__('get', Throw);"); | 10930 "x.__defineGetter__('get', Throw);"); |
9710 Local<v8::Object> x = | 10931 Local<v8::Object> x = Local<v8::Object>::Cast( |
9711 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); | 10932 context->Global()->Get(context.local(), v8_str("x")).ToLocalChecked()); |
9712 v8::TryCatch try_catch(isolate); | 10933 v8::TryCatch try_catch(isolate); |
9713 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10934 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8)) |
9714 x->Get(v8_str("get")); | 10935 .IsNothing()); |
9715 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10936 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty()); |
9716 x->Get(v8_str("get")); | 10937 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8)) |
9717 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10938 .IsNothing()); |
9718 x->Get(v8_str("get")); | 10939 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty()); |
9719 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); | 10940 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8)) |
9720 x->Get(v8_str("get")); | 10941 .IsNothing()); |
10942 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty()); | |
10943 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8)) | |
10944 .IsNothing()); | |
10945 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty()); | |
9721 } | 10946 } |
9722 | 10947 |
9723 | 10948 |
9724 THREADED_TEST(Constructor) { | 10949 THREADED_TEST(Constructor) { |
9725 LocalContext context; | 10950 LocalContext context; |
9726 v8::Isolate* isolate = context->GetIsolate(); | 10951 v8::Isolate* isolate = context->GetIsolate(); |
9727 v8::HandleScope handle_scope(isolate); | 10952 v8::HandleScope handle_scope(isolate); |
9728 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 10953 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
9729 templ->SetClassName(v8_str("Fun")); | 10954 templ->SetClassName(v8_str("Fun")); |
9730 Local<Function> cons = templ->GetFunction(); | 10955 Local<Function> cons = templ->GetFunction(context.local()).ToLocalChecked(); |
9731 context->Global()->Set(v8_str("Fun"), cons); | 10956 CHECK( |
9732 Local<v8::Object> inst = cons->NewInstance(); | 10957 context->Global()->Set(context.local(), v8_str("Fun"), cons).FromJust()); |
10958 Local<v8::Object> inst = cons->NewInstance(context.local()).ToLocalChecked(); | |
9733 i::Handle<i::JSReceiver> obj(v8::Utils::OpenHandle(*inst)); | 10959 i::Handle<i::JSReceiver> obj(v8::Utils::OpenHandle(*inst)); |
9734 CHECK(obj->IsJSObject()); | 10960 CHECK(obj->IsJSObject()); |
9735 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); | 10961 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); |
9736 CHECK(value->BooleanValue()); | 10962 CHECK(value->BooleanValue(context.local()).FromJust()); |
9737 } | 10963 } |
9738 | 10964 |
9739 | 10965 |
9740 static void ConstructorCallback( | 10966 static void ConstructorCallback( |
9741 const v8::FunctionCallbackInfo<v8::Value>& args) { | 10967 const v8::FunctionCallbackInfo<v8::Value>& args) { |
9742 ApiTestFuzzer::Fuzz(); | 10968 ApiTestFuzzer::Fuzz(); |
9743 Local<Object> This; | 10969 Local<Object> This; |
9744 | 10970 |
10971 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); | |
9745 if (args.IsConstructCall()) { | 10972 if (args.IsConstructCall()) { |
9746 Local<Object> Holder = args.Holder(); | 10973 Local<Object> Holder = args.Holder(); |
9747 This = Object::New(args.GetIsolate()); | 10974 This = Object::New(args.GetIsolate()); |
9748 Local<Value> proto = Holder->GetPrototype(); | 10975 Local<Value> proto = Holder->GetPrototype(); |
9749 if (proto->IsObject()) { | 10976 if (proto->IsObject()) { |
9750 This->SetPrototype(proto); | 10977 This->SetPrototype(context, proto).FromJust(); |
9751 } | 10978 } |
9752 } else { | 10979 } else { |
9753 This = args.This(); | 10980 This = args.This(); |
9754 } | 10981 } |
9755 | 10982 |
9756 This->Set(v8_str("a"), args[0]); | 10983 This->Set(context, v8_str("a"), args[0]).FromJust(); |
9757 args.GetReturnValue().Set(This); | 10984 args.GetReturnValue().Set(This); |
9758 } | 10985 } |
9759 | 10986 |
9760 | 10987 |
9761 static void FakeConstructorCallback( | 10988 static void FakeConstructorCallback( |
9762 const v8::FunctionCallbackInfo<v8::Value>& args) { | 10989 const v8::FunctionCallbackInfo<v8::Value>& args) { |
9763 ApiTestFuzzer::Fuzz(); | 10990 ApiTestFuzzer::Fuzz(); |
9764 args.GetReturnValue().Set(args[0]); | 10991 args.GetReturnValue().Set(args[0]); |
9765 } | 10992 } |
9766 | 10993 |
9767 | 10994 |
9768 THREADED_TEST(ConstructorForObject) { | 10995 THREADED_TEST(ConstructorForObject) { |
9769 LocalContext context; | 10996 LocalContext context; |
9770 v8::Isolate* isolate = context->GetIsolate(); | 10997 v8::Isolate* isolate = context->GetIsolate(); |
9771 v8::HandleScope handle_scope(isolate); | 10998 v8::HandleScope handle_scope(isolate); |
9772 | 10999 |
9773 { | 11000 { |
9774 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11001 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
9775 instance_template->SetCallAsFunctionHandler(ConstructorCallback); | 11002 instance_template->SetCallAsFunctionHandler(ConstructorCallback); |
9776 Local<Object> instance = instance_template->NewInstance(); | 11003 Local<Object> instance = |
9777 context->Global()->Set(v8_str("obj"), instance); | 11004 instance_template->NewInstance(context.local()).ToLocalChecked(); |
11005 CHECK(context->Global() | |
11006 ->Set(context.local(), v8_str("obj"), instance) | |
11007 .FromJust()); | |
9778 v8::TryCatch try_catch(isolate); | 11008 v8::TryCatch try_catch(isolate); |
9779 Local<Value> value; | 11009 Local<Value> value; |
9780 CHECK(!try_catch.HasCaught()); | 11010 CHECK(!try_catch.HasCaught()); |
9781 | 11011 |
9782 // Call the Object's constructor with a 32-bit signed integer. | 11012 // Call the Object's constructor with a 32-bit signed integer. |
9783 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); | 11013 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); |
9784 CHECK(!try_catch.HasCaught()); | 11014 CHECK(!try_catch.HasCaught()); |
9785 CHECK(value->IsInt32()); | 11015 CHECK(value->IsInt32()); |
9786 CHECK_EQ(28, value->Int32Value()); | 11016 CHECK_EQ(28, value->Int32Value(context.local()).FromJust()); |
9787 | 11017 |
9788 Local<Value> args1[] = {v8_num(28)}; | 11018 Local<Value> args1[] = {v8_num(28)}; |
9789 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1); | 11019 Local<Value> value_obj1 = |
11020 instance->CallAsConstructor(context.local(), 1, args1).ToLocalChecked(); | |
9790 CHECK(value_obj1->IsObject()); | 11021 CHECK(value_obj1->IsObject()); |
9791 Local<Object> object1 = Local<Object>::Cast(value_obj1); | 11022 Local<Object> object1 = Local<Object>::Cast(value_obj1); |
9792 value = object1->Get(v8_str("a")); | 11023 value = object1->Get(context.local(), v8_str("a")).ToLocalChecked(); |
9793 CHECK(value->IsInt32()); | 11024 CHECK(value->IsInt32()); |
9794 CHECK(!try_catch.HasCaught()); | 11025 CHECK(!try_catch.HasCaught()); |
9795 CHECK_EQ(28, value->Int32Value()); | 11026 CHECK_EQ(28, value->Int32Value(context.local()).FromJust()); |
9796 | 11027 |
9797 // Call the Object's constructor with a String. | 11028 // Call the Object's constructor with a String. |
9798 value = | 11029 value = |
9799 CompileRun("(function() { var o = new obj('tipli'); return o.a; })()"); | 11030 CompileRun("(function() { var o = new obj('tipli'); return o.a; })()"); |
9800 CHECK(!try_catch.HasCaught()); | 11031 CHECK(!try_catch.HasCaught()); |
9801 CHECK(value->IsString()); | 11032 CHECK(value->IsString()); |
9802 String::Utf8Value string_value1(value->ToString(isolate)); | 11033 String::Utf8Value string_value1( |
11034 value->ToString(context.local()).ToLocalChecked()); | |
9803 CHECK_EQ(0, strcmp("tipli", *string_value1)); | 11035 CHECK_EQ(0, strcmp("tipli", *string_value1)); |
9804 | 11036 |
9805 Local<Value> args2[] = {v8_str("tipli")}; | 11037 Local<Value> args2[] = {v8_str("tipli")}; |
9806 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2); | 11038 Local<Value> value_obj2 = |
11039 instance->CallAsConstructor(context.local(), 1, args2).ToLocalChecked(); | |
9807 CHECK(value_obj2->IsObject()); | 11040 CHECK(value_obj2->IsObject()); |
9808 Local<Object> object2 = Local<Object>::Cast(value_obj2); | 11041 Local<Object> object2 = Local<Object>::Cast(value_obj2); |
9809 value = object2->Get(v8_str("a")); | 11042 value = object2->Get(context.local(), v8_str("a")).ToLocalChecked(); |
9810 CHECK(!try_catch.HasCaught()); | 11043 CHECK(!try_catch.HasCaught()); |
9811 CHECK(value->IsString()); | 11044 CHECK(value->IsString()); |
9812 String::Utf8Value string_value2(value->ToString(isolate)); | 11045 String::Utf8Value string_value2( |
11046 value->ToString(context.local()).ToLocalChecked()); | |
9813 CHECK_EQ(0, strcmp("tipli", *string_value2)); | 11047 CHECK_EQ(0, strcmp("tipli", *string_value2)); |
9814 | 11048 |
9815 // Call the Object's constructor with a Boolean. | 11049 // Call the Object's constructor with a Boolean. |
9816 value = CompileRun("(function() { var o = new obj(true); return o.a; })()"); | 11050 value = CompileRun("(function() { var o = new obj(true); return o.a; })()"); |
9817 CHECK(!try_catch.HasCaught()); | 11051 CHECK(!try_catch.HasCaught()); |
9818 CHECK(value->IsBoolean()); | 11052 CHECK(value->IsBoolean()); |
9819 CHECK_EQ(true, value->BooleanValue()); | 11053 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); |
9820 | 11054 |
9821 Handle<Value> args3[] = {v8::True(isolate)}; | 11055 Local<Value> args3[] = {v8::True(isolate)}; |
9822 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3); | 11056 Local<Value> value_obj3 = |
11057 instance->CallAsConstructor(context.local(), 1, args3).ToLocalChecked(); | |
9823 CHECK(value_obj3->IsObject()); | 11058 CHECK(value_obj3->IsObject()); |
9824 Local<Object> object3 = Local<Object>::Cast(value_obj3); | 11059 Local<Object> object3 = Local<Object>::Cast(value_obj3); |
9825 value = object3->Get(v8_str("a")); | 11060 value = object3->Get(context.local(), v8_str("a")).ToLocalChecked(); |
9826 CHECK(!try_catch.HasCaught()); | 11061 CHECK(!try_catch.HasCaught()); |
9827 CHECK(value->IsBoolean()); | 11062 CHECK(value->IsBoolean()); |
9828 CHECK_EQ(true, value->BooleanValue()); | 11063 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust()); |
9829 | 11064 |
9830 // Call the Object's constructor with undefined. | 11065 // Call the Object's constructor with undefined. |
9831 Handle<Value> args4[] = {v8::Undefined(isolate)}; | 11066 Local<Value> args4[] = {v8::Undefined(isolate)}; |
9832 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4); | 11067 Local<Value> value_obj4 = |
11068 instance->CallAsConstructor(context.local(), 1, args4).ToLocalChecked(); | |
9833 CHECK(value_obj4->IsObject()); | 11069 CHECK(value_obj4->IsObject()); |
9834 Local<Object> object4 = Local<Object>::Cast(value_obj4); | 11070 Local<Object> object4 = Local<Object>::Cast(value_obj4); |
9835 value = object4->Get(v8_str("a")); | 11071 value = object4->Get(context.local(), v8_str("a")).ToLocalChecked(); |
9836 CHECK(!try_catch.HasCaught()); | 11072 CHECK(!try_catch.HasCaught()); |
9837 CHECK(value->IsUndefined()); | 11073 CHECK(value->IsUndefined()); |
9838 | 11074 |
9839 // Call the Object's constructor with null. | 11075 // Call the Object's constructor with null. |
9840 Handle<Value> args5[] = {v8::Null(isolate)}; | 11076 Local<Value> args5[] = {v8::Null(isolate)}; |
9841 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5); | 11077 Local<Value> value_obj5 = |
11078 instance->CallAsConstructor(context.local(), 1, args5).ToLocalChecked(); | |
9842 CHECK(value_obj5->IsObject()); | 11079 CHECK(value_obj5->IsObject()); |
9843 Local<Object> object5 = Local<Object>::Cast(value_obj5); | 11080 Local<Object> object5 = Local<Object>::Cast(value_obj5); |
9844 value = object5->Get(v8_str("a")); | 11081 value = object5->Get(context.local(), v8_str("a")).ToLocalChecked(); |
9845 CHECK(!try_catch.HasCaught()); | 11082 CHECK(!try_catch.HasCaught()); |
9846 CHECK(value->IsNull()); | 11083 CHECK(value->IsNull()); |
9847 } | 11084 } |
9848 | 11085 |
9849 // Check exception handling when there is no constructor set for the Object. | 11086 // Check exception handling when there is no constructor set for the Object. |
9850 { | 11087 { |
9851 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11088 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
9852 Local<Object> instance = instance_template->NewInstance(); | 11089 Local<Object> instance = |
9853 context->Global()->Set(v8_str("obj2"), instance); | 11090 instance_template->NewInstance(context.local()).ToLocalChecked(); |
11091 CHECK(context->Global() | |
11092 ->Set(context.local(), v8_str("obj2"), instance) | |
11093 .FromJust()); | |
9854 v8::TryCatch try_catch(isolate); | 11094 v8::TryCatch try_catch(isolate); |
9855 Local<Value> value; | 11095 Local<Value> value; |
9856 CHECK(!try_catch.HasCaught()); | 11096 CHECK(!try_catch.HasCaught()); |
9857 | 11097 |
9858 value = CompileRun("new obj2(28)"); | 11098 value = CompileRun("new obj2(28)"); |
9859 CHECK(try_catch.HasCaught()); | 11099 CHECK(try_catch.HasCaught()); |
9860 String::Utf8Value exception_value1(try_catch.Exception()); | 11100 String::Utf8Value exception_value1(try_catch.Exception()); |
9861 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); | 11101 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); |
9862 try_catch.Reset(); | 11102 try_catch.Reset(); |
9863 | 11103 |
9864 Local<Value> args[] = {v8_num(29)}; | 11104 Local<Value> args[] = {v8_num(29)}; |
9865 value = instance->CallAsConstructor(1, args); | 11105 CHECK(instance->CallAsConstructor(context.local(), 1, args).IsEmpty()); |
9866 CHECK(try_catch.HasCaught()); | 11106 CHECK(try_catch.HasCaught()); |
9867 String::Utf8Value exception_value2(try_catch.Exception()); | 11107 String::Utf8Value exception_value2(try_catch.Exception()); |
9868 CHECK_EQ(0, | 11108 CHECK_EQ(0, |
9869 strcmp("TypeError: object is not a function", *exception_value2)); | 11109 strcmp("TypeError: object is not a function", *exception_value2)); |
9870 try_catch.Reset(); | 11110 try_catch.Reset(); |
9871 } | 11111 } |
9872 | 11112 |
9873 // Check the case when constructor throws exception. | 11113 // Check the case when constructor throws exception. |
9874 { | 11114 { |
9875 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11115 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
9876 instance_template->SetCallAsFunctionHandler(ThrowValue); | 11116 instance_template->SetCallAsFunctionHandler(ThrowValue); |
9877 Local<Object> instance = instance_template->NewInstance(); | 11117 Local<Object> instance = |
9878 context->Global()->Set(v8_str("obj3"), instance); | 11118 instance_template->NewInstance(context.local()).ToLocalChecked(); |
11119 CHECK(context->Global() | |
11120 ->Set(context.local(), v8_str("obj3"), instance) | |
11121 .FromJust()); | |
9879 v8::TryCatch try_catch(isolate); | 11122 v8::TryCatch try_catch(isolate); |
9880 Local<Value> value; | 11123 Local<Value> value; |
9881 CHECK(!try_catch.HasCaught()); | 11124 CHECK(!try_catch.HasCaught()); |
9882 | 11125 |
9883 value = CompileRun("new obj3(22)"); | 11126 value = CompileRun("new obj3(22)"); |
9884 CHECK(try_catch.HasCaught()); | 11127 CHECK(try_catch.HasCaught()); |
9885 String::Utf8Value exception_value1(try_catch.Exception()); | 11128 String::Utf8Value exception_value1(try_catch.Exception()); |
9886 CHECK_EQ(0, strcmp("22", *exception_value1)); | 11129 CHECK_EQ(0, strcmp("22", *exception_value1)); |
9887 try_catch.Reset(); | 11130 try_catch.Reset(); |
9888 | 11131 |
9889 Local<Value> args[] = {v8_num(23)}; | 11132 Local<Value> args[] = {v8_num(23)}; |
9890 value = instance->CallAsConstructor(1, args); | 11133 CHECK(instance->CallAsConstructor(context.local(), 1, args).IsEmpty()); |
9891 CHECK(try_catch.HasCaught()); | 11134 CHECK(try_catch.HasCaught()); |
9892 String::Utf8Value exception_value2(try_catch.Exception()); | 11135 String::Utf8Value exception_value2(try_catch.Exception()); |
9893 CHECK_EQ(0, strcmp("23", *exception_value2)); | 11136 CHECK_EQ(0, strcmp("23", *exception_value2)); |
9894 try_catch.Reset(); | 11137 try_catch.Reset(); |
9895 } | 11138 } |
9896 | 11139 |
9897 // Check whether constructor returns with an object or non-object. | 11140 // Check whether constructor returns with an object or non-object. |
9898 { | 11141 { |
9899 Local<FunctionTemplate> function_template = | 11142 Local<FunctionTemplate> function_template = |
9900 FunctionTemplate::New(isolate, FakeConstructorCallback); | 11143 FunctionTemplate::New(isolate, FakeConstructorCallback); |
9901 Local<Function> function = function_template->GetFunction(); | 11144 Local<Function> function = |
11145 function_template->GetFunction(context.local()).ToLocalChecked(); | |
9902 Local<Object> instance1 = function; | 11146 Local<Object> instance1 = function; |
9903 context->Global()->Set(v8_str("obj4"), instance1); | 11147 CHECK(context->Global() |
11148 ->Set(context.local(), v8_str("obj4"), instance1) | |
11149 .FromJust()); | |
9904 v8::TryCatch try_catch(isolate); | 11150 v8::TryCatch try_catch(isolate); |
9905 Local<Value> value; | 11151 Local<Value> value; |
9906 CHECK(!try_catch.HasCaught()); | 11152 CHECK(!try_catch.HasCaught()); |
9907 | 11153 |
9908 CHECK(instance1->IsObject()); | 11154 CHECK(instance1->IsObject()); |
9909 CHECK(instance1->IsFunction()); | 11155 CHECK(instance1->IsFunction()); |
9910 | 11156 |
9911 value = CompileRun("new obj4(28)"); | 11157 value = CompileRun("new obj4(28)"); |
9912 CHECK(!try_catch.HasCaught()); | 11158 CHECK(!try_catch.HasCaught()); |
9913 CHECK(value->IsObject()); | 11159 CHECK(value->IsObject()); |
9914 | 11160 |
9915 Local<Value> args1[] = {v8_num(28)}; | 11161 Local<Value> args1[] = {v8_num(28)}; |
9916 value = instance1->CallAsConstructor(1, args1); | 11162 value = instance1->CallAsConstructor(context.local(), 1, args1) |
11163 .ToLocalChecked(); | |
9917 CHECK(!try_catch.HasCaught()); | 11164 CHECK(!try_catch.HasCaught()); |
9918 CHECK(value->IsObject()); | 11165 CHECK(value->IsObject()); |
9919 | 11166 |
9920 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11167 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
9921 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); | 11168 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); |
9922 Local<Object> instance2 = instance_template->NewInstance(); | 11169 Local<Object> instance2 = |
9923 context->Global()->Set(v8_str("obj5"), instance2); | 11170 instance_template->NewInstance(context.local()).ToLocalChecked(); |
11171 CHECK(context->Global() | |
11172 ->Set(context.local(), v8_str("obj5"), instance2) | |
11173 .FromJust()); | |
9924 CHECK(!try_catch.HasCaught()); | 11174 CHECK(!try_catch.HasCaught()); |
9925 | 11175 |
9926 CHECK(instance2->IsObject()); | 11176 CHECK(instance2->IsObject()); |
9927 CHECK(instance2->IsFunction()); | 11177 CHECK(instance2->IsFunction()); |
9928 | 11178 |
9929 value = CompileRun("new obj5(28)"); | 11179 value = CompileRun("new obj5(28)"); |
9930 CHECK(!try_catch.HasCaught()); | 11180 CHECK(!try_catch.HasCaught()); |
9931 CHECK(!value->IsObject()); | 11181 CHECK(!value->IsObject()); |
9932 | 11182 |
9933 Local<Value> args2[] = {v8_num(28)}; | 11183 Local<Value> args2[] = {v8_num(28)}; |
9934 value = instance2->CallAsConstructor(1, args2); | 11184 value = instance2->CallAsConstructor(context.local(), 1, args2) |
11185 .ToLocalChecked(); | |
9935 CHECK(!try_catch.HasCaught()); | 11186 CHECK(!try_catch.HasCaught()); |
9936 CHECK(!value->IsObject()); | 11187 CHECK(!value->IsObject()); |
9937 } | 11188 } |
9938 } | 11189 } |
9939 | 11190 |
9940 | 11191 |
9941 THREADED_TEST(FunctionDescriptorException) { | 11192 THREADED_TEST(FunctionDescriptorException) { |
9942 LocalContext context; | 11193 LocalContext context; |
9943 v8::Isolate* isolate = context->GetIsolate(); | 11194 v8::Isolate* isolate = context->GetIsolate(); |
9944 v8::HandleScope handle_scope(isolate); | 11195 v8::HandleScope handle_scope(isolate); |
9945 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 11196 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
9946 templ->SetClassName(v8_str("Fun")); | 11197 templ->SetClassName(v8_str("Fun")); |
9947 Local<Function> cons = templ->GetFunction(); | 11198 Local<Function> cons = templ->GetFunction(context.local()).ToLocalChecked(); |
9948 context->Global()->Set(v8_str("Fun"), cons); | 11199 CHECK( |
11200 context->Global()->Set(context.local(), v8_str("Fun"), cons).FromJust()); | |
9949 Local<Value> value = CompileRun( | 11201 Local<Value> value = CompileRun( |
9950 "function test() {" | 11202 "function test() {" |
9951 " try {" | 11203 " try {" |
9952 " (new Fun()).blah()" | 11204 " (new Fun()).blah()" |
9953 " } catch (e) {" | 11205 " } catch (e) {" |
9954 " var str = String(e);" | 11206 " var str = String(e);" |
9955 // " if (str.indexOf('TypeError') == -1) return 1;" | 11207 // " if (str.indexOf('TypeError') == -1) return 1;" |
9956 // " if (str.indexOf('[object Fun]') != -1) return 2;" | 11208 // " if (str.indexOf('[object Fun]') != -1) return 2;" |
9957 // " if (str.indexOf('#<Fun>') == -1) return 3;" | 11209 // " if (str.indexOf('#<Fun>') == -1) return 3;" |
9958 " return 0;" | 11210 " return 0;" |
9959 " }" | 11211 " }" |
9960 " return 4;" | 11212 " return 4;" |
9961 "}" | 11213 "}" |
9962 "test();"); | 11214 "test();"); |
9963 CHECK_EQ(0, value->Int32Value()); | 11215 CHECK_EQ(0, value->Int32Value(context.local()).FromJust()); |
9964 } | 11216 } |
9965 | 11217 |
9966 | 11218 |
9967 THREADED_TEST(EvalAliasedDynamic) { | 11219 THREADED_TEST(EvalAliasedDynamic) { |
9968 LocalContext current; | 11220 LocalContext current; |
9969 v8::HandleScope scope(current->GetIsolate()); | 11221 v8::HandleScope scope(current->GetIsolate()); |
9970 | 11222 |
9971 // Tests where aliased eval can only be resolved dynamically. | 11223 // Tests where aliased eval can only be resolved dynamically. |
9972 Local<Script> script = v8_compile( | 11224 Local<Script> script = v8_compile( |
9973 "function f(x) { " | 11225 "function f(x) { " |
9974 " var foo = 2;" | 11226 " var foo = 2;" |
9975 " with (x) { return eval('foo'); }" | 11227 " with (x) { return eval('foo'); }" |
9976 "}" | 11228 "}" |
9977 "foo = 0;" | 11229 "foo = 0;" |
9978 "result1 = f(new Object());" | 11230 "result1 = f(new Object());" |
9979 "result2 = f(this);" | 11231 "result2 = f(this);" |
9980 "var x = new Object();" | 11232 "var x = new Object();" |
9981 "x.eval = function(x) { return 1; };" | 11233 "x.eval = function(x) { return 1; };" |
9982 "result3 = f(x);"); | 11234 "result3 = f(x);"); |
9983 script->Run(); | 11235 script->Run(current.local()).ToLocalChecked(); |
9984 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); | 11236 CHECK_EQ(2, current->Global() |
9985 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); | 11237 ->Get(current.local(), v8_str("result1")) |
9986 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); | 11238 .ToLocalChecked() |
11239 ->Int32Value(current.local()) | |
11240 .FromJust()); | |
11241 CHECK_EQ(0, current->Global() | |
11242 ->Get(current.local(), v8_str("result2")) | |
11243 .ToLocalChecked() | |
11244 ->Int32Value(current.local()) | |
11245 .FromJust()); | |
11246 CHECK_EQ(1, current->Global() | |
11247 ->Get(current.local(), v8_str("result3")) | |
11248 .ToLocalChecked() | |
11249 ->Int32Value(current.local()) | |
11250 .FromJust()); | |
9987 | 11251 |
9988 v8::TryCatch try_catch(current->GetIsolate()); | 11252 v8::TryCatch try_catch(current->GetIsolate()); |
9989 script = v8_compile( | 11253 script = v8_compile( |
9990 "function f(x) { " | 11254 "function f(x) { " |
9991 " var bar = 2;" | 11255 " var bar = 2;" |
9992 " with (x) { return eval('bar'); }" | 11256 " with (x) { return eval('bar'); }" |
9993 "}" | 11257 "}" |
9994 "result4 = f(this)"); | 11258 "result4 = f(this)"); |
9995 script->Run(); | 11259 script->Run(current.local()).ToLocalChecked(); |
9996 CHECK(!try_catch.HasCaught()); | 11260 CHECK(!try_catch.HasCaught()); |
9997 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); | 11261 CHECK_EQ(2, current->Global() |
11262 ->Get(current.local(), v8_str("result4")) | |
11263 .ToLocalChecked() | |
11264 ->Int32Value(current.local()) | |
11265 .FromJust()); | |
9998 | 11266 |
9999 try_catch.Reset(); | 11267 try_catch.Reset(); |
10000 } | 11268 } |
10001 | 11269 |
10002 | 11270 |
10003 THREADED_TEST(CrossEval) { | 11271 THREADED_TEST(CrossEval) { |
10004 v8::HandleScope scope(CcTest::isolate()); | 11272 v8::HandleScope scope(CcTest::isolate()); |
10005 LocalContext other; | 11273 LocalContext other; |
10006 LocalContext current; | 11274 LocalContext current; |
10007 | 11275 |
10008 Local<String> token = v8_str("<security token>"); | 11276 Local<String> token = v8_str("<security token>"); |
10009 other->SetSecurityToken(token); | 11277 other->SetSecurityToken(token); |
10010 current->SetSecurityToken(token); | 11278 current->SetSecurityToken(token); |
10011 | 11279 |
10012 // Set up reference from current to other. | 11280 // Set up reference from current to other. |
10013 current->Global()->Set(v8_str("other"), other->Global()); | 11281 CHECK(current->Global() |
11282 ->Set(current.local(), v8_str("other"), other->Global()) | |
11283 .FromJust()); | |
10014 | 11284 |
10015 // Check that new variables are introduced in other context. | 11285 // Check that new variables are introduced in other context. |
10016 Local<Script> script = v8_compile("other.eval('var foo = 1234')"); | 11286 Local<Script> script = v8_compile("other.eval('var foo = 1234')"); |
10017 script->Run(); | 11287 script->Run(current.local()).ToLocalChecked(); |
10018 Local<Value> foo = other->Global()->Get(v8_str("foo")); | 11288 Local<Value> foo = other->Global()->Get(v8_str("foo")); |
10019 CHECK_EQ(1234, foo->Int32Value()); | 11289 CHECK_EQ(1234, foo->Int32Value(other.local()).FromJust()); |
10020 CHECK(!current->Global()->Has(v8_str("foo"))); | 11290 CHECK(!current->Global()->Has(v8_str("foo"))); |
10021 | 11291 |
10022 // Check that writing to non-existing properties introduces them in | 11292 // Check that writing to non-existing properties introduces them in |
10023 // the other context. | 11293 // the other context. |
10024 script = v8_compile("other.eval('na = 1234')"); | 11294 script = v8_compile("other.eval('na = 1234')"); |
10025 script->Run(); | 11295 script->Run(); |
10026 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value()); | 11296 CHECK_EQ( |
11297 1234, | |
11298 other->Global()->Get(v8_str("na"))->Int32Value(other.local()).FromJust()); | |
10027 CHECK(!current->Global()->Has(v8_str("na"))); | 11299 CHECK(!current->Global()->Has(v8_str("na"))); |
10028 | 11300 |
10029 // Check that global variables in current context are not visible in other | 11301 // Check that global variables in current context are not visible in other |
10030 // context. | 11302 // context. |
10031 v8::TryCatch try_catch(CcTest::isolate()); | 11303 v8::TryCatch try_catch(CcTest::isolate()); |
10032 script = v8_compile("var bar = 42; other.eval('bar');"); | 11304 script = v8_compile("var bar = 42; other.eval('bar');"); |
10033 Local<Value> result = script->Run(); | 11305 Local<Value> result = script->Run(); |
10034 CHECK(try_catch.HasCaught()); | 11306 CHECK(try_catch.HasCaught()); |
10035 try_catch.Reset(); | 11307 try_catch.Reset(); |
10036 | 11308 |
10037 // Check that local variables in current context are not visible in other | 11309 // Check that local variables in current context are not visible in other |
10038 // context. | 11310 // context. |
10039 script = v8_compile( | 11311 script = v8_compile( |
10040 "(function() { " | 11312 "(function() { " |
10041 " var baz = 87;" | 11313 " var baz = 87;" |
10042 " return other.eval('baz');" | 11314 " return other.eval('baz');" |
10043 "})();"); | 11315 "})();"); |
10044 result = script->Run(); | 11316 result = script->Run(); |
10045 CHECK(try_catch.HasCaught()); | 11317 CHECK(try_catch.HasCaught()); |
10046 try_catch.Reset(); | 11318 try_catch.Reset(); |
10047 | 11319 |
10048 // Check that global variables in the other environment are visible | 11320 // Check that global variables in the other environment are visible |
10049 // when evaluting code. | 11321 // when evaluting code. |
10050 other->Global()->Set(v8_str("bis"), v8_num(1234)); | 11322 CHECK(other->Global() |
11323 ->Set(other.local(), v8_str("bis"), v8_num(1234)) | |
11324 .FromJust()); | |
10051 script = v8_compile("other.eval('bis')"); | 11325 script = v8_compile("other.eval('bis')"); |
10052 CHECK_EQ(1234, script->Run()->Int32Value()); | 11326 CHECK_EQ(1234, script->Run()->Int32Value(other.local()).FromJust()); |
10053 CHECK(!try_catch.HasCaught()); | 11327 CHECK(!try_catch.HasCaught()); |
10054 | 11328 |
10055 // Check that the 'this' pointer points to the global object evaluating | 11329 // Check that the 'this' pointer points to the global object evaluating |
10056 // code. | 11330 // code. |
10057 other->Global()->Set(v8_str("t"), other->Global()); | 11331 CHECK(other->Global() |
11332 ->Set(other.local(), v8_str("t"), other->Global()) | |
11333 .FromJust()); | |
10058 script = v8_compile("other.eval('this == t')"); | 11334 script = v8_compile("other.eval('this == t')"); |
10059 result = script->Run(); | 11335 result = script->Run(); |
10060 CHECK(result->IsTrue()); | 11336 CHECK(result->IsTrue()); |
10061 CHECK(!try_catch.HasCaught()); | 11337 CHECK(!try_catch.HasCaught()); |
10062 | 11338 |
10063 // Check that variables introduced in with-statement are not visible in | 11339 // Check that variables introduced in with-statement are not visible in |
10064 // other context. | 11340 // other context. |
10065 script = v8_compile("with({x:2}){other.eval('x')}"); | 11341 script = v8_compile("with({x:2}){other.eval('x')}"); |
10066 result = script->Run(); | 11342 result = script->Run(); |
10067 CHECK(try_catch.HasCaught()); | 11343 CHECK(try_catch.HasCaught()); |
(...skipping 11 matching lines...) Expand all Loading... | |
10079 // its global proxy works. | 11355 // its global proxy works. |
10080 THREADED_TEST(EvalInDetachedGlobal) { | 11356 THREADED_TEST(EvalInDetachedGlobal) { |
10081 v8::Isolate* isolate = CcTest::isolate(); | 11357 v8::Isolate* isolate = CcTest::isolate(); |
10082 v8::HandleScope scope(isolate); | 11358 v8::HandleScope scope(isolate); |
10083 | 11359 |
10084 v8::Local<Context> context0 = Context::New(isolate); | 11360 v8::Local<Context> context0 = Context::New(isolate); |
10085 v8::Local<Context> context1 = Context::New(isolate); | 11361 v8::Local<Context> context1 = Context::New(isolate); |
10086 | 11362 |
10087 // Set up function in context0 that uses eval from context0. | 11363 // Set up function in context0 that uses eval from context0. |
10088 context0->Enter(); | 11364 context0->Enter(); |
10089 v8::Handle<v8::Value> fun = CompileRun( | 11365 v8::Local<v8::Value> fun = CompileRun( |
10090 "var x = 42;" | 11366 "var x = 42;" |
10091 "(function() {" | 11367 "(function() {" |
10092 " var e = eval;" | 11368 " var e = eval;" |
10093 " return function(s) { return e(s); }" | 11369 " return function(s) { return e(s); }" |
10094 "})()"); | 11370 "})()"); |
10095 context0->Exit(); | 11371 context0->Exit(); |
10096 | 11372 |
10097 // Put the function into context1 and call it before and after | 11373 // Put the function into context1 and call it before and after |
10098 // detaching the global. Before detaching, the call succeeds and | 11374 // detaching the global. Before detaching, the call succeeds and |
10099 // after detaching and exception is thrown. | 11375 // after detaching and exception is thrown. |
10100 context1->Enter(); | 11376 context1->Enter(); |
10101 context1->Global()->Set(v8_str("fun"), fun); | 11377 CHECK(context1->Global()->Set(context1, v8_str("fun"), fun).FromJust()); |
10102 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); | 11378 v8::Local<v8::Value> x_value = CompileRun("fun('x')"); |
10103 CHECK_EQ(42, x_value->Int32Value()); | 11379 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
10104 context0->DetachGlobal(); | 11380 context0->DetachGlobal(); |
10105 v8::TryCatch catcher(isolate); | 11381 v8::TryCatch catcher(isolate); |
10106 x_value = CompileRun("fun('x')"); | 11382 x_value = CompileRun("fun('x')"); |
10107 CHECK_EQ(42, x_value->Int32Value()); | 11383 CHECK_EQ(42, x_value->Int32Value(context1).FromJust()); |
10108 context1->Exit(); | 11384 context1->Exit(); |
10109 } | 11385 } |
10110 | 11386 |
10111 | 11387 |
10112 THREADED_TEST(CrossLazyLoad) { | 11388 THREADED_TEST(CrossLazyLoad) { |
10113 v8::HandleScope scope(CcTest::isolate()); | 11389 v8::HandleScope scope(CcTest::isolate()); |
10114 LocalContext other; | 11390 LocalContext other; |
10115 LocalContext current; | 11391 LocalContext current; |
10116 | 11392 |
10117 Local<String> token = v8_str("<security token>"); | 11393 Local<String> token = v8_str("<security token>"); |
10118 other->SetSecurityToken(token); | 11394 other->SetSecurityToken(token); |
10119 current->SetSecurityToken(token); | 11395 current->SetSecurityToken(token); |
10120 | 11396 |
10121 // Set up reference from current to other. | 11397 // Set up reference from current to other. |
10122 current->Global()->Set(v8_str("other"), other->Global()); | 11398 CHECK(current->Global() |
11399 ->Set(current.local(), v8_str("other"), other->Global()) | |
11400 .FromJust()); | |
10123 | 11401 |
10124 // Trigger lazy loading in other context. | 11402 // Trigger lazy loading in other context. |
10125 Local<Script> script = v8_compile("other.eval('new Date(42)')"); | 11403 Local<Script> script = v8_compile("other.eval('new Date(42)')"); |
10126 Local<Value> value = script->Run(); | 11404 Local<Value> value = script->Run(); |
10127 CHECK_EQ(42.0, value->NumberValue()); | 11405 CHECK_EQ(42.0, value->NumberValue()); |
10128 } | 11406 } |
10129 | 11407 |
10130 | 11408 |
10131 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { | 11409 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { |
10132 ApiTestFuzzer::Fuzz(); | 11410 ApiTestFuzzer::Fuzz(); |
10133 if (args.IsConstructCall()) { | 11411 if (args.IsConstructCall()) { |
10134 if (args[0]->IsInt32()) { | 11412 if (args[0]->IsInt32()) { |
10135 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); | 11413 args.GetReturnValue().Set( |
11414 v8_num(-args[0] | |
11415 ->Int32Value(args.GetIsolate()->GetCurrentContext()) | |
11416 .FromJust())); | |
10136 return; | 11417 return; |
10137 } | 11418 } |
10138 } | 11419 } |
10139 | 11420 |
10140 args.GetReturnValue().Set(args[0]); | 11421 args.GetReturnValue().Set(args[0]); |
10141 } | 11422 } |
10142 | 11423 |
10143 | 11424 |
10144 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { | 11425 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { |
10145 args.GetReturnValue().Set(args.This()); | 11426 args.GetReturnValue().Set(args.This()); |
10146 } | 11427 } |
10147 | 11428 |
10148 | 11429 |
10149 // Test that a call handler can be set for objects which will allow | 11430 // Test that a call handler can be set for objects which will allow |
10150 // non-function objects created through the API to be called as | 11431 // non-function objects created through the API to be called as |
10151 // functions. | 11432 // functions. |
10152 THREADED_TEST(CallAsFunction) { | 11433 THREADED_TEST(CallAsFunction) { |
10153 LocalContext context; | 11434 LocalContext context; |
10154 v8::Isolate* isolate = context->GetIsolate(); | 11435 v8::Isolate* isolate = context->GetIsolate(); |
10155 v8::HandleScope scope(isolate); | 11436 v8::HandleScope scope(isolate); |
10156 | 11437 |
10157 { | 11438 { |
10158 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 11439 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10159 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 11440 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
10160 instance_template->SetCallAsFunctionHandler(call_as_function); | 11441 instance_template->SetCallAsFunctionHandler(call_as_function); |
10161 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 11442 Local<v8::Object> instance = t->GetFunction(context.local()) |
10162 context->Global()->Set(v8_str("obj"), instance); | 11443 .ToLocalChecked() |
11444 ->NewInstance(context.local()) | |
11445 .ToLocalChecked(); | |
11446 CHECK(context->Global() | |
11447 ->Set(context.local(), v8_str("obj"), instance) | |
11448 .FromJust()); | |
10163 v8::TryCatch try_catch(isolate); | 11449 v8::TryCatch try_catch(isolate); |
10164 Local<Value> value; | 11450 Local<Value> value; |
10165 CHECK(!try_catch.HasCaught()); | 11451 CHECK(!try_catch.HasCaught()); |
10166 | 11452 |
10167 value = CompileRun("obj(42)"); | 11453 value = CompileRun("obj(42)"); |
10168 CHECK(!try_catch.HasCaught()); | 11454 CHECK(!try_catch.HasCaught()); |
10169 CHECK_EQ(42, value->Int32Value()); | 11455 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
10170 | 11456 |
10171 value = CompileRun("(function(o){return o(49)})(obj)"); | 11457 value = CompileRun("(function(o){return o(49)})(obj)"); |
10172 CHECK(!try_catch.HasCaught()); | 11458 CHECK(!try_catch.HasCaught()); |
10173 CHECK_EQ(49, value->Int32Value()); | 11459 CHECK_EQ(49, value->Int32Value(context.local()).FromJust()); |
10174 | 11460 |
10175 // test special case of call as function | 11461 // test special case of call as function |
10176 value = CompileRun("[obj]['0'](45)"); | 11462 value = CompileRun("[obj]['0'](45)"); |
10177 CHECK(!try_catch.HasCaught()); | 11463 CHECK(!try_catch.HasCaught()); |
10178 CHECK_EQ(45, value->Int32Value()); | 11464 CHECK_EQ(45, value->Int32Value(context.local()).FromJust()); |
10179 | 11465 |
10180 value = CompileRun( | 11466 value = CompileRun( |
10181 "obj.call = Function.prototype.call;" | 11467 "obj.call = Function.prototype.call;" |
10182 "obj.call(null, 87)"); | 11468 "obj.call(null, 87)"); |
10183 CHECK(!try_catch.HasCaught()); | 11469 CHECK(!try_catch.HasCaught()); |
10184 CHECK_EQ(87, value->Int32Value()); | 11470 CHECK_EQ(87, value->Int32Value(context.local()).FromJust()); |
10185 | 11471 |
10186 // Regression tests for bug #1116356: Calling call through call/apply | 11472 // Regression tests for bug #1116356: Calling call through call/apply |
10187 // must work for non-function receivers. | 11473 // must work for non-function receivers. |
10188 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; | 11474 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; |
10189 value = CompileRun(apply_99); | 11475 value = CompileRun(apply_99); |
10190 CHECK(!try_catch.HasCaught()); | 11476 CHECK(!try_catch.HasCaught()); |
10191 CHECK_EQ(99, value->Int32Value()); | 11477 CHECK_EQ(99, value->Int32Value(context.local()).FromJust()); |
10192 | 11478 |
10193 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; | 11479 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; |
10194 value = CompileRun(call_17); | 11480 value = CompileRun(call_17); |
10195 CHECK(!try_catch.HasCaught()); | 11481 CHECK(!try_catch.HasCaught()); |
10196 CHECK_EQ(17, value->Int32Value()); | 11482 CHECK_EQ(17, value->Int32Value(context.local()).FromJust()); |
10197 | 11483 |
10198 // Check that the call-as-function handler can be called through | 11484 // Check that the call-as-function handler can be called through |
10199 // new. | 11485 // new. |
10200 value = CompileRun("new obj(43)"); | 11486 value = CompileRun("new obj(43)"); |
10201 CHECK(!try_catch.HasCaught()); | 11487 CHECK(!try_catch.HasCaught()); |
10202 CHECK_EQ(-43, value->Int32Value()); | 11488 CHECK_EQ(-43, value->Int32Value(context.local()).FromJust()); |
10203 | 11489 |
10204 // Check that the call-as-function handler can be called through | 11490 // Check that the call-as-function handler can be called through |
10205 // the API. | 11491 // the API. |
10206 v8::Handle<Value> args[] = {v8_num(28)}; | 11492 v8::Local<Value> args[] = {v8_num(28)}; |
10207 value = instance->CallAsFunction(instance, 1, args); | 11493 value = instance->CallAsFunction(instance, 1, args); |
10208 CHECK(!try_catch.HasCaught()); | 11494 CHECK(!try_catch.HasCaught()); |
10209 CHECK_EQ(28, value->Int32Value()); | 11495 CHECK_EQ(28, value->Int32Value(context.local()).FromJust()); |
10210 } | 11496 } |
10211 | 11497 |
10212 { | 11498 { |
10213 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 11499 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10214 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); | 11500 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); |
10215 USE(instance_template); | 11501 USE(instance_template); |
10216 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 11502 Local<v8::Object> instance = t->GetFunction(context.local()) |
10217 context->Global()->Set(v8_str("obj2"), instance); | 11503 .ToLocalChecked() |
11504 ->NewInstance(context.local()) | |
11505 .ToLocalChecked(); | |
11506 CHECK(context->Global() | |
11507 ->Set(context.local(), v8_str("obj2"), instance) | |
11508 .FromJust()); | |
10218 v8::TryCatch try_catch(isolate); | 11509 v8::TryCatch try_catch(isolate); |
10219 Local<Value> value; | 11510 Local<Value> value; |
10220 CHECK(!try_catch.HasCaught()); | 11511 CHECK(!try_catch.HasCaught()); |
10221 | 11512 |
10222 // Call an object without call-as-function handler through the JS | 11513 // Call an object without call-as-function handler through the JS |
10223 value = CompileRun("obj2(28)"); | 11514 value = CompileRun("obj2(28)"); |
10224 CHECK(value.IsEmpty()); | 11515 CHECK(value.IsEmpty()); |
10225 CHECK(try_catch.HasCaught()); | 11516 CHECK(try_catch.HasCaught()); |
10226 String::Utf8Value exception_value1(try_catch.Exception()); | 11517 String::Utf8Value exception_value1(try_catch.Exception()); |
10227 // TODO(verwaest): Better message | 11518 // TODO(verwaest): Better message |
10228 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); | 11519 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); |
10229 try_catch.Reset(); | 11520 try_catch.Reset(); |
10230 | 11521 |
10231 // Call an object without call-as-function handler through the API | 11522 // Call an object without call-as-function handler through the API |
10232 value = CompileRun("obj2(28)"); | 11523 value = CompileRun("obj2(28)"); |
10233 v8::Handle<Value> args[] = {v8_num(28)}; | 11524 v8::Local<Value> args[] = {v8_num(28)}; |
10234 value = instance->CallAsFunction(instance, 1, args); | 11525 value = instance->CallAsFunction(instance, 1, args); |
10235 CHECK(value.IsEmpty()); | 11526 CHECK(value.IsEmpty()); |
10236 CHECK(try_catch.HasCaught()); | 11527 CHECK(try_catch.HasCaught()); |
10237 String::Utf8Value exception_value2(try_catch.Exception()); | 11528 String::Utf8Value exception_value2(try_catch.Exception()); |
10238 CHECK_EQ(0, | 11529 CHECK_EQ(0, |
10239 strcmp("TypeError: object is not a function", *exception_value2)); | 11530 strcmp("TypeError: object is not a function", *exception_value2)); |
10240 try_catch.Reset(); | 11531 try_catch.Reset(); |
10241 } | 11532 } |
10242 | 11533 |
10243 { | 11534 { |
10244 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 11535 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10245 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 11536 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
10246 instance_template->SetCallAsFunctionHandler(ThrowValue); | 11537 instance_template->SetCallAsFunctionHandler(ThrowValue); |
10247 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 11538 Local<v8::Object> instance = t->GetFunction(context.local()) |
10248 context->Global()->Set(v8_str("obj3"), instance); | 11539 .ToLocalChecked() |
11540 ->NewInstance(context.local()) | |
11541 .ToLocalChecked(); | |
11542 CHECK(context->Global() | |
11543 ->Set(context.local(), v8_str("obj3"), instance) | |
11544 .FromJust()); | |
10249 v8::TryCatch try_catch(isolate); | 11545 v8::TryCatch try_catch(isolate); |
10250 Local<Value> value; | 11546 Local<Value> value; |
10251 CHECK(!try_catch.HasCaught()); | 11547 CHECK(!try_catch.HasCaught()); |
10252 | 11548 |
10253 // Catch the exception which is thrown by call-as-function handler | 11549 // Catch the exception which is thrown by call-as-function handler |
10254 value = CompileRun("obj3(22)"); | 11550 value = CompileRun("obj3(22)"); |
10255 CHECK(try_catch.HasCaught()); | 11551 CHECK(try_catch.HasCaught()); |
10256 String::Utf8Value exception_value1(try_catch.Exception()); | 11552 String::Utf8Value exception_value1(try_catch.Exception()); |
10257 CHECK_EQ(0, strcmp("22", *exception_value1)); | 11553 CHECK_EQ(0, strcmp("22", *exception_value1)); |
10258 try_catch.Reset(); | 11554 try_catch.Reset(); |
10259 | 11555 |
10260 v8::Handle<Value> args[] = {v8_num(23)}; | 11556 v8::Local<Value> args[] = {v8_num(23)}; |
10261 value = instance->CallAsFunction(instance, 1, args); | 11557 value = instance->CallAsFunction(instance, 1, args); |
10262 CHECK(try_catch.HasCaught()); | 11558 CHECK(try_catch.HasCaught()); |
10263 String::Utf8Value exception_value2(try_catch.Exception()); | 11559 String::Utf8Value exception_value2(try_catch.Exception()); |
10264 CHECK_EQ(0, strcmp("23", *exception_value2)); | 11560 CHECK_EQ(0, strcmp("23", *exception_value2)); |
10265 try_catch.Reset(); | 11561 try_catch.Reset(); |
10266 } | 11562 } |
10267 | 11563 |
10268 { | 11564 { |
10269 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); | 11565 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); |
10270 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); | 11566 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); |
10271 instance_template->SetCallAsFunctionHandler(ReturnThis); | 11567 instance_template->SetCallAsFunctionHandler(ReturnThis); |
10272 Local<v8::Object> instance = t->GetFunction()->NewInstance(); | 11568 Local<v8::Object> instance = t->GetFunction(context.local()) |
11569 .ToLocalChecked() | |
11570 ->NewInstance(context.local()) | |
11571 .ToLocalChecked(); | |
10273 | 11572 |
10274 Local<v8::Value> a1 = | 11573 Local<v8::Value> a1 = |
10275 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); | 11574 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); |
10276 CHECK(a1->StrictEquals(instance)); | 11575 CHECK(a1->StrictEquals(instance)); |
10277 Local<v8::Value> a2 = instance->CallAsFunction(v8::Null(isolate), 0, NULL); | 11576 Local<v8::Value> a2 = instance->CallAsFunction(v8::Null(isolate), 0, NULL); |
10278 CHECK(a2->StrictEquals(instance)); | 11577 CHECK(a2->StrictEquals(instance)); |
10279 Local<v8::Value> a3 = instance->CallAsFunction(v8_num(42), 0, NULL); | 11578 Local<v8::Value> a3 = instance->CallAsFunction(v8_num(42), 0, NULL); |
10280 CHECK(a3->StrictEquals(instance)); | 11579 CHECK(a3->StrictEquals(instance)); |
10281 Local<v8::Value> a4 = instance->CallAsFunction(v8_str("hello"), 0, NULL); | 11580 Local<v8::Value> a4 = instance->CallAsFunction(v8_str("hello"), 0, NULL); |
10282 CHECK(a4->StrictEquals(instance)); | 11581 CHECK(a4->StrictEquals(instance)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10336 | 11635 |
10337 // Check whether a non-function object is callable. | 11636 // Check whether a non-function object is callable. |
10338 THREADED_TEST(CallableObject) { | 11637 THREADED_TEST(CallableObject) { |
10339 LocalContext context; | 11638 LocalContext context; |
10340 v8::Isolate* isolate = context->GetIsolate(); | 11639 v8::Isolate* isolate = context->GetIsolate(); |
10341 v8::HandleScope scope(isolate); | 11640 v8::HandleScope scope(isolate); |
10342 | 11641 |
10343 { | 11642 { |
10344 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11643 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10345 instance_template->SetCallAsFunctionHandler(call_as_function); | 11644 instance_template->SetCallAsFunctionHandler(call_as_function); |
10346 Local<Object> instance = instance_template->NewInstance(); | 11645 Local<Object> instance = |
11646 instance_template->NewInstance(context.local()).ToLocalChecked(); | |
10347 v8::TryCatch try_catch(isolate); | 11647 v8::TryCatch try_catch(isolate); |
10348 | 11648 |
10349 CHECK(instance->IsCallable()); | 11649 CHECK(instance->IsCallable()); |
10350 CHECK(!try_catch.HasCaught()); | 11650 CHECK(!try_catch.HasCaught()); |
10351 } | 11651 } |
10352 | 11652 |
10353 { | 11653 { |
10354 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); | 11654 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); |
10355 Local<Object> instance = instance_template->NewInstance(); | 11655 Local<Object> instance = |
11656 instance_template->NewInstance(context.local()).ToLocalChecked(); | |
10356 v8::TryCatch try_catch(isolate); | 11657 v8::TryCatch try_catch(isolate); |
10357 | 11658 |
10358 CHECK(!instance->IsCallable()); | 11659 CHECK(!instance->IsCallable()); |
10359 CHECK(!try_catch.HasCaught()); | 11660 CHECK(!try_catch.HasCaught()); |
10360 } | 11661 } |
10361 | 11662 |
10362 { | 11663 { |
10363 Local<FunctionTemplate> function_template = | 11664 Local<FunctionTemplate> function_template = |
10364 FunctionTemplate::New(isolate, call_as_function); | 11665 FunctionTemplate::New(isolate, call_as_function); |
10365 Local<Function> function = function_template->GetFunction(); | 11666 Local<Function> function = |
11667 function_template->GetFunction(context.local()).ToLocalChecked(); | |
10366 Local<Object> instance = function; | 11668 Local<Object> instance = function; |
10367 v8::TryCatch try_catch(isolate); | 11669 v8::TryCatch try_catch(isolate); |
10368 | 11670 |
10369 CHECK(instance->IsCallable()); | 11671 CHECK(instance->IsCallable()); |
10370 CHECK(!try_catch.HasCaught()); | 11672 CHECK(!try_catch.HasCaught()); |
10371 } | 11673 } |
10372 | 11674 |
10373 { | 11675 { |
10374 Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate); | 11676 Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate); |
10375 Local<Function> function = function_template->GetFunction(); | 11677 Local<Function> function = |
11678 function_template->GetFunction(context.local()).ToLocalChecked(); | |
10376 Local<Object> instance = function; | 11679 Local<Object> instance = function; |
10377 v8::TryCatch try_catch(isolate); | 11680 v8::TryCatch try_catch(isolate); |
10378 | 11681 |
10379 CHECK(instance->IsCallable()); | 11682 CHECK(instance->IsCallable()); |
10380 CHECK(!try_catch.HasCaught()); | 11683 CHECK(!try_catch.HasCaught()); |
10381 } | 11684 } |
10382 } | 11685 } |
10383 | 11686 |
10384 | 11687 |
10385 static int Recurse(v8::Isolate* isolate, int depth, int iterations) { | 11688 static int Recurse(v8::Isolate* isolate, int depth, int iterations) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10436 } | 11739 } |
10437 | 11740 |
10438 static void FastApiCallback_TrivialSignature( | 11741 static void FastApiCallback_TrivialSignature( |
10439 const v8::FunctionCallbackInfo<v8::Value>& args) { | 11742 const v8::FunctionCallbackInfo<v8::Value>& args) { |
10440 ApiTestFuzzer::Fuzz(); | 11743 ApiTestFuzzer::Fuzz(); |
10441 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); | 11744 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); |
10442 v8::Isolate* isolate = CcTest::isolate(); | 11745 v8::Isolate* isolate = CcTest::isolate(); |
10443 CHECK_EQ(isolate, args.GetIsolate()); | 11746 CHECK_EQ(isolate, args.GetIsolate()); |
10444 CHECK(args.This()->Equals(args.Holder())); | 11747 CHECK(args.This()->Equals(args.Holder())); |
10445 CHECK(args.Data()->Equals(v8_str("method_data"))); | 11748 CHECK(args.Data()->Equals(v8_str("method_data"))); |
10446 args.GetReturnValue().Set(args[0]->Int32Value() + 1); | 11749 args.GetReturnValue().Set( |
11750 args[0]->Int32Value(isolate->GetCurrentContext()).FromJust() + 1); | |
10447 } | 11751 } |
10448 | 11752 |
10449 static void FastApiCallback_SimpleSignature( | 11753 static void FastApiCallback_SimpleSignature( |
10450 const v8::FunctionCallbackInfo<v8::Value>& args) { | 11754 const v8::FunctionCallbackInfo<v8::Value>& args) { |
10451 ApiTestFuzzer::Fuzz(); | 11755 ApiTestFuzzer::Fuzz(); |
10452 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); | 11756 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); |
10453 v8::Isolate* isolate = CcTest::isolate(); | 11757 v8::Isolate* isolate = CcTest::isolate(); |
10454 CHECK_EQ(isolate, args.GetIsolate()); | 11758 CHECK_EQ(isolate, args.GetIsolate()); |
10455 CHECK(args.This()->GetPrototype()->Equals(args.Holder())); | 11759 CHECK(args.This()->GetPrototype()->Equals(args.Holder())); |
10456 CHECK(args.Data()->Equals(v8_str("method_data"))); | 11760 CHECK(args.Data()->Equals(v8_str("method_data"))); |
10457 // Note, we're using HasRealNamedProperty instead of Has to avoid | 11761 // Note, we're using HasRealNamedProperty instead of Has to avoid |
10458 // invoking the interceptor again. | 11762 // invoking the interceptor again. |
10459 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); | 11763 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); |
10460 args.GetReturnValue().Set(args[0]->Int32Value() + 1); | 11764 args.GetReturnValue().Set( |
11765 args[0]->Int32Value(isolate->GetCurrentContext()).FromJust() + 1); | |
10461 } | 11766 } |
10462 | 11767 |
10463 | 11768 |
10464 // Helper to maximize the odds of object moving. | 11769 // Helper to maximize the odds of object moving. |
10465 static void GenerateSomeGarbage() { | 11770 static void GenerateSomeGarbage() { |
10466 CompileRun( | 11771 CompileRun( |
10467 "var garbage;" | 11772 "var garbage;" |
10468 "for (var i = 0; i < 1000; i++) {" | 11773 "for (var i = 0; i < 1000; i++) {" |
10469 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" | 11774 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" |
10470 "}" | 11775 "}" |
10471 "garbage = undefined;"); | 11776 "garbage = undefined;"); |
10472 } | 11777 } |
10473 | 11778 |
10474 | 11779 |
10475 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { | 11780 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { |
10476 static int count = 0; | 11781 static int count = 0; |
10477 if (count++ % 3 == 0) { | 11782 if (count++ % 3 == 0) { |
10478 CcTest::heap()->CollectAllGarbage(); | 11783 CcTest::heap()->CollectAllGarbage(); |
10479 // This should move the stub | 11784 // This should move the stub |
10480 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed | 11785 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed |
10481 } | 11786 } |
10482 } | 11787 } |
10483 | 11788 |
10484 | 11789 |
10485 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { | 11790 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { |
10486 LocalContext context; | 11791 LocalContext context; |
10487 v8::Isolate* isolate = context->GetIsolate(); | 11792 v8::Isolate* isolate = context->GetIsolate(); |
10488 v8::HandleScope scope(isolate); | 11793 v8::HandleScope scope(isolate); |
10489 v8::Handle<v8::ObjectTemplate> nativeobject_templ = | 11794 v8::Local<v8::ObjectTemplate> nativeobject_templ = |
10490 v8::ObjectTemplate::New(isolate); | 11795 v8::ObjectTemplate::New(isolate); |
10491 nativeobject_templ->Set(isolate, "callback", | 11796 nativeobject_templ->Set(isolate, "callback", |
10492 v8::FunctionTemplate::New(isolate, | 11797 v8::FunctionTemplate::New(isolate, |
10493 DirectApiCallback)); | 11798 DirectApiCallback)); |
10494 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11799 v8::Local<v8::Object> nativeobject_obj = |
10495 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11800 nativeobject_templ->NewInstance(context.local()).ToLocalChecked(); |
11801 CHECK(context->Global() | |
11802 ->Set(context.local(), v8_str("nativeobject"), nativeobject_obj) | |
11803 .FromJust()); | |
10496 // call the api function multiple times to ensure direct call stub creation. | 11804 // call the api function multiple times to ensure direct call stub creation. |
10497 CompileRun( | 11805 CompileRun( |
10498 "function f() {" | 11806 "function f() {" |
10499 " for (var i = 1; i <= 30; i++) {" | 11807 " for (var i = 1; i <= 30; i++) {" |
10500 " nativeobject.callback();" | 11808 " nativeobject.callback();" |
10501 " }" | 11809 " }" |
10502 "}" | 11810 "}" |
10503 "f();"); | 11811 "f();"); |
10504 } | 11812 } |
10505 | 11813 |
10506 | 11814 |
10507 void ThrowingDirectApiCallback( | 11815 void ThrowingDirectApiCallback( |
10508 const v8::FunctionCallbackInfo<v8::Value>& args) { | 11816 const v8::FunctionCallbackInfo<v8::Value>& args) { |
10509 args.GetIsolate()->ThrowException(v8_str("g")); | 11817 args.GetIsolate()->ThrowException(v8_str("g")); |
10510 } | 11818 } |
10511 | 11819 |
10512 | 11820 |
10513 THREADED_TEST(CallICFastApi_DirectCall_Throw) { | 11821 THREADED_TEST(CallICFastApi_DirectCall_Throw) { |
10514 LocalContext context; | 11822 LocalContext context; |
10515 v8::Isolate* isolate = context->GetIsolate(); | 11823 v8::Isolate* isolate = context->GetIsolate(); |
10516 v8::HandleScope scope(isolate); | 11824 v8::HandleScope scope(isolate); |
10517 v8::Handle<v8::ObjectTemplate> nativeobject_templ = | 11825 v8::Local<v8::ObjectTemplate> nativeobject_templ = |
10518 v8::ObjectTemplate::New(isolate); | 11826 v8::ObjectTemplate::New(isolate); |
10519 nativeobject_templ->Set(isolate, "callback", | 11827 nativeobject_templ->Set(isolate, "callback", |
10520 v8::FunctionTemplate::New(isolate, | 11828 v8::FunctionTemplate::New(isolate, |
10521 ThrowingDirectApiCallback)); | 11829 ThrowingDirectApiCallback)); |
10522 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); | 11830 v8::Local<v8::Object> nativeobject_obj = |
10523 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); | 11831 nativeobject_templ->NewInstance(context.local()).ToLocalChecked(); |
11832 CHECK(context->Global() | |
11833 ->Set(context.local(), v8_str("nativeobject"), nativeobject_obj) | |
11834 .FromJust()); | |
10524 // call the api function multiple times to ensure direct call stub creation. | 11835 // call the api function multiple times to ensure direct call stub creation. |
10525 v8::Handle<Value> result = CompileRun( | 11836 v8::Local<Value> result = CompileRun( |
10526 "var result = '';" | 11837 "var result = '';" |
10527 "function f() {" | 11838 "function f() {" |
10528 " for (var i = 1; i <= 5; i++) {" | 11839 " for (var i = 1; i <= 5; i++) {" |
10529 " try { nativeobject.callback(); } catch (e) { result += e; }" | 11840 " try { nativeobject.callback(); } catch (e) { result += e; }" |
10530 " }" | 11841 " }" |
10531 "}" | 11842 "}" |
10532 "f(); result;"); | 11843 "f(); result;"); |
10533 CHECK(v8_str("ggggg")->Equals(result)); | 11844 CHECK(v8_str("ggggg")->Equals(result)); |
10534 } | 11845 } |
10535 | 11846 |
10536 | 11847 |
10537 static int p_getter_count_3; | 11848 static int p_getter_count_3; |
10538 | 11849 |
10539 | 11850 |
10540 static Handle<Value> DoDirectGetter() { | 11851 static Local<Value> DoDirectGetter() { |
10541 if (++p_getter_count_3 % 3 == 0) { | 11852 if (++p_getter_count_3 % 3 == 0) { |
10542 CcTest::heap()->CollectAllGarbage(); | 11853 CcTest::heap()->CollectAllGarbage(); |
10543 GenerateSomeGarbage(); | 11854 GenerateSomeGarbage(); |
10544 } | 11855 } |
10545 return v8_str("Direct Getter Result"); | 11856 return v8_str("Direct Getter Result"); |
10546 } | 11857 } |
10547 | 11858 |
10548 | 11859 |
10549 static void DirectGetterCallback( | 11860 static void DirectGetterCallback( |
10550 Local<String> name, | 11861 Local<String> name, |
10551 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11862 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10552 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); | 11863 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); |
10553 info.GetReturnValue().Set(DoDirectGetter()); | 11864 info.GetReturnValue().Set(DoDirectGetter()); |
10554 } | 11865 } |
10555 | 11866 |
10556 | 11867 |
10557 template<typename Accessor> | 11868 template<typename Accessor> |
10558 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { | 11869 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { |
10559 LocalContext context; | 11870 LocalContext context; |
10560 v8::Isolate* isolate = context->GetIsolate(); | 11871 v8::Isolate* isolate = context->GetIsolate(); |
10561 v8::HandleScope scope(isolate); | 11872 v8::HandleScope scope(isolate); |
10562 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); | 11873 v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); |
10563 obj->SetAccessor(v8_str("p1"), accessor); | 11874 obj->SetAccessor(v8_str("p1"), accessor); |
10564 context->Global()->Set(v8_str("o1"), obj->NewInstance()); | 11875 CHECK(context->Global() |
11876 ->Set(context.local(), v8_str("o1"), | |
11877 obj->NewInstance(context.local()).ToLocalChecked()) | |
11878 .FromJust()); | |
10565 p_getter_count_3 = 0; | 11879 p_getter_count_3 = 0; |
10566 v8::Handle<v8::Value> result = CompileRun( | 11880 v8::Local<v8::Value> result = CompileRun( |
10567 "function f() {" | 11881 "function f() {" |
10568 " for (var i = 0; i < 30; i++) o1.p1;" | 11882 " for (var i = 0; i < 30; i++) o1.p1;" |
10569 " return o1.p1" | 11883 " return o1.p1" |
10570 "}" | 11884 "}" |
10571 "f();"); | 11885 "f();"); |
10572 CHECK(v8_str("Direct Getter Result")->Equals(result)); | 11886 CHECK(v8_str("Direct Getter Result")->Equals(result)); |
10573 CHECK_EQ(31, p_getter_count_3); | 11887 CHECK_EQ(31, p_getter_count_3); |
10574 } | 11888 } |
10575 | 11889 |
10576 | 11890 |
10577 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { | 11891 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { |
10578 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); | 11892 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); |
10579 } | 11893 } |
10580 | 11894 |
10581 | 11895 |
10582 void ThrowingDirectGetterCallback( | 11896 void ThrowingDirectGetterCallback( |
10583 Local<String> name, | 11897 Local<String> name, |
10584 const v8::PropertyCallbackInfo<v8::Value>& info) { | 11898 const v8::PropertyCallbackInfo<v8::Value>& info) { |
10585 info.GetIsolate()->ThrowException(v8_str("g")); | 11899 info.GetIsolate()->ThrowException(v8_str("g")); |
10586 } | 11900 } |
10587 | 11901 |
10588 | 11902 |
10589 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { | 11903 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { |
10590 LocalContext context; | 11904 LocalContext context; |
10591 v8::Isolate* isolate = context->GetIsolate(); | 11905 v8::Isolate* isolate = context->GetIsolate(); |
10592 v8::HandleScope scope(isolate); | 11906 v8::HandleScope scope(isolate); |
10593 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); | 11907 v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); |
10594 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); | 11908 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); |
10595 context->Global()->Set(v8_str("o1"), obj->NewInstance()); | 11909 CHECK(context->Global() |
10596 v8::Handle<Value> result = CompileRun( | 11910 ->Set(context.local(), v8_str("o1"), |
11911 obj->NewInstance(context.local()).ToLocalChecked()) | |
11912 .FromJust()); | |
11913 v8::Local<Value> result = CompileRun( | |
10597 "var result = '';" | 11914 "var result = '';" |
10598 "for (var i = 0; i < 5; i++) {" | 11915 "for (var i = 0; i < 5; i++) {" |
10599 " try { o1.p1; } catch (e) { result += e; }" | 11916 " try { o1.p1; } catch (e) { result += e; }" |
10600 "}" | 11917 "}" |
10601 "result;"); | 11918 "result;"); |
10602 CHECK(v8_str("ggggg")->Equals(result)); | 11919 CHECK(v8_str("ggggg")->Equals(result)); |
10603 } | 11920 } |
10604 | 11921 |
10605 | 11922 |
10606 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { | 11923 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { |
10607 int interceptor_call_count = 0; | 11924 int interceptor_call_count = 0; |
10608 v8::Isolate* isolate = CcTest::isolate(); | 11925 v8::Isolate* isolate = CcTest::isolate(); |
10609 v8::HandleScope scope(isolate); | 11926 v8::HandleScope scope(isolate); |
10610 v8::Handle<v8::FunctionTemplate> fun_templ = | 11927 v8::Local<v8::FunctionTemplate> fun_templ = |
10611 v8::FunctionTemplate::New(isolate); | 11928 v8::FunctionTemplate::New(isolate); |
10612 v8::Handle<v8::FunctionTemplate> method_templ = | 11929 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10613 v8::FunctionTemplate::New(isolate, | 11930 isolate, FastApiCallback_TrivialSignature, v8_str("method_data"), |
10614 FastApiCallback_TrivialSignature, | 11931 v8::Local<v8::Signature>()); |
10615 v8_str("method_data"), | 11932 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10616 v8::Handle<v8::Signature>()); | |
10617 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | |
10618 proto_templ->Set(v8_str("method"), method_templ); | 11933 proto_templ->Set(v8_str("method"), method_templ); |
10619 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11934 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10620 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 11935 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10621 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11936 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10622 v8::External::New(isolate, &interceptor_call_count))); | 11937 v8::External::New(isolate, &interceptor_call_count))); |
10623 LocalContext context; | 11938 LocalContext context; |
10624 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11939 v8::Local<v8::Function> fun = |
11940 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10625 GenerateSomeGarbage(); | 11941 GenerateSomeGarbage(); |
10626 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11942 CHECK(context->Global() |
11943 ->Set(context.local(), v8_str("o"), | |
11944 fun->NewInstance(context.local()).ToLocalChecked()) | |
11945 .FromJust()); | |
10627 CompileRun( | 11946 CompileRun( |
10628 "var result = 0;" | 11947 "var result = 0;" |
10629 "for (var i = 0; i < 100; i++) {" | 11948 "for (var i = 0; i < 100; i++) {" |
10630 " result = o.method(41);" | 11949 " result = o.method(41);" |
10631 "}"); | 11950 "}"); |
10632 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 11951 CHECK_EQ(42, context->Global() |
11952 ->Get(v8_str("result")) | |
11953 ->Int32Value(context.local()) | |
11954 .FromJust()); | |
10633 CHECK_EQ(100, interceptor_call_count); | 11955 CHECK_EQ(100, interceptor_call_count); |
10634 } | 11956 } |
10635 | 11957 |
10636 | 11958 |
10637 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { | 11959 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { |
10638 int interceptor_call_count = 0; | 11960 int interceptor_call_count = 0; |
10639 v8::Isolate* isolate = CcTest::isolate(); | 11961 v8::Isolate* isolate = CcTest::isolate(); |
10640 v8::HandleScope scope(isolate); | 11962 v8::HandleScope scope(isolate); |
10641 v8::Handle<v8::FunctionTemplate> fun_templ = | 11963 v8::Local<v8::FunctionTemplate> fun_templ = |
10642 v8::FunctionTemplate::New(isolate); | 11964 v8::FunctionTemplate::New(isolate); |
10643 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 11965 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10644 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 11966 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10645 v8::Signature::New(isolate, fun_templ)); | 11967 v8::Signature::New(isolate, fun_templ)); |
10646 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 11968 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10647 proto_templ->Set(v8_str("method"), method_templ); | 11969 proto_templ->Set(v8_str("method"), method_templ); |
10648 fun_templ->SetHiddenPrototype(true); | 11970 fun_templ->SetHiddenPrototype(true); |
10649 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 11971 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10650 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 11972 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10651 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 11973 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10652 v8::External::New(isolate, &interceptor_call_count))); | 11974 v8::External::New(isolate, &interceptor_call_count))); |
10653 LocalContext context; | 11975 LocalContext context; |
10654 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 11976 v8::Local<v8::Function> fun = |
11977 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10655 GenerateSomeGarbage(); | 11978 GenerateSomeGarbage(); |
10656 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 11979 CHECK(context->Global() |
11980 ->Set(context.local(), v8_str("o"), | |
11981 fun->NewInstance(context.local()).ToLocalChecked()) | |
11982 .FromJust()); | |
10657 CompileRun( | 11983 CompileRun( |
10658 "o.foo = 17;" | 11984 "o.foo = 17;" |
10659 "var receiver = {};" | 11985 "var receiver = {};" |
10660 "receiver.__proto__ = o;" | 11986 "receiver.__proto__ = o;" |
10661 "var result = 0;" | 11987 "var result = 0;" |
10662 "for (var i = 0; i < 100; i++) {" | 11988 "for (var i = 0; i < 100; i++) {" |
10663 " result = receiver.method(41);" | 11989 " result = receiver.method(41);" |
10664 "}"); | 11990 "}"); |
10665 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 11991 CHECK_EQ(42, context->Global() |
11992 ->Get(v8_str("result")) | |
11993 ->Int32Value(context.local()) | |
11994 .FromJust()); | |
10666 CHECK_EQ(100, interceptor_call_count); | 11995 CHECK_EQ(100, interceptor_call_count); |
10667 } | 11996 } |
10668 | 11997 |
10669 | 11998 |
10670 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { | 11999 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { |
10671 int interceptor_call_count = 0; | 12000 int interceptor_call_count = 0; |
10672 v8::Isolate* isolate = CcTest::isolate(); | 12001 v8::Isolate* isolate = CcTest::isolate(); |
10673 v8::HandleScope scope(isolate); | 12002 v8::HandleScope scope(isolate); |
10674 v8::Handle<v8::FunctionTemplate> fun_templ = | 12003 v8::Local<v8::FunctionTemplate> fun_templ = |
10675 v8::FunctionTemplate::New(isolate); | 12004 v8::FunctionTemplate::New(isolate); |
10676 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12005 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10677 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12006 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10678 v8::Signature::New(isolate, fun_templ)); | 12007 v8::Signature::New(isolate, fun_templ)); |
10679 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12008 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10680 proto_templ->Set(v8_str("method"), method_templ); | 12009 proto_templ->Set(v8_str("method"), method_templ); |
10681 fun_templ->SetHiddenPrototype(true); | 12010 fun_templ->SetHiddenPrototype(true); |
10682 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12011 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10683 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 12012 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10684 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12013 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10685 v8::External::New(isolate, &interceptor_call_count))); | 12014 v8::External::New(isolate, &interceptor_call_count))); |
10686 LocalContext context; | 12015 LocalContext context; |
10687 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12016 v8::Local<v8::Function> fun = |
12017 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10688 GenerateSomeGarbage(); | 12018 GenerateSomeGarbage(); |
10689 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12019 CHECK(context->Global() |
12020 ->Set(context.local(), v8_str("o"), | |
12021 fun->NewInstance(context.local()).ToLocalChecked()) | |
12022 .FromJust()); | |
10690 CompileRun( | 12023 CompileRun( |
10691 "o.foo = 17;" | 12024 "o.foo = 17;" |
10692 "var receiver = {};" | 12025 "var receiver = {};" |
10693 "receiver.__proto__ = o;" | 12026 "receiver.__proto__ = o;" |
10694 "var result = 0;" | 12027 "var result = 0;" |
10695 "var saved_result = 0;" | 12028 "var saved_result = 0;" |
10696 "for (var i = 0; i < 100; i++) {" | 12029 "for (var i = 0; i < 100; i++) {" |
10697 " result = receiver.method(41);" | 12030 " result = receiver.method(41);" |
10698 " if (i == 50) {" | 12031 " if (i == 50) {" |
10699 " saved_result = result;" | 12032 " saved_result = result;" |
10700 " receiver = {method: function(x) { return x - 1 }};" | 12033 " receiver = {method: function(x) { return x - 1 }};" |
10701 " }" | 12034 " }" |
10702 "}"); | 12035 "}"); |
10703 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 12036 CHECK_EQ(40, context->Global() |
10704 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12037 ->Get(v8_str("result")) |
12038 ->Int32Value(context.local()) | |
12039 .FromJust()); | |
12040 CHECK_EQ(42, context->Global() | |
12041 ->Get(v8_str("saved_result")) | |
12042 ->Int32Value(context.local()) | |
12043 .FromJust()); | |
10705 CHECK_GE(interceptor_call_count, 50); | 12044 CHECK_GE(interceptor_call_count, 50); |
10706 } | 12045 } |
10707 | 12046 |
10708 | 12047 |
10709 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { | 12048 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { |
10710 int interceptor_call_count = 0; | 12049 int interceptor_call_count = 0; |
10711 v8::Isolate* isolate = CcTest::isolate(); | 12050 v8::Isolate* isolate = CcTest::isolate(); |
10712 v8::HandleScope scope(isolate); | 12051 v8::HandleScope scope(isolate); |
10713 v8::Handle<v8::FunctionTemplate> fun_templ = | 12052 v8::Local<v8::FunctionTemplate> fun_templ = |
10714 v8::FunctionTemplate::New(isolate); | 12053 v8::FunctionTemplate::New(isolate); |
10715 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12054 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10716 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12055 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10717 v8::Signature::New(isolate, fun_templ)); | 12056 v8::Signature::New(isolate, fun_templ)); |
10718 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12057 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10719 proto_templ->Set(v8_str("method"), method_templ); | 12058 proto_templ->Set(v8_str("method"), method_templ); |
10720 fun_templ->SetHiddenPrototype(true); | 12059 fun_templ->SetHiddenPrototype(true); |
10721 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12060 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10722 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 12061 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10723 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12062 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10724 v8::External::New(isolate, &interceptor_call_count))); | 12063 v8::External::New(isolate, &interceptor_call_count))); |
10725 LocalContext context; | 12064 LocalContext context; |
10726 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12065 v8::Local<v8::Function> fun = |
12066 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10727 GenerateSomeGarbage(); | 12067 GenerateSomeGarbage(); |
10728 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12068 CHECK(context->Global() |
12069 ->Set(context.local(), v8_str("o"), | |
12070 fun->NewInstance(context.local()).ToLocalChecked()) | |
12071 .FromJust()); | |
10729 CompileRun( | 12072 CompileRun( |
10730 "o.foo = 17;" | 12073 "o.foo = 17;" |
10731 "var receiver = {};" | 12074 "var receiver = {};" |
10732 "receiver.__proto__ = o;" | 12075 "receiver.__proto__ = o;" |
10733 "var result = 0;" | 12076 "var result = 0;" |
10734 "var saved_result = 0;" | 12077 "var saved_result = 0;" |
10735 "for (var i = 0; i < 100; i++) {" | 12078 "for (var i = 0; i < 100; i++) {" |
10736 " result = receiver.method(41);" | 12079 " result = receiver.method(41);" |
10737 " if (i == 50) {" | 12080 " if (i == 50) {" |
10738 " saved_result = result;" | 12081 " saved_result = result;" |
10739 " o.method = function(x) { return x - 1 };" | 12082 " o.method = function(x) { return x - 1 };" |
10740 " }" | 12083 " }" |
10741 "}"); | 12084 "}"); |
10742 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 12085 CHECK_EQ(40, context->Global() |
10743 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12086 ->Get(v8_str("result")) |
12087 ->Int32Value(context.local()) | |
12088 .FromJust()); | |
12089 CHECK_EQ(42, context->Global() | |
12090 ->Get(v8_str("saved_result")) | |
12091 ->Int32Value(context.local()) | |
12092 .FromJust()); | |
10744 CHECK_GE(interceptor_call_count, 50); | 12093 CHECK_GE(interceptor_call_count, 50); |
10745 } | 12094 } |
10746 | 12095 |
10747 | 12096 |
10748 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { | 12097 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { |
10749 int interceptor_call_count = 0; | 12098 int interceptor_call_count = 0; |
10750 v8::Isolate* isolate = CcTest::isolate(); | 12099 v8::Isolate* isolate = CcTest::isolate(); |
10751 v8::HandleScope scope(isolate); | 12100 v8::HandleScope scope(isolate); |
10752 v8::Handle<v8::FunctionTemplate> fun_templ = | 12101 v8::Local<v8::FunctionTemplate> fun_templ = |
10753 v8::FunctionTemplate::New(isolate); | 12102 v8::FunctionTemplate::New(isolate); |
10754 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12103 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10755 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12104 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10756 v8::Signature::New(isolate, fun_templ)); | 12105 v8::Signature::New(isolate, fun_templ)); |
10757 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12106 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10758 proto_templ->Set(v8_str("method"), method_templ); | 12107 proto_templ->Set(v8_str("method"), method_templ); |
10759 fun_templ->SetHiddenPrototype(true); | 12108 fun_templ->SetHiddenPrototype(true); |
10760 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12109 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10761 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 12110 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10762 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12111 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10763 v8::External::New(isolate, &interceptor_call_count))); | 12112 v8::External::New(isolate, &interceptor_call_count))); |
10764 LocalContext context; | 12113 LocalContext context; |
10765 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12114 v8::Local<v8::Function> fun = |
12115 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10766 GenerateSomeGarbage(); | 12116 GenerateSomeGarbage(); |
10767 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12117 CHECK(context->Global() |
12118 ->Set(context.local(), v8_str("o"), | |
12119 fun->NewInstance(context.local()).ToLocalChecked()) | |
12120 .FromJust()); | |
10768 v8::TryCatch try_catch(isolate); | 12121 v8::TryCatch try_catch(isolate); |
10769 CompileRun( | 12122 CompileRun( |
10770 "o.foo = 17;" | 12123 "o.foo = 17;" |
10771 "var receiver = {};" | 12124 "var receiver = {};" |
10772 "receiver.__proto__ = o;" | 12125 "receiver.__proto__ = o;" |
10773 "var result = 0;" | 12126 "var result = 0;" |
10774 "var saved_result = 0;" | 12127 "var saved_result = 0;" |
10775 "for (var i = 0; i < 100; i++) {" | 12128 "for (var i = 0; i < 100; i++) {" |
10776 " result = receiver.method(41);" | 12129 " result = receiver.method(41);" |
10777 " if (i == 50) {" | 12130 " if (i == 50) {" |
10778 " saved_result = result;" | 12131 " saved_result = result;" |
10779 " receiver = 333;" | 12132 " receiver = 333;" |
10780 " }" | 12133 " }" |
10781 "}"); | 12134 "}"); |
10782 CHECK(try_catch.HasCaught()); | 12135 CHECK(try_catch.HasCaught()); |
10783 // TODO(verwaest): Adjust message. | 12136 // TODO(verwaest): Adjust message. |
10784 CHECK(v8_str("TypeError: receiver.method is not a function") | 12137 CHECK(v8_str("TypeError: receiver.method is not a function") |
10785 ->Equals(try_catch.Exception()->ToString(isolate))); | 12138 ->Equals(try_catch.Exception()->ToString(isolate))); |
10786 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12139 CHECK_EQ(42, context->Global() |
12140 ->Get(v8_str("saved_result")) | |
12141 ->Int32Value(context.local()) | |
12142 .FromJust()); | |
10787 CHECK_GE(interceptor_call_count, 50); | 12143 CHECK_GE(interceptor_call_count, 50); |
10788 } | 12144 } |
10789 | 12145 |
10790 | 12146 |
10791 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { | 12147 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { |
10792 int interceptor_call_count = 0; | 12148 int interceptor_call_count = 0; |
10793 v8::Isolate* isolate = CcTest::isolate(); | 12149 v8::Isolate* isolate = CcTest::isolate(); |
10794 v8::HandleScope scope(isolate); | 12150 v8::HandleScope scope(isolate); |
10795 v8::Handle<v8::FunctionTemplate> fun_templ = | 12151 v8::Local<v8::FunctionTemplate> fun_templ = |
10796 v8::FunctionTemplate::New(isolate); | 12152 v8::FunctionTemplate::New(isolate); |
10797 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12153 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10798 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12154 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10799 v8::Signature::New(isolate, fun_templ)); | 12155 v8::Signature::New(isolate, fun_templ)); |
10800 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12156 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10801 proto_templ->Set(v8_str("method"), method_templ); | 12157 proto_templ->Set(v8_str("method"), method_templ); |
10802 fun_templ->SetHiddenPrototype(true); | 12158 fun_templ->SetHiddenPrototype(true); |
10803 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); | 12159 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); |
10804 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 12160 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
10805 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, | 12161 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, |
10806 v8::External::New(isolate, &interceptor_call_count))); | 12162 v8::External::New(isolate, &interceptor_call_count))); |
10807 LocalContext context; | 12163 LocalContext context; |
10808 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12164 v8::Local<v8::Function> fun = |
12165 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10809 GenerateSomeGarbage(); | 12166 GenerateSomeGarbage(); |
10810 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12167 CHECK(context->Global() |
12168 ->Set(context.local(), v8_str("o"), | |
12169 fun->NewInstance(context.local()).ToLocalChecked()) | |
12170 .FromJust()); | |
10811 v8::TryCatch try_catch(isolate); | 12171 v8::TryCatch try_catch(isolate); |
10812 CompileRun( | 12172 CompileRun( |
10813 "o.foo = 17;" | 12173 "o.foo = 17;" |
10814 "var receiver = {};" | 12174 "var receiver = {};" |
10815 "receiver.__proto__ = o;" | 12175 "receiver.__proto__ = o;" |
10816 "var result = 0;" | 12176 "var result = 0;" |
10817 "var saved_result = 0;" | 12177 "var saved_result = 0;" |
10818 "for (var i = 0; i < 100; i++) {" | 12178 "for (var i = 0; i < 100; i++) {" |
10819 " result = receiver.method(41);" | 12179 " result = receiver.method(41);" |
10820 " if (i == 50) {" | 12180 " if (i == 50) {" |
10821 " saved_result = result;" | 12181 " saved_result = result;" |
10822 " receiver = {method: receiver.method};" | 12182 " receiver = {method: receiver.method};" |
10823 " }" | 12183 " }" |
10824 "}"); | 12184 "}"); |
10825 CHECK(try_catch.HasCaught()); | 12185 CHECK(try_catch.HasCaught()); |
10826 CHECK(v8_str("TypeError: Illegal invocation") | 12186 CHECK(v8_str("TypeError: Illegal invocation") |
10827 ->Equals(try_catch.Exception()->ToString(isolate))); | 12187 ->Equals(try_catch.Exception()->ToString(isolate))); |
10828 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12188 CHECK_EQ(42, context->Global() |
12189 ->Get(v8_str("saved_result")) | |
12190 ->Int32Value(context.local()) | |
12191 .FromJust()); | |
10829 CHECK_GE(interceptor_call_count, 50); | 12192 CHECK_GE(interceptor_call_count, 50); |
10830 } | 12193 } |
10831 | 12194 |
10832 | 12195 |
10833 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { | 12196 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { |
10834 v8::Isolate* isolate = CcTest::isolate(); | 12197 v8::Isolate* isolate = CcTest::isolate(); |
10835 v8::HandleScope scope(isolate); | 12198 v8::HandleScope scope(isolate); |
10836 v8::Handle<v8::FunctionTemplate> fun_templ = | 12199 v8::Local<v8::FunctionTemplate> fun_templ = |
10837 v8::FunctionTemplate::New(isolate); | 12200 v8::FunctionTemplate::New(isolate); |
10838 v8::Handle<v8::FunctionTemplate> method_templ = | 12201 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10839 v8::FunctionTemplate::New(isolate, | 12202 isolate, FastApiCallback_TrivialSignature, v8_str("method_data"), |
10840 FastApiCallback_TrivialSignature, | 12203 v8::Local<v8::Signature>()); |
10841 v8_str("method_data"), | 12204 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10842 v8::Handle<v8::Signature>()); | |
10843 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | |
10844 proto_templ->Set(v8_str("method"), method_templ); | 12205 proto_templ->Set(v8_str("method"), method_templ); |
10845 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12206 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10846 USE(templ); | 12207 USE(templ); |
10847 LocalContext context; | 12208 LocalContext context; |
10848 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12209 v8::Local<v8::Function> fun = |
12210 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10849 GenerateSomeGarbage(); | 12211 GenerateSomeGarbage(); |
10850 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12212 CHECK(context->Global() |
12213 ->Set(context.local(), v8_str("o"), | |
12214 fun->NewInstance(context.local()).ToLocalChecked()) | |
12215 .FromJust()); | |
10851 CompileRun( | 12216 CompileRun( |
10852 "var result = 0;" | 12217 "var result = 0;" |
10853 "for (var i = 0; i < 100; i++) {" | 12218 "for (var i = 0; i < 100; i++) {" |
10854 " result = o.method(41);" | 12219 " result = o.method(41);" |
10855 "}"); | 12220 "}"); |
10856 | 12221 |
10857 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12222 CHECK_EQ(42, context->Global() |
12223 ->Get(v8_str("result")) | |
12224 ->Int32Value(context.local()) | |
12225 .FromJust()); | |
10858 } | 12226 } |
10859 | 12227 |
10860 | 12228 |
10861 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { | 12229 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { |
10862 v8::Isolate* isolate = CcTest::isolate(); | 12230 v8::Isolate* isolate = CcTest::isolate(); |
10863 v8::HandleScope scope(isolate); | 12231 v8::HandleScope scope(isolate); |
10864 v8::Handle<v8::FunctionTemplate> fun_templ = | 12232 v8::Local<v8::FunctionTemplate> fun_templ = |
10865 v8::FunctionTemplate::New(isolate); | 12233 v8::FunctionTemplate::New(isolate); |
10866 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12234 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10867 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12235 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10868 v8::Signature::New(isolate, fun_templ)); | 12236 v8::Signature::New(isolate, fun_templ)); |
10869 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12237 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10870 proto_templ->Set(v8_str("method"), method_templ); | 12238 proto_templ->Set(v8_str("method"), method_templ); |
10871 fun_templ->SetHiddenPrototype(true); | 12239 fun_templ->SetHiddenPrototype(true); |
10872 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12240 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10873 CHECK(!templ.IsEmpty()); | 12241 CHECK(!templ.IsEmpty()); |
10874 LocalContext context; | 12242 LocalContext context; |
10875 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12243 v8::Local<v8::Function> fun = |
12244 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10876 GenerateSomeGarbage(); | 12245 GenerateSomeGarbage(); |
10877 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12246 CHECK(context->Global() |
12247 ->Set(context.local(), v8_str("o"), | |
12248 fun->NewInstance(context.local()).ToLocalChecked()) | |
12249 .FromJust()); | |
10878 CompileRun( | 12250 CompileRun( |
10879 "o.foo = 17;" | 12251 "o.foo = 17;" |
10880 "var receiver = {};" | 12252 "var receiver = {};" |
10881 "receiver.__proto__ = o;" | 12253 "receiver.__proto__ = o;" |
10882 "var result = 0;" | 12254 "var result = 0;" |
10883 "for (var i = 0; i < 100; i++) {" | 12255 "for (var i = 0; i < 100; i++) {" |
10884 " result = receiver.method(41);" | 12256 " result = receiver.method(41);" |
10885 "}"); | 12257 "}"); |
10886 | 12258 |
10887 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); | 12259 CHECK_EQ(42, context->Global() |
12260 ->Get(v8_str("result")) | |
12261 ->Int32Value(context.local()) | |
12262 .FromJust()); | |
10888 } | 12263 } |
10889 | 12264 |
10890 | 12265 |
10891 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { | 12266 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { |
10892 v8::Isolate* isolate = CcTest::isolate(); | 12267 v8::Isolate* isolate = CcTest::isolate(); |
10893 v8::HandleScope scope(isolate); | 12268 v8::HandleScope scope(isolate); |
10894 v8::Handle<v8::FunctionTemplate> fun_templ = | 12269 v8::Local<v8::FunctionTemplate> fun_templ = |
10895 v8::FunctionTemplate::New(isolate); | 12270 v8::FunctionTemplate::New(isolate); |
10896 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12271 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10897 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12272 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10898 v8::Signature::New(isolate, fun_templ)); | 12273 v8::Signature::New(isolate, fun_templ)); |
10899 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12274 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10900 proto_templ->Set(v8_str("method"), method_templ); | 12275 proto_templ->Set(v8_str("method"), method_templ); |
10901 fun_templ->SetHiddenPrototype(true); | 12276 fun_templ->SetHiddenPrototype(true); |
10902 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12277 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10903 CHECK(!templ.IsEmpty()); | 12278 CHECK(!templ.IsEmpty()); |
10904 LocalContext context; | 12279 LocalContext context; |
10905 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12280 v8::Local<v8::Function> fun = |
12281 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10906 GenerateSomeGarbage(); | 12282 GenerateSomeGarbage(); |
10907 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12283 CHECK(context->Global() |
12284 ->Set(context.local(), v8_str("o"), | |
12285 fun->NewInstance(context.local()).ToLocalChecked()) | |
12286 .FromJust()); | |
10908 CompileRun( | 12287 CompileRun( |
10909 "o.foo = 17;" | 12288 "o.foo = 17;" |
10910 "var receiver = {};" | 12289 "var receiver = {};" |
10911 "receiver.__proto__ = o;" | 12290 "receiver.__proto__ = o;" |
10912 "var result = 0;" | 12291 "var result = 0;" |
10913 "var saved_result = 0;" | 12292 "var saved_result = 0;" |
10914 "for (var i = 0; i < 100; i++) {" | 12293 "for (var i = 0; i < 100; i++) {" |
10915 " result = receiver.method(41);" | 12294 " result = receiver.method(41);" |
10916 " if (i == 50) {" | 12295 " if (i == 50) {" |
10917 " saved_result = result;" | 12296 " saved_result = result;" |
10918 " receiver = {method: function(x) { return x - 1 }};" | 12297 " receiver = {method: function(x) { return x - 1 }};" |
10919 " }" | 12298 " }" |
10920 "}"); | 12299 "}"); |
10921 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); | 12300 CHECK_EQ(40, context->Global() |
10922 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12301 ->Get(v8_str("result")) |
12302 ->Int32Value(context.local()) | |
12303 .FromJust()); | |
12304 CHECK_EQ(42, context->Global() | |
12305 ->Get(v8_str("saved_result")) | |
12306 ->Int32Value(context.local()) | |
12307 .FromJust()); | |
10923 } | 12308 } |
10924 | 12309 |
10925 | 12310 |
10926 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { | 12311 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { |
10927 v8::Isolate* isolate = CcTest::isolate(); | 12312 v8::Isolate* isolate = CcTest::isolate(); |
10928 v8::HandleScope scope(isolate); | 12313 v8::HandleScope scope(isolate); |
10929 v8::Handle<v8::FunctionTemplate> fun_templ = | 12314 v8::Local<v8::FunctionTemplate> fun_templ = |
10930 v8::FunctionTemplate::New(isolate); | 12315 v8::FunctionTemplate::New(isolate); |
10931 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12316 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10932 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12317 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10933 v8::Signature::New(isolate, fun_templ)); | 12318 v8::Signature::New(isolate, fun_templ)); |
10934 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12319 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10935 proto_templ->Set(v8_str("method"), method_templ); | 12320 proto_templ->Set(v8_str("method"), method_templ); |
10936 fun_templ->SetHiddenPrototype(true); | 12321 fun_templ->SetHiddenPrototype(true); |
10937 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12322 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10938 CHECK(!templ.IsEmpty()); | 12323 CHECK(!templ.IsEmpty()); |
10939 LocalContext context; | 12324 LocalContext context; |
10940 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12325 v8::Local<v8::Function> fun = |
12326 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10941 GenerateSomeGarbage(); | 12327 GenerateSomeGarbage(); |
10942 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12328 CHECK(context->Global() |
12329 ->Set(context.local(), v8_str("o"), | |
12330 fun->NewInstance(context.local()).ToLocalChecked()) | |
12331 .FromJust()); | |
10943 v8::TryCatch try_catch(isolate); | 12332 v8::TryCatch try_catch(isolate); |
10944 CompileRun( | 12333 CompileRun( |
10945 "o.foo = 17;" | 12334 "o.foo = 17;" |
10946 "var receiver = {};" | 12335 "var receiver = {};" |
10947 "receiver.__proto__ = o;" | 12336 "receiver.__proto__ = o;" |
10948 "var result = 0;" | 12337 "var result = 0;" |
10949 "var saved_result = 0;" | 12338 "var saved_result = 0;" |
10950 "for (var i = 0; i < 100; i++) {" | 12339 "for (var i = 0; i < 100; i++) {" |
10951 " result = receiver.method(41);" | 12340 " result = receiver.method(41);" |
10952 " if (i == 50) {" | 12341 " if (i == 50) {" |
10953 " saved_result = result;" | 12342 " saved_result = result;" |
10954 " receiver = 333;" | 12343 " receiver = 333;" |
10955 " }" | 12344 " }" |
10956 "}"); | 12345 "}"); |
10957 CHECK(try_catch.HasCaught()); | 12346 CHECK(try_catch.HasCaught()); |
10958 // TODO(verwaest): Adjust message. | 12347 // TODO(verwaest): Adjust message. |
10959 CHECK(v8_str("TypeError: receiver.method is not a function") | 12348 CHECK(v8_str("TypeError: receiver.method is not a function") |
10960 ->Equals(try_catch.Exception()->ToString(isolate))); | 12349 ->Equals(try_catch.Exception()->ToString(isolate))); |
10961 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12350 CHECK_EQ(42, context->Global() |
12351 ->Get(v8_str("saved_result")) | |
12352 ->Int32Value(context.local()) | |
12353 .FromJust()); | |
10962 } | 12354 } |
10963 | 12355 |
10964 | 12356 |
10965 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { | 12357 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { |
10966 v8::Isolate* isolate = CcTest::isolate(); | 12358 v8::Isolate* isolate = CcTest::isolate(); |
10967 v8::HandleScope scope(isolate); | 12359 v8::HandleScope scope(isolate); |
10968 v8::Handle<v8::FunctionTemplate> fun_templ = | 12360 v8::Local<v8::FunctionTemplate> fun_templ = |
10969 v8::FunctionTemplate::New(isolate); | 12361 v8::FunctionTemplate::New(isolate); |
10970 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( | 12362 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( |
10971 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), | 12363 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), |
10972 v8::Signature::New(isolate, fun_templ)); | 12364 v8::Signature::New(isolate, fun_templ)); |
10973 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); | 12365 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); |
10974 proto_templ->Set(v8_str("method"), method_templ); | 12366 proto_templ->Set(v8_str("method"), method_templ); |
10975 fun_templ->SetHiddenPrototype(true); | 12367 fun_templ->SetHiddenPrototype(true); |
10976 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); | 12368 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); |
10977 CHECK(!templ.IsEmpty()); | 12369 CHECK(!templ.IsEmpty()); |
10978 LocalContext context; | 12370 LocalContext context; |
10979 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); | 12371 v8::Local<v8::Function> fun = |
12372 fun_templ->GetFunction(context.local()).ToLocalChecked(); | |
10980 GenerateSomeGarbage(); | 12373 GenerateSomeGarbage(); |
10981 context->Global()->Set(v8_str("o"), fun->NewInstance()); | 12374 CHECK(context->Global() |
12375 ->Set(context.local(), v8_str("o"), | |
12376 fun->NewInstance(context.local()).ToLocalChecked()) | |
12377 .FromJust()); | |
10982 v8::TryCatch try_catch(isolate); | 12378 v8::TryCatch try_catch(isolate); |
10983 CompileRun( | 12379 CompileRun( |
10984 "o.foo = 17;" | 12380 "o.foo = 17;" |
10985 "var receiver = {};" | 12381 "var receiver = {};" |
10986 "receiver.__proto__ = o;" | 12382 "receiver.__proto__ = o;" |
10987 "var result = 0;" | 12383 "var result = 0;" |
10988 "var saved_result = 0;" | 12384 "var saved_result = 0;" |
10989 "for (var i = 0; i < 100; i++) {" | 12385 "for (var i = 0; i < 100; i++) {" |
10990 " result = receiver.method(41);" | 12386 " result = receiver.method(41);" |
10991 " if (i == 50) {" | 12387 " if (i == 50) {" |
10992 " saved_result = result;" | 12388 " saved_result = result;" |
10993 " receiver = Object.create(receiver);" | 12389 " receiver = Object.create(receiver);" |
10994 " }" | 12390 " }" |
10995 "}"); | 12391 "}"); |
10996 CHECK(try_catch.HasCaught()); | 12392 CHECK(try_catch.HasCaught()); |
10997 CHECK(v8_str("TypeError: Illegal invocation") | 12393 CHECK(v8_str("TypeError: Illegal invocation") |
10998 ->Equals(try_catch.Exception()->ToString(isolate))); | 12394 ->Equals(try_catch.Exception()->ToString(isolate))); |
10999 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); | 12395 CHECK_EQ(42, context->Global() |
12396 ->Get(v8_str("saved_result")) | |
12397 ->Int32Value(context.local()) | |
12398 .FromJust()); | |
11000 } | 12399 } |
11001 | 12400 |
11002 | 12401 |
11003 static void ThrowingGetter(Local<String> name, | 12402 static void ThrowingGetter(Local<String> name, |
11004 const v8::PropertyCallbackInfo<v8::Value>& info) { | 12403 const v8::PropertyCallbackInfo<v8::Value>& info) { |
11005 ApiTestFuzzer::Fuzz(); | 12404 ApiTestFuzzer::Fuzz(); |
11006 info.GetIsolate()->ThrowException(Handle<Value>()); | 12405 info.GetIsolate()->ThrowException(Local<Value>()); |
11007 info.GetReturnValue().SetUndefined(); | 12406 info.GetReturnValue().SetUndefined(); |
11008 } | 12407 } |
11009 | 12408 |
11010 | 12409 |
11011 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { | 12410 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { |
11012 LocalContext context; | 12411 LocalContext context; |
11013 HandleScope scope(context->GetIsolate()); | 12412 HandleScope scope(context->GetIsolate()); |
11014 | 12413 |
11015 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 12414 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
11016 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); | 12415 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); |
11017 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); | 12416 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); |
11018 | 12417 |
11019 Local<Object> instance = templ->GetFunction()->NewInstance(); | 12418 Local<Object> instance = templ->GetFunction(context.local()) |
12419 .ToLocalChecked() | |
12420 ->NewInstance(context.local()) | |
12421 .ToLocalChecked(); | |
11020 | 12422 |
11021 Local<Object> another = Object::New(context->GetIsolate()); | 12423 Local<Object> another = Object::New(context->GetIsolate()); |
11022 another->SetPrototype(instance); | 12424 another->SetPrototype(instance); |
11023 | 12425 |
11024 Local<Object> with_js_getter = CompileRun( | 12426 Local<Object> with_js_getter = CompileRun( |
11025 "o = {};\n" | 12427 "o = {};\n" |
11026 "o.__defineGetter__('f', function() { throw undefined; });\n" | 12428 "o.__defineGetter__('f', function() { throw undefined; });\n" |
11027 "o\n").As<Object>(); | 12429 "o\n").As<Object>(); |
11028 CHECK(!with_js_getter.IsEmpty()); | 12430 CHECK(!with_js_getter.IsEmpty()); |
11029 | 12431 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11087 CompileRun("throw 'from JS';"); | 12489 CompileRun("throw 'from JS';"); |
11088 CHECK(try_catch.HasCaught()); | 12490 CHECK(try_catch.HasCaught()); |
11089 CHECK(!CcTest::i_isolate()->has_pending_exception()); | 12491 CHECK(!CcTest::i_isolate()->has_pending_exception()); |
11090 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); | 12492 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); |
11091 } | 12493 } |
11092 | 12494 |
11093 | 12495 |
11094 static int call_depth; | 12496 static int call_depth; |
11095 | 12497 |
11096 | 12498 |
11097 static void WithTryCatch(Handle<Message> message, Handle<Value> data) { | 12499 static void WithTryCatch(Local<Message> message, Local<Value> data) { |
11098 TryCatch try_catch(CcTest::isolate()); | 12500 TryCatch try_catch(CcTest::isolate()); |
11099 } | 12501 } |
11100 | 12502 |
11101 | 12503 |
11102 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) { | 12504 static void ThrowFromJS(Local<Message> message, Local<Value> data) { |
11103 if (--call_depth) CompileRun("throw 'ThrowInJS';"); | 12505 if (--call_depth) CompileRun("throw 'ThrowInJS';"); |
11104 } | 12506 } |
11105 | 12507 |
11106 | 12508 |
11107 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) { | 12509 static void ThrowViaApi(Local<Message> message, Local<Value> data) { |
11108 if (--call_depth) CcTest::isolate()->ThrowException(v8_str("ThrowViaApi")); | 12510 if (--call_depth) CcTest::isolate()->ThrowException(v8_str("ThrowViaApi")); |
11109 } | 12511 } |
11110 | 12512 |
11111 | 12513 |
11112 static void WebKitLike(Handle<Message> message, Handle<Value> data) { | 12514 static void WebKitLike(Local<Message> message, Local<Value> data) { |
11113 Handle<String> errorMessageString = message->Get(); | 12515 Local<String> errorMessageString = message->Get(); |
11114 CHECK(!errorMessageString.IsEmpty()); | 12516 CHECK(!errorMessageString.IsEmpty()); |
11115 message->GetStackTrace(); | 12517 message->GetStackTrace(); |
11116 message->GetScriptOrigin().ResourceName(); | 12518 message->GetScriptOrigin().ResourceName(); |
11117 } | 12519 } |
11118 | 12520 |
11119 | 12521 |
11120 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { | 12522 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { |
11121 LocalContext context; | 12523 LocalContext context; |
11122 v8::Isolate* isolate = context->GetIsolate(); | 12524 v8::Isolate* isolate = context->GetIsolate(); |
11123 HandleScope scope(isolate); | 12525 HandleScope scope(isolate); |
11124 | 12526 |
11125 Local<Function> func = | 12527 Local<Function> func = |
11126 FunctionTemplate::New(isolate, | 12528 FunctionTemplate::New(isolate, ThrowingCallbackWithTryCatch) |
11127 ThrowingCallbackWithTryCatch)->GetFunction(); | 12529 ->GetFunction(context.local()) |
11128 context->Global()->Set(v8_str("func"), func); | 12530 .ToLocalChecked(); |
12531 CHECK( | |
12532 context->Global()->Set(context.local(), v8_str("func"), func).FromJust()); | |
11129 | 12533 |
11130 MessageCallback callbacks[] = | 12534 MessageCallback callbacks[] = |
11131 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; | 12535 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; |
11132 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { | 12536 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { |
11133 MessageCallback callback = callbacks[i]; | 12537 MessageCallback callback = callbacks[i]; |
11134 if (callback != NULL) { | 12538 if (callback != NULL) { |
11135 V8::AddMessageListener(callback); | 12539 V8::AddMessageListener(callback); |
11136 } | 12540 } |
11137 // Some small number to control number of times message handler should | 12541 // Some small number to control number of times message handler should |
11138 // throw an exception. | 12542 // throw an exception. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11182 // instances. | 12586 // instances. |
11183 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); | 12587 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); |
11184 // Add 'g' twice. The 'g' added last should get called for instances. | 12588 // Add 'g' twice. The 'g' added last should get called for instances. |
11185 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); | 12589 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); |
11186 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); | 12590 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); |
11187 | 12591 |
11188 // Add 'h' as an accessor to the proto template with ReadOnly attributes | 12592 // Add 'h' as an accessor to the proto template with ReadOnly attributes |
11189 // so 'h' can be shadowed on the instance object. | 12593 // so 'h' can be shadowed on the instance object. |
11190 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate(); | 12594 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate(); |
11191 child_proto_templ->SetAccessor(v8_str("h"), ParentGetter, 0, | 12595 child_proto_templ->SetAccessor(v8_str("h"), ParentGetter, 0, |
11192 v8::Handle<Value>(), v8::DEFAULT, v8::ReadOnly); | 12596 v8::Local<Value>(), v8::DEFAULT, v8::ReadOnly); |
11193 | 12597 |
11194 // Add 'i' as an accessor to the instance template with ReadOnly attributes | 12598 // Add 'i' as an accessor to the instance template with ReadOnly attributes |
11195 // but the attribute does not have effect because it is duplicated with | 12599 // but the attribute does not have effect because it is duplicated with |
11196 // NULL setter. | 12600 // NULL setter. |
11197 child_instance_templ->SetAccessor(v8_str("i"), ChildGetter, 0, | 12601 child_instance_templ->SetAccessor(v8_str("i"), ChildGetter, 0, |
11198 v8::Handle<Value>(), v8::DEFAULT, v8::ReadOnly); | 12602 v8::Local<Value>(), v8::DEFAULT, |
11199 | 12603 v8::ReadOnly); |
11200 | 12604 |
11201 | 12605 |
11202 // Instantiate the child template. | 12606 // Instantiate the child template. |
11203 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance(); | 12607 Local<v8::Object> instance = child_templ->GetFunction(context.local()) |
12608 .ToLocalChecked() | |
12609 ->NewInstance(context.local()) | |
12610 .ToLocalChecked(); | |
11204 | 12611 |
11205 // Check that the child function overrides the parent one. | 12612 // Check that the child function overrides the parent one. |
11206 context->Global()->Set(v8_str("o"), instance); | 12613 CHECK(context->Global() |
12614 ->Set(context.local(), v8_str("o"), instance) | |
12615 .FromJust()); | |
11207 Local<Value> value = v8_compile("o.f")->Run(); | 12616 Local<Value> value = v8_compile("o.f")->Run(); |
11208 // Check that the 'g' that was added last is hit. | 12617 // Check that the 'g' that was added last is hit. |
11209 CHECK_EQ(42, value->Int32Value()); | 12618 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
11210 value = v8_compile("o.g")->Run(); | 12619 value = v8_compile("o.g")->Run(); |
11211 CHECK_EQ(42, value->Int32Value()); | 12620 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
11212 | 12621 |
11213 // Check that 'h' cannot be shadowed. | 12622 // Check that 'h' cannot be shadowed. |
11214 value = v8_compile("o.h = 3; o.h")->Run(); | 12623 value = v8_compile("o.h = 3; o.h")->Run(); |
11215 CHECK_EQ(1, value->Int32Value()); | 12624 CHECK_EQ(1, value->Int32Value(context.local()).FromJust()); |
11216 | 12625 |
11217 // Check that 'i' cannot be shadowed or changed. | 12626 // Check that 'i' cannot be shadowed or changed. |
11218 value = v8_compile("o.i = 3; o.i")->Run(); | 12627 value = v8_compile("o.i = 3; o.i")->Run(); |
11219 CHECK_EQ(42, value->Int32Value()); | 12628 CHECK_EQ(42, value->Int32Value(context.local()).FromJust()); |
11220 } | 12629 } |
11221 | 12630 |
11222 | 12631 |
11223 static void IsConstructHandler( | 12632 static void IsConstructHandler( |
11224 const v8::FunctionCallbackInfo<v8::Value>& args) { | 12633 const v8::FunctionCallbackInfo<v8::Value>& args) { |
11225 ApiTestFuzzer::Fuzz(); | 12634 ApiTestFuzzer::Fuzz(); |
11226 args.GetReturnValue().Set(args.IsConstructCall()); | 12635 args.GetReturnValue().Set(args.IsConstructCall()); |
11227 } | 12636 } |
11228 | 12637 |
11229 | 12638 |
11230 THREADED_TEST(IsConstructCall) { | 12639 THREADED_TEST(IsConstructCall) { |
11231 v8::Isolate* isolate = CcTest::isolate(); | 12640 v8::Isolate* isolate = CcTest::isolate(); |
11232 v8::HandleScope scope(isolate); | 12641 v8::HandleScope scope(isolate); |
11233 | 12642 |
11234 // Function template with call handler. | 12643 // Function template with call handler. |
11235 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 12644 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
11236 templ->SetCallHandler(IsConstructHandler); | 12645 templ->SetCallHandler(IsConstructHandler); |
11237 | 12646 |
11238 LocalContext context; | 12647 LocalContext context; |
11239 | 12648 |
11240 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 12649 CHECK(context->Global() |
12650 ->Set(context.local(), v8_str("f"), | |
12651 templ->GetFunction(context.local()).ToLocalChecked()) | |
12652 .FromJust()); | |
11241 Local<Value> value = v8_compile("f()")->Run(); | 12653 Local<Value> value = v8_compile("f()")->Run(); |
11242 CHECK(!value->BooleanValue()); | 12654 CHECK(!value->BooleanValue()); |
11243 value = v8_compile("new f()")->Run(); | 12655 value = v8_compile("new f()")->Run(); |
11244 CHECK(value->BooleanValue()); | 12656 CHECK(value->BooleanValue()); |
11245 } | 12657 } |
11246 | 12658 |
11247 | 12659 |
11248 THREADED_TEST(ObjectProtoToString) { | 12660 THREADED_TEST(ObjectProtoToString) { |
11249 v8::Isolate* isolate = CcTest::isolate(); | 12661 v8::Isolate* isolate = CcTest::isolate(); |
11250 v8::HandleScope scope(isolate); | 12662 v8::HandleScope scope(isolate); |
11251 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); | 12663 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); |
11252 templ->SetClassName(v8_str("MyClass")); | 12664 templ->SetClassName(v8_str("MyClass")); |
11253 | 12665 |
11254 LocalContext context; | 12666 LocalContext context; |
11255 | 12667 |
11256 Local<String> customized_tostring = v8_str("customized toString"); | 12668 Local<String> customized_tostring = v8_str("customized toString"); |
11257 | 12669 |
11258 // Replace Object.prototype.toString | 12670 // Replace Object.prototype.toString |
11259 v8_compile("Object.prototype.toString = function() {" | 12671 v8_compile("Object.prototype.toString = function() {" |
11260 " return 'customized toString';" | 12672 " return 'customized toString';" |
11261 "}")->Run(); | 12673 "}")->Run(); |
11262 | 12674 |
11263 // Normal ToString call should call replaced Object.prototype.toString | 12675 // Normal ToString call should call replaced Object.prototype.toString |
11264 Local<v8::Object> instance = templ->GetFunction()->NewInstance(); | 12676 Local<v8::Object> instance = templ->GetFunction(context.local()) |
12677 .ToLocalChecked() | |
12678 ->NewInstance(context.local()) | |
12679 .ToLocalChecked(); | |
11265 Local<String> value = instance->ToString(isolate); | 12680 Local<String> value = instance->ToString(isolate); |
11266 CHECK(value->IsString() && value->Equals(customized_tostring)); | 12681 CHECK(value->IsString() && value->Equals(customized_tostring)); |
11267 | 12682 |
11268 // ObjectProtoToString should not call replace toString function. | 12683 // ObjectProtoToString should not call replace toString function. |
11269 value = instance->ObjectProtoToString(); | 12684 value = instance->ObjectProtoToString(); |
11270 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); | 12685 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); |
11271 | 12686 |
11272 // Check global | 12687 // Check global |
11273 value = context->Global()->ObjectProtoToString(); | 12688 value = context->Global()->ObjectProtoToString(); |
11274 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); | 12689 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); |
(...skipping 16 matching lines...) Expand all Loading... | |
11291 | 12706 |
11292 Local<String> customized_tostring = v8_str("customized toString"); | 12707 Local<String> customized_tostring = v8_str("customized toString"); |
11293 | 12708 |
11294 // Replace Object.prototype.toString | 12709 // Replace Object.prototype.toString |
11295 CompileRun( | 12710 CompileRun( |
11296 "Object.prototype.toString = function() {" | 12711 "Object.prototype.toString = function() {" |
11297 " return 'customized toString';" | 12712 " return 'customized toString';" |
11298 "}"); | 12713 "}"); |
11299 | 12714 |
11300 // Normal ToString call should call replaced Object.prototype.toString | 12715 // Normal ToString call should call replaced Object.prototype.toString |
11301 Local<v8::Object> instance = templ->GetFunction()->NewInstance(); | 12716 Local<v8::Object> instance = templ->GetFunction(context.local()) |
12717 .ToLocalChecked() | |
12718 ->NewInstance(context.local()) | |
12719 .ToLocalChecked(); | |
11302 Local<String> value = instance->ToString(isolate); | 12720 Local<String> value = instance->ToString(isolate); |
11303 CHECK(value->IsString() && value->Equals(customized_tostring)); | 12721 CHECK(value->IsString() && value->Equals(customized_tostring)); |
11304 | 12722 |
11305 // ObjectProtoToString should not call replace toString function. | 12723 // ObjectProtoToString should not call replace toString function. |
11306 value = instance->ObjectProtoToString(); | 12724 value = instance->ObjectProtoToString(); |
11307 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); | 12725 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); |
11308 | 12726 |
11309 // Check global | 12727 // Check global |
11310 value = context->Global()->ObjectProtoToString(); | 12728 value = context->Global()->ObjectProtoToString(); |
11311 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); | 12729 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11634 | 13052 |
11635 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { | 13053 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { |
11636 v8::Isolate* isolate = args.GetIsolate(); | 13054 v8::Isolate* isolate = args.GetIsolate(); |
11637 CHECK(v8::Locker::IsLocked(isolate)); | 13055 CHECK(v8::Locker::IsLocked(isolate)); |
11638 ApiTestFuzzer::Fuzz(); | 13056 ApiTestFuzzer::Fuzz(); |
11639 v8::Unlocker unlocker(isolate); | 13057 v8::Unlocker unlocker(isolate); |
11640 const char* code = "throw 7;"; | 13058 const char* code = "throw 7;"; |
11641 { | 13059 { |
11642 v8::Locker nested_locker(isolate); | 13060 v8::Locker nested_locker(isolate); |
11643 v8::HandleScope scope(isolate); | 13061 v8::HandleScope scope(isolate); |
11644 v8::Handle<Value> exception; | 13062 v8::Local<Value> exception; |
11645 { | 13063 { |
11646 v8::TryCatch try_catch(isolate); | 13064 v8::TryCatch try_catch(isolate); |
11647 v8::Handle<Value> value = CompileRun(code); | 13065 v8::Local<Value> value = CompileRun(code); |
11648 CHECK(value.IsEmpty()); | 13066 CHECK(value.IsEmpty()); |
11649 CHECK(try_catch.HasCaught()); | 13067 CHECK(try_catch.HasCaught()); |
11650 // Make sure to wrap the exception in a new handle because | 13068 // Make sure to wrap the exception in a new handle because |
11651 // the handle returned from the TryCatch is destroyed | 13069 // the handle returned from the TryCatch is destroyed |
11652 // when the TryCatch is destroyed. | 13070 // when the TryCatch is destroyed. |
11653 exception = Local<Value>::New(isolate, try_catch.Exception()); | 13071 exception = Local<Value>::New(isolate, try_catch.Exception()); |
11654 } | 13072 } |
11655 args.GetIsolate()->ThrowException(exception); | 13073 args.GetIsolate()->ThrowException(exception); |
11656 } | 13074 } |
11657 } | 13075 } |
11658 | 13076 |
11659 | 13077 |
11660 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { | 13078 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { |
11661 CHECK(v8::Locker::IsLocked(CcTest::isolate())); | 13079 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
11662 ApiTestFuzzer::Fuzz(); | 13080 ApiTestFuzzer::Fuzz(); |
11663 v8::Unlocker unlocker(CcTest::isolate()); | 13081 v8::Unlocker unlocker(CcTest::isolate()); |
11664 const char* code = "throw 7;"; | 13082 const char* code = "throw 7;"; |
11665 { | 13083 { |
11666 v8::Locker nested_locker(CcTest::isolate()); | 13084 v8::Locker nested_locker(CcTest::isolate()); |
11667 v8::HandleScope scope(args.GetIsolate()); | 13085 v8::HandleScope scope(args.GetIsolate()); |
11668 v8::Handle<Value> value = CompileRun(code); | 13086 v8::Local<Value> value = CompileRun(code); |
11669 CHECK(value.IsEmpty()); | 13087 CHECK(value.IsEmpty()); |
11670 args.GetReturnValue().Set(v8_str("foo")); | 13088 args.GetReturnValue().Set(v8_str("foo")); |
11671 } | 13089 } |
11672 } | 13090 } |
11673 | 13091 |
11674 | 13092 |
11675 // These are locking tests that don't need to be run again | 13093 // These are locking tests that don't need to be run again |
11676 // as part of the locking aggregation tests. | 13094 // as part of the locking aggregation tests. |
11677 TEST(NestedLockers) { | 13095 TEST(NestedLockers) { |
11678 v8::Isolate* isolate = CcTest::isolate(); | 13096 v8::Isolate* isolate = CcTest::isolate(); |
11679 v8::Locker locker(isolate); | 13097 v8::Locker locker(isolate); |
11680 CHECK(v8::Locker::IsLocked(isolate)); | 13098 CHECK(v8::Locker::IsLocked(isolate)); |
11681 LocalContext env; | 13099 LocalContext env; |
11682 v8::HandleScope scope(env->GetIsolate()); | 13100 v8::HandleScope scope(env->GetIsolate()); |
11683 Local<v8::FunctionTemplate> fun_templ = | 13101 Local<v8::FunctionTemplate> fun_templ = |
11684 v8::FunctionTemplate::New(isolate, ThrowInJS); | 13102 v8::FunctionTemplate::New(isolate, ThrowInJS); |
11685 Local<Function> fun = fun_templ->GetFunction(); | 13103 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
11686 env->Global()->Set(v8_str("throw_in_js"), fun); | 13104 CHECK(env->Global()->Set(env.local(), v8_str("throw_in_js"), fun).FromJust()); |
11687 Local<Script> script = v8_compile("(function () {" | 13105 Local<Script> script = v8_compile("(function () {" |
11688 " try {" | 13106 " try {" |
11689 " throw_in_js();" | 13107 " throw_in_js();" |
11690 " return 42;" | 13108 " return 42;" |
11691 " } catch (e) {" | 13109 " } catch (e) {" |
11692 " return e * 13;" | 13110 " return e * 13;" |
11693 " }" | 13111 " }" |
11694 "})();"); | 13112 "})();"); |
11695 CHECK_EQ(91, script->Run()->Int32Value()); | 13113 CHECK_EQ(91, script->Run()->Int32Value(env.local()).FromJust()); |
11696 } | 13114 } |
11697 | 13115 |
11698 | 13116 |
11699 // These are locking tests that don't need to be run again | 13117 // These are locking tests that don't need to be run again |
11700 // as part of the locking aggregation tests. | 13118 // as part of the locking aggregation tests. |
11701 TEST(NestedLockersNoTryCatch) { | 13119 TEST(NestedLockersNoTryCatch) { |
11702 v8::Locker locker(CcTest::isolate()); | 13120 v8::Locker locker(CcTest::isolate()); |
11703 LocalContext env; | 13121 LocalContext env; |
11704 v8::HandleScope scope(env->GetIsolate()); | 13122 v8::HandleScope scope(env->GetIsolate()); |
11705 Local<v8::FunctionTemplate> fun_templ = | 13123 Local<v8::FunctionTemplate> fun_templ = |
11706 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch); | 13124 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch); |
11707 Local<Function> fun = fun_templ->GetFunction(); | 13125 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
11708 env->Global()->Set(v8_str("throw_in_js"), fun); | 13126 CHECK(env->Global()->Set(env.local(), v8_str("throw_in_js"), fun).FromJust()); |
11709 Local<Script> script = v8_compile("(function () {" | 13127 Local<Script> script = v8_compile("(function () {" |
11710 " try {" | 13128 " try {" |
11711 " throw_in_js();" | 13129 " throw_in_js();" |
11712 " return 42;" | 13130 " return 42;" |
11713 " } catch (e) {" | 13131 " } catch (e) {" |
11714 " return e * 13;" | 13132 " return e * 13;" |
11715 " }" | 13133 " }" |
11716 "})();"); | 13134 "})();"); |
11717 CHECK_EQ(91, script->Run()->Int32Value()); | 13135 CHECK_EQ(91, script->Run()->Int32Value(env.local()).FromJust()); |
11718 } | 13136 } |
11719 | 13137 |
11720 | 13138 |
11721 THREADED_TEST(RecursiveLocking) { | 13139 THREADED_TEST(RecursiveLocking) { |
11722 v8::Locker locker(CcTest::isolate()); | 13140 v8::Locker locker(CcTest::isolate()); |
11723 { | 13141 { |
11724 v8::Locker locker2(CcTest::isolate()); | 13142 v8::Locker locker2(CcTest::isolate()); |
11725 CHECK(v8::Locker::IsLocked(CcTest::isolate())); | 13143 CHECK(v8::Locker::IsLocked(CcTest::isolate())); |
11726 } | 13144 } |
11727 } | 13145 } |
11728 | 13146 |
11729 | 13147 |
11730 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { | 13148 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { |
11731 ApiTestFuzzer::Fuzz(); | 13149 ApiTestFuzzer::Fuzz(); |
11732 v8::Unlocker unlocker(CcTest::isolate()); | 13150 v8::Unlocker unlocker(CcTest::isolate()); |
11733 } | 13151 } |
11734 | 13152 |
11735 | 13153 |
11736 THREADED_TEST(LockUnlockLock) { | 13154 THREADED_TEST(LockUnlockLock) { |
11737 { | 13155 { |
11738 v8::Locker locker(CcTest::isolate()); | 13156 v8::Locker locker(CcTest::isolate()); |
11739 v8::HandleScope scope(CcTest::isolate()); | 13157 v8::HandleScope scope(CcTest::isolate()); |
11740 LocalContext env; | 13158 LocalContext env; |
11741 Local<v8::FunctionTemplate> fun_templ = | 13159 Local<v8::FunctionTemplate> fun_templ = |
11742 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); | 13160 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); |
11743 Local<Function> fun = fun_templ->GetFunction(); | 13161 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
11744 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 13162 CHECK(env->Global() |
13163 ->Set(env.local(), v8_str("unlock_for_a_moment"), fun) | |
13164 .FromJust()); | |
11745 Local<Script> script = v8_compile("(function () {" | 13165 Local<Script> script = v8_compile("(function () {" |
11746 " unlock_for_a_moment();" | 13166 " unlock_for_a_moment();" |
11747 " return 42;" | 13167 " return 42;" |
11748 "})();"); | 13168 "})();"); |
11749 CHECK_EQ(42, script->Run()->Int32Value()); | 13169 CHECK_EQ(42, script->Run()->Int32Value(env.local()).FromJust()); |
11750 } | 13170 } |
11751 { | 13171 { |
11752 v8::Locker locker(CcTest::isolate()); | 13172 v8::Locker locker(CcTest::isolate()); |
11753 v8::HandleScope scope(CcTest::isolate()); | 13173 v8::HandleScope scope(CcTest::isolate()); |
11754 LocalContext env; | 13174 LocalContext env; |
11755 Local<v8::FunctionTemplate> fun_templ = | 13175 Local<v8::FunctionTemplate> fun_templ = |
11756 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); | 13176 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); |
11757 Local<Function> fun = fun_templ->GetFunction(); | 13177 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
11758 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); | 13178 CHECK(env->Global() |
13179 ->Set(env.local(), v8_str("unlock_for_a_moment"), fun) | |
13180 .FromJust()); | |
11759 Local<Script> script = v8_compile("(function () {" | 13181 Local<Script> script = v8_compile("(function () {" |
11760 " unlock_for_a_moment();" | 13182 " unlock_for_a_moment();" |
11761 " return 42;" | 13183 " return 42;" |
11762 "})();"); | 13184 "})();"); |
11763 CHECK_EQ(42, script->Run()->Int32Value()); | 13185 CHECK_EQ(42, script->Run()->Int32Value(env.local()).FromJust()); |
11764 } | 13186 } |
11765 } | 13187 } |
11766 | 13188 |
11767 | 13189 |
11768 static int GetGlobalObjectsCount() { | 13190 static int GetGlobalObjectsCount() { |
11769 int count = 0; | 13191 int count = 0; |
11770 i::HeapIterator it(CcTest::heap()); | 13192 i::HeapIterator it(CcTest::heap()); |
11771 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) | 13193 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) |
11772 if (object->IsJSGlobalObject()) { | 13194 if (object->IsJSGlobalObject()) { |
11773 i::JSGlobalObject* g = i::JSGlobalObject::cast(object); | 13195 i::JSGlobalObject* g = i::JSGlobalObject::cast(object); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12022 CompileRun(source); | 13444 CompileRun(source); |
12023 } | 13445 } |
12024 { v8::HandleScope scope(CcTest::isolate()); | 13446 { v8::HandleScope scope(CcTest::isolate()); |
12025 LocalContext context; | 13447 LocalContext context; |
12026 CompileRun(source); | 13448 CompileRun(source); |
12027 } | 13449 } |
12028 } | 13450 } |
12029 } | 13451 } |
12030 | 13452 |
12031 | 13453 |
12032 static v8::Handle<Value> NestedScope(v8::Local<Context> env) { | 13454 static v8::Local<Value> NestedScope(v8::Local<Context> env) { |
12033 v8::EscapableHandleScope inner(env->GetIsolate()); | 13455 v8::EscapableHandleScope inner(env->GetIsolate()); |
12034 env->Enter(); | 13456 env->Enter(); |
12035 v8::Local<Value> three = v8_num(3); | 13457 v8::Local<Value> three = v8_num(3); |
12036 v8::Local<Value> value = inner.Escape(three); | 13458 v8::Local<Value> value = inner.Escape(three); |
12037 env->Exit(); | 13459 env->Exit(); |
12038 return value; | 13460 return value; |
12039 } | 13461 } |
12040 | 13462 |
12041 | 13463 |
12042 THREADED_TEST(NestedHandleScopeAndContexts) { | 13464 THREADED_TEST(NestedHandleScopeAndContexts) { |
12043 v8::Isolate* isolate = CcTest::isolate(); | 13465 v8::Isolate* isolate = CcTest::isolate(); |
12044 v8::HandleScope outer(isolate); | 13466 v8::HandleScope outer(isolate); |
12045 v8::Local<Context> env = Context::New(isolate); | 13467 v8::Local<Context> env = Context::New(isolate); |
12046 env->Enter(); | 13468 env->Enter(); |
12047 v8::Handle<Value> value = NestedScope(env); | 13469 v8::Local<Value> value = NestedScope(env); |
12048 v8::Handle<String> str(value->ToString(isolate)); | 13470 v8::Local<String> str(value->ToString(isolate)); |
12049 CHECK(!str.IsEmpty()); | 13471 CHECK(!str.IsEmpty()); |
12050 env->Exit(); | 13472 env->Exit(); |
12051 } | 13473 } |
12052 | 13474 |
12053 | 13475 |
12054 static bool MatchPointers(void* key1, void* key2) { | 13476 static bool MatchPointers(void* key1, void* key2) { |
12055 return key1 == key2; | 13477 return key1 == key2; |
12056 } | 13478 } |
12057 | 13479 |
12058 | 13480 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12285 } | 13707 } |
12286 | 13708 |
12287 | 13709 |
12288 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { | 13710 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { |
12289 v8::HandleScope outer(isolate); | 13711 v8::HandleScope outer(isolate); |
12290 v8::Local<Context> env = Context::New(isolate); | 13712 v8::Local<Context> env = Context::New(isolate); |
12291 env->Enter(); | 13713 env->Enter(); |
12292 | 13714 |
12293 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); | 13715 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); |
12294 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); | 13716 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); |
12295 env->Global()->Set(v8_str("obj"), t->NewInstance()); | 13717 CHECK(env->Global() |
13718 ->Set(env, v8_str("obj"), t->NewInstance(env).ToLocalChecked()) | |
13719 .FromJust()); | |
12296 | 13720 |
12297 const char* script = | 13721 const char* script = |
12298 "function bar() {\n" | 13722 "function bar() {\n" |
12299 " var sum = 0;\n" | 13723 " var sum = 0;\n" |
12300 " for (i = 0; i < 100; ++i)\n" | 13724 " for (i = 0; i < 100; ++i)\n" |
12301 " sum = foo(i);\n" | 13725 " sum = foo(i);\n" |
12302 " return sum;\n" | 13726 " return sum;\n" |
12303 "}\n" | 13727 "}\n" |
12304 "function foo(i) { return i * i; }\n" | 13728 "function foo(i) { return i * i; }\n" |
12305 "// Invoke on the runtime function.\n" | 13729 "// Invoke on the runtime function.\n" |
12306 "obj.asdf()"; | 13730 "obj.asdf()"; |
12307 CompileRun(script); | 13731 CompileRun(script); |
12308 bar_func_ = i::Handle<i::JSFunction>::cast( | 13732 bar_func_ = i::Handle<i::JSFunction>::cast( |
12309 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar")))); | 13733 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar")))); |
12310 DCHECK(!bar_func_.is_null()); | 13734 DCHECK(!bar_func_.is_null()); |
12311 | 13735 |
12312 foo_func_ = | 13736 foo_func_ = |
12313 i::Handle<i::JSFunction>::cast( | 13737 i::Handle<i::JSFunction>::cast( |
12314 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo")))); | 13738 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo")))); |
12315 DCHECK(!foo_func_.is_null()); | 13739 DCHECK(!foo_func_.is_null()); |
12316 | 13740 |
12317 v8::Handle<v8::Value> value = CompileRun("bar();"); | 13741 v8::Local<v8::Value> value = CompileRun("bar();"); |
12318 CHECK(value->IsNumber()); | 13742 CHECK(value->IsNumber()); |
12319 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); | 13743 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
12320 | 13744 |
12321 // Test the optimized codegen path. | 13745 // Test the optimized codegen path. |
12322 value = CompileRun("%OptimizeFunctionOnNextCall(foo);" | 13746 value = CompileRun("%OptimizeFunctionOnNextCall(foo);" |
12323 "bar();"); | 13747 "bar();"); |
12324 CHECK(value->IsNumber()); | 13748 CHECK(value->IsNumber()); |
12325 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); | 13749 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); |
12326 | 13750 |
12327 env->Exit(); | 13751 env->Exit(); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12672 LocalContext context; | 14096 LocalContext context; |
12673 v8::Isolate* isolate = context->GetIsolate(); | 14097 v8::Isolate* isolate = context->GetIsolate(); |
12674 v8::HandleScope outer(isolate); | 14098 v8::HandleScope outer(isolate); |
12675 static v8::Persistent<v8::ObjectTemplate> templ; | 14099 static v8::Persistent<v8::ObjectTemplate> templ; |
12676 if (templ.IsEmpty()) { | 14100 if (templ.IsEmpty()) { |
12677 v8::EscapableHandleScope inner(isolate); | 14101 v8::EscapableHandleScope inner(isolate); |
12678 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate); | 14102 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate); |
12679 local->SetInternalFieldCount(1); | 14103 local->SetInternalFieldCount(1); |
12680 templ.Reset(isolate, inner.Escape(local)); | 14104 templ.Reset(isolate, inner.Escape(local)); |
12681 } | 14105 } |
12682 v8::Handle<v8::Object> result = | 14106 v8::Local<v8::Object> result = |
12683 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); | 14107 v8::Local<v8::ObjectTemplate>::New(isolate, templ) |
14108 ->NewInstance(context.local()) | |
14109 .ToLocalChecked(); | |
12684 CHECK_EQ(1, result->InternalFieldCount()); | 14110 CHECK_EQ(1, result->InternalFieldCount()); |
12685 } | 14111 } |
12686 | 14112 |
12687 | 14113 |
12688 // If part of the threaded tests, this test makes ThreadingTest fail | 14114 // If part of the threaded tests, this test makes ThreadingTest fail |
12689 // on mac. | 14115 // on mac. |
12690 TEST(CatchStackOverflow) { | 14116 TEST(CatchStackOverflow) { |
12691 LocalContext context; | 14117 LocalContext context; |
12692 v8::HandleScope scope(context->GetIsolate()); | 14118 v8::HandleScope scope(context->GetIsolate()); |
12693 v8::TryCatch try_catch(context->GetIsolate()); | 14119 v8::TryCatch try_catch(context->GetIsolate()); |
12694 v8::Handle<v8::Value> result = CompileRun( | 14120 v8::Local<v8::Value> result = CompileRun( |
12695 "function f() {" | 14121 "function f() {" |
12696 " return f();" | 14122 " return f();" |
12697 "}" | 14123 "}" |
12698 "" | 14124 "" |
12699 "f();"); | 14125 "f();"); |
12700 CHECK(result.IsEmpty()); | 14126 CHECK(result.IsEmpty()); |
12701 } | 14127 } |
12702 | 14128 |
12703 | 14129 |
12704 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, | 14130 static void CheckTryCatchSourceInfo(v8::Local<v8::Script> script, |
12705 const char* resource_name, | 14131 const char* resource_name, |
12706 int line_offset) { | 14132 int line_offset) { |
12707 v8::HandleScope scope(CcTest::isolate()); | 14133 v8::HandleScope scope(CcTest::isolate()); |
12708 v8::TryCatch try_catch(CcTest::isolate()); | 14134 v8::TryCatch try_catch(CcTest::isolate()); |
12709 v8::Handle<v8::Value> result = script->Run(); | 14135 v8::Local<v8::Value> result = script->Run(); |
12710 CHECK(result.IsEmpty()); | 14136 CHECK(result.IsEmpty()); |
12711 CHECK(try_catch.HasCaught()); | 14137 CHECK(try_catch.HasCaught()); |
12712 v8::Handle<v8::Message> message = try_catch.Message(); | 14138 v8::Local<v8::Message> message = try_catch.Message(); |
12713 CHECK(!message.IsEmpty()); | 14139 CHECK(!message.IsEmpty()); |
12714 CHECK_EQ(10 + line_offset, message->GetLineNumber()); | 14140 CHECK_EQ(10 + line_offset, message->GetLineNumber()); |
12715 CHECK_EQ(91, message->GetStartPosition()); | 14141 CHECK_EQ(91, message->GetStartPosition()); |
12716 CHECK_EQ(92, message->GetEndPosition()); | 14142 CHECK_EQ(92, message->GetEndPosition()); |
12717 CHECK_EQ(2, message->GetStartColumn()); | 14143 CHECK_EQ(2, message->GetStartColumn()); |
12718 CHECK_EQ(3, message->GetEndColumn()); | 14144 CHECK_EQ(3, message->GetEndColumn()); |
12719 v8::String::Utf8Value line(message->GetSourceLine()); | 14145 v8::String::Utf8Value line(message->GetSourceLine()); |
12720 CHECK_EQ(0, strcmp(" throw 'nirk';", *line)); | 14146 CHECK_EQ(0, strcmp(" throw 'nirk';", *line)); |
12721 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); | 14147 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); |
12722 CHECK_EQ(0, strcmp(resource_name, *name)); | 14148 CHECK_EQ(0, strcmp(resource_name, *name)); |
(...skipping 12 matching lines...) Expand all Loading... | |
12735 " return Baz();\n" | 14161 " return Baz();\n" |
12736 "}\n" | 14162 "}\n" |
12737 "\n" | 14163 "\n" |
12738 "function Baz() {\n" | 14164 "function Baz() {\n" |
12739 " throw 'nirk';\n" | 14165 " throw 'nirk';\n" |
12740 "}\n" | 14166 "}\n" |
12741 "\n" | 14167 "\n" |
12742 "Foo();\n"); | 14168 "Foo();\n"); |
12743 | 14169 |
12744 const char* resource_name; | 14170 const char* resource_name; |
12745 v8::Handle<v8::Script> script; | 14171 v8::Local<v8::Script> script; |
12746 resource_name = "test.js"; | 14172 resource_name = "test.js"; |
12747 script = CompileWithOrigin(source, resource_name); | 14173 script = CompileWithOrigin(source, resource_name); |
12748 CheckTryCatchSourceInfo(script, resource_name, 0); | 14174 CheckTryCatchSourceInfo(script, resource_name, 0); |
12749 | 14175 |
12750 resource_name = "test1.js"; | 14176 resource_name = "test1.js"; |
12751 v8::ScriptOrigin origin1( | 14177 v8::ScriptOrigin origin1(v8_str(resource_name)); |
12752 v8::String::NewFromUtf8(context->GetIsolate(), resource_name)); | |
12753 script = v8::Script::Compile(source, &origin1); | 14178 script = v8::Script::Compile(source, &origin1); |
12754 CheckTryCatchSourceInfo(script, resource_name, 0); | 14179 CheckTryCatchSourceInfo(script, resource_name, 0); |
12755 | 14180 |
12756 resource_name = "test2.js"; | 14181 resource_name = "test2.js"; |
12757 v8::ScriptOrigin origin2( | 14182 v8::ScriptOrigin origin2(v8_str(resource_name), |
12758 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), | 14183 v8::Integer::New(context->GetIsolate(), 7)); |
12759 v8::Integer::New(context->GetIsolate(), 7)); | |
12760 script = v8::Script::Compile(source, &origin2); | 14184 script = v8::Script::Compile(source, &origin2); |
12761 CheckTryCatchSourceInfo(script, resource_name, 7); | 14185 CheckTryCatchSourceInfo(script, resource_name, 7); |
12762 } | 14186 } |
12763 | 14187 |
12764 | 14188 |
12765 THREADED_TEST(TryCatchSourceInfoForEOSError) { | 14189 THREADED_TEST(TryCatchSourceInfoForEOSError) { |
12766 LocalContext context; | 14190 LocalContext context; |
12767 v8::HandleScope scope(context->GetIsolate()); | 14191 v8::HandleScope scope(context->GetIsolate()); |
12768 v8::TryCatch try_catch(context->GetIsolate()); | 14192 v8::TryCatch try_catch(context->GetIsolate()); |
12769 v8::Script::Compile(v8_str("!\n")); | 14193 v8::Script::Compile(v8_str("!\n")); |
12770 CHECK(try_catch.HasCaught()); | 14194 CHECK(try_catch.HasCaught()); |
12771 v8::Handle<v8::Message> message = try_catch.Message(); | 14195 v8::Local<v8::Message> message = try_catch.Message(); |
12772 CHECK_EQ(1, message->GetLineNumber()); | 14196 CHECK_EQ(1, message->GetLineNumber()); |
12773 CHECK_EQ(0, message->GetStartColumn()); | 14197 CHECK_EQ(0, message->GetStartColumn()); |
12774 } | 14198 } |
12775 | 14199 |
12776 | 14200 |
12777 THREADED_TEST(CompilationCache) { | 14201 THREADED_TEST(CompilationCache) { |
12778 LocalContext context; | 14202 LocalContext context; |
12779 v8::HandleScope scope(context->GetIsolate()); | 14203 v8::HandleScope scope(context->GetIsolate()); |
12780 v8::Handle<v8::String> source0 = | 14204 v8::Local<v8::String> source0 = v8_str("1234"); |
12781 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); | 14205 v8::Local<v8::String> source1 = v8_str("1234"); |
12782 v8::Handle<v8::String> source1 = | 14206 v8::Local<v8::Script> script0 = CompileWithOrigin(source0, "test.js"); |
12783 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); | 14207 v8::Local<v8::Script> script1 = CompileWithOrigin(source1, "test.js"); |
12784 v8::Handle<v8::Script> script0 = CompileWithOrigin(source0, "test.js"); | 14208 v8::Local<v8::Script> script2 = |
12785 v8::Handle<v8::Script> script1 = CompileWithOrigin(source1, "test.js"); | |
12786 v8::Handle<v8::Script> script2 = | |
12787 v8::Script::Compile(source0); // different origin | 14209 v8::Script::Compile(source0); // different origin |
12788 CHECK_EQ(1234, script0->Run()->Int32Value()); | 14210 CHECK_EQ(1234, script0->Run()->Int32Value(context.local()).FromJust()); |
12789 CHECK_EQ(1234, script1->Run()->Int32Value()); | 14211 CHECK_EQ(1234, script1->Run()->Int32Value(context.local()).FromJust()); |
12790 CHECK_EQ(1234, script2->Run()->Int32Value()); | 14212 CHECK_EQ(1234, script2->Run()->Int32Value(context.local()).FromJust()); |
12791 } | 14213 } |
12792 | 14214 |
12793 | 14215 |
12794 static void FunctionNameCallback( | 14216 static void FunctionNameCallback( |
12795 const v8::FunctionCallbackInfo<v8::Value>& args) { | 14217 const v8::FunctionCallbackInfo<v8::Value>& args) { |
12796 ApiTestFuzzer::Fuzz(); | 14218 ApiTestFuzzer::Fuzz(); |
12797 args.GetReturnValue().Set(v8_num(42)); | 14219 args.GetReturnValue().Set(v8_num(42)); |
12798 } | 14220 } |
12799 | 14221 |
12800 | 14222 |
12801 THREADED_TEST(CallbackFunctionName) { | 14223 THREADED_TEST(CallbackFunctionName) { |
12802 LocalContext context; | 14224 LocalContext context; |
12803 v8::Isolate* isolate = context->GetIsolate(); | 14225 v8::Isolate* isolate = context->GetIsolate(); |
12804 v8::HandleScope scope(isolate); | 14226 v8::HandleScope scope(isolate); |
12805 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); | 14227 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); |
12806 t->Set(v8_str("asdf"), | 14228 t->Set(v8_str("asdf"), |
12807 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); | 14229 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); |
12808 context->Global()->Set(v8_str("obj"), t->NewInstance()); | 14230 CHECK(context->Global() |
12809 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); | 14231 ->Set(context.local(), v8_str("obj"), |
14232 t->NewInstance(context.local()).ToLocalChecked()) | |
14233 .FromJust()); | |
14234 v8::Local<v8::Value> value = CompileRun("obj.asdf.name"); | |
12810 CHECK(value->IsString()); | 14235 CHECK(value->IsString()); |
12811 v8::String::Utf8Value name(value); | 14236 v8::String::Utf8Value name(value); |
12812 CHECK_EQ(0, strcmp("asdf", *name)); | 14237 CHECK_EQ(0, strcmp("asdf", *name)); |
12813 } | 14238 } |
12814 | 14239 |
12815 | 14240 |
12816 THREADED_TEST(DateAccess) { | 14241 THREADED_TEST(DateAccess) { |
12817 LocalContext context; | 14242 LocalContext context; |
12818 v8::HandleScope scope(context->GetIsolate()); | 14243 v8::HandleScope scope(context->GetIsolate()); |
12819 v8::Handle<v8::Value> date = | 14244 v8::Local<v8::Value> date = |
12820 v8::Date::New(context->GetIsolate(), 1224744689038.0); | 14245 v8::Date::New(context->GetIsolate(), 1224744689038.0); |
12821 CHECK(date->IsDate()); | 14246 CHECK(date->IsDate()); |
12822 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); | 14247 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); |
12823 } | 14248 } |
12824 | 14249 |
12825 | 14250 |
12826 void CheckProperties(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 14251 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, |
12827 unsigned elmc, const char* elmv[]) { | 14252 unsigned elmc, const char* elmv[]) { |
12828 v8::Handle<v8::Object> obj = val.As<v8::Object>(); | 14253 v8::Local<v8::Object> obj = val.As<v8::Object>(); |
12829 v8::Handle<v8::Array> props = obj->GetPropertyNames(); | 14254 v8::Local<v8::Array> props = obj->GetPropertyNames(); |
12830 CHECK_EQ(elmc, props->Length()); | 14255 CHECK_EQ(elmc, props->Length()); |
12831 for (unsigned i = 0; i < elmc; i++) { | 14256 for (unsigned i = 0; i < elmc; i++) { |
12832 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); | 14257 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); |
12833 CHECK_EQ(0, strcmp(elmv[i], *elm)); | 14258 CHECK_EQ(0, strcmp(elmv[i], *elm)); |
12834 } | 14259 } |
12835 } | 14260 } |
12836 | 14261 |
12837 | 14262 |
12838 void CheckOwnProperties(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 14263 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val, |
12839 unsigned elmc, const char* elmv[]) { | 14264 unsigned elmc, const char* elmv[]) { |
12840 v8::Handle<v8::Object> obj = val.As<v8::Object>(); | 14265 v8::Local<v8::Object> obj = val.As<v8::Object>(); |
12841 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); | 14266 v8::Local<v8::Array> props = obj->GetOwnPropertyNames(); |
12842 CHECK_EQ(elmc, props->Length()); | 14267 CHECK_EQ(elmc, props->Length()); |
12843 for (unsigned i = 0; i < elmc; i++) { | 14268 for (unsigned i = 0; i < elmc; i++) { |
12844 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); | 14269 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); |
12845 CHECK_EQ(0, strcmp(elmv[i], *elm)); | 14270 CHECK_EQ(0, strcmp(elmv[i], *elm)); |
12846 } | 14271 } |
12847 } | 14272 } |
12848 | 14273 |
12849 | 14274 |
12850 THREADED_TEST(PropertyEnumeration) { | 14275 THREADED_TEST(PropertyEnumeration) { |
12851 LocalContext context; | 14276 LocalContext context; |
12852 v8::Isolate* isolate = context->GetIsolate(); | 14277 v8::Isolate* isolate = context->GetIsolate(); |
12853 v8::HandleScope scope(isolate); | 14278 v8::HandleScope scope(isolate); |
12854 v8::Handle<v8::Value> obj = CompileRun( | 14279 v8::Local<v8::Value> obj = CompileRun( |
12855 "var result = [];" | 14280 "var result = [];" |
12856 "result[0] = {};" | 14281 "result[0] = {};" |
12857 "result[1] = {a: 1, b: 2};" | 14282 "result[1] = {a: 1, b: 2};" |
12858 "result[2] = [1, 2, 3];" | 14283 "result[2] = [1, 2, 3];" |
12859 "var proto = {x: 1, y: 2, z: 3};" | 14284 "var proto = {x: 1, y: 2, z: 3};" |
12860 "var x = { __proto__: proto, w: 0, z: 1 };" | 14285 "var x = { __proto__: proto, w: 0, z: 1 };" |
12861 "result[3] = x;" | 14286 "result[3] = x;" |
12862 "result;"); | 14287 "result;"); |
12863 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14288 v8::Local<v8::Array> elms = obj.As<v8::Array>(); |
12864 CHECK_EQ(4u, elms->Length()); | 14289 CHECK_EQ(4u, elms->Length()); |
12865 int elmc0 = 0; | 14290 int elmc0 = 0; |
12866 const char** elmv0 = NULL; | 14291 const char** elmv0 = NULL; |
12867 CheckProperties( | 14292 CheckProperties( |
12868 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14293 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
12869 CheckOwnProperties( | 14294 CheckOwnProperties( |
12870 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14295 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
12871 int elmc1 = 2; | 14296 int elmc1 = 2; |
12872 const char* elmv1[] = {"a", "b"}; | 14297 const char* elmv1[] = {"a", "b"}; |
12873 CheckProperties( | 14298 CheckProperties( |
(...skipping 14 matching lines...) Expand all Loading... | |
12888 const char* elmv4[] = {"w", "z"}; | 14313 const char* elmv4[] = {"w", "z"}; |
12889 CheckOwnProperties( | 14314 CheckOwnProperties( |
12890 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); | 14315 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); |
12891 } | 14316 } |
12892 | 14317 |
12893 | 14318 |
12894 THREADED_TEST(PropertyEnumeration2) { | 14319 THREADED_TEST(PropertyEnumeration2) { |
12895 LocalContext context; | 14320 LocalContext context; |
12896 v8::Isolate* isolate = context->GetIsolate(); | 14321 v8::Isolate* isolate = context->GetIsolate(); |
12897 v8::HandleScope scope(isolate); | 14322 v8::HandleScope scope(isolate); |
12898 v8::Handle<v8::Value> obj = CompileRun( | 14323 v8::Local<v8::Value> obj = CompileRun( |
12899 "var result = [];" | 14324 "var result = [];" |
12900 "result[0] = {};" | 14325 "result[0] = {};" |
12901 "result[1] = {a: 1, b: 2};" | 14326 "result[1] = {a: 1, b: 2};" |
12902 "result[2] = [1, 2, 3];" | 14327 "result[2] = [1, 2, 3];" |
12903 "var proto = {x: 1, y: 2, z: 3};" | 14328 "var proto = {x: 1, y: 2, z: 3};" |
12904 "var x = { __proto__: proto, w: 0, z: 1 };" | 14329 "var x = { __proto__: proto, w: 0, z: 1 };" |
12905 "result[3] = x;" | 14330 "result[3] = x;" |
12906 "result;"); | 14331 "result;"); |
12907 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); | 14332 v8::Local<v8::Array> elms = obj.As<v8::Array>(); |
12908 CHECK_EQ(4u, elms->Length()); | 14333 CHECK_EQ(4u, elms->Length()); |
12909 int elmc0 = 0; | 14334 int elmc0 = 0; |
12910 const char** elmv0 = NULL; | 14335 const char** elmv0 = NULL; |
12911 CheckProperties(isolate, | 14336 CheckProperties(isolate, |
12912 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); | 14337 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); |
12913 | 14338 |
12914 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); | 14339 v8::Local<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); |
12915 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); | 14340 v8::Local<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); |
12916 CHECK_EQ(0u, props->Length()); | 14341 CHECK_EQ(0u, props->Length()); |
12917 for (uint32_t i = 0; i < props->Length(); i++) { | 14342 for (uint32_t i = 0; i < props->Length(); i++) { |
12918 printf("p[%u]\n", i); | 14343 printf("p[%u]\n", i); |
12919 } | 14344 } |
12920 } | 14345 } |
12921 | 14346 |
12922 | 14347 |
12923 THREADED_TEST(AccessChecksReenabledCorrectly) { | 14348 THREADED_TEST(AccessChecksReenabledCorrectly) { |
12924 LocalContext context; | 14349 LocalContext context; |
12925 v8::Isolate* isolate = context->GetIsolate(); | 14350 v8::Isolate* isolate = context->GetIsolate(); |
(...skipping 10 matching lines...) Expand all Loading... | |
12936 for (char j = '0'; j <= '9'; j++) { | 14361 for (char j = '0'; j <= '9'; j++) { |
12937 buf[1] = j; | 14362 buf[1] = j; |
12938 for (char k = '0'; k <= '9'; k++) { | 14363 for (char k = '0'; k <= '9'; k++) { |
12939 buf[2] = k; | 14364 buf[2] = k; |
12940 buf[3] = 0; | 14365 buf[3] = 0; |
12941 templ->Set(v8_str(buf), v8::Number::New(isolate, k)); | 14366 templ->Set(v8_str(buf), v8::Number::New(isolate, k)); |
12942 } | 14367 } |
12943 } | 14368 } |
12944 } | 14369 } |
12945 | 14370 |
12946 Local<v8::Object> instance_1 = templ->NewInstance(); | 14371 Local<v8::Object> instance_1 = |
12947 context->Global()->Set(v8_str("obj_1"), instance_1); | 14372 templ->NewInstance(context.local()).ToLocalChecked(); |
14373 CHECK(context->Global() | |
14374 ->Set(context.local(), v8_str("obj_1"), instance_1) | |
14375 .FromJust()); | |
12948 | 14376 |
12949 Local<Value> value_1 = CompileRun("obj_1.a"); | 14377 Local<Value> value_1 = CompileRun("obj_1.a"); |
12950 CHECK(value_1.IsEmpty()); | 14378 CHECK(value_1.IsEmpty()); |
12951 | 14379 |
12952 Local<v8::Object> instance_2 = templ->NewInstance(); | 14380 Local<v8::Object> instance_2 = |
12953 context->Global()->Set(v8_str("obj_2"), instance_2); | 14381 templ->NewInstance(context.local()).ToLocalChecked(); |
14382 CHECK(context->Global() | |
14383 ->Set(context.local(), v8_str("obj_2"), instance_2) | |
14384 .FromJust()); | |
12954 | 14385 |
12955 Local<Value> value_2 = CompileRun("obj_2.a"); | 14386 Local<Value> value_2 = CompileRun("obj_2.a"); |
12956 CHECK(value_2.IsEmpty()); | 14387 CHECK(value_2.IsEmpty()); |
12957 } | 14388 } |
12958 | 14389 |
12959 | 14390 |
12960 // Tests that ScriptData can be serialized and deserialized. | 14391 // Tests that ScriptData can be serialized and deserialized. |
12961 TEST(PreCompileSerialization) { | 14392 TEST(PreCompileSerialization) { |
12962 v8::V8::Initialize(); | 14393 v8::V8::Initialize(); |
12963 LocalContext env; | 14394 LocalContext env; |
(...skipping 25 matching lines...) Expand all Loading... | |
12989 // This tests that we do not allow dictionary load/call inline caches | 14420 // This tests that we do not allow dictionary load/call inline caches |
12990 // to use functions that have not yet been compiled. The potential | 14421 // to use functions that have not yet been compiled. The potential |
12991 // problem of loading a function that has not yet been compiled can | 14422 // problem of loading a function that has not yet been compiled can |
12992 // arise because we share code between contexts via the compilation | 14423 // arise because we share code between contexts via the compilation |
12993 // cache. | 14424 // cache. |
12994 THREADED_TEST(DictionaryICLoadedFunction) { | 14425 THREADED_TEST(DictionaryICLoadedFunction) { |
12995 v8::HandleScope scope(CcTest::isolate()); | 14426 v8::HandleScope scope(CcTest::isolate()); |
12996 // Test LoadIC. | 14427 // Test LoadIC. |
12997 for (int i = 0; i < 2; i++) { | 14428 for (int i = 0; i < 2; i++) { |
12998 LocalContext context; | 14429 LocalContext context; |
12999 context->Global()->Set(v8_str("tmp"), v8::True(CcTest::isolate())); | 14430 CHECK(context->Global() |
14431 ->Set(context.local(), v8_str("tmp"), v8::True(CcTest::isolate())) | |
14432 .FromJust()); | |
13000 context->Global()->Delete(v8_str("tmp")); | 14433 context->Global()->Delete(v8_str("tmp")); |
13001 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 14434 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
13002 } | 14435 } |
13003 // Test CallIC. | 14436 // Test CallIC. |
13004 for (int i = 0; i < 2; i++) { | 14437 for (int i = 0; i < 2; i++) { |
13005 LocalContext context; | 14438 LocalContext context; |
13006 context->Global()->Set(v8_str("tmp"), v8::True(CcTest::isolate())); | 14439 CHECK(context->Global() |
14440 ->Set(context.local(), v8_str("tmp"), v8::True(CcTest::isolate())) | |
14441 .FromJust()); | |
13007 context->Global()->Delete(v8_str("tmp")); | 14442 context->Global()->Delete(v8_str("tmp")); |
13008 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 14443 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
13009 } | 14444 } |
13010 } | 14445 } |
13011 | 14446 |
13012 | 14447 |
13013 // Test that cross-context new calls use the context of the callee to | 14448 // Test that cross-context new calls use the context of the callee to |
13014 // create the new JavaScript object. | 14449 // create the new JavaScript object. |
13015 THREADED_TEST(CrossContextNew) { | 14450 THREADED_TEST(CrossContextNew) { |
13016 v8::Isolate* isolate = CcTest::isolate(); | 14451 v8::Isolate* isolate = CcTest::isolate(); |
13017 v8::HandleScope scope(isolate); | 14452 v8::HandleScope scope(isolate); |
13018 v8::Local<Context> context0 = Context::New(isolate); | 14453 v8::Local<Context> context0 = Context::New(isolate); |
13019 v8::Local<Context> context1 = Context::New(isolate); | 14454 v8::Local<Context> context1 = Context::New(isolate); |
13020 | 14455 |
13021 // Allow cross-domain access. | 14456 // Allow cross-domain access. |
13022 Local<String> token = v8_str("<security token>"); | 14457 Local<String> token = v8_str("<security token>"); |
13023 context0->SetSecurityToken(token); | 14458 context0->SetSecurityToken(token); |
13024 context1->SetSecurityToken(token); | 14459 context1->SetSecurityToken(token); |
13025 | 14460 |
13026 // Set an 'x' property on the Object prototype and define a | 14461 // Set an 'x' property on the Object prototype and define a |
13027 // constructor function in context0. | 14462 // constructor function in context0. |
13028 context0->Enter(); | 14463 context0->Enter(); |
13029 CompileRun("Object.prototype.x = 42; function C() {};"); | 14464 CompileRun("Object.prototype.x = 42; function C() {};"); |
13030 context0->Exit(); | 14465 context0->Exit(); |
13031 | 14466 |
13032 // Call the constructor function from context0 and check that the | 14467 // Call the constructor function from context0 and check that the |
13033 // result has the 'x' property. | 14468 // result has the 'x' property. |
13034 context1->Enter(); | 14469 context1->Enter(); |
13035 context1->Global()->Set(v8_str("other"), context0->Global()); | 14470 CHECK(context1->Global() |
14471 ->Set(context1, v8_str("other"), context0->Global()) | |
14472 .FromJust()); | |
13036 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); | 14473 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
13037 CHECK(value->IsInt32()); | 14474 CHECK(value->IsInt32()); |
13038 CHECK_EQ(42, value->Int32Value()); | 14475 CHECK_EQ(42, value->Int32Value(context1).FromJust()); |
13039 context1->Exit(); | 14476 context1->Exit(); |
13040 } | 14477 } |
13041 | 14478 |
13042 | 14479 |
13043 // Verify that we can clone an object | 14480 // Verify that we can clone an object |
13044 TEST(ObjectClone) { | 14481 TEST(ObjectClone) { |
13045 LocalContext env; | 14482 LocalContext env; |
13046 v8::Isolate* isolate = env->GetIsolate(); | 14483 v8::Isolate* isolate = env->GetIsolate(); |
13047 v8::HandleScope scope(isolate); | 14484 v8::HandleScope scope(isolate); |
13048 | 14485 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13139 i::Vector<const uint16_t>(two_byte_string, | 14576 i::Vector<const uint16_t>(two_byte_string, |
13140 i::StrLength(c_string))); | 14577 i::StrLength(c_string))); |
13141 | 14578 |
13142 Local<String> lhs( | 14579 Local<String> lhs( |
13143 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( | 14580 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( |
13144 &one_byte_resource).ToHandleChecked())); | 14581 &one_byte_resource).ToHandleChecked())); |
13145 Local<String> rhs( | 14582 Local<String> rhs( |
13146 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( | 14583 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( |
13147 &one_byte_resource).ToHandleChecked())); | 14584 &one_byte_resource).ToHandleChecked())); |
13148 | 14585 |
13149 env->Global()->Set(v8_str("lhs"), lhs); | 14586 CHECK(env->Global()->Set(env.local(), v8_str("lhs"), lhs).FromJust()); |
13150 env->Global()->Set(v8_str("rhs"), rhs); | 14587 CHECK(env->Global()->Set(env.local(), v8_str("rhs"), rhs).FromJust()); |
13151 | 14588 |
13152 CompileRun( | 14589 CompileRun( |
13153 "var cons = lhs + rhs;" | 14590 "var cons = lhs + rhs;" |
13154 "var slice = lhs.substring(1, lhs.length - 1);" | 14591 "var slice = lhs.substring(1, lhs.length - 1);" |
13155 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);"); | 14592 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);"); |
13156 | 14593 |
13157 CHECK(lhs->IsOneByte()); | 14594 CHECK(lhs->IsOneByte()); |
13158 CHECK(rhs->IsOneByte()); | 14595 CHECK(rhs->IsOneByte()); |
13159 | 14596 |
13160 MorphAString(*v8::Utils::OpenHandle(*lhs), &one_byte_resource, | 14597 MorphAString(*v8::Utils::OpenHandle(*lhs), &one_byte_resource, |
13161 &uc16_resource); | 14598 &uc16_resource); |
13162 MorphAString(*v8::Utils::OpenHandle(*rhs), &one_byte_resource, | 14599 MorphAString(*v8::Utils::OpenHandle(*rhs), &one_byte_resource, |
13163 &uc16_resource); | 14600 &uc16_resource); |
13164 | 14601 |
13165 // This should UTF-8 without flattening, since everything is ASCII. | 14602 // This should UTF-8 without flattening, since everything is ASCII. |
13166 Handle<String> cons = v8_compile("cons")->Run().As<String>(); | 14603 Local<String> cons = v8_compile("cons")->Run().As<String>(); |
13167 CHECK_EQ(128, cons->Utf8Length()); | 14604 CHECK_EQ(128, cons->Utf8Length()); |
13168 int nchars = -1; | 14605 int nchars = -1; |
13169 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars)); | 14606 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars)); |
13170 CHECK_EQ(128, nchars); | 14607 CHECK_EQ(128, nchars); |
13171 CHECK_EQ(0, strcmp( | 14608 CHECK_EQ(0, strcmp( |
13172 utf_buffer, | 14609 utf_buffer, |
13173 "Now is the time for all good men to come to the aid of the party" | 14610 "Now is the time for all good men to come to the aid of the party" |
13174 "Now is the time for all good men to come to the aid of the party")); | 14611 "Now is the time for all good men to come to the aid of the party")); |
13175 | 14612 |
13176 // Now do some stuff to make sure the strings are flattened, etc. | 14613 // Now do some stuff to make sure the strings are flattened, etc. |
13177 CompileRun( | 14614 CompileRun( |
13178 "/[^a-z]/.test(cons);" | 14615 "/[^a-z]/.test(cons);" |
13179 "/[^a-z]/.test(slice);" | 14616 "/[^a-z]/.test(slice);" |
13180 "/[^a-z]/.test(slice_on_cons);"); | 14617 "/[^a-z]/.test(slice_on_cons);"); |
13181 const char* expected_cons = | 14618 const char* expected_cons = |
13182 "Now is the time for all good men to come to the aid of the party" | 14619 "Now is the time for all good men to come to the aid of the party" |
13183 "Now is the time for all good men to come to the aid of the party"; | 14620 "Now is the time for all good men to come to the aid of the party"; |
13184 const char* expected_slice = | 14621 const char* expected_slice = |
13185 "ow is the time for all good men to come to the aid of the part"; | 14622 "ow is the time for all good men to come to the aid of the part"; |
13186 const char* expected_slice_on_cons = | 14623 const char* expected_slice_on_cons = |
13187 "ow is the time for all good men to come to the aid of the party" | 14624 "ow is the time for all good men to come to the aid of the party" |
13188 "Now is the time for all good men to come to the aid of the part"; | 14625 "Now is the time for all good men to come to the aid of the part"; |
13189 CHECK(String::NewFromUtf8(env->GetIsolate(), expected_cons) | 14626 CHECK(v8_str(expected_cons)->Equals(env->Global()->Get(v8_str("cons")))); |
13190 ->Equals(env->Global()->Get(v8_str("cons")))); | 14627 CHECK(v8_str(expected_slice)->Equals(env->Global()->Get(v8_str("slice")))); |
13191 CHECK(String::NewFromUtf8(env->GetIsolate(), expected_slice) | 14628 CHECK(v8_str(expected_slice_on_cons) |
13192 ->Equals(env->Global()->Get(v8_str("slice")))); | |
13193 CHECK(String::NewFromUtf8(env->GetIsolate(), expected_slice_on_cons) | |
13194 ->Equals(env->Global()->Get(v8_str("slice_on_cons")))); | 14629 ->Equals(env->Global()->Get(v8_str("slice_on_cons")))); |
13195 } | 14630 } |
13196 i::DeleteArray(two_byte_string); | 14631 i::DeleteArray(two_byte_string); |
13197 } | 14632 } |
13198 | 14633 |
13199 | 14634 |
13200 TEST(CompileExternalTwoByteSource) { | 14635 TEST(CompileExternalTwoByteSource) { |
13201 LocalContext context; | 14636 LocalContext context; |
13202 v8::HandleScope scope(context->GetIsolate()); | 14637 v8::HandleScope scope(context->GetIsolate()); |
13203 | 14638 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13297 } | 14732 } |
13298 | 14733 |
13299 #endif // V8_INTERPRETED_REGEXP | 14734 #endif // V8_INTERPRETED_REGEXP |
13300 | 14735 |
13301 | 14736 |
13302 // Test that we cannot set a property on the global object if there | 14737 // Test that we cannot set a property on the global object if there |
13303 // is a read-only property in the prototype chain. | 14738 // is a read-only property in the prototype chain. |
13304 TEST(ReadOnlyPropertyInGlobalProto) { | 14739 TEST(ReadOnlyPropertyInGlobalProto) { |
13305 v8::Isolate* isolate = CcTest::isolate(); | 14740 v8::Isolate* isolate = CcTest::isolate(); |
13306 v8::HandleScope scope(isolate); | 14741 v8::HandleScope scope(isolate); |
13307 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 14742 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
13308 LocalContext context(0, templ); | 14743 LocalContext context(0, templ); |
13309 v8::Handle<v8::Object> global = context->Global(); | 14744 v8::Local<v8::Object> global = context->Global(); |
13310 v8::Handle<v8::Object> global_proto = | 14745 v8::Local<v8::Object> global_proto = |
13311 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); | 14746 v8::Local<v8::Object>::Cast(global->Get(v8_str("__proto__"))); |
13312 global_proto->ForceSet(v8_str("x"), v8::Integer::New(isolate, 0), | 14747 global_proto->ForceSet(v8_str("x"), v8::Integer::New(isolate, 0), |
13313 v8::ReadOnly); | 14748 v8::ReadOnly); |
13314 global_proto->ForceSet(v8_str("y"), v8::Integer::New(isolate, 0), | 14749 global_proto->ForceSet(v8_str("y"), v8::Integer::New(isolate, 0), |
13315 v8::ReadOnly); | 14750 v8::ReadOnly); |
13316 // Check without 'eval' or 'with'. | 14751 // Check without 'eval' or 'with'. |
13317 v8::Handle<v8::Value> res = | 14752 v8::Local<v8::Value> res = |
13318 CompileRun("function f() { x = 42; return x; }; f()"); | 14753 CompileRun("function f() { x = 42; return x; }; f()"); |
13319 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); | 14754 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); |
13320 // Check with 'eval'. | 14755 // Check with 'eval'. |
13321 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); | 14756 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); |
13322 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); | 14757 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); |
13323 // Check with 'with'. | 14758 // Check with 'with'. |
13324 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); | 14759 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); |
13325 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); | 14760 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); |
13326 } | 14761 } |
13327 | 14762 |
(...skipping 30 matching lines...) Expand all Loading... | |
13358 } | 14793 } |
13359 | 14794 |
13360 | 14795 |
13361 TEST(ForceSet) { | 14796 TEST(ForceSet) { |
13362 force_set_get_count = 0; | 14797 force_set_get_count = 0; |
13363 force_set_set_count = 0; | 14798 force_set_set_count = 0; |
13364 pass_on_get = false; | 14799 pass_on_get = false; |
13365 | 14800 |
13366 v8::Isolate* isolate = CcTest::isolate(); | 14801 v8::Isolate* isolate = CcTest::isolate(); |
13367 v8::HandleScope scope(isolate); | 14802 v8::HandleScope scope(isolate); |
13368 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 14803 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
13369 v8::Handle<v8::String> access_property = | 14804 v8::Local<v8::String> access_property = v8_str("a"); |
13370 v8::String::NewFromUtf8(isolate, "a"); | |
13371 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); | 14805 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); |
13372 LocalContext context(NULL, templ); | 14806 LocalContext context(NULL, templ); |
13373 v8::Handle<v8::Object> global = context->Global(); | 14807 v8::Local<v8::Object> global = context->Global(); |
13374 | 14808 |
13375 // Ordinary properties | 14809 // Ordinary properties |
13376 v8::Handle<v8::String> simple_property = | 14810 v8::Local<v8::String> simple_property = v8_str("p"); |
13377 v8::String::NewFromUtf8(isolate, "p"); | |
13378 global->ForceSet(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); | 14811 global->ForceSet(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly); |
13379 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 14812 CHECK_EQ( |
14813 4, global->Get(simple_property)->Int32Value(context.local()).FromJust()); | |
13380 // This should fail because the property is read-only | 14814 // This should fail because the property is read-only |
13381 global->Set(simple_property, v8::Int32::New(isolate, 5)); | 14815 global->Set(simple_property, v8::Int32::New(isolate, 5)); |
13382 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); | 14816 CHECK_EQ( |
14817 4, global->Get(simple_property)->Int32Value(context.local()).FromJust()); | |
13383 // This should succeed even though the property is read-only | 14818 // This should succeed even though the property is read-only |
13384 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); | 14819 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); |
13385 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); | 14820 CHECK_EQ( |
14821 6, global->Get(simple_property)->Int32Value(context.local()).FromJust()); | |
13386 | 14822 |
13387 // Accessors | 14823 // Accessors |
13388 CHECK_EQ(0, force_set_set_count); | 14824 CHECK_EQ(0, force_set_set_count); |
13389 CHECK_EQ(0, force_set_get_count); | 14825 CHECK_EQ(0, force_set_get_count); |
13390 CHECK_EQ(3, global->Get(access_property)->Int32Value()); | 14826 CHECK_EQ( |
14827 3, global->Get(access_property)->Int32Value(context.local()).FromJust()); | |
13391 // CHECK_EQ the property shouldn't override it, just call the setter | 14828 // CHECK_EQ the property shouldn't override it, just call the setter |
13392 // which in this case does nothing. | 14829 // which in this case does nothing. |
13393 global->Set(access_property, v8::Int32::New(isolate, 7)); | 14830 global->Set(access_property, v8::Int32::New(isolate, 7)); |
13394 CHECK_EQ(3, global->Get(access_property)->Int32Value()); | 14831 CHECK_EQ( |
14832 3, global->Get(access_property)->Int32Value(context.local()).FromJust()); | |
13395 CHECK_EQ(1, force_set_set_count); | 14833 CHECK_EQ(1, force_set_set_count); |
13396 CHECK_EQ(2, force_set_get_count); | 14834 CHECK_EQ(2, force_set_get_count); |
13397 // ForceSet doesn't call the accessors for now. | 14835 // ForceSet doesn't call the accessors for now. |
13398 // TODO(verwaest): Update once blink doesn't rely on ForceSet to delete api | 14836 // TODO(verwaest): Update once blink doesn't rely on ForceSet to delete api |
13399 // accessors. | 14837 // accessors. |
13400 global->ForceSet(access_property, v8::Int32::New(isolate, 8)); | 14838 global->ForceSet(access_property, v8::Int32::New(isolate, 8)); |
13401 CHECK_EQ(8, global->Get(access_property)->Int32Value()); | 14839 CHECK_EQ( |
14840 8, global->Get(access_property)->Int32Value(context.local()).FromJust()); | |
13402 CHECK_EQ(1, force_set_set_count); | 14841 CHECK_EQ(1, force_set_set_count); |
13403 CHECK_EQ(2, force_set_get_count); | 14842 CHECK_EQ(2, force_set_get_count); |
13404 } | 14843 } |
13405 | 14844 |
13406 | 14845 |
13407 TEST(ForceSetWithInterceptor) { | 14846 TEST(ForceSetWithInterceptor) { |
13408 v8::Isolate* isolate = CcTest::isolate(); | 14847 v8::Isolate* isolate = CcTest::isolate(); |
13409 v8::HandleScope scope(isolate); | 14848 v8::HandleScope scope(isolate); |
13410 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 14849 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
13411 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 14850 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
13412 ForceSetInterceptGetter, ForceSetInterceptSetter)); | 14851 ForceSetInterceptGetter, ForceSetInterceptSetter)); |
13413 pass_on_get = true; | 14852 pass_on_get = true; |
13414 LocalContext context(NULL, templ); | 14853 LocalContext context(NULL, templ); |
13415 v8::Handle<v8::Object> global = context->Global(); | 14854 v8::Local<v8::Object> global = context->Global(); |
13416 | 14855 |
13417 force_set_get_count = 0; | 14856 force_set_get_count = 0; |
13418 force_set_set_count = 0; | 14857 force_set_set_count = 0; |
13419 pass_on_get = false; | 14858 pass_on_get = false; |
13420 | 14859 |
13421 v8::Handle<v8::String> some_property = | 14860 v8::Local<v8::String> some_property = v8_str("a"); |
13422 v8::String::NewFromUtf8(isolate, "a"); | |
13423 CHECK_EQ(0, force_set_set_count); | 14861 CHECK_EQ(0, force_set_set_count); |
13424 CHECK_EQ(0, force_set_get_count); | 14862 CHECK_EQ(0, force_set_get_count); |
13425 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 14863 CHECK_EQ(3, |
14864 global->Get(some_property)->Int32Value(context.local()).FromJust()); | |
13426 // Setting the property shouldn't override it, just call the setter | 14865 // Setting the property shouldn't override it, just call the setter |
13427 // which in this case does nothing. | 14866 // which in this case does nothing. |
13428 global->Set(some_property, v8::Int32::New(isolate, 7)); | 14867 global->Set(some_property, v8::Int32::New(isolate, 7)); |
13429 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 14868 CHECK_EQ(3, |
14869 global->Get(some_property)->Int32Value(context.local()).FromJust()); | |
13430 CHECK_EQ(1, force_set_set_count); | 14870 CHECK_EQ(1, force_set_set_count); |
13431 CHECK_EQ(2, force_set_get_count); | 14871 CHECK_EQ(2, force_set_get_count); |
13432 // Getting the property when the interceptor returns an empty handle | 14872 // Getting the property when the interceptor returns an empty handle |
13433 // should yield undefined, since the property isn't present on the | 14873 // should yield undefined, since the property isn't present on the |
13434 // object itself yet. | 14874 // object itself yet. |
13435 pass_on_get = true; | 14875 pass_on_get = true; |
13436 CHECK(global->Get(some_property)->IsUndefined()); | 14876 CHECK(global->Get(some_property)->IsUndefined()); |
13437 CHECK_EQ(1, force_set_set_count); | 14877 CHECK_EQ(1, force_set_set_count); |
13438 CHECK_EQ(3, force_set_get_count); | 14878 CHECK_EQ(3, force_set_get_count); |
13439 // Forcing the property to be set should cause the value to be | 14879 // Forcing the property to be set should cause the value to be |
13440 // set locally without calling the interceptor. | 14880 // set locally without calling the interceptor. |
13441 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); | 14881 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); |
13442 CHECK_EQ(8, global->Get(some_property)->Int32Value()); | 14882 CHECK_EQ(8, |
14883 global->Get(some_property)->Int32Value(context.local()).FromJust()); | |
13443 CHECK_EQ(1, force_set_set_count); | 14884 CHECK_EQ(1, force_set_set_count); |
13444 CHECK_EQ(4, force_set_get_count); | 14885 CHECK_EQ(4, force_set_get_count); |
13445 // Reenabling the interceptor should cause it to take precedence over | 14886 // Reenabling the interceptor should cause it to take precedence over |
13446 // the property | 14887 // the property |
13447 pass_on_get = false; | 14888 pass_on_get = false; |
13448 CHECK_EQ(3, global->Get(some_property)->Int32Value()); | 14889 CHECK_EQ(3, |
14890 global->Get(some_property)->Int32Value(context.local()).FromJust()); | |
13449 CHECK_EQ(1, force_set_set_count); | 14891 CHECK_EQ(1, force_set_set_count); |
13450 CHECK_EQ(5, force_set_get_count); | 14892 CHECK_EQ(5, force_set_get_count); |
13451 // The interceptor should also work for other properties | 14893 // The interceptor should also work for other properties |
13452 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) | 14894 CHECK_EQ(3, global->Get(v8_str("b"))->Int32Value(context.local()).FromJust()); |
13453 ->Int32Value()); | |
13454 CHECK_EQ(1, force_set_set_count); | 14895 CHECK_EQ(1, force_set_set_count); |
13455 CHECK_EQ(6, force_set_get_count); | 14896 CHECK_EQ(6, force_set_get_count); |
13456 } | 14897 } |
13457 | 14898 |
13458 | 14899 |
13459 TEST(CreateDataProperty) { | 14900 TEST(CreateDataProperty) { |
13460 LocalContext env; | 14901 LocalContext env; |
13461 v8::Isolate* isolate = env->GetIsolate(); | 14902 v8::Isolate* isolate = env->GetIsolate(); |
13462 v8::HandleScope handle_scope(isolate); | 14903 v8::HandleScope handle_scope(isolate); |
13463 | 14904 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13690 } | 15131 } |
13691 | 15132 |
13692 | 15133 |
13693 // Check that a variable declaration with no explicit initialization | 15134 // Check that a variable declaration with no explicit initialization |
13694 // value does shadow an existing property in the prototype chain. | 15135 // value does shadow an existing property in the prototype chain. |
13695 THREADED_TEST(InitGlobalVarInProtoChain) { | 15136 THREADED_TEST(InitGlobalVarInProtoChain) { |
13696 LocalContext context; | 15137 LocalContext context; |
13697 v8::HandleScope scope(context->GetIsolate()); | 15138 v8::HandleScope scope(context->GetIsolate()); |
13698 // Introduce a variable in the prototype chain. | 15139 // Introduce a variable in the prototype chain. |
13699 CompileRun("__proto__.x = 42"); | 15140 CompileRun("__proto__.x = 42"); |
13700 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); | 15141 v8::Local<v8::Value> result = CompileRun("var x = 43; x"); |
13701 CHECK(!result->IsUndefined()); | 15142 CHECK(!result->IsUndefined()); |
13702 CHECK_EQ(43, result->Int32Value()); | 15143 CHECK_EQ(43, result->Int32Value(context.local()).FromJust()); |
13703 } | 15144 } |
13704 | 15145 |
13705 | 15146 |
13706 // Regression test for issue 398. | 15147 // Regression test for issue 398. |
13707 // If a function is added to an object, creating a constant function | 15148 // If a function is added to an object, creating a constant function |
13708 // field, and the result is cloned, replacing the constant function on the | 15149 // field, and the result is cloned, replacing the constant function on the |
13709 // original should not affect the clone. | 15150 // original should not affect the clone. |
13710 // See http://code.google.com/p/v8/issues/detail?id=398 | 15151 // See http://code.google.com/p/v8/issues/detail?id=398 |
13711 THREADED_TEST(ReplaceConstantFunction) { | 15152 THREADED_TEST(ReplaceConstantFunction) { |
13712 LocalContext context; | 15153 LocalContext context; |
13713 v8::Isolate* isolate = context->GetIsolate(); | 15154 v8::Isolate* isolate = context->GetIsolate(); |
13714 v8::HandleScope scope(isolate); | 15155 v8::HandleScope scope(isolate); |
13715 v8::Handle<v8::Object> obj = v8::Object::New(isolate); | 15156 v8::Local<v8::Object> obj = v8::Object::New(isolate); |
13716 v8::Handle<v8::FunctionTemplate> func_templ = | 15157 v8::Local<v8::FunctionTemplate> func_templ = |
13717 v8::FunctionTemplate::New(isolate); | 15158 v8::FunctionTemplate::New(isolate); |
13718 v8::Handle<v8::String> foo_string = | 15159 v8::Local<v8::String> foo_string = v8_str("foo"); |
13719 v8::String::NewFromUtf8(isolate, "foo"); | 15160 obj->Set(foo_string, |
13720 obj->Set(foo_string, func_templ->GetFunction()); | 15161 func_templ->GetFunction(context.local()).ToLocalChecked()); |
13721 v8::Handle<v8::Object> obj_clone = obj->Clone(); | 15162 v8::Local<v8::Object> obj_clone = obj->Clone(); |
13722 obj_clone->Set(foo_string, | 15163 obj_clone->Set(foo_string, v8_str("Hello")); |
13723 v8::String::NewFromUtf8(isolate, "Hello")); | |
13724 CHECK(!obj->Get(foo_string)->IsUndefined()); | 15164 CHECK(!obj->Get(foo_string)->IsUndefined()); |
13725 } | 15165 } |
13726 | 15166 |
13727 | 15167 |
13728 static void CheckElementValue(i::Isolate* isolate, | 15168 static void CheckElementValue(i::Isolate* isolate, |
13729 int expected, | 15169 int expected, |
13730 i::Handle<i::Object> obj, | 15170 i::Handle<i::Object> obj, |
13731 int offset) { | 15171 int offset) { |
13732 i::Object* element = | 15172 i::Object* element = |
13733 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked(); | 15173 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked(); |
13734 CHECK_EQ(expected, i::Smi::cast(element)->value()); | 15174 CHECK_EQ(expected, i::Smi::cast(element)->value()); |
13735 } | 15175 } |
13736 | 15176 |
13737 | 15177 |
13738 template <class ExternalArrayClass, class ElementType> | 15178 template <class ExternalArrayClass, class ElementType> |
13739 static void ObjectWithExternalArrayTestHelper(Handle<Context> context, | 15179 static void ObjectWithExternalArrayTestHelper(Local<Context> context, |
13740 v8::Handle<Object> obj, | 15180 v8::Local<Object> obj, |
13741 int element_count, | 15181 int element_count, |
13742 i::ExternalArrayType array_type, | 15182 i::ExternalArrayType array_type, |
13743 int64_t low, int64_t high) { | 15183 int64_t low, int64_t high) { |
13744 i::Handle<i::JSReceiver> jsobj = v8::Utils::OpenHandle(*obj); | 15184 i::Handle<i::JSReceiver> jsobj = v8::Utils::OpenHandle(*obj); |
13745 i::Isolate* isolate = jsobj->GetIsolate(); | 15185 i::Isolate* isolate = jsobj->GetIsolate(); |
13746 obj->Set(v8_str("field"), | 15186 obj->Set(v8_str("field"), |
13747 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); | 15187 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); |
13748 context->Global()->Set(v8_str("ext_array"), obj); | 15188 CHECK(context->Global()->Set(context, v8_str("ext_array"), obj).FromJust()); |
13749 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); | 15189 v8::Local<v8::Value> result = CompileRun("ext_array.field"); |
13750 CHECK_EQ(1503, result->Int32Value()); | 15190 CHECK_EQ(1503, result->Int32Value(context).FromJust()); |
13751 result = CompileRun("ext_array[1]"); | 15191 result = CompileRun("ext_array[1]"); |
13752 CHECK_EQ(1, result->Int32Value()); | 15192 CHECK_EQ(1, result->Int32Value(context).FromJust()); |
13753 | 15193 |
13754 // Check assigned smis | 15194 // Check assigned smis |
13755 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15195 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13756 " ext_array[i] = i;" | 15196 " ext_array[i] = i;" |
13757 "}" | 15197 "}" |
13758 "var sum = 0;" | 15198 "var sum = 0;" |
13759 "for (var i = 0; i < 8; i++) {" | 15199 "for (var i = 0; i < 8; i++) {" |
13760 " sum += ext_array[i];" | 15200 " sum += ext_array[i];" |
13761 "}" | 15201 "}" |
13762 "sum;"); | 15202 "sum;"); |
13763 | 15203 |
13764 CHECK_EQ(28, result->Int32Value()); | 15204 CHECK_EQ(28, result->Int32Value(context).FromJust()); |
13765 // Check pass through of assigned smis | 15205 // Check pass through of assigned smis |
13766 result = CompileRun("var sum = 0;" | 15206 result = CompileRun("var sum = 0;" |
13767 "for (var i = 0; i < 8; i++) {" | 15207 "for (var i = 0; i < 8; i++) {" |
13768 " sum += ext_array[i] = ext_array[i] = -i;" | 15208 " sum += ext_array[i] = ext_array[i] = -i;" |
13769 "}" | 15209 "}" |
13770 "sum;"); | 15210 "sum;"); |
13771 CHECK_EQ(-28, result->Int32Value()); | 15211 CHECK_EQ(-28, result->Int32Value(context).FromJust()); |
13772 | 15212 |
13773 | 15213 |
13774 // Check assigned smis in reverse order | 15214 // Check assigned smis in reverse order |
13775 result = CompileRun("for (var i = 8; --i >= 0; ) {" | 15215 result = CompileRun("for (var i = 8; --i >= 0; ) {" |
13776 " ext_array[i] = i;" | 15216 " ext_array[i] = i;" |
13777 "}" | 15217 "}" |
13778 "var sum = 0;" | 15218 "var sum = 0;" |
13779 "for (var i = 0; i < 8; i++) {" | 15219 "for (var i = 0; i < 8; i++) {" |
13780 " sum += ext_array[i];" | 15220 " sum += ext_array[i];" |
13781 "}" | 15221 "}" |
13782 "sum;"); | 15222 "sum;"); |
13783 CHECK_EQ(28, result->Int32Value()); | 15223 CHECK_EQ(28, result->Int32Value(context).FromJust()); |
13784 | 15224 |
13785 // Check pass through of assigned HeapNumbers | 15225 // Check pass through of assigned HeapNumbers |
13786 result = CompileRun("var sum = 0;" | 15226 result = CompileRun("var sum = 0;" |
13787 "for (var i = 0; i < 16; i+=2) {" | 15227 "for (var i = 0; i < 16; i+=2) {" |
13788 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);" | 15228 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);" |
13789 "}" | 15229 "}" |
13790 "sum;"); | 15230 "sum;"); |
13791 CHECK_EQ(-28, result->Int32Value()); | 15231 CHECK_EQ(-28, result->Int32Value(context).FromJust()); |
13792 | 15232 |
13793 // Check assigned HeapNumbers | 15233 // Check assigned HeapNumbers |
13794 result = CompileRun("for (var i = 0; i < 16; i+=2) {" | 15234 result = CompileRun("for (var i = 0; i < 16; i+=2) {" |
13795 " ext_array[i] = (i * 0.5);" | 15235 " ext_array[i] = (i * 0.5);" |
13796 "}" | 15236 "}" |
13797 "var sum = 0;" | 15237 "var sum = 0;" |
13798 "for (var i = 0; i < 16; i+=2) {" | 15238 "for (var i = 0; i < 16; i+=2) {" |
13799 " sum += ext_array[i];" | 15239 " sum += ext_array[i];" |
13800 "}" | 15240 "}" |
13801 "sum;"); | 15241 "sum;"); |
13802 CHECK_EQ(28, result->Int32Value()); | 15242 CHECK_EQ(28, result->Int32Value(context).FromJust()); |
13803 | 15243 |
13804 // Check assigned HeapNumbers in reverse order | 15244 // Check assigned HeapNumbers in reverse order |
13805 result = CompileRun("for (var i = 14; i >= 0; i-=2) {" | 15245 result = CompileRun("for (var i = 14; i >= 0; i-=2) {" |
13806 " ext_array[i] = (i * 0.5);" | 15246 " ext_array[i] = (i * 0.5);" |
13807 "}" | 15247 "}" |
13808 "var sum = 0;" | 15248 "var sum = 0;" |
13809 "for (var i = 0; i < 16; i+=2) {" | 15249 "for (var i = 0; i < 16; i+=2) {" |
13810 " sum += ext_array[i];" | 15250 " sum += ext_array[i];" |
13811 "}" | 15251 "}" |
13812 "sum;"); | 15252 "sum;"); |
13813 CHECK_EQ(28, result->Int32Value()); | 15253 CHECK_EQ(28, result->Int32Value(context).FromJust()); |
13814 | 15254 |
13815 i::ScopedVector<char> test_buf(1024); | 15255 i::ScopedVector<char> test_buf(1024); |
13816 | 15256 |
13817 // Check legal boundary conditions. | 15257 // Check legal boundary conditions. |
13818 // The repeated loads and stores ensure the ICs are exercised. | 15258 // The repeated loads and stores ensure the ICs are exercised. |
13819 const char* boundary_program = | 15259 const char* boundary_program = |
13820 "var res = 0;" | 15260 "var res = 0;" |
13821 "for (var i = 0; i < 16; i++) {" | 15261 "for (var i = 0; i < 16; i++) {" |
13822 " ext_array[i] = %lld;" | 15262 " ext_array[i] = %lld;" |
13823 " if (i > 8) {" | 15263 " if (i > 8) {" |
(...skipping 19 matching lines...) Expand all Loading... | |
13843 "for (var i = 0; i < 8; i++) {" | 15283 "for (var i = 0; i < 8; i++) {" |
13844 " tmp_array[i] = i;" | 15284 " tmp_array[i] = i;" |
13845 " sum += tmp_array[i];" | 15285 " sum += tmp_array[i];" |
13846 " if (i == 4) {" | 15286 " if (i == 4) {" |
13847 " tmp_array = {};" | 15287 " tmp_array = {};" |
13848 " }" | 15288 " }" |
13849 "}" | 15289 "}" |
13850 "sum;"); | 15290 "sum;"); |
13851 // Force GC to trigger verification. | 15291 // Force GC to trigger verification. |
13852 CcTest::heap()->CollectAllGarbage(); | 15292 CcTest::heap()->CollectAllGarbage(); |
13853 CHECK_EQ(28, result->Int32Value()); | 15293 CHECK_EQ(28, result->Int32Value(context).FromJust()); |
13854 | 15294 |
13855 // Make sure out-of-range loads do not throw. | 15295 // Make sure out-of-range loads do not throw. |
13856 i::SNPrintF(test_buf, | 15296 i::SNPrintF(test_buf, |
13857 "var caught_exception = false;" | 15297 "var caught_exception = false;" |
13858 "try {" | 15298 "try {" |
13859 " ext_array[%d];" | 15299 " ext_array[%d];" |
13860 "} catch (e) {" | 15300 "} catch (e) {" |
13861 " caught_exception = true;" | 15301 " caught_exception = true;" |
13862 "}" | 15302 "}" |
13863 "caught_exception;", | 15303 "caught_exception;", |
(...skipping 12 matching lines...) Expand all Loading... | |
13876 "caught_exception;", | 15316 "caught_exception;", |
13877 element_count); | 15317 element_count); |
13878 result = CompileRun(test_buf.start()); | 15318 result = CompileRun(test_buf.start()); |
13879 CHECK_EQ(false, result->BooleanValue()); | 15319 CHECK_EQ(false, result->BooleanValue()); |
13880 | 15320 |
13881 // Check other boundary conditions, values and operations. | 15321 // Check other boundary conditions, values and operations. |
13882 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15322 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13883 " ext_array[7] = undefined;" | 15323 " ext_array[7] = undefined;" |
13884 "}" | 15324 "}" |
13885 "ext_array[7];"); | 15325 "ext_array[7];"); |
13886 CHECK_EQ(0, result->Int32Value()); | 15326 CHECK_EQ(0, result->Int32Value(context).FromJust()); |
13887 if (array_type == i::kExternalFloat64Array || | 15327 if (array_type == i::kExternalFloat64Array || |
13888 array_type == i::kExternalFloat32Array) { | 15328 array_type == i::kExternalFloat32Array) { |
13889 CHECK(std::isnan( | 15329 CHECK(std::isnan( |
13890 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number())); | 15330 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number())); |
13891 } else { | 15331 } else { |
13892 CheckElementValue(isolate, 0, jsobj, 7); | 15332 CheckElementValue(isolate, 0, jsobj, 7); |
13893 } | 15333 } |
13894 | 15334 |
13895 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15335 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13896 " ext_array[6] = '2.3';" | 15336 " ext_array[6] = '2.3';" |
13897 "}" | 15337 "}" |
13898 "ext_array[6];"); | 15338 "ext_array[6];"); |
13899 CHECK_EQ(2, result->Int32Value()); | 15339 CHECK_EQ(2, result->Int32Value(context).FromJust()); |
13900 CHECK_EQ(2, | 15340 CHECK_EQ(2, |
13901 static_cast<int>( | 15341 static_cast<int>( |
13902 i::Object::GetElement( | 15342 i::Object::GetElement( |
13903 isolate, jsobj, 6).ToHandleChecked()->Number())); | 15343 isolate, jsobj, 6).ToHandleChecked()->Number())); |
13904 | 15344 |
13905 if (array_type != i::kExternalFloat32Array && | 15345 if (array_type != i::kExternalFloat32Array && |
13906 array_type != i::kExternalFloat64Array) { | 15346 array_type != i::kExternalFloat64Array) { |
13907 // Though the specification doesn't state it, be explicit about | 15347 // Though the specification doesn't state it, be explicit about |
13908 // converting NaNs and +/-Infinity to zero. | 15348 // converting NaNs and +/-Infinity to zero. |
13909 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15349 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13910 " ext_array[i] = 5;" | 15350 " ext_array[i] = 5;" |
13911 "}" | 15351 "}" |
13912 "for (var i = 0; i < 8; i++) {" | 15352 "for (var i = 0; i < 8; i++) {" |
13913 " ext_array[i] = NaN;" | 15353 " ext_array[i] = NaN;" |
13914 "}" | 15354 "}" |
13915 "ext_array[5];"); | 15355 "ext_array[5];"); |
13916 CHECK_EQ(0, result->Int32Value()); | 15356 CHECK_EQ(0, result->Int32Value(context).FromJust()); |
13917 CheckElementValue(isolate, 0, jsobj, 5); | 15357 CheckElementValue(isolate, 0, jsobj, 5); |
13918 | 15358 |
13919 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15359 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13920 " ext_array[i] = 5;" | 15360 " ext_array[i] = 5;" |
13921 "}" | 15361 "}" |
13922 "for (var i = 0; i < 8; i++) {" | 15362 "for (var i = 0; i < 8; i++) {" |
13923 " ext_array[i] = Infinity;" | 15363 " ext_array[i] = Infinity;" |
13924 "}" | 15364 "}" |
13925 "ext_array[5];"); | 15365 "ext_array[5];"); |
13926 int expected_value = | 15366 int expected_value = |
13927 (array_type == i::kExternalUint8ClampedArray) ? 255 : 0; | 15367 (array_type == i::kExternalUint8ClampedArray) ? 255 : 0; |
13928 CHECK_EQ(expected_value, result->Int32Value()); | 15368 CHECK_EQ(expected_value, result->Int32Value(context).FromJust()); |
13929 CheckElementValue(isolate, expected_value, jsobj, 5); | 15369 CheckElementValue(isolate, expected_value, jsobj, 5); |
13930 | 15370 |
13931 result = CompileRun("for (var i = 0; i < 8; i++) {" | 15371 result = CompileRun("for (var i = 0; i < 8; i++) {" |
13932 " ext_array[i] = 5;" | 15372 " ext_array[i] = 5;" |
13933 "}" | 15373 "}" |
13934 "for (var i = 0; i < 8; i++) {" | 15374 "for (var i = 0; i < 8; i++) {" |
13935 " ext_array[i] = -Infinity;" | 15375 " ext_array[i] = -Infinity;" |
13936 "}" | 15376 "}" |
13937 "ext_array[5];"); | 15377 "ext_array[5];"); |
13938 CHECK_EQ(0, result->Int32Value()); | 15378 CHECK_EQ(0, result->Int32Value(context).FromJust()); |
13939 CheckElementValue(isolate, 0, jsobj, 5); | 15379 CheckElementValue(isolate, 0, jsobj, 5); |
13940 | 15380 |
13941 // Check truncation behavior of integral arrays. | 15381 // Check truncation behavior of integral arrays. |
13942 const char* unsigned_data = | 15382 const char* unsigned_data = |
13943 "var source_data = [0.6, 10.6];" | 15383 "var source_data = [0.6, 10.6];" |
13944 "var expected_results = [0, 10];"; | 15384 "var expected_results = [0, 10];"; |
13945 const char* signed_data = | 15385 const char* signed_data = |
13946 "var source_data = [0.6, 10.6, -0.6, -10.6];" | 15386 "var source_data = [0.6, 10.6, -0.6, -10.6];" |
13947 "var expected_results = [0, 10, 0, -10];"; | 15387 "var expected_results = [0, 10, 0, -10];"; |
13948 const char* pixel_data = | 15388 const char* pixel_data = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13983 " sum += (ext_array[i] += 1);" | 15423 " sum += (ext_array[i] += 1);" |
13984 " sum += (ext_array[i] -= 1);" | 15424 " sum += (ext_array[i] -= 1);" |
13985 " } " | 15425 " } " |
13986 " return sum;" | 15426 " return sum;" |
13987 "}" | 15427 "}" |
13988 "sum=0;" | 15428 "sum=0;" |
13989 "for (var i=0;i<10000;++i) {" | 15429 "for (var i=0;i<10000;++i) {" |
13990 " sum=ee_op_test_complex_func(sum);" | 15430 " sum=ee_op_test_complex_func(sum);" |
13991 "}" | 15431 "}" |
13992 "sum;"); | 15432 "sum;"); |
13993 CHECK_EQ(16000000, result->Int32Value()); | 15433 CHECK_EQ(16000000, result->Int32Value(context).FromJust()); |
13994 | 15434 |
13995 // Test count operations | 15435 // Test count operations |
13996 result = CompileRun("function ee_op_test_count_func(sum) {" | 15436 result = CompileRun("function ee_op_test_count_func(sum) {" |
13997 " for (var i = 0; i < 40; ++i) {" | 15437 " for (var i = 0; i < 40; ++i) {" |
13998 " sum += (++ext_array[i]);" | 15438 " sum += (++ext_array[i]);" |
13999 " sum += (--ext_array[i]);" | 15439 " sum += (--ext_array[i]);" |
14000 " } " | 15440 " } " |
14001 " return sum;" | 15441 " return sum;" |
14002 "}" | 15442 "}" |
14003 "sum=0;" | 15443 "sum=0;" |
14004 "for (var i=0;i<10000;++i) {" | 15444 "for (var i=0;i<10000;++i) {" |
14005 " sum=ee_op_test_count_func(sum);" | 15445 " sum=ee_op_test_count_func(sum);" |
14006 "}" | 15446 "}" |
14007 "sum;"); | 15447 "sum;"); |
14008 CHECK_EQ(16000000, result->Int32Value()); | 15448 CHECK_EQ(16000000, result->Int32Value(context).FromJust()); |
14009 | 15449 |
14010 result = CompileRun("ext_array[3] = 33;" | 15450 result = CompileRun("ext_array[3] = 33;" |
14011 "delete ext_array[3];" | 15451 "delete ext_array[3];" |
14012 "ext_array[3];"); | 15452 "ext_array[3];"); |
14013 CHECK_EQ(33, result->Int32Value()); | 15453 CHECK_EQ(33, result->Int32Value(context).FromJust()); |
14014 | 15454 |
14015 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" | 15455 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" |
14016 "ext_array[2] = 12; ext_array[3] = 13;" | 15456 "ext_array[2] = 12; ext_array[3] = 13;" |
14017 "ext_array.__defineGetter__('2'," | 15457 "ext_array.__defineGetter__('2'," |
14018 "function() { return 120; });" | 15458 "function() { return 120; });" |
14019 "ext_array[2];"); | 15459 "ext_array[2];"); |
14020 CHECK_EQ(12, result->Int32Value()); | 15460 CHECK_EQ(12, result->Int32Value(context).FromJust()); |
14021 | 15461 |
14022 result = CompileRun("var js_array = new Array(40);" | 15462 result = CompileRun("var js_array = new Array(40);" |
14023 "js_array[0] = 77;" | 15463 "js_array[0] = 77;" |
14024 "js_array;"); | 15464 "js_array;"); |
14025 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 15465 CHECK_EQ(77, v8::Object::Cast(*result) |
15466 ->Get(v8_str("0")) | |
15467 ->Int32Value(context) | |
15468 .FromJust()); | |
14026 | 15469 |
14027 result = CompileRun("ext_array[1] = 23;" | 15470 result = CompileRun("ext_array[1] = 23;" |
14028 "ext_array.__proto__ = [];" | 15471 "ext_array.__proto__ = [];" |
14029 "js_array.__proto__ = ext_array;" | 15472 "js_array.__proto__ = ext_array;" |
14030 "js_array.concat(ext_array);"); | 15473 "js_array.concat(ext_array);"); |
14031 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); | 15474 CHECK_EQ(77, v8::Object::Cast(*result) |
14032 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); | 15475 ->Get(v8_str("0")) |
15476 ->Int32Value(context) | |
15477 .FromJust()); | |
15478 CHECK_EQ(23, v8::Object::Cast(*result) | |
15479 ->Get(v8_str("1")) | |
15480 ->Int32Value(context) | |
15481 .FromJust()); | |
14033 | 15482 |
14034 result = CompileRun("ext_array[1] = 23;"); | 15483 result = CompileRun("ext_array[1] = 23;"); |
14035 CHECK_EQ(23, result->Int32Value()); | 15484 CHECK_EQ(23, result->Int32Value(context).FromJust()); |
14036 } | 15485 } |
14037 | 15486 |
14038 | 15487 |
14039 template <class FixedTypedArrayClass, i::ElementsKind elements_kind, | 15488 template <class FixedTypedArrayClass, i::ElementsKind elements_kind, |
14040 class ElementType> | 15489 class ElementType> |
14041 static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type, | 15490 static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type, |
14042 ElementType low, ElementType high) { | 15491 ElementType low, ElementType high) { |
14043 i::FLAG_allow_natives_syntax = true; | 15492 i::FLAG_allow_natives_syntax = true; |
14044 LocalContext context; | 15493 LocalContext context; |
14045 i::Isolate* isolate = CcTest::i_isolate(); | 15494 i::Isolate* isolate = CcTest::i_isolate(); |
(...skipping 10 matching lines...) Expand all Loading... | |
14056 CcTest::heap()->CollectAllGarbage(); | 15505 CcTest::heap()->CollectAllGarbage(); |
14057 for (int i = 0; i < kElementCount; i++) { | 15506 for (int i = 0; i < kElementCount; i++) { |
14058 fixed_array->set(i, static_cast<ElementType>(i)); | 15507 fixed_array->set(i, static_cast<ElementType>(i)); |
14059 } | 15508 } |
14060 // Force GC to trigger verification. | 15509 // Force GC to trigger verification. |
14061 CcTest::heap()->CollectAllGarbage(); | 15510 CcTest::heap()->CollectAllGarbage(); |
14062 for (int i = 0; i < kElementCount; i++) { | 15511 for (int i = 0; i < kElementCount; i++) { |
14063 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), | 15512 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), |
14064 static_cast<int64_t>(fixed_array->get_scalar(i))); | 15513 static_cast<int64_t>(fixed_array->get_scalar(i))); |
14065 } | 15514 } |
14066 v8::Handle<v8::Object> obj = v8::Utils::ToLocal(jsobj); | 15515 v8::Local<v8::Object> obj = v8::Utils::ToLocal(jsobj); |
14067 | 15516 |
14068 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>( | 15517 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>( |
14069 context.local(), obj, kElementCount, array_type, | 15518 context.local(), obj, kElementCount, array_type, |
14070 static_cast<int64_t>(low), | 15519 static_cast<int64_t>(low), |
14071 static_cast<int64_t>(high)); | 15520 static_cast<int64_t>(high)); |
14072 } | 15521 } |
14073 | 15522 |
14074 | 15523 |
14075 THREADED_TEST(FixedUint8Array) { | 15524 THREADED_TEST(FixedUint8Array) { |
14076 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>( | 15525 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>( |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14369 v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize); | 15818 v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize); |
14370 Local<v8::DataView> dv = | 15819 Local<v8::DataView> dv = |
14371 v8::DataView::New(ab, 2, kSize); | 15820 v8::DataView::New(ab, 2, kSize); |
14372 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); | 15821 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); |
14373 CHECK_EQ(2u, dv->ByteOffset()); | 15822 CHECK_EQ(2u, dv->ByteOffset()); |
14374 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); | 15823 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); |
14375 CHECK(ab->Equals(dv->Buffer())); | 15824 CHECK(ab->Equals(dv->Buffer())); |
14376 } | 15825 } |
14377 | 15826 |
14378 | 15827 |
14379 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ | 15828 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ |
14380 THREADED_TEST(Is##View) { \ | 15829 THREADED_TEST(Is##View) { \ |
14381 LocalContext env; \ | 15830 LocalContext env; \ |
14382 v8::Isolate* isolate = env->GetIsolate(); \ | 15831 v8::Isolate* isolate = env->GetIsolate(); \ |
14383 v8::HandleScope handle_scope(isolate); \ | 15832 v8::HandleScope handle_scope(isolate); \ |
14384 \ | 15833 \ |
14385 Handle<Value> result = CompileRun( \ | 15834 Local<Value> result = CompileRun( \ |
14386 "var ab = new ArrayBuffer(128);" \ | 15835 "var ab = new ArrayBuffer(128);" \ |
14387 "new " #View "(ab)"); \ | 15836 "new " #View "(ab)"); \ |
14388 CHECK(result->IsArrayBufferView()); \ | 15837 CHECK(result->IsArrayBufferView()); \ |
14389 CHECK(result->Is##View()); \ | 15838 CHECK(result->Is##View()); \ |
14390 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \ | 15839 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \ |
14391 } | 15840 } |
14392 | 15841 |
14393 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array) | 15842 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array) |
14394 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array) | 15843 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array) |
14395 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array) | 15844 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array) |
14396 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array) | 15845 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array) |
14397 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array) | 15846 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array) |
14398 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array) | 15847 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array) |
14399 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array) | 15848 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array) |
14400 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array) | 15849 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array) |
14401 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray) | 15850 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray) |
14402 IS_ARRAY_BUFFER_VIEW_TEST(DataView) | 15851 IS_ARRAY_BUFFER_VIEW_TEST(DataView) |
14403 | 15852 |
14404 #undef IS_ARRAY_BUFFER_VIEW_TEST | 15853 #undef IS_ARRAY_BUFFER_VIEW_TEST |
14405 | 15854 |
14406 | 15855 |
14407 | 15856 |
14408 THREADED_TEST(ScriptContextDependence) { | 15857 THREADED_TEST(ScriptContextDependence) { |
14409 LocalContext c1; | 15858 LocalContext c1; |
14410 v8::HandleScope scope(c1->GetIsolate()); | 15859 v8::HandleScope scope(c1->GetIsolate()); |
14411 const char *source = "foo"; | 15860 const char *source = "foo"; |
14412 v8::Handle<v8::Script> dep = v8_compile(source); | 15861 v8::Local<v8::Script> dep = v8_compile(source); |
14413 v8::ScriptCompiler::Source script_source(v8::String::NewFromUtf8( | 15862 v8::ScriptCompiler::Source script_source( |
14414 c1->GetIsolate(), source)); | 15863 v8::String::NewFromUtf8(c1->GetIsolate(), source, |
14415 v8::Handle<v8::UnboundScript> indep = | 15864 v8::NewStringType::kNormal) |
15865 .ToLocalChecked()); | |
15866 v8::Local<v8::UnboundScript> indep = | |
14416 v8::ScriptCompiler::CompileUnbound(c1->GetIsolate(), &script_source); | 15867 v8::ScriptCompiler::CompileUnbound(c1->GetIsolate(), &script_source); |
14417 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), | 15868 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo", |
15869 v8::NewStringType::kNormal) | |
15870 .ToLocalChecked(), | |
14418 v8::Integer::New(c1->GetIsolate(), 100)); | 15871 v8::Integer::New(c1->GetIsolate(), 100)); |
14419 CHECK_EQ(dep->Run()->Int32Value(), 100); | 15872 CHECK_EQ(dep->Run()->Int32Value(c1.local()).FromJust(), 100); |
14420 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100); | 15873 CHECK_EQ( |
15874 indep->BindToCurrentContext()->Run()->Int32Value(c1.local()).FromJust(), | |
15875 100); | |
14421 LocalContext c2; | 15876 LocalContext c2; |
14422 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), | 15877 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo", |
15878 v8::NewStringType::kNormal) | |
15879 .ToLocalChecked(), | |
14423 v8::Integer::New(c2->GetIsolate(), 101)); | 15880 v8::Integer::New(c2->GetIsolate(), 101)); |
14424 CHECK_EQ(dep->Run()->Int32Value(), 100); | 15881 CHECK_EQ(dep->Run()->Int32Value(c2.local()).FromJust(), 100); |
14425 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101); | 15882 CHECK_EQ( |
15883 indep->BindToCurrentContext()->Run()->Int32Value(c2.local()).FromJust(), | |
15884 101); | |
14426 } | 15885 } |
14427 | 15886 |
14428 | 15887 |
14429 THREADED_TEST(StackTrace) { | 15888 THREADED_TEST(StackTrace) { |
14430 LocalContext context; | 15889 LocalContext context; |
14431 v8::HandleScope scope(context->GetIsolate()); | 15890 v8::HandleScope scope(context->GetIsolate()); |
14432 v8::TryCatch try_catch(context->GetIsolate()); | 15891 v8::TryCatch try_catch(context->GetIsolate()); |
14433 const char *source = "function foo() { FAIL.FAIL; }; foo();"; | 15892 const char *source = "function foo() { FAIL.FAIL; }; foo();"; |
14434 v8::Handle<v8::String> src = | 15893 v8::Local<v8::String> src = v8_str(source); |
14435 v8::String::NewFromUtf8(context->GetIsolate(), source); | 15894 v8::Local<v8::String> origin = v8_str("stack-trace-test"); |
14436 v8::Handle<v8::String> origin = | |
14437 v8::String::NewFromUtf8(context->GetIsolate(), "stack-trace-test"); | |
14438 v8::ScriptCompiler::Source script_source(src, v8::ScriptOrigin(origin)); | 15895 v8::ScriptCompiler::Source script_source(src, v8::ScriptOrigin(origin)); |
14439 v8::ScriptCompiler::CompileUnbound(context->GetIsolate(), &script_source) | 15896 v8::ScriptCompiler::CompileUnbound(context->GetIsolate(), &script_source) |
14440 ->BindToCurrentContext() | 15897 ->BindToCurrentContext() |
14441 ->Run(); | 15898 ->Run(); |
14442 CHECK(try_catch.HasCaught()); | 15899 CHECK(try_catch.HasCaught()); |
14443 v8::String::Utf8Value stack(try_catch.StackTrace()); | 15900 v8::String::Utf8Value stack(try_catch.StackTrace()); |
14444 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); | 15901 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); |
14445 } | 15902 } |
14446 | 15903 |
14447 | 15904 |
14448 // Checks that a StackFrame has certain expected values. | 15905 // Checks that a StackFrame has certain expected values. |
14449 void checkStackFrame(const char* expected_script_name, | 15906 void checkStackFrame(const char* expected_script_name, |
14450 const char* expected_func_name, int expected_line_number, | 15907 const char* expected_func_name, int expected_line_number, |
14451 int expected_column, bool is_eval, bool is_constructor, | 15908 int expected_column, bool is_eval, bool is_constructor, |
14452 v8::Handle<v8::StackFrame> frame) { | 15909 v8::Local<v8::StackFrame> frame) { |
14453 v8::HandleScope scope(CcTest::isolate()); | 15910 v8::HandleScope scope(CcTest::isolate()); |
14454 v8::String::Utf8Value func_name(frame->GetFunctionName()); | 15911 v8::String::Utf8Value func_name(frame->GetFunctionName()); |
14455 v8::String::Utf8Value script_name(frame->GetScriptName()); | 15912 v8::String::Utf8Value script_name(frame->GetScriptName()); |
14456 if (*script_name == NULL) { | 15913 if (*script_name == NULL) { |
14457 // The situation where there is no associated script, like for evals. | 15914 // The situation where there is no associated script, like for evals. |
14458 CHECK(expected_script_name == NULL); | 15915 CHECK(expected_script_name == NULL); |
14459 } else { | 15916 } else { |
14460 CHECK(strstr(*script_name, expected_script_name) != NULL); | 15917 CHECK(strstr(*script_name, expected_script_name) != NULL); |
14461 } | 15918 } |
14462 CHECK(strstr(*func_name, expected_func_name) != NULL); | 15919 CHECK(strstr(*func_name, expected_func_name) != NULL); |
(...skipping 10 matching lines...) Expand all Loading... | |
14473 const int kOverviewTest = 1; | 15930 const int kOverviewTest = 1; |
14474 const int kDetailedTest = 2; | 15931 const int kDetailedTest = 2; |
14475 const int kFunctionName = 3; | 15932 const int kFunctionName = 3; |
14476 const int kDisplayName = 4; | 15933 const int kDisplayName = 4; |
14477 const int kFunctionNameAndDisplayName = 5; | 15934 const int kFunctionNameAndDisplayName = 5; |
14478 const int kDisplayNameIsNotString = 6; | 15935 const int kDisplayNameIsNotString = 6; |
14479 const int kFunctionNameIsNotString = 7; | 15936 const int kFunctionNameIsNotString = 7; |
14480 | 15937 |
14481 DCHECK(args.Length() == 1); | 15938 DCHECK(args.Length() == 1); |
14482 | 15939 |
14483 int testGroup = args[0]->Int32Value(); | 15940 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); |
15941 int testGroup = args[0]->Int32Value(context).FromJust(); | |
14484 if (testGroup == kOverviewTest) { | 15942 if (testGroup == kOverviewTest) { |
14485 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 15943 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
14486 args.GetIsolate(), 10, v8::StackTrace::kOverview); | 15944 args.GetIsolate(), 10, v8::StackTrace::kOverview); |
14487 CHECK_EQ(4, stackTrace->GetFrameCount()); | 15945 CHECK_EQ(4, stackTrace->GetFrameCount()); |
14488 checkStackFrame(origin, "bar", 2, 10, false, false, | 15946 checkStackFrame(origin, "bar", 2, 10, false, false, |
14489 stackTrace->GetFrame(0)); | 15947 stackTrace->GetFrame(0)); |
14490 checkStackFrame(origin, "foo", 6, 3, false, false, | 15948 checkStackFrame(origin, "foo", 6, 3, false, false, |
14491 stackTrace->GetFrame(1)); | 15949 stackTrace->GetFrame(1)); |
14492 // This is the source string inside the eval which has the call to foo. | 15950 // This is the source string inside the eval which has the call to foo. |
14493 checkStackFrame(NULL, "", 1, 1, false, false, stackTrace->GetFrame(2)); | 15951 checkStackFrame(NULL, "", 1, 1, false, false, stackTrace->GetFrame(2)); |
14494 // The last frame is an anonymous function which has the initial eval call. | 15952 // The last frame is an anonymous function which has the initial eval call. |
14495 checkStackFrame(origin, "", 8, 7, false, false, stackTrace->GetFrame(3)); | 15953 checkStackFrame(origin, "", 8, 7, false, false, stackTrace->GetFrame(3)); |
14496 | 15954 |
14497 CHECK(stackTrace->AsArray()->IsArray()); | 15955 CHECK(stackTrace->AsArray()->IsArray()); |
14498 } else if (testGroup == kDetailedTest) { | 15956 } else if (testGroup == kDetailedTest) { |
14499 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 15957 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
14500 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 15958 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
14501 CHECK_EQ(4, stackTrace->GetFrameCount()); | 15959 CHECK_EQ(4, stackTrace->GetFrameCount()); |
14502 checkStackFrame(origin, "bat", 4, 22, false, false, | 15960 checkStackFrame(origin, "bat", 4, 22, false, false, |
14503 stackTrace->GetFrame(0)); | 15961 stackTrace->GetFrame(0)); |
14504 checkStackFrame(origin, "baz", 8, 3, false, true, | 15962 checkStackFrame(origin, "baz", 8, 3, false, true, |
14505 stackTrace->GetFrame(1)); | 15963 stackTrace->GetFrame(1)); |
14506 bool is_eval = true; | 15964 bool is_eval = true; |
14507 // This is the source string inside the eval which has the call to baz. | 15965 // This is the source string inside the eval which has the call to baz. |
14508 checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2)); | 15966 checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2)); |
14509 // The last frame is an anonymous function which has the initial eval call. | 15967 // The last frame is an anonymous function which has the initial eval call. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14542 } | 16000 } |
14543 } | 16001 } |
14544 | 16002 |
14545 | 16003 |
14546 // Tests the C++ StackTrace API. | 16004 // Tests the C++ StackTrace API. |
14547 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. | 16005 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. |
14548 // THREADED_TEST(CaptureStackTrace) { | 16006 // THREADED_TEST(CaptureStackTrace) { |
14549 TEST(CaptureStackTrace) { | 16007 TEST(CaptureStackTrace) { |
14550 v8::Isolate* isolate = CcTest::isolate(); | 16008 v8::Isolate* isolate = CcTest::isolate(); |
14551 v8::HandleScope scope(isolate); | 16009 v8::HandleScope scope(isolate); |
14552 v8::Handle<v8::String> origin = | 16010 v8::Local<v8::String> origin = v8_str("capture-stack-trace-test"); |
14553 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test"); | |
14554 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 16011 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
14555 templ->Set(v8_str("AnalyzeStackInNativeCode"), | 16012 templ->Set(v8_str("AnalyzeStackInNativeCode"), |
14556 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); | 16013 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); |
14557 LocalContext context(0, templ); | 16014 LocalContext context(0, templ); |
14558 | 16015 |
14559 // Test getting OVERVIEW information. Should ignore information that is not | 16016 // Test getting OVERVIEW information. Should ignore information that is not |
14560 // script name, function name, line number, and column offset. | 16017 // script name, function name, line number, and column offset. |
14561 const char *overview_source = | 16018 const char *overview_source = |
14562 "function bar() {\n" | 16019 "function bar() {\n" |
14563 " var y; AnalyzeStackInNativeCode(1);\n" | 16020 " var y; AnalyzeStackInNativeCode(1);\n" |
14564 "}\n" | 16021 "}\n" |
14565 "function foo() {\n" | 16022 "function foo() {\n" |
14566 "\n" | 16023 "\n" |
14567 " bar();\n" | 16024 " bar();\n" |
14568 "}\n" | 16025 "}\n" |
14569 "var x;eval('new foo();');"; | 16026 "var x;eval('new foo();');"; |
14570 v8::Handle<v8::String> overview_src = | 16027 v8::Local<v8::String> overview_src = v8_str(overview_source); |
14571 v8::String::NewFromUtf8(isolate, overview_source); | |
14572 v8::ScriptCompiler::Source script_source(overview_src, | 16028 v8::ScriptCompiler::Source script_source(overview_src, |
14573 v8::ScriptOrigin(origin)); | 16029 v8::ScriptOrigin(origin)); |
14574 v8::Handle<Value> overview_result( | 16030 v8::Local<Value> overview_result( |
14575 v8::ScriptCompiler::CompileUnbound(isolate, &script_source) | 16031 v8::ScriptCompiler::CompileUnbound(isolate, &script_source) |
14576 ->BindToCurrentContext() | 16032 ->BindToCurrentContext() |
14577 ->Run()); | 16033 ->Run()); |
14578 CHECK(!overview_result.IsEmpty()); | 16034 CHECK(!overview_result.IsEmpty()); |
14579 CHECK(overview_result->IsObject()); | 16035 CHECK(overview_result->IsObject()); |
14580 | 16036 |
14581 // Test getting DETAILED information. | 16037 // Test getting DETAILED information. |
14582 const char *detailed_source = | 16038 const char *detailed_source = |
14583 "function bat() {AnalyzeStackInNativeCode(2);\n" | 16039 "function bat() {AnalyzeStackInNativeCode(2);\n" |
14584 "}\n" | 16040 "}\n" |
14585 "\n" | 16041 "\n" |
14586 "function baz() {\n" | 16042 "function baz() {\n" |
14587 " bat();\n" | 16043 " bat();\n" |
14588 "}\n" | 16044 "}\n" |
14589 "eval('new baz();');"; | 16045 "eval('new baz();');"; |
14590 v8::Handle<v8::String> detailed_src = | 16046 v8::Local<v8::String> detailed_src = v8_str(detailed_source); |
14591 v8::String::NewFromUtf8(isolate, detailed_source); | |
14592 // Make the script using a non-zero line and column offset. | 16047 // Make the script using a non-zero line and column offset. |
14593 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); | 16048 v8::Local<v8::Integer> line_offset = v8::Integer::New(isolate, 3); |
14594 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); | 16049 v8::Local<v8::Integer> column_offset = v8::Integer::New(isolate, 5); |
14595 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); | 16050 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); |
14596 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin); | 16051 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin); |
14597 v8::Handle<v8::UnboundScript> detailed_script( | 16052 v8::Local<v8::UnboundScript> detailed_script( |
14598 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2)); | 16053 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2)); |
14599 v8::Handle<Value> detailed_result( | 16054 v8::Local<Value> detailed_result( |
14600 detailed_script->BindToCurrentContext()->Run()); | 16055 detailed_script->BindToCurrentContext()->Run()); |
14601 CHECK(!detailed_result.IsEmpty()); | 16056 CHECK(!detailed_result.IsEmpty()); |
14602 CHECK(detailed_result->IsObject()); | 16057 CHECK(detailed_result->IsObject()); |
14603 | 16058 |
14604 // Test using function.name and function.displayName in stack trace | 16059 // Test using function.name and function.displayName in stack trace |
14605 const char* function_name_source = | 16060 const char* function_name_source = |
14606 "function bar(function_name, display_name, testGroup) {\n" | 16061 "function bar(function_name, display_name, testGroup) {\n" |
14607 " var f = function() { AnalyzeStackInNativeCode(testGroup); };\n" | 16062 " var f = function() { AnalyzeStackInNativeCode(testGroup); };\n" |
14608 " if (function_name) {\n" | 16063 " if (function_name) {\n" |
14609 " Object.defineProperty(f, 'name', { value: function_name });\n" | 16064 " Object.defineProperty(f, 'name', { value: function_name });\n" |
(...skipping 14 matching lines...) Expand all Loading... | |
14624 v8::ScriptOrigin(origin)); | 16079 v8::ScriptOrigin(origin)); |
14625 v8::Handle<Value> function_name_result( | 16080 v8::Handle<Value> function_name_result( |
14626 v8::ScriptCompiler::CompileUnbound(isolate, &script_source3) | 16081 v8::ScriptCompiler::CompileUnbound(isolate, &script_source3) |
14627 ->BindToCurrentContext() | 16082 ->BindToCurrentContext() |
14628 ->Run()); | 16083 ->Run()); |
14629 CHECK(!function_name_result.IsEmpty()); | 16084 CHECK(!function_name_result.IsEmpty()); |
14630 } | 16085 } |
14631 | 16086 |
14632 | 16087 |
14633 static void StackTraceForUncaughtExceptionListener( | 16088 static void StackTraceForUncaughtExceptionListener( |
14634 v8::Handle<v8::Message> message, | 16089 v8::Local<v8::Message> message, v8::Local<Value>) { |
14635 v8::Handle<Value>) { | |
14636 report_count++; | 16090 report_count++; |
14637 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16091 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14638 CHECK_EQ(2, stack_trace->GetFrameCount()); | 16092 CHECK_EQ(2, stack_trace->GetFrameCount()); |
14639 checkStackFrame("origin", "foo", 2, 3, false, false, | 16093 checkStackFrame("origin", "foo", 2, 3, false, false, |
14640 stack_trace->GetFrame(0)); | 16094 stack_trace->GetFrame(0)); |
14641 checkStackFrame("origin", "bar", 5, 3, false, false, | 16095 checkStackFrame("origin", "bar", 5, 3, false, false, |
14642 stack_trace->GetFrame(1)); | 16096 stack_trace->GetFrame(1)); |
14643 } | 16097 } |
14644 | 16098 |
14645 | 16099 |
14646 TEST(CaptureStackTraceForUncaughtException) { | 16100 TEST(CaptureStackTraceForUncaughtException) { |
14647 report_count = 0; | 16101 report_count = 0; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14712 " 'isConstructor'];\n" | 16166 " 'isConstructor'];\n" |
14713 "for (var i = 0; i < setters.length; i++) {\n" | 16167 "for (var i = 0; i < setters.length; i++) {\n" |
14714 " var prop = setters[i];\n" | 16168 " var prop = setters[i];\n" |
14715 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" | 16169 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" |
14716 "}\n"); | 16170 "}\n"); |
14717 CompileRun("throw 'exception';"); | 16171 CompileRun("throw 'exception';"); |
14718 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 16172 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14719 } | 16173 } |
14720 | 16174 |
14721 | 16175 |
14722 static void StackTraceFunctionNameListener(v8::Handle<v8::Message> message, | 16176 static void StackTraceFunctionNameListener(v8::Local<v8::Message> message, |
14723 v8::Handle<Value>) { | 16177 v8::Local<Value>) { |
14724 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16178 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14725 CHECK_EQ(5, stack_trace->GetFrameCount()); | 16179 CHECK_EQ(5, stack_trace->GetFrameCount()); |
14726 checkStackFrame("origin", "foo:0", 4, 7, false, false, | 16180 checkStackFrame("origin", "foo:0", 4, 7, false, false, |
14727 stack_trace->GetFrame(0)); | 16181 stack_trace->GetFrame(0)); |
14728 checkStackFrame("origin", "foo:1", 5, 27, false, false, | 16182 checkStackFrame("origin", "foo:1", 5, 27, false, false, |
14729 stack_trace->GetFrame(1)); | 16183 stack_trace->GetFrame(1)); |
14730 checkStackFrame("origin", "foo", 5, 27, false, false, | 16184 checkStackFrame("origin", "foo", 5, 27, false, false, |
14731 stack_trace->GetFrame(2)); | 16185 stack_trace->GetFrame(2)); |
14732 checkStackFrame("origin", "foo", 5, 27, false, false, | 16186 checkStackFrame("origin", "foo", 5, 27, false, false, |
14733 stack_trace->GetFrame(3)); | 16187 stack_trace->GetFrame(3)); |
14734 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(4)); | 16188 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(4)); |
(...skipping 25 matching lines...) Expand all Loading... | |
14760 "origin"); | 16214 "origin"); |
14761 | 16215 |
14762 v8::V8::AddMessageListener(StackTraceFunctionNameListener); | 16216 v8::V8::AddMessageListener(StackTraceFunctionNameListener); |
14763 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 16217 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
14764 CompileRunWithOrigin("gen('foo', 3)();", "origin"); | 16218 CompileRunWithOrigin("gen('foo', 3)();", "origin"); |
14765 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 16219 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14766 v8::V8::RemoveMessageListeners(StackTraceFunctionNameListener); | 16220 v8::V8::RemoveMessageListeners(StackTraceFunctionNameListener); |
14767 } | 16221 } |
14768 | 16222 |
14769 | 16223 |
14770 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, | 16224 static void RethrowStackTraceHandler(v8::Local<v8::Message> message, |
14771 v8::Handle<v8::Value> data) { | 16225 v8::Local<v8::Value> data) { |
14772 // Use the frame where JavaScript is called from. | 16226 // Use the frame where JavaScript is called from. |
14773 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16227 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14774 CHECK(!stack_trace.IsEmpty()); | 16228 CHECK(!stack_trace.IsEmpty()); |
14775 int frame_count = stack_trace->GetFrameCount(); | 16229 int frame_count = stack_trace->GetFrameCount(); |
14776 CHECK_EQ(3, frame_count); | 16230 CHECK_EQ(3, frame_count); |
14777 int line_number[] = {1, 2, 5}; | 16231 int line_number[] = {1, 2, 5}; |
14778 for (int i = 0; i < frame_count; i++) { | 16232 for (int i = 0; i < frame_count; i++) { |
14779 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); | 16233 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); |
14780 } | 16234 } |
14781 } | 16235 } |
14782 | 16236 |
14783 | 16237 |
(...skipping 20 matching lines...) Expand all Loading... | |
14804 " } \n" | 16258 " } \n" |
14805 "} \n"; | 16259 "} \n"; |
14806 v8::V8::AddMessageListener(RethrowStackTraceHandler); | 16260 v8::V8::AddMessageListener(RethrowStackTraceHandler); |
14807 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 16261 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
14808 CompileRun(source); | 16262 CompileRun(source); |
14809 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 16263 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14810 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler); | 16264 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler); |
14811 } | 16265 } |
14812 | 16266 |
14813 | 16267 |
14814 static void RethrowPrimitiveStackTraceHandler(v8::Handle<v8::Message> message, | 16268 static void RethrowPrimitiveStackTraceHandler(v8::Local<v8::Message> message, |
14815 v8::Handle<v8::Value> data) { | 16269 v8::Local<v8::Value> data) { |
14816 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16270 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14817 CHECK(!stack_trace.IsEmpty()); | 16271 CHECK(!stack_trace.IsEmpty()); |
14818 int frame_count = stack_trace->GetFrameCount(); | 16272 int frame_count = stack_trace->GetFrameCount(); |
14819 CHECK_EQ(2, frame_count); | 16273 CHECK_EQ(2, frame_count); |
14820 int line_number[] = {3, 7}; | 16274 int line_number[] = {3, 7}; |
14821 for (int i = 0; i < frame_count; i++) { | 16275 for (int i = 0; i < frame_count; i++) { |
14822 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); | 16276 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); |
14823 } | 16277 } |
14824 } | 16278 } |
14825 | 16279 |
14826 | 16280 |
(...skipping 13 matching lines...) Expand all Loading... | |
14840 " t(e1) \n" | 16294 " t(e1) \n" |
14841 "} \n"; | 16295 "} \n"; |
14842 v8::V8::AddMessageListener(RethrowPrimitiveStackTraceHandler); | 16296 v8::V8::AddMessageListener(RethrowPrimitiveStackTraceHandler); |
14843 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 16297 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
14844 CompileRun(source); | 16298 CompileRun(source); |
14845 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 16299 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14846 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler); | 16300 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler); |
14847 } | 16301 } |
14848 | 16302 |
14849 | 16303 |
14850 static void RethrowExistingStackTraceHandler(v8::Handle<v8::Message> message, | 16304 static void RethrowExistingStackTraceHandler(v8::Local<v8::Message> message, |
14851 v8::Handle<v8::Value> data) { | 16305 v8::Local<v8::Value> data) { |
14852 // Use the frame where JavaScript is called from. | 16306 // Use the frame where JavaScript is called from. |
14853 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16307 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14854 CHECK(!stack_trace.IsEmpty()); | 16308 CHECK(!stack_trace.IsEmpty()); |
14855 CHECK_EQ(1, stack_trace->GetFrameCount()); | 16309 CHECK_EQ(1, stack_trace->GetFrameCount()); |
14856 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); | 16310 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); |
14857 } | 16311 } |
14858 | 16312 |
14859 | 16313 |
14860 // Test that the stack trace is captured when the error object is created and | 16314 // Test that the stack trace is captured when the error object is created and |
14861 // not where it is thrown. | 16315 // not where it is thrown. |
14862 TEST(RethrowExistingStackTrace) { | 16316 TEST(RethrowExistingStackTrace) { |
14863 LocalContext env; | 16317 LocalContext env; |
14864 v8::HandleScope scope(env->GetIsolate()); | 16318 v8::HandleScope scope(env->GetIsolate()); |
14865 const char* source = | 16319 const char* source = |
14866 "var e = new Error(); \n" | 16320 "var e = new Error(); \n" |
14867 "throw e; \n"; | 16321 "throw e; \n"; |
14868 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler); | 16322 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler); |
14869 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 16323 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
14870 CompileRun(source); | 16324 CompileRun(source); |
14871 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); | 16325 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); |
14872 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler); | 16326 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler); |
14873 } | 16327 } |
14874 | 16328 |
14875 | 16329 |
14876 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message, | 16330 static void RethrowBogusErrorStackTraceHandler(v8::Local<v8::Message> message, |
14877 v8::Handle<v8::Value> data) { | 16331 v8::Local<v8::Value> data) { |
14878 // Use the frame where JavaScript is called from. | 16332 // Use the frame where JavaScript is called from. |
14879 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16333 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14880 CHECK(!stack_trace.IsEmpty()); | 16334 CHECK(!stack_trace.IsEmpty()); |
14881 CHECK_EQ(1, stack_trace->GetFrameCount()); | 16335 CHECK_EQ(1, stack_trace->GetFrameCount()); |
14882 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber()); | 16336 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber()); |
14883 } | 16337 } |
14884 | 16338 |
14885 | 16339 |
14886 // Test that the stack trace is captured where the bogus Error object is thrown. | 16340 // Test that the stack trace is captured where the bogus Error object is thrown. |
14887 TEST(RethrowBogusErrorStackTrace) { | 16341 TEST(RethrowBogusErrorStackTrace) { |
14888 LocalContext env; | 16342 LocalContext env; |
14889 v8::HandleScope scope(env->GetIsolate()); | 16343 v8::HandleScope scope(env->GetIsolate()); |
(...skipping 15 matching lines...) Expand all Loading... | |
14905 int promise_reject_msg_column_number = -1; | 16359 int promise_reject_msg_column_number = -1; |
14906 int promise_reject_line_number = -1; | 16360 int promise_reject_line_number = -1; |
14907 int promise_reject_column_number = -1; | 16361 int promise_reject_column_number = -1; |
14908 int promise_reject_frame_count = -1; | 16362 int promise_reject_frame_count = -1; |
14909 | 16363 |
14910 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) { | 16364 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) { |
14911 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) { | 16365 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) { |
14912 promise_reject_counter++; | 16366 promise_reject_counter++; |
14913 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise()); | 16367 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise()); |
14914 CcTest::global()->Set(v8_str("value"), reject_message.GetValue()); | 16368 CcTest::global()->Set(v8_str("value"), reject_message.GetValue()); |
14915 v8::Handle<v8::Message> message = | 16369 v8::Local<v8::Message> message = |
14916 v8::Exception::CreateMessage(reject_message.GetValue()); | 16370 v8::Exception::CreateMessage(reject_message.GetValue()); |
14917 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); | 16371 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace(); |
14918 | 16372 |
14919 promise_reject_msg_line_number = message->GetLineNumber(); | 16373 promise_reject_msg_line_number = message->GetLineNumber(); |
14920 promise_reject_msg_column_number = message->GetStartColumn() + 1; | 16374 promise_reject_msg_column_number = message->GetStartColumn() + 1; |
14921 | 16375 |
14922 if (!stack_trace.IsEmpty()) { | 16376 if (!stack_trace.IsEmpty()) { |
14923 promise_reject_frame_count = stack_trace->GetFrameCount(); | 16377 promise_reject_frame_count = stack_trace->GetFrameCount(); |
14924 if (promise_reject_frame_count > 0) { | 16378 if (promise_reject_frame_count > 0) { |
14925 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); | 16379 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); |
14926 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); | 16380 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); |
14927 promise_reject_column_number = stack_trace->GetFrame(0)->GetColumn(); | 16381 promise_reject_column_number = stack_trace->GetFrame(0)->GetColumn(); |
14928 } else { | 16382 } else { |
14929 promise_reject_line_number = -1; | 16383 promise_reject_line_number = -1; |
14930 promise_reject_column_number = -1; | 16384 promise_reject_column_number = -1; |
14931 } | 16385 } |
14932 } | 16386 } |
14933 } else { | 16387 } else { |
14934 promise_revoke_counter++; | 16388 promise_revoke_counter++; |
14935 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise()); | 16389 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise()); |
14936 CHECK(reject_message.GetValue().IsEmpty()); | 16390 CHECK(reject_message.GetValue().IsEmpty()); |
14937 } | 16391 } |
14938 } | 16392 } |
14939 | 16393 |
14940 | 16394 |
14941 v8::Handle<v8::Promise> GetPromise(const char* name) { | 16395 v8::Local<v8::Promise> GetPromise(const char* name) { |
14942 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); | 16396 return v8::Local<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); |
14943 } | 16397 } |
14944 | 16398 |
14945 | 16399 |
14946 v8::Handle<v8::Value> RejectValue() { | 16400 v8::Local<v8::Value> RejectValue() { |
14947 return CcTest::global()->Get(v8_str("value")); | 16401 return CcTest::global()->Get(v8_str("value")); |
14948 } | 16402 } |
14949 | 16403 |
14950 | 16404 |
14951 void ResetPromiseStates() { | 16405 void ResetPromiseStates() { |
14952 promise_reject_counter = 0; | 16406 promise_reject_counter = 0; |
14953 promise_revoke_counter = 0; | 16407 promise_revoke_counter = 0; |
14954 promise_reject_msg_line_number = -1; | 16408 promise_reject_msg_line_number = -1; |
14955 promise_reject_msg_column_number = -1; | 16409 promise_reject_msg_column_number = -1; |
14956 promise_reject_line_number = -1; | 16410 promise_reject_line_number = -1; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15275 CHECK_EQ(5, promise_reject_line_number); | 16729 CHECK_EQ(5, promise_reject_line_number); |
15276 CHECK_EQ(10, promise_reject_column_number); | 16730 CHECK_EQ(10, promise_reject_column_number); |
15277 CHECK_EQ(2, promise_reject_msg_line_number); | 16731 CHECK_EQ(2, promise_reject_msg_line_number); |
15278 CHECK_EQ(7, promise_reject_msg_column_number); | 16732 CHECK_EQ(7, promise_reject_msg_column_number); |
15279 } | 16733 } |
15280 | 16734 |
15281 | 16735 |
15282 void AnalyzeStackOfEvalWithSourceURL( | 16736 void AnalyzeStackOfEvalWithSourceURL( |
15283 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16737 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15284 v8::HandleScope scope(args.GetIsolate()); | 16738 v8::HandleScope scope(args.GetIsolate()); |
15285 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16739 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
15286 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 16740 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
15287 CHECK_EQ(5, stackTrace->GetFrameCount()); | 16741 CHECK_EQ(5, stackTrace->GetFrameCount()); |
15288 v8::Handle<v8::String> url = v8_str("eval_url"); | 16742 v8::Local<v8::String> url = v8_str("eval_url"); |
15289 for (int i = 0; i < 3; i++) { | 16743 for (int i = 0; i < 3; i++) { |
15290 v8::Handle<v8::String> name = | 16744 v8::Local<v8::String> name = |
15291 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 16745 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
15292 CHECK(!name.IsEmpty()); | 16746 CHECK(!name.IsEmpty()); |
15293 CHECK(url->Equals(name)); | 16747 CHECK(url->Equals(name)); |
15294 } | 16748 } |
15295 } | 16749 } |
15296 | 16750 |
15297 | 16751 |
15298 TEST(SourceURLInStackTrace) { | 16752 TEST(SourceURLInStackTrace) { |
15299 v8::Isolate* isolate = CcTest::isolate(); | 16753 v8::Isolate* isolate = CcTest::isolate(); |
15300 v8::HandleScope scope(isolate); | 16754 v8::HandleScope scope(isolate); |
(...skipping 22 matching lines...) Expand all Loading... | |
15323 i::SNPrintF(code, source, "//@ sourceURL=eval_url"); | 16777 i::SNPrintF(code, source, "//@ sourceURL=eval_url"); |
15324 CHECK(CompileRun(code.start())->IsUndefined()); | 16778 CHECK(CompileRun(code.start())->IsUndefined()); |
15325 } | 16779 } |
15326 | 16780 |
15327 | 16781 |
15328 static int scriptIdInStack[2]; | 16782 static int scriptIdInStack[2]; |
15329 | 16783 |
15330 void AnalyzeScriptIdInStack( | 16784 void AnalyzeScriptIdInStack( |
15331 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16785 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15332 v8::HandleScope scope(args.GetIsolate()); | 16786 v8::HandleScope scope(args.GetIsolate()); |
15333 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16787 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
15334 args.GetIsolate(), 10, v8::StackTrace::kScriptId); | 16788 args.GetIsolate(), 10, v8::StackTrace::kScriptId); |
15335 CHECK_EQ(2, stackTrace->GetFrameCount()); | 16789 CHECK_EQ(2, stackTrace->GetFrameCount()); |
15336 for (int i = 0; i < 2; i++) { | 16790 for (int i = 0; i < 2; i++) { |
15337 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); | 16791 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); |
15338 } | 16792 } |
15339 } | 16793 } |
15340 | 16794 |
15341 | 16795 |
15342 TEST(ScriptIdInStackTrace) { | 16796 TEST(ScriptIdInStackTrace) { |
15343 v8::Isolate* isolate = CcTest::isolate(); | 16797 v8::Isolate* isolate = CcTest::isolate(); |
15344 v8::HandleScope scope(isolate); | 16798 v8::HandleScope scope(isolate); |
15345 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 16799 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
15346 templ->Set(v8_str("AnalyzeScriptIdInStack"), | 16800 templ->Set(v8_str("AnalyzeScriptIdInStack"), |
15347 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); | 16801 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); |
15348 LocalContext context(0, templ); | 16802 LocalContext context(0, templ); |
15349 | 16803 |
15350 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 16804 v8::Local<v8::String> scriptSource = v8_str( |
15351 isolate, | 16805 "function foo() {\n" |
15352 "function foo() {\n" | 16806 " AnalyzeScriptIdInStack();" |
15353 " AnalyzeScriptIdInStack();" | 16807 "}\n" |
15354 "}\n" | 16808 "foo();\n"); |
15355 "foo();\n"); | |
15356 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test"); | 16809 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test"); |
15357 script->Run(); | 16810 script->Run(); |
15358 for (int i = 0; i < 2; i++) { | 16811 for (int i = 0; i < 2; i++) { |
15359 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); | 16812 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); |
15360 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId()); | 16813 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId()); |
15361 } | 16814 } |
15362 } | 16815 } |
15363 | 16816 |
15364 | 16817 |
15365 void AnalyzeStackOfInlineScriptWithSourceURL( | 16818 void AnalyzeStackOfInlineScriptWithSourceURL( |
15366 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16819 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15367 v8::HandleScope scope(args.GetIsolate()); | 16820 v8::HandleScope scope(args.GetIsolate()); |
15368 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16821 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
15369 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 16822 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
15370 CHECK_EQ(4, stackTrace->GetFrameCount()); | 16823 CHECK_EQ(4, stackTrace->GetFrameCount()); |
15371 v8::Handle<v8::String> url = v8_str("source_url"); | 16824 v8::Local<v8::String> url = v8_str("source_url"); |
15372 for (int i = 0; i < 3; i++) { | 16825 for (int i = 0; i < 3; i++) { |
15373 v8::Handle<v8::String> name = | 16826 v8::Local<v8::String> name = |
15374 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 16827 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
15375 CHECK(!name.IsEmpty()); | 16828 CHECK(!name.IsEmpty()); |
15376 CHECK(url->Equals(name)); | 16829 CHECK(url->Equals(name)); |
15377 } | 16830 } |
15378 } | 16831 } |
15379 | 16832 |
15380 | 16833 |
15381 TEST(InlineScriptWithSourceURLInStackTrace) { | 16834 TEST(InlineScriptWithSourceURLInStackTrace) { |
15382 v8::Isolate* isolate = CcTest::isolate(); | 16835 v8::Isolate* isolate = CcTest::isolate(); |
15383 v8::HandleScope scope(isolate); | 16836 v8::HandleScope scope(isolate); |
(...skipping 20 matching lines...) Expand all Loading... | |
15404 i::SNPrintF(code, source, "//# sourceURL=source_url"); | 16857 i::SNPrintF(code, source, "//# sourceURL=source_url"); |
15405 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); | 16858 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); |
15406 i::SNPrintF(code, source, "//@ sourceURL=source_url"); | 16859 i::SNPrintF(code, source, "//@ sourceURL=source_url"); |
15407 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); | 16860 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); |
15408 } | 16861 } |
15409 | 16862 |
15410 | 16863 |
15411 void AnalyzeStackOfDynamicScriptWithSourceURL( | 16864 void AnalyzeStackOfDynamicScriptWithSourceURL( |
15412 const v8::FunctionCallbackInfo<v8::Value>& args) { | 16865 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15413 v8::HandleScope scope(args.GetIsolate()); | 16866 v8::HandleScope scope(args.GetIsolate()); |
15414 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( | 16867 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( |
15415 args.GetIsolate(), 10, v8::StackTrace::kDetailed); | 16868 args.GetIsolate(), 10, v8::StackTrace::kDetailed); |
15416 CHECK_EQ(4, stackTrace->GetFrameCount()); | 16869 CHECK_EQ(4, stackTrace->GetFrameCount()); |
15417 v8::Handle<v8::String> url = v8_str("source_url"); | 16870 v8::Local<v8::String> url = v8_str("source_url"); |
15418 for (int i = 0; i < 3; i++) { | 16871 for (int i = 0; i < 3; i++) { |
15419 v8::Handle<v8::String> name = | 16872 v8::Local<v8::String> name = |
15420 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); | 16873 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); |
15421 CHECK(!name.IsEmpty()); | 16874 CHECK(!name.IsEmpty()); |
15422 CHECK(url->Equals(name)); | 16875 CHECK(url->Equals(name)); |
15423 } | 16876 } |
15424 } | 16877 } |
15425 | 16878 |
15426 | 16879 |
15427 TEST(DynamicWithSourceURLInStackTrace) { | 16880 TEST(DynamicWithSourceURLInStackTrace) { |
15428 v8::Isolate* isolate = CcTest::isolate(); | 16881 v8::Isolate* isolate = CcTest::isolate(); |
15429 v8::HandleScope scope(isolate); | 16882 v8::HandleScope scope(isolate); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15488 " eval(scriptContents);\n" | 16941 " eval(scriptContents);\n" |
15489 " foo(); }\n" | 16942 " foo(); }\n" |
15490 "outer();\n" | 16943 "outer();\n" |
15491 "//# sourceURL=outer_url"; | 16944 "//# sourceURL=outer_url"; |
15492 | 16945 |
15493 v8::TryCatch try_catch(context->GetIsolate()); | 16946 v8::TryCatch try_catch(context->GetIsolate()); |
15494 CompileRun(source); | 16947 CompileRun(source); |
15495 CHECK(try_catch.HasCaught()); | 16948 CHECK(try_catch.HasCaught()); |
15496 | 16949 |
15497 Local<v8::Message> message = try_catch.Message(); | 16950 Local<v8::Message> message = try_catch.Message(); |
15498 Handle<Value> sourceURL = | 16951 Local<Value> sourceURL = message->GetScriptOrigin().ResourceName(); |
15499 message->GetScriptOrigin().ResourceName(); | |
15500 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); | 16952 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); |
15501 } | 16953 } |
15502 | 16954 |
15503 | 16955 |
15504 TEST(RecursionWithSourceURLInMessageScriptResourceNameOrSourceURL) { | 16956 TEST(RecursionWithSourceURLInMessageScriptResourceNameOrSourceURL) { |
15505 LocalContext context; | 16957 LocalContext context; |
15506 v8::HandleScope scope(context->GetIsolate()); | 16958 v8::HandleScope scope(context->GetIsolate()); |
15507 | 16959 |
15508 const char *source = | 16960 const char *source = |
15509 "function outer() {\n" | 16961 "function outer() {\n" |
15510 " var scriptContents = \"function boo(){ boo(); }\\\n" | 16962 " var scriptContents = \"function boo(){ boo(); }\\\n" |
15511 " //# sourceURL=source_url\";\n" | 16963 " //# sourceURL=source_url\";\n" |
15512 " eval(scriptContents);\n" | 16964 " eval(scriptContents);\n" |
15513 " boo(); }\n" | 16965 " boo(); }\n" |
15514 "outer();\n" | 16966 "outer();\n" |
15515 "//# sourceURL=outer_url"; | 16967 "//# sourceURL=outer_url"; |
15516 | 16968 |
15517 v8::TryCatch try_catch(context->GetIsolate()); | 16969 v8::TryCatch try_catch(context->GetIsolate()); |
15518 CompileRun(source); | 16970 CompileRun(source); |
15519 CHECK(try_catch.HasCaught()); | 16971 CHECK(try_catch.HasCaught()); |
15520 | 16972 |
15521 Local<v8::Message> message = try_catch.Message(); | 16973 Local<v8::Message> message = try_catch.Message(); |
15522 Handle<Value> sourceURL = | 16974 Local<Value> sourceURL = message->GetScriptOrigin().ResourceName(); |
15523 message->GetScriptOrigin().ResourceName(); | |
15524 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); | 16975 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); |
15525 } | 16976 } |
15526 | 16977 |
15527 | 16978 |
15528 static void CreateGarbageInOldSpace() { | 16979 static void CreateGarbageInOldSpace() { |
15529 i::Factory* factory = CcTest::i_isolate()->factory(); | 16980 i::Factory* factory = CcTest::i_isolate()->factory(); |
15530 v8::HandleScope scope(CcTest::isolate()); | 16981 v8::HandleScope scope(CcTest::isolate()); |
15531 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate()); | 16982 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate()); |
15532 for (int i = 0; i < 1000; i++) { | 16983 for (int i = 0; i < 1000; i++) { |
15533 factory->NewFixedArray(1000, i::TENURED); | 16984 factory->NewFixedArray(1000, i::TENURED); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15603 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); | 17054 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); |
15604 | 17055 |
15605 // Set stack limit. | 17056 // Set stack limit. |
15606 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); | 17057 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); |
15607 | 17058 |
15608 // Execute a script. | 17059 // Execute a script. |
15609 LocalContext env; | 17060 LocalContext env; |
15610 v8::HandleScope scope(env->GetIsolate()); | 17061 v8::HandleScope scope(env->GetIsolate()); |
15611 Local<v8::FunctionTemplate> fun_templ = | 17062 Local<v8::FunctionTemplate> fun_templ = |
15612 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback); | 17063 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback); |
15613 Local<Function> fun = fun_templ->GetFunction(); | 17064 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
15614 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17065 CHECK(env->Global() |
17066 ->Set(env.local(), v8_str("get_stack_limit"), fun) | |
17067 .FromJust()); | |
15615 CompileRun("get_stack_limit();"); | 17068 CompileRun("get_stack_limit();"); |
15616 | 17069 |
15617 CHECK(stack_limit == set_limit); | 17070 CHECK(stack_limit == set_limit); |
15618 } | 17071 } |
15619 | 17072 |
15620 | 17073 |
15621 TEST(SetStackLimitInThread) { | 17074 TEST(SetStackLimitInThread) { |
15622 uint32_t* set_limit; | 17075 uint32_t* set_limit; |
15623 { | 17076 { |
15624 v8::Locker locker(CcTest::isolate()); | 17077 v8::Locker locker(CcTest::isolate()); |
15625 set_limit = ComputeStackLimit(stack_breathing_room); | 17078 set_limit = ComputeStackLimit(stack_breathing_room); |
15626 | 17079 |
15627 // Set stack limit. | 17080 // Set stack limit. |
15628 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); | 17081 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); |
15629 | 17082 |
15630 // Execute a script. | 17083 // Execute a script. |
15631 v8::HandleScope scope(CcTest::isolate()); | 17084 v8::HandleScope scope(CcTest::isolate()); |
15632 LocalContext env; | 17085 LocalContext env; |
15633 Local<v8::FunctionTemplate> fun_templ = | 17086 Local<v8::FunctionTemplate> fun_templ = |
15634 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback); | 17087 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback); |
15635 Local<Function> fun = fun_templ->GetFunction(); | 17088 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked(); |
15636 env->Global()->Set(v8_str("get_stack_limit"), fun); | 17089 CHECK(env->Global() |
17090 ->Set(env.local(), v8_str("get_stack_limit"), fun) | |
17091 .FromJust()); | |
15637 CompileRun("get_stack_limit();"); | 17092 CompileRun("get_stack_limit();"); |
15638 | 17093 |
15639 CHECK(stack_limit == set_limit); | 17094 CHECK(stack_limit == set_limit); |
15640 } | 17095 } |
15641 { | 17096 { |
15642 v8::Locker locker(CcTest::isolate()); | 17097 v8::Locker locker(CcTest::isolate()); |
15643 CHECK(stack_limit == set_limit); | 17098 CHECK(stack_limit == set_limit); |
15644 } | 17099 } |
15645 } | 17100 } |
15646 | 17101 |
(...skipping 12 matching lines...) Expand all Loading... | |
15659 | 17114 |
15660 class VisitorImpl : public v8::ExternalResourceVisitor { | 17115 class VisitorImpl : public v8::ExternalResourceVisitor { |
15661 public: | 17116 public: |
15662 explicit VisitorImpl(TestResource** resource) { | 17117 explicit VisitorImpl(TestResource** resource) { |
15663 for (int i = 0; i < 4; i++) { | 17118 for (int i = 0; i < 4; i++) { |
15664 resource_[i] = resource[i]; | 17119 resource_[i] = resource[i]; |
15665 found_resource_[i] = false; | 17120 found_resource_[i] = false; |
15666 } | 17121 } |
15667 } | 17122 } |
15668 virtual ~VisitorImpl() {} | 17123 virtual ~VisitorImpl() {} |
15669 virtual void VisitExternalString(v8::Handle<v8::String> string) { | 17124 virtual void VisitExternalString(v8::Local<v8::String> string) { |
15670 if (!string->IsExternal()) { | 17125 if (!string->IsExternal()) { |
15671 CHECK(string->IsExternalOneByte()); | 17126 CHECK(string->IsExternalOneByte()); |
15672 return; | 17127 return; |
15673 } | 17128 } |
15674 v8::String::ExternalStringResource* resource = | 17129 v8::String::ExternalStringResource* resource = |
15675 string->GetExternalStringResource(); | 17130 string->GetExternalStringResource(); |
15676 CHECK(resource); | 17131 CHECK(resource); |
15677 for (int i = 0; i < 4; i++) { | 17132 for (int i = 0; i < 4; i++) { |
15678 if (resource_[i] == resource) { | 17133 if (resource_[i] == resource) { |
15679 CHECK(!found_resource_[i]); | 17134 CHECK(!found_resource_[i]); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15746 TestResource* resource[4]; | 17201 TestResource* resource[4]; |
15747 resource[0] = new TestResource(two_byte_string); | 17202 resource[0] = new TestResource(two_byte_string); |
15748 v8::Local<v8::String> string0 = | 17203 v8::Local<v8::String> string0 = |
15749 v8::String::NewExternal(env->GetIsolate(), resource[0]); | 17204 v8::String::NewExternal(env->GetIsolate(), resource[0]); |
15750 resource[1] = new TestResource(two_byte_string, NULL, false); | 17205 resource[1] = new TestResource(two_byte_string, NULL, false); |
15751 v8::Local<v8::String> string1 = | 17206 v8::Local<v8::String> string1 = |
15752 v8::String::NewExternal(env->GetIsolate(), resource[1]); | 17207 v8::String::NewExternal(env->GetIsolate(), resource[1]); |
15753 | 17208 |
15754 // Externalized symbol. | 17209 // Externalized symbol. |
15755 resource[2] = new TestResource(two_byte_string, NULL, false); | 17210 resource[2] = new TestResource(two_byte_string, NULL, false); |
15756 v8::Local<v8::String> string2 = v8::String::NewFromUtf8( | 17211 v8::Local<v8::String> string2 = |
15757 env->GetIsolate(), string, v8::String::kInternalizedString); | 17212 v8::String::NewFromUtf8(env->GetIsolate(), string, |
17213 v8::NewStringType::kInternalized) | |
17214 .ToLocalChecked(); | |
15758 CHECK(string2->MakeExternal(resource[2])); | 17215 CHECK(string2->MakeExternal(resource[2])); |
15759 | 17216 |
15760 // Symbolized External. | 17217 // Symbolized External. |
15761 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); | 17218 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); |
15762 v8::Local<v8::String> string3 = | 17219 v8::Local<v8::String> string3 = |
15763 v8::String::NewExternal(env->GetIsolate(), resource[3]); | 17220 v8::String::NewExternal(env->GetIsolate(), resource[3]); |
15764 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. | 17221 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. |
15765 // Turn into a symbol. | 17222 // Turn into a symbol. |
15766 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); | 17223 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); |
15767 CHECK(!CcTest::i_isolate()->factory()->InternalizeString( | 17224 CHECK(!CcTest::i_isolate()->factory()->InternalizeString( |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15923 -infinity, | 17380 -infinity, |
15924 -qnan, | 17381 -qnan, |
15925 -snan | 17382 -snan |
15926 }; | 17383 }; |
15927 int num_test_values = 20; | 17384 int num_test_values = 20; |
15928 | 17385 |
15929 for (int i = 0; i < num_test_values; i++) { | 17386 for (int i = 0; i < num_test_values; i++) { |
15930 double test_value = test_values[i]; | 17387 double test_value = test_values[i]; |
15931 | 17388 |
15932 // Check that Number::New preserves non-NaNs and quiets SNaNs. | 17389 // Check that Number::New preserves non-NaNs and quiets SNaNs. |
15933 v8::Handle<v8::Value> number = v8::Number::New(isolate, test_value); | 17390 v8::Local<v8::Value> number = v8::Number::New(isolate, test_value); |
15934 double stored_number = number->NumberValue(); | 17391 double stored_number = number->NumberValue(); |
15935 if (!std::isnan(test_value)) { | 17392 if (!std::isnan(test_value)) { |
15936 CHECK_EQ(test_value, stored_number); | 17393 CHECK_EQ(test_value, stored_number); |
15937 } else { | 17394 } else { |
15938 uint64_t stored_bits = DoubleToBits(stored_number); | 17395 uint64_t stored_bits = DoubleToBits(stored_number); |
15939 // Check if quiet nan (bits 51..62 all set). | 17396 // Check if quiet nan (bits 51..62 all set). |
15940 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ | 17397 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ |
15941 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ | 17398 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ |
15942 !defined(USE_SIMULATOR) | 17399 !defined(USE_SIMULATOR) |
15943 // Most significant fraction bit for quiet nan is set to 0 | 17400 // Most significant fraction bit for quiet nan is set to 0 |
15944 // on MIPS architecture. Allowed by IEEE-754. | 17401 // on MIPS architecture. Allowed by IEEE-754. |
15945 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17402 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); |
15946 #else | 17403 #else |
15947 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17404 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); |
15948 #endif | 17405 #endif |
15949 } | 17406 } |
15950 | 17407 |
15951 // Check that Date::New preserves non-NaNs in the date range and | 17408 // Check that Date::New preserves non-NaNs in the date range and |
15952 // quiets SNaNs. | 17409 // quiets SNaNs. |
15953 v8::Handle<v8::Value> date = | 17410 v8::Local<v8::Value> date = v8::Date::New(isolate, test_value); |
15954 v8::Date::New(isolate, test_value); | |
15955 double expected_stored_date = DoubleToDateTime(test_value); | 17411 double expected_stored_date = DoubleToDateTime(test_value); |
15956 double stored_date = date->NumberValue(); | 17412 double stored_date = date->NumberValue(); |
15957 if (!std::isnan(expected_stored_date)) { | 17413 if (!std::isnan(expected_stored_date)) { |
15958 CHECK_EQ(expected_stored_date, stored_date); | 17414 CHECK_EQ(expected_stored_date, stored_date); |
15959 } else { | 17415 } else { |
15960 uint64_t stored_bits = DoubleToBits(stored_date); | 17416 uint64_t stored_bits = DoubleToBits(stored_date); |
15961 // Check if quiet nan (bits 51..62 all set). | 17417 // Check if quiet nan (bits 51..62 all set). |
15962 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ | 17418 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ |
15963 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ | 17419 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ |
15964 !defined(USE_SIMULATOR) | 17420 !defined(USE_SIMULATOR) |
15965 // Most significant fraction bit for quiet nan is set to 0 | 17421 // Most significant fraction bit for quiet nan is set to 0 |
15966 // on MIPS architecture. Allowed by IEEE-754. | 17422 // on MIPS architecture. Allowed by IEEE-754. |
15967 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17423 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); |
15968 #else | 17424 #else |
15969 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); | 17425 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); |
15970 #endif | 17426 #endif |
15971 } | 17427 } |
15972 } | 17428 } |
15973 } | 17429 } |
15974 | 17430 |
15975 | 17431 |
15976 static void SpaghettiIncident( | 17432 static void SpaghettiIncident( |
15977 const v8::FunctionCallbackInfo<v8::Value>& args) { | 17433 const v8::FunctionCallbackInfo<v8::Value>& args) { |
15978 v8::HandleScope scope(args.GetIsolate()); | 17434 v8::HandleScope scope(args.GetIsolate()); |
15979 v8::TryCatch tc(args.GetIsolate()); | 17435 v8::TryCatch tc(args.GetIsolate()); |
15980 v8::Handle<v8::String> str(args[0]->ToString(args.GetIsolate())); | 17436 v8::Local<v8::String> str(args[0]->ToString(args.GetIsolate())); |
15981 USE(str); | 17437 USE(str); |
15982 if (tc.HasCaught()) | 17438 if (tc.HasCaught()) |
15983 tc.ReThrow(); | 17439 tc.ReThrow(); |
15984 } | 17440 } |
15985 | 17441 |
15986 | 17442 |
15987 // Test that an exception can be propagated down through a spaghetti | 17443 // Test that an exception can be propagated down through a spaghetti |
15988 // stack using ReThrow. | 17444 // stack using ReThrow. |
15989 THREADED_TEST(SpaghettiStackReThrow) { | 17445 THREADED_TEST(SpaghettiStackReThrow) { |
15990 v8::Isolate* isolate = CcTest::isolate(); | 17446 v8::Isolate* isolate = CcTest::isolate(); |
15991 v8::HandleScope scope(isolate); | 17447 v8::HandleScope scope(isolate); |
15992 LocalContext context; | 17448 LocalContext context; |
15993 context->Global()->Set( | 17449 context->Global()->Set(v8_str("s"), |
15994 v8::String::NewFromUtf8(isolate, "s"), | 17450 v8::FunctionTemplate::New(isolate, SpaghettiIncident) |
15995 v8::FunctionTemplate::New(isolate, SpaghettiIncident)->GetFunction()); | 17451 ->GetFunction(context.local()) |
17452 .ToLocalChecked()); | |
15996 v8::TryCatch try_catch(isolate); | 17453 v8::TryCatch try_catch(isolate); |
15997 CompileRun( | 17454 CompileRun( |
15998 "var i = 0;" | 17455 "var i = 0;" |
15999 "var o = {" | 17456 "var o = {" |
16000 " toString: function () {" | 17457 " toString: function () {" |
16001 " if (i == 10) {" | 17458 " if (i == 10) {" |
16002 " throw 'Hey!';" | 17459 " throw 'Hey!';" |
16003 " } else {" | 17460 " } else {" |
16004 " i++;" | 17461 " i++;" |
16005 " return s(o);" | 17462 " return s(o);" |
(...skipping 20 matching lines...) Expand all Loading... | |
16026 other_context = Context::New(isolate); | 17483 other_context = Context::New(isolate); |
16027 | 17484 |
16028 // Context-dependent context data creates reference from the compilation | 17485 // Context-dependent context data creates reference from the compilation |
16029 // cache to the global object. | 17486 // cache to the global object. |
16030 const char* source_simple = "1"; | 17487 const char* source_simple = "1"; |
16031 { | 17488 { |
16032 v8::HandleScope scope(isolate); | 17489 v8::HandleScope scope(isolate); |
16033 v8::Local<Context> context = Context::New(isolate); | 17490 v8::Local<Context> context = Context::New(isolate); |
16034 | 17491 |
16035 context->Enter(); | 17492 context->Enter(); |
16036 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); | 17493 Local<v8::String> obj = v8_str(""); |
16037 context->SetEmbedderData(0, obj); | 17494 context->SetEmbedderData(0, obj); |
16038 CompileRun(source_simple); | 17495 CompileRun(source_simple); |
16039 context->Exit(); | 17496 context->Exit(); |
16040 } | 17497 } |
16041 isolate->ContextDisposedNotification(); | 17498 isolate->ContextDisposedNotification(); |
16042 for (gc_count = 1; gc_count < 10; gc_count++) { | 17499 for (gc_count = 1; gc_count < 10; gc_count++) { |
16043 other_context->Enter(); | 17500 other_context->Enter(); |
16044 CompileRun(source_simple); | 17501 CompileRun(source_simple); |
16045 other_context->Exit(); | 17502 other_context->Exit(); |
16046 CcTest::heap()->CollectAllGarbage(); | 17503 CcTest::heap()->CollectAllGarbage(); |
(...skipping 28 matching lines...) Expand all Loading... | |
16075 // compilation cache to the global object. | 17532 // compilation cache to the global object. |
16076 const char* source_exception = "function f(){throw 1;} f()"; | 17533 const char* source_exception = "function f(){throw 1;} f()"; |
16077 { | 17534 { |
16078 v8::HandleScope scope(isolate); | 17535 v8::HandleScope scope(isolate); |
16079 v8::Local<Context> context = Context::New(isolate); | 17536 v8::Local<Context> context = Context::New(isolate); |
16080 | 17537 |
16081 context->Enter(); | 17538 context->Enter(); |
16082 v8::TryCatch try_catch(isolate); | 17539 v8::TryCatch try_catch(isolate); |
16083 CompileRun(source_exception); | 17540 CompileRun(source_exception); |
16084 CHECK(try_catch.HasCaught()); | 17541 CHECK(try_catch.HasCaught()); |
16085 v8::Handle<v8::Message> message = try_catch.Message(); | 17542 v8::Local<v8::Message> message = try_catch.Message(); |
16086 CHECK(!message.IsEmpty()); | 17543 CHECK(!message.IsEmpty()); |
16087 CHECK_EQ(1, message->GetLineNumber()); | 17544 CHECK_EQ(1, message->GetLineNumber()); |
16088 context->Exit(); | 17545 context->Exit(); |
16089 } | 17546 } |
16090 isolate->ContextDisposedNotification(); | 17547 isolate->ContextDisposedNotification(); |
16091 for (gc_count = 1; gc_count < 10; gc_count++) { | 17548 for (gc_count = 1; gc_count < 10; gc_count++) { |
16092 other_context->Enter(); | 17549 other_context->Enter(); |
16093 CompileRun(source_exception); | 17550 CompileRun(source_exception); |
16094 other_context->Exit(); | 17551 other_context->Exit(); |
16095 CcTest::heap()->CollectAllGarbage(); | 17552 CcTest::heap()->CollectAllGarbage(); |
16096 if (GetGlobalObjectsCount() == 1) break; | 17553 if (GetGlobalObjectsCount() == 1) break; |
16097 } | 17554 } |
16098 CHECK_GE(2, gc_count); | 17555 CHECK_GE(2, gc_count); |
16099 CHECK_EQ(1, GetGlobalObjectsCount()); | 17556 CHECK_EQ(1, GetGlobalObjectsCount()); |
16100 | 17557 |
16101 isolate->ContextDisposedNotification(); | 17558 isolate->ContextDisposedNotification(); |
16102 } | 17559 } |
16103 | 17560 |
16104 | 17561 |
16105 THREADED_TEST(ScriptOrigin) { | 17562 THREADED_TEST(ScriptOrigin) { |
16106 LocalContext env; | 17563 LocalContext env; |
16107 v8::HandleScope scope(env->GetIsolate()); | 17564 v8::HandleScope scope(env->GetIsolate()); |
16108 v8::ScriptOrigin origin = v8::ScriptOrigin( | 17565 v8::ScriptOrigin origin = v8::ScriptOrigin( |
16109 v8::String::NewFromUtf8(env->GetIsolate(), "test"), | 17566 v8_str("test"), v8::Integer::New(env->GetIsolate(), 1), |
16110 v8::Integer::New(env->GetIsolate(), 1), | |
16111 v8::Integer::New(env->GetIsolate(), 1), v8::True(env->GetIsolate()), | 17567 v8::Integer::New(env->GetIsolate(), 1), v8::True(env->GetIsolate()), |
16112 v8::Handle<v8::Integer>(), v8::True(env->GetIsolate()), | 17568 v8::Local<v8::Integer>(), v8::True(env->GetIsolate()), |
16113 v8::String::NewFromUtf8(env->GetIsolate(), "http://sourceMapUrl"), | 17569 v8_str("http://sourceMapUrl"), v8::True(env->GetIsolate())); |
16114 v8::True(env->GetIsolate())); | 17570 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); |
16115 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | |
16116 env->GetIsolate(), "function f() {}\n\nfunction g() {}"); | |
16117 v8::Script::Compile(script, &origin)->Run(); | 17571 v8::Script::Compile(script, &origin)->Run(); |
16118 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17572 v8::Local<v8::Function> f = |
16119 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 17573 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); |
16120 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 17574 v8::Local<v8::Function> g = |
16121 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 17575 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); |
16122 | 17576 |
16123 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); | 17577 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); |
16124 CHECK_EQ(0, strcmp("test", | 17578 CHECK_EQ(0, strcmp("test", |
16125 *v8::String::Utf8Value(script_origin_f.ResourceName()))); | 17579 *v8::String::Utf8Value(script_origin_f.ResourceName()))); |
16126 CHECK_EQ(1, script_origin_f.ResourceLineOffset()->Int32Value()); | 17580 CHECK_EQ( |
17581 1, | |
17582 script_origin_f.ResourceLineOffset()->Int32Value(env.local()).FromJust()); | |
16127 CHECK(script_origin_f.Options().IsSharedCrossOrigin()); | 17583 CHECK(script_origin_f.Options().IsSharedCrossOrigin()); |
16128 CHECK(script_origin_f.Options().IsEmbedderDebugScript()); | 17584 CHECK(script_origin_f.Options().IsEmbedderDebugScript()); |
16129 CHECK(script_origin_f.Options().IsOpaque()); | 17585 CHECK(script_origin_f.Options().IsOpaque()); |
16130 printf("is name = %d\n", script_origin_f.SourceMapUrl()->IsUndefined()); | 17586 printf("is name = %d\n", script_origin_f.SourceMapUrl()->IsUndefined()); |
16131 | 17587 |
16132 CHECK_EQ(0, strcmp("http://sourceMapUrl", | 17588 CHECK_EQ(0, strcmp("http://sourceMapUrl", |
16133 *v8::String::Utf8Value(script_origin_f.SourceMapUrl()))); | 17589 *v8::String::Utf8Value(script_origin_f.SourceMapUrl()))); |
16134 | 17590 |
16135 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); | 17591 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); |
16136 CHECK_EQ(0, strcmp("test", | 17592 CHECK_EQ(0, strcmp("test", |
16137 *v8::String::Utf8Value(script_origin_g.ResourceName()))); | 17593 *v8::String::Utf8Value(script_origin_g.ResourceName()))); |
16138 CHECK_EQ(1, script_origin_g.ResourceLineOffset()->Int32Value()); | 17594 CHECK_EQ( |
17595 1, | |
17596 script_origin_g.ResourceLineOffset()->Int32Value(env.local()).FromJust()); | |
16139 CHECK(script_origin_g.Options().IsSharedCrossOrigin()); | 17597 CHECK(script_origin_g.Options().IsSharedCrossOrigin()); |
16140 CHECK(script_origin_g.Options().IsEmbedderDebugScript()); | 17598 CHECK(script_origin_g.Options().IsEmbedderDebugScript()); |
16141 CHECK(script_origin_g.Options().IsOpaque()); | 17599 CHECK(script_origin_g.Options().IsOpaque()); |
16142 CHECK_EQ(0, strcmp("http://sourceMapUrl", | 17600 CHECK_EQ(0, strcmp("http://sourceMapUrl", |
16143 *v8::String::Utf8Value(script_origin_g.SourceMapUrl()))); | 17601 *v8::String::Utf8Value(script_origin_g.SourceMapUrl()))); |
16144 } | 17602 } |
16145 | 17603 |
16146 | 17604 |
16147 THREADED_TEST(FunctionGetInferredName) { | 17605 THREADED_TEST(FunctionGetInferredName) { |
16148 LocalContext env; | 17606 LocalContext env; |
16149 v8::HandleScope scope(env->GetIsolate()); | 17607 v8::HandleScope scope(env->GetIsolate()); |
16150 v8::ScriptOrigin origin = | 17608 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
16151 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 17609 v8::Local<v8::String> script = |
16152 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | 17610 v8_str("var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); |
16153 env->GetIsolate(), | |
16154 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); | |
16155 v8::Script::Compile(script, &origin)->Run(); | 17611 v8::Script::Compile(script, &origin)->Run(); |
16156 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17612 v8::Local<v8::Function> f = |
16157 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 17613 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); |
16158 CHECK_EQ(0, | 17614 CHECK_EQ(0, |
16159 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()))); | 17615 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()))); |
16160 } | 17616 } |
16161 | 17617 |
16162 | 17618 |
16163 THREADED_TEST(FunctionGetDebugName) { | 17619 THREADED_TEST(FunctionGetDebugName) { |
16164 LocalContext env; | 17620 LocalContext env; |
16165 v8::HandleScope scope(env->GetIsolate()); | 17621 v8::HandleScope scope(env->GetIsolate()); |
16166 const char* code = | 17622 const char* code = |
16167 "var error = false;" | 17623 "var error = false;" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16261 " throw new Error();" | 17717 " throw new Error();" |
16262 "});" | 17718 "});" |
16263 "function f() {};" | 17719 "function f() {};" |
16264 "f.displayName = { 'foo': 6, toString: function() {" | 17720 "f.displayName = { 'foo': 6, toString: function() {" |
16265 " error = true;" | 17721 " error = true;" |
16266 " return 'wrong_display_name';" | 17722 " return 'wrong_display_name';" |
16267 "}};" | 17723 "}};" |
16268 "var g = function() {" | 17724 "var g = function() {" |
16269 " arguments.callee.displayName = 'set_in_runtime';" | 17725 " arguments.callee.displayName = 'set_in_runtime';" |
16270 "}; g();"; | 17726 "}; g();"; |
16271 v8::ScriptOrigin origin = | 17727 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
16272 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 17728 v8::Script::Compile(v8_str(code), &origin)->Run(); |
16273 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), code), &origin) | 17729 v8::Local<v8::Value> error = env->Global()->Get(v8_str("error")); |
16274 ->Run(); | 17730 v8::Local<v8::Function> a = |
16275 v8::Local<v8::Value> error = | 17731 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("a"))); |
16276 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "error")); | 17732 v8::Local<v8::Function> b = |
16277 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast( | 17733 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("b"))); |
16278 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "a"))); | 17734 v8::Local<v8::Function> c = |
16279 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast( | 17735 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("c"))); |
16280 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "b"))); | 17736 v8::Local<v8::Function> d = |
16281 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast( | 17737 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("d"))); |
16282 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c"))); | 17738 v8::Local<v8::Function> e = |
16283 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast( | 17739 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("e"))); |
16284 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "d"))); | 17740 v8::Local<v8::Function> f = |
16285 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast( | 17741 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); |
16286 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "e"))); | 17742 v8::Local<v8::Function> g = |
16287 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17743 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); |
16288 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | |
16289 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | |
16290 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | |
16291 CHECK_EQ(false, error->BooleanValue()); | 17744 CHECK_EQ(false, error->BooleanValue()); |
16292 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName()))); | 17745 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName()))); |
16293 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName()))); | 17746 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName()))); |
16294 CHECK(c->GetDisplayName()->IsUndefined()); | 17747 CHECK(c->GetDisplayName()->IsUndefined()); |
16295 CHECK(d->GetDisplayName()->IsUndefined()); | 17748 CHECK(d->GetDisplayName()->IsUndefined()); |
16296 CHECK(e->GetDisplayName()->IsUndefined()); | 17749 CHECK(e->GetDisplayName()->IsUndefined()); |
16297 CHECK(f->GetDisplayName()->IsUndefined()); | 17750 CHECK(f->GetDisplayName()->IsUndefined()); |
16298 CHECK_EQ( | 17751 CHECK_EQ( |
16299 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()))); | 17752 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()))); |
16300 } | 17753 } |
16301 | 17754 |
16302 | 17755 |
16303 THREADED_TEST(ScriptLineNumber) { | 17756 THREADED_TEST(ScriptLineNumber) { |
16304 LocalContext env; | 17757 LocalContext env; |
16305 v8::HandleScope scope(env->GetIsolate()); | 17758 v8::HandleScope scope(env->GetIsolate()); |
16306 v8::ScriptOrigin origin = | 17759 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
16307 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); | 17760 v8::Local<v8::String> script = v8_str("function f() {}\n\nfunction g() {}"); |
16308 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | |
16309 env->GetIsolate(), "function f() {}\n\nfunction g() {}"); | |
16310 v8::Script::Compile(script, &origin)->Run(); | 17761 v8::Script::Compile(script, &origin)->Run(); |
16311 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17762 v8::Local<v8::Function> f = |
16312 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 17763 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); |
16313 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 17764 v8::Local<v8::Function> g = |
16314 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 17765 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); |
16315 CHECK_EQ(0, f->GetScriptLineNumber()); | 17766 CHECK_EQ(0, f->GetScriptLineNumber()); |
16316 CHECK_EQ(2, g->GetScriptLineNumber()); | 17767 CHECK_EQ(2, g->GetScriptLineNumber()); |
16317 } | 17768 } |
16318 | 17769 |
16319 | 17770 |
16320 THREADED_TEST(ScriptColumnNumber) { | 17771 THREADED_TEST(ScriptColumnNumber) { |
16321 LocalContext env; | 17772 LocalContext env; |
16322 v8::Isolate* isolate = env->GetIsolate(); | 17773 v8::Isolate* isolate = env->GetIsolate(); |
16323 v8::HandleScope scope(isolate); | 17774 v8::HandleScope scope(isolate); |
16324 v8::ScriptOrigin origin = | 17775 v8::ScriptOrigin origin = |
16325 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), | 17776 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), |
16326 v8::Integer::New(isolate, 3), | |
16327 v8::Integer::New(isolate, 2)); | 17777 v8::Integer::New(isolate, 2)); |
16328 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | 17778 v8::Local<v8::String> script = |
16329 isolate, "function foo() {}\n\n function bar() {}"); | 17779 v8_str("function foo() {}\n\n function bar() {}"); |
16330 v8::Script::Compile(script, &origin)->Run(); | 17780 v8::Script::Compile(script, &origin)->Run(); |
16331 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 17781 v8::Local<v8::Function> foo = |
16332 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); | 17782 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo"))); |
16333 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 17783 v8::Local<v8::Function> bar = |
16334 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); | 17784 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar"))); |
16335 CHECK_EQ(14, foo->GetScriptColumnNumber()); | 17785 CHECK_EQ(14, foo->GetScriptColumnNumber()); |
16336 CHECK_EQ(17, bar->GetScriptColumnNumber()); | 17786 CHECK_EQ(17, bar->GetScriptColumnNumber()); |
16337 } | 17787 } |
16338 | 17788 |
16339 | 17789 |
16340 THREADED_TEST(FunctionIsBuiltin) { | 17790 THREADED_TEST(FunctionIsBuiltin) { |
16341 LocalContext env; | 17791 LocalContext env; |
16342 v8::Isolate* isolate = env->GetIsolate(); | 17792 v8::Isolate* isolate = env->GetIsolate(); |
16343 v8::HandleScope scope(isolate); | 17793 v8::HandleScope scope(isolate); |
16344 v8::Local<v8::Function> f; | 17794 v8::Local<v8::Function> f; |
16345 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); | 17795 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); |
16346 CHECK(f->IsBuiltin()); | 17796 CHECK(f->IsBuiltin()); |
16347 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); | 17797 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); |
16348 CHECK(f->IsBuiltin()); | 17798 CHECK(f->IsBuiltin()); |
16349 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); | 17799 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); |
16350 CHECK(f->IsBuiltin()); | 17800 CHECK(f->IsBuiltin()); |
16351 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); | 17801 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); |
16352 CHECK(f->IsBuiltin()); | 17802 CHECK(f->IsBuiltin()); |
16353 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); | 17803 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); |
16354 CHECK(!f->IsBuiltin()); | 17804 CHECK(!f->IsBuiltin()); |
16355 } | 17805 } |
16356 | 17806 |
16357 | 17807 |
16358 THREADED_TEST(FunctionGetScriptId) { | 17808 THREADED_TEST(FunctionGetScriptId) { |
16359 LocalContext env; | 17809 LocalContext env; |
16360 v8::Isolate* isolate = env->GetIsolate(); | 17810 v8::Isolate* isolate = env->GetIsolate(); |
16361 v8::HandleScope scope(isolate); | 17811 v8::HandleScope scope(isolate); |
16362 v8::ScriptOrigin origin = | 17812 v8::ScriptOrigin origin = |
16363 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), | 17813 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3), |
16364 v8::Integer::New(isolate, 3), | |
16365 v8::Integer::New(isolate, 2)); | 17814 v8::Integer::New(isolate, 2)); |
16366 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( | 17815 v8::Local<v8::String> scriptSource = |
16367 isolate, "function foo() {}\n\n function bar() {}"); | 17816 v8_str("function foo() {}\n\n function bar() {}"); |
16368 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); | 17817 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); |
16369 script->Run(); | 17818 script->Run(); |
16370 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( | 17819 v8::Local<v8::Function> foo = |
16371 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); | 17820 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo"))); |
16372 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( | 17821 v8::Local<v8::Function> bar = |
16373 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); | 17822 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar"))); |
16374 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId()); | 17823 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId()); |
16375 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId()); | 17824 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId()); |
16376 } | 17825 } |
16377 | 17826 |
16378 | 17827 |
16379 THREADED_TEST(FunctionGetBoundFunction) { | 17828 THREADED_TEST(FunctionGetBoundFunction) { |
16380 LocalContext env; | 17829 LocalContext env; |
16381 v8::HandleScope scope(env->GetIsolate()); | 17830 v8::HandleScope scope(env->GetIsolate()); |
16382 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8( | 17831 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test")); |
16383 env->GetIsolate(), "test")); | 17832 v8::Local<v8::String> script = v8_str( |
16384 v8::Handle<v8::String> script = v8::String::NewFromUtf8( | |
16385 env->GetIsolate(), | |
16386 "var a = new Object();\n" | 17833 "var a = new Object();\n" |
16387 "a.x = 1;\n" | 17834 "a.x = 1;\n" |
16388 "function f () { return this.x };\n" | 17835 "function f () { return this.x };\n" |
16389 "var g = f.bind(a);\n" | 17836 "var g = f.bind(a);\n" |
16390 "var b = g();"); | 17837 "var b = g();"); |
16391 v8::Script::Compile(script, &origin)->Run(); | 17838 v8::Script::Compile(script, &origin)->Run(); |
16392 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 17839 v8::Local<v8::Function> f = |
16393 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); | 17840 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f"))); |
16394 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( | 17841 v8::Local<v8::Function> g = |
16395 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); | 17842 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g"))); |
16396 CHECK(g->GetBoundFunction()->IsFunction()); | 17843 CHECK(g->GetBoundFunction()->IsFunction()); |
16397 Local<v8::Function> original_function = Local<v8::Function>::Cast( | 17844 Local<v8::Function> original_function = Local<v8::Function>::Cast( |
16398 g->GetBoundFunction()); | 17845 g->GetBoundFunction()); |
16399 CHECK(f->GetName()->Equals(original_function->GetName())); | 17846 CHECK(f->GetName()->Equals(original_function->GetName())); |
16400 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); | 17847 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); |
16401 CHECK_EQ(f->GetScriptColumnNumber(), | 17848 CHECK_EQ(f->GetScriptColumnNumber(), |
16402 original_function->GetScriptColumnNumber()); | 17849 original_function->GetScriptColumnNumber()); |
16403 } | 17850 } |
16404 | 17851 |
16405 | 17852 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16441 } | 17888 } |
16442 | 17889 |
16443 | 17890 |
16444 TEST(SetterOnConstructorPrototype) { | 17891 TEST(SetterOnConstructorPrototype) { |
16445 v8::Isolate* isolate = CcTest::isolate(); | 17892 v8::Isolate* isolate = CcTest::isolate(); |
16446 v8::HandleScope scope(isolate); | 17893 v8::HandleScope scope(isolate); |
16447 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 17894 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
16448 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, | 17895 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
16449 SetterWhichSetsYOnThisTo23); | 17896 SetterWhichSetsYOnThisTo23); |
16450 LocalContext context; | 17897 LocalContext context; |
16451 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 17898 CHECK(context->Global() |
17899 ->Set(context.local(), v8_str("P"), | |
17900 templ->NewInstance(context.local()).ToLocalChecked()) | |
17901 .FromJust()); | |
16452 CompileRun("function C1() {" | 17902 CompileRun("function C1() {" |
16453 " this.x = 23;" | 17903 " this.x = 23;" |
16454 "};" | 17904 "};" |
16455 "C1.prototype = P;" | 17905 "C1.prototype = P;" |
16456 "function C2() {" | 17906 "function C2() {" |
16457 " this.x = 23" | 17907 " this.x = 23" |
16458 "};" | 17908 "};" |
16459 "C2.prototype = { };" | 17909 "C2.prototype = { };" |
16460 "C2.prototype.__proto__ = P;"); | 17910 "C2.prototype.__proto__ = P;"); |
16461 | 17911 |
16462 v8::Local<v8::Script> script; | 17912 v8::Local<v8::Script> script; |
16463 script = v8_compile("new C1();"); | 17913 script = v8_compile("new C1();"); |
16464 for (int i = 0; i < 10; i++) { | 17914 for (int i = 0; i < 10; i++) { |
16465 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 17915 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); |
16466 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 17916 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16467 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 17917 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16468 } | 17918 } |
16469 | 17919 |
16470 script = v8_compile("new C2();"); | 17920 script = v8_compile("new C2();"); |
16471 for (int i = 0; i < 10; i++) { | 17921 for (int i = 0; i < 10; i++) { |
16472 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 17922 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run()); |
16473 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); | 17923 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16474 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); | 17924 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16475 } | 17925 } |
16476 } | 17926 } |
16477 | 17927 |
16478 | 17928 |
16479 static void NamedPropertyGetterWhichReturns42( | 17929 static void NamedPropertyGetterWhichReturns42( |
16480 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { | 17930 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { |
16481 info.GetReturnValue().Set(v8_num(42)); | 17931 info.GetReturnValue().Set(v8_num(42)); |
16482 } | 17932 } |
16483 | 17933 |
16484 | 17934 |
16485 static void NamedPropertySetterWhichSetsYOnThisTo23( | 17935 static void NamedPropertySetterWhichSetsYOnThisTo23( |
16486 Local<Name> name, Local<Value> value, | 17936 Local<Name> name, Local<Value> value, |
16487 const v8::PropertyCallbackInfo<v8::Value>& info) { | 17937 const v8::PropertyCallbackInfo<v8::Value>& info) { |
16488 if (name->Equals(v8_str("x"))) { | 17938 if (name->Equals(v8_str("x"))) { |
16489 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); | 17939 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); |
16490 } | 17940 } |
16491 } | 17941 } |
16492 | 17942 |
16493 | 17943 |
16494 THREADED_TEST(InterceptorOnConstructorPrototype) { | 17944 THREADED_TEST(InterceptorOnConstructorPrototype) { |
16495 v8::Isolate* isolate = CcTest::isolate(); | 17945 v8::Isolate* isolate = CcTest::isolate(); |
16496 v8::HandleScope scope(isolate); | 17946 v8::HandleScope scope(isolate); |
16497 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 17947 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
16498 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 17948 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
16499 NamedPropertyGetterWhichReturns42, | 17949 NamedPropertyGetterWhichReturns42, |
16500 NamedPropertySetterWhichSetsYOnThisTo23)); | 17950 NamedPropertySetterWhichSetsYOnThisTo23)); |
16501 LocalContext context; | 17951 LocalContext context; |
16502 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 17952 CHECK(context->Global() |
17953 ->Set(context.local(), v8_str("P"), | |
17954 templ->NewInstance(context.local()).ToLocalChecked()) | |
17955 .FromJust()); | |
16503 CompileRun("function C1() {" | 17956 CompileRun("function C1() {" |
16504 " this.x = 23;" | 17957 " this.x = 23;" |
16505 "};" | 17958 "};" |
16506 "C1.prototype = P;" | 17959 "C1.prototype = P;" |
16507 "function C2() {" | 17960 "function C2() {" |
16508 " this.x = 23" | 17961 " this.x = 23" |
16509 "};" | 17962 "};" |
16510 "C2.prototype = { };" | 17963 "C2.prototype = { };" |
16511 "C2.prototype.__proto__ = P;"); | 17964 "C2.prototype.__proto__ = P;"); |
16512 | 17965 |
16513 v8::Local<v8::Script> script; | 17966 v8::Local<v8::Script> script; |
16514 script = v8_compile("new C1();"); | 17967 script = v8_compile("new C1();"); |
16515 for (int i = 0; i < 10; i++) { | 17968 for (int i = 0; i < 10; i++) { |
16516 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 17969 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); |
16517 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 17970 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16518 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 17971 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16519 } | 17972 } |
16520 | 17973 |
16521 script = v8_compile("new C2();"); | 17974 script = v8_compile("new C2();"); |
16522 for (int i = 0; i < 10; i++) { | 17975 for (int i = 0; i < 10; i++) { |
16523 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); | 17976 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run()); |
16524 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); | 17977 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16525 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); | 17978 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16526 } | 17979 } |
16527 } | 17980 } |
16528 | 17981 |
16529 | 17982 |
16530 TEST(Regress618) { | 17983 TEST(Regress618) { |
16531 const char* source = "function C1() {" | 17984 const char* source = "function C1() {" |
16532 " this.x = 23;" | 17985 " this.x = 23;" |
16533 "};" | 17986 "};" |
16534 "C1.prototype = P;"; | 17987 "C1.prototype = P;"; |
16535 | 17988 |
16536 LocalContext context; | 17989 LocalContext context; |
16537 v8::Isolate* isolate = context->GetIsolate(); | 17990 v8::Isolate* isolate = context->GetIsolate(); |
16538 v8::HandleScope scope(isolate); | 17991 v8::HandleScope scope(isolate); |
16539 v8::Local<v8::Script> script; | 17992 v8::Local<v8::Script> script; |
16540 | 17993 |
16541 // Use a simple object as prototype. | 17994 // Use a simple object as prototype. |
16542 v8::Local<v8::Object> prototype = v8::Object::New(isolate); | 17995 v8::Local<v8::Object> prototype = v8::Object::New(isolate); |
16543 prototype->Set(v8_str("y"), v8_num(42)); | 17996 prototype->Set(v8_str("y"), v8_num(42)); |
16544 context->Global()->Set(v8_str("P"), prototype); | 17997 CHECK(context->Global() |
17998 ->Set(context.local(), v8_str("P"), prototype) | |
17999 .FromJust()); | |
16545 | 18000 |
16546 // This compile will add the code to the compilation cache. | 18001 // This compile will add the code to the compilation cache. |
16547 CompileRun(source); | 18002 CompileRun(source); |
16548 | 18003 |
16549 script = v8_compile("new C1();"); | 18004 script = v8_compile("new C1();"); |
16550 // Allow enough iterations for the inobject slack tracking logic | 18005 // Allow enough iterations for the inobject slack tracking logic |
16551 // to finalize instance size and install the fast construct stub. | 18006 // to finalize instance size and install the fast construct stub. |
16552 for (int i = 0; i < 256; i++) { | 18007 for (int i = 0; i < 256; i++) { |
16553 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18008 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); |
16554 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); | 18009 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16555 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); | 18010 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16556 } | 18011 } |
16557 | 18012 |
16558 // Use an API object with accessors as prototype. | 18013 // Use an API object with accessors as prototype. |
16559 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 18014 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
16560 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, | 18015 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, |
16561 SetterWhichSetsYOnThisTo23); | 18016 SetterWhichSetsYOnThisTo23); |
16562 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 18017 CHECK(context->Global() |
18018 ->Set(context.local(), v8_str("P"), | |
18019 templ->NewInstance(context.local()).ToLocalChecked()) | |
18020 .FromJust()); | |
16563 | 18021 |
16564 // This compile will get the code from the compilation cache. | 18022 // This compile will get the code from the compilation cache. |
16565 CompileRun(source); | 18023 CompileRun(source); |
16566 | 18024 |
16567 script = v8_compile("new C1();"); | 18025 script = v8_compile("new C1();"); |
16568 for (int i = 0; i < 10; i++) { | 18026 for (int i = 0; i < 10; i++) { |
16569 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); | 18027 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run()); |
16570 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); | 18028 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust()); |
16571 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); | 18029 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust()); |
16572 } | 18030 } |
16573 } | 18031 } |
16574 | 18032 |
16575 v8::Isolate* gc_callbacks_isolate = NULL; | 18033 v8::Isolate* gc_callbacks_isolate = NULL; |
16576 int prologue_call_count = 0; | 18034 int prologue_call_count = 0; |
16577 int epilogue_call_count = 0; | 18035 int epilogue_call_count = 0; |
16578 int prologue_call_count_second = 0; | 18036 int prologue_call_count_second = 0; |
16579 int epilogue_call_count_second = 0; | 18037 int epilogue_call_count_second = 0; |
16580 int prologue_call_count_alloc = 0; | 18038 int prologue_call_count_alloc = 0; |
16581 int epilogue_call_count_alloc = 0; | 18039 int epilogue_call_count_alloc = 0; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16805 CHECK(string->IsOneByteRepresentation()); | 18263 CHECK(string->IsOneByteRepresentation()); |
16806 i::ConsString* cons = i::ConsString::cast(*string); | 18264 i::ConsString* cons = i::ConsString::cast(*string); |
16807 CHECK_EQ(0, cons->second()->length()); | 18265 CHECK_EQ(0, cons->second()->length()); |
16808 CHECK(cons->first()->IsTwoByteRepresentation()); | 18266 CHECK(cons->first()->IsTwoByteRepresentation()); |
16809 } | 18267 } |
16810 | 18268 |
16811 // Check that some string operations work. | 18269 // Check that some string operations work. |
16812 | 18270 |
16813 // Atom RegExp. | 18271 // Atom RegExp. |
16814 Local<Value> reresult = CompileRun("str2.match(/abel/g).length;"); | 18272 Local<Value> reresult = CompileRun("str2.match(/abel/g).length;"); |
16815 CHECK_EQ(6, reresult->Int32Value()); | 18273 CHECK_EQ(6, reresult->Int32Value(context.local()).FromJust()); |
16816 | 18274 |
16817 // Nonatom RegExp. | 18275 // Nonatom RegExp. |
16818 reresult = CompileRun("str2.match(/abe./g).length;"); | 18276 reresult = CompileRun("str2.match(/abe./g).length;"); |
16819 CHECK_EQ(6, reresult->Int32Value()); | 18277 CHECK_EQ(6, reresult->Int32Value(context.local()).FromJust()); |
16820 | 18278 |
16821 reresult = CompileRun("str2.search(/bel/g);"); | 18279 reresult = CompileRun("str2.search(/bel/g);"); |
16822 CHECK_EQ(1, reresult->Int32Value()); | 18280 CHECK_EQ(1, reresult->Int32Value(context.local()).FromJust()); |
16823 | 18281 |
16824 reresult = CompileRun("str2.search(/be./g);"); | 18282 reresult = CompileRun("str2.search(/be./g);"); |
16825 CHECK_EQ(1, reresult->Int32Value()); | 18283 CHECK_EQ(1, reresult->Int32Value(context.local()).FromJust()); |
16826 | 18284 |
16827 ExpectTrue("/bel/g.test(str2);"); | 18285 ExpectTrue("/bel/g.test(str2);"); |
16828 | 18286 |
16829 ExpectTrue("/be./g.test(str2);"); | 18287 ExpectTrue("/be./g.test(str2);"); |
16830 | 18288 |
16831 reresult = CompileRun("/bel/g.exec(str2);"); | 18289 reresult = CompileRun("/bel/g.exec(str2);"); |
16832 CHECK(!reresult->IsNull()); | 18290 CHECK(!reresult->IsNull()); |
16833 | 18291 |
16834 reresult = CompileRun("/be./g.exec(str2);"); | 18292 reresult = CompileRun("/be./g.exec(str2);"); |
16835 CHECK(!reresult->IsNull()); | 18293 CHECK(!reresult->IsNull()); |
16836 | 18294 |
16837 ExpectString("str2.substring(2, 10);", "elspenda"); | 18295 ExpectString("str2.substring(2, 10);", "elspenda"); |
16838 | 18296 |
16839 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); | 18297 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); |
16840 | 18298 |
16841 ExpectString("str2.charAt(2);", "e"); | 18299 ExpectString("str2.charAt(2);", "e"); |
16842 | 18300 |
16843 ExpectObject("str2.indexOf('els');", indexof); | 18301 ExpectObject("str2.indexOf('els');", indexof); |
16844 | 18302 |
16845 ExpectObject("str2.lastIndexOf('dab');", lastindexof); | 18303 ExpectObject("str2.lastIndexOf('dab');", lastindexof); |
16846 | 18304 |
16847 reresult = CompileRun("str2.charCodeAt(2);"); | 18305 reresult = CompileRun("str2.charCodeAt(2);"); |
16848 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); | 18306 CHECK_EQ(static_cast<int32_t>('e'), |
18307 reresult->Int32Value(context.local()).FromJust()); | |
16849 } | 18308 } |
16850 | 18309 |
16851 | 18310 |
16852 TEST(ContainsOnlyOneByte) { | 18311 TEST(ContainsOnlyOneByte) { |
16853 v8::V8::Initialize(); | 18312 v8::V8::Initialize(); |
16854 v8::Isolate* isolate = CcTest::isolate(); | 18313 v8::Isolate* isolate = CcTest::isolate(); |
16855 v8::HandleScope scope(isolate); | 18314 v8::HandleScope scope(isolate); |
16856 // Make a buffer long enough that it won't automatically be converted. | 18315 // Make a buffer long enough that it won't automatically be converted. |
16857 const int length = 512; | 18316 const int length = 512; |
16858 // Ensure word aligned assignment. | 18317 // Ensure word aligned assignment. |
16859 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); | 18318 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); |
16860 v8::base::SmartArrayPointer<uintptr_t> aligned_contents( | 18319 v8::base::SmartArrayPointer<uintptr_t> aligned_contents( |
16861 new uintptr_t[aligned_length]); | 18320 new uintptr_t[aligned_length]); |
16862 uint16_t* string_contents = | 18321 uint16_t* string_contents = |
16863 reinterpret_cast<uint16_t*>(aligned_contents.get()); | 18322 reinterpret_cast<uint16_t*>(aligned_contents.get()); |
16864 // Set to contain only one byte. | 18323 // Set to contain only one byte. |
16865 for (int i = 0; i < length-1; i++) { | 18324 for (int i = 0; i < length-1; i++) { |
16866 string_contents[i] = 0x41; | 18325 string_contents[i] = 0x41; |
16867 } | 18326 } |
16868 string_contents[length-1] = 0; | 18327 string_contents[length-1] = 0; |
16869 // Simple case. | 18328 // Simple case. |
16870 Handle<String> string = | 18329 Local<String> string = String::NewExternal( |
16871 String::NewExternal(isolate, | 18330 isolate, new TestResource(string_contents, NULL, false)); |
16872 new TestResource(string_contents, NULL, false)); | |
16873 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18331 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
16874 // Counter example. | 18332 // Counter example. |
16875 string = String::NewFromTwoByte(isolate, string_contents); | 18333 string = String::NewFromTwoByte(isolate, string_contents); |
16876 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18334 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
16877 // Test left right and balanced cons strings. | 18335 // Test left right and balanced cons strings. |
16878 Handle<String> base = String::NewFromUtf8(isolate, "a"); | 18336 Local<String> base = v8_str("a"); |
16879 Handle<String> left = base; | 18337 Local<String> left = base; |
16880 Handle<String> right = base; | 18338 Local<String> right = base; |
16881 for (int i = 0; i < 1000; i++) { | 18339 for (int i = 0; i < 1000; i++) { |
16882 left = String::Concat(base, left); | 18340 left = String::Concat(base, left); |
16883 right = String::Concat(right, base); | 18341 right = String::Concat(right, base); |
16884 } | 18342 } |
16885 Handle<String> balanced = String::Concat(left, base); | 18343 Local<String> balanced = String::Concat(left, base); |
16886 balanced = String::Concat(balanced, right); | 18344 balanced = String::Concat(balanced, right); |
16887 Handle<String> cons_strings[] = {left, balanced, right}; | 18345 Local<String> cons_strings[] = {left, balanced, right}; |
16888 Handle<String> two_byte = | 18346 Local<String> two_byte = String::NewExternal( |
16889 String::NewExternal(isolate, | 18347 isolate, new TestResource(string_contents, NULL, false)); |
16890 new TestResource(string_contents, NULL, false)); | |
16891 USE(two_byte); USE(cons_strings); | 18348 USE(two_byte); USE(cons_strings); |
16892 for (size_t i = 0; i < arraysize(cons_strings); i++) { | 18349 for (size_t i = 0; i < arraysize(cons_strings); i++) { |
16893 // Base assumptions. | 18350 // Base assumptions. |
16894 string = cons_strings[i]; | 18351 string = cons_strings[i]; |
16895 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); | 18352 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); |
16896 // Test left and right concatentation. | 18353 // Test left and right concatentation. |
16897 string = String::Concat(two_byte, cons_strings[i]); | 18354 string = String::Concat(two_byte, cons_strings[i]); |
16898 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18355 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
16899 string = String::Concat(cons_strings[i], two_byte); | 18356 string = String::Concat(cons_strings[i], two_byte); |
16900 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); | 18357 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
16936 // invocation. Then force the callback to be called from va | 18393 // invocation. Then force the callback to be called from va |
16937 | 18394 |
16938 v8::V8::Initialize(); | 18395 v8::V8::Initialize(); |
16939 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); | 18396 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); |
16940 | 18397 |
16941 v8::Isolate* isolate = CcTest::isolate(); | 18398 v8::Isolate* isolate = CcTest::isolate(); |
16942 v8::HandleScope scope(isolate); | 18399 v8::HandleScope scope(isolate); |
16943 | 18400 |
16944 // Create an ObjectTemplate for global objects and install access | 18401 // Create an ObjectTemplate for global objects and install access |
16945 // check callbacks that will block access. | 18402 // check callbacks that will block access. |
16946 v8::Handle<v8::ObjectTemplate> global_template = | 18403 v8::Local<v8::ObjectTemplate> global_template = |
16947 v8::ObjectTemplate::New(isolate); | 18404 v8::ObjectTemplate::New(isolate); |
16948 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 18405 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
16949 | 18406 |
16950 // Create a context and set an x property on it's global object. | 18407 // Create a context and set an x property on it's global object. |
16951 LocalContext context0(NULL, global_template); | 18408 LocalContext context0(NULL, global_template); |
16952 context0->Global()->Set(v8_str("x"), v8_num(42)); | 18409 CHECK(context0->Global() |
16953 v8::Handle<v8::Object> global0 = context0->Global(); | 18410 ->Set(context0.local(), v8_str("x"), v8_num(42)) |
18411 .FromJust()); | |
18412 v8::Local<v8::Object> global0 = context0->Global(); | |
16954 | 18413 |
16955 // Create a context with a different security token so that the | 18414 // Create a context with a different security token so that the |
16956 // failed access check callback will be called on each access. | 18415 // failed access check callback will be called on each access. |
16957 LocalContext context1(NULL, global_template); | 18416 LocalContext context1(NULL, global_template); |
16958 context1->Global()->Set(v8_str("other"), global0); | 18417 CHECK(context1->Global() |
18418 ->Set(context1.local(), v8_str("other"), global0) | |
18419 .FromJust()); | |
16959 | 18420 |
16960 v8::TryCatch try_catch(isolate); | 18421 v8::TryCatch try_catch(isolate); |
16961 | 18422 |
16962 // Get property with failed access check. | 18423 // Get property with failed access check. |
16963 CHECK(CompileRun("other.x").IsEmpty()); | 18424 CHECK(CompileRun("other.x").IsEmpty()); |
16964 CHECK(try_catch.HasCaught()); | 18425 CHECK(try_catch.HasCaught()); |
16965 try_catch.Reset(); | 18426 try_catch.Reset(); |
16966 | 18427 |
16967 // Get element with failed access check. | 18428 // Get element with failed access check. |
16968 CHECK(CompileRun("other[0]").IsEmpty()); | 18429 CHECK(CompileRun("other[0]").IsEmpty()); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17541 public: | 19002 public: |
17542 explicit Visitor42(v8::Persistent<v8::Object>* object) | 19003 explicit Visitor42(v8::Persistent<v8::Object>* object) |
17543 : counter_(0), object_(object) { } | 19004 : counter_(0), object_(object) { } |
17544 | 19005 |
17545 virtual void VisitPersistentHandle(Persistent<Value>* value, | 19006 virtual void VisitPersistentHandle(Persistent<Value>* value, |
17546 uint16_t class_id) { | 19007 uint16_t class_id) { |
17547 if (class_id != 42) return; | 19008 if (class_id != 42) return; |
17548 CHECK_EQ(42, value->WrapperClassId()); | 19009 CHECK_EQ(42, value->WrapperClassId()); |
17549 v8::Isolate* isolate = CcTest::isolate(); | 19010 v8::Isolate* isolate = CcTest::isolate(); |
17550 v8::HandleScope handle_scope(isolate); | 19011 v8::HandleScope handle_scope(isolate); |
17551 v8::Handle<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); | 19012 v8::Local<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); |
17552 v8::Handle<v8::Value> object = | 19013 v8::Local<v8::Value> object = v8::Local<v8::Object>::New(isolate, *object_); |
17553 v8::Local<v8::Object>::New(isolate, *object_); | |
17554 CHECK(handle->IsObject()); | 19014 CHECK(handle->IsObject()); |
17555 CHECK(Handle<Object>::Cast(handle)->Equals(object)); | 19015 CHECK(Local<Object>::Cast(handle)->Equals(object)); |
17556 ++counter_; | 19016 ++counter_; |
17557 } | 19017 } |
17558 | 19018 |
17559 int counter_; | 19019 int counter_; |
17560 v8::Persistent<v8::Object>* object_; | 19020 v8::Persistent<v8::Object>* object_; |
17561 }; | 19021 }; |
17562 | 19022 |
17563 | 19023 |
17564 TEST(PersistentHandleVisitor) { | 19024 TEST(PersistentHandleVisitor) { |
17565 LocalContext context; | 19025 LocalContext context; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17615 object2.Reset(); | 19075 object2.Reset(); |
17616 } | 19076 } |
17617 | 19077 |
17618 | 19078 |
17619 TEST(RegExp) { | 19079 TEST(RegExp) { |
17620 i::FLAG_harmony_regexps = true; | 19080 i::FLAG_harmony_regexps = true; |
17621 i::FLAG_harmony_unicode_regexps = true; | 19081 i::FLAG_harmony_unicode_regexps = true; |
17622 LocalContext context; | 19082 LocalContext context; |
17623 v8::HandleScope scope(context->GetIsolate()); | 19083 v8::HandleScope scope(context->GetIsolate()); |
17624 | 19084 |
17625 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); | 19085 v8::Local<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); |
17626 CHECK(re->IsRegExp()); | 19086 CHECK(re->IsRegExp()); |
17627 CHECK(re->GetSource()->Equals(v8_str("foo"))); | 19087 CHECK(re->GetSource()->Equals(v8_str("foo"))); |
17628 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); | 19088 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); |
17629 | 19089 |
17630 re = v8::RegExp::New(v8_str("bar"), | 19090 re = v8::RegExp::New(v8_str("bar"), |
17631 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 19091 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
17632 v8::RegExp::kGlobal)); | 19092 v8::RegExp::kGlobal)); |
17633 CHECK(re->IsRegExp()); | 19093 CHECK(re->IsRegExp()); |
17634 CHECK(re->GetSource()->Equals(v8_str("bar"))); | 19094 CHECK(re->GetSource()->Equals(v8_str("bar"))); |
17635 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal, | 19095 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17672 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); | 19132 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); |
17673 | 19133 |
17674 re = v8::RegExp::New(v8_str("foobarbaz"), | 19134 re = v8::RegExp::New(v8_str("foobarbaz"), |
17675 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 19135 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
17676 v8::RegExp::kMultiline)); | 19136 v8::RegExp::kMultiline)); |
17677 CHECK(re->IsRegExp()); | 19137 CHECK(re->IsRegExp()); |
17678 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); | 19138 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); |
17679 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, | 19139 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, |
17680 static_cast<int>(re->GetFlags())); | 19140 static_cast<int>(re->GetFlags())); |
17681 | 19141 |
17682 context->Global()->Set(v8_str("re"), re); | 19142 CHECK(context->Global()->Set(context.local(), v8_str("re"), re).FromJust()); |
17683 ExpectTrue("re.test('FoobarbaZ')"); | 19143 ExpectTrue("re.test('FoobarbaZ')"); |
17684 | 19144 |
17685 // RegExps are objects on which you can set properties. | 19145 // RegExps are objects on which you can set properties. |
17686 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); | 19146 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); |
17687 v8::Handle<v8::Value> value(CompileRun("re.property")); | 19147 v8::Local<v8::Value> value(CompileRun("re.property")); |
17688 CHECK_EQ(32, value->Int32Value()); | 19148 CHECK_EQ(32, value->Int32Value(context.local()).FromJust()); |
17689 | 19149 |
17690 v8::TryCatch try_catch(context->GetIsolate()); | 19150 v8::TryCatch try_catch(context->GetIsolate()); |
17691 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 19151 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
17692 CHECK(re.IsEmpty()); | 19152 CHECK(re.IsEmpty()); |
17693 CHECK(try_catch.HasCaught()); | 19153 CHECK(try_catch.HasCaught()); |
17694 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 19154 CHECK(context->Global() |
19155 ->Set(context.local(), v8_str("ex"), try_catch.Exception()) | |
19156 .FromJust()); | |
17695 ExpectTrue("ex instanceof SyntaxError"); | 19157 ExpectTrue("ex instanceof SyntaxError"); |
17696 } | 19158 } |
17697 | 19159 |
17698 | 19160 |
17699 THREADED_TEST(Equals) { | 19161 THREADED_TEST(Equals) { |
17700 LocalContext localContext; | 19162 LocalContext localContext; |
17701 v8::HandleScope handleScope(localContext->GetIsolate()); | 19163 v8::HandleScope handleScope(localContext->GetIsolate()); |
17702 | 19164 |
17703 v8::Handle<v8::Object> globalProxy = localContext->Global(); | 19165 v8::Local<v8::Object> globalProxy = localContext->Global(); |
17704 v8::Handle<Value> global = globalProxy->GetPrototype(); | 19166 v8::Local<Value> global = globalProxy->GetPrototype(); |
17705 | 19167 |
17706 CHECK(global->StrictEquals(global)); | 19168 CHECK(global->StrictEquals(global)); |
17707 CHECK(!global->StrictEquals(globalProxy)); | 19169 CHECK(!global->StrictEquals(globalProxy)); |
17708 CHECK(!globalProxy->StrictEquals(global)); | 19170 CHECK(!globalProxy->StrictEquals(global)); |
17709 CHECK(globalProxy->StrictEquals(globalProxy)); | 19171 CHECK(globalProxy->StrictEquals(globalProxy)); |
17710 | 19172 |
17711 CHECK(global->Equals(global)); | 19173 CHECK(global->Equals(global)); |
17712 CHECK(!global->Equals(globalProxy)); | 19174 CHECK(!global->Equals(globalProxy)); |
17713 CHECK(!globalProxy->Equals(global)); | 19175 CHECK(!globalProxy->Equals(global)); |
17714 CHECK(globalProxy->Equals(globalProxy)); | 19176 CHECK(globalProxy->Equals(globalProxy)); |
17715 } | 19177 } |
17716 | 19178 |
17717 | 19179 |
17718 static void Getter(v8::Local<v8::Name> property, | 19180 static void Getter(v8::Local<v8::Name> property, |
17719 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19181 const v8::PropertyCallbackInfo<v8::Value>& info) { |
17720 info.GetReturnValue().Set(v8_str("42!")); | 19182 info.GetReturnValue().Set(v8_str("42!")); |
17721 } | 19183 } |
17722 | 19184 |
17723 | 19185 |
17724 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { | 19186 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { |
17725 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); | 19187 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate()); |
17726 result->Set(0, v8_str("universalAnswer")); | 19188 result->Set(0, v8_str("universalAnswer")); |
17727 info.GetReturnValue().Set(result); | 19189 info.GetReturnValue().Set(result); |
17728 } | 19190 } |
17729 | 19191 |
17730 | 19192 |
17731 TEST(NamedEnumeratorAndForIn) { | 19193 TEST(NamedEnumeratorAndForIn) { |
17732 LocalContext context; | 19194 LocalContext context; |
17733 v8::Isolate* isolate = context->GetIsolate(); | 19195 v8::Isolate* isolate = context->GetIsolate(); |
17734 v8::HandleScope handle_scope(isolate); | 19196 v8::HandleScope handle_scope(isolate); |
17735 v8::Context::Scope context_scope(context.local()); | 19197 v8::Context::Scope context_scope(context.local()); |
17736 | 19198 |
17737 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); | 19199 v8::Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); |
17738 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, | 19200 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, |
17739 NULL, Enumerator)); | 19201 NULL, Enumerator)); |
17740 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 19202 CHECK(context->Global() |
17741 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 19203 ->Set(context.local(), v8_str("o"), |
17742 "var result = []; for (var k in o) result.push(k); result")); | 19204 tmpl->NewInstance(context.local()).ToLocalChecked()) |
19205 .FromJust()); | |
19206 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast( | |
19207 CompileRun("var result = []; for (var k in o) result.push(k); result")); | |
17743 CHECK_EQ(1u, result->Length()); | 19208 CHECK_EQ(1u, result->Length()); |
17744 CHECK(v8_str("universalAnswer")->Equals(result->Get(0))); | 19209 CHECK(v8_str("universalAnswer")->Equals(result->Get(0))); |
17745 } | 19210 } |
17746 | 19211 |
17747 | 19212 |
17748 TEST(DefinePropertyPostDetach) { | 19213 TEST(DefinePropertyPostDetach) { |
17749 LocalContext context; | 19214 LocalContext context; |
17750 v8::HandleScope scope(context->GetIsolate()); | 19215 v8::HandleScope scope(context->GetIsolate()); |
17751 v8::Handle<v8::Object> proxy = context->Global(); | 19216 v8::Local<v8::Object> proxy = context->Global(); |
17752 v8::Handle<v8::Function> define_property = | 19217 v8::Local<v8::Function> define_property = |
17753 CompileRun("(function() {" | 19218 CompileRun( |
17754 " Object.defineProperty(" | 19219 "(function() {" |
17755 " this," | 19220 " Object.defineProperty(" |
17756 " 1," | 19221 " this," |
17757 " { configurable: true, enumerable: true, value: 3 });" | 19222 " 1," |
17758 "})").As<Function>(); | 19223 " { configurable: true, enumerable: true, value: 3 });" |
19224 "})") | |
19225 .As<Function>(); | |
17759 context->DetachGlobal(); | 19226 context->DetachGlobal(); |
17760 define_property->Call(proxy, 0, NULL); | 19227 define_property->Call(proxy, 0, NULL); |
17761 } | 19228 } |
17762 | 19229 |
17763 | 19230 |
17764 static void InstallContextId(v8::Handle<Context> context, int id) { | 19231 static void InstallContextId(v8::Local<Context> context, int id) { |
17765 Context::Scope scope(context); | 19232 Context::Scope scope(context); |
17766 CompileRun("Object.prototype").As<Object>()-> | 19233 CHECK(CompileRun("Object.prototype") |
17767 Set(v8_str("context_id"), v8::Integer::New(context->GetIsolate(), id)); | 19234 .As<Object>() |
19235 ->Set(context, v8_str("context_id"), | |
19236 v8::Integer::New(context->GetIsolate(), id)) | |
19237 .FromJust()); | |
17768 } | 19238 } |
17769 | 19239 |
17770 | 19240 |
17771 static void CheckContextId(v8::Handle<Object> object, int expected) { | 19241 static void CheckContextId(v8::Local<Object> object, int expected) { |
17772 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); | 19242 CHECK_EQ(expected, object->Get(v8_str("context_id")) |
19243 ->Int32Value(CcTest::isolate()->GetCurrentContext()) | |
19244 .FromJust()); | |
17773 } | 19245 } |
17774 | 19246 |
17775 | 19247 |
17776 THREADED_TEST(CreationContext) { | 19248 THREADED_TEST(CreationContext) { |
17777 v8::Isolate* isolate = CcTest::isolate(); | 19249 v8::Isolate* isolate = CcTest::isolate(); |
17778 HandleScope handle_scope(isolate); | 19250 HandleScope handle_scope(isolate); |
17779 Handle<Context> context1 = Context::New(isolate); | 19251 Local<Context> context1 = Context::New(isolate); |
17780 InstallContextId(context1, 1); | 19252 InstallContextId(context1, 1); |
17781 Handle<Context> context2 = Context::New(isolate); | 19253 Local<Context> context2 = Context::New(isolate); |
17782 InstallContextId(context2, 2); | 19254 InstallContextId(context2, 2); |
17783 Handle<Context> context3 = Context::New(isolate); | 19255 Local<Context> context3 = Context::New(isolate); |
17784 InstallContextId(context3, 3); | 19256 InstallContextId(context3, 3); |
17785 | 19257 |
17786 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); | 19258 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); |
17787 | 19259 |
17788 Local<Object> object1; | 19260 Local<Object> object1; |
17789 Local<Function> func1; | 19261 Local<Function> func1; |
17790 { | 19262 { |
17791 Context::Scope scope(context1); | 19263 Context::Scope scope(context1); |
17792 object1 = Object::New(isolate); | 19264 object1 = Object::New(isolate); |
17793 func1 = tmpl->GetFunction(); | 19265 func1 = tmpl->GetFunction(context1).ToLocalChecked(); |
17794 } | 19266 } |
17795 | 19267 |
17796 Local<Object> object2; | 19268 Local<Object> object2; |
17797 Local<Function> func2; | 19269 Local<Function> func2; |
17798 { | 19270 { |
17799 Context::Scope scope(context2); | 19271 Context::Scope scope(context2); |
17800 object2 = Object::New(isolate); | 19272 object2 = Object::New(isolate); |
17801 func2 = tmpl->GetFunction(); | 19273 func2 = tmpl->GetFunction(context2).ToLocalChecked(); |
17802 } | 19274 } |
17803 | 19275 |
17804 Local<Object> instance1; | 19276 Local<Object> instance1; |
17805 Local<Object> instance2; | 19277 Local<Object> instance2; |
17806 | 19278 |
17807 { | 19279 { |
17808 Context::Scope scope(context3); | 19280 Context::Scope scope(context3); |
17809 instance1 = func1->NewInstance(); | 19281 instance1 = func1->NewInstance(context3).ToLocalChecked(); |
17810 instance2 = func2->NewInstance(); | 19282 instance2 = func2->NewInstance(context3).ToLocalChecked(); |
17811 } | 19283 } |
17812 | 19284 |
17813 { | 19285 { |
17814 Handle<Context> other_context = Context::New(isolate); | 19286 Local<Context> other_context = Context::New(isolate); |
17815 Context::Scope scope(other_context); | 19287 Context::Scope scope(other_context); |
17816 CHECK(object1->CreationContext() == context1); | 19288 CHECK(object1->CreationContext() == context1); |
17817 CheckContextId(object1, 1); | 19289 CheckContextId(object1, 1); |
17818 CHECK(func1->CreationContext() == context1); | 19290 CHECK(func1->CreationContext() == context1); |
17819 CheckContextId(func1, 1); | 19291 CheckContextId(func1, 1); |
17820 CHECK(instance1->CreationContext() == context1); | 19292 CHECK(instance1->CreationContext() == context1); |
17821 CheckContextId(instance1, 1); | 19293 CheckContextId(instance1, 1); |
17822 CHECK(object2->CreationContext() == context2); | 19294 CHECK(object2->CreationContext() == context2); |
17823 CheckContextId(object2, 2); | 19295 CheckContextId(object2, 2); |
17824 CHECK(func2->CreationContext() == context2); | 19296 CHECK(func2->CreationContext() == context2); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
17856 CHECK(func2->CreationContext() == context2); | 19328 CHECK(func2->CreationContext() == context2); |
17857 CheckContextId(func2, 2); | 19329 CheckContextId(func2, 2); |
17858 CHECK(instance2->CreationContext() == context2); | 19330 CHECK(instance2->CreationContext() == context2); |
17859 CheckContextId(instance2, 2); | 19331 CheckContextId(instance2, 2); |
17860 } | 19332 } |
17861 } | 19333 } |
17862 | 19334 |
17863 | 19335 |
17864 THREADED_TEST(CreationContextOfJsFunction) { | 19336 THREADED_TEST(CreationContextOfJsFunction) { |
17865 HandleScope handle_scope(CcTest::isolate()); | 19337 HandleScope handle_scope(CcTest::isolate()); |
17866 Handle<Context> context = Context::New(CcTest::isolate()); | 19338 Local<Context> context = Context::New(CcTest::isolate()); |
17867 InstallContextId(context, 1); | 19339 InstallContextId(context, 1); |
17868 | 19340 |
17869 Local<Object> function; | 19341 Local<Object> function; |
17870 { | 19342 { |
17871 Context::Scope scope(context); | 19343 Context::Scope scope(context); |
17872 function = CompileRun("function foo() {}; foo").As<Object>(); | 19344 function = CompileRun("function foo() {}; foo").As<Object>(); |
17873 } | 19345 } |
17874 | 19346 |
17875 Handle<Context> other_context = Context::New(CcTest::isolate()); | 19347 Local<Context> other_context = Context::New(CcTest::isolate()); |
17876 Context::Scope scope(other_context); | 19348 Context::Scope scope(other_context); |
17877 CHECK(function->CreationContext() == context); | 19349 CHECK(function->CreationContext() == context); |
17878 CheckContextId(function, 1); | 19350 CheckContextId(function, 1); |
17879 } | 19351 } |
17880 | 19352 |
17881 | 19353 |
17882 void HasOwnPropertyIndexedPropertyGetter( | 19354 void HasOwnPropertyIndexedPropertyGetter( |
17883 uint32_t index, | 19355 uint32_t index, |
17884 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19356 const v8::PropertyCallbackInfo<v8::Value>& info) { |
17885 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); | 19357 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); |
(...skipping 29 matching lines...) Expand all Loading... | |
17915 const v8::PropertyCallbackInfo<v8::Value>& info) { | 19387 const v8::PropertyCallbackInfo<v8::Value>& info) { |
17916 info.GetReturnValue().Set(v8_str("yes")); | 19388 info.GetReturnValue().Set(v8_str("yes")); |
17917 } | 19389 } |
17918 | 19390 |
17919 | 19391 |
17920 TEST(HasOwnProperty) { | 19392 TEST(HasOwnProperty) { |
17921 LocalContext env; | 19393 LocalContext env; |
17922 v8::Isolate* isolate = env->GetIsolate(); | 19394 v8::Isolate* isolate = env->GetIsolate(); |
17923 v8::HandleScope scope(isolate); | 19395 v8::HandleScope scope(isolate); |
17924 { // Check normal properties and defined getters. | 19396 { // Check normal properties and defined getters. |
17925 Handle<Value> value = CompileRun( | 19397 Local<Value> value = CompileRun( |
17926 "function Foo() {" | 19398 "function Foo() {" |
17927 " this.foo = 11;" | 19399 " this.foo = 11;" |
17928 " this.__defineGetter__('baz', function() { return 1; });" | 19400 " this.__defineGetter__('baz', function() { return 1; });" |
17929 "};" | 19401 "};" |
17930 "function Bar() { " | 19402 "function Bar() { " |
17931 " this.bar = 13;" | 19403 " this.bar = 13;" |
17932 " this.__defineGetter__('bla', function() { return 2; });" | 19404 " this.__defineGetter__('bla', function() { return 2; });" |
17933 "};" | 19405 "};" |
17934 "Bar.prototype = new Foo();" | 19406 "Bar.prototype = new Foo();" |
17935 "new Bar();"); | 19407 "new Bar();"); |
17936 CHECK(value->IsObject()); | 19408 CHECK(value->IsObject()); |
17937 Handle<Object> object = value->ToObject(isolate); | 19409 Local<Object> object = value->ToObject(isolate); |
17938 CHECK(object->Has(v8_str("foo"))); | 19410 CHECK(object->Has(v8_str("foo"))); |
17939 CHECK(!object->HasOwnProperty(v8_str("foo"))); | 19411 CHECK(!object->HasOwnProperty(v8_str("foo"))); |
17940 CHECK(object->HasOwnProperty(v8_str("bar"))); | 19412 CHECK(object->HasOwnProperty(v8_str("bar"))); |
17941 CHECK(object->Has(v8_str("baz"))); | 19413 CHECK(object->Has(v8_str("baz"))); |
17942 CHECK(!object->HasOwnProperty(v8_str("baz"))); | 19414 CHECK(!object->HasOwnProperty(v8_str("baz"))); |
17943 CHECK(object->HasOwnProperty(v8_str("bla"))); | 19415 CHECK(object->HasOwnProperty(v8_str("bla"))); |
17944 } | 19416 } |
17945 { // Check named getter interceptors. | 19417 { // Check named getter interceptors. |
17946 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19418 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17947 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19419 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
17948 HasOwnPropertyNamedPropertyGetter)); | 19420 HasOwnPropertyNamedPropertyGetter)); |
17949 Handle<Object> instance = templ->NewInstance(); | 19421 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17950 CHECK(!instance->HasOwnProperty(v8_str("42"))); | 19422 CHECK(!instance->HasOwnProperty(v8_str("42"))); |
17951 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19423 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
17952 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19424 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
17953 } | 19425 } |
17954 { // Check indexed getter interceptors. | 19426 { // Check indexed getter interceptors. |
17955 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19427 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17956 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19428 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
17957 HasOwnPropertyIndexedPropertyGetter)); | 19429 HasOwnPropertyIndexedPropertyGetter)); |
17958 Handle<Object> instance = templ->NewInstance(); | 19430 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17959 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19431 CHECK(instance->HasOwnProperty(v8_str("42"))); |
17960 CHECK(!instance->HasOwnProperty(v8_str("43"))); | 19432 CHECK(!instance->HasOwnProperty(v8_str("43"))); |
17961 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19433 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
17962 } | 19434 } |
17963 { // Check named query interceptors. | 19435 { // Check named query interceptors. |
17964 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19436 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17965 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19437 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
17966 0, 0, HasOwnPropertyNamedPropertyQuery)); | 19438 0, 0, HasOwnPropertyNamedPropertyQuery)); |
17967 Handle<Object> instance = templ->NewInstance(); | 19439 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17968 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19440 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
17969 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19441 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
17970 } | 19442 } |
17971 { // Check indexed query interceptors. | 19443 { // Check indexed query interceptors. |
17972 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19444 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17973 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19445 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
17974 0, 0, HasOwnPropertyIndexedPropertyQuery)); | 19446 0, 0, HasOwnPropertyIndexedPropertyQuery)); |
17975 Handle<Object> instance = templ->NewInstance(); | 19447 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17976 CHECK(instance->HasOwnProperty(v8_str("42"))); | 19448 CHECK(instance->HasOwnProperty(v8_str("42"))); |
17977 CHECK(!instance->HasOwnProperty(v8_str("41"))); | 19449 CHECK(!instance->HasOwnProperty(v8_str("41"))); |
17978 } | 19450 } |
17979 { // Check callbacks. | 19451 { // Check callbacks. |
17980 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19452 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17981 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); | 19453 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); |
17982 Handle<Object> instance = templ->NewInstance(); | 19454 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17983 CHECK(instance->HasOwnProperty(v8_str("foo"))); | 19455 CHECK(instance->HasOwnProperty(v8_str("foo"))); |
17984 CHECK(!instance->HasOwnProperty(v8_str("bar"))); | 19456 CHECK(!instance->HasOwnProperty(v8_str("bar"))); |
17985 } | 19457 } |
17986 { // Check that query wins on disagreement. | 19458 { // Check that query wins on disagreement. |
17987 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19459 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
17988 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( | 19460 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( |
17989 HasOwnPropertyNamedPropertyGetter, 0, | 19461 HasOwnPropertyNamedPropertyGetter, 0, |
17990 HasOwnPropertyNamedPropertyQuery2)); | 19462 HasOwnPropertyNamedPropertyQuery2)); |
17991 Handle<Object> instance = templ->NewInstance(); | 19463 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked(); |
17992 CHECK(!instance->HasOwnProperty(v8_str("foo"))); | 19464 CHECK(!instance->HasOwnProperty(v8_str("foo"))); |
17993 CHECK(instance->HasOwnProperty(v8_str("bar"))); | 19465 CHECK(instance->HasOwnProperty(v8_str("bar"))); |
17994 } | 19466 } |
17995 } | 19467 } |
17996 | 19468 |
17997 | 19469 |
17998 TEST(IndexedInterceptorWithStringProto) { | 19470 TEST(IndexedInterceptorWithStringProto) { |
17999 v8::Isolate* isolate = CcTest::isolate(); | 19471 v8::Isolate* isolate = CcTest::isolate(); |
18000 v8::HandleScope scope(isolate); | 19472 v8::HandleScope scope(isolate); |
18001 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19473 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18002 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( | 19474 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( |
18003 NULL, NULL, HasOwnPropertyIndexedPropertyQuery)); | 19475 NULL, NULL, HasOwnPropertyIndexedPropertyQuery)); |
18004 LocalContext context; | 19476 LocalContext context; |
18005 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 19477 CHECK(context->Global() |
19478 ->Set(context.local(), v8_str("obj"), | |
19479 templ->NewInstance(context.local()).ToLocalChecked()) | |
19480 .FromJust()); | |
18006 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); | 19481 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); |
18007 // These should be intercepted. | 19482 // These should be intercepted. |
18008 CHECK(CompileRun("42 in obj")->BooleanValue()); | 19483 CHECK(CompileRun("42 in obj")->BooleanValue()); |
18009 CHECK(CompileRun("'42' in obj")->BooleanValue()); | 19484 CHECK(CompileRun("'42' in obj")->BooleanValue()); |
18010 // These should fall through to the String prototype. | 19485 // These should fall through to the String prototype. |
18011 CHECK(CompileRun("0 in obj")->BooleanValue()); | 19486 CHECK(CompileRun("0 in obj")->BooleanValue()); |
18012 CHECK(CompileRun("'0' in obj")->BooleanValue()); | 19487 CHECK(CompileRun("'0' in obj")->BooleanValue()); |
18013 // And these should both fail. | 19488 // And these should both fail. |
18014 CHECK(!CompileRun("32 in obj")->BooleanValue()); | 19489 CHECK(!CompileRun("32 in obj")->BooleanValue()); |
18015 CHECK(!CompileRun("'32' in obj")->BooleanValue()); | 19490 CHECK(!CompileRun("'32' in obj")->BooleanValue()); |
18016 } | 19491 } |
18017 | 19492 |
18018 | 19493 |
18019 void CheckCodeGenerationAllowed() { | 19494 void CheckCodeGenerationAllowed() { |
18020 Handle<Value> result = CompileRun("eval('42')"); | 19495 Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
18021 CHECK_EQ(42, result->Int32Value()); | 19496 Local<Value> result = CompileRun("eval('42')"); |
19497 CHECK_EQ(42, result->Int32Value(context).FromJust()); | |
18022 result = CompileRun("(function(e) { return e('42'); })(eval)"); | 19498 result = CompileRun("(function(e) { return e('42'); })(eval)"); |
18023 CHECK_EQ(42, result->Int32Value()); | 19499 CHECK_EQ(42, result->Int32Value(context).FromJust()); |
18024 result = CompileRun("var f = new Function('return 42'); f()"); | 19500 result = CompileRun("var f = new Function('return 42'); f()"); |
18025 CHECK_EQ(42, result->Int32Value()); | 19501 CHECK_EQ(42, result->Int32Value(context).FromJust()); |
18026 } | 19502 } |
18027 | 19503 |
18028 | 19504 |
18029 void CheckCodeGenerationDisallowed() { | 19505 void CheckCodeGenerationDisallowed() { |
18030 TryCatch try_catch(CcTest::isolate()); | 19506 TryCatch try_catch(CcTest::isolate()); |
18031 | 19507 |
18032 Handle<Value> result = CompileRun("eval('42')"); | 19508 Local<Value> result = CompileRun("eval('42')"); |
18033 CHECK(result.IsEmpty()); | 19509 CHECK(result.IsEmpty()); |
18034 CHECK(try_catch.HasCaught()); | 19510 CHECK(try_catch.HasCaught()); |
18035 try_catch.Reset(); | 19511 try_catch.Reset(); |
18036 | 19512 |
18037 result = CompileRun("(function(e) { return e('42'); })(eval)"); | 19513 result = CompileRun("(function(e) { return e('42'); })(eval)"); |
18038 CHECK(result.IsEmpty()); | 19514 CHECK(result.IsEmpty()); |
18039 CHECK(try_catch.HasCaught()); | 19515 CHECK(try_catch.HasCaught()); |
18040 try_catch.Reset(); | 19516 try_catch.Reset(); |
18041 | 19517 |
18042 result = CompileRun("var f = new Function('return 42'); f()"); | 19518 result = CompileRun("var f = new Function('return 42'); f()"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18085 CHECK(!context->IsCodeGenerationFromStringsAllowed()); | 19561 CHECK(!context->IsCodeGenerationFromStringsAllowed()); |
18086 CheckCodeGenerationDisallowed(); | 19562 CheckCodeGenerationDisallowed(); |
18087 } | 19563 } |
18088 | 19564 |
18089 | 19565 |
18090 TEST(SetErrorMessageForCodeGenFromStrings) { | 19566 TEST(SetErrorMessageForCodeGenFromStrings) { |
18091 LocalContext context; | 19567 LocalContext context; |
18092 v8::HandleScope scope(context->GetIsolate()); | 19568 v8::HandleScope scope(context->GetIsolate()); |
18093 TryCatch try_catch(context->GetIsolate()); | 19569 TryCatch try_catch(context->GetIsolate()); |
18094 | 19570 |
18095 Handle<String> message = v8_str("Message"); | 19571 Local<String> message = v8_str("Message"); |
18096 Handle<String> expected_message = v8_str("Uncaught EvalError: Message"); | 19572 Local<String> expected_message = v8_str("Uncaught EvalError: Message"); |
18097 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); | 19573 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); |
18098 context->AllowCodeGenerationFromStrings(false); | 19574 context->AllowCodeGenerationFromStrings(false); |
18099 context->SetErrorMessageForCodeGenerationFromStrings(message); | 19575 context->SetErrorMessageForCodeGenerationFromStrings(message); |
18100 Handle<Value> result = CompileRun("eval('42')"); | 19576 Local<Value> result = CompileRun("eval('42')"); |
18101 CHECK(result.IsEmpty()); | 19577 CHECK(result.IsEmpty()); |
18102 CHECK(try_catch.HasCaught()); | 19578 CHECK(try_catch.HasCaught()); |
18103 Handle<String> actual_message = try_catch.Message()->Get(); | 19579 Local<String> actual_message = try_catch.Message()->Get(); |
18104 CHECK(expected_message->Equals(actual_message)); | 19580 CHECK(expected_message->Equals(actual_message)); |
18105 } | 19581 } |
18106 | 19582 |
18107 | 19583 |
18108 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { | 19584 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { |
18109 } | 19585 } |
18110 | 19586 |
18111 | 19587 |
18112 THREADED_TEST(CallAPIFunctionOnNonObject) { | 19588 THREADED_TEST(CallAPIFunctionOnNonObject) { |
18113 LocalContext context; | 19589 LocalContext context; |
18114 v8::Isolate* isolate = context->GetIsolate(); | 19590 v8::Isolate* isolate = context->GetIsolate(); |
18115 v8::HandleScope scope(isolate); | 19591 v8::HandleScope scope(isolate); |
18116 Handle<FunctionTemplate> templ = | 19592 Local<FunctionTemplate> templ = |
18117 v8::FunctionTemplate::New(isolate, NonObjectThis); | 19593 v8::FunctionTemplate::New(isolate, NonObjectThis); |
18118 Handle<Function> function = templ->GetFunction(); | 19594 Local<Function> function = |
18119 context->Global()->Set(v8_str("f"), function); | 19595 templ->GetFunction(context.local()).ToLocalChecked(); |
19596 CHECK(context->Global() | |
19597 ->Set(context.local(), v8_str("f"), function) | |
19598 .FromJust()); | |
18120 TryCatch try_catch(isolate); | 19599 TryCatch try_catch(isolate); |
18121 CompileRun("f.call(2)"); | 19600 CompileRun("f.call(2)"); |
18122 } | 19601 } |
18123 | 19602 |
18124 | 19603 |
18125 // Regression test for issue 1470. | 19604 // Regression test for issue 1470. |
18126 THREADED_TEST(ReadOnlyIndexedProperties) { | 19605 THREADED_TEST(ReadOnlyIndexedProperties) { |
18127 v8::Isolate* isolate = CcTest::isolate(); | 19606 v8::Isolate* isolate = CcTest::isolate(); |
18128 v8::HandleScope scope(isolate); | 19607 v8::HandleScope scope(isolate); |
18129 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 19608 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
18130 | 19609 |
18131 LocalContext context; | 19610 LocalContext context; |
18132 Local<v8::Object> obj = templ->NewInstance(); | 19611 Local<v8::Object> obj = templ->NewInstance(context.local()).ToLocalChecked(); |
18133 context->Global()->Set(v8_str("obj"), obj); | 19612 CHECK(context->Global()->Set(context.local(), v8_str("obj"), obj).FromJust()); |
18134 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19613 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); |
18135 obj->Set(v8_str("1"), v8_str("foobar")); | 19614 obj->Set(v8_str("1"), v8_str("foobar")); |
18136 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("1")))); | 19615 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("1")))); |
18137 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19616 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); |
18138 obj->Set(v8_num(2), v8_str("foobar")); | 19617 obj->Set(v8_num(2), v8_str("foobar")); |
18139 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_num(2)))); | 19618 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_num(2)))); |
18140 | 19619 |
18141 // Test non-smi case. | 19620 // Test non-smi case. |
18142 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); | 19621 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); |
18143 obj->Set(v8_str("2000000000"), v8_str("foobar")); | 19622 obj->Set(v8_str("2000000000"), v8_str("foobar")); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18202 protected_hidden_proto_template->SetHiddenPrototype(true); | 19681 protected_hidden_proto_template->SetHiddenPrototype(true); |
18203 | 19682 |
18204 // Context for "foreign" objects used in test. | 19683 // Context for "foreign" objects used in test. |
18205 Local<Context> context = v8::Context::New(isolate); | 19684 Local<Context> context = v8::Context::New(isolate); |
18206 context->Enter(); | 19685 context->Enter(); |
18207 | 19686 |
18208 // Plain object, no security check. | 19687 // Plain object, no security check. |
18209 Local<Object> simple_object = Object::New(isolate); | 19688 Local<Object> simple_object = Object::New(isolate); |
18210 | 19689 |
18211 // Object with explicit security check. | 19690 // Object with explicit security check. |
18212 Local<Object> protected_object = no_proto_template->NewInstance(); | 19691 Local<Object> protected_object = |
19692 no_proto_template->NewInstance(context).ToLocalChecked(); | |
18213 | 19693 |
18214 // JSGlobalProxy object, always have security check. | 19694 // JSGlobalProxy object, always have security check. |
18215 Local<Object> proxy_object = context->Global(); | 19695 Local<Object> proxy_object = context->Global(); |
18216 | 19696 |
18217 // Global object, the prototype of proxy_object. No security checks. | 19697 // Global object, the prototype of proxy_object. No security checks. |
18218 Local<Object> global_object = proxy_object->GetPrototype()->ToObject(isolate); | 19698 Local<Object> global_object = proxy_object->GetPrototype()->ToObject(isolate); |
18219 | 19699 |
18220 // Hidden prototype without security check. | 19700 // Hidden prototype without security check. |
18221 Local<Object> hidden_prototype = | 19701 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context) |
18222 hidden_proto_template->GetFunction()->NewInstance(); | 19702 .ToLocalChecked() |
19703 ->NewInstance(context) | |
19704 .ToLocalChecked(); | |
18223 Local<Object> object_with_hidden = | 19705 Local<Object> object_with_hidden = |
18224 Object::New(isolate); | 19706 Object::New(isolate); |
18225 object_with_hidden->SetPrototype(hidden_prototype); | 19707 object_with_hidden->SetPrototype(hidden_prototype); |
18226 | 19708 |
18227 context->Exit(); | 19709 context->Exit(); |
18228 | 19710 |
18229 // Template for object for second context. Values to test are put on it as | 19711 // Template for object for second context. Values to test are put on it as |
18230 // properties. | 19712 // properties. |
18231 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); | 19713 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); |
18232 global_template->Set(v8_str("simple"), simple_object); | 19714 global_template->Set(v8_str("simple"), simple_object); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18303 | 19785 |
18304 CompileRun("function ownfunc() { return { 0: this.id, " | 19786 CompileRun("function ownfunc() { return { 0: this.id, " |
18305 " 1: this, " | 19787 " 1: this, " |
18306 " toString: function() { " | 19788 " toString: function() { " |
18307 " return this[0];" | 19789 " return this[0];" |
18308 " }" | 19790 " }" |
18309 " };" | 19791 " };" |
18310 "}" | 19792 "}" |
18311 "var id = 'o';" | 19793 "var id = 'o';" |
18312 "ownfunc"); | 19794 "ownfunc"); |
18313 context->Global()->Set(v8_str("func"), foreign_function); | 19795 CHECK(context->Global() |
19796 ->Set(context.local(), v8_str("func"), foreign_function) | |
19797 .FromJust()); | |
18314 | 19798 |
18315 // Sanity check the contexts. | 19799 // Sanity check the contexts. |
18316 CHECK(i->Equals(foreign_context->Global()->Get(id))); | 19800 CHECK(i->Equals(foreign_context->Global()->Get(id))); |
18317 CHECK(o->Equals(context->Global()->Get(id))); | 19801 CHECK(o->Equals(context->Global()->Get(id))); |
18318 | 19802 |
18319 // Checking local function's receiver. | 19803 // Checking local function's receiver. |
18320 // Calling function using its call/apply methods. | 19804 // Calling function using its call/apply methods. |
18321 TestReceiver(o, context->Global(), "ownfunc.call()"); | 19805 TestReceiver(o, context->Global(), "ownfunc.call()"); |
18322 TestReceiver(o, context->Global(), "ownfunc.apply()"); | 19806 TestReceiver(o, context->Global(), "ownfunc.apply()"); |
18323 // Making calls through built-in functions. | 19807 // Making calls through built-in functions. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18366 } | 19850 } |
18367 | 19851 |
18368 | 19852 |
18369 void CallCompletedCallback2() { | 19853 void CallCompletedCallback2() { |
18370 v8::base::OS::Print("Firing callback 2.\n"); | 19854 v8::base::OS::Print("Firing callback 2.\n"); |
18371 callback_fired ^= 2; // Toggle second bit. | 19855 callback_fired ^= 2; // Toggle second bit. |
18372 } | 19856 } |
18373 | 19857 |
18374 | 19858 |
18375 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { | 19859 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { |
18376 int32_t level = args[0]->Int32Value(); | 19860 int32_t level = |
19861 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust(); | |
18377 if (level < 3) { | 19862 if (level < 3) { |
18378 level++; | 19863 level++; |
18379 v8::base::OS::Print("Entering recursion level %d.\n", level); | 19864 v8::base::OS::Print("Entering recursion level %d.\n", level); |
18380 char script[64]; | 19865 char script[64]; |
18381 i::Vector<char> script_vector(script, sizeof(script)); | 19866 i::Vector<char> script_vector(script, sizeof(script)); |
18382 i::SNPrintF(script_vector, "recursion(%d)", level); | 19867 i::SNPrintF(script_vector, "recursion(%d)", level); |
18383 CompileRun(script_vector.start()); | 19868 CompileRun(script_vector.start()); |
18384 v8::base::OS::Print("Leaving recursion level %d.\n", level); | 19869 v8::base::OS::Print("Leaving recursion level %d.\n", level); |
18385 CHECK_EQ(0, callback_fired); | 19870 CHECK_EQ(0, callback_fired); |
18386 } else { | 19871 } else { |
18387 v8::base::OS::Print("Recursion ends.\n"); | 19872 v8::base::OS::Print("Recursion ends.\n"); |
18388 CHECK_EQ(0, callback_fired); | 19873 CHECK_EQ(0, callback_fired); |
18389 } | 19874 } |
18390 } | 19875 } |
18391 | 19876 |
18392 | 19877 |
18393 TEST(CallCompletedCallback) { | 19878 TEST(CallCompletedCallback) { |
18394 LocalContext env; | 19879 LocalContext env; |
18395 v8::HandleScope scope(env->GetIsolate()); | 19880 v8::HandleScope scope(env->GetIsolate()); |
18396 v8::Handle<v8::FunctionTemplate> recursive_runtime = | 19881 v8::Local<v8::FunctionTemplate> recursive_runtime = |
18397 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); | 19882 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); |
18398 env->Global()->Set(v8_str("recursion"), | 19883 env->Global()->Set( |
18399 recursive_runtime->GetFunction()); | 19884 v8_str("recursion"), |
19885 recursive_runtime->GetFunction(env.local()).ToLocalChecked()); | |
18400 // Adding the same callback a second time has no effect. | 19886 // Adding the same callback a second time has no effect. |
18401 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 19887 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
18402 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); | 19888 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); |
18403 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); | 19889 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); |
18404 v8::base::OS::Print("--- Script (1) ---\n"); | 19890 v8::base::OS::Print("--- Script (1) ---\n"); |
18405 Local<Script> script = v8::Script::Compile( | 19891 Local<Script> script = v8::Script::Compile(v8_str("recursion(0)")); |
18406 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); | |
18407 script->Run(); | 19892 script->Run(); |
18408 CHECK_EQ(3, callback_fired); | 19893 CHECK_EQ(3, callback_fired); |
18409 | 19894 |
18410 v8::base::OS::Print("\n--- Script (2) ---\n"); | 19895 v8::base::OS::Print("\n--- Script (2) ---\n"); |
18411 callback_fired = 0; | 19896 callback_fired = 0; |
18412 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); | 19897 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); |
18413 script->Run(); | 19898 script->Run(); |
18414 CHECK_EQ(2, callback_fired); | 19899 CHECK_EQ(2, callback_fired); |
18415 | 19900 |
18416 v8::base::OS::Print("\n--- Function ---\n"); | 19901 v8::base::OS::Print("\n--- Function ---\n"); |
18417 callback_fired = 0; | 19902 callback_fired = 0; |
18418 Local<Function> recursive_function = | 19903 Local<Function> recursive_function = |
18419 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); | 19904 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); |
18420 v8::Handle<Value> args[] = { v8_num(0) }; | 19905 v8::Local<Value> args[] = {v8_num(0)}; |
18421 recursive_function->Call(env->Global(), 1, args); | 19906 recursive_function->Call(env->Global(), 1, args); |
18422 CHECK_EQ(2, callback_fired); | 19907 CHECK_EQ(2, callback_fired); |
18423 } | 19908 } |
18424 | 19909 |
18425 | 19910 |
18426 void CallCompletedCallbackNoException() { | 19911 void CallCompletedCallbackNoException() { |
18427 v8::HandleScope scope(CcTest::isolate()); | 19912 v8::HandleScope scope(CcTest::isolate()); |
18428 CompileRun("1+1;"); | 19913 CompileRun("1+1;"); |
18429 } | 19914 } |
18430 | 19915 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18471 } | 19956 } |
18472 | 19957 |
18473 | 19958 |
18474 TEST(EnqueueMicrotask) { | 19959 TEST(EnqueueMicrotask) { |
18475 LocalContext env; | 19960 LocalContext env; |
18476 v8::HandleScope scope(env->GetIsolate()); | 19961 v8::HandleScope scope(env->GetIsolate()); |
18477 CompileRun( | 19962 CompileRun( |
18478 "var ext1Calls = 0;" | 19963 "var ext1Calls = 0;" |
18479 "var ext2Calls = 0;"); | 19964 "var ext2Calls = 0;"); |
18480 CompileRun("1+1;"); | 19965 CompileRun("1+1;"); |
18481 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); | 19966 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18482 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 19967 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18483 | 19968 |
18484 env->GetIsolate()->EnqueueMicrotask( | 19969 env->GetIsolate()->EnqueueMicrotask( |
18485 Function::New(env->GetIsolate(), MicrotaskOne)); | 19970 Function::New(env->GetIsolate(), MicrotaskOne)); |
18486 CompileRun("1+1;"); | 19971 CompileRun("1+1;"); |
18487 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 19972 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18488 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 19973 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18489 | 19974 |
18490 env->GetIsolate()->EnqueueMicrotask( | 19975 env->GetIsolate()->EnqueueMicrotask( |
18491 Function::New(env->GetIsolate(), MicrotaskOne)); | 19976 Function::New(env->GetIsolate(), MicrotaskOne)); |
18492 env->GetIsolate()->EnqueueMicrotask( | 19977 env->GetIsolate()->EnqueueMicrotask( |
18493 Function::New(env->GetIsolate(), MicrotaskTwo)); | 19978 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18494 CompileRun("1+1;"); | 19979 CompileRun("1+1;"); |
18495 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 19980 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18496 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 19981 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18497 | 19982 |
18498 env->GetIsolate()->EnqueueMicrotask( | 19983 env->GetIsolate()->EnqueueMicrotask( |
18499 Function::New(env->GetIsolate(), MicrotaskTwo)); | 19984 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18500 CompileRun("1+1;"); | 19985 CompileRun("1+1;"); |
18501 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 19986 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18502 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 19987 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18503 | 19988 |
18504 CompileRun("1+1;"); | 19989 CompileRun("1+1;"); |
18505 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 19990 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18506 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 19991 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18507 | 19992 |
18508 g_passed_to_three = NULL; | 19993 g_passed_to_three = NULL; |
18509 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); | 19994 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); |
18510 CompileRun("1+1;"); | 19995 CompileRun("1+1;"); |
18511 CHECK(!g_passed_to_three); | 19996 CHECK(!g_passed_to_three); |
18512 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 19997 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18513 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 19998 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18514 | 19999 |
18515 int dummy; | 20000 int dummy; |
18516 env->GetIsolate()->EnqueueMicrotask( | 20001 env->GetIsolate()->EnqueueMicrotask( |
18517 Function::New(env->GetIsolate(), MicrotaskOne)); | 20002 Function::New(env->GetIsolate(), MicrotaskOne)); |
18518 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); | 20003 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); |
18519 env->GetIsolate()->EnqueueMicrotask( | 20004 env->GetIsolate()->EnqueueMicrotask( |
18520 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20005 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18521 CompileRun("1+1;"); | 20006 CompileRun("1+1;"); |
18522 CHECK_EQ(&dummy, g_passed_to_three); | 20007 CHECK_EQ(&dummy, g_passed_to_three); |
18523 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value()); | 20008 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18524 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); | 20009 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18525 g_passed_to_three = NULL; | 20010 g_passed_to_three = NULL; |
18526 } | 20011 } |
18527 | 20012 |
18528 | 20013 |
18529 static void MicrotaskExceptionOne( | 20014 static void MicrotaskExceptionOne( |
18530 const v8::FunctionCallbackInfo<Value>& info) { | 20015 const v8::FunctionCallbackInfo<Value>& info) { |
18531 v8::HandleScope scope(info.GetIsolate()); | 20016 v8::HandleScope scope(info.GetIsolate()); |
18532 CompileRun("exception1Calls++;"); | 20017 CompileRun("exception1Calls++;"); |
18533 info.GetIsolate()->ThrowException( | 20018 info.GetIsolate()->ThrowException( |
18534 v8::Exception::Error(v8_str("first"))); | 20019 v8::Exception::Error(v8_str("first"))); |
(...skipping 16 matching lines...) Expand all Loading... | |
18551 CompileRun( | 20036 CompileRun( |
18552 "var exception1Calls = 0;" | 20037 "var exception1Calls = 0;" |
18553 "var exception2Calls = 0;"); | 20038 "var exception2Calls = 0;"); |
18554 isolate->EnqueueMicrotask( | 20039 isolate->EnqueueMicrotask( |
18555 Function::New(isolate, MicrotaskExceptionOne)); | 20040 Function::New(isolate, MicrotaskExceptionOne)); |
18556 isolate->EnqueueMicrotask( | 20041 isolate->EnqueueMicrotask( |
18557 Function::New(isolate, MicrotaskExceptionTwo)); | 20042 Function::New(isolate, MicrotaskExceptionTwo)); |
18558 TryCatch try_catch(isolate); | 20043 TryCatch try_catch(isolate); |
18559 CompileRun("1+1;"); | 20044 CompileRun("1+1;"); |
18560 CHECK(!try_catch.HasCaught()); | 20045 CHECK(!try_catch.HasCaught()); |
18561 CHECK_EQ(1, CompileRun("exception1Calls")->Int32Value()); | 20046 CHECK_EQ(1, |
18562 CHECK_EQ(1, CompileRun("exception2Calls")->Int32Value()); | 20047 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust()); |
20048 CHECK_EQ(1, | |
20049 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust()); | |
18563 } | 20050 } |
18564 | 20051 |
18565 | 20052 |
18566 TEST(SetAutorunMicrotasks) { | 20053 TEST(SetAutorunMicrotasks) { |
18567 LocalContext env; | 20054 LocalContext env; |
18568 v8::HandleScope scope(env->GetIsolate()); | 20055 v8::HandleScope scope(env->GetIsolate()); |
18569 CompileRun( | 20056 CompileRun( |
18570 "var ext1Calls = 0;" | 20057 "var ext1Calls = 0;" |
18571 "var ext2Calls = 0;"); | 20058 "var ext2Calls = 0;"); |
18572 CompileRun("1+1;"); | 20059 CompileRun("1+1;"); |
18573 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); | 20060 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18574 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20061 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18575 | 20062 |
18576 env->GetIsolate()->EnqueueMicrotask( | 20063 env->GetIsolate()->EnqueueMicrotask( |
18577 Function::New(env->GetIsolate(), MicrotaskOne)); | 20064 Function::New(env->GetIsolate(), MicrotaskOne)); |
18578 CompileRun("1+1;"); | 20065 CompileRun("1+1;"); |
18579 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20066 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18580 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20067 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18581 | 20068 |
18582 env->GetIsolate()->SetAutorunMicrotasks(false); | 20069 env->GetIsolate()->SetAutorunMicrotasks(false); |
18583 env->GetIsolate()->EnqueueMicrotask( | 20070 env->GetIsolate()->EnqueueMicrotask( |
18584 Function::New(env->GetIsolate(), MicrotaskOne)); | 20071 Function::New(env->GetIsolate(), MicrotaskOne)); |
18585 env->GetIsolate()->EnqueueMicrotask( | 20072 env->GetIsolate()->EnqueueMicrotask( |
18586 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20073 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18587 CompileRun("1+1;"); | 20074 CompileRun("1+1;"); |
18588 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20075 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18589 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); | 20076 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18590 | 20077 |
18591 env->GetIsolate()->RunMicrotasks(); | 20078 env->GetIsolate()->RunMicrotasks(); |
18592 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20079 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18593 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 20080 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18594 | 20081 |
18595 env->GetIsolate()->EnqueueMicrotask( | 20082 env->GetIsolate()->EnqueueMicrotask( |
18596 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20083 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18597 CompileRun("1+1;"); | 20084 CompileRun("1+1;"); |
18598 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20085 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18599 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); | 20086 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18600 | 20087 |
18601 env->GetIsolate()->RunMicrotasks(); | 20088 env->GetIsolate()->RunMicrotasks(); |
18602 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20089 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18603 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); | 20090 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18604 | 20091 |
18605 env->GetIsolate()->SetAutorunMicrotasks(true); | 20092 env->GetIsolate()->SetAutorunMicrotasks(true); |
18606 env->GetIsolate()->EnqueueMicrotask( | 20093 env->GetIsolate()->EnqueueMicrotask( |
18607 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20094 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18608 CompileRun("1+1;"); | 20095 CompileRun("1+1;"); |
18609 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20096 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18610 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); | 20097 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18611 | 20098 |
18612 env->GetIsolate()->EnqueueMicrotask( | 20099 env->GetIsolate()->EnqueueMicrotask( |
18613 Function::New(env->GetIsolate(), MicrotaskTwo)); | 20100 Function::New(env->GetIsolate(), MicrotaskTwo)); |
18614 { | 20101 { |
18615 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); | 20102 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); |
18616 CompileRun("1+1;"); | 20103 CompileRun("1+1;"); |
18617 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20104 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18618 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); | 20105 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18619 } | 20106 } |
18620 | 20107 |
18621 CompileRun("1+1;"); | 20108 CompileRun("1+1;"); |
18622 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); | 20109 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust()); |
18623 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value()); | 20110 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust()); |
18624 } | 20111 } |
18625 | 20112 |
18626 | 20113 |
18627 TEST(RunMicrotasksWithoutEnteringContext) { | 20114 TEST(RunMicrotasksWithoutEnteringContext) { |
18628 v8::Isolate* isolate = CcTest::isolate(); | 20115 v8::Isolate* isolate = CcTest::isolate(); |
18629 HandleScope handle_scope(isolate); | 20116 HandleScope handle_scope(isolate); |
18630 isolate->SetAutorunMicrotasks(false); | 20117 isolate->SetAutorunMicrotasks(false); |
18631 Handle<Context> context = Context::New(isolate); | 20118 Local<Context> context = Context::New(isolate); |
18632 { | 20119 { |
18633 Context::Scope context_scope(context); | 20120 Context::Scope context_scope(context); |
18634 CompileRun("var ext1Calls = 0;"); | 20121 CompileRun("var ext1Calls = 0;"); |
18635 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne)); | 20122 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne)); |
18636 } | 20123 } |
18637 isolate->RunMicrotasks(); | 20124 isolate->RunMicrotasks(); |
18638 { | 20125 { |
18639 Context::Scope context_scope(context); | 20126 Context::Scope context_scope(context); |
18640 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); | 20127 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(context).FromJust()); |
18641 } | 20128 } |
18642 isolate->SetAutorunMicrotasks(true); | 20129 isolate->SetAutorunMicrotasks(true); |
18643 } | 20130 } |
18644 | 20131 |
18645 | 20132 |
18646 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { | 20133 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { |
18647 v8::DebugEvent event = event_details.GetEvent(); | 20134 v8::DebugEvent event = event_details.GetEvent(); |
18648 if (event != v8::Break) return; | 20135 if (event != v8::Break) return; |
18649 Handle<Object> exec_state = event_details.GetExecutionState(); | 20136 Local<Object> exec_state = event_details.GetExecutionState(); |
18650 Handle<Value> break_id = exec_state->Get(v8_str("break_id")); | 20137 Local<Value> break_id = exec_state->Get(v8_str("break_id")); |
18651 CompileRun("function f(id) { new FrameDetails(id, 0); }"); | 20138 CompileRun("function f(id) { new FrameDetails(id, 0); }"); |
18652 Handle<Function> fun = | 20139 Local<Function> fun = |
18653 Handle<Function>::Cast(CcTest::global()->Get(v8_str("f"))); | 20140 Local<Function>::Cast(CcTest::global()->Get(v8_str("f"))); |
18654 fun->Call(CcTest::global(), 1, &break_id); | 20141 fun->Call(CcTest::global(), 1, &break_id); |
18655 } | 20142 } |
18656 | 20143 |
18657 | 20144 |
18658 TEST(Regress385349) { | 20145 TEST(Regress385349) { |
18659 i::FLAG_allow_natives_syntax = true; | 20146 i::FLAG_allow_natives_syntax = true; |
18660 v8::Isolate* isolate = CcTest::isolate(); | 20147 v8::Isolate* isolate = CcTest::isolate(); |
18661 HandleScope handle_scope(isolate); | 20148 HandleScope handle_scope(isolate); |
18662 isolate->SetAutorunMicrotasks(false); | 20149 isolate->SetAutorunMicrotasks(false); |
18663 Handle<Context> context = Context::New(isolate); | 20150 Local<Context> context = Context::New(isolate); |
18664 v8::Debug::SetDebugEventListener(DebugEventInObserver); | 20151 v8::Debug::SetDebugEventListener(DebugEventInObserver); |
18665 { | 20152 { |
18666 Context::Scope context_scope(context); | 20153 Context::Scope context_scope(context); |
18667 CompileRun("var obj = {};" | 20154 CompileRun("var obj = {};" |
18668 "Object.observe(obj, function(changes) { debugger; });" | 20155 "Object.observe(obj, function(changes) { debugger; });" |
18669 "obj.a = 0;"); | 20156 "obj.a = 0;"); |
18670 } | 20157 } |
18671 isolate->RunMicrotasks(); | 20158 isolate->RunMicrotasks(); |
18672 isolate->SetAutorunMicrotasks(true); | 20159 isolate->SetAutorunMicrotasks(true); |
18673 v8::Debug::SetDebugEventListener(NULL); | 20160 v8::Debug::SetDebugEventListener(NULL); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18916 } | 20403 } |
18917 | 20404 |
18918 | 20405 |
18919 THREADED_TEST(InstanceCheckOnInstanceAccessor) { | 20406 THREADED_TEST(InstanceCheckOnInstanceAccessor) { |
18920 v8::internal::FLAG_allow_natives_syntax = true; | 20407 v8::internal::FLAG_allow_natives_syntax = true; |
18921 LocalContext context; | 20408 LocalContext context; |
18922 v8::HandleScope scope(context->GetIsolate()); | 20409 v8::HandleScope scope(context->GetIsolate()); |
18923 | 20410 |
18924 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 20411 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
18925 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | 20412 Local<ObjectTemplate> inst = templ->InstanceTemplate(); |
18926 inst->SetAccessor(v8_str("foo"), | 20413 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, |
18927 InstanceCheckedGetter, InstanceCheckedSetter, | 20414 Local<Value>(), v8::DEFAULT, v8::None, |
18928 Handle<Value>(), | |
18929 v8::DEFAULT, | |
18930 v8::None, | |
18931 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20415 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
18932 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20416 CHECK(context->Global() |
20417 ->Set(context.local(), v8_str("f"), | |
20418 templ->GetFunction(context.local()).ToLocalChecked()) | |
20419 .FromJust()); | |
18933 | 20420 |
18934 printf("Testing positive ...\n"); | 20421 printf("Testing positive ...\n"); |
18935 CompileRun("var obj = new f();"); | 20422 CompileRun("var obj = new f();"); |
18936 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20423 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
18937 CheckInstanceCheckedAccessors(true); | 20424 CheckInstanceCheckedAccessors(true); |
18938 | 20425 |
18939 printf("Testing negative ...\n"); | 20426 printf("Testing negative ...\n"); |
18940 CompileRun("var obj = {};" | 20427 CompileRun("var obj = {};" |
18941 "obj.__proto__ = new f();"); | 20428 "obj.__proto__ = new f();"); |
18942 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20429 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
(...skipping 12 matching lines...) Expand all Loading... | |
18955 | 20442 |
18956 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { | 20443 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { |
18957 v8::internal::FLAG_allow_natives_syntax = true; | 20444 v8::internal::FLAG_allow_natives_syntax = true; |
18958 LocalContext context; | 20445 LocalContext context; |
18959 v8::HandleScope scope(context->GetIsolate()); | 20446 v8::HandleScope scope(context->GetIsolate()); |
18960 | 20447 |
18961 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 20448 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
18962 Local<ObjectTemplate> inst = templ->InstanceTemplate(); | 20449 Local<ObjectTemplate> inst = templ->InstanceTemplate(); |
18963 templ->InstanceTemplate()->SetNamedPropertyHandler(EmptyInterceptorGetter, | 20450 templ->InstanceTemplate()->SetNamedPropertyHandler(EmptyInterceptorGetter, |
18964 EmptyInterceptorSetter); | 20451 EmptyInterceptorSetter); |
18965 inst->SetAccessor(v8_str("foo"), | 20452 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter, |
18966 InstanceCheckedGetter, InstanceCheckedSetter, | 20453 Local<Value>(), v8::DEFAULT, v8::None, |
18967 Handle<Value>(), | |
18968 v8::DEFAULT, | |
18969 v8::None, | |
18970 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20454 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
18971 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20455 CHECK(context->Global() |
20456 ->Set(context.local(), v8_str("f"), | |
20457 templ->GetFunction(context.local()).ToLocalChecked()) | |
20458 .FromJust()); | |
18972 | 20459 |
18973 printf("Testing positive ...\n"); | 20460 printf("Testing positive ...\n"); |
18974 CompileRun("var obj = new f();"); | 20461 CompileRun("var obj = new f();"); |
18975 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20462 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
18976 CheckInstanceCheckedAccessors(true); | 20463 CheckInstanceCheckedAccessors(true); |
18977 | 20464 |
18978 printf("Testing negative ...\n"); | 20465 printf("Testing negative ...\n"); |
18979 CompileRun("var obj = {};" | 20466 CompileRun("var obj = {};" |
18980 "obj.__proto__ = new f();"); | 20467 "obj.__proto__ = new f();"); |
18981 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20468 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
18982 CheckInstanceCheckedAccessors(false); | 20469 CheckInstanceCheckedAccessors(false); |
18983 } | 20470 } |
18984 | 20471 |
18985 | 20472 |
18986 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { | 20473 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { |
18987 v8::internal::FLAG_allow_natives_syntax = true; | 20474 v8::internal::FLAG_allow_natives_syntax = true; |
18988 LocalContext context; | 20475 LocalContext context; |
18989 v8::HandleScope scope(context->GetIsolate()); | 20476 v8::HandleScope scope(context->GetIsolate()); |
18990 | 20477 |
18991 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); | 20478 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); |
18992 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); | 20479 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); |
18993 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, | 20480 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, |
18994 InstanceCheckedSetter, Handle<Value>(), v8::DEFAULT, | 20481 InstanceCheckedSetter, Local<Value>(), v8::DEFAULT, |
18995 v8::None, | 20482 v8::None, |
18996 v8::AccessorSignature::New(context->GetIsolate(), templ)); | 20483 v8::AccessorSignature::New(context->GetIsolate(), templ)); |
18997 context->Global()->Set(v8_str("f"), templ->GetFunction()); | 20484 CHECK(context->Global() |
20485 ->Set(context.local(), v8_str("f"), | |
20486 templ->GetFunction(context.local()).ToLocalChecked()) | |
20487 .FromJust()); | |
18998 | 20488 |
18999 printf("Testing positive ...\n"); | 20489 printf("Testing positive ...\n"); |
19000 CompileRun("var obj = new f();"); | 20490 CompileRun("var obj = new f();"); |
19001 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20491 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
19002 CheckInstanceCheckedAccessors(true); | 20492 CheckInstanceCheckedAccessors(true); |
19003 | 20493 |
19004 printf("Testing negative ...\n"); | 20494 printf("Testing negative ...\n"); |
19005 CompileRun("var obj = {};" | 20495 CompileRun("var obj = {};" |
19006 "obj.__proto__ = new f();"); | 20496 "obj.__proto__ = new f();"); |
19007 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); | 20497 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19067 LocalContext context; | 20557 LocalContext context; |
19068 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); | 20558 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); |
19069 if (interceptor) { | 20559 if (interceptor) { |
19070 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor, | 20560 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor, |
19071 FooSetInterceptor)); | 20561 FooSetInterceptor)); |
19072 } else { | 20562 } else { |
19073 templ->SetAccessor(v8_str("foo"), | 20563 templ->SetAccessor(v8_str("foo"), |
19074 GetterWhichReturns42, | 20564 GetterWhichReturns42, |
19075 SetterWhichSetsYOnThisTo23); | 20565 SetterWhichSetsYOnThisTo23); |
19076 } | 20566 } |
19077 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20567 CHECK(context->Global() |
20568 ->Set(context.local(), v8_str("obj"), | |
20569 templ->NewInstance(context.local()).ToLocalChecked()) | |
20570 .FromJust()); | |
19078 | 20571 |
19079 // Turn monomorphic on slow object with native accessor, then turn | 20572 // Turn monomorphic on slow object with native accessor, then turn |
19080 // polymorphic, finally optimize to create negative lookup and fail. | 20573 // polymorphic, finally optimize to create negative lookup and fail. |
19081 CompileRun(do_store ? | 20574 CompileRun(do_store ? |
19082 "function f(x) { x.foo = void 0; }" : | 20575 "function f(x) { x.foo = void 0; }" : |
19083 "function f(x) { return x.foo; }"); | 20576 "function f(x) { return x.foo; }"); |
19084 CompileRun("obj.y = void 0;"); | 20577 CompileRun("obj.y = void 0;"); |
19085 if (!interceptor) { | 20578 if (!interceptor) { |
19086 CompileRun("%OptimizeObjectForAddingMultipleProperties(obj, 1);"); | 20579 CompileRun("%OptimizeObjectForAddingMultipleProperties(obj, 1);"); |
19087 } | 20580 } |
19088 CompileRun("obj.__proto__ = null;" | 20581 CompileRun("obj.__proto__ = null;" |
19089 "f(obj); f(obj); f(obj);"); | 20582 "f(obj); f(obj); f(obj);"); |
19090 if (polymorphic) { | 20583 if (polymorphic) { |
19091 CompileRun("f({});"); | 20584 CompileRun("f({});"); |
19092 } | 20585 } |
19093 CompileRun("obj.y = void 0;" | 20586 CompileRun("obj.y = void 0;" |
19094 "%OptimizeFunctionOnNextCall(f);"); | 20587 "%OptimizeFunctionOnNextCall(f);"); |
19095 if (remove_accessor) { | 20588 if (remove_accessor) { |
19096 CompileRun("delete obj.foo;"); | 20589 CompileRun("delete obj.foo;"); |
19097 } | 20590 } |
19098 CompileRun("var result = f(obj);"); | 20591 CompileRun("var result = f(obj);"); |
19099 if (do_store) { | 20592 if (do_store) { |
19100 CompileRun("result = obj.y;"); | 20593 CompileRun("result = obj.y;"); |
19101 } | 20594 } |
19102 if (remove_accessor && !interceptor) { | 20595 if (remove_accessor && !interceptor) { |
19103 CHECK(context->Global()->Get(v8_str("result"))->IsUndefined()); | 20596 CHECK(context->Global()->Get(v8_str("result"))->IsUndefined()); |
19104 } else { | 20597 } else { |
19105 CHECK_EQ(do_store ? 23 : 42, | 20598 CHECK_EQ(do_store ? 23 : 42, context->Global() |
19106 context->Global()->Get(v8_str("result"))->Int32Value()); | 20599 ->Get(v8_str("result")) |
20600 ->Int32Value(context.local()) | |
20601 .FromJust()); | |
19107 } | 20602 } |
19108 } | 20603 } |
19109 | 20604 |
19110 | 20605 |
19111 THREADED_TEST(Regress137002a) { | 20606 THREADED_TEST(Regress137002a) { |
19112 i::FLAG_allow_natives_syntax = true; | 20607 i::FLAG_allow_natives_syntax = true; |
19113 i::FLAG_compilation_cache = false; | 20608 i::FLAG_compilation_cache = false; |
19114 v8::HandleScope scope(CcTest::isolate()); | 20609 v8::HandleScope scope(CcTest::isolate()); |
19115 for (int i = 0; i < 16; i++) { | 20610 for (int i = 0; i < 16; i++) { |
19116 Helper137002(i & 8, i & 4, i & 2, i & 1); | 20611 Helper137002(i & 8, i & 4, i & 2, i & 1); |
19117 } | 20612 } |
19118 } | 20613 } |
19119 | 20614 |
19120 | 20615 |
19121 THREADED_TEST(Regress137002b) { | 20616 THREADED_TEST(Regress137002b) { |
19122 i::FLAG_allow_natives_syntax = true; | 20617 i::FLAG_allow_natives_syntax = true; |
19123 LocalContext context; | 20618 LocalContext context; |
19124 v8::Isolate* isolate = context->GetIsolate(); | 20619 v8::Isolate* isolate = context->GetIsolate(); |
19125 v8::HandleScope scope(isolate); | 20620 v8::HandleScope scope(isolate); |
19126 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 20621 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19127 templ->SetAccessor(v8_str("foo"), | 20622 templ->SetAccessor(v8_str("foo"), |
19128 GetterWhichReturns42, | 20623 GetterWhichReturns42, |
19129 SetterWhichSetsYOnThisTo23); | 20624 SetterWhichSetsYOnThisTo23); |
19130 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20625 CHECK(context->Global() |
20626 ->Set(context.local(), v8_str("obj"), | |
20627 templ->NewInstance(context.local()).ToLocalChecked()) | |
20628 .FromJust()); | |
19131 | 20629 |
19132 // Turn monomorphic on slow object with native accessor, then just | 20630 // Turn monomorphic on slow object with native accessor, then just |
19133 // delete the property and fail. | 20631 // delete the property and fail. |
19134 CompileRun("function load(x) { return x.foo; }" | 20632 CompileRun("function load(x) { return x.foo; }" |
19135 "function store(x) { x.foo = void 0; }" | 20633 "function store(x) { x.foo = void 0; }" |
19136 "function keyed_load(x, key) { return x[key]; }" | 20634 "function keyed_load(x, key) { return x[key]; }" |
19137 // Second version of function has a different source (add void 0) | 20635 // Second version of function has a different source (add void 0) |
19138 // so that it does not share code with the first version. This | 20636 // so that it does not share code with the first version. This |
19139 // ensures that the ICs are monomorphic. | 20637 // ensures that the ICs are monomorphic. |
19140 "function load2(x) { void 0; return x.foo; }" | 20638 "function load2(x) { void 0; return x.foo; }" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19189 | 20687 |
19190 THREADED_TEST(Regress142088) { | 20688 THREADED_TEST(Regress142088) { |
19191 i::FLAG_allow_natives_syntax = true; | 20689 i::FLAG_allow_natives_syntax = true; |
19192 LocalContext context; | 20690 LocalContext context; |
19193 v8::Isolate* isolate = context->GetIsolate(); | 20691 v8::Isolate* isolate = context->GetIsolate(); |
19194 v8::HandleScope scope(isolate); | 20692 v8::HandleScope scope(isolate); |
19195 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 20693 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19196 templ->SetAccessor(v8_str("foo"), | 20694 templ->SetAccessor(v8_str("foo"), |
19197 GetterWhichReturns42, | 20695 GetterWhichReturns42, |
19198 SetterWhichSetsYOnThisTo23); | 20696 SetterWhichSetsYOnThisTo23); |
19199 context->Global()->Set(v8_str("obj"), templ->NewInstance()); | 20697 CHECK(context->Global() |
20698 ->Set(context.local(), v8_str("obj"), | |
20699 templ->NewInstance(context.local()).ToLocalChecked()) | |
20700 .FromJust()); | |
19200 | 20701 |
19201 CompileRun("function load(x) { return x.foo; }" | 20702 CompileRun("function load(x) { return x.foo; }" |
19202 "var o = Object.create(obj);" | 20703 "var o = Object.create(obj);" |
19203 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" | 20704 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" |
19204 "load(o); load(o); load(o); load(o);"); | 20705 "load(o); load(o); load(o); load(o);"); |
19205 } | 20706 } |
19206 | 20707 |
19207 | 20708 |
19208 THREADED_TEST(Regress137496) { | 20709 THREADED_TEST(Regress137496) { |
19209 i::FLAG_expose_gc = true; | 20710 i::FLAG_expose_gc = true; |
19210 LocalContext context; | 20711 LocalContext context; |
19211 v8::HandleScope scope(context->GetIsolate()); | 20712 v8::HandleScope scope(context->GetIsolate()); |
19212 | 20713 |
19213 // Compile a try-finally clause where the finally block causes a GC | 20714 // Compile a try-finally clause where the finally block causes a GC |
19214 // while there still is a message pending for external reporting. | 20715 // while there still is a message pending for external reporting. |
19215 TryCatch try_catch(context->GetIsolate()); | 20716 TryCatch try_catch(context->GetIsolate()); |
19216 try_catch.SetVerbose(true); | 20717 try_catch.SetVerbose(true); |
19217 CompileRun("try { throw new Error(); } finally { gc(); }"); | 20718 CompileRun("try { throw new Error(); } finally { gc(); }"); |
19218 CHECK(try_catch.HasCaught()); | 20719 CHECK(try_catch.HasCaught()); |
19219 } | 20720 } |
19220 | 20721 |
19221 | 20722 |
19222 THREADED_TEST(Regress157124) { | 20723 THREADED_TEST(Regress157124) { |
19223 LocalContext context; | 20724 LocalContext context; |
19224 v8::Isolate* isolate = context->GetIsolate(); | 20725 v8::Isolate* isolate = context->GetIsolate(); |
19225 v8::HandleScope scope(isolate); | 20726 v8::HandleScope scope(isolate); |
19226 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 20727 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19227 Local<Object> obj = templ->NewInstance(); | 20728 Local<Object> obj = templ->NewInstance(context.local()).ToLocalChecked(); |
19228 obj->GetIdentityHash(); | 20729 obj->GetIdentityHash(); |
19229 obj->DeletePrivate(context.local(), | 20730 obj->DeletePrivate(context.local(), |
19230 v8::Private::ForApi(isolate, v8_str("Bug"))) | 20731 v8::Private::ForApi(isolate, v8_str("Bug"))) |
19231 .FromJust(); | 20732 .FromJust(); |
19232 } | 20733 } |
19233 | 20734 |
19234 | 20735 |
19235 THREADED_TEST(Regress2535) { | 20736 THREADED_TEST(Regress2535) { |
19236 LocalContext context; | 20737 LocalContext context; |
19237 v8::HandleScope scope(context->GetIsolate()); | 20738 v8::HandleScope scope(context->GetIsolate()); |
(...skipping 20 matching lines...) Expand all Loading... | |
19258 } | 20759 } |
19259 | 20760 |
19260 | 20761 |
19261 THREADED_TEST(Regress260106) { | 20762 THREADED_TEST(Regress260106) { |
19262 LocalContext context; | 20763 LocalContext context; |
19263 v8::Isolate* isolate = context->GetIsolate(); | 20764 v8::Isolate* isolate = context->GetIsolate(); |
19264 v8::HandleScope scope(isolate); | 20765 v8::HandleScope scope(isolate); |
19265 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, | 20766 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, |
19266 DummyCallHandler); | 20767 DummyCallHandler); |
19267 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); | 20768 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); |
19268 Local<Function> function = templ->GetFunction(); | 20769 Local<Function> function = |
20770 templ->GetFunction(context.local()).ToLocalChecked(); | |
19269 CHECK(!function.IsEmpty()); | 20771 CHECK(!function.IsEmpty()); |
19270 CHECK(function->IsFunction()); | 20772 CHECK(function->IsFunction()); |
19271 } | 20773 } |
19272 | 20774 |
19273 | 20775 |
19274 THREADED_TEST(JSONParseObject) { | 20776 THREADED_TEST(JSONParseObject) { |
19275 LocalContext context; | 20777 LocalContext context; |
19276 HandleScope scope(context->GetIsolate()); | 20778 HandleScope scope(context->GetIsolate()); |
19277 Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); | 20779 Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); |
19278 Handle<Object> global = context->Global(); | 20780 Local<Object> global = context->Global(); |
19279 global->Set(v8_str("obj"), obj); | 20781 global->Set(v8_str("obj"), obj); |
19280 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); | 20782 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); |
19281 } | 20783 } |
19282 | 20784 |
19283 | 20785 |
19284 THREADED_TEST(JSONParseNumber) { | 20786 THREADED_TEST(JSONParseNumber) { |
19285 LocalContext context; | 20787 LocalContext context; |
19286 HandleScope scope(context->GetIsolate()); | 20788 HandleScope scope(context->GetIsolate()); |
19287 Local<Value> obj = v8::JSON::Parse(v8_str("42")); | 20789 Local<Value> obj = v8::JSON::Parse(v8_str("42")); |
19288 Handle<Object> global = context->Global(); | 20790 Local<Object> global = context->Global(); |
19289 global->Set(v8_str("obj"), obj); | 20791 global->Set(v8_str("obj"), obj); |
19290 ExpectString("JSON.stringify(obj)", "42"); | 20792 ExpectString("JSON.stringify(obj)", "42"); |
19291 } | 20793 } |
19292 | 20794 |
19293 | 20795 |
19294 #if V8_OS_POSIX && !V8_OS_NACL | 20796 #if V8_OS_POSIX && !V8_OS_NACL |
19295 class ThreadInterruptTest { | 20797 class ThreadInterruptTest { |
19296 public: | 20798 public: |
19297 ThreadInterruptTest() : sem_(0), sem_value_(0) { } | 20799 ThreadInterruptTest() : sem_(0), sem_value_(0) { } |
19298 ~ThreadInterruptTest() {} | 20800 ~ThreadInterruptTest() {} |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19360 } | 20862 } |
19361 | 20863 |
19362 | 20864 |
19363 TEST(JSONStringifyAccessCheck) { | 20865 TEST(JSONStringifyAccessCheck) { |
19364 v8::V8::Initialize(); | 20866 v8::V8::Initialize(); |
19365 v8::Isolate* isolate = CcTest::isolate(); | 20867 v8::Isolate* isolate = CcTest::isolate(); |
19366 v8::HandleScope scope(isolate); | 20868 v8::HandleScope scope(isolate); |
19367 | 20869 |
19368 // Create an ObjectTemplate for global objects and install access | 20870 // Create an ObjectTemplate for global objects and install access |
19369 // check callbacks that will block access. | 20871 // check callbacks that will block access. |
19370 v8::Handle<v8::ObjectTemplate> global_template = | 20872 v8::Local<v8::ObjectTemplate> global_template = |
19371 v8::ObjectTemplate::New(isolate); | 20873 v8::ObjectTemplate::New(isolate); |
19372 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 20874 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
19373 | 20875 |
19374 // Create a context and set an x property on it's global object. | 20876 // Create a context and set an x property on it's global object. |
19375 LocalContext context0(NULL, global_template); | 20877 LocalContext context0(NULL, global_template); |
19376 v8::Handle<v8::Object> global0 = context0->Global(); | 20878 v8::Local<v8::Object> global0 = context0->Global(); |
19377 global0->Set(v8_str("x"), v8_num(42)); | 20879 global0->Set(v8_str("x"), v8_num(42)); |
19378 ExpectString("JSON.stringify(this)", "{\"x\":42}"); | 20880 ExpectString("JSON.stringify(this)", "{\"x\":42}"); |
19379 | 20881 |
19380 for (int i = 0; i < 2; i++) { | 20882 for (int i = 0; i < 2; i++) { |
19381 if (i == 1) { | 20883 if (i == 1) { |
19382 // Install a toJSON function on the second run. | 20884 // Install a toJSON function on the second run. |
19383 v8::Handle<v8::FunctionTemplate> toJSON = | 20885 v8::Local<v8::FunctionTemplate> toJSON = |
19384 v8::FunctionTemplate::New(isolate, UnreachableCallback); | 20886 v8::FunctionTemplate::New(isolate, UnreachableCallback); |
19385 | 20887 |
19386 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); | 20888 global0->Set(v8_str("toJSON"), |
20889 toJSON->GetFunction(context0.local()).ToLocalChecked()); | |
19387 } | 20890 } |
19388 // Create a context with a different security token so that the | 20891 // Create a context with a different security token so that the |
19389 // failed access check callback will be called on each access. | 20892 // failed access check callback will be called on each access. |
19390 LocalContext context1(NULL, global_template); | 20893 LocalContext context1(NULL, global_template); |
19391 context1->Global()->Set(v8_str("other"), global0); | 20894 CHECK(context1->Global() |
20895 ->Set(context1.local(), v8_str("other"), global0) | |
20896 .FromJust()); | |
19392 | 20897 |
19393 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); | 20898 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); |
19394 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); | 20899 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); |
19395 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty()); | 20900 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty()); |
19396 } | 20901 } |
19397 } | 20902 } |
19398 | 20903 |
19399 | 20904 |
19400 bool access_check_fail_thrown = false; | 20905 bool access_check_fail_thrown = false; |
19401 bool catch_callback_called = false; | 20906 bool catch_callback_called = false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19448 | 20953 |
19449 TEST(AccessCheckThrows) { | 20954 TEST(AccessCheckThrows) { |
19450 i::FLAG_allow_natives_syntax = true; | 20955 i::FLAG_allow_natives_syntax = true; |
19451 v8::V8::Initialize(); | 20956 v8::V8::Initialize(); |
19452 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); | 20957 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); |
19453 v8::Isolate* isolate = CcTest::isolate(); | 20958 v8::Isolate* isolate = CcTest::isolate(); |
19454 v8::HandleScope scope(isolate); | 20959 v8::HandleScope scope(isolate); |
19455 | 20960 |
19456 // Create an ObjectTemplate for global objects and install access | 20961 // Create an ObjectTemplate for global objects and install access |
19457 // check callbacks that will block access. | 20962 // check callbacks that will block access. |
19458 v8::Handle<v8::ObjectTemplate> global_template = | 20963 v8::Local<v8::ObjectTemplate> global_template = |
19459 v8::ObjectTemplate::New(isolate); | 20964 v8::ObjectTemplate::New(isolate); |
19460 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 20965 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
19461 | 20966 |
19462 // Create a context and set an x property on it's global object. | 20967 // Create a context and set an x property on it's global object. |
19463 LocalContext context0(NULL, global_template); | 20968 LocalContext context0(NULL, global_template); |
19464 v8::Handle<v8::Object> global0 = context0->Global(); | 20969 v8::Local<v8::Object> global0 = context0->Global(); |
19465 | 20970 |
19466 // Create a context with a different security token so that the | 20971 // Create a context with a different security token so that the |
19467 // failed access check callback will be called on each access. | 20972 // failed access check callback will be called on each access. |
19468 LocalContext context1(NULL, global_template); | 20973 LocalContext context1(NULL, global_template); |
19469 context1->Global()->Set(v8_str("other"), global0); | 20974 CHECK(context1->Global() |
20975 ->Set(context1.local(), v8_str("other"), global0) | |
20976 .FromJust()); | |
19470 | 20977 |
19471 v8::Handle<v8::FunctionTemplate> catcher_fun = | 20978 v8::Local<v8::FunctionTemplate> catcher_fun = |
19472 v8::FunctionTemplate::New(isolate, CatcherCallback); | 20979 v8::FunctionTemplate::New(isolate, CatcherCallback); |
19473 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); | 20980 CHECK(context1->Global() |
20981 ->Set(context1.local(), v8_str("catcher"), | |
20982 catcher_fun->GetFunction(context1.local()).ToLocalChecked()) | |
20983 .FromJust()); | |
19474 | 20984 |
19475 v8::Handle<v8::FunctionTemplate> has_own_property_fun = | 20985 v8::Local<v8::FunctionTemplate> has_own_property_fun = |
19476 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback); | 20986 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback); |
19477 context1->Global()->Set(v8_str("has_own_property"), | 20987 CHECK(context1->Global() |
19478 has_own_property_fun->GetFunction()); | 20988 ->Set(context1.local(), v8_str("has_own_property"), |
20989 has_own_property_fun->GetFunction(context1.local()) | |
20990 .ToLocalChecked()) | |
20991 .FromJust()); | |
19479 | 20992 |
19480 { | 20993 { |
19481 v8::TryCatch try_catch(isolate); | 20994 v8::TryCatch try_catch(isolate); |
19482 access_check_fail_thrown = false; | 20995 access_check_fail_thrown = false; |
19483 CompileRun("other.x;"); | 20996 CompileRun("other.x;"); |
19484 CHECK(access_check_fail_thrown); | 20997 CHECK(access_check_fail_thrown); |
19485 CHECK(try_catch.HasCaught()); | 20998 CHECK(try_catch.HasCaught()); |
19486 } | 20999 } |
19487 | 21000 |
19488 CheckCorrectThrow("other.x"); | 21001 CheckCorrectThrow("other.x"); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19601 InterruptThread i_thread; | 21114 InterruptThread i_thread; |
19602 }; | 21115 }; |
19603 | 21116 |
19604 | 21117 |
19605 class RequestInterruptTestWithFunctionCall | 21118 class RequestInterruptTestWithFunctionCall |
19606 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21119 : public RequestInterruptTestBaseWithSimpleInterrupt { |
19607 public: | 21120 public: |
19608 virtual void TestBody() { | 21121 virtual void TestBody() { |
19609 Local<Function> func = Function::New( | 21122 Local<Function> func = Function::New( |
19610 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); | 21123 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); |
19611 env_->Global()->Set(v8_str("ShouldContinue"), func); | 21124 CHECK(env_->Global() |
21125 ->Set(env_.local(), v8_str("ShouldContinue"), func) | |
21126 .FromJust()); | |
19612 | 21127 |
19613 CompileRun("while (ShouldContinue()) { }"); | 21128 CompileRun("while (ShouldContinue()) { }"); |
19614 } | 21129 } |
19615 }; | 21130 }; |
19616 | 21131 |
19617 | 21132 |
19618 class RequestInterruptTestWithMethodCall | 21133 class RequestInterruptTestWithMethodCall |
19619 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21134 : public RequestInterruptTestBaseWithSimpleInterrupt { |
19620 public: | 21135 public: |
19621 virtual void TestBody() { | 21136 virtual void TestBody() { |
19622 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21137 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
19623 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 21138 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
19624 proto->Set(v8_str("shouldContinue"), Function::New( | 21139 proto->Set(v8_str("shouldContinue"), Function::New( |
19625 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 21140 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
19626 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 21141 CHECK(env_->Global() |
21142 ->Set(env_.local(), v8_str("Klass"), | |
21143 t->GetFunction(env_.local()).ToLocalChecked()) | |
21144 .FromJust()); | |
19627 | 21145 |
19628 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 21146 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
19629 } | 21147 } |
19630 }; | 21148 }; |
19631 | 21149 |
19632 | 21150 |
19633 class RequestInterruptTestWithAccessor | 21151 class RequestInterruptTestWithAccessor |
19634 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21152 : public RequestInterruptTestBaseWithSimpleInterrupt { |
19635 public: | 21153 public: |
19636 virtual void TestBody() { | 21154 virtual void TestBody() { |
19637 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21155 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
19638 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 21156 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
19639 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( | 21157 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( |
19640 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 21158 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
19641 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 21159 CHECK(env_->Global() |
21160 ->Set(env_.local(), v8_str("Klass"), | |
21161 t->GetFunction(env_.local()).ToLocalChecked()) | |
21162 .FromJust()); | |
19642 | 21163 |
19643 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); | 21164 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
19644 } | 21165 } |
19645 }; | 21166 }; |
19646 | 21167 |
19647 | 21168 |
19648 class RequestInterruptTestWithNativeAccessor | 21169 class RequestInterruptTestWithNativeAccessor |
19649 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21170 : public RequestInterruptTestBaseWithSimpleInterrupt { |
19650 public: | 21171 public: |
19651 virtual void TestBody() { | 21172 virtual void TestBody() { |
19652 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21173 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
19653 t->InstanceTemplate()->SetNativeDataProperty( | 21174 t->InstanceTemplate()->SetNativeDataProperty( |
19654 v8_str("shouldContinue"), | 21175 v8_str("shouldContinue"), |
19655 &ShouldContinueNativeGetter, | 21176 &ShouldContinueNativeGetter, |
19656 NULL, | 21177 NULL, |
19657 v8::External::New(isolate_, this)); | 21178 v8::External::New(isolate_, this)); |
19658 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 21179 CHECK(env_->Global() |
21180 ->Set(env_.local(), v8_str("Klass"), | |
21181 t->GetFunction(env_.local()).ToLocalChecked()) | |
21182 .FromJust()); | |
19659 | 21183 |
19660 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); | 21184 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); |
19661 } | 21185 } |
19662 | 21186 |
19663 private: | 21187 private: |
19664 static void ShouldContinueNativeGetter( | 21188 static void ShouldContinueNativeGetter( |
19665 Local<String> property, | 21189 Local<String> property, |
19666 const v8::PropertyCallbackInfo<v8::Value>& info) { | 21190 const v8::PropertyCallbackInfo<v8::Value>& info) { |
19667 RequestInterruptTestBase* test = | 21191 RequestInterruptTestBase* test = |
19668 reinterpret_cast<RequestInterruptTestBase*>( | 21192 reinterpret_cast<RequestInterruptTestBase*>( |
19669 info.Data().As<v8::External>()->Value()); | 21193 info.Data().As<v8::External>()->Value()); |
19670 info.GetReturnValue().Set(test->ShouldContinue()); | 21194 info.GetReturnValue().Set(test->ShouldContinue()); |
19671 } | 21195 } |
19672 }; | 21196 }; |
19673 | 21197 |
19674 | 21198 |
19675 class RequestInterruptTestWithMethodCallAndInterceptor | 21199 class RequestInterruptTestWithMethodCallAndInterceptor |
19676 : public RequestInterruptTestBaseWithSimpleInterrupt { | 21200 : public RequestInterruptTestBaseWithSimpleInterrupt { |
19677 public: | 21201 public: |
19678 virtual void TestBody() { | 21202 virtual void TestBody() { |
19679 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); | 21203 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); |
19680 v8::Local<v8::Template> proto = t->PrototypeTemplate(); | 21204 v8::Local<v8::Template> proto = t->PrototypeTemplate(); |
19681 proto->Set(v8_str("shouldContinue"), Function::New( | 21205 proto->Set(v8_str("shouldContinue"), Function::New( |
19682 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); | 21206 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); |
19683 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); | 21207 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); |
19684 instance_template->SetHandler( | 21208 instance_template->SetHandler( |
19685 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); | 21209 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); |
19686 | 21210 |
19687 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); | 21211 CHECK(env_->Global() |
21212 ->Set(env_.local(), v8_str("Klass"), | |
21213 t->GetFunction(env_.local()).ToLocalChecked()) | |
21214 .FromJust()); | |
19688 | 21215 |
19689 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); | 21216 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); |
19690 } | 21217 } |
19691 | 21218 |
19692 private: | 21219 private: |
19693 static void EmptyInterceptor( | 21220 static void EmptyInterceptor( |
19694 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} | 21221 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} |
19695 }; | 21222 }; |
19696 | 21223 |
19697 | 21224 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19784 public: | 21311 public: |
19785 RequestMultipleInterrupts() : i_thread(this), counter_(0) {} | 21312 RequestMultipleInterrupts() : i_thread(this), counter_(0) {} |
19786 | 21313 |
19787 virtual void StartInterruptThread() { | 21314 virtual void StartInterruptThread() { |
19788 i_thread.Start(); | 21315 i_thread.Start(); |
19789 } | 21316 } |
19790 | 21317 |
19791 virtual void TestBody() { | 21318 virtual void TestBody() { |
19792 Local<Function> func = Function::New( | 21319 Local<Function> func = Function::New( |
19793 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); | 21320 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); |
19794 env_->Global()->Set(v8_str("ShouldContinue"), func); | 21321 CHECK(env_->Global() |
21322 ->Set(env_.local(), v8_str("ShouldContinue"), func) | |
21323 .FromJust()); | |
19795 | 21324 |
19796 CompileRun("while (ShouldContinue()) { }"); | 21325 CompileRun("while (ShouldContinue()) { }"); |
19797 } | 21326 } |
19798 | 21327 |
19799 private: | 21328 private: |
19800 class InterruptThread : public v8::base::Thread { | 21329 class InterruptThread : public v8::base::Thread { |
19801 public: | 21330 public: |
19802 enum { NUM_INTERRUPTS = 10 }; | 21331 enum { NUM_INTERRUPTS = 10 }; |
19803 explicit InterruptThread(RequestMultipleInterrupts* test) | 21332 explicit InterruptThread(RequestMultipleInterrupts* test) |
19804 : Thread(Options("RequestInterruptTest")), test_(test) {} | 21333 : Thread(Options("RequestInterruptTest")), test_(test) {} |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19855 } | 21384 } |
19856 | 21385 |
19857 | 21386 |
19858 THREADED_TEST(FunctionNew) { | 21387 THREADED_TEST(FunctionNew) { |
19859 LocalContext env; | 21388 LocalContext env; |
19860 v8::Isolate* isolate = env->GetIsolate(); | 21389 v8::Isolate* isolate = env->GetIsolate(); |
19861 v8::HandleScope scope(isolate); | 21390 v8::HandleScope scope(isolate); |
19862 Local<Object> data = v8::Object::New(isolate); | 21391 Local<Object> data = v8::Object::New(isolate); |
19863 function_new_expected_env = data; | 21392 function_new_expected_env = data; |
19864 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); | 21393 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); |
19865 env->Global()->Set(v8_str("func"), func); | 21394 CHECK(env->Global()->Set(env.local(), v8_str("func"), func).FromJust()); |
19866 Local<Value> result = CompileRun("func();"); | 21395 Local<Value> result = CompileRun("func();"); |
19867 CHECK(v8::Integer::New(isolate, 17)->Equals(result)); | 21396 CHECK(v8::Integer::New(isolate, 17)->Equals(result)); |
19868 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 21397 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
19869 // Verify function not cached | 21398 // Verify function not cached |
19870 auto serial_number = handle( | 21399 auto serial_number = handle( |
19871 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) | 21400 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) |
19872 ->shared() | 21401 ->shared() |
19873 ->get_api_func_data() | 21402 ->get_api_func_data() |
19874 ->serial_number()), | 21403 ->serial_number()), |
19875 i_isolate); | 21404 i_isolate); |
19876 auto cache = i_isolate->function_cache(); | 21405 auto cache = i_isolate->function_cache(); |
19877 CHECK(cache->Lookup(serial_number)->IsTheHole()); | 21406 CHECK(cache->Lookup(serial_number)->IsTheHole()); |
19878 // Verify that each Function::New creates a new function instance | 21407 // Verify that each Function::New creates a new function instance |
19879 Local<Object> data2 = v8::Object::New(isolate); | 21408 Local<Object> data2 = v8::Object::New(isolate); |
19880 function_new_expected_env = data2; | 21409 function_new_expected_env = data2; |
19881 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); | 21410 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); |
19882 CHECK(!func2->IsNull()); | 21411 CHECK(!func2->IsNull()); |
19883 CHECK(!func->Equals(func2)); | 21412 CHECK(!func->Equals(func2)); |
19884 env->Global()->Set(v8_str("func2"), func2); | 21413 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust()); |
19885 Local<Value> result2 = CompileRun("func2();"); | 21414 Local<Value> result2 = CompileRun("func2();"); |
19886 CHECK(v8::Integer::New(isolate, 17)->Equals(result2)); | 21415 CHECK(v8::Integer::New(isolate, 17)->Equals(result2)); |
19887 } | 21416 } |
19888 | 21417 |
19889 | 21418 |
19890 TEST(EscapeableHandleScope) { | 21419 TEST(EscapeableHandleScope) { |
19891 HandleScope outer_scope(CcTest::isolate()); | 21420 HandleScope outer_scope(CcTest::isolate()); |
19892 LocalContext context; | 21421 LocalContext context; |
19893 const int runs = 10; | 21422 const int runs = 10; |
19894 Local<String> values[runs]; | 21423 Local<String> values[runs]; |
(...skipping 19 matching lines...) Expand all Loading... | |
19914 CHECK(info.Holder() != info.This()); | 21443 CHECK(info.Holder() != info.This()); |
19915 } | 21444 } |
19916 | 21445 |
19917 | 21446 |
19918 TEST(Regress239669) { | 21447 TEST(Regress239669) { |
19919 LocalContext context; | 21448 LocalContext context; |
19920 v8::Isolate* isolate = context->GetIsolate(); | 21449 v8::Isolate* isolate = context->GetIsolate(); |
19921 v8::HandleScope scope(isolate); | 21450 v8::HandleScope scope(isolate); |
19922 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | 21451 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); |
19923 templ->SetAccessor(v8_str("x"), 0, SetterWhichExpectsThisAndHolderToDiffer); | 21452 templ->SetAccessor(v8_str("x"), 0, SetterWhichExpectsThisAndHolderToDiffer); |
19924 context->Global()->Set(v8_str("P"), templ->NewInstance()); | 21453 CHECK(context->Global() |
21454 ->Set(context.local(), v8_str("P"), | |
21455 templ->NewInstance(context.local()).ToLocalChecked()) | |
21456 .FromJust()); | |
19925 CompileRun( | 21457 CompileRun( |
19926 "function C1() {" | 21458 "function C1() {" |
19927 " this.x = 23;" | 21459 " this.x = 23;" |
19928 "};" | 21460 "};" |
19929 "C1.prototype = P;" | 21461 "C1.prototype = P;" |
19930 "for (var i = 0; i < 4; i++ ) {" | 21462 "for (var i = 0; i < 4; i++ ) {" |
19931 " new C1();" | 21463 " new C1();" |
19932 "}"); | 21464 "}"); |
19933 } | 21465 } |
19934 | 21466 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
19998 signature = v8::Signature::New(isolate, parent_template); | 21530 signature = v8::Signature::New(isolate, parent_template); |
19999 break; | 21531 break; |
20000 } | 21532 } |
20001 signature_template = function_template->InstanceTemplate(); | 21533 signature_template = function_template->InstanceTemplate(); |
20002 } | 21534 } |
20003 // Global object must pass checks. | 21535 // Global object must pass checks. |
20004 Local<v8::Context> context = | 21536 Local<v8::Context> context = |
20005 v8::Context::New(isolate, NULL, signature_template); | 21537 v8::Context::New(isolate, NULL, signature_template); |
20006 v8::Context::Scope context_scope(context); | 21538 v8::Context::Scope context_scope(context); |
20007 // Install regular object that can pass signature checks. | 21539 // Install regular object that can pass signature checks. |
20008 Local<Object> function_receiver = signature_template->NewInstance(); | 21540 Local<Object> function_receiver = |
20009 context->Global()->Set(v8_str("function_receiver"), function_receiver); | 21541 signature_template->NewInstance(context).ToLocalChecked(); |
21542 CHECK(context->Global() | |
21543 ->Set(context, v8_str("function_receiver"), function_receiver) | |
21544 .FromJust()); | |
20010 // Get the holder objects. | 21545 // Get the holder objects. |
20011 Local<Object> inner_global = | 21546 Local<Object> inner_global = |
20012 Local<Object>::Cast(context->Global()->GetPrototype()); | 21547 Local<Object>::Cast(context->Global()->GetPrototype()); |
20013 // Install functions on hidden prototype object if there is one. | 21548 // Install functions on hidden prototype object if there is one. |
20014 data = Object::New(isolate); | 21549 data = Object::New(isolate); |
20015 Local<FunctionTemplate> function_template = FunctionTemplate::New( | 21550 Local<FunctionTemplate> function_template = FunctionTemplate::New( |
20016 isolate, OptimizationCallback, data, signature); | 21551 isolate, OptimizationCallback, data, signature); |
20017 Local<Function> function = function_template->GetFunction(); | 21552 Local<Function> function = |
21553 function_template->GetFunction(context).ToLocalChecked(); | |
20018 Local<Object> global_holder = inner_global; | 21554 Local<Object> global_holder = inner_global; |
20019 Local<Object> function_holder = function_receiver; | 21555 Local<Object> function_holder = function_receiver; |
20020 if (signature_type == kSignatureOnPrototype) { | 21556 if (signature_type == kSignatureOnPrototype) { |
20021 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); | 21557 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); |
20022 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); | 21558 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); |
20023 } | 21559 } |
20024 global_holder->Set(v8_str("g_f"), function); | 21560 global_holder->Set(v8_str("g_f"), function); |
20025 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); | 21561 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); |
20026 function_holder->Set(v8_str("f"), function); | 21562 function_holder->Set(v8_str("f"), function); |
20027 function_holder->SetAccessorProperty(v8_str("acc"), function, function); | 21563 function_holder->SetAccessorProperty(v8_str("acc"), function, function); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20115 ApiCallOptimizationChecker checker; | 21651 ApiCallOptimizationChecker checker; |
20116 checker.RunAll(); | 21652 checker.RunAll(); |
20117 } | 21653 } |
20118 | 21654 |
20119 | 21655 |
20120 TEST(FunctionCallOptimizationMultipleArgs) { | 21656 TEST(FunctionCallOptimizationMultipleArgs) { |
20121 i::FLAG_allow_natives_syntax = true; | 21657 i::FLAG_allow_natives_syntax = true; |
20122 LocalContext context; | 21658 LocalContext context; |
20123 v8::Isolate* isolate = context->GetIsolate(); | 21659 v8::Isolate* isolate = context->GetIsolate(); |
20124 v8::HandleScope scope(isolate); | 21660 v8::HandleScope scope(isolate); |
20125 Handle<Object> global = context->Global(); | 21661 Local<Object> global = context->Global(); |
20126 Local<v8::Function> function = Function::New(isolate, Returns42); | 21662 Local<v8::Function> function = Function::New(isolate, Returns42); |
20127 global->Set(v8_str("x"), function); | 21663 global->Set(v8_str("x"), function); |
20128 CompileRun( | 21664 CompileRun( |
20129 "function x_wrap() {\n" | 21665 "function x_wrap() {\n" |
20130 " for (var i = 0; i < 5; i++) {\n" | 21666 " for (var i = 0; i < 5; i++) {\n" |
20131 " x(1,2,3);\n" | 21667 " x(1,2,3);\n" |
20132 " }\n" | 21668 " }\n" |
20133 "}\n" | 21669 "}\n" |
20134 "x_wrap();\n" | 21670 "x_wrap();\n" |
20135 "%OptimizeFunctionOnNextCall(x_wrap);" | 21671 "%OptimizeFunctionOnNextCall(x_wrap);" |
20136 "x_wrap();\n"); | 21672 "x_wrap();\n"); |
20137 } | 21673 } |
20138 | 21674 |
20139 | 21675 |
20140 static void ReturnsSymbolCallback( | 21676 static void ReturnsSymbolCallback( |
20141 const v8::FunctionCallbackInfo<v8::Value>& info) { | 21677 const v8::FunctionCallbackInfo<v8::Value>& info) { |
20142 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate())); | 21678 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate())); |
20143 } | 21679 } |
20144 | 21680 |
20145 | 21681 |
20146 TEST(ApiCallbackCanReturnSymbols) { | 21682 TEST(ApiCallbackCanReturnSymbols) { |
20147 i::FLAG_allow_natives_syntax = true; | 21683 i::FLAG_allow_natives_syntax = true; |
20148 LocalContext context; | 21684 LocalContext context; |
20149 v8::Isolate* isolate = context->GetIsolate(); | 21685 v8::Isolate* isolate = context->GetIsolate(); |
20150 v8::HandleScope scope(isolate); | 21686 v8::HandleScope scope(isolate); |
20151 Handle<Object> global = context->Global(); | 21687 Local<Object> global = context->Global(); |
20152 Local<v8::Function> function = Function::New(isolate, ReturnsSymbolCallback); | 21688 Local<v8::Function> function = Function::New(isolate, ReturnsSymbolCallback); |
20153 global->Set(v8_str("x"), function); | 21689 global->Set(v8_str("x"), function); |
20154 CompileRun( | 21690 CompileRun( |
20155 "function x_wrap() {\n" | 21691 "function x_wrap() {\n" |
20156 " for (var i = 0; i < 5; i++) {\n" | 21692 " for (var i = 0; i < 5; i++) {\n" |
20157 " x();\n" | 21693 " x();\n" |
20158 " }\n" | 21694 " }\n" |
20159 "}\n" | 21695 "}\n" |
20160 "x_wrap();\n" | 21696 "x_wrap();\n" |
20161 "%OptimizeFunctionOnNextCall(x_wrap);" | 21697 "%OptimizeFunctionOnNextCall(x_wrap);" |
20162 "x_wrap();\n"); | 21698 "x_wrap();\n"); |
20163 } | 21699 } |
20164 | 21700 |
20165 | 21701 |
20166 TEST(EmptyApiCallback) { | 21702 TEST(EmptyApiCallback) { |
20167 LocalContext context; | 21703 LocalContext context; |
20168 auto isolate = context->GetIsolate(); | 21704 auto isolate = context->GetIsolate(); |
20169 v8::HandleScope scope(isolate); | 21705 v8::HandleScope scope(isolate); |
20170 auto global = context->Global(); | 21706 auto global = context->Global(); |
20171 auto function = FunctionTemplate::New(isolate)->GetFunction(); | 21707 auto function = FunctionTemplate::New(isolate) |
21708 ->GetFunction(context.local()) | |
21709 .ToLocalChecked(); | |
20172 global->Set(v8_str("x"), function); | 21710 global->Set(v8_str("x"), function); |
20173 | 21711 |
20174 auto result = CompileRun("x()"); | 21712 auto result = CompileRun("x()"); |
20175 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); | 21713 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
20176 | 21714 |
20177 result = CompileRun("x(1,2,3)"); | 21715 result = CompileRun("x(1,2,3)"); |
20178 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); | 21716 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
20179 | 21717 |
20180 result = CompileRun("7 + x.call(3) + 11"); | 21718 result = CompileRun("7 + x.call(3) + 11"); |
20181 CHECK(result->IsInt32()); | 21719 CHECK(result->IsInt32()); |
20182 CHECK_EQ(21, result->Int32Value()); | 21720 CHECK_EQ(21, result->Int32Value(context.local()).FromJust()); |
20183 | 21721 |
20184 result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11"); | 21722 result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11"); |
20185 CHECK(result->IsInt32()); | 21723 CHECK(result->IsInt32()); |
20186 CHECK_EQ(21, result->Int32Value()); | 21724 CHECK_EQ(21, result->Int32Value(context.local()).FromJust()); |
20187 | 21725 |
20188 result = CompileRun("var y = []; x.call(y)"); | 21726 result = CompileRun("var y = []; x.call(y)"); |
20189 CHECK(result->IsArray()); | 21727 CHECK(result->IsArray()); |
20190 | 21728 |
20191 result = CompileRun("x.call(y, 1, 2, 3, 4)"); | 21729 result = CompileRun("x.call(y, 1, 2, 3, 4)"); |
20192 CHECK(result->IsArray()); | 21730 CHECK(result->IsArray()); |
20193 } | 21731 } |
20194 | 21732 |
20195 | 21733 |
20196 TEST(SimpleSignatureCheck) { | 21734 TEST(SimpleSignatureCheck) { |
20197 LocalContext context; | 21735 LocalContext context; |
20198 auto isolate = context->GetIsolate(); | 21736 auto isolate = context->GetIsolate(); |
20199 v8::HandleScope scope(isolate); | 21737 v8::HandleScope scope(isolate); |
20200 auto global = context->Global(); | 21738 auto global = context->Global(); |
20201 auto sig_obj = FunctionTemplate::New(isolate); | 21739 auto sig_obj = FunctionTemplate::New(isolate); |
20202 auto sig = v8::Signature::New(isolate, sig_obj); | 21740 auto sig = v8::Signature::New(isolate, sig_obj); |
20203 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); | 21741 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
20204 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); | 21742 global->Set(v8_str("sig_obj"), |
20205 global->Set(v8_str("x"), x->GetFunction()); | 21743 sig_obj->GetFunction(context.local()).ToLocalChecked()); |
21744 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | |
20206 CompileRun("var s = new sig_obj();"); | 21745 CompileRun("var s = new sig_obj();"); |
20207 { | 21746 { |
20208 TryCatch try_catch(isolate); | 21747 TryCatch try_catch(isolate); |
20209 CompileRun("x()"); | 21748 CompileRun("x()"); |
20210 CHECK(try_catch.HasCaught()); | 21749 CHECK(try_catch.HasCaught()); |
20211 } | 21750 } |
20212 { | 21751 { |
20213 TryCatch try_catch(isolate); | 21752 TryCatch try_catch(isolate); |
20214 CompileRun("x.call(1)"); | 21753 CompileRun("x.call(1)"); |
20215 CHECK(try_catch.HasCaught()); | 21754 CHECK(try_catch.HasCaught()); |
20216 } | 21755 } |
20217 { | 21756 { |
20218 TryCatch try_catch(isolate); | 21757 TryCatch try_catch(isolate); |
20219 auto result = CompileRun("s.x = x; s.x()"); | 21758 auto result = CompileRun("s.x = x; s.x()"); |
20220 CHECK(!try_catch.HasCaught()); | 21759 CHECK(!try_catch.HasCaught()); |
20221 CHECK_EQ(42, result->Int32Value()); | 21760 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20222 } | 21761 } |
20223 { | 21762 { |
20224 TryCatch try_catch(isolate); | 21763 TryCatch try_catch(isolate); |
20225 auto result = CompileRun("x.call(s)"); | 21764 auto result = CompileRun("x.call(s)"); |
20226 CHECK(!try_catch.HasCaught()); | 21765 CHECK(!try_catch.HasCaught()); |
20227 CHECK_EQ(42, result->Int32Value()); | 21766 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20228 } | 21767 } |
20229 } | 21768 } |
20230 | 21769 |
20231 | 21770 |
20232 TEST(ChainSignatureCheck) { | 21771 TEST(ChainSignatureCheck) { |
20233 LocalContext context; | 21772 LocalContext context; |
20234 auto isolate = context->GetIsolate(); | 21773 auto isolate = context->GetIsolate(); |
20235 v8::HandleScope scope(isolate); | 21774 v8::HandleScope scope(isolate); |
20236 auto global = context->Global(); | 21775 auto global = context->Global(); |
20237 auto sig_obj = FunctionTemplate::New(isolate); | 21776 auto sig_obj = FunctionTemplate::New(isolate); |
20238 auto sig = v8::Signature::New(isolate, sig_obj); | 21777 auto sig = v8::Signature::New(isolate, sig_obj); |
20239 for (int i = 0; i < 4; ++i) { | 21778 for (int i = 0; i < 4; ++i) { |
20240 auto temp = FunctionTemplate::New(isolate); | 21779 auto temp = FunctionTemplate::New(isolate); |
20241 temp->Inherit(sig_obj); | 21780 temp->Inherit(sig_obj); |
20242 sig_obj = temp; | 21781 sig_obj = temp; |
20243 } | 21782 } |
20244 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); | 21783 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
20245 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); | 21784 global->Set(v8_str("sig_obj"), |
20246 global->Set(v8_str("x"), x->GetFunction()); | 21785 sig_obj->GetFunction(context.local()).ToLocalChecked()); |
21786 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | |
20247 CompileRun("var s = new sig_obj();"); | 21787 CompileRun("var s = new sig_obj();"); |
20248 { | 21788 { |
20249 TryCatch try_catch(isolate); | 21789 TryCatch try_catch(isolate); |
20250 CompileRun("x()"); | 21790 CompileRun("x()"); |
20251 CHECK(try_catch.HasCaught()); | 21791 CHECK(try_catch.HasCaught()); |
20252 } | 21792 } |
20253 { | 21793 { |
20254 TryCatch try_catch(isolate); | 21794 TryCatch try_catch(isolate); |
20255 CompileRun("x.call(1)"); | 21795 CompileRun("x.call(1)"); |
20256 CHECK(try_catch.HasCaught()); | 21796 CHECK(try_catch.HasCaught()); |
20257 } | 21797 } |
20258 { | 21798 { |
20259 TryCatch try_catch(isolate); | 21799 TryCatch try_catch(isolate); |
20260 auto result = CompileRun("s.x = x; s.x()"); | 21800 auto result = CompileRun("s.x = x; s.x()"); |
20261 CHECK(!try_catch.HasCaught()); | 21801 CHECK(!try_catch.HasCaught()); |
20262 CHECK_EQ(42, result->Int32Value()); | 21802 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20263 } | 21803 } |
20264 { | 21804 { |
20265 TryCatch try_catch(isolate); | 21805 TryCatch try_catch(isolate); |
20266 auto result = CompileRun("x.call(s)"); | 21806 auto result = CompileRun("x.call(s)"); |
20267 CHECK(!try_catch.HasCaught()); | 21807 CHECK(!try_catch.HasCaught()); |
20268 CHECK_EQ(42, result->Int32Value()); | 21808 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20269 } | 21809 } |
20270 } | 21810 } |
20271 | 21811 |
20272 | 21812 |
20273 TEST(PrototypeSignatureCheck) { | 21813 TEST(PrototypeSignatureCheck) { |
20274 LocalContext context; | 21814 LocalContext context; |
20275 auto isolate = context->GetIsolate(); | 21815 auto isolate = context->GetIsolate(); |
20276 v8::HandleScope scope(isolate); | 21816 v8::HandleScope scope(isolate); |
20277 auto global = context->Global(); | 21817 auto global = context->Global(); |
20278 auto sig_obj = FunctionTemplate::New(isolate); | 21818 auto sig_obj = FunctionTemplate::New(isolate); |
20279 sig_obj->SetHiddenPrototype(true); | 21819 sig_obj->SetHiddenPrototype(true); |
20280 auto sig = v8::Signature::New(isolate, sig_obj); | 21820 auto sig = v8::Signature::New(isolate, sig_obj); |
20281 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); | 21821 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig); |
20282 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); | 21822 global->Set(v8_str("sig_obj"), |
20283 global->Set(v8_str("x"), x->GetFunction()); | 21823 sig_obj->GetFunction(context.local()).ToLocalChecked()); |
21824 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked()); | |
20284 CompileRun("s = {}; s.__proto__ = new sig_obj();"); | 21825 CompileRun("s = {}; s.__proto__ = new sig_obj();"); |
20285 { | 21826 { |
20286 TryCatch try_catch(isolate); | 21827 TryCatch try_catch(isolate); |
20287 CompileRun("x()"); | 21828 CompileRun("x()"); |
20288 CHECK(try_catch.HasCaught()); | 21829 CHECK(try_catch.HasCaught()); |
20289 } | 21830 } |
20290 { | 21831 { |
20291 TryCatch try_catch(isolate); | 21832 TryCatch try_catch(isolate); |
20292 CompileRun("x.call(1)"); | 21833 CompileRun("x.call(1)"); |
20293 CHECK(try_catch.HasCaught()); | 21834 CHECK(try_catch.HasCaught()); |
20294 } | 21835 } |
20295 { | 21836 { |
20296 TryCatch try_catch(isolate); | 21837 TryCatch try_catch(isolate); |
20297 auto result = CompileRun("s.x = x; s.x()"); | 21838 auto result = CompileRun("s.x = x; s.x()"); |
20298 CHECK(!try_catch.HasCaught()); | 21839 CHECK(!try_catch.HasCaught()); |
20299 CHECK_EQ(42, result->Int32Value()); | 21840 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20300 } | 21841 } |
20301 { | 21842 { |
20302 TryCatch try_catch(isolate); | 21843 TryCatch try_catch(isolate); |
20303 auto result = CompileRun("x.call(s)"); | 21844 auto result = CompileRun("x.call(s)"); |
20304 CHECK(!try_catch.HasCaught()); | 21845 CHECK(!try_catch.HasCaught()); |
20305 CHECK_EQ(42, result->Int32Value()); | 21846 CHECK_EQ(42, result->Int32Value(context.local()).FromJust()); |
20306 } | 21847 } |
20307 } | 21848 } |
20308 | 21849 |
20309 | 21850 |
20310 static const char* last_event_message; | 21851 static const char* last_event_message; |
20311 static int last_event_status; | 21852 static int last_event_status; |
20312 void StoringEventLoggerCallback(const char* message, int status) { | 21853 void StoringEventLoggerCallback(const char* message, int status) { |
20313 last_event_message = message; | 21854 last_event_message = message; |
20314 last_event_status = status; | 21855 last_event_status = status; |
20315 } | 21856 } |
(...skipping 11 matching lines...) Expand all Loading... | |
20327 histogramTimer.Stop(); | 21868 histogramTimer.Stop(); |
20328 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); | 21869 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); |
20329 CHECK_EQ(1, last_event_status); | 21870 CHECK_EQ(1, last_event_status); |
20330 } | 21871 } |
20331 | 21872 |
20332 | 21873 |
20333 TEST(Promises) { | 21874 TEST(Promises) { |
20334 LocalContext context; | 21875 LocalContext context; |
20335 v8::Isolate* isolate = context->GetIsolate(); | 21876 v8::Isolate* isolate = context->GetIsolate(); |
20336 v8::HandleScope scope(isolate); | 21877 v8::HandleScope scope(isolate); |
20337 Handle<Object> global = context->Global(); | 21878 Local<Object> global = context->Global(); |
20338 | 21879 |
20339 // Creation. | 21880 // Creation. |
20340 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); | 21881 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); |
20341 Handle<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate); | 21882 Local<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate); |
20342 Handle<v8::Promise> p = pr->GetPromise(); | 21883 Local<v8::Promise> p = pr->GetPromise(); |
20343 Handle<v8::Promise> r = rr->GetPromise(); | 21884 Local<v8::Promise> r = rr->GetPromise(); |
20344 CHECK_EQ(isolate, p->GetIsolate()); | 21885 CHECK_EQ(isolate, p->GetIsolate()); |
20345 | 21886 |
20346 // IsPromise predicate. | 21887 // IsPromise predicate. |
20347 CHECK(p->IsPromise()); | 21888 CHECK(p->IsPromise()); |
20348 CHECK(r->IsPromise()); | 21889 CHECK(r->IsPromise()); |
20349 Handle<Value> o = v8::Object::New(isolate); | 21890 Local<Value> o = v8::Object::New(isolate); |
20350 CHECK(!o->IsPromise()); | 21891 CHECK(!o->IsPromise()); |
20351 | 21892 |
20352 // Resolution and rejection. | 21893 // Resolution and rejection. |
20353 pr->Resolve(v8::Integer::New(isolate, 1)); | 21894 pr->Resolve(v8::Integer::New(isolate, 1)); |
20354 CHECK(p->IsPromise()); | 21895 CHECK(p->IsPromise()); |
20355 rr->Reject(v8::Integer::New(isolate, 2)); | 21896 rr->Reject(v8::Integer::New(isolate, 2)); |
20356 CHECK(r->IsPromise()); | 21897 CHECK(r->IsPromise()); |
20357 | 21898 |
20358 // Chaining non-pending promises. | 21899 // Chaining non-pending promises. |
20359 CompileRun( | 21900 CompileRun( |
20360 "var x1 = 0;\n" | 21901 "var x1 = 0;\n" |
20361 "var x2 = 0;\n" | 21902 "var x2 = 0;\n" |
20362 "function f1(x) { x1 = x; return x+1 };\n" | 21903 "function f1(x) { x1 = x; return x+1 };\n" |
20363 "function f2(x) { x2 = x; return x+1 };\n"); | 21904 "function f2(x) { x2 = x; return x+1 };\n"); |
20364 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); | 21905 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1"))); |
20365 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); | 21906 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2"))); |
20366 | 21907 |
20367 p->Chain(f1); | 21908 p->Chain(f1); |
20368 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 21909 CHECK_EQ(0, |
21910 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
20369 isolate->RunMicrotasks(); | 21911 isolate->RunMicrotasks(); |
20370 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 21912 CHECK_EQ(1, |
21913 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
20371 | 21914 |
20372 p->Catch(f2); | 21915 p->Catch(f2); |
20373 isolate->RunMicrotasks(); | 21916 isolate->RunMicrotasks(); |
20374 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21917 CHECK_EQ(0, |
21918 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20375 | 21919 |
20376 r->Catch(f2); | 21920 r->Catch(f2); |
20377 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21921 CHECK_EQ(0, |
21922 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20378 isolate->RunMicrotasks(); | 21923 isolate->RunMicrotasks(); |
20379 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); | 21924 CHECK_EQ(2, |
21925 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20380 | 21926 |
20381 r->Chain(f1); | 21927 r->Chain(f1); |
20382 isolate->RunMicrotasks(); | 21928 isolate->RunMicrotasks(); |
20383 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 21929 CHECK_EQ(1, |
21930 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
20384 | 21931 |
20385 // Chaining pending promises. | 21932 // Chaining pending promises. |
20386 CompileRun("x1 = x2 = 0;"); | 21933 CompileRun("x1 = x2 = 0;"); |
20387 pr = v8::Promise::Resolver::New(isolate); | 21934 pr = v8::Promise::Resolver::New(isolate); |
20388 rr = v8::Promise::Resolver::New(isolate); | 21935 rr = v8::Promise::Resolver::New(isolate); |
20389 | 21936 |
20390 pr->GetPromise()->Chain(f1); | 21937 pr->GetPromise()->Chain(f1); |
20391 rr->GetPromise()->Catch(f2); | 21938 rr->GetPromise()->Catch(f2); |
20392 isolate->RunMicrotasks(); | 21939 isolate->RunMicrotasks(); |
20393 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 21940 CHECK_EQ(0, |
20394 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21941 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21942 CHECK_EQ(0, | |
21943 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20395 | 21944 |
20396 pr->Resolve(v8::Integer::New(isolate, 1)); | 21945 pr->Resolve(v8::Integer::New(isolate, 1)); |
20397 rr->Reject(v8::Integer::New(isolate, 2)); | 21946 rr->Reject(v8::Integer::New(isolate, 2)); |
20398 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 21947 CHECK_EQ(0, |
20399 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21948 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21949 CHECK_EQ(0, | |
21950 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20400 | 21951 |
20401 isolate->RunMicrotasks(); | 21952 isolate->RunMicrotasks(); |
20402 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 21953 CHECK_EQ(1, |
20403 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); | 21954 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21955 CHECK_EQ(2, | |
21956 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20404 | 21957 |
20405 // Multi-chaining. | 21958 // Multi-chaining. |
20406 CompileRun("x1 = x2 = 0;"); | 21959 CompileRun("x1 = x2 = 0;"); |
20407 pr = v8::Promise::Resolver::New(isolate); | 21960 pr = v8::Promise::Resolver::New(isolate); |
20408 pr->GetPromise()->Chain(f1)->Chain(f2); | 21961 pr->GetPromise()->Chain(f1)->Chain(f2); |
20409 pr->Resolve(v8::Integer::New(isolate, 3)); | 21962 pr->Resolve(v8::Integer::New(isolate, 3)); |
20410 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 21963 CHECK_EQ(0, |
20411 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21964 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21965 CHECK_EQ(0, | |
21966 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20412 isolate->RunMicrotasks(); | 21967 isolate->RunMicrotasks(); |
20413 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 21968 CHECK_EQ(3, |
20414 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 21969 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21970 CHECK_EQ(4, | |
21971 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20415 | 21972 |
20416 CompileRun("x1 = x2 = 0;"); | 21973 CompileRun("x1 = x2 = 0;"); |
20417 rr = v8::Promise::Resolver::New(isolate); | 21974 rr = v8::Promise::Resolver::New(isolate); |
20418 rr->GetPromise()->Catch(f1)->Chain(f2); | 21975 rr->GetPromise()->Catch(f1)->Chain(f2); |
20419 rr->Reject(v8::Integer::New(isolate, 3)); | 21976 rr->Reject(v8::Integer::New(isolate, 3)); |
20420 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 21977 CHECK_EQ(0, |
20421 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 21978 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21979 CHECK_EQ(0, | |
21980 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20422 isolate->RunMicrotasks(); | 21981 isolate->RunMicrotasks(); |
20423 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 21982 CHECK_EQ(3, |
20424 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 21983 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
21984 CHECK_EQ(4, | |
21985 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20425 } | 21986 } |
20426 | 21987 |
20427 | 21988 |
20428 TEST(PromiseThen) { | 21989 TEST(PromiseThen) { |
20429 LocalContext context; | 21990 LocalContext context; |
20430 v8::Isolate* isolate = context->GetIsolate(); | 21991 v8::Isolate* isolate = context->GetIsolate(); |
20431 v8::HandleScope scope(isolate); | 21992 v8::HandleScope scope(isolate); |
20432 Handle<Object> global = context->Global(); | 21993 Local<Object> global = context->Global(); |
20433 | 21994 |
20434 // Creation. | 21995 // Creation. |
20435 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); | 21996 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); |
20436 Handle<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate); | 21997 Local<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate); |
20437 Handle<v8::Promise> p = pr->GetPromise(); | 21998 Local<v8::Promise> p = pr->GetPromise(); |
20438 Handle<v8::Promise> q = qr->GetPromise(); | 21999 Local<v8::Promise> q = qr->GetPromise(); |
20439 | 22000 |
20440 CHECK(p->IsPromise()); | 22001 CHECK(p->IsPromise()); |
20441 CHECK(q->IsPromise()); | 22002 CHECK(q->IsPromise()); |
20442 | 22003 |
20443 pr->Resolve(v8::Integer::New(isolate, 1)); | 22004 pr->Resolve(v8::Integer::New(isolate, 1)); |
20444 qr->Resolve(p); | 22005 qr->Resolve(p); |
20445 | 22006 |
20446 // Chaining non-pending promises. | 22007 // Chaining non-pending promises. |
20447 CompileRun( | 22008 CompileRun( |
20448 "var x1 = 0;\n" | 22009 "var x1 = 0;\n" |
20449 "var x2 = 0;\n" | 22010 "var x2 = 0;\n" |
20450 "function f1(x) { x1 = x; return x+1 };\n" | 22011 "function f1(x) { x1 = x; return x+1 };\n" |
20451 "function f2(x) { x2 = x; return x+1 };\n"); | 22012 "function f2(x) { x2 = x; return x+1 };\n"); |
20452 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); | 22013 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1"))); |
20453 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); | 22014 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2"))); |
20454 | 22015 |
20455 // TODO(caitp): remove tests once PromiseChain is removed, per bug 3237 | 22016 // TODO(caitp): remove tests once PromiseChain is removed, per bug 3237 |
20456 /* q->Chain(f1); | 22017 /* q->Chain(f1); |
20457 CHECK(global->Get(v8_str2("x1"))->IsNumber()); | 22018 CHECK(global->Get(v8_str2("x1"))->IsNumber()); |
20458 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22019 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); |
20459 isolate->RunMicrotasks(); | 22020 isolate->RunMicrotasks(); |
20460 CHECK(!global->Get(v8_str("x1"))->IsNumber()); | 22021 CHECK(!global->Get(v8_str("x1"))->IsNumber()); |
20461 CHECK(p->Equals(global->Get(v8_str("x1")))); */ | 22022 CHECK(p->Equals(global->Get(v8_str("x1")))); */ |
20462 | 22023 |
20463 // Then | 22024 // Then |
20464 CompileRun("x1 = x2 = 0;"); | 22025 CompileRun("x1 = x2 = 0;"); |
20465 q->Then(f1); | 22026 q->Then(f1); |
20466 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22027 CHECK_EQ(0, |
22028 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
20467 isolate->RunMicrotasks(); | 22029 isolate->RunMicrotasks(); |
20468 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); | 22030 CHECK_EQ(1, |
22031 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); | |
20469 | 22032 |
20470 // Then | 22033 // Then |
20471 CompileRun("x1 = x2 = 0;"); | 22034 CompileRun("x1 = x2 = 0;"); |
20472 pr = v8::Promise::Resolver::New(isolate); | 22035 pr = v8::Promise::Resolver::New(isolate); |
20473 qr = v8::Promise::Resolver::New(isolate); | 22036 qr = v8::Promise::Resolver::New(isolate); |
20474 | 22037 |
20475 qr->Resolve(pr); | 22038 qr->Resolve(pr); |
20476 qr->GetPromise()->Then(f1)->Then(f2); | 22039 qr->GetPromise()->Then(f1)->Then(f2); |
20477 | 22040 |
20478 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22041 CHECK_EQ(0, |
20479 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22042 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
22043 CHECK_EQ(0, | |
22044 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20480 isolate->RunMicrotasks(); | 22045 isolate->RunMicrotasks(); |
20481 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22046 CHECK_EQ(0, |
20482 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22047 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
22048 CHECK_EQ(0, | |
22049 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20483 | 22050 |
20484 pr->Resolve(v8::Integer::New(isolate, 3)); | 22051 pr->Resolve(v8::Integer::New(isolate, 3)); |
20485 | 22052 |
20486 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); | 22053 CHECK_EQ(0, |
20487 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); | 22054 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
22055 CHECK_EQ(0, | |
22056 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20488 isolate->RunMicrotasks(); | 22057 isolate->RunMicrotasks(); |
20489 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); | 22058 CHECK_EQ(3, |
20490 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); | 22059 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust()); |
22060 CHECK_EQ(4, | |
22061 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust()); | |
20491 } | 22062 } |
20492 | 22063 |
20493 | 22064 |
20494 TEST(DisallowJavascriptExecutionScope) { | 22065 TEST(DisallowJavascriptExecutionScope) { |
20495 LocalContext context; | 22066 LocalContext context; |
20496 v8::Isolate* isolate = context->GetIsolate(); | 22067 v8::Isolate* isolate = context->GetIsolate(); |
20497 v8::HandleScope scope(isolate); | 22068 v8::HandleScope scope(isolate); |
20498 v8::Isolate::DisallowJavascriptExecutionScope no_js( | 22069 v8::Isolate::DisallowJavascriptExecutionScope no_js( |
20499 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); | 22070 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); |
20500 CompileRun("2+2"); | 22071 CompileRun("2+2"); |
(...skipping 24 matching lines...) Expand all Loading... | |
20525 CompileRun("1+1"); | 22096 CompileRun("1+1"); |
20526 CHECK(try_catch.HasCaught()); | 22097 CHECK(try_catch.HasCaught()); |
20527 } | 22098 } |
20528 | 22099 |
20529 | 22100 |
20530 TEST(Regress354123) { | 22101 TEST(Regress354123) { |
20531 LocalContext current; | 22102 LocalContext current; |
20532 v8::Isolate* isolate = current->GetIsolate(); | 22103 v8::Isolate* isolate = current->GetIsolate(); |
20533 v8::HandleScope scope(isolate); | 22104 v8::HandleScope scope(isolate); |
20534 | 22105 |
20535 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | 22106 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); |
20536 templ->SetAccessCheckCallback(AccessCounter); | 22107 templ->SetAccessCheckCallback(AccessCounter); |
20537 current->Global()->Set(v8_str("friend"), templ->NewInstance()); | 22108 CHECK(current->Global() |
22109 ->Set(current.local(), v8_str("friend"), | |
22110 templ->NewInstance(current.local()).ToLocalChecked()) | |
22111 .FromJust()); | |
20538 | 22112 |
20539 // Test access using __proto__ from the prototype chain. | 22113 // Test access using __proto__ from the prototype chain. |
20540 access_count = 0; | 22114 access_count = 0; |
20541 CompileRun("friend.__proto__ = {};"); | 22115 CompileRun("friend.__proto__ = {};"); |
20542 CHECK_EQ(2, access_count); | 22116 CHECK_EQ(2, access_count); |
20543 CompileRun("friend.__proto__;"); | 22117 CompileRun("friend.__proto__;"); |
20544 CHECK_EQ(4, access_count); | 22118 CHECK_EQ(4, access_count); |
20545 | 22119 |
20546 // Test access using __proto__ as a hijacked function (A). | 22120 // Test access using __proto__ as a hijacked function (A). |
20547 access_count = 0; | 22121 access_count = 0; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20596 isolate, &script_source); | 22170 isolate, &script_source); |
20597 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 22171 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
20598 CHECK(!script_name.IsEmpty()); | 22172 CHECK(!script_name.IsEmpty()); |
20599 CHECK(script_name->IsString()); | 22173 CHECK(script_name->IsString()); |
20600 String::Utf8Value utf8_name(script_name); | 22174 String::Utf8Value utf8_name(script_name); |
20601 CHECK_EQ(0, strcmp(url, *utf8_name)); | 22175 CHECK_EQ(0, strcmp(url, *utf8_name)); |
20602 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 22176 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
20603 CHECK_EQ(13, line_number); | 22177 CHECK_EQ(13, line_number); |
20604 } | 22178 } |
20605 | 22179 |
20606 void CheckMagicComments(Handle<Script> script, const char* expected_source_url, | 22180 void CheckMagicComments(Local<Script> script, const char* expected_source_url, |
20607 const char* expected_source_mapping_url) { | 22181 const char* expected_source_mapping_url) { |
20608 if (expected_source_url != NULL) { | 22182 if (expected_source_url != NULL) { |
20609 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); | 22183 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
20610 CHECK_EQ(0, strcmp(expected_source_url, *url)); | 22184 CHECK_EQ(0, strcmp(expected_source_url, *url)); |
20611 } else { | 22185 } else { |
20612 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); | 22186 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
20613 } | 22187 } |
20614 if (expected_source_mapping_url != NULL) { | 22188 if (expected_source_mapping_url != NULL) { |
20615 v8::String::Utf8Value url( | 22189 v8::String::Utf8Value url( |
20616 script->GetUnboundScript()->GetSourceMappingURL()); | 22190 script->GetUnboundScript()->GetSourceMappingURL()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20705 Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop")); | 22279 Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop")); |
20706 CHECK(desc->IsUndefined()); | 22280 CHECK(desc->IsUndefined()); |
20707 desc = x->GetOwnPropertyDescriptor(v8_str("p0")); | 22281 desc = x->GetOwnPropertyDescriptor(v8_str("p0")); |
20708 CHECK(v8_num(12)->Equals(Local<Object>::Cast(desc)->Get(v8_str("value")))); | 22282 CHECK(v8_num(12)->Equals(Local<Object>::Cast(desc)->Get(v8_str("value")))); |
20709 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); | 22283 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); |
20710 Local<Function> set = | 22284 Local<Function> set = |
20711 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); | 22285 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); |
20712 Local<Function> get = | 22286 Local<Function> get = |
20713 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); | 22287 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); |
20714 CHECK(v8_num(13)->Equals(get->Call(x, 0, NULL))); | 22288 CHECK(v8_num(13)->Equals(get->Call(x, 0, NULL))); |
20715 Handle<Value> args[] = { v8_num(14) }; | 22289 Local<Value> args[] = {v8_num(14)}; |
20716 set->Call(x, 1, args); | 22290 set->Call(x, 1, args); |
20717 CHECK(v8_num(14)->Equals(get->Call(x, 0, NULL))); | 22291 CHECK(v8_num(14)->Equals(get->Call(x, 0, NULL))); |
20718 } | 22292 } |
20719 | 22293 |
20720 | 22294 |
20721 TEST(Regress411877) { | 22295 TEST(Regress411877) { |
20722 v8::Isolate* isolate = CcTest::isolate(); | 22296 v8::Isolate* isolate = CcTest::isolate(); |
20723 v8::HandleScope handle_scope(isolate); | 22297 v8::HandleScope handle_scope(isolate); |
20724 v8::Handle<v8::ObjectTemplate> object_template = | 22298 v8::Local<v8::ObjectTemplate> object_template = |
20725 v8::ObjectTemplate::New(isolate); | 22299 v8::ObjectTemplate::New(isolate); |
20726 object_template->SetAccessCheckCallback(AccessCounter); | 22300 object_template->SetAccessCheckCallback(AccessCounter); |
20727 | 22301 |
20728 v8::Handle<Context> context = Context::New(isolate); | 22302 v8::Local<Context> context = Context::New(isolate); |
20729 v8::Context::Scope context_scope(context); | 22303 v8::Context::Scope context_scope(context); |
20730 | 22304 |
20731 context->Global()->Set(v8_str("o"), object_template->NewInstance()); | 22305 CHECK(context->Global() |
22306 ->Set(context, v8_str("o"), | |
22307 object_template->NewInstance(context).ToLocalChecked()) | |
22308 .FromJust()); | |
20732 CompileRun("Object.getOwnPropertyNames(o)"); | 22309 CompileRun("Object.getOwnPropertyNames(o)"); |
20733 } | 22310 } |
20734 | 22311 |
20735 | 22312 |
20736 TEST(GetHiddenPropertyTableAfterAccessCheck) { | 22313 TEST(GetHiddenPropertyTableAfterAccessCheck) { |
20737 v8::Isolate* isolate = CcTest::isolate(); | 22314 v8::Isolate* isolate = CcTest::isolate(); |
20738 v8::HandleScope handle_scope(isolate); | 22315 v8::HandleScope handle_scope(isolate); |
20739 v8::Handle<v8::ObjectTemplate> object_template = | 22316 v8::Local<v8::ObjectTemplate> object_template = |
20740 v8::ObjectTemplate::New(isolate); | 22317 v8::ObjectTemplate::New(isolate); |
20741 object_template->SetAccessCheckCallback(AccessCounter); | 22318 object_template->SetAccessCheckCallback(AccessCounter); |
20742 | 22319 |
20743 v8::Handle<Context> context = Context::New(isolate); | 22320 v8::Local<Context> context = Context::New(isolate); |
20744 v8::Context::Scope context_scope(context); | 22321 v8::Context::Scope context_scope(context); |
20745 | 22322 |
20746 v8::Handle<v8::Object> obj = object_template->NewInstance(); | 22323 v8::Local<v8::Object> obj = |
22324 object_template->NewInstance(context).ToLocalChecked(); | |
20747 obj->Set(v8_str("key"), v8_str("value")); | 22325 obj->Set(v8_str("key"), v8_str("value")); |
20748 obj->Delete(v8_str("key")); | 22326 obj->Delete(v8_str("key")); |
20749 | 22327 |
20750 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")), | 22328 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")), |
20751 v8_str("hidden value 2")) | 22329 v8_str("hidden value 2")) |
20752 .FromJust(); | 22330 .FromJust(); |
20753 } | 22331 } |
20754 | 22332 |
20755 | 22333 |
20756 TEST(Regress411793) { | 22334 TEST(Regress411793) { |
20757 v8::Isolate* isolate = CcTest::isolate(); | 22335 v8::Isolate* isolate = CcTest::isolate(); |
20758 v8::HandleScope handle_scope(isolate); | 22336 v8::HandleScope handle_scope(isolate); |
20759 v8::Handle<v8::ObjectTemplate> object_template = | 22337 v8::Local<v8::ObjectTemplate> object_template = |
20760 v8::ObjectTemplate::New(isolate); | 22338 v8::ObjectTemplate::New(isolate); |
20761 object_template->SetAccessCheckCallback(AccessCounter); | 22339 object_template->SetAccessCheckCallback(AccessCounter); |
20762 | 22340 |
20763 v8::Handle<Context> context = Context::New(isolate); | 22341 v8::Local<Context> context = Context::New(isolate); |
20764 v8::Context::Scope context_scope(context); | 22342 v8::Context::Scope context_scope(context); |
20765 | 22343 |
20766 context->Global()->Set(v8_str("o"), object_template->NewInstance()); | 22344 CHECK(context->Global() |
22345 ->Set(context, v8_str("o"), | |
22346 object_template->NewInstance(context).ToLocalChecked()) | |
22347 .FromJust()); | |
20767 CompileRun( | 22348 CompileRun( |
20768 "Object.defineProperty(o, 'key', " | 22349 "Object.defineProperty(o, 'key', " |
20769 " { get: function() {}, set: function() {} });"); | 22350 " { get: function() {}, set: function() {} });"); |
20770 } | 22351 } |
20771 | 22352 |
20772 class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream { | 22353 class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream { |
20773 public: | 22354 public: |
20774 explicit TestSourceStream(const char** chunks) : chunks_(chunks), index_(0) {} | 22355 explicit TestSourceStream(const char** chunks) : chunks_(chunks), index_(0) {} |
20775 | 22356 |
20776 virtual size_t GetMoreData(const uint8_t** src) { | 22357 virtual size_t GetMoreData(const uint8_t** src) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
20832 // TestSourceStream::GetMoreData won't block, so it's OK to just run the | 22413 // TestSourceStream::GetMoreData won't block, so it's OK to just run the |
20833 // task here in the main thread. | 22414 // task here in the main thread. |
20834 task->Run(); | 22415 task->Run(); |
20835 delete task; | 22416 delete task; |
20836 | 22417 |
20837 // Possible errors are only produced while compiling. | 22418 // Possible errors are only produced while compiling. |
20838 CHECK_EQ(false, try_catch.HasCaught()); | 22419 CHECK_EQ(false, try_catch.HasCaught()); |
20839 | 22420 |
20840 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 22421 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
20841 char* full_source = TestSourceStream::FullSourceString(chunks); | 22422 char* full_source = TestSourceStream::FullSourceString(chunks); |
20842 v8::Handle<Script> script = v8::ScriptCompiler::Compile( | 22423 v8::Local<Script> script = v8::ScriptCompiler::Compile( |
20843 isolate, &source, v8_str(full_source), origin); | 22424 isolate, &source, v8_str(full_source), origin); |
20844 if (expected_success) { | 22425 if (expected_success) { |
20845 CHECK(!script.IsEmpty()); | 22426 CHECK(!script.IsEmpty()); |
20846 v8::Handle<Value> result(script->Run()); | 22427 v8::Local<Value> result(script->Run()); |
20847 // All scripts are supposed to return the fixed value 13 when ran. | 22428 // All scripts are supposed to return the fixed value 13 when ran. |
20848 CHECK_EQ(13, result->Int32Value()); | 22429 CHECK_EQ(13, result->Int32Value(env.local()).FromJust()); |
20849 CheckMagicComments(script, expected_source_url, | 22430 CheckMagicComments(script, expected_source_url, |
20850 expected_source_mapping_url); | 22431 expected_source_mapping_url); |
20851 } else { | 22432 } else { |
20852 CHECK(script.IsEmpty()); | 22433 CHECK(script.IsEmpty()); |
20853 CHECK(try_catch.HasCaught()); | 22434 CHECK(try_catch.HasCaught()); |
20854 } | 22435 } |
20855 delete[] full_source; | 22436 delete[] full_source; |
20856 } | 22437 } |
20857 | 22438 |
20858 | 22439 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21107 task->Run(); | 22688 task->Run(); |
21108 delete task; | 22689 delete task; |
21109 | 22690 |
21110 CHECK(!try_catch.HasCaught()); | 22691 CHECK(!try_catch.HasCaught()); |
21111 | 22692 |
21112 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 22693 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
21113 char* full_source = TestSourceStream::FullSourceString(chunks); | 22694 char* full_source = TestSourceStream::FullSourceString(chunks); |
21114 | 22695 |
21115 EnableDebugger(); | 22696 EnableDebugger(); |
21116 | 22697 |
21117 v8::Handle<Script> script = v8::ScriptCompiler::Compile( | 22698 v8::Local<Script> script = v8::ScriptCompiler::Compile( |
21118 isolate, &source, v8_str(full_source), origin); | 22699 isolate, &source, v8_str(full_source), origin); |
21119 | 22700 |
21120 Maybe<uint32_t> result = | 22701 Maybe<uint32_t> result = |
21121 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); | 22702 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); |
21122 CHECK_EQ(3U, result.FromMaybe(0)); | 22703 CHECK_EQ(3U, result.FromMaybe(0)); |
21123 | 22704 |
21124 delete[] full_source; | 22705 delete[] full_source; |
21125 | 22706 |
21126 DisableDebugger(); | 22707 DisableDebugger(); |
21127 } | 22708 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21211 v8::ScriptCompiler::StartStreamingScript(isolate, &source); | 22792 v8::ScriptCompiler::StartStreamingScript(isolate, &source); |
21212 task->Run(); | 22793 task->Run(); |
21213 delete task; | 22794 delete task; |
21214 | 22795 |
21215 // Parsing should succeed (the script will be parsed and compiled in a context | 22796 // Parsing should succeed (the script will be parsed and compiled in a context |
21216 // independent way, so the error is not detected). | 22797 // independent way, so the error is not detected). |
21217 CHECK_EQ(false, try_catch.HasCaught()); | 22798 CHECK_EQ(false, try_catch.HasCaught()); |
21218 | 22799 |
21219 v8::ScriptOrigin origin(v8_str("http://foo.com")); | 22800 v8::ScriptOrigin origin(v8_str("http://foo.com")); |
21220 char* full_source = TestSourceStream::FullSourceString(chunks); | 22801 char* full_source = TestSourceStream::FullSourceString(chunks); |
21221 v8::Handle<Script> script = v8::ScriptCompiler::Compile( | 22802 v8::Local<Script> script = v8::ScriptCompiler::Compile( |
21222 isolate, &source, v8_str(full_source), origin); | 22803 isolate, &source, v8_str(full_source), origin); |
21223 CHECK(!script.IsEmpty()); | 22804 CHECK(!script.IsEmpty()); |
21224 CHECK_EQ(false, try_catch.HasCaught()); | 22805 CHECK_EQ(false, try_catch.HasCaught()); |
21225 | 22806 |
21226 // Running the script exposes the error. | 22807 // Running the script exposes the error. |
21227 v8::Handle<Value> result(script->Run()); | 22808 v8::Local<Value> result(script->Run()); |
21228 CHECK(result.IsEmpty()); | 22809 CHECK(result.IsEmpty()); |
21229 CHECK(try_catch.HasCaught()); | 22810 CHECK(try_catch.HasCaught()); |
21230 delete[] full_source; | 22811 delete[] full_source; |
21231 } | 22812 } |
21232 | 22813 |
21233 | 22814 |
21234 TEST(CodeCache) { | 22815 TEST(CodeCache) { |
21235 v8::Isolate::CreateParams create_params; | 22816 v8::Isolate::CreateParams create_params; |
21236 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 22817 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
21237 | 22818 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21270 v8::ScriptCompiler::Source source(source_string, script_origin, cache); | 22851 v8::ScriptCompiler::Source source(source_string, script_origin, cache); |
21271 v8::ScriptCompiler::CompileOptions option = | 22852 v8::ScriptCompiler::CompileOptions option = |
21272 v8::ScriptCompiler::kConsumeCodeCache; | 22853 v8::ScriptCompiler::kConsumeCodeCache; |
21273 v8::Local<v8::Script> script; | 22854 v8::Local<v8::Script> script; |
21274 { | 22855 { |
21275 i::DisallowCompilation no_compile( | 22856 i::DisallowCompilation no_compile( |
21276 reinterpret_cast<i::Isolate*>(isolate2)); | 22857 reinterpret_cast<i::Isolate*>(isolate2)); |
21277 script = v8::ScriptCompiler::Compile(context, &source, option) | 22858 script = v8::ScriptCompiler::Compile(context, &source, option) |
21278 .ToLocalChecked(); | 22859 .ToLocalChecked(); |
21279 } | 22860 } |
21280 CHECK_EQ(2, script->Run()->ToInt32(isolate2)->Int32Value()); | 22861 CHECK_EQ(2, |
22862 script->Run()->ToInt32(isolate2)->Int32Value(context).FromJust()); | |
21281 } | 22863 } |
21282 isolate2->Dispose(); | 22864 isolate2->Dispose(); |
21283 } | 22865 } |
21284 | 22866 |
21285 | 22867 |
21286 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { | 22868 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { |
21287 const char* garbage = "garbage garbage garbage garbage garbage garbage"; | 22869 const char* garbage = "garbage garbage garbage garbage garbage garbage"; |
21288 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); | 22870 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); |
21289 int length = 16; | 22871 int length = 16; |
21290 v8::ScriptCompiler::CachedData* cached_data = | 22872 v8::ScriptCompiler::CachedData* cached_data = |
21291 new v8::ScriptCompiler::CachedData(data, length); | 22873 new v8::ScriptCompiler::CachedData(data, length); |
21292 DCHECK(!cached_data->rejected); | 22874 DCHECK(!cached_data->rejected); |
21293 v8::ScriptOrigin origin(v8_str("origin")); | 22875 v8::ScriptOrigin origin(v8_str("origin")); |
21294 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); | 22876 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); |
21295 v8::Handle<v8::Script> script = | 22877 v8::Local<v8::Script> script = |
21296 v8::ScriptCompiler::Compile(CcTest::isolate(), &source, option); | 22878 v8::ScriptCompiler::Compile(CcTest::isolate(), &source, option); |
21297 CHECK(cached_data->rejected); | 22879 CHECK(cached_data->rejected); |
21298 CHECK_EQ(42, script->Run()->Int32Value()); | 22880 CHECK_EQ(42, script->Run() |
22881 ->Int32Value(CcTest::isolate()->GetCurrentContext()) | |
22882 .FromJust()); | |
21299 } | 22883 } |
21300 | 22884 |
21301 | 22885 |
21302 TEST(InvalidCacheData) { | 22886 TEST(InvalidCacheData) { |
21303 v8::V8::Initialize(); | 22887 v8::V8::Initialize(); |
21304 v8::HandleScope scope(CcTest::isolate()); | 22888 v8::HandleScope scope(CcTest::isolate()); |
21305 LocalContext context; | 22889 LocalContext context; |
21306 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); | 22890 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); |
21307 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); | 22891 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); |
21308 } | 22892 } |
21309 | 22893 |
21310 | 22894 |
21311 TEST(ParserCacheRejectedGracefully) { | 22895 TEST(ParserCacheRejectedGracefully) { |
21312 i::FLAG_min_preparse_length = 0; | 22896 i::FLAG_min_preparse_length = 0; |
21313 v8::V8::Initialize(); | 22897 v8::V8::Initialize(); |
21314 v8::HandleScope scope(CcTest::isolate()); | 22898 v8::HandleScope scope(CcTest::isolate()); |
21315 LocalContext context; | 22899 LocalContext context; |
21316 // Produce valid cached data. | 22900 // Produce valid cached data. |
21317 v8::ScriptOrigin origin(v8_str("origin")); | 22901 v8::ScriptOrigin origin(v8_str("origin")); |
21318 v8::Local<v8::String> source_str = v8_str("function foo() {}"); | 22902 v8::Local<v8::String> source_str = v8_str("function foo() {}"); |
21319 v8::ScriptCompiler::Source source(source_str, origin); | 22903 v8::ScriptCompiler::Source source(source_str, origin); |
21320 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile( | 22904 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile( |
21321 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache); | 22905 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache); |
21322 CHECK(!script.IsEmpty()); | 22906 CHECK(!script.IsEmpty()); |
21323 const v8::ScriptCompiler::CachedData* original_cached_data = | 22907 const v8::ScriptCompiler::CachedData* original_cached_data = |
21324 source.GetCachedData(); | 22908 source.GetCachedData(); |
21325 CHECK(original_cached_data != NULL); | 22909 CHECK(original_cached_data != NULL); |
21326 CHECK(original_cached_data->data != NULL); | 22910 CHECK(original_cached_data->data != NULL); |
21327 CHECK(!original_cached_data->rejected); | 22911 CHECK(!original_cached_data->rejected); |
21328 CHECK_GT(original_cached_data->length, 0); | 22912 CHECK_GT(original_cached_data->length, 0); |
21329 // Recompiling the same script with it won't reject the data. | 22913 // Recompiling the same script with it won't reject the data. |
21330 { | 22914 { |
21331 v8::ScriptCompiler::Source source_with_cached_data( | 22915 v8::ScriptCompiler::Source source_with_cached_data( |
21332 source_str, origin, | 22916 source_str, origin, |
21333 new v8::ScriptCompiler::CachedData(original_cached_data->data, | 22917 new v8::ScriptCompiler::CachedData(original_cached_data->data, |
21334 original_cached_data->length)); | 22918 original_cached_data->length)); |
21335 v8::Handle<v8::Script> script = | 22919 v8::Local<v8::Script> script = |
21336 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, | 22920 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, |
21337 v8::ScriptCompiler::kConsumeParserCache); | 22921 v8::ScriptCompiler::kConsumeParserCache); |
21338 CHECK(!script.IsEmpty()); | 22922 CHECK(!script.IsEmpty()); |
21339 const v8::ScriptCompiler::CachedData* new_cached_data = | 22923 const v8::ScriptCompiler::CachedData* new_cached_data = |
21340 source_with_cached_data.GetCachedData(); | 22924 source_with_cached_data.GetCachedData(); |
21341 CHECK(new_cached_data != NULL); | 22925 CHECK(new_cached_data != NULL); |
21342 CHECK(!new_cached_data->rejected); | 22926 CHECK(!new_cached_data->rejected); |
21343 } | 22927 } |
21344 // Compile an incompatible script with the cached data. The new script doesn't | 22928 // Compile an incompatible script with the cached data. The new script doesn't |
21345 // have the same starting position for the function as the old one, so the old | 22929 // have the same starting position for the function as the old one, so the old |
21346 // cached data will be incompatible with it and will be rejected. | 22930 // cached data will be incompatible with it and will be rejected. |
21347 { | 22931 { |
21348 v8::Local<v8::String> incompatible_source_str = | 22932 v8::Local<v8::String> incompatible_source_str = |
21349 v8_str(" function foo() {}"); | 22933 v8_str(" function foo() {}"); |
21350 v8::ScriptCompiler::Source source_with_cached_data( | 22934 v8::ScriptCompiler::Source source_with_cached_data( |
21351 incompatible_source_str, origin, | 22935 incompatible_source_str, origin, |
21352 new v8::ScriptCompiler::CachedData(original_cached_data->data, | 22936 new v8::ScriptCompiler::CachedData(original_cached_data->data, |
21353 original_cached_data->length)); | 22937 original_cached_data->length)); |
21354 v8::Handle<v8::Script> script = | 22938 v8::Local<v8::Script> script = |
21355 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, | 22939 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, |
21356 v8::ScriptCompiler::kConsumeParserCache); | 22940 v8::ScriptCompiler::kConsumeParserCache); |
21357 CHECK(!script.IsEmpty()); | 22941 CHECK(!script.IsEmpty()); |
21358 const v8::ScriptCompiler::CachedData* new_cached_data = | 22942 const v8::ScriptCompiler::CachedData* new_cached_data = |
21359 source_with_cached_data.GetCachedData(); | 22943 source_with_cached_data.GetCachedData(); |
21360 CHECK(new_cached_data != NULL); | 22944 CHECK(new_cached_data != NULL); |
21361 CHECK(new_cached_data->rejected); | 22945 CHECK(new_cached_data->rejected); |
21362 } | 22946 } |
21363 } | 22947 } |
21364 | 22948 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21413 CHECK_EQ(should_be_neuterable, result->IsNeuterable()); | 22997 CHECK_EQ(should_be_neuterable, result->IsNeuterable()); |
21414 } | 22998 } |
21415 | 22999 |
21416 | 23000 |
21417 TEST(GetPrototypeAccessControl) { | 23001 TEST(GetPrototypeAccessControl) { |
21418 i::FLAG_allow_natives_syntax = true; | 23002 i::FLAG_allow_natives_syntax = true; |
21419 v8::Isolate* isolate = CcTest::isolate(); | 23003 v8::Isolate* isolate = CcTest::isolate(); |
21420 v8::HandleScope handle_scope(isolate); | 23004 v8::HandleScope handle_scope(isolate); |
21421 LocalContext env; | 23005 LocalContext env; |
21422 | 23006 |
21423 v8::Handle<v8::ObjectTemplate> obj_template = | 23007 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
21424 v8::ObjectTemplate::New(isolate); | |
21425 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); | 23008 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); |
21426 | 23009 |
21427 env->Global()->Set(v8_str("prohibited"), obj_template->NewInstance()); | 23010 CHECK(env->Global() |
23011 ->Set(env.local(), v8_str("prohibited"), | |
23012 obj_template->NewInstance(env.local()).ToLocalChecked()) | |
23013 .FromJust()); | |
21428 | 23014 |
21429 CHECK(CompileRun( | 23015 CHECK(CompileRun( |
21430 "function f() { return %_GetPrototype(prohibited); }" | 23016 "function f() { return %_GetPrototype(prohibited); }" |
21431 "%OptimizeFunctionOnNextCall(f);" | 23017 "%OptimizeFunctionOnNextCall(f);" |
21432 "f();")->IsNull()); | 23018 "f();")->IsNull()); |
21433 } | 23019 } |
21434 | 23020 |
21435 | 23021 |
21436 TEST(GetPrototypeHidden) { | 23022 TEST(GetPrototypeHidden) { |
21437 i::FLAG_allow_natives_syntax = true; | 23023 i::FLAG_allow_natives_syntax = true; |
21438 v8::Isolate* isolate = CcTest::isolate(); | 23024 v8::Isolate* isolate = CcTest::isolate(); |
21439 v8::HandleScope handle_scope(isolate); | 23025 v8::HandleScope handle_scope(isolate); |
21440 LocalContext env; | 23026 LocalContext env; |
21441 | 23027 |
21442 Handle<FunctionTemplate> t = FunctionTemplate::New(isolate); | 23028 Local<FunctionTemplate> t = FunctionTemplate::New(isolate); |
21443 t->SetHiddenPrototype(true); | 23029 t->SetHiddenPrototype(true); |
21444 Handle<Object> proto = t->GetFunction()->NewInstance(); | 23030 Local<Object> proto = t->GetFunction(env.local()) |
21445 Handle<Object> object = Object::New(isolate); | 23031 .ToLocalChecked() |
21446 Handle<Object> proto2 = Object::New(isolate); | 23032 ->NewInstance(env.local()) |
23033 .ToLocalChecked(); | |
23034 Local<Object> object = Object::New(isolate); | |
23035 Local<Object> proto2 = Object::New(isolate); | |
21447 object->SetPrototype(proto); | 23036 object->SetPrototype(proto); |
21448 proto->SetPrototype(proto2); | 23037 proto->SetPrototype(proto2); |
21449 | 23038 |
21450 env->Global()->Set(v8_str("object"), object); | 23039 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); |
21451 env->Global()->Set(v8_str("proto"), proto); | 23040 CHECK(env->Global()->Set(env.local(), v8_str("proto"), proto).FromJust()); |
21452 env->Global()->Set(v8_str("proto2"), proto2); | 23041 CHECK(env->Global()->Set(env.local(), v8_str("proto2"), proto2).FromJust()); |
21453 | 23042 |
21454 v8::Handle<v8::Value> result = CompileRun("%_GetPrototype(object)"); | 23043 v8::Local<v8::Value> result = CompileRun("%_GetPrototype(object)"); |
21455 CHECK(result->Equals(proto2)); | 23044 CHECK(result->Equals(proto2)); |
21456 | 23045 |
21457 result = CompileRun( | 23046 result = CompileRun( |
21458 "function f() { return %_GetPrototype(object); }" | 23047 "function f() { return %_GetPrototype(object); }" |
21459 "%OptimizeFunctionOnNextCall(f);" | 23048 "%OptimizeFunctionOnNextCall(f);" |
21460 "f()"); | 23049 "f()"); |
21461 CHECK(result->Equals(proto2)); | 23050 CHECK(result->Equals(proto2)); |
21462 } | 23051 } |
21463 | 23052 |
21464 | 23053 |
21465 TEST(ClassPrototypeCreationContext) { | 23054 TEST(ClassPrototypeCreationContext) { |
21466 v8::Isolate* isolate = CcTest::isolate(); | 23055 v8::Isolate* isolate = CcTest::isolate(); |
21467 v8::HandleScope handle_scope(isolate); | 23056 v8::HandleScope handle_scope(isolate); |
21468 LocalContext env; | 23057 LocalContext env; |
21469 | 23058 |
21470 Handle<Object> result = Handle<Object>::Cast( | 23059 Local<Object> result = Local<Object>::Cast( |
21471 CompileRun("'use strict'; class Example { }; Example.prototype")); | 23060 CompileRun("'use strict'; class Example { }; Example.prototype")); |
21472 CHECK(env.local() == result->CreationContext()); | 23061 CHECK(env.local() == result->CreationContext()); |
21473 } | 23062 } |
21474 | 23063 |
21475 | 23064 |
21476 TEST(SimpleStreamingScriptWithSourceURL) { | 23065 TEST(SimpleStreamingScriptWithSourceURL) { |
21477 const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n", | 23066 const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n", |
21478 "//# sourceURL=bar2.js\n", NULL}; | 23067 "//# sourceURL=bar2.js\n", NULL}; |
21479 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, | 23068 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, |
21480 "bar2.js"); | 23069 "bar2.js"); |
(...skipping 20 matching lines...) Expand all Loading... | |
21501 v8::Isolate* isolate = CcTest::isolate(); | 23090 v8::Isolate* isolate = CcTest::isolate(); |
21502 v8::HandleScope handle_scope(isolate); | 23091 v8::HandleScope handle_scope(isolate); |
21503 const int length = i::String::kMaxLength + 1; | 23092 const int length = i::String::kMaxLength + 1; |
21504 const int buffer_size = length * sizeof(uint16_t); | 23093 const int buffer_size = length * sizeof(uint16_t); |
21505 void* buffer = malloc(buffer_size); | 23094 void* buffer = malloc(buffer_size); |
21506 if (buffer == NULL) return; | 23095 if (buffer == NULL) return; |
21507 memset(buffer, 'A', buffer_size); | 23096 memset(buffer, 'A', buffer_size); |
21508 { | 23097 { |
21509 v8::TryCatch try_catch(isolate); | 23098 v8::TryCatch try_catch(isolate); |
21510 char* data = reinterpret_cast<char*>(buffer); | 23099 char* data = reinterpret_cast<char*>(buffer); |
21511 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, | 23100 CHECK(v8::String::NewFromUtf8(isolate, data, v8::NewStringType::kNormal, |
21512 length).IsEmpty()); | 23101 length) |
23102 .IsEmpty()); | |
21513 CHECK(!try_catch.HasCaught()); | 23103 CHECK(!try_catch.HasCaught()); |
21514 } | 23104 } |
21515 { | 23105 { |
21516 v8::TryCatch try_catch(isolate); | 23106 v8::TryCatch try_catch(isolate); |
21517 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); | 23107 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); |
21518 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, | 23108 CHECK(v8::String::NewFromOneByte(isolate, data, v8::NewStringType::kNormal, |
21519 length).IsEmpty()); | 23109 length) |
23110 .IsEmpty()); | |
21520 CHECK(!try_catch.HasCaught()); | 23111 CHECK(!try_catch.HasCaught()); |
21521 } | 23112 } |
21522 { | 23113 { |
21523 v8::TryCatch try_catch(isolate); | 23114 v8::TryCatch try_catch(isolate); |
21524 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 23115 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
21525 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 23116 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::NewStringType::kNormal, |
21526 length).IsEmpty()); | 23117 length) |
23118 .IsEmpty()); | |
21527 CHECK(!try_catch.HasCaught()); | 23119 CHECK(!try_catch.HasCaught()); |
21528 } | 23120 } |
21529 free(buffer); | 23121 free(buffer); |
21530 } | 23122 } |
21531 | 23123 |
21532 | 23124 |
21533 TEST(SealHandleScope) { | 23125 TEST(SealHandleScope) { |
21534 v8::Isolate* isolate = CcTest::isolate(); | 23126 v8::Isolate* isolate = CcTest::isolate(); |
21535 v8::HandleScope handle_scope(isolate); | 23127 v8::HandleScope handle_scope(isolate); |
21536 LocalContext env; | 23128 LocalContext env; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
21576 Local<v8::Object> accessed_object) { | 23168 Local<v8::Object> accessed_object) { |
21577 access_was_called = true; | 23169 access_was_called = true; |
21578 return false; | 23170 return false; |
21579 } | 23171 } |
21580 | 23172 |
21581 | 23173 |
21582 TEST(StrongModeAccessCheckAllowed) { | 23174 TEST(StrongModeAccessCheckAllowed) { |
21583 i::FLAG_strong_mode = true; | 23175 i::FLAG_strong_mode = true; |
21584 v8::Isolate* isolate = CcTest::isolate(); | 23176 v8::Isolate* isolate = CcTest::isolate(); |
21585 v8::HandleScope handle_scope(isolate); | 23177 v8::HandleScope handle_scope(isolate); |
21586 v8::Handle<Value> value; | 23178 v8::Local<Value> value; |
21587 access_was_called = false; | 23179 access_was_called = false; |
21588 | 23180 |
21589 v8::Handle<v8::ObjectTemplate> obj_template = | 23181 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
21590 v8::ObjectTemplate::New(isolate); | |
21591 | 23182 |
21592 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 23183 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
21593 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag); | 23184 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag); |
21594 | 23185 |
21595 // Create an environment | 23186 // Create an environment |
21596 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 23187 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
21597 context0->Enter(); | 23188 context0->Enter(); |
21598 v8::Handle<v8::Object> global0 = context0->Global(); | 23189 v8::Local<v8::Object> global0 = context0->Global(); |
21599 global0->Set(v8_str("object"), obj_template->NewInstance()); | 23190 global0->Set(v8_str("object"), |
23191 obj_template->NewInstance(context0).ToLocalChecked()); | |
21600 { | 23192 { |
21601 v8::TryCatch try_catch(isolate); | 23193 v8::TryCatch try_catch(isolate); |
21602 value = CompileRun("'use strong'; object.x"); | 23194 value = CompileRun("'use strong'; object.x"); |
21603 CHECK(!try_catch.HasCaught()); | 23195 CHECK(!try_catch.HasCaught()); |
21604 CHECK(!access_was_called); | 23196 CHECK(!access_was_called); |
21605 CHECK_EQ(42, value->Int32Value()); | 23197 CHECK_EQ(42, value->Int32Value(context0).FromJust()); |
21606 } | 23198 } |
21607 { | 23199 { |
21608 v8::TryCatch try_catch(isolate); | 23200 v8::TryCatch try_catch(isolate); |
21609 value = CompileRun("'use strong'; object.foo"); | 23201 value = CompileRun("'use strong'; object.foo"); |
21610 CHECK(try_catch.HasCaught()); | 23202 CHECK(try_catch.HasCaught()); |
21611 CHECK(!access_was_called); | 23203 CHECK(!access_was_called); |
21612 } | 23204 } |
21613 { | 23205 { |
21614 v8::TryCatch try_catch(isolate); | 23206 v8::TryCatch try_catch(isolate); |
21615 value = CompileRun("'use strong'; object[10]"); | 23207 value = CompileRun("'use strong'; object[10]"); |
21616 CHECK(try_catch.HasCaught()); | 23208 CHECK(try_catch.HasCaught()); |
21617 CHECK(!access_was_called); | 23209 CHECK(!access_was_called); |
21618 } | 23210 } |
21619 | 23211 |
21620 // Create an environment | 23212 // Create an environment |
21621 v8::Local<Context> context1 = Context::New(isolate); | 23213 v8::Local<Context> context1 = Context::New(isolate); |
21622 context1->Enter(); | 23214 context1->Enter(); |
21623 v8::Handle<v8::Object> global1 = context1->Global(); | 23215 v8::Local<v8::Object> global1 = context1->Global(); |
21624 global1->Set(v8_str("object"), obj_template->NewInstance()); | 23216 global1->Set(v8_str("object"), |
23217 obj_template->NewInstance(context1).ToLocalChecked()); | |
21625 { | 23218 { |
21626 v8::TryCatch try_catch(isolate); | 23219 v8::TryCatch try_catch(isolate); |
21627 value = CompileRun("'use strong'; object.x"); | 23220 value = CompileRun("'use strong'; object.x"); |
21628 CHECK(!try_catch.HasCaught()); | 23221 CHECK(!try_catch.HasCaught()); |
21629 CHECK(access_was_called); | 23222 CHECK(access_was_called); |
21630 CHECK_EQ(42, value->Int32Value()); | 23223 CHECK_EQ(42, value->Int32Value(context1).FromJust()); |
21631 } | 23224 } |
21632 access_was_called = false; | 23225 access_was_called = false; |
21633 { | 23226 { |
21634 v8::TryCatch try_catch(isolate); | 23227 v8::TryCatch try_catch(isolate); |
21635 value = CompileRun("'use strong'; object.foo"); | 23228 value = CompileRun("'use strong'; object.foo"); |
21636 CHECK(try_catch.HasCaught()); | 23229 CHECK(try_catch.HasCaught()); |
21637 CHECK(access_was_called); | 23230 CHECK(access_was_called); |
21638 } | 23231 } |
21639 access_was_called = false; | 23232 access_was_called = false; |
21640 { | 23233 { |
21641 v8::TryCatch try_catch(isolate); | 23234 v8::TryCatch try_catch(isolate); |
21642 value = CompileRun("'use strong'; object[10]"); | 23235 value = CompileRun("'use strong'; object[10]"); |
21643 CHECK(try_catch.HasCaught()); | 23236 CHECK(try_catch.HasCaught()); |
21644 CHECK(access_was_called); | 23237 CHECK(access_was_called); |
21645 } | 23238 } |
21646 | 23239 |
21647 context1->Exit(); | 23240 context1->Exit(); |
21648 context0->Exit(); | 23241 context0->Exit(); |
21649 } | 23242 } |
21650 | 23243 |
21651 | 23244 |
21652 TEST(StrongModeAccessCheckBlocked) { | 23245 TEST(StrongModeAccessCheckBlocked) { |
21653 i::FLAG_strong_mode = true; | 23246 i::FLAG_strong_mode = true; |
21654 v8::Isolate* isolate = CcTest::isolate(); | 23247 v8::Isolate* isolate = CcTest::isolate(); |
21655 v8::HandleScope handle_scope(isolate); | 23248 v8::HandleScope handle_scope(isolate); |
21656 v8::Handle<Value> value; | 23249 v8::Local<Value> value; |
21657 access_was_called = false; | 23250 access_was_called = false; |
21658 | 23251 |
21659 v8::Handle<v8::ObjectTemplate> obj_template = | 23252 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate); |
21660 v8::ObjectTemplate::New(isolate); | |
21661 | 23253 |
21662 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); | 23254 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); |
21663 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag); | 23255 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag); |
21664 | 23256 |
21665 // Create an environment | 23257 // Create an environment |
21666 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); | 23258 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); |
21667 context0->Enter(); | 23259 context0->Enter(); |
21668 v8::Handle<v8::Object> global0 = context0->Global(); | 23260 v8::Local<v8::Object> global0 = context0->Global(); |
21669 global0->Set(v8_str("object"), obj_template->NewInstance()); | 23261 global0->Set(v8_str("object"), |
23262 obj_template->NewInstance(context0).ToLocalChecked()); | |
21670 { | 23263 { |
21671 v8::TryCatch try_catch(isolate); | 23264 v8::TryCatch try_catch(isolate); |
21672 value = CompileRun("'use strong'; object.x"); | 23265 value = CompileRun("'use strong'; object.x"); |
21673 CHECK(!try_catch.HasCaught()); | 23266 CHECK(!try_catch.HasCaught()); |
21674 CHECK(!access_was_called); | 23267 CHECK(!access_was_called); |
21675 CHECK_EQ(42, value->Int32Value()); | 23268 CHECK_EQ(42, value->Int32Value(context0).FromJust()); |
21676 } | 23269 } |
21677 { | 23270 { |
21678 v8::TryCatch try_catch(isolate); | 23271 v8::TryCatch try_catch(isolate); |
21679 value = CompileRun("'use strong'; object.foo"); | 23272 value = CompileRun("'use strong'; object.foo"); |
21680 CHECK(try_catch.HasCaught()); | 23273 CHECK(try_catch.HasCaught()); |
21681 CHECK(!access_was_called); | 23274 CHECK(!access_was_called); |
21682 } | 23275 } |
21683 { | 23276 { |
21684 v8::TryCatch try_catch(isolate); | 23277 v8::TryCatch try_catch(isolate); |
21685 value = CompileRun("'use strong'; object[10]"); | 23278 value = CompileRun("'use strong'; object[10]"); |
21686 CHECK(try_catch.HasCaught()); | 23279 CHECK(try_catch.HasCaught()); |
21687 CHECK(!access_was_called); | 23280 CHECK(!access_was_called); |
21688 } | 23281 } |
21689 | 23282 |
21690 // Create an environment | 23283 // Create an environment |
21691 v8::Local<Context> context1 = Context::New(isolate); | 23284 v8::Local<Context> context1 = Context::New(isolate); |
21692 context1->Enter(); | 23285 context1->Enter(); |
21693 v8::Handle<v8::Object> global1 = context1->Global(); | 23286 v8::Local<v8::Object> global1 = context1->Global(); |
21694 global1->Set(v8_str("object"), obj_template->NewInstance()); | 23287 global1->Set(v8_str("object"), |
23288 obj_template->NewInstance(context1).ToLocalChecked()); | |
21695 { | 23289 { |
21696 v8::TryCatch try_catch(isolate); | 23290 v8::TryCatch try_catch(isolate); |
21697 value = CompileRun("'use strong'; object.x"); | 23291 value = CompileRun("'use strong'; object.x"); |
21698 CHECK(try_catch.HasCaught()); | 23292 CHECK(try_catch.HasCaught()); |
21699 CHECK(access_was_called); | 23293 CHECK(access_was_called); |
21700 } | 23294 } |
21701 access_was_called = false; | 23295 access_was_called = false; |
21702 { | 23296 { |
21703 v8::TryCatch try_catch(isolate); | 23297 v8::TryCatch try_catch(isolate); |
21704 value = CompileRun("'use strong'; object.foo"); | 23298 value = CompileRun("'use strong'; object.foo"); |
(...skipping 29 matching lines...) Expand all Loading... | |
21734 } | 23328 } |
21735 | 23329 |
21736 { | 23330 { |
21737 v8::TryCatch try_catch(isolate); | 23331 v8::TryCatch try_catch(isolate); |
21738 fun->Call(v8::Undefined(isolate), 0, nullptr); | 23332 fun->Call(v8::Undefined(isolate), 0, nullptr); |
21739 CHECK(try_catch.HasCaught()); | 23333 CHECK(try_catch.HasCaught()); |
21740 } | 23334 } |
21741 | 23335 |
21742 { | 23336 { |
21743 v8::TryCatch try_catch(isolate); | 23337 v8::TryCatch try_catch(isolate); |
21744 v8::Handle<Value> args[] = {v8_num(42)}; | 23338 v8::Local<Value> args[] = {v8_num(42)}; |
21745 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23339 fun->Call(v8::Undefined(isolate), arraysize(args), args); |
21746 CHECK(!try_catch.HasCaught()); | 23340 CHECK(!try_catch.HasCaught()); |
21747 } | 23341 } |
21748 | 23342 |
21749 { | 23343 { |
21750 v8::TryCatch try_catch(isolate); | 23344 v8::TryCatch try_catch(isolate); |
21751 v8::Handle<Value> args[] = {v8_num(42), v8_num(555)}; | 23345 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; |
21752 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23346 fun->Call(v8::Undefined(isolate), arraysize(args), args); |
21753 CHECK(!try_catch.HasCaught()); | 23347 CHECK(!try_catch.HasCaught()); |
21754 } | 23348 } |
21755 } | 23349 } |
21756 | 23350 |
21757 | 23351 |
21758 TEST(StrongModeArityCallFromApi2) { | 23352 TEST(StrongModeArityCallFromApi2) { |
21759 i::FLAG_strong_mode = true; | 23353 i::FLAG_strong_mode = true; |
21760 LocalContext env; | 23354 LocalContext env; |
21761 v8::Isolate* isolate = env->GetIsolate(); | 23355 v8::Isolate* isolate = env->GetIsolate(); |
(...skipping 10 matching lines...) Expand all Loading... | |
21772 } | 23366 } |
21773 | 23367 |
21774 { | 23368 { |
21775 v8::TryCatch try_catch(isolate); | 23369 v8::TryCatch try_catch(isolate); |
21776 fun->Call(v8::Undefined(isolate), 0, nullptr); | 23370 fun->Call(v8::Undefined(isolate), 0, nullptr); |
21777 CHECK(try_catch.HasCaught()); | 23371 CHECK(try_catch.HasCaught()); |
21778 } | 23372 } |
21779 | 23373 |
21780 { | 23374 { |
21781 v8::TryCatch try_catch(isolate); | 23375 v8::TryCatch try_catch(isolate); |
21782 v8::Handle<Value> args[] = {v8_num(42)}; | 23376 v8::Local<Value> args[] = {v8_num(42)}; |
21783 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23377 fun->Call(v8::Undefined(isolate), arraysize(args), args); |
21784 CHECK(!try_catch.HasCaught()); | 23378 CHECK(!try_catch.HasCaught()); |
21785 } | 23379 } |
21786 | 23380 |
21787 { | 23381 { |
21788 v8::TryCatch try_catch(isolate); | 23382 v8::TryCatch try_catch(isolate); |
21789 v8::Handle<Value> args[] = {v8_num(42), v8_num(555)}; | 23383 v8::Local<Value> args[] = {v8_num(42), v8_num(555)}; |
21790 fun->Call(v8::Undefined(isolate), arraysize(args), args); | 23384 fun->Call(v8::Undefined(isolate), arraysize(args), args); |
21791 CHECK(!try_catch.HasCaught()); | 23385 CHECK(!try_catch.HasCaught()); |
21792 } | 23386 } |
21793 } | 23387 } |
21794 | 23388 |
21795 | 23389 |
21796 TEST(StrongObjectDelete) { | 23390 TEST(StrongObjectDelete) { |
21797 i::FLAG_strong_mode = true; | 23391 i::FLAG_strong_mode = true; |
21798 LocalContext env; | 23392 LocalContext env; |
21799 v8::Isolate* isolate = env->GetIsolate(); | 23393 v8::Isolate* isolate = env->GetIsolate(); |
(...skipping 10 matching lines...) Expand all Loading... | |
21810 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); | 23404 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); |
21811 CHECK(obj->HasOwnProperty(v8_str("foo"))); | 23405 CHECK(obj->HasOwnProperty(v8_str("foo"))); |
21812 CHECK(obj->HasOwnProperty(v8_str("2"))); | 23406 CHECK(obj->HasOwnProperty(v8_str("2"))); |
21813 CHECK(!obj->Delete(v8_str("foo"))); | 23407 CHECK(!obj->Delete(v8_str("foo"))); |
21814 CHECK(!obj->Delete(2)); | 23408 CHECK(!obj->Delete(2)); |
21815 } | 23409 } |
21816 | 23410 |
21817 | 23411 |
21818 static void ExtrasBindingTestRuntimeFunction( | 23412 static void ExtrasBindingTestRuntimeFunction( |
21819 const v8::FunctionCallbackInfo<v8::Value>& args) { | 23413 const v8::FunctionCallbackInfo<v8::Value>& args) { |
21820 CHECK_EQ(3, args[0]->Int32Value()); | 23414 CHECK_EQ( |
23415 3, | |
23416 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust()); | |
21821 args.GetReturnValue().Set(v8_num(7)); | 23417 args.GetReturnValue().Set(v8_num(7)); |
21822 } | 23418 } |
21823 | 23419 |
21824 | 23420 |
21825 TEST(ExtrasBindingObject) { | 23421 TEST(ExtrasBindingObject) { |
21826 v8::Isolate* isolate = CcTest::isolate(); | 23422 v8::Isolate* isolate = CcTest::isolate(); |
21827 v8::HandleScope handle_scope(isolate); | 23423 v8::HandleScope handle_scope(isolate); |
21828 LocalContext env; | 23424 LocalContext env; |
21829 | 23425 |
21830 // standalone.gypi ensures we include the test-extra.js file, which should | 23426 // standalone.gypi ensures we include the test-extra.js file, which should |
21831 // export the tested functions. | 23427 // export the tested functions. |
21832 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23428 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
21833 | 23429 |
21834 auto func = | 23430 auto func = |
21835 binding->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); | 23431 binding->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); |
21836 auto undefined = v8::Undefined(isolate); | 23432 auto undefined = v8::Undefined(isolate); |
21837 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23433 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); |
21838 CHECK_EQ(5, result->Int32Value()); | 23434 CHECK_EQ(5, result->Int32Value(env.local()).FromJust()); |
21839 | 23435 |
21840 v8::Handle<v8::FunctionTemplate> runtimeFunction = | 23436 v8::Local<v8::FunctionTemplate> runtimeFunction = |
21841 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); | 23437 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); |
21842 binding->Set(v8_str("runtime"), runtimeFunction->GetFunction()); | 23438 binding->Set(v8_str("runtime"), |
23439 runtimeFunction->GetFunction(env.local()).ToLocalChecked()); | |
21843 func = | 23440 func = |
21844 binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>(); | 23441 binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>(); |
21845 result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23442 result = func->Call(undefined, 0, {}).As<v8::Number>(); |
21846 CHECK_EQ(7, result->Int32Value()); | 23443 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); |
21847 } | 23444 } |
21848 | 23445 |
21849 | 23446 |
21850 TEST(ExperimentalExtras) { | 23447 TEST(ExperimentalExtras) { |
21851 i::FLAG_experimental_extras = true; | 23448 i::FLAG_experimental_extras = true; |
21852 | 23449 |
21853 v8::Isolate* isolate = CcTest::isolate(); | 23450 v8::Isolate* isolate = CcTest::isolate(); |
21854 v8::HandleScope handle_scope(isolate); | 23451 v8::HandleScope handle_scope(isolate); |
21855 LocalContext env; | 23452 LocalContext env; |
21856 | 23453 |
21857 // standalone.gypi ensures we include the test-experimental-extra.js file, | 23454 // standalone.gypi ensures we include the test-experimental-extra.js file, |
21858 // which should export the tested functions. | 23455 // which should export the tested functions. |
21859 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23456 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
21860 | 23457 |
21861 auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen")) | 23458 auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen")) |
21862 .As<v8::Function>(); | 23459 .As<v8::Function>(); |
21863 auto undefined = v8::Undefined(isolate); | 23460 auto undefined = v8::Undefined(isolate); |
21864 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23461 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); |
21865 CHECK_EQ(10, result->Int32Value()); | 23462 CHECK_EQ(10, result->Int32Value(env.local()).FromJust()); |
21866 | 23463 |
21867 v8::Handle<v8::FunctionTemplate> runtimeFunction = | 23464 v8::Local<v8::FunctionTemplate> runtimeFunction = |
21868 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); | 23465 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); |
21869 binding->Set(v8_str("runtime"), runtimeFunction->GetFunction()); | 23466 binding->Set(v8_str("runtime"), |
23467 runtimeFunction->GetFunction(env.local()).ToLocalChecked()); | |
21870 func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime")) | 23468 func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime")) |
21871 .As<v8::Function>(); | 23469 .As<v8::Function>(); |
21872 result = func->Call(undefined, 0, {}).As<v8::Number>(); | 23470 result = func->Call(undefined, 0, {}).As<v8::Number>(); |
21873 CHECK_EQ(7, result->Int32Value()); | 23471 CHECK_EQ(7, result->Int32Value(env.local()).FromJust()); |
21874 } | 23472 } |
21875 | 23473 |
21876 | 23474 |
21877 TEST(ExtrasUtilsObject) { | 23475 TEST(ExtrasUtilsObject) { |
21878 LocalContext context; | 23476 LocalContext context; |
21879 v8::Isolate* isolate = context->GetIsolate(); | 23477 v8::Isolate* isolate = context->GetIsolate(); |
21880 v8::HandleScope handle_scope(isolate); | 23478 v8::HandleScope handle_scope(isolate); |
21881 | 23479 |
21882 LocalContext env; | 23480 LocalContext env; |
21883 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); | 23481 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); |
21884 | 23482 |
21885 auto func = binding->Get(v8_str("testExtraCanUseUtils")).As<v8::Function>(); | 23483 auto func = binding->Get(v8_str("testExtraCanUseUtils")).As<v8::Function>(); |
21886 auto undefined = v8::Undefined(isolate); | 23484 auto undefined = v8::Undefined(isolate); |
21887 auto result = func->Call(undefined, 0, {}).As<v8::Object>(); | 23485 auto result = func->Call(undefined, 0, {}).As<v8::Object>(); |
21888 | 23486 |
21889 auto private_symbol = result->Get(v8_str("privateSymbol")).As<v8::Symbol>(); | 23487 auto private_symbol = result->Get(v8_str("privateSymbol")).As<v8::Symbol>(); |
21890 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol); | 23488 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol); |
21891 CHECK_EQ(true, ips->IsPrivate()); | 23489 CHECK_EQ(true, ips->IsPrivate()); |
21892 | 23490 |
21893 CompileRun("var result = 0; function store(x) { result = x; }"); | 23491 CompileRun("var result = 0; function store(x) { result = x; }"); |
21894 auto store = CompileRun("store").As<v8::Function>(); | 23492 auto store = CompileRun("store").As<v8::Function>(); |
21895 | 23493 |
21896 auto fulfilled_promise = | 23494 auto fulfilled_promise = |
21897 result->Get(v8_str("fulfilledPromise")).As<v8::Promise>(); | 23495 result->Get(v8_str("fulfilledPromise")).As<v8::Promise>(); |
21898 fulfilled_promise->Then(store); | 23496 fulfilled_promise->Then(store); |
21899 isolate->RunMicrotasks(); | 23497 isolate->RunMicrotasks(); |
21900 CHECK_EQ(1, CompileRun("result")->Int32Value()); | 23498 CHECK_EQ(1, CompileRun("result")->Int32Value(env.local()).FromJust()); |
21901 | 23499 |
21902 auto fulfilled_promise_2 = | 23500 auto fulfilled_promise_2 = |
21903 result->Get(v8_str("fulfilledPromise2")).As<v8::Promise>(); | 23501 result->Get(v8_str("fulfilledPromise2")).As<v8::Promise>(); |
21904 fulfilled_promise_2->Then(store); | 23502 fulfilled_promise_2->Then(store); |
21905 isolate->RunMicrotasks(); | 23503 isolate->RunMicrotasks(); |
21906 CHECK_EQ(2, CompileRun("result")->Int32Value()); | 23504 CHECK_EQ(2, CompileRun("result")->Int32Value(env.local()).FromJust()); |
21907 | 23505 |
21908 auto rejected_promise = | 23506 auto rejected_promise = |
21909 result->Get(v8_str("rejectedPromise")).As<v8::Promise>(); | 23507 result->Get(v8_str("rejectedPromise")).As<v8::Promise>(); |
21910 rejected_promise->Catch(store); | 23508 rejected_promise->Catch(store); |
21911 isolate->RunMicrotasks(); | 23509 isolate->RunMicrotasks(); |
21912 CHECK_EQ(3, CompileRun("result")->Int32Value()); | 23510 CHECK_EQ(3, CompileRun("result")->Int32Value(env.local()).FromJust()); |
21913 } | 23511 } |
21914 | 23512 |
21915 | 23513 |
21916 TEST(Map) { | 23514 TEST(Map) { |
21917 v8::Isolate* isolate = CcTest::isolate(); | 23515 v8::Isolate* isolate = CcTest::isolate(); |
21918 v8::HandleScope handle_scope(isolate); | 23516 v8::HandleScope handle_scope(isolate); |
21919 LocalContext env; | 23517 LocalContext env; |
21920 | 23518 |
21921 v8::Local<v8::Map> map = v8::Map::New(isolate); | 23519 v8::Local<v8::Map> map = v8::Map::New(isolate); |
21922 CHECK(map->IsObject()); | 23520 CHECK(map->IsObject()); |
(...skipping 16 matching lines...) Expand all Loading... | |
21939 CHECK_EQ(2U, map->Size()); | 23537 CHECK_EQ(2U, map->Size()); |
21940 | 23538 |
21941 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); | 23539 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); |
21942 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); | 23540 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); |
21943 | 23541 |
21944 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); | 23542 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); |
21945 CHECK(!map->Has(env.local(), map).FromJust()); | 23543 CHECK(!map->Has(env.local(), map).FromJust()); |
21946 | 23544 |
21947 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) | 23545 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) |
21948 .ToLocalChecked() | 23546 .ToLocalChecked() |
21949 ->Int32Value()); | 23547 ->Int32Value(env.local()) |
23548 .FromJust()); | |
21950 CHECK_EQ(4, map->Get(env.local(), v8::Integer::New(isolate, 3)) | 23549 CHECK_EQ(4, map->Get(env.local(), v8::Integer::New(isolate, 3)) |
21951 .ToLocalChecked() | 23550 .ToLocalChecked() |
21952 ->Int32Value()); | 23551 ->Int32Value(env.local()) |
23552 .FromJust()); | |
21953 | 23553 |
21954 CHECK(map->Get(env.local(), v8::Integer::New(isolate, 42)) | 23554 CHECK(map->Get(env.local(), v8::Integer::New(isolate, 42)) |
21955 .ToLocalChecked() | 23555 .ToLocalChecked() |
21956 ->IsUndefined()); | 23556 ->IsUndefined()); |
21957 | 23557 |
21958 CHECK(!map->Set(env.local(), map, map).IsEmpty()); | 23558 CHECK(!map->Set(env.local(), map, map).IsEmpty()); |
21959 CHECK_EQ(3U, map->Size()); | 23559 CHECK_EQ(3U, map->Size()); |
21960 CHECK(map->Has(env.local(), map).FromJust()); | 23560 CHECK(map->Has(env.local(), map).FromJust()); |
21961 | 23561 |
21962 CHECK(map->Delete(env.local(), map).FromJust()); | 23562 CHECK(map->Delete(env.local(), map).FromJust()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22016 v8::Isolate* isolate = CcTest::isolate(); | 23616 v8::Isolate* isolate = CcTest::isolate(); |
22017 v8::HandleScope scope(isolate); | 23617 v8::HandleScope scope(isolate); |
22018 v8::Local<v8::FunctionTemplate> parent = FunctionTemplate::New(isolate); | 23618 v8::Local<v8::FunctionTemplate> parent = FunctionTemplate::New(isolate); |
22019 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, parent); | 23619 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, parent); |
22020 auto returns_42 = | 23620 auto returns_42 = |
22021 v8::FunctionTemplate::New(isolate, Returns42, Local<Value>(), signature); | 23621 v8::FunctionTemplate::New(isolate, Returns42, Local<Value>(), signature); |
22022 parent->PrototypeTemplate()->SetAccessorProperty(v8_str("age"), returns_42); | 23622 parent->PrototypeTemplate()->SetAccessorProperty(v8_str("age"), returns_42); |
22023 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate); | 23623 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate); |
22024 child->Inherit(parent); | 23624 child->Inherit(parent); |
22025 LocalContext env; | 23625 LocalContext env; |
22026 env->Global()->Set(v8_str("Child"), child->GetFunction()); | 23626 CHECK(env->Global() |
23627 ->Set(env.local(), v8_str("Child"), | |
23628 child->GetFunction(env.local()).ToLocalChecked()) | |
23629 .FromJust()); | |
22027 | 23630 |
22028 // Make sure there's a compiled stub for "Child.prototype.age" in the cache. | 23631 // Make sure there's a compiled stub for "Child.prototype.age" in the cache. |
22029 CompileRun( | 23632 CompileRun( |
22030 "var real = new Child();\n" | 23633 "var real = new Child();\n" |
22031 "for (var i = 0; i < 3; ++i) {\n" | 23634 "for (var i = 0; i < 3; ++i) {\n" |
22032 " real.age;\n" | 23635 " real.age;\n" |
22033 "}\n"); | 23636 "}\n"); |
22034 | 23637 |
22035 // Check that the cached stub is never used. | 23638 // Check that the cached stub is never used. |
22036 ExpectInt32( | 23639 ExpectInt32( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22099 | 23702 |
22100 bool NoAbortOnUncaughtException(v8::Isolate* isolate) { | 23703 bool NoAbortOnUncaughtException(v8::Isolate* isolate) { |
22101 ++nb_uncaught_exception_callback_calls; | 23704 ++nb_uncaught_exception_callback_calls; |
22102 return false; | 23705 return false; |
22103 } | 23706 } |
22104 | 23707 |
22105 | 23708 |
22106 TEST(AbortOnUncaughtExceptionNoAbort) { | 23709 TEST(AbortOnUncaughtExceptionNoAbort) { |
22107 v8::Isolate* isolate = CcTest::isolate(); | 23710 v8::Isolate* isolate = CcTest::isolate(); |
22108 v8::HandleScope handle_scope(isolate); | 23711 v8::HandleScope handle_scope(isolate); |
22109 v8::Handle<v8::ObjectTemplate> global_template = | 23712 v8::Local<v8::ObjectTemplate> global_template = |
22110 v8::ObjectTemplate::New(isolate); | 23713 v8::ObjectTemplate::New(isolate); |
22111 LocalContext env(NULL, global_template); | 23714 LocalContext env(NULL, global_template); |
22112 | 23715 |
22113 i::FLAG_abort_on_uncaught_exception = true; | 23716 i::FLAG_abort_on_uncaught_exception = true; |
22114 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException); | 23717 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException); |
22115 | 23718 |
22116 CompileRun("function boom() { throw new Error(\"boom\") }"); | 23719 CompileRun("function boom() { throw new Error(\"boom\") }"); |
22117 | 23720 |
22118 v8::Local<v8::Object> global_object = env->Global(); | 23721 v8::Local<v8::Object> global_object = env->Global(); |
22119 v8::Local<v8::Function> foo = | 23722 v8::Local<v8::Function> foo = |
22120 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("boom"))); | 23723 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("boom"))); |
22121 | 23724 |
22122 foo->Call(global_object, 0, NULL); | 23725 foo->Call(global_object, 0, NULL); |
22123 | 23726 |
22124 CHECK_EQ(1, nb_uncaught_exception_callback_calls); | 23727 CHECK_EQ(1, nb_uncaught_exception_callback_calls); |
22125 } | 23728 } |
22126 | 23729 |
22127 | 23730 |
22128 TEST(AccessCheckedIsConcatSpreadable) { | 23731 TEST(AccessCheckedIsConcatSpreadable) { |
22129 i::FLAG_harmony_concat_spreadable = true; | 23732 i::FLAG_harmony_concat_spreadable = true; |
22130 v8::Isolate* isolate = CcTest::isolate(); | 23733 v8::Isolate* isolate = CcTest::isolate(); |
22131 HandleScope scope(isolate); | 23734 HandleScope scope(isolate); |
22132 LocalContext env; | 23735 LocalContext env; |
22133 | 23736 |
22134 // Object with access check | 23737 // Object with access check |
22135 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate); | 23738 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate); |
22136 spreadable_template->SetAccessCheckCallback(AccessBlocker); | 23739 spreadable_template->SetAccessCheckCallback(AccessBlocker); |
22137 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate), | 23740 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate), |
22138 v8::Boolean::New(isolate, true)); | 23741 v8::Boolean::New(isolate, true)); |
22139 Local<Object> object = spreadable_template->NewInstance(); | 23742 Local<Object> object = |
23743 spreadable_template->NewInstance(env.local()).ToLocalChecked(); | |
22140 | 23744 |
22141 allowed_access = true; | 23745 allowed_access = true; |
22142 env->Global()->Set(v8_str("object"), object); | 23746 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust()); |
22143 object->Set(v8_str("length"), v8_num(2)); | 23747 object->Set(v8_str("length"), v8_num(2)); |
22144 object->Set(0U, v8_str("a")); | 23748 object->Set(0U, v8_str("a")); |
22145 object->Set(1U, v8_str("b")); | 23749 object->Set(1U, v8_str("b")); |
22146 | 23750 |
22147 // Access check is allowed, and the object is spread | 23751 // Access check is allowed, and the object is spread |
22148 CompileRun("var result = [].concat(object)"); | 23752 CompileRun("var result = [].concat(object)"); |
22149 ExpectTrue("Array.isArray(result)"); | 23753 ExpectTrue("Array.isArray(result)"); |
22150 ExpectString("result[0]", "a"); | 23754 ExpectString("result[0]", "a"); |
22151 ExpectString("result[1]", "b"); | 23755 ExpectString("result[1]", "b"); |
22152 ExpectTrue("result.length === 2"); | 23756 ExpectTrue("result.length === 2"); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
22201 | 23805 |
22202 | 23806 |
22203 TEST(ObjectTemplateIntrinsics) { | 23807 TEST(ObjectTemplateIntrinsics) { |
22204 v8::Isolate* isolate = CcTest::isolate(); | 23808 v8::Isolate* isolate = CcTest::isolate(); |
22205 v8::HandleScope scope(isolate); | 23809 v8::HandleScope scope(isolate); |
22206 LocalContext env; | 23810 LocalContext env; |
22207 | 23811 |
22208 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); | 23812 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); |
22209 object_template->SetIntrinsicDataProperty(v8_str("values"), | 23813 object_template->SetIntrinsicDataProperty(v8_str("values"), |
22210 v8::kArrayProto_values); | 23814 v8::kArrayProto_values); |
22211 Local<Object> object = object_template->NewInstance(); | 23815 Local<Object> object = |
23816 object_template->NewInstance(env.local()).ToLocalChecked(); | |
22212 | 23817 |
22213 env->Global()->Set(v8_str("obj1"), object); | 23818 CHECK(env->Global()->Set(env.local(), v8_str("obj1"), object).FromJust()); |
22214 ExpectString("typeof obj1.values", "function"); | 23819 ExpectString("typeof obj1.values", "function"); |
22215 | 23820 |
22216 auto values = Local<Function>::Cast(object->Get(v8_str("values"))); | 23821 auto values = Local<Function>::Cast(object->Get(v8_str("values"))); |
22217 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values)); | 23822 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values)); |
22218 auto ctx = v8::Utils::OpenHandle(*env.local()); | 23823 auto ctx = v8::Utils::OpenHandle(*env.local()); |
22219 CHECK_EQ(fn->GetCreationContext(), *ctx); | 23824 CHECK_EQ(fn->GetCreationContext(), *ctx); |
22220 | 23825 |
22221 { | 23826 { |
22222 LocalContext env2; | 23827 LocalContext env2; |
22223 Local<Object> object2 = object_template->NewInstance(); | 23828 Local<Object> object2 = |
22224 env2->Global()->Set(v8_str("obj2"), object2); | 23829 object_template->NewInstance(env2.local()).ToLocalChecked(); |
23830 CHECK( | |
23831 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust()); | |
22225 ExpectString("typeof obj2.values", "function"); | 23832 ExpectString("typeof obj2.values", "function"); |
22226 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); | 23833 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); |
22227 | 23834 |
22228 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); | 23835 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); |
22229 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); | 23836 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); |
22230 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); | 23837 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); |
22231 CHECK_EQ(fn2->GetCreationContext(), *ctx2); | 23838 CHECK_EQ(fn2->GetCreationContext(), *ctx2); |
22232 } | 23839 } |
22233 } | 23840 } |
OLD | NEW |