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

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

Issue 1427643005: Remove usage of deprecated APIs from test-api.cc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Lines 1-10k, plus some tidbits beyond that. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // TODO(jochen): Remove this after the setting is turned on globally.
29 // #define V8_IMMINENT_DEPRECATION_WARNINGS
30
28 #include <climits> 31 #include <climits>
29 #include <csignal> 32 #include <csignal>
30 #include <map> 33 #include <map>
31 #include <string> 34 #include <string>
32 35
33 #include "test/cctest/test-api.h" 36 #include "test/cctest/test-api.h"
34 37
35 #if V8_OS_POSIX 38 #if V8_OS_POSIX
36 #include <unistd.h> // NOLINT 39 #include <unistd.h> // NOLINT
37 #endif 40 #endif
(...skipping 15 matching lines...) Expand all
53 #include "test/cctest/heap-tester.h" 56 #include "test/cctest/heap-tester.h"
54 57
55 static const bool kLogThreading = false; 58 static const bool kLogThreading = false;
56 59
57 using ::v8::Boolean; 60 using ::v8::Boolean;
58 using ::v8::BooleanObject; 61 using ::v8::BooleanObject;
59 using ::v8::Context; 62 using ::v8::Context;
60 using ::v8::Extension; 63 using ::v8::Extension;
61 using ::v8::Function; 64 using ::v8::Function;
62 using ::v8::FunctionTemplate; 65 using ::v8::FunctionTemplate;
63 using ::v8::Handle;
64 using ::v8::HandleScope; 66 using ::v8::HandleScope;
65 using ::v8::Local; 67 using ::v8::Local;
66 using ::v8::Maybe; 68 using ::v8::Maybe;
67 using ::v8::Message; 69 using ::v8::Message;
68 using ::v8::MessageCallback; 70 using ::v8::MessageCallback;
69 using ::v8::Name; 71 using ::v8::Name;
70 using ::v8::None; 72 using ::v8::None;
71 using ::v8::Object; 73 using ::v8::Object;
72 using ::v8::ObjectTemplate; 74 using ::v8::ObjectTemplate;
73 using ::v8::Persistent; 75 using ::v8::Persistent;
(...skipping 10 matching lines...) Expand all
84 86
85 87
86 #define THREADED_PROFILED_TEST(Name) \ 88 #define THREADED_PROFILED_TEST(Name) \
87 static void Test##Name(); \ 89 static void Test##Name(); \
88 TEST(Name##WithProfiler) { \ 90 TEST(Name##WithProfiler) { \
89 RunWithProfiler(&Test##Name); \ 91 RunWithProfiler(&Test##Name); \
90 } \ 92 } \
91 THREADED_TEST(Name) 93 THREADED_TEST(Name)
92 94
93 95
96 // TODO(vogelheim): move tocctest
94 void RunWithProfiler(void (*test)()) { 97 void RunWithProfiler(void (*test)()) {
95 LocalContext env; 98 LocalContext env;
96 v8::HandleScope scope(env->GetIsolate()); 99 v8::HandleScope scope(env->GetIsolate());
97 v8::Local<v8::String> profile_name = 100 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(); 101 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
100 102
101 cpu_profiler->StartProfiling(profile_name); 103 cpu_profiler->StartProfiling(profile_name);
102 (*test)(); 104 (*test)();
103 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles(); 105 reinterpret_cast<i::CpuProfiler*>(cpu_profiler)->DeleteAllProfiles();
104 } 106 }
105 107
106 108
107 static int signature_callback_count; 109 static int signature_callback_count;
108 static Local<Value> signature_expected_receiver; 110 static Local<Value> signature_expected_receiver;
109 static void IncrementingSignatureCallback( 111 static void IncrementingSignatureCallback(
110 const v8::FunctionCallbackInfo<v8::Value>& args) { 112 const v8::FunctionCallbackInfo<v8::Value>& args) {
111 ApiTestFuzzer::Fuzz(); 113 ApiTestFuzzer::Fuzz();
112 signature_callback_count++; 114 signature_callback_count++;
113 CHECK(signature_expected_receiver->Equals(args.Holder())); 115 CHECK(signature_expected_receiver->Equals(
114 CHECK(signature_expected_receiver->Equals(args.This())); 116 args.GetIsolate()->GetCurrentContext(),
115 v8::Handle<v8::Array> result = 117 args.Holder())
118 .FromJust());
119 CHECK(signature_expected_receiver->Equals(
120 args.GetIsolate()->GetCurrentContext(),
121 args.This())
122 .FromJust());
123 v8::Local<v8::Array> result =
116 v8::Array::New(args.GetIsolate(), args.Length()); 124 v8::Array::New(args.GetIsolate(), args.Length());
117 for (int i = 0; i < args.Length(); i++) 125 for (int i = 0; i < args.Length(); i++) {
118 result->Set(v8::Integer::New(args.GetIsolate(), i), args[i]); 126 CHECK(result->Set(args.GetIsolate()->GetCurrentContext(),
127 v8::Integer::New(args.GetIsolate(), i), args[i])
128 .FromJust());
129 }
119 args.GetReturnValue().Set(result); 130 args.GetReturnValue().Set(result);
120 } 131 }
121 132
122 133
123 static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) { 134 static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) {
124 info.GetReturnValue().Set(42); 135 info.GetReturnValue().Set(42);
125 } 136 }
126 137
127 138
128 // Tests that call v8::V8::Dispose() cannot be threaded. 139 // Tests that call v8::V8::Dispose() cannot be threaded.
(...skipping 18 matching lines...) Expand all
147 Local<Context> local_env; 158 Local<Context> local_env;
148 { 159 {
149 LocalContext env; 160 LocalContext env;
150 local_env = env.local(); 161 local_env = env.local();
151 } 162 }
152 163
153 // Local context should still be live. 164 // Local context should still be live.
154 CHECK(!local_env.IsEmpty()); 165 CHECK(!local_env.IsEmpty());
155 local_env->Enter(); 166 local_env->Enter();
156 167
157 v8::Handle<v8::Primitive> undef = v8::Undefined(CcTest::isolate()); 168 v8::Local<v8::Primitive> undef = v8::Undefined(CcTest::isolate());
158 CHECK(!undef.IsEmpty()); 169 CHECK(!undef.IsEmpty());
159 CHECK(undef->IsUndefined()); 170 CHECK(undef->IsUndefined());
160 171
161 const char* source = "1 + 2 + 3"; 172 const char* source = "1 + 2 + 3";
162 Local<Script> script = v8_compile(source); 173 Local<Script> script = v8_compile(source);
163 CHECK_EQ(6, script->Run()->Int32Value()); 174 CHECK_EQ(6, v8_run_int32value(script));
164 175
165 local_env->Exit(); 176 local_env->Exit();
166 } 177 }
167 178
168 179
169 THREADED_TEST(IsolateOfContext) { 180 THREADED_TEST(IsolateOfContext) {
170 v8::HandleScope scope(CcTest::isolate()); 181 v8::HandleScope scope(CcTest::isolate());
171 v8::Handle<Context> env = Context::New(CcTest::isolate()); 182 v8::Local<Context> env = Context::New(CcTest::isolate());
172 183
173 CHECK(!env->GetIsolate()->InContext()); 184 CHECK(!env->GetIsolate()->InContext());
174 CHECK(env->GetIsolate() == CcTest::isolate()); 185 CHECK(env->GetIsolate() == CcTest::isolate());
175 env->Enter(); 186 env->Enter();
176 CHECK(env->GetIsolate()->InContext()); 187 CHECK(env->GetIsolate()->InContext());
177 CHECK(env->GetIsolate() == CcTest::isolate()); 188 CHECK(env->GetIsolate() == CcTest::isolate());
178 env->Exit(); 189 env->Exit();
179 CHECK(!env->GetIsolate()->InContext()); 190 CHECK(!env->GetIsolate()->InContext());
180 CHECK(env->GetIsolate() == CcTest::isolate()); 191 CHECK(env->GetIsolate() == CcTest::isolate());
181 } 192 }
(...skipping 10 matching lines...) Expand all
192 signature_callback_count = 0; 203 signature_callback_count = 0;
193 signature_expected_receiver = receiver; 204 signature_expected_receiver = receiver;
194 bool expected_to_throw = receiver.IsEmpty(); 205 bool expected_to_throw = receiver.IsEmpty();
195 v8::TryCatch try_catch(isolate); 206 v8::TryCatch try_catch(isolate);
196 CompileRun(source.start()); 207 CompileRun(source.start());
197 CHECK_EQ(expected_to_throw, try_catch.HasCaught()); 208 CHECK_EQ(expected_to_throw, try_catch.HasCaught());
198 if (!expected_to_throw) { 209 if (!expected_to_throw) {
199 CHECK_EQ(10, signature_callback_count); 210 CHECK_EQ(10, signature_callback_count);
200 } else { 211 } else {
201 CHECK(v8_str("TypeError: Illegal invocation") 212 CHECK(v8_str("TypeError: Illegal invocation")
202 ->Equals(try_catch.Exception()->ToString(isolate))); 213 ->Equals(isolate->GetCurrentContext(),
214 try_catch.Exception()
215 ->ToString(isolate->GetCurrentContext())
216 .ToLocalChecked())
217 .FromJust());
203 } 218 }
204 } 219 }
205 220
206 221
207 THREADED_TEST(ReceiverSignature) { 222 THREADED_TEST(ReceiverSignature) {
208 LocalContext env; 223 LocalContext env;
209 v8::Isolate* isolate = env->GetIsolate(); 224 v8::Isolate* isolate = env->GetIsolate();
210 v8::HandleScope scope(isolate); 225 v8::HandleScope scope(isolate);
211 // Setup templates. 226 // Setup templates.
212 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 227 v8::Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
213 v8::Handle<v8::Signature> sig = v8::Signature::New(isolate, fun); 228 v8::Local<v8::Signature> sig = v8::Signature::New(isolate, fun);
214 v8::Handle<v8::FunctionTemplate> callback_sig = 229 v8::Local<v8::FunctionTemplate> callback_sig = v8::FunctionTemplate::New(
215 v8::FunctionTemplate::New( 230 isolate, IncrementingSignatureCallback, Local<Value>(), sig);
216 isolate, IncrementingSignatureCallback, Local<Value>(), sig); 231 v8::Local<v8::FunctionTemplate> callback =
217 v8::Handle<v8::FunctionTemplate> callback =
218 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback); 232 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback);
219 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate); 233 v8::Local<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate);
220 sub_fun->Inherit(fun); 234 sub_fun->Inherit(fun);
221 v8::Handle<v8::FunctionTemplate> unrel_fun = 235 v8::Local<v8::FunctionTemplate> unrel_fun =
222 v8::FunctionTemplate::New(isolate); 236 v8::FunctionTemplate::New(isolate);
223 // Install properties. 237 // Install properties.
224 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); 238 v8::Local<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate();
225 fun_proto->Set(v8_str("prop_sig"), callback_sig); 239 fun_proto->Set(v8_str("prop_sig"), callback_sig);
226 fun_proto->Set(v8_str("prop"), callback); 240 fun_proto->Set(v8_str("prop"), callback);
227 fun_proto->SetAccessorProperty( 241 fun_proto->SetAccessorProperty(
228 v8_str("accessor_sig"), callback_sig, callback_sig); 242 v8_str("accessor_sig"), callback_sig, callback_sig);
229 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); 243 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback);
230 // Instantiate templates. 244 // Instantiate templates.
231 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); 245 Local<Value> fun_instance =
232 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance(); 246 fun->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked();
247 Local<Value> sub_fun_instance =
248 sub_fun->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked();
233 // Setup global variables. 249 // Setup global variables.
234 env->Global()->Set(v8_str("Fun"), fun->GetFunction()); 250 CHECK(env->Global()
235 env->Global()->Set(v8_str("UnrelFun"), unrel_fun->GetFunction()); 251 ->Set(env.local(), v8_str("Fun"),
236 env->Global()->Set(v8_str("fun_instance"), fun_instance); 252 fun->GetFunction(env.local()).ToLocalChecked())
237 env->Global()->Set(v8_str("sub_fun_instance"), sub_fun_instance); 253 .FromJust());
254 CHECK(env->Global()
255 ->Set(env.local(), v8_str("UnrelFun"),
256 unrel_fun->GetFunction(env.local()).ToLocalChecked())
257 .FromJust());
258 CHECK(env->Global()
259 ->Set(env.local(), v8_str("fun_instance"), fun_instance)
260 .FromJust());
261 CHECK(env->Global()
262 ->Set(env.local(), v8_str("sub_fun_instance"), sub_fun_instance)
263 .FromJust());
238 CompileRun( 264 CompileRun(
239 "var accessor_sig_key = 'accessor_sig';" 265 "var accessor_sig_key = 'accessor_sig';"
240 "var accessor_key = 'accessor';" 266 "var accessor_key = 'accessor';"
241 "var prop_sig_key = 'prop_sig';" 267 "var prop_sig_key = 'prop_sig';"
242 "var prop_key = 'prop';" 268 "var prop_key = 'prop';"
243 "" 269 ""
244 "function copy_props(obj) {" 270 "function copy_props(obj) {"
245 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];" 271 " var keys = [accessor_sig_key, accessor_key, prop_sig_key, prop_key];"
246 " var source = Fun.prototype;" 272 " var source = Fun.prototype;"
247 " for (var i in keys) {" 273 " for (var i in keys) {"
(...skipping 28 matching lines...) Expand all
276 TestSignature("test_object.accessor_sig = 1;", test_object, isolate); 302 TestSignature("test_object.accessor_sig = 1;", test_object, isolate);
277 TestSignature("test_object[accessor_sig_key] = 1;", test_object, isolate); 303 TestSignature("test_object[accessor_sig_key] = 1;", test_object, isolate);
278 } 304 }
279 } 305 }
280 306
281 307
282 THREADED_TEST(HulIgennem) { 308 THREADED_TEST(HulIgennem) {
283 LocalContext env; 309 LocalContext env;
284 v8::Isolate* isolate = env->GetIsolate(); 310 v8::Isolate* isolate = env->GetIsolate();
285 v8::HandleScope scope(isolate); 311 v8::HandleScope scope(isolate);
286 v8::Handle<v8::Primitive> undef = v8::Undefined(isolate); 312 v8::Local<v8::Primitive> undef = v8::Undefined(isolate);
287 Local<String> undef_str = undef->ToString(isolate); 313 Local<String> undef_str = undef->ToString(env.local()).ToLocalChecked();
288 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1); 314 char* value = i::NewArray<char>(undef_str->Utf8Length() + 1);
289 undef_str->WriteUtf8(value); 315 undef_str->WriteUtf8(value);
290 CHECK_EQ(0, strcmp(value, "undefined")); 316 CHECK_EQ(0, strcmp(value, "undefined"));
291 i::DeleteArray(value); 317 i::DeleteArray(value);
292 } 318 }
293 319
294 320
295 THREADED_TEST(Access) { 321 THREADED_TEST(Access) {
296 LocalContext env; 322 LocalContext env;
297 v8::Isolate* isolate = env->GetIsolate(); 323 v8::Isolate* isolate = env->GetIsolate();
298 v8::HandleScope scope(isolate); 324 v8::HandleScope scope(isolate);
299 Local<v8::Object> obj = v8::Object::New(isolate); 325 Local<v8::Object> obj = v8::Object::New(isolate);
300 Local<Value> foo_before = obj->Get(v8_str("foo")); 326 Local<Value> foo_before =
327 obj->Get(env.local(), v8_str("foo")).ToLocalChecked();
301 CHECK(foo_before->IsUndefined()); 328 CHECK(foo_before->IsUndefined());
302 Local<String> bar_str = v8_str("bar"); 329 Local<String> bar_str = v8_str("bar");
303 obj->Set(v8_str("foo"), bar_str); 330 CHECK(obj->Set(env.local(), v8_str("foo"), bar_str).FromJust());
304 Local<Value> foo_after = obj->Get(v8_str("foo")); 331 Local<Value> foo_after =
332 obj->Get(env.local(), v8_str("foo")).ToLocalChecked();
305 CHECK(!foo_after->IsUndefined()); 333 CHECK(!foo_after->IsUndefined());
306 CHECK(foo_after->IsString()); 334 CHECK(foo_after->IsString());
307 CHECK(bar_str->Equals(foo_after)); 335 CHECK(bar_str->Equals(env.local(), foo_after).FromJust());
308 } 336 }
309 337
310 338
311 THREADED_TEST(AccessElement) { 339 THREADED_TEST(AccessElement) {
312 LocalContext env; 340 LocalContext env;
313 v8::HandleScope scope(env->GetIsolate()); 341 v8::HandleScope scope(env->GetIsolate());
314 Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 342 Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
315 Local<Value> before = obj->Get(1); 343 Local<Value> before = obj->Get(env.local(), 1).ToLocalChecked();
316 CHECK(before->IsUndefined()); 344 CHECK(before->IsUndefined());
317 Local<String> bar_str = v8_str("bar"); 345 Local<String> bar_str = v8_str("bar");
318 obj->Set(1, bar_str); 346 CHECK(obj->Set(env.local(), 1, bar_str).FromJust());
319 Local<Value> after = obj->Get(1); 347 Local<Value> after = obj->Get(env.local(), 1).ToLocalChecked();
320 CHECK(!after->IsUndefined()); 348 CHECK(!after->IsUndefined());
321 CHECK(after->IsString()); 349 CHECK(after->IsString());
322 CHECK(bar_str->Equals(after)); 350 CHECK(bar_str->Equals(env.local(), after).FromJust());
323 351
324 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>(); 352 Local<v8::Array> value = CompileRun("[\"a\", \"b\"]").As<v8::Array>();
325 CHECK(v8_str("a")->Equals(value->Get(0))); 353 CHECK(v8_str("a")
326 CHECK(v8_str("b")->Equals(value->Get(1))); 354 ->Equals(env.local(), value->Get(env.local(), 0).ToLocalChecked())
355 .FromJust());
356 CHECK(v8_str("b")
357 ->Equals(env.local(), value->Get(env.local(), 1).ToLocalChecked())
358 .FromJust());
327 } 359 }
328 360
329 361
330 THREADED_TEST(Script) { 362 THREADED_TEST(Script) {
331 LocalContext env; 363 LocalContext env;
332 v8::HandleScope scope(env->GetIsolate()); 364 v8::HandleScope scope(env->GetIsolate());
333 const char* source = "1 + 2 + 3"; 365 const char* source = "1 + 2 + 3";
334 Local<Script> script = v8_compile(source); 366 Local<Script> script = v8_compile(source);
335 CHECK_EQ(6, script->Run()->Int32Value()); 367 CHECK_EQ(6, v8_run_int32value(script));
336 } 368 }
337 369
338 370
339 class TestResource: public String::ExternalStringResource { 371 class TestResource: public String::ExternalStringResource {
340 public: 372 public:
341 explicit TestResource(uint16_t* data, int* counter = NULL, 373 explicit TestResource(uint16_t* data, int* counter = NULL,
342 bool owning_data = true) 374 bool owning_data = true)
343 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) { 375 : data_(data), length_(0), counter_(counter), owning_data_(owning_data) {
344 while (data[length_]) ++length_; 376 while (data[length_]) ++length_;
345 } 377 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 428
397 429
398 THREADED_TEST(ScriptUsingStringResource) { 430 THREADED_TEST(ScriptUsingStringResource) {
399 int dispose_count = 0; 431 int dispose_count = 0;
400 const char* c_source = "1 + 2 * 3"; 432 const char* c_source = "1 + 2 * 3";
401 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 433 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
402 { 434 {
403 LocalContext env; 435 LocalContext env;
404 v8::HandleScope scope(env->GetIsolate()); 436 v8::HandleScope scope(env->GetIsolate());
405 TestResource* resource = new TestResource(two_byte_source, &dispose_count); 437 TestResource* resource = new TestResource(two_byte_source, &dispose_count);
406 Local<String> source = String::NewExternal(env->GetIsolate(), resource); 438 Local<String> source =
439 String::NewExternalTwoByte(env->GetIsolate(), resource)
440 .ToLocalChecked();
407 Local<Script> script = v8_compile(source); 441 Local<Script> script = v8_compile(source);
408 Local<Value> value = script->Run(); 442 Local<Value> value = script->Run(env.local()).ToLocalChecked();
409 CHECK(value->IsNumber()); 443 CHECK(value->IsNumber());
410 CHECK_EQ(7, value->Int32Value()); 444 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
411 CHECK(source->IsExternal()); 445 CHECK(source->IsExternal());
412 CHECK_EQ(resource, 446 CHECK_EQ(resource,
413 static_cast<TestResource*>(source->GetExternalStringResource())); 447 static_cast<TestResource*>(source->GetExternalStringResource()));
414 String::Encoding encoding = String::UNKNOWN_ENCODING; 448 String::Encoding encoding = String::UNKNOWN_ENCODING;
415 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 449 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
416 source->GetExternalStringResourceBase(&encoding)); 450 source->GetExternalStringResourceBase(&encoding));
417 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding); 451 CHECK_EQ(String::TWO_BYTE_ENCODING, encoding);
418 CcTest::heap()->CollectAllGarbage(); 452 CcTest::heap()->CollectAllGarbage();
419 CHECK_EQ(0, dispose_count); 453 CHECK_EQ(0, dispose_count);
420 } 454 }
421 CcTest::i_isolate()->compilation_cache()->Clear(); 455 CcTest::i_isolate()->compilation_cache()->Clear();
422 CcTest::heap()->CollectAllAvailableGarbage(); 456 CcTest::heap()->CollectAllAvailableGarbage();
423 CHECK_EQ(1, dispose_count); 457 CHECK_EQ(1, dispose_count);
424 } 458 }
425 459
426 460
427 THREADED_TEST(ScriptUsingOneByteStringResource) { 461 THREADED_TEST(ScriptUsingOneByteStringResource) {
428 int dispose_count = 0; 462 int dispose_count = 0;
429 const char* c_source = "1 + 2 * 3"; 463 const char* c_source = "1 + 2 * 3";
430 { 464 {
431 LocalContext env; 465 LocalContext env;
432 v8::HandleScope scope(env->GetIsolate()); 466 v8::HandleScope scope(env->GetIsolate());
433 TestOneByteResource* resource = 467 TestOneByteResource* resource =
434 new TestOneByteResource(i::StrDup(c_source), &dispose_count); 468 new TestOneByteResource(i::StrDup(c_source), &dispose_count);
435 Local<String> source = String::NewExternal(env->GetIsolate(), resource); 469 Local<String> source =
470 String::NewExternalOneByte(env->GetIsolate(), resource)
471 .ToLocalChecked();
436 CHECK(source->IsExternalOneByte()); 472 CHECK(source->IsExternalOneByte());
437 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 473 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
438 source->GetExternalOneByteStringResource()); 474 source->GetExternalOneByteStringResource());
439 String::Encoding encoding = String::UNKNOWN_ENCODING; 475 String::Encoding encoding = String::UNKNOWN_ENCODING;
440 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource), 476 CHECK_EQ(static_cast<const String::ExternalStringResourceBase*>(resource),
441 source->GetExternalStringResourceBase(&encoding)); 477 source->GetExternalStringResourceBase(&encoding));
442 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); 478 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding);
443 Local<Script> script = v8_compile(source); 479 Local<Script> script = v8_compile(source);
444 Local<Value> value = script->Run(); 480 Local<Value> value = script->Run(env.local()).ToLocalChecked();
445 CHECK(value->IsNumber()); 481 CHECK(value->IsNumber());
446 CHECK_EQ(7, value->Int32Value()); 482 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
447 CcTest::heap()->CollectAllGarbage(); 483 CcTest::heap()->CollectAllGarbage();
448 CHECK_EQ(0, dispose_count); 484 CHECK_EQ(0, dispose_count);
449 } 485 }
450 CcTest::i_isolate()->compilation_cache()->Clear(); 486 CcTest::i_isolate()->compilation_cache()->Clear();
451 CcTest::heap()->CollectAllAvailableGarbage(); 487 CcTest::heap()->CollectAllAvailableGarbage();
452 CHECK_EQ(1, dispose_count); 488 CHECK_EQ(1, dispose_count);
453 } 489 }
454 490
455 491
456 THREADED_TEST(ScriptMakingExternalString) { 492 THREADED_TEST(ScriptMakingExternalString) {
457 int dispose_count = 0; 493 int dispose_count = 0;
458 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); 494 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3");
459 { 495 {
460 LocalContext env; 496 LocalContext env;
461 v8::HandleScope scope(env->GetIsolate()); 497 v8::HandleScope scope(env->GetIsolate());
462 Local<String> source = 498 Local<String> source =
463 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 499 String::NewFromTwoByte(env->GetIsolate(), two_byte_source,
500 v8::NewStringType::kNormal)
501 .ToLocalChecked();
464 // Trigger GCs so that the newly allocated string moves to old gen. 502 // Trigger GCs so that the newly allocated string moves to old gen.
465 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 503 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
466 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 504 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
467 CHECK_EQ(source->IsExternal(), false); 505 CHECK_EQ(source->IsExternal(), false);
468 CHECK_EQ(source->IsExternalOneByte(), false); 506 CHECK_EQ(source->IsExternalOneByte(), false);
469 String::Encoding encoding = String::UNKNOWN_ENCODING; 507 String::Encoding encoding = String::UNKNOWN_ENCODING;
470 CHECK(!source->GetExternalStringResourceBase(&encoding)); 508 CHECK(!source->GetExternalStringResourceBase(&encoding));
471 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding); 509 CHECK_EQ(String::ONE_BYTE_ENCODING, encoding);
472 bool success = source->MakeExternal(new TestResource(two_byte_source, 510 bool success = source->MakeExternal(new TestResource(two_byte_source,
473 &dispose_count)); 511 &dispose_count));
474 CHECK(success); 512 CHECK(success);
475 Local<Script> script = v8_compile(source); 513 Local<Script> script = v8_compile(source);
476 Local<Value> value = script->Run(); 514 Local<Value> value = script->Run(env.local()).ToLocalChecked();
477 CHECK(value->IsNumber()); 515 CHECK(value->IsNumber());
478 CHECK_EQ(7, value->Int32Value()); 516 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
479 CcTest::heap()->CollectAllGarbage(); 517 CcTest::heap()->CollectAllGarbage();
480 CHECK_EQ(0, dispose_count); 518 CHECK_EQ(0, dispose_count);
481 } 519 }
482 CcTest::i_isolate()->compilation_cache()->Clear(); 520 CcTest::i_isolate()->compilation_cache()->Clear();
483 CcTest::heap()->CollectAllGarbage(); 521 CcTest::heap()->CollectAllGarbage();
484 CHECK_EQ(1, dispose_count); 522 CHECK_EQ(1, dispose_count);
485 } 523 }
486 524
487 525
488 THREADED_TEST(ScriptMakingExternalOneByteString) { 526 THREADED_TEST(ScriptMakingExternalOneByteString) {
489 int dispose_count = 0; 527 int dispose_count = 0;
490 const char* c_source = "1 + 2 * 3"; 528 const char* c_source = "1 + 2 * 3";
491 { 529 {
492 LocalContext env; 530 LocalContext env;
493 v8::HandleScope scope(env->GetIsolate()); 531 v8::HandleScope scope(env->GetIsolate());
494 Local<String> source = v8_str(c_source); 532 Local<String> source = v8_str(c_source);
495 // Trigger GCs so that the newly allocated string moves to old gen. 533 // Trigger GCs so that the newly allocated string moves to old gen.
496 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 534 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
497 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 535 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
498 bool success = source->MakeExternal( 536 bool success = source->MakeExternal(
499 new TestOneByteResource(i::StrDup(c_source), &dispose_count)); 537 new TestOneByteResource(i::StrDup(c_source), &dispose_count));
500 CHECK(success); 538 CHECK(success);
501 Local<Script> script = v8_compile(source); 539 Local<Script> script = v8_compile(source);
502 Local<Value> value = script->Run(); 540 Local<Value> value = script->Run(env.local()).ToLocalChecked();
503 CHECK(value->IsNumber()); 541 CHECK(value->IsNumber());
504 CHECK_EQ(7, value->Int32Value()); 542 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
505 CcTest::heap()->CollectAllGarbage(); 543 CcTest::heap()->CollectAllGarbage();
506 CHECK_EQ(0, dispose_count); 544 CHECK_EQ(0, dispose_count);
507 } 545 }
508 CcTest::i_isolate()->compilation_cache()->Clear(); 546 CcTest::i_isolate()->compilation_cache()->Clear();
509 CcTest::heap()->CollectAllGarbage(); 547 CcTest::heap()->CollectAllGarbage();
510 CHECK_EQ(1, dispose_count); 548 CHECK_EQ(1, dispose_count);
511 } 549 }
512 550
513 551
514 TEST(MakingExternalStringConditions) { 552 TEST(MakingExternalStringConditions) {
515 LocalContext env; 553 LocalContext env;
516 v8::HandleScope scope(env->GetIsolate()); 554 v8::HandleScope scope(env->GetIsolate());
517 555
518 // Free some space in the new space so that we can check freshness. 556 // Free some space in the new space so that we can check freshness.
519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 557 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
520 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 558 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
521 559
522 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); 560 uint16_t* two_byte_string = AsciiToTwoByteString("s1");
523 Local<String> small_string = 561 Local<String> small_string =
524 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); 562 String::NewFromTwoByte(env->GetIsolate(), two_byte_string,
563 v8::NewStringType::kNormal)
564 .ToLocalChecked();
525 i::DeleteArray(two_byte_string); 565 i::DeleteArray(two_byte_string);
526 566
527 // We should refuse to externalize small strings. 567 // We should refuse to externalize small strings.
528 CHECK(!small_string->CanMakeExternal()); 568 CHECK(!small_string->CanMakeExternal());
529 // Trigger GCs so that the newly allocated string moves to old gen. 569 // Trigger GCs so that the newly allocated string moves to old gen.
530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 570 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
531 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 571 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
532 // Old space strings should be accepted. 572 // Old space strings should be accepted.
533 CHECK(small_string->CanMakeExternal()); 573 CHECK(small_string->CanMakeExternal());
534 574
535 two_byte_string = AsciiToTwoByteString("small string 2"); 575 two_byte_string = AsciiToTwoByteString("small string 2");
536 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string); 576 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string,
577 v8::NewStringType::kNormal)
578 .ToLocalChecked();
537 i::DeleteArray(two_byte_string); 579 i::DeleteArray(two_byte_string);
538 580
539 const int buf_size = 10 * 1024; 581 const int buf_size = 10 * 1024;
540 char* buf = i::NewArray<char>(buf_size); 582 char* buf = i::NewArray<char>(buf_size);
541 memset(buf, 'a', buf_size); 583 memset(buf, 'a', buf_size);
542 buf[buf_size - 1] = '\0'; 584 buf[buf_size - 1] = '\0';
543 585
544 two_byte_string = AsciiToTwoByteString(buf); 586 two_byte_string = AsciiToTwoByteString(buf);
545 Local<String> large_string = 587 Local<String> large_string =
546 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); 588 String::NewFromTwoByte(env->GetIsolate(), two_byte_string,
589 v8::NewStringType::kNormal)
590 .ToLocalChecked();
547 i::DeleteArray(buf); 591 i::DeleteArray(buf);
548 i::DeleteArray(two_byte_string); 592 i::DeleteArray(two_byte_string);
549 // Large strings should be immediately accepted. 593 // Large strings should be immediately accepted.
550 CHECK(large_string->CanMakeExternal()); 594 CHECK(large_string->CanMakeExternal());
551 } 595 }
552 596
553 597
554 TEST(MakingExternalOneByteStringConditions) { 598 TEST(MakingExternalOneByteStringConditions) {
555 LocalContext env; 599 LocalContext env;
556 v8::HandleScope scope(env->GetIsolate()); 600 v8::HandleScope scope(env->GetIsolate());
557 601
558 // Free some space in the new space so that we can check freshness. 602 // Free some space in the new space so that we can check freshness.
559 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 603 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
560 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 604 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
561 605
562 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); 606 Local<String> small_string = v8_str("s1");
563 // We should refuse to externalize small strings. 607 // We should refuse to externalize small strings.
564 CHECK(!small_string->CanMakeExternal()); 608 CHECK(!small_string->CanMakeExternal());
565 // Trigger GCs so that the newly allocated string moves to old gen. 609 // Trigger GCs so that the newly allocated string moves to old gen.
566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 610 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 611 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
568 // Old space strings should be accepted. 612 // Old space strings should be accepted.
569 CHECK(small_string->CanMakeExternal()); 613 CHECK(small_string->CanMakeExternal());
570 614
571 const int buf_size = 10 * 1024; 615 const int buf_size = 10 * 1024;
572 char* buf = i::NewArray<char>(buf_size); 616 char* buf = i::NewArray<char>(buf_size);
573 memset(buf, 'a', buf_size); 617 memset(buf, 'a', buf_size);
574 buf[buf_size - 1] = '\0'; 618 buf[buf_size - 1] = '\0';
575 Local<String> large_string = String::NewFromUtf8(env->GetIsolate(), buf); 619 Local<String> large_string = v8_str(buf);
576 i::DeleteArray(buf); 620 i::DeleteArray(buf);
577 // Large strings should be immediately accepted. 621 // Large strings should be immediately accepted.
578 CHECK(large_string->CanMakeExternal()); 622 CHECK(large_string->CanMakeExternal());
579 } 623 }
580 624
581 625
582 TEST(MakingExternalUnalignedOneByteString) { 626 TEST(MakingExternalUnalignedOneByteString) {
583 LocalContext env; 627 LocalContext env;
584 v8::HandleScope scope(env->GetIsolate()); 628 v8::HandleScope scope(env->GetIsolate());
585 629
(...skipping 25 matching lines...) Expand all
611 CcTest::heap()->CollectAllGarbage(); 655 CcTest::heap()->CollectAllGarbage();
612 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); 656 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask);
613 } 657 }
614 658
615 659
616 THREADED_TEST(UsingExternalString) { 660 THREADED_TEST(UsingExternalString) {
617 i::Factory* factory = CcTest::i_isolate()->factory(); 661 i::Factory* factory = CcTest::i_isolate()->factory();
618 { 662 {
619 v8::HandleScope scope(CcTest::isolate()); 663 v8::HandleScope scope(CcTest::isolate());
620 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 664 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
621 Local<String> string = String::NewExternal( 665 Local<String> string =
622 CcTest::isolate(), new TestResource(two_byte_string)); 666 String::NewExternalTwoByte(CcTest::isolate(),
667 new TestResource(two_byte_string))
668 .ToLocalChecked();
623 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 669 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
624 // Trigger GCs so that the newly allocated string moves to old gen. 670 // Trigger GCs so that the newly allocated string moves to old gen.
625 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 671 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
626 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 672 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
627 i::Handle<i::String> isymbol = 673 i::Handle<i::String> isymbol =
628 factory->InternalizeString(istring); 674 factory->InternalizeString(istring);
629 CHECK(isymbol->IsInternalizedString()); 675 CHECK(isymbol->IsInternalizedString());
630 } 676 }
631 CcTest::heap()->CollectAllGarbage(); 677 CcTest::heap()->CollectAllGarbage();
632 CcTest::heap()->CollectAllGarbage(); 678 CcTest::heap()->CollectAllGarbage();
633 } 679 }
634 680
635 681
636 THREADED_TEST(UsingExternalOneByteString) { 682 THREADED_TEST(UsingExternalOneByteString) {
637 i::Factory* factory = CcTest::i_isolate()->factory(); 683 i::Factory* factory = CcTest::i_isolate()->factory();
638 { 684 {
639 v8::HandleScope scope(CcTest::isolate()); 685 v8::HandleScope scope(CcTest::isolate());
640 const char* one_byte_string = "test string"; 686 const char* one_byte_string = "test string";
641 Local<String> string = String::NewExternal( 687 Local<String> string =
642 CcTest::isolate(), new TestOneByteResource(i::StrDup(one_byte_string))); 688 String::NewExternalOneByte(
689 CcTest::isolate(),
690 new TestOneByteResource(i::StrDup(one_byte_string)))
691 .ToLocalChecked();
643 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 692 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
644 // Trigger GCs so that the newly allocated string moves to old gen. 693 // Trigger GCs so that the newly allocated string moves to old gen.
645 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 694 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
646 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 695 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
647 i::Handle<i::String> isymbol = 696 i::Handle<i::String> isymbol =
648 factory->InternalizeString(istring); 697 factory->InternalizeString(istring);
649 CHECK(isymbol->IsInternalizedString()); 698 CHECK(isymbol->IsInternalizedString());
650 } 699 }
651 CcTest::heap()->CollectAllGarbage(); 700 CcTest::heap()->CollectAllGarbage();
652 CcTest::heap()->CollectAllGarbage(); 701 CcTest::heap()->CollectAllGarbage();
(...skipping 24 matching lines...) Expand all
677 int length_; 726 int length_;
678 }; 727 };
679 728
680 729
681 THREADED_TEST(NewExternalForVeryLongString) { 730 THREADED_TEST(NewExternalForVeryLongString) {
682 auto isolate = CcTest::isolate(); 731 auto isolate = CcTest::isolate();
683 { 732 {
684 v8::HandleScope scope(isolate); 733 v8::HandleScope scope(isolate);
685 v8::TryCatch try_catch(isolate); 734 v8::TryCatch try_catch(isolate);
686 RandomLengthOneByteResource r(1 << 30); 735 RandomLengthOneByteResource r(1 << 30);
687 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); 736 v8::MaybeLocal<v8::String> maybe_str =
688 CHECK(str.IsEmpty()); 737 v8::String::NewExternalOneByte(isolate, &r);
738 CHECK(maybe_str.IsEmpty());
689 CHECK(!try_catch.HasCaught()); 739 CHECK(!try_catch.HasCaught());
690 } 740 }
691 741
692 { 742 {
693 v8::HandleScope scope(isolate); 743 v8::HandleScope scope(isolate);
694 v8::TryCatch try_catch(isolate); 744 v8::TryCatch try_catch(isolate);
695 RandomLengthResource r(1 << 30); 745 RandomLengthResource r(1 << 30);
696 v8::Local<v8::String> str = v8::String::NewExternal(isolate, &r); 746 v8::MaybeLocal<v8::String> maybe_str =
697 CHECK(str.IsEmpty()); 747 v8::String::NewExternalTwoByte(isolate, &r);
748 CHECK(maybe_str.IsEmpty());
698 CHECK(!try_catch.HasCaught()); 749 CHECK(!try_catch.HasCaught());
699 } 750 }
700 } 751 }
701 752
702 753
703 THREADED_TEST(ScavengeExternalString) { 754 THREADED_TEST(ScavengeExternalString) {
704 i::FLAG_stress_compaction = false; 755 i::FLAG_stress_compaction = false;
705 i::FLAG_gc_global = false; 756 i::FLAG_gc_global = false;
706 int dispose_count = 0; 757 int dispose_count = 0;
707 bool in_new_space = false; 758 bool in_new_space = false;
708 { 759 {
709 v8::HandleScope scope(CcTest::isolate()); 760 v8::HandleScope scope(CcTest::isolate());
710 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); 761 uint16_t* two_byte_string = AsciiToTwoByteString("test string");
711 Local<String> string = String::NewExternal( 762 Local<String> string =
712 CcTest::isolate(), new TestResource(two_byte_string, &dispose_count)); 763 String::NewExternalTwoByte(
764 CcTest::isolate(),
765 new TestResource(two_byte_string, &dispose_count))
766 .ToLocalChecked();
713 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 767 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
714 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 768 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
715 in_new_space = CcTest::heap()->InNewSpace(*istring); 769 in_new_space = CcTest::heap()->InNewSpace(*istring);
716 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); 770 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring));
717 CHECK_EQ(0, dispose_count); 771 CHECK_EQ(0, dispose_count);
718 } 772 }
719 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); 773 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE);
720 CHECK_EQ(1, dispose_count); 774 CHECK_EQ(1, dispose_count);
721 } 775 }
722 776
723 777
724 THREADED_TEST(ScavengeExternalOneByteString) { 778 THREADED_TEST(ScavengeExternalOneByteString) {
725 i::FLAG_stress_compaction = false; 779 i::FLAG_stress_compaction = false;
726 i::FLAG_gc_global = false; 780 i::FLAG_gc_global = false;
727 int dispose_count = 0; 781 int dispose_count = 0;
728 bool in_new_space = false; 782 bool in_new_space = false;
729 { 783 {
730 v8::HandleScope scope(CcTest::isolate()); 784 v8::HandleScope scope(CcTest::isolate());
731 const char* one_byte_string = "test string"; 785 const char* one_byte_string = "test string";
732 Local<String> string = String::NewExternal( 786 Local<String> string =
733 CcTest::isolate(), 787 String::NewExternalOneByte(
734 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count)); 788 CcTest::isolate(),
789 new TestOneByteResource(i::StrDup(one_byte_string), &dispose_count))
790 .ToLocalChecked();
735 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); 791 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string);
736 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 792 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
737 in_new_space = CcTest::heap()->InNewSpace(*istring); 793 in_new_space = CcTest::heap()->InNewSpace(*istring);
738 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring)); 794 CHECK(in_new_space || CcTest::heap()->old_space()->Contains(*istring));
739 CHECK_EQ(0, dispose_count); 795 CHECK_EQ(0, dispose_count);
740 } 796 }
741 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE); 797 CcTest::heap()->CollectGarbage(in_new_space ? i::NEW_SPACE : i::OLD_SPACE);
742 CHECK_EQ(1, dispose_count); 798 CHECK_EQ(1, dispose_count);
743 } 799 }
744 800
(...skipping 23 matching lines...) Expand all
768 TEST(ExternalStringWithDisposeHandling) { 824 TEST(ExternalStringWithDisposeHandling) {
769 const char* c_source = "1 + 2 * 3"; 825 const char* c_source = "1 + 2 * 3";
770 826
771 // Use a stack allocated external string resource allocated object. 827 // Use a stack allocated external string resource allocated object.
772 TestOneByteResourceWithDisposeControl::dispose_count = 0; 828 TestOneByteResourceWithDisposeControl::dispose_count = 0;
773 TestOneByteResourceWithDisposeControl::dispose_calls = 0; 829 TestOneByteResourceWithDisposeControl::dispose_calls = 0;
774 TestOneByteResourceWithDisposeControl res_stack(i::StrDup(c_source), false); 830 TestOneByteResourceWithDisposeControl res_stack(i::StrDup(c_source), false);
775 { 831 {
776 LocalContext env; 832 LocalContext env;
777 v8::HandleScope scope(env->GetIsolate()); 833 v8::HandleScope scope(env->GetIsolate());
778 Local<String> source = String::NewExternal(env->GetIsolate(), &res_stack); 834 Local<String> source =
835 String::NewExternalOneByte(env->GetIsolate(), &res_stack)
836 .ToLocalChecked();
779 Local<Script> script = v8_compile(source); 837 Local<Script> script = v8_compile(source);
780 Local<Value> value = script->Run(); 838 Local<Value> value = script->Run(env.local()).ToLocalChecked();
781 CHECK(value->IsNumber()); 839 CHECK(value->IsNumber());
782 CHECK_EQ(7, value->Int32Value()); 840 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
783 CcTest::heap()->CollectAllAvailableGarbage(); 841 CcTest::heap()->CollectAllAvailableGarbage();
784 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); 842 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count);
785 } 843 }
786 CcTest::i_isolate()->compilation_cache()->Clear(); 844 CcTest::i_isolate()->compilation_cache()->Clear();
787 CcTest::heap()->CollectAllAvailableGarbage(); 845 CcTest::heap()->CollectAllAvailableGarbage();
788 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); 846 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls);
789 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); 847 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count);
790 848
791 // Use a heap allocated external string resource allocated object. 849 // Use a heap allocated external string resource allocated object.
792 TestOneByteResourceWithDisposeControl::dispose_count = 0; 850 TestOneByteResourceWithDisposeControl::dispose_count = 0;
793 TestOneByteResourceWithDisposeControl::dispose_calls = 0; 851 TestOneByteResourceWithDisposeControl::dispose_calls = 0;
794 TestOneByteResource* res_heap = 852 TestOneByteResource* res_heap =
795 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true); 853 new TestOneByteResourceWithDisposeControl(i::StrDup(c_source), true);
796 { 854 {
797 LocalContext env; 855 LocalContext env;
798 v8::HandleScope scope(env->GetIsolate()); 856 v8::HandleScope scope(env->GetIsolate());
799 Local<String> source = String::NewExternal(env->GetIsolate(), res_heap); 857 Local<String> source =
858 String::NewExternalOneByte(env->GetIsolate(), res_heap)
859 .ToLocalChecked();
800 Local<Script> script = v8_compile(source); 860 Local<Script> script = v8_compile(source);
801 Local<Value> value = script->Run(); 861 Local<Value> value = script->Run(env.local()).ToLocalChecked();
802 CHECK(value->IsNumber()); 862 CHECK(value->IsNumber());
803 CHECK_EQ(7, value->Int32Value()); 863 CHECK_EQ(7, value->Int32Value(env.local()).FromJust());
804 CcTest::heap()->CollectAllAvailableGarbage(); 864 CcTest::heap()->CollectAllAvailableGarbage();
805 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count); 865 CHECK_EQ(0, TestOneByteResourceWithDisposeControl::dispose_count);
806 } 866 }
807 CcTest::i_isolate()->compilation_cache()->Clear(); 867 CcTest::i_isolate()->compilation_cache()->Clear();
808 CcTest::heap()->CollectAllAvailableGarbage(); 868 CcTest::heap()->CollectAllAvailableGarbage();
809 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls); 869 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_calls);
810 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count); 870 CHECK_EQ(1, TestOneByteResourceWithDisposeControl::dispose_count);
811 } 871 }
812 872
813 873
814 THREADED_TEST(StringConcat) { 874 THREADED_TEST(StringConcat) {
815 { 875 {
816 LocalContext env; 876 LocalContext env;
817 v8::HandleScope scope(env->GetIsolate()); 877 v8::HandleScope scope(env->GetIsolate());
818 const char* one_byte_string_1 = "function a_times_t"; 878 const char* one_byte_string_1 = "function a_times_t";
819 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; 879 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) + "; 880 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) + "; 881 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) + "; 882 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) + "; 883 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);"; 884 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);";
825 Local<String> left = v8_str(one_byte_string_1); 885 Local<String> left = v8_str(one_byte_string_1);
826 886
827 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); 887 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1);
828 Local<String> right = 888 Local<String> right =
829 String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 889 String::NewFromTwoByte(env->GetIsolate(), two_byte_source,
890 v8::NewStringType::kNormal)
891 .ToLocalChecked();
830 i::DeleteArray(two_byte_source); 892 i::DeleteArray(two_byte_source);
831 893
832 Local<String> source = String::Concat(left, right); 894 Local<String> source = String::Concat(left, right);
833 right = String::NewExternal( 895 right = String::NewExternalOneByte(
834 env->GetIsolate(), 896 env->GetIsolate(),
835 new TestOneByteResource(i::StrDup(one_byte_extern_1))); 897 new TestOneByteResource(i::StrDup(one_byte_extern_1)))
898 .ToLocalChecked();
836 source = String::Concat(source, right); 899 source = String::Concat(source, right);
837 right = String::NewExternal( 900 right = String::NewExternalTwoByte(
838 env->GetIsolate(), 901 env->GetIsolate(),
839 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); 902 new TestResource(AsciiToTwoByteString(two_byte_extern_1)))
903 .ToLocalChecked();
840 source = String::Concat(source, right); 904 source = String::Concat(source, right);
841 right = v8_str(one_byte_string_2); 905 right = v8_str(one_byte_string_2);
842 source = String::Concat(source, right); 906 source = String::Concat(source, right);
843 907
844 two_byte_source = AsciiToTwoByteString(two_byte_string_2); 908 two_byte_source = AsciiToTwoByteString(two_byte_string_2);
845 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source); 909 right = String::NewFromTwoByte(env->GetIsolate(), two_byte_source,
910 v8::NewStringType::kNormal)
911 .ToLocalChecked();
846 i::DeleteArray(two_byte_source); 912 i::DeleteArray(two_byte_source);
847 913
848 source = String::Concat(source, right); 914 source = String::Concat(source, right);
849 right = String::NewExternal( 915 right = String::NewExternalTwoByte(
850 env->GetIsolate(), 916 env->GetIsolate(),
851 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); 917 new TestResource(AsciiToTwoByteString(two_byte_extern_2)))
918 .ToLocalChecked();
852 source = String::Concat(source, right); 919 source = String::Concat(source, right);
853 Local<Script> script = v8_compile(source); 920 Local<Script> script = v8_compile(source);
854 Local<Value> value = script->Run(); 921 Local<Value> value = script->Run(env.local()).ToLocalChecked();
855 CHECK(value->IsNumber()); 922 CHECK(value->IsNumber());
856 CHECK_EQ(68, value->Int32Value()); 923 CHECK_EQ(68, value->Int32Value(env.local()).FromJust());
857 } 924 }
858 CcTest::i_isolate()->compilation_cache()->Clear(); 925 CcTest::i_isolate()->compilation_cache()->Clear();
859 CcTest::heap()->CollectAllGarbage(); 926 CcTest::heap()->CollectAllGarbage();
860 CcTest::heap()->CollectAllGarbage(); 927 CcTest::heap()->CollectAllGarbage();
861 } 928 }
862 929
863 930
864 THREADED_TEST(GlobalProperties) { 931 THREADED_TEST(GlobalProperties) {
865 LocalContext env; 932 LocalContext env;
866 v8::HandleScope scope(env->GetIsolate()); 933 v8::HandleScope scope(env->GetIsolate());
867 v8::Handle<v8::Object> global = env->Global(); 934 v8::Local<v8::Object> global = env->Global();
868 global->Set(v8_str("pi"), v8_num(3.1415926)); 935 CHECK(global->Set(env.local(), v8_str("pi"), v8_num(3.1415926)).FromJust());
869 Local<Value> pi = global->Get(v8_str("pi")); 936 Local<Value> pi = global->Get(env.local(), v8_str("pi")).ToLocalChecked();
870 CHECK_EQ(3.1415926, pi->NumberValue()); 937 CHECK_EQ(3.1415926, pi->NumberValue(env.local()).FromJust());
871 } 938 }
872 939
873 940
874 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info, 941 static void handle_callback_impl(const v8::FunctionCallbackInfo<Value>& info,
875 i::Address callback) { 942 i::Address callback) {
876 ApiTestFuzzer::Fuzz(); 943 ApiTestFuzzer::Fuzz();
877 CheckReturnValue(info, callback); 944 CheckReturnValue(info, callback);
878 info.GetReturnValue().Set(v8_str("bad value")); 945 info.GetReturnValue().Set(v8_str("bad value"));
879 info.GetReturnValue().Set(v8_num(102)); 946 info.GetReturnValue().Set(v8_num(102));
880 } 947 }
881 948
882 949
883 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) { 950 static void handle_callback(const v8::FunctionCallbackInfo<Value>& info) {
884 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback)); 951 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback));
885 } 952 }
886 953
887 954
888 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) { 955 static void handle_callback_2(const v8::FunctionCallbackInfo<Value>& info) {
889 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2)); 956 return handle_callback_impl(info, FUNCTION_ADDR(handle_callback_2));
890 } 957 }
891 958
892 static void construct_callback( 959 static void construct_callback(
893 const v8::FunctionCallbackInfo<Value>& info) { 960 const v8::FunctionCallbackInfo<Value>& info) {
894 ApiTestFuzzer::Fuzz(); 961 ApiTestFuzzer::Fuzz();
895 CheckReturnValue(info, FUNCTION_ADDR(construct_callback)); 962 CheckReturnValue(info, FUNCTION_ADDR(construct_callback));
896 info.This()->Set(v8_str("x"), v8_num(1)); 963 CHECK(
897 info.This()->Set(v8_str("y"), v8_num(2)); 964 info.This()
965 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("x"), v8_num(1))
966 .FromJust());
967 CHECK(
968 info.This()
969 ->Set(info.GetIsolate()->GetCurrentContext(), v8_str("y"), v8_num(2))
970 .FromJust());
898 info.GetReturnValue().Set(v8_str("bad value")); 971 info.GetReturnValue().Set(v8_str("bad value"));
899 info.GetReturnValue().Set(info.This()); 972 info.GetReturnValue().Set(info.This());
900 } 973 }
901 974
902 975
903 static void Return239Callback( 976 static void Return239Callback(
904 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) { 977 Local<String> name, const v8::PropertyCallbackInfo<Value>& info) {
905 ApiTestFuzzer::Fuzz(); 978 ApiTestFuzzer::Fuzz();
906 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback)); 979 CheckReturnValue(info, FUNCTION_ADDR(Return239Callback));
907 info.GetReturnValue().Set(v8_str("bad value")); 980 info.GetReturnValue().Set(v8_str("bad value"));
908 info.GetReturnValue().Set(v8_num(239)); 981 info.GetReturnValue().Set(v8_num(239));
909 } 982 }
910 983
911 984
912 template<typename Handler> 985 template<typename Handler>
913 static void TestFunctionTemplateInitializer(Handler handler, 986 static void TestFunctionTemplateInitializer(Handler handler,
914 Handler handler_2) { 987 Handler handler_2) {
915 // Test constructor calls. 988 // Test constructor calls.
916 { 989 {
917 LocalContext env; 990 LocalContext env;
918 v8::Isolate* isolate = env->GetIsolate(); 991 v8::Isolate* isolate = env->GetIsolate();
919 v8::HandleScope scope(isolate); 992 v8::HandleScope scope(isolate);
920 993
921 Local<v8::FunctionTemplate> fun_templ = 994 Local<v8::FunctionTemplate> fun_templ =
922 v8::FunctionTemplate::New(isolate, handler); 995 v8::FunctionTemplate::New(isolate, handler);
923 Local<Function> fun = fun_templ->GetFunction(); 996 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
924 env->Global()->Set(v8_str("obj"), fun); 997 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust());
925 Local<Script> script = v8_compile("obj()"); 998 Local<Script> script = v8_compile("obj()");
926 for (int i = 0; i < 30; i++) { 999 for (int i = 0; i < 30; i++) {
927 CHECK_EQ(102, script->Run()->Int32Value()); 1000 CHECK_EQ(102, v8_run_int32value(script));
928 } 1001 }
929 } 1002 }
930 // Use SetCallHandler to initialize a function template, should work like 1003 // Use SetCallHandler to initialize a function template, should work like
931 // the previous one. 1004 // the previous one.
932 { 1005 {
933 LocalContext env; 1006 LocalContext env;
934 v8::Isolate* isolate = env->GetIsolate(); 1007 v8::Isolate* isolate = env->GetIsolate();
935 v8::HandleScope scope(isolate); 1008 v8::HandleScope scope(isolate);
936 1009
937 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate); 1010 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
938 fun_templ->SetCallHandler(handler_2); 1011 fun_templ->SetCallHandler(handler_2);
939 Local<Function> fun = fun_templ->GetFunction(); 1012 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
940 env->Global()->Set(v8_str("obj"), fun); 1013 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust());
941 Local<Script> script = v8_compile("obj()"); 1014 Local<Script> script = v8_compile("obj()");
942 for (int i = 0; i < 30; i++) { 1015 for (int i = 0; i < 30; i++) {
943 CHECK_EQ(102, script->Run()->Int32Value()); 1016 CHECK_EQ(102, v8_run_int32value(script));
944 } 1017 }
945 } 1018 }
946 } 1019 }
947 1020
948 1021
949 template<typename Constructor, typename Accessor> 1022 template<typename Constructor, typename Accessor>
950 static void TestFunctionTemplateAccessor(Constructor constructor, 1023 static void TestFunctionTemplateAccessor(Constructor constructor,
951 Accessor accessor) { 1024 Accessor accessor) {
952 LocalContext env; 1025 LocalContext env;
953 v8::HandleScope scope(env->GetIsolate()); 1026 v8::HandleScope scope(env->GetIsolate());
954 1027
955 Local<v8::FunctionTemplate> fun_templ = 1028 Local<v8::FunctionTemplate> fun_templ =
956 v8::FunctionTemplate::New(env->GetIsolate(), constructor); 1029 v8::FunctionTemplate::New(env->GetIsolate(), constructor);
957 fun_templ->SetClassName(v8_str("funky")); 1030 fun_templ->SetClassName(v8_str("funky"));
958 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); 1031 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor);
959 Local<Function> fun = fun_templ->GetFunction(); 1032 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
960 env->Global()->Set(v8_str("obj"), fun); 1033 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust());
961 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 1034 Local<Value> result =
962 CHECK(v8_str("[object funky]")->Equals(result)); 1035 v8_compile("(new obj()).toString()")->Run(env.local()).ToLocalChecked();
1036 CHECK(v8_str("[object funky]")->Equals(env.local(), result).FromJust());
963 CompileRun("var obj_instance = new obj();"); 1037 CompileRun("var obj_instance = new obj();");
964 Local<Script> script; 1038 Local<Script> script;
965 script = v8_compile("obj_instance.x"); 1039 script = v8_compile("obj_instance.x");
966 for (int i = 0; i < 30; i++) { 1040 for (int i = 0; i < 30; i++) {
967 CHECK_EQ(1, script->Run()->Int32Value()); 1041 CHECK_EQ(1, v8_run_int32value(script));
968 } 1042 }
969 script = v8_compile("obj_instance.m"); 1043 script = v8_compile("obj_instance.m");
970 for (int i = 0; i < 30; i++) { 1044 for (int i = 0; i < 30; i++) {
971 CHECK_EQ(239, script->Run()->Int32Value()); 1045 CHECK_EQ(239, v8_run_int32value(script));
972 } 1046 }
973 } 1047 }
974 1048
975 1049
976 THREADED_PROFILED_TEST(FunctionTemplate) { 1050 THREADED_PROFILED_TEST(FunctionTemplate) {
977 TestFunctionTemplateInitializer(handle_callback, handle_callback_2); 1051 TestFunctionTemplateInitializer(handle_callback, handle_callback_2);
978 TestFunctionTemplateAccessor(construct_callback, Return239Callback); 1052 TestFunctionTemplateAccessor(construct_callback, Return239Callback);
979 } 1053 }
980 1054
981 1055
982 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { 1056 static void SimpleCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
983 ApiTestFuzzer::Fuzz(); 1057 ApiTestFuzzer::Fuzz();
984 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback)); 1058 CheckReturnValue(info, FUNCTION_ADDR(SimpleCallback));
985 info.GetReturnValue().Set(v8_num(51423 + info.Length())); 1059 info.GetReturnValue().Set(v8_num(51423 + info.Length()));
986 } 1060 }
987 1061
988 1062
989 template<typename Callback> 1063 template<typename Callback>
990 static void TestSimpleCallback(Callback callback) { 1064 static void TestSimpleCallback(Callback callback) {
991 LocalContext env; 1065 LocalContext env;
992 v8::Isolate* isolate = env->GetIsolate(); 1066 v8::Isolate* isolate = env->GetIsolate();
993 v8::HandleScope scope(isolate); 1067 v8::HandleScope scope(isolate);
994 1068
995 v8::Handle<v8::ObjectTemplate> object_template = 1069 v8::Local<v8::ObjectTemplate> object_template =
996 v8::ObjectTemplate::New(isolate); 1070 v8::ObjectTemplate::New(isolate);
997 object_template->Set(isolate, "callback", 1071 object_template->Set(isolate, "callback",
998 v8::FunctionTemplate::New(isolate, callback)); 1072 v8::FunctionTemplate::New(isolate, callback));
999 v8::Local<v8::Object> object = object_template->NewInstance(); 1073 v8::Local<v8::Object> object =
1000 (*env)->Global()->Set(v8_str("callback_object"), object); 1074 object_template->NewInstance(env.local()).ToLocalChecked();
1001 v8::Handle<v8::Script> script; 1075 CHECK((*env)
1076 ->Global()
1077 ->Set(env.local(), v8_str("callback_object"), object)
1078 .FromJust());
1079 v8::Local<v8::Script> script;
1002 script = v8_compile("callback_object.callback(17)"); 1080 script = v8_compile("callback_object.callback(17)");
1003 for (int i = 0; i < 30; i++) { 1081 for (int i = 0; i < 30; i++) {
1004 CHECK_EQ(51424, script->Run()->Int32Value()); 1082 CHECK_EQ(51424, v8_run_int32value(script));
1005 } 1083 }
1006 script = v8_compile("callback_object.callback(17, 24)"); 1084 script = v8_compile("callback_object.callback(17, 24)");
1007 for (int i = 0; i < 30; i++) { 1085 for (int i = 0; i < 30; i++) {
1008 CHECK_EQ(51425, script->Run()->Int32Value()); 1086 CHECK_EQ(51425, v8_run_int32value(script));
1009 } 1087 }
1010 } 1088 }
1011 1089
1012 1090
1013 THREADED_PROFILED_TEST(SimpleCallback) { 1091 THREADED_PROFILED_TEST(SimpleCallback) {
1014 TestSimpleCallback(SimpleCallback); 1092 TestSimpleCallback(SimpleCallback);
1015 } 1093 }
1016 1094
1017 1095
1018 template<typename T> 1096 template<typename T>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 break; 1157 break;
1080 case kEmptyStringReturnValue: 1158 case kEmptyStringReturnValue:
1081 info.GetReturnValue().SetEmptyString(); 1159 info.GetReturnValue().SetEmptyString();
1082 break; 1160 break;
1083 } 1161 }
1084 } 1162 }
1085 1163
1086 template<> 1164 template<>
1087 void FastReturnValueCallback<Object>( 1165 void FastReturnValueCallback<Object>(
1088 const v8::FunctionCallbackInfo<v8::Value>& info) { 1166 const v8::FunctionCallbackInfo<v8::Value>& info) {
1089 v8::Handle<v8::Object> object; 1167 v8::Local<v8::Object> object;
1090 if (!fast_return_value_object_is_empty) { 1168 if (!fast_return_value_object_is_empty) {
1091 object = Object::New(info.GetIsolate()); 1169 object = Object::New(info.GetIsolate());
1092 } 1170 }
1093 info.GetReturnValue().Set(object); 1171 info.GetReturnValue().Set(object);
1094 } 1172 }
1095 1173
1096 template<typename T> 1174 template <typename T>
1097 Handle<Value> TestFastReturnValues() { 1175 Local<Value> TestFastReturnValues() {
1098 LocalContext env; 1176 LocalContext env;
1099 v8::Isolate* isolate = env->GetIsolate(); 1177 v8::Isolate* isolate = env->GetIsolate();
1100 v8::EscapableHandleScope scope(isolate); 1178 v8::EscapableHandleScope scope(isolate);
1101 v8::Handle<v8::ObjectTemplate> object_template = 1179 v8::Local<v8::ObjectTemplate> object_template =
1102 v8::ObjectTemplate::New(isolate); 1180 v8::ObjectTemplate::New(isolate);
1103 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1181 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1104 object_template->Set(isolate, "callback", 1182 object_template->Set(isolate, "callback",
1105 v8::FunctionTemplate::New(isolate, callback)); 1183 v8::FunctionTemplate::New(isolate, callback));
1106 v8::Local<v8::Object> object = object_template->NewInstance(); 1184 v8::Local<v8::Object> object =
1107 (*env)->Global()->Set(v8_str("callback_object"), object); 1185 object_template->NewInstance(env.local()).ToLocalChecked();
1186 CHECK((*env)
1187 ->Global()
1188 ->Set(env.local(), v8_str("callback_object"), object)
1189 .FromJust());
1108 return scope.Escape(CompileRun("callback_object.callback()")); 1190 return scope.Escape(CompileRun("callback_object.callback()"));
1109 } 1191 }
1110 1192
1111 1193
1112 THREADED_PROFILED_TEST(FastReturnValues) { 1194 THREADED_PROFILED_TEST(FastReturnValues) {
1113 LocalContext env; 1195 LocalContext env;
1114 v8::Isolate* isolate = env->GetIsolate(); 1196 v8::Isolate* isolate = env->GetIsolate();
1115 v8::HandleScope scope(isolate); 1197 v8::HandleScope scope(isolate);
1116 v8::Handle<v8::Value> value; 1198 v8::Local<v8::Value> value;
1117 // check int32_t and uint32_t 1199 // check int32_t and uint32_t
1118 int32_t int_values[] = { 1200 int32_t int_values[] = {
1119 0, 234, -723, 1201 0, 234, -723,
1120 i::Smi::kMinValue, i::Smi::kMaxValue 1202 i::Smi::kMinValue, i::Smi::kMaxValue
1121 }; 1203 };
1122 for (size_t i = 0; i < arraysize(int_values); i++) { 1204 for (size_t i = 0; i < arraysize(int_values); i++) {
1123 for (int modifier = -1; modifier <= 1; modifier++) { 1205 for (int modifier = -1; modifier <= 1; modifier++) {
1124 int int_value = int_values[i] + modifier; 1206 int int_value = int_values[i] + modifier;
1125 // check int32_t 1207 // check int32_t
1126 fast_return_value_int32 = int_value; 1208 fast_return_value_int32 = int_value;
1127 value = TestFastReturnValues<int32_t>(); 1209 value = TestFastReturnValues<int32_t>();
1128 CHECK(value->IsInt32()); 1210 CHECK(value->IsInt32());
1129 CHECK(fast_return_value_int32 == value->Int32Value()); 1211 CHECK_EQ(fast_return_value_int32,
1212 value->Int32Value(env.local()).FromJust());
1130 // check uint32_t 1213 // check uint32_t
1131 fast_return_value_uint32 = static_cast<uint32_t>(int_value); 1214 fast_return_value_uint32 = static_cast<uint32_t>(int_value);
1132 value = TestFastReturnValues<uint32_t>(); 1215 value = TestFastReturnValues<uint32_t>();
1133 CHECK(value->IsUint32()); 1216 CHECK(value->IsUint32());
1134 CHECK(fast_return_value_uint32 == value->Uint32Value()); 1217 CHECK_EQ(fast_return_value_uint32,
1218 value->Uint32Value(env.local()).FromJust());
1135 } 1219 }
1136 } 1220 }
1137 // check double 1221 // check double
1138 value = TestFastReturnValues<double>(); 1222 value = TestFastReturnValues<double>();
1139 CHECK(value->IsNumber()); 1223 CHECK(value->IsNumber());
1140 CHECK_EQ(kFastReturnValueDouble, value->ToNumber(isolate)->Value()); 1224 CHECK_EQ(kFastReturnValueDouble,
1225 value->ToNumber(env.local()).ToLocalChecked()->Value());
1141 // check bool values 1226 // check bool values
1142 for (int i = 0; i < 2; i++) { 1227 for (int i = 0; i < 2; i++) {
1143 fast_return_value_bool = i == 0; 1228 fast_return_value_bool = i == 0;
1144 value = TestFastReturnValues<bool>(); 1229 value = TestFastReturnValues<bool>();
1145 CHECK(value->IsBoolean()); 1230 CHECK(value->IsBoolean());
1146 CHECK_EQ(fast_return_value_bool, value->ToBoolean(isolate)->Value()); 1231 CHECK_EQ(fast_return_value_bool,
1232 value->ToBoolean(env.local()).ToLocalChecked()->Value());
1147 } 1233 }
1148 // check oddballs 1234 // check oddballs
1149 ReturnValueOddball oddballs[] = { 1235 ReturnValueOddball oddballs[] = {
1150 kNullReturnValue, 1236 kNullReturnValue,
1151 kUndefinedReturnValue, 1237 kUndefinedReturnValue,
1152 kEmptyStringReturnValue 1238 kEmptyStringReturnValue
1153 }; 1239 };
1154 for (size_t i = 0; i < arraysize(oddballs); i++) { 1240 for (size_t i = 0; i < arraysize(oddballs); i++) {
1155 fast_return_value_void = oddballs[i]; 1241 fast_return_value_void = oddballs[i];
1156 value = TestFastReturnValues<void>(); 1242 value = TestFastReturnValues<void>();
(...skipping 19 matching lines...) Expand all
1176 CHECK(value->IsUndefined()); 1262 CHECK(value->IsUndefined());
1177 } 1263 }
1178 1264
1179 1265
1180 THREADED_TEST(FunctionTemplateSetLength) { 1266 THREADED_TEST(FunctionTemplateSetLength) {
1181 LocalContext env; 1267 LocalContext env;
1182 v8::Isolate* isolate = env->GetIsolate(); 1268 v8::Isolate* isolate = env->GetIsolate();
1183 v8::HandleScope scope(isolate); 1269 v8::HandleScope scope(isolate);
1184 { 1270 {
1185 Local<v8::FunctionTemplate> fun_templ = 1271 Local<v8::FunctionTemplate> fun_templ =
1186 v8::FunctionTemplate::New(isolate, 1272 v8::FunctionTemplate::New(isolate, handle_callback, Local<v8::Value>(),
1187 handle_callback, 1273 Local<v8::Signature>(), 23);
1188 Handle<v8::Value>(), 1274 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
1189 Handle<v8::Signature>(), 1275 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"); 1276 Local<Script> script = v8_compile("obj.length");
1194 CHECK_EQ(23, script->Run()->Int32Value()); 1277 CHECK_EQ(23, v8_run_int32value(script));
1195 } 1278 }
1196 { 1279 {
1197 Local<v8::FunctionTemplate> fun_templ = 1280 Local<v8::FunctionTemplate> fun_templ =
1198 v8::FunctionTemplate::New(isolate, handle_callback); 1281 v8::FunctionTemplate::New(isolate, handle_callback);
1199 fun_templ->SetLength(22); 1282 fun_templ->SetLength(22);
1200 Local<Function> fun = fun_templ->GetFunction(); 1283 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
1201 env->Global()->Set(v8_str("obj"), fun); 1284 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust());
1202 Local<Script> script = v8_compile("obj.length"); 1285 Local<Script> script = v8_compile("obj.length");
1203 CHECK_EQ(22, script->Run()->Int32Value()); 1286 CHECK_EQ(22, v8_run_int32value(script));
1204 } 1287 }
1205 { 1288 {
1206 // Without setting length it defaults to 0. 1289 // Without setting length it defaults to 0.
1207 Local<v8::FunctionTemplate> fun_templ = 1290 Local<v8::FunctionTemplate> fun_templ =
1208 v8::FunctionTemplate::New(isolate, handle_callback); 1291 v8::FunctionTemplate::New(isolate, handle_callback);
1209 Local<Function> fun = fun_templ->GetFunction(); 1292 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
1210 env->Global()->Set(v8_str("obj"), fun); 1293 CHECK(env->Global()->Set(env.local(), v8_str("obj"), fun).FromJust());
1211 Local<Script> script = v8_compile("obj.length"); 1294 Local<Script> script = v8_compile("obj.length");
1212 CHECK_EQ(0, script->Run()->Int32Value()); 1295 CHECK_EQ(0, v8_run_int32value(script));
1213 } 1296 }
1214 } 1297 }
1215 1298
1216 1299
1217 static void* expected_ptr; 1300 static void* expected_ptr;
1218 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { 1301 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) {
1219 void* ptr = v8::External::Cast(*args.Data())->Value(); 1302 void* ptr = v8::External::Cast(*args.Data())->Value();
1220 CHECK_EQ(expected_ptr, ptr); 1303 CHECK_EQ(expected_ptr, ptr);
1221 args.GetReturnValue().Set(true); 1304 args.GetReturnValue().Set(true);
1222 } 1305 }
1223 1306
1224 1307
1225 static void TestExternalPointerWrapping() { 1308 static void TestExternalPointerWrapping() {
1226 LocalContext env; 1309 LocalContext env;
1227 v8::Isolate* isolate = env->GetIsolate(); 1310 v8::Isolate* isolate = env->GetIsolate();
1228 v8::HandleScope scope(isolate); 1311 v8::HandleScope scope(isolate);
1229 1312
1230 v8::Handle<v8::Value> data = 1313 v8::Local<v8::Value> data = v8::External::New(isolate, expected_ptr);
1231 v8::External::New(isolate, expected_ptr);
1232 1314
1233 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 1315 v8::Local<v8::Object> obj = v8::Object::New(isolate);
1234 obj->Set(v8_str("func"), 1316 CHECK(obj->Set(env.local(), v8_str("func"),
1235 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction()); 1317 v8::FunctionTemplate::New(isolate, callback, data)
1236 env->Global()->Set(v8_str("obj"), obj); 1318 ->GetFunction(env.local())
1319 .ToLocalChecked())
1320 .FromJust());
1321 CHECK(env->Global()->Set(env.local(), v8_str("obj"), obj).FromJust());
1237 1322
1238 CHECK(CompileRun( 1323 CHECK(CompileRun("function foo() {\n"
1239 "function foo() {\n" 1324 " for (var i = 0; i < 13; i++) obj.func();\n"
1240 " for (var i = 0; i < 13; i++) obj.func();\n" 1325 "}\n"
1241 "}\n" 1326 "foo(), true")
1242 "foo(), true")->BooleanValue()); 1327 ->BooleanValue(env.local())
1328 .FromJust());
1243 } 1329 }
1244 1330
1245 1331
1246 THREADED_TEST(ExternalWrap) { 1332 THREADED_TEST(ExternalWrap) {
1247 // Check heap allocated object. 1333 // Check heap allocated object.
1248 int* ptr = new int; 1334 int* ptr = new int;
1249 expected_ptr = ptr; 1335 expected_ptr = ptr;
1250 TestExternalPointerWrapping(); 1336 TestExternalPointerWrapping();
1251 delete ptr; 1337 delete ptr;
1252 1338
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 THREADED_TEST(FindInstanceInPrototypeChain) { 1378 THREADED_TEST(FindInstanceInPrototypeChain) {
1293 LocalContext env; 1379 LocalContext env;
1294 v8::Isolate* isolate = env->GetIsolate(); 1380 v8::Isolate* isolate = env->GetIsolate();
1295 v8::HandleScope scope(isolate); 1381 v8::HandleScope scope(isolate);
1296 1382
1297 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate); 1383 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate);
1298 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate); 1384 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate);
1299 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate); 1385 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate);
1300 derived->Inherit(base); 1386 derived->Inherit(base);
1301 1387
1302 Local<v8::Function> base_function = base->GetFunction(); 1388 Local<v8::Function> base_function =
1303 Local<v8::Function> derived_function = derived->GetFunction(); 1389 base->GetFunction(env.local()).ToLocalChecked();
1304 Local<v8::Function> other_function = other->GetFunction(); 1390 Local<v8::Function> derived_function =
1391 derived->GetFunction(env.local()).ToLocalChecked();
1392 Local<v8::Function> other_function =
1393 other->GetFunction(env.local()).ToLocalChecked();
1305 1394
1306 Local<v8::Object> base_instance = base_function->NewInstance(); 1395 Local<v8::Object> base_instance =
1307 Local<v8::Object> derived_instance = derived_function->NewInstance(); 1396 base_function->NewInstance(env.local()).ToLocalChecked();
1308 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); 1397 Local<v8::Object> derived_instance =
1309 Local<v8::Object> other_instance = other_function->NewInstance(); 1398 derived_function->NewInstance(env.local()).ToLocalChecked();
1310 derived_instance2->Set(v8_str("__proto__"), derived_instance); 1399 Local<v8::Object> derived_instance2 =
1311 other_instance->Set(v8_str("__proto__"), derived_instance2); 1400 derived_function->NewInstance(env.local()).ToLocalChecked();
1401 Local<v8::Object> other_instance =
1402 other_function->NewInstance(env.local()).ToLocalChecked();
1403 CHECK(
1404 derived_instance2->Set(env.local(), v8_str("__proto__"), derived_instance)
1405 .FromJust());
1406 CHECK(other_instance->Set(env.local(), v8_str("__proto__"), derived_instance2)
1407 .FromJust());
1312 1408
1313 // base_instance is only an instance of base. 1409 // base_instance is only an instance of base.
1314 CHECK( 1410 CHECK(base_instance->Equals(env.local(),
1315 base_instance->Equals(base_instance->FindInstanceInPrototypeChain(base))); 1411 base_instance->FindInstanceInPrototypeChain(base))
1412 .FromJust());
1316 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty()); 1413 CHECK(base_instance->FindInstanceInPrototypeChain(derived).IsEmpty());
1317 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty()); 1414 CHECK(base_instance->FindInstanceInPrototypeChain(other).IsEmpty());
1318 1415
1319 // derived_instance is an instance of base and derived. 1416 // derived_instance is an instance of base and derived.
1320 CHECK(derived_instance->Equals( 1417 CHECK(derived_instance->Equals(env.local(),
1321 derived_instance->FindInstanceInPrototypeChain(base))); 1418 derived_instance->FindInstanceInPrototypeChain(
1322 CHECK(derived_instance->Equals( 1419 base))
1323 derived_instance->FindInstanceInPrototypeChain(derived))); 1420 .FromJust());
1421 CHECK(derived_instance->Equals(env.local(),
1422 derived_instance->FindInstanceInPrototypeChain(
1423 derived))
1424 .FromJust());
1324 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty()); 1425 CHECK(derived_instance->FindInstanceInPrototypeChain(other).IsEmpty());
1325 1426
1326 // other_instance is an instance of other and its immediate 1427 // other_instance is an instance of other and its immediate
1327 // prototype derived_instance2 is an instance of base and derived. 1428 // prototype derived_instance2 is an instance of base and derived.
1328 // Note, derived_instance is an instance of base and derived too, 1429 // Note, derived_instance is an instance of base and derived too,
1329 // but it comes after derived_instance2 in the prototype chain of 1430 // but it comes after derived_instance2 in the prototype chain of
1330 // other_instance. 1431 // other_instance.
1331 CHECK(derived_instance2->Equals( 1432 CHECK(derived_instance2->Equals(
1332 other_instance->FindInstanceInPrototypeChain(base))); 1433 env.local(),
1333 CHECK(derived_instance2->Equals( 1434 other_instance->FindInstanceInPrototypeChain(base))
1334 other_instance->FindInstanceInPrototypeChain(derived))); 1435 .FromJust());
1436 CHECK(derived_instance2->Equals(env.local(),
1437 other_instance->FindInstanceInPrototypeChain(
1438 derived))
1439 .FromJust());
1335 CHECK(other_instance->Equals( 1440 CHECK(other_instance->Equals(
1336 other_instance->FindInstanceInPrototypeChain(other))); 1441 env.local(),
1442 other_instance->FindInstanceInPrototypeChain(other))
1443 .FromJust());
1337 } 1444 }
1338 1445
1339 1446
1340 THREADED_TEST(TinyInteger) { 1447 THREADED_TEST(TinyInteger) {
1341 LocalContext env; 1448 LocalContext env;
1342 v8::Isolate* isolate = env->GetIsolate(); 1449 v8::Isolate* isolate = env->GetIsolate();
1343 v8::HandleScope scope(isolate); 1450 v8::HandleScope scope(isolate);
1344 1451
1345 int32_t value = 239; 1452 int32_t value = 239;
1346 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value); 1453 Local<v8::Integer> value_obj = v8::Integer::New(isolate, value);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1563 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1457 1564
1458 value_obj = v8::Integer::NewFromUnsigned(isolate, value); 1565 value_obj = v8::Integer::NewFromUnsigned(isolate, value);
1459 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); 1566 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value());
1460 } 1567 }
1461 1568
1462 1569
1463 THREADED_TEST(IsNativeError) { 1570 THREADED_TEST(IsNativeError) {
1464 LocalContext env; 1571 LocalContext env;
1465 v8::HandleScope scope(env->GetIsolate()); 1572 v8::HandleScope scope(env->GetIsolate());
1466 v8::Handle<Value> syntax_error = CompileRun( 1573 v8::Local<Value> syntax_error = CompileRun(
1467 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); 1574 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
1468 CHECK(syntax_error->IsNativeError()); 1575 CHECK(syntax_error->IsNativeError());
1469 v8::Handle<Value> not_error = CompileRun("{a:42}"); 1576 v8::Local<Value> not_error = CompileRun("{a:42}");
1470 CHECK(!not_error->IsNativeError()); 1577 CHECK(!not_error->IsNativeError());
1471 v8::Handle<Value> not_object = CompileRun("42"); 1578 v8::Local<Value> not_object = CompileRun("42");
1472 CHECK(!not_object->IsNativeError()); 1579 CHECK(!not_object->IsNativeError());
1473 } 1580 }
1474 1581
1475 1582
1476 THREADED_TEST(IsGeneratorFunctionOrObject) { 1583 THREADED_TEST(IsGeneratorFunctionOrObject) {
1477 LocalContext env; 1584 LocalContext env;
1478 v8::HandleScope scope(env->GetIsolate()); 1585 v8::HandleScope scope(env->GetIsolate());
1479 1586
1480 CompileRun("function *gen() { yield 1; }\nfunction func() {}"); 1587 CompileRun("function *gen() { yield 1; }\nfunction func() {}");
1481 v8::Handle<Value> gen = CompileRun("gen"); 1588 v8::Local<Value> gen = CompileRun("gen");
1482 v8::Handle<Value> genObj = CompileRun("gen()"); 1589 v8::Local<Value> genObj = CompileRun("gen()");
1483 v8::Handle<Value> object = CompileRun("{a:42}"); 1590 v8::Local<Value> object = CompileRun("{a:42}");
1484 v8::Handle<Value> func = CompileRun("func"); 1591 v8::Local<Value> func = CompileRun("func");
1485 1592
1486 CHECK(gen->IsGeneratorFunction()); 1593 CHECK(gen->IsGeneratorFunction());
1487 CHECK(gen->IsFunction()); 1594 CHECK(gen->IsFunction());
1488 CHECK(!gen->IsGeneratorObject()); 1595 CHECK(!gen->IsGeneratorObject());
1489 1596
1490 CHECK(!genObj->IsGeneratorFunction()); 1597 CHECK(!genObj->IsGeneratorFunction());
1491 CHECK(!genObj->IsFunction()); 1598 CHECK(!genObj->IsFunction());
1492 CHECK(genObj->IsGeneratorObject()); 1599 CHECK(genObj->IsGeneratorObject());
1493 1600
1494 CHECK(!object->IsGeneratorFunction()); 1601 CHECK(!object->IsGeneratorFunction());
1495 CHECK(!object->IsFunction()); 1602 CHECK(!object->IsFunction());
1496 CHECK(!object->IsGeneratorObject()); 1603 CHECK(!object->IsGeneratorObject());
1497 1604
1498 CHECK(!func->IsGeneratorFunction()); 1605 CHECK(!func->IsGeneratorFunction());
1499 CHECK(func->IsFunction()); 1606 CHECK(func->IsFunction());
1500 CHECK(!func->IsGeneratorObject()); 1607 CHECK(!func->IsGeneratorObject());
1501 } 1608 }
1502 1609
1503 1610
1504 THREADED_TEST(ArgumentsObject) { 1611 THREADED_TEST(ArgumentsObject) {
1505 LocalContext env; 1612 LocalContext env;
1506 v8::HandleScope scope(env->GetIsolate()); 1613 v8::HandleScope scope(env->GetIsolate());
1507 v8::Handle<Value> arguments_object = 1614 v8::Local<Value> arguments_object =
1508 CompileRun("var out = 0; (function(){ out = arguments; })(1,2,3); out;"); 1615 CompileRun("var out = 0; (function(){ out = arguments; })(1,2,3); out;");
1509 CHECK(arguments_object->IsArgumentsObject()); 1616 CHECK(arguments_object->IsArgumentsObject());
1510 v8::Handle<Value> array = CompileRun("[1,2,3]"); 1617 v8::Local<Value> array = CompileRun("[1,2,3]");
1511 CHECK(!array->IsArgumentsObject()); 1618 CHECK(!array->IsArgumentsObject());
1512 v8::Handle<Value> object = CompileRun("{a:42}"); 1619 v8::Local<Value> object = CompileRun("{a:42}");
1513 CHECK(!object->IsArgumentsObject()); 1620 CHECK(!object->IsArgumentsObject());
1514 } 1621 }
1515 1622
1516 1623
1517 THREADED_TEST(IsMapOrSet) { 1624 THREADED_TEST(IsMapOrSet) {
1518 LocalContext env; 1625 LocalContext env;
1519 v8::HandleScope scope(env->GetIsolate()); 1626 v8::HandleScope scope(env->GetIsolate());
1520 v8::Handle<Value> map = CompileRun("new Map()"); 1627 v8::Local<Value> map = CompileRun("new Map()");
1521 v8::Handle<Value> set = CompileRun("new Set()"); 1628 v8::Local<Value> set = CompileRun("new Set()");
1522 v8::Handle<Value> weak_map = CompileRun("new WeakMap()"); 1629 v8::Local<Value> weak_map = CompileRun("new WeakMap()");
1523 v8::Handle<Value> weak_set = CompileRun("new WeakSet()"); 1630 v8::Local<Value> weak_set = CompileRun("new WeakSet()");
1524 CHECK(map->IsMap()); 1631 CHECK(map->IsMap());
1525 CHECK(set->IsSet()); 1632 CHECK(set->IsSet());
1526 CHECK(weak_map->IsWeakMap()); 1633 CHECK(weak_map->IsWeakMap());
1527 CHECK(weak_set->IsWeakSet()); 1634 CHECK(weak_set->IsWeakSet());
1528 1635
1529 CHECK(!map->IsSet()); 1636 CHECK(!map->IsSet());
1530 CHECK(!map->IsWeakMap()); 1637 CHECK(!map->IsWeakMap());
1531 CHECK(!map->IsWeakSet()); 1638 CHECK(!map->IsWeakSet());
1532 1639
1533 CHECK(!set->IsMap()); 1640 CHECK(!set->IsMap());
1534 CHECK(!set->IsWeakMap()); 1641 CHECK(!set->IsWeakMap());
1535 CHECK(!set->IsWeakSet()); 1642 CHECK(!set->IsWeakSet());
1536 1643
1537 CHECK(!weak_map->IsMap()); 1644 CHECK(!weak_map->IsMap());
1538 CHECK(!weak_map->IsSet()); 1645 CHECK(!weak_map->IsSet());
1539 CHECK(!weak_map->IsWeakSet()); 1646 CHECK(!weak_map->IsWeakSet());
1540 1647
1541 CHECK(!weak_set->IsMap()); 1648 CHECK(!weak_set->IsMap());
1542 CHECK(!weak_set->IsSet()); 1649 CHECK(!weak_set->IsSet());
1543 CHECK(!weak_set->IsWeakMap()); 1650 CHECK(!weak_set->IsWeakMap());
1544 1651
1545 v8::Handle<Value> object = CompileRun("{a:42}"); 1652 v8::Local<Value> object = CompileRun("{a:42}");
1546 CHECK(!object->IsMap()); 1653 CHECK(!object->IsMap());
1547 CHECK(!object->IsSet()); 1654 CHECK(!object->IsSet());
1548 CHECK(!object->IsWeakMap()); 1655 CHECK(!object->IsWeakMap());
1549 CHECK(!object->IsWeakSet()); 1656 CHECK(!object->IsWeakSet());
1550 } 1657 }
1551 1658
1552 1659
1553 THREADED_TEST(StringObject) { 1660 THREADED_TEST(StringObject) {
1554 LocalContext env; 1661 LocalContext env;
1555 v8::HandleScope scope(env->GetIsolate()); 1662 v8::HandleScope scope(env->GetIsolate());
1556 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); 1663 v8::Local<Value> boxed_string = CompileRun("new String(\"test\")");
1557 CHECK(boxed_string->IsStringObject()); 1664 CHECK(boxed_string->IsStringObject());
1558 v8::Handle<Value> unboxed_string = CompileRun("\"test\""); 1665 v8::Local<Value> unboxed_string = CompileRun("\"test\"");
1559 CHECK(!unboxed_string->IsStringObject()); 1666 CHECK(!unboxed_string->IsStringObject());
1560 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)"); 1667 v8::Local<Value> boxed_not_string = CompileRun("new Number(42)");
1561 CHECK(!boxed_not_string->IsStringObject()); 1668 CHECK(!boxed_not_string->IsStringObject());
1562 v8::Handle<Value> not_object = CompileRun("0"); 1669 v8::Local<Value> not_object = CompileRun("0");
1563 CHECK(!not_object->IsStringObject()); 1670 CHECK(!not_object->IsStringObject());
1564 v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>(); 1671 v8::Local<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>();
1565 CHECK(!as_boxed.IsEmpty()); 1672 CHECK(!as_boxed.IsEmpty());
1566 Local<v8::String> the_string = as_boxed->ValueOf(); 1673 Local<v8::String> the_string = as_boxed->ValueOf();
1567 CHECK(!the_string.IsEmpty()); 1674 CHECK(!the_string.IsEmpty());
1568 ExpectObject("\"test\"", the_string); 1675 ExpectObject("\"test\"", the_string);
1569 v8::Handle<v8::Value> new_boxed_string = v8::StringObject::New(the_string); 1676 v8::Local<v8::Value> new_boxed_string = v8::StringObject::New(the_string);
1570 CHECK(new_boxed_string->IsStringObject()); 1677 CHECK(new_boxed_string->IsStringObject());
1571 as_boxed = new_boxed_string.As<v8::StringObject>(); 1678 as_boxed = new_boxed_string.As<v8::StringObject>();
1572 the_string = as_boxed->ValueOf(); 1679 the_string = as_boxed->ValueOf();
1573 CHECK(!the_string.IsEmpty()); 1680 CHECK(!the_string.IsEmpty());
1574 ExpectObject("\"test\"", the_string); 1681 ExpectObject("\"test\"", the_string);
1575 } 1682 }
1576 1683
1577 1684
1578 TEST(StringObjectDelete) { 1685 TEST(StringObjectDelete) {
1579 LocalContext context; 1686 LocalContext context;
1580 v8::HandleScope scope(context->GetIsolate()); 1687 v8::HandleScope scope(context->GetIsolate());
1581 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); 1688 v8::Local<Value> boxed_string = CompileRun("new String(\"test\")");
1582 CHECK(boxed_string->IsStringObject()); 1689 CHECK(boxed_string->IsStringObject());
1583 v8::Handle<v8::Object> str_obj = boxed_string.As<v8::Object>(); 1690 v8::Local<v8::Object> str_obj = boxed_string.As<v8::Object>();
1584 CHECK(!str_obj->Delete(2)); 1691 CHECK(!str_obj->Delete(context.local(), 2).FromJust());
1585 CHECK(!str_obj->Delete(v8_num(2))); 1692 CHECK(!str_obj->Delete(context.local(), v8_num(2)).FromJust());
1586 } 1693 }
1587 1694
1588 1695
1589 THREADED_TEST(NumberObject) { 1696 THREADED_TEST(NumberObject) {
1590 LocalContext env; 1697 LocalContext env;
1591 v8::HandleScope scope(env->GetIsolate()); 1698 v8::HandleScope scope(env->GetIsolate());
1592 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); 1699 v8::Local<Value> boxed_number = CompileRun("new Number(42)");
1593 CHECK(boxed_number->IsNumberObject()); 1700 CHECK(boxed_number->IsNumberObject());
1594 v8::Handle<Value> unboxed_number = CompileRun("42"); 1701 v8::Local<Value> unboxed_number = CompileRun("42");
1595 CHECK(!unboxed_number->IsNumberObject()); 1702 CHECK(!unboxed_number->IsNumberObject());
1596 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); 1703 v8::Local<Value> boxed_not_number = CompileRun("new Boolean(false)");
1597 CHECK(!boxed_not_number->IsNumberObject()); 1704 CHECK(!boxed_not_number->IsNumberObject());
1598 v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>(); 1705 v8::Local<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>();
1599 CHECK(!as_boxed.IsEmpty()); 1706 CHECK(!as_boxed.IsEmpty());
1600 double the_number = as_boxed->ValueOf(); 1707 double the_number = as_boxed->ValueOf();
1601 CHECK_EQ(42.0, the_number); 1708 CHECK_EQ(42.0, the_number);
1602 v8::Handle<v8::Value> new_boxed_number = 1709 v8::Local<v8::Value> new_boxed_number =
1603 v8::NumberObject::New(env->GetIsolate(), 43); 1710 v8::NumberObject::New(env->GetIsolate(), 43);
1604 CHECK(new_boxed_number->IsNumberObject()); 1711 CHECK(new_boxed_number->IsNumberObject());
1605 as_boxed = new_boxed_number.As<v8::NumberObject>(); 1712 as_boxed = new_boxed_number.As<v8::NumberObject>();
1606 the_number = as_boxed->ValueOf(); 1713 the_number = as_boxed->ValueOf();
1607 CHECK_EQ(43.0, the_number); 1714 CHECK_EQ(43.0, the_number);
1608 } 1715 }
1609 1716
1610 1717
1611 THREADED_TEST(BooleanObject) { 1718 THREADED_TEST(BooleanObject) {
1612 LocalContext env; 1719 LocalContext env;
1613 v8::HandleScope scope(env->GetIsolate()); 1720 v8::HandleScope scope(env->GetIsolate());
1614 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)"); 1721 v8::Local<Value> boxed_boolean = CompileRun("new Boolean(true)");
1615 CHECK(boxed_boolean->IsBooleanObject()); 1722 CHECK(boxed_boolean->IsBooleanObject());
1616 v8::Handle<Value> unboxed_boolean = CompileRun("true"); 1723 v8::Local<Value> unboxed_boolean = CompileRun("true");
1617 CHECK(!unboxed_boolean->IsBooleanObject()); 1724 CHECK(!unboxed_boolean->IsBooleanObject());
1618 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)"); 1725 v8::Local<Value> boxed_not_boolean = CompileRun("new Number(42)");
1619 CHECK(!boxed_not_boolean->IsBooleanObject()); 1726 CHECK(!boxed_not_boolean->IsBooleanObject());
1620 v8::Handle<v8::BooleanObject> as_boxed = 1727 v8::Local<v8::BooleanObject> as_boxed = boxed_boolean.As<v8::BooleanObject>();
1621 boxed_boolean.As<v8::BooleanObject>();
1622 CHECK(!as_boxed.IsEmpty()); 1728 CHECK(!as_boxed.IsEmpty());
1623 bool the_boolean = as_boxed->ValueOf(); 1729 bool the_boolean = as_boxed->ValueOf();
1624 CHECK_EQ(true, the_boolean); 1730 CHECK_EQ(true, the_boolean);
1625 v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true); 1731 v8::Local<v8::Value> boxed_true = v8::BooleanObject::New(true);
1626 v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false); 1732 v8::Local<v8::Value> boxed_false = v8::BooleanObject::New(false);
1627 CHECK(boxed_true->IsBooleanObject()); 1733 CHECK(boxed_true->IsBooleanObject());
1628 CHECK(boxed_false->IsBooleanObject()); 1734 CHECK(boxed_false->IsBooleanObject());
1629 as_boxed = boxed_true.As<v8::BooleanObject>(); 1735 as_boxed = boxed_true.As<v8::BooleanObject>();
1630 CHECK_EQ(true, as_boxed->ValueOf()); 1736 CHECK_EQ(true, as_boxed->ValueOf());
1631 as_boxed = boxed_false.As<v8::BooleanObject>(); 1737 as_boxed = boxed_false.As<v8::BooleanObject>();
1632 CHECK_EQ(false, as_boxed->ValueOf()); 1738 CHECK_EQ(false, as_boxed->ValueOf());
1633 } 1739 }
1634 1740
1635 1741
1636 THREADED_TEST(PrimitiveAndWrappedBooleans) { 1742 THREADED_TEST(PrimitiveAndWrappedBooleans) {
1637 LocalContext env; 1743 LocalContext env;
1638 v8::HandleScope scope(env->GetIsolate()); 1744 v8::HandleScope scope(env->GetIsolate());
1639 1745
1640 Local<Value> primitive_false = Boolean::New(env->GetIsolate(), false); 1746 Local<Value> primitive_false = Boolean::New(env->GetIsolate(), false);
1641 CHECK(primitive_false->IsBoolean()); 1747 CHECK(primitive_false->IsBoolean());
1642 CHECK(!primitive_false->IsBooleanObject()); 1748 CHECK(!primitive_false->IsBooleanObject());
1643 CHECK(!primitive_false->BooleanValue()); 1749 CHECK(!primitive_false->BooleanValue(env.local()).FromJust());
1644 CHECK(!primitive_false->IsTrue()); 1750 CHECK(!primitive_false->IsTrue());
1645 CHECK(primitive_false->IsFalse()); 1751 CHECK(primitive_false->IsFalse());
1646 1752
1647 Local<Value> false_value = BooleanObject::New(false); 1753 Local<Value> false_value = BooleanObject::New(false);
1648 CHECK(!false_value->IsBoolean()); 1754 CHECK(!false_value->IsBoolean());
1649 CHECK(false_value->IsBooleanObject()); 1755 CHECK(false_value->IsBooleanObject());
1650 CHECK(false_value->BooleanValue()); 1756 CHECK(false_value->BooleanValue(env.local()).FromJust());
1651 CHECK(!false_value->IsTrue()); 1757 CHECK(!false_value->IsTrue());
1652 CHECK(!false_value->IsFalse()); 1758 CHECK(!false_value->IsFalse());
1653 1759
1654 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>(); 1760 Local<BooleanObject> false_boolean_object = false_value.As<BooleanObject>();
1655 CHECK(!false_boolean_object->IsBoolean()); 1761 CHECK(!false_boolean_object->IsBoolean());
1656 CHECK(false_boolean_object->IsBooleanObject()); 1762 CHECK(false_boolean_object->IsBooleanObject());
1657 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted. 1763 CHECK(false_boolean_object->BooleanValue(env.local()).FromJust());
1658 // CHECK(false_boolean_object->BooleanValue());
1659 CHECK(!false_boolean_object->ValueOf()); 1764 CHECK(!false_boolean_object->ValueOf());
1660 CHECK(!false_boolean_object->IsTrue()); 1765 CHECK(!false_boolean_object->IsTrue());
1661 CHECK(!false_boolean_object->IsFalse()); 1766 CHECK(!false_boolean_object->IsFalse());
1662 1767
1663 Local<Value> primitive_true = Boolean::New(env->GetIsolate(), true); 1768 Local<Value> primitive_true = Boolean::New(env->GetIsolate(), true);
1664 CHECK(primitive_true->IsBoolean()); 1769 CHECK(primitive_true->IsBoolean());
1665 CHECK(!primitive_true->IsBooleanObject()); 1770 CHECK(!primitive_true->IsBooleanObject());
1666 CHECK(primitive_true->BooleanValue()); 1771 CHECK(primitive_true->BooleanValue(env.local()).FromJust());
1667 CHECK(primitive_true->IsTrue()); 1772 CHECK(primitive_true->IsTrue());
1668 CHECK(!primitive_true->IsFalse()); 1773 CHECK(!primitive_true->IsFalse());
1669 1774
1670 Local<Value> true_value = BooleanObject::New(true); 1775 Local<Value> true_value = BooleanObject::New(true);
1671 CHECK(!true_value->IsBoolean()); 1776 CHECK(!true_value->IsBoolean());
1672 CHECK(true_value->IsBooleanObject()); 1777 CHECK(true_value->IsBooleanObject());
1673 CHECK(true_value->BooleanValue()); 1778 CHECK(true_value->BooleanValue(env.local()).FromJust());
1674 CHECK(!true_value->IsTrue()); 1779 CHECK(!true_value->IsTrue());
1675 CHECK(!true_value->IsFalse()); 1780 CHECK(!true_value->IsFalse());
1676 1781
1677 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>(); 1782 Local<BooleanObject> true_boolean_object = true_value.As<BooleanObject>();
1678 CHECK(!true_boolean_object->IsBoolean()); 1783 CHECK(!true_boolean_object->IsBoolean());
1679 CHECK(true_boolean_object->IsBooleanObject()); 1784 CHECK(true_boolean_object->IsBooleanObject());
1680 // TODO(svenpanne) Uncomment when BooleanObject::BooleanValue() is deleted. 1785 CHECK(true_boolean_object->BooleanValue(env.local()).FromJust());
1681 // CHECK(true_boolean_object->BooleanValue());
1682 CHECK(true_boolean_object->ValueOf()); 1786 CHECK(true_boolean_object->ValueOf());
1683 CHECK(!true_boolean_object->IsTrue()); 1787 CHECK(!true_boolean_object->IsTrue());
1684 CHECK(!true_boolean_object->IsFalse()); 1788 CHECK(!true_boolean_object->IsFalse());
1685 } 1789 }
1686 1790
1687 1791
1688 THREADED_TEST(Number) { 1792 THREADED_TEST(Number) {
1689 LocalContext env; 1793 LocalContext env;
1690 v8::HandleScope scope(env->GetIsolate()); 1794 v8::HandleScope scope(env->GetIsolate());
1691 double PI = 3.1415926; 1795 double PI = 3.1415926;
1692 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI); 1796 Local<v8::Number> pi_obj = v8::Number::New(env->GetIsolate(), PI);
1693 CHECK_EQ(PI, pi_obj->NumberValue()); 1797 CHECK_EQ(PI, pi_obj->NumberValue(env.local()).FromJust());
1694 } 1798 }
1695 1799
1696 1800
1697 THREADED_TEST(ToNumber) { 1801 THREADED_TEST(ToNumber) {
1698 LocalContext env; 1802 LocalContext env;
1699 v8::Isolate* isolate = CcTest::isolate(); 1803 v8::Isolate* isolate = CcTest::isolate();
1700 v8::HandleScope scope(isolate); 1804 v8::HandleScope scope(isolate);
1701 Local<String> str = v8_str("3.1415926"); 1805 Local<String> str = v8_str("3.1415926");
1702 CHECK_EQ(3.1415926, str->NumberValue()); 1806 CHECK_EQ(3.1415926, str->NumberValue(env.local()).FromJust());
1703 v8::Handle<v8::Boolean> t = v8::True(isolate); 1807 v8::Local<v8::Boolean> t = v8::True(isolate);
1704 CHECK_EQ(1.0, t->NumberValue()); 1808 CHECK_EQ(1.0, t->NumberValue(env.local()).FromJust());
1705 v8::Handle<v8::Boolean> f = v8::False(isolate); 1809 v8::Local<v8::Boolean> f = v8::False(isolate);
1706 CHECK_EQ(0.0, f->NumberValue()); 1810 CHECK_EQ(0.0, f->NumberValue(env.local()).FromJust());
1707 } 1811 }
1708 1812
1709 1813
1710 THREADED_TEST(Date) { 1814 THREADED_TEST(Date) {
1711 LocalContext env; 1815 LocalContext env;
1712 v8::HandleScope scope(env->GetIsolate()); 1816 v8::HandleScope scope(env->GetIsolate());
1713 double PI = 3.1415926; 1817 double PI = 3.1415926;
1714 Local<Value> date = v8::Date::New(env->GetIsolate(), PI); 1818 Local<Value> date = v8::Date::New(env.local(), PI).ToLocalChecked();
1715 CHECK_EQ(3.0, date->NumberValue()); 1819 CHECK_EQ(3.0, date->NumberValue(env.local()).FromJust());
1716 date.As<v8::Date>()->Set(v8_str("property"), 1820 CHECK(date.As<v8::Date>()
1717 v8::Integer::New(env->GetIsolate(), 42)); 1821 ->Set(env.local(), v8_str("property"),
1718 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); 1822 v8::Integer::New(env->GetIsolate(), 42))
1823 .FromJust());
1824 CHECK_EQ(42, date.As<v8::Date>()
1825 ->Get(env.local(), v8_str("property"))
1826 .ToLocalChecked()
1827 ->Int32Value(env.local())
1828 .FromJust());
1719 } 1829 }
1720 1830
1721 1831
1722 THREADED_TEST(Boolean) { 1832 THREADED_TEST(Boolean) {
1723 LocalContext env; 1833 LocalContext env;
1724 v8::Isolate* isolate = env->GetIsolate(); 1834 v8::Isolate* isolate = env->GetIsolate();
1725 v8::HandleScope scope(isolate); 1835 v8::HandleScope scope(isolate);
1726 v8::Handle<v8::Boolean> t = v8::True(isolate); 1836 v8::Local<v8::Boolean> t = v8::True(isolate);
1727 CHECK(t->Value()); 1837 CHECK(t->Value());
1728 v8::Handle<v8::Boolean> f = v8::False(isolate); 1838 v8::Local<v8::Boolean> f = v8::False(isolate);
1729 CHECK(!f->Value()); 1839 CHECK(!f->Value());
1730 v8::Handle<v8::Primitive> u = v8::Undefined(isolate); 1840 v8::Local<v8::Primitive> u = v8::Undefined(isolate);
1731 CHECK(!u->BooleanValue()); 1841 CHECK(!u->BooleanValue(env.local()).FromJust());
1732 v8::Handle<v8::Primitive> n = v8::Null(isolate); 1842 v8::Local<v8::Primitive> n = v8::Null(isolate);
1733 CHECK(!n->BooleanValue()); 1843 CHECK(!n->BooleanValue(env.local()).FromJust());
1734 v8::Handle<String> str1 = v8_str(""); 1844 v8::Local<String> str1 = v8_str("");
1735 CHECK(!str1->BooleanValue()); 1845 CHECK(!str1->BooleanValue(env.local()).FromJust());
1736 v8::Handle<String> str2 = v8_str("x"); 1846 v8::Local<String> str2 = v8_str("x");
1737 CHECK(str2->BooleanValue()); 1847 CHECK(str2->BooleanValue(env.local()).FromJust());
1738 CHECK(!v8::Number::New(isolate, 0)->BooleanValue()); 1848 CHECK(!v8::Number::New(isolate, 0)->BooleanValue(env.local()).FromJust());
1739 CHECK(v8::Number::New(isolate, -1)->BooleanValue()); 1849 CHECK(v8::Number::New(isolate, -1)->BooleanValue(env.local()).FromJust());
1740 CHECK(v8::Number::New(isolate, 1)->BooleanValue()); 1850 CHECK(v8::Number::New(isolate, 1)->BooleanValue(env.local()).FromJust());
1741 CHECK(v8::Number::New(isolate, 42)->BooleanValue()); 1851 CHECK(v8::Number::New(isolate, 42)->BooleanValue(env.local()).FromJust());
1742 CHECK(!v8_compile("NaN")->Run()->BooleanValue()); 1852 CHECK(!v8_compile("NaN")
1853 ->Run(env.local())
1854 .ToLocalChecked()
1855 ->BooleanValue(env.local())
1856 .FromJust());
1743 } 1857 }
1744 1858
1745 1859
1746 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) { 1860 static void DummyCallHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {
1747 ApiTestFuzzer::Fuzz(); 1861 ApiTestFuzzer::Fuzz();
1748 args.GetReturnValue().Set(v8_num(13.4)); 1862 args.GetReturnValue().Set(v8_num(13.4));
1749 } 1863 }
1750 1864
1751 1865
1752 static void GetM(Local<String> name, 1866 static void GetM(Local<String> name,
1753 const v8::PropertyCallbackInfo<v8::Value>& info) { 1867 const v8::PropertyCallbackInfo<v8::Value>& info) {
1754 ApiTestFuzzer::Fuzz(); 1868 ApiTestFuzzer::Fuzz();
1755 info.GetReturnValue().Set(v8_num(876)); 1869 info.GetReturnValue().Set(v8_num(876));
1756 } 1870 }
1757 1871
1758 1872
1759 THREADED_TEST(GlobalPrototype) { 1873 THREADED_TEST(GlobalPrototype) {
1760 v8::Isolate* isolate = CcTest::isolate(); 1874 v8::Isolate* isolate = CcTest::isolate();
1761 v8::HandleScope scope(isolate); 1875 v8::HandleScope scope(isolate);
1762 v8::Handle<v8::FunctionTemplate> func_templ = 1876 v8::Local<v8::FunctionTemplate> func_templ =
1763 v8::FunctionTemplate::New(isolate); 1877 v8::FunctionTemplate::New(isolate);
1764 func_templ->PrototypeTemplate()->Set( 1878 func_templ->PrototypeTemplate()->Set(
1765 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler)); 1879 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler));
1766 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1880 v8::Local<ObjectTemplate> templ = func_templ->InstanceTemplate();
1767 templ->Set(isolate, "x", v8_num(200)); 1881 templ->Set(isolate, "x", v8_num(200));
1768 templ->SetAccessor(v8_str("m"), GetM); 1882 templ->SetAccessor(v8_str("m"), GetM);
1769 LocalContext env(0, templ); 1883 LocalContext env(0, templ);
1770 v8::Handle<Script> script(v8_compile("dummy()")); 1884 v8::Local<Script> script(v8_compile("dummy()"));
1771 v8::Handle<Value> result(script->Run()); 1885 v8::Local<Value> result(script->Run(env.local()).ToLocalChecked());
1772 CHECK_EQ(13.4, result->NumberValue()); 1886 CHECK_EQ(13.4, result->NumberValue(env.local()).FromJust());
1773 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1887 CHECK_EQ(200, v8_run_int32value(v8_compile("x")));
1774 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1888 CHECK_EQ(876, v8_run_int32value(v8_compile("m")));
1775 } 1889 }
1776 1890
1777 1891
1778 THREADED_TEST(ObjectTemplate) { 1892 THREADED_TEST(ObjectTemplate) {
1779 v8::Isolate* isolate = CcTest::isolate(); 1893 v8::Isolate* isolate = CcTest::isolate();
1780 v8::HandleScope scope(isolate); 1894 v8::HandleScope scope(isolate);
1781 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate); 1895 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
1782 v8::Local<v8::String> class_name = 1896 v8::Local<v8::String> class_name = v8_str("the_class_name");
1783 v8::String::NewFromUtf8(isolate, "the_class_name");
1784 fun->SetClassName(class_name); 1897 fun->SetClassName(class_name);
1785 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun); 1898 Local<ObjectTemplate> templ1 = ObjectTemplate::New(isolate, fun);
1786 templ1->Set(isolate, "x", v8_num(10)); 1899 templ1->Set(isolate, "x", v8_num(10));
1787 templ1->Set(isolate, "y", v8_num(13)); 1900 templ1->Set(isolate, "y", v8_num(13));
1788 LocalContext env; 1901 LocalContext env;
1789 Local<v8::Object> instance1 = templ1->NewInstance(); 1902 Local<v8::Object> instance1 =
1903 templ1->NewInstance(env.local()).ToLocalChecked();
1790 CHECK(class_name->StrictEquals(instance1->GetConstructorName())); 1904 CHECK(class_name->StrictEquals(instance1->GetConstructorName()));
1791 env->Global()->Set(v8_str("p"), instance1); 1905 CHECK(env->Global()->Set(env.local(), v8_str("p"), instance1).FromJust());
1792 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1906 CHECK(v8_compile("(p.x == 10)")
1793 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1907 ->Run(env.local())
1908 .ToLocalChecked()
1909 ->BooleanValue(env.local())
1910 .FromJust());
1911 CHECK(v8_compile("(p.y == 13)")
1912 ->Run(env.local())
1913 .ToLocalChecked()
1914 ->BooleanValue(env.local())
1915 .FromJust());
1794 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate); 1916 Local<v8::FunctionTemplate> fun2 = v8::FunctionTemplate::New(isolate);
1795 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123)); 1917 fun2->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1796 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate(); 1918 Local<ObjectTemplate> templ2 = fun2->InstanceTemplate();
1797 templ2->Set(isolate, "a", v8_num(12)); 1919 templ2->Set(isolate, "a", v8_num(12));
1798 templ2->Set(isolate, "b", templ1); 1920 templ2->Set(isolate, "b", templ1);
1799 Local<v8::Object> instance2 = templ2->NewInstance(); 1921 Local<v8::Object> instance2 =
1800 env->Global()->Set(v8_str("q"), instance2); 1922 templ2->NewInstance(env.local()).ToLocalChecked();
1801 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); 1923 CHECK(env->Global()->Set(env.local(), v8_str("q"), instance2).FromJust());
1802 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); 1924 CHECK(v8_compile("(q.nirk == 123)")
1803 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); 1925 ->Run(env.local())
1804 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); 1926 .ToLocalChecked()
1927 ->BooleanValue(env.local())
1928 .FromJust());
1929 CHECK(v8_compile("(q.a == 12)")
1930 ->Run(env.local())
1931 .ToLocalChecked()
1932 ->BooleanValue(env.local())
1933 .FromJust());
1934 CHECK(v8_compile("(q.b.x == 10)")
1935 ->Run(env.local())
1936 .ToLocalChecked()
1937 ->BooleanValue(env.local())
1938 .FromJust());
1939 CHECK(v8_compile("(q.b.y == 13)")
1940 ->Run(env.local())
1941 .ToLocalChecked()
1942 ->BooleanValue(env.local())
1943 .FromJust());
1805 } 1944 }
1806 1945
1807 1946
1808 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 1947 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1809 ApiTestFuzzer::Fuzz(); 1948 ApiTestFuzzer::Fuzz();
1810 args.GetReturnValue().Set(v8_num(17.2)); 1949 args.GetReturnValue().Set(v8_num(17.2));
1811 } 1950 }
1812 1951
1813 1952
1814 static void GetKnurd(Local<String> property, 1953 static void GetKnurd(Local<String> property,
1815 const v8::PropertyCallbackInfo<v8::Value>& info) { 1954 const v8::PropertyCallbackInfo<v8::Value>& info) {
1816 ApiTestFuzzer::Fuzz(); 1955 ApiTestFuzzer::Fuzz();
1817 info.GetReturnValue().Set(v8_num(15.2)); 1956 info.GetReturnValue().Set(v8_num(15.2));
1818 } 1957 }
1819 1958
1820 1959
1821 THREADED_TEST(DescriptorInheritance) { 1960 THREADED_TEST(DescriptorInheritance) {
1822 v8::Isolate* isolate = CcTest::isolate(); 1961 v8::Isolate* isolate = CcTest::isolate();
1823 v8::HandleScope scope(isolate); 1962 v8::HandleScope scope(isolate);
1824 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate); 1963 v8::Local<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate);
1825 super->PrototypeTemplate()->Set(isolate, "flabby", 1964 super->PrototypeTemplate()->Set(isolate, "flabby",
1826 v8::FunctionTemplate::New(isolate, 1965 v8::FunctionTemplate::New(isolate,
1827 GetFlabby)); 1966 GetFlabby));
1828 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14)); 1967 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14));
1829 1968
1830 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); 1969 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd);
1831 1970
1832 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate); 1971 v8::Local<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate);
1833 base1->Inherit(super); 1972 base1->Inherit(super);
1834 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1)); 1973 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1));
1835 1974
1836 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate); 1975 v8::Local<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate);
1837 base2->Inherit(super); 1976 base2->Inherit(super);
1838 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1)); 1977 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1));
1839 1978
1840 LocalContext env; 1979 LocalContext env;
1841 1980
1842 env->Global()->Set(v8_str("s"), super->GetFunction()); 1981 CHECK(env->Global()
1843 env->Global()->Set(v8_str("base1"), base1->GetFunction()); 1982 ->Set(env.local(), v8_str("s"),
1844 env->Global()->Set(v8_str("base2"), base2->GetFunction()); 1983 super->GetFunction(env.local()).ToLocalChecked())
1984 .FromJust());
1985 CHECK(env->Global()
1986 ->Set(env.local(), v8_str("base1"),
1987 base1->GetFunction(env.local()).ToLocalChecked())
1988 .FromJust());
1989 CHECK(env->Global()
1990 ->Set(env.local(), v8_str("base2"),
1991 base2->GetFunction(env.local()).ToLocalChecked())
1992 .FromJust());
1845 1993
1846 // Checks right __proto__ chain. 1994 // Checks right __proto__ chain.
1847 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); 1995 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")
1848 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); 1996 ->BooleanValue(env.local())
1997 .FromJust());
1998 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")
1999 ->BooleanValue(env.local())
2000 .FromJust());
1849 2001
1850 CHECK(v8_compile("s.prototype.PI == 3.14")->Run()->BooleanValue()); 2002 CHECK(v8_compile("s.prototype.PI == 3.14")
2003 ->Run(env.local())
2004 .ToLocalChecked()
2005 ->BooleanValue(env.local())
2006 .FromJust());
1851 2007
1852 // Instance accessor should not be visible on function object or its prototype 2008 // Instance accessor should not be visible on function object or its prototype
1853 CHECK(CompileRun("s.knurd == undefined")->BooleanValue()); 2009 CHECK(
1854 CHECK(CompileRun("s.prototype.knurd == undefined")->BooleanValue()); 2010 CompileRun("s.knurd == undefined")->BooleanValue(env.local()).FromJust());
1855 CHECK(CompileRun("base1.prototype.knurd == undefined")->BooleanValue()); 2011 CHECK(CompileRun("s.prototype.knurd == undefined")
2012 ->BooleanValue(env.local())
2013 .FromJust());
2014 CHECK(CompileRun("base1.prototype.knurd == undefined")
2015 ->BooleanValue(env.local())
2016 .FromJust());
1856 2017
1857 env->Global()->Set(v8_str("obj"), 2018 CHECK(env->Global()
1858 base1->GetFunction()->NewInstance()); 2019 ->Set(env.local(), v8_str("obj"), base1->GetFunction(env.local())
1859 CHECK_EQ(17.2, v8_compile("obj.flabby()")->Run()->NumberValue()); 2020 .ToLocalChecked()
1860 CHECK(v8_compile("'flabby' in obj")->Run()->BooleanValue()); 2021 ->NewInstance(env.local())
1861 CHECK_EQ(15.2, v8_compile("obj.knurd")->Run()->NumberValue()); 2022 .ToLocalChecked())
1862 CHECK(v8_compile("'knurd' in obj")->Run()->BooleanValue()); 2023 .FromJust());
1863 CHECK_EQ(20.1, v8_compile("obj.v1")->Run()->NumberValue()); 2024 CHECK_EQ(17.2, v8_compile("obj.flabby()")
2025 ->Run(env.local())
2026 .ToLocalChecked()
2027 ->NumberValue(env.local())
2028 .FromJust());
2029 CHECK(v8_compile("'flabby' in obj")
2030 ->Run(env.local())
2031 .ToLocalChecked()
2032 ->BooleanValue(env.local())
2033 .FromJust());
2034 CHECK_EQ(15.2, v8_compile("obj.knurd")
2035 ->Run(env.local())
2036 .ToLocalChecked()
2037 ->NumberValue(env.local())
2038 .FromJust());
2039 CHECK(v8_compile("'knurd' in obj")
2040 ->Run(env.local())
2041 .ToLocalChecked()
2042 ->BooleanValue(env.local())
2043 .FromJust());
2044 CHECK_EQ(20.1, v8_compile("obj.v1")
2045 ->Run(env.local())
2046 .ToLocalChecked()
2047 ->NumberValue(env.local())
2048 .FromJust());
1864 2049
1865 env->Global()->Set(v8_str("obj2"), 2050 CHECK(env->Global()
1866 base2->GetFunction()->NewInstance()); 2051 ->Set(env.local(), v8_str("obj2"), base2->GetFunction(env.local())
1867 CHECK_EQ(17.2, v8_compile("obj2.flabby()")->Run()->NumberValue()); 2052 .ToLocalChecked()
1868 CHECK(v8_compile("'flabby' in obj2")->Run()->BooleanValue()); 2053 ->NewInstance(env.local())
1869 CHECK_EQ(15.2, v8_compile("obj2.knurd")->Run()->NumberValue()); 2054 .ToLocalChecked())
1870 CHECK(v8_compile("'knurd' in obj2")->Run()->BooleanValue()); 2055 .FromJust());
1871 CHECK_EQ(10.1, v8_compile("obj2.v2")->Run()->NumberValue()); 2056 CHECK_EQ(17.2, v8_compile("obj2.flabby()")
2057 ->Run(env.local())
2058 .ToLocalChecked()
2059 ->NumberValue(env.local())
2060 .FromJust());
2061 CHECK(v8_compile("'flabby' in obj2")
2062 ->Run(env.local())
2063 .ToLocalChecked()
2064 ->BooleanValue(env.local())
2065 .FromJust());
2066 CHECK_EQ(15.2, v8_compile("obj2.knurd")
2067 ->Run(env.local())
2068 .ToLocalChecked()
2069 ->NumberValue(env.local())
2070 .FromJust());
2071 CHECK(v8_compile("'knurd' in obj2")
2072 ->Run(env.local())
2073 .ToLocalChecked()
2074 ->BooleanValue(env.local())
2075 .FromJust());
2076 CHECK_EQ(10.1, v8_compile("obj2.v2")
2077 ->Run(env.local())
2078 .ToLocalChecked()
2079 ->NumberValue(env.local())
2080 .FromJust());
1872 2081
1873 // base1 and base2 cannot cross reference to each's prototype 2082 // base1 and base2 cannot cross reference to each's prototype
1874 CHECK(v8_compile("obj.v2")->Run()->IsUndefined()); 2083 CHECK(v8_compile("obj.v2")->Run(env.local()).ToLocalChecked()->IsUndefined());
1875 CHECK(v8_compile("obj2.v1")->Run()->IsUndefined()); 2084 CHECK(
2085 v8_compile("obj2.v1")->Run(env.local()).ToLocalChecked()->IsUndefined());
1876 } 2086 }
1877 2087
1878 2088
1879 // Helper functions for Interceptor/Accessor interaction tests 2089 // Helper functions for Interceptor/Accessor interaction tests
1880 2090
1881 void SimpleAccessorGetter(Local<String> name, 2091 void SimpleAccessorGetter(Local<String> name,
1882 const v8::PropertyCallbackInfo<v8::Value>& info) { 2092 const v8::PropertyCallbackInfo<v8::Value>& info) {
1883 Handle<Object> self = Handle<Object>::Cast(info.This()); 2093 Local<Object> self = Local<Object>::Cast(info.This());
1884 info.GetReturnValue().Set( 2094 info.GetReturnValue().Set(self->Get(info.GetIsolate()->GetCurrentContext(),
1885 self->Get(String::Concat(v8_str("accessor_"), name))); 2095 String::Concat(v8_str("accessor_"), name))
2096 .ToLocalChecked());
1886 } 2097 }
1887 2098
1888 void SimpleAccessorSetter(Local<String> name, Local<Value> value, 2099 void SimpleAccessorSetter(Local<String> name, Local<Value> value,
1889 const v8::PropertyCallbackInfo<void>& info) { 2100 const v8::PropertyCallbackInfo<void>& info) {
1890 Handle<Object> self = Handle<Object>::Cast(info.This()); 2101 Local<Object> self = Local<Object>::Cast(info.This());
1891 self->Set(String::Concat(v8_str("accessor_"), name), value); 2102 CHECK(self->Set(info.GetIsolate()->GetCurrentContext(),
2103 String::Concat(v8_str("accessor_"), name), value)
2104 .FromJust());
1892 } 2105 }
1893 2106
1894 void SymbolAccessorGetter(Local<Name> name, 2107 void SymbolAccessorGetter(Local<Name> name,
1895 const v8::PropertyCallbackInfo<v8::Value>& info) { 2108 const v8::PropertyCallbackInfo<v8::Value>& info) {
1896 CHECK(name->IsSymbol()); 2109 CHECK(name->IsSymbol());
1897 Local<Symbol> sym = Local<Symbol>::Cast(name); 2110 Local<Symbol> sym = Local<Symbol>::Cast(name);
1898 if (sym->Name()->IsUndefined()) 2111 if (sym->Name()->IsUndefined())
1899 return; 2112 return;
1900 SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info); 2113 SimpleAccessorGetter(Local<String>::Cast(sym->Name()), info);
1901 } 2114 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 i::Handle<i::String> name(v8::Utils::OpenHandle(*v8_str("length"))); 2150 i::Handle<i::String> name(v8::Utils::OpenHandle(*v8_str("length")));
1938 i::LookupIterator it(a, name, i::LookupIterator::OWN_SKIP_INTERCEPTOR); 2151 i::LookupIterator it(a, name, i::LookupIterator::OWN_SKIP_INTERCEPTOR);
1939 CHECK_EQ(i::LookupIterator::ACCESSOR, it.state()); 2152 CHECK_EQ(i::LookupIterator::ACCESSOR, it.state());
1940 CHECK(it.GetAccessors()->IsExecutableAccessorInfo()); 2153 CHECK(it.GetAccessors()->IsExecutableAccessorInfo());
1941 } 2154 }
1942 2155
1943 2156
1944 THREADED_TEST(UndefinedIsNotEnumerable) { 2157 THREADED_TEST(UndefinedIsNotEnumerable) {
1945 LocalContext env; 2158 LocalContext env;
1946 v8::HandleScope scope(env->GetIsolate()); 2159 v8::HandleScope scope(env->GetIsolate());
1947 v8::Handle<Value> result = CompileRun("this.propertyIsEnumerable(undefined)"); 2160 v8::Local<Value> result = CompileRun("this.propertyIsEnumerable(undefined)");
1948 CHECK(result->IsFalse()); 2161 CHECK(result->IsFalse());
1949 } 2162 }
1950 2163
1951 2164
1952 v8::Handle<Script> call_recursively_script; 2165 v8::Local<Script> call_recursively_script;
1953 static const int kTargetRecursionDepth = 150; // near maximum 2166 static const int kTargetRecursionDepth = 150; // near maximum
1954 2167
1955 2168
1956 static void CallScriptRecursivelyCall( 2169 static void CallScriptRecursivelyCall(
1957 const v8::FunctionCallbackInfo<v8::Value>& args) { 2170 const v8::FunctionCallbackInfo<v8::Value>& args) {
1958 ApiTestFuzzer::Fuzz(); 2171 ApiTestFuzzer::Fuzz();
1959 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2172 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
2173 int depth = args.This()
2174 ->Get(context, v8_str("depth"))
2175 .ToLocalChecked()
2176 ->Int32Value(context)
2177 .FromJust();
1960 if (depth == kTargetRecursionDepth) return; 2178 if (depth == kTargetRecursionDepth) return;
1961 args.This()->Set(v8_str("depth"), 2179 CHECK(args.This()
1962 v8::Integer::New(args.GetIsolate(), depth + 1)); 2180 ->Set(context, v8_str("depth"),
1963 args.GetReturnValue().Set(call_recursively_script->Run()); 2181 v8::Integer::New(args.GetIsolate(), depth + 1))
2182 .FromJust());
2183 args.GetReturnValue().Set(
2184 call_recursively_script->Run(context).ToLocalChecked());
1964 } 2185 }
1965 2186
1966 2187
1967 static void CallFunctionRecursivelyCall( 2188 static void CallFunctionRecursivelyCall(
1968 const v8::FunctionCallbackInfo<v8::Value>& args) { 2189 const v8::FunctionCallbackInfo<v8::Value>& args) {
1969 ApiTestFuzzer::Fuzz(); 2190 ApiTestFuzzer::Fuzz();
1970 int depth = args.This()->Get(v8_str("depth"))->Int32Value(); 2191 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
2192 int depth = args.This()
2193 ->Get(context, v8_str("depth"))
2194 .ToLocalChecked()
2195 ->Int32Value(context)
2196 .FromJust();
1971 if (depth == kTargetRecursionDepth) { 2197 if (depth == kTargetRecursionDepth) {
1972 printf("[depth = %d]\n", depth); 2198 printf("[depth = %d]\n", depth);
1973 return; 2199 return;
1974 } 2200 }
1975 args.This()->Set(v8_str("depth"), 2201 CHECK(args.This()
1976 v8::Integer::New(args.GetIsolate(), depth + 1)); 2202 ->Set(context, v8_str("depth"),
1977 v8::Handle<Value> function = 2203 v8::Integer::New(args.GetIsolate(), depth + 1))
1978 args.This()->Get(v8_str("callFunctionRecursively")); 2204 .FromJust());
1979 args.GetReturnValue().Set( 2205 v8::Local<Value> function =
1980 function.As<Function>()->Call(args.This(), 0, NULL)); 2206 args.This()
2207 ->Get(context, v8_str("callFunctionRecursively"))
2208 .ToLocalChecked();
2209 args.GetReturnValue().Set(function.As<Function>()
2210 ->Call(context, args.This(), 0, NULL)
2211 .ToLocalChecked());
1981 } 2212 }
1982 2213
1983 2214
1984 THREADED_TEST(DeepCrossLanguageRecursion) { 2215 THREADED_TEST(DeepCrossLanguageRecursion) {
1985 v8::Isolate* isolate = CcTest::isolate(); 2216 v8::Isolate* isolate = CcTest::isolate();
1986 v8::HandleScope scope(isolate); 2217 v8::HandleScope scope(isolate);
1987 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); 2218 v8::Local<v8::ObjectTemplate> global = ObjectTemplate::New(isolate);
1988 global->Set(v8_str("callScriptRecursively"), 2219 global->Set(v8_str("callScriptRecursively"),
1989 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall)); 2220 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall));
1990 global->Set(v8_str("callFunctionRecursively"), 2221 global->Set(v8_str("callFunctionRecursively"),
1991 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall)); 2222 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall));
1992 LocalContext env(NULL, global); 2223 LocalContext env(NULL, global);
1993 2224
1994 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2225 CHECK(env->Global()
2226 ->Set(env.local(), v8_str("depth"), v8::Integer::New(isolate, 0))
2227 .FromJust());
1995 call_recursively_script = v8_compile("callScriptRecursively()"); 2228 call_recursively_script = v8_compile("callScriptRecursively()");
1996 call_recursively_script->Run(); 2229 call_recursively_script->Run(env.local()).ToLocalChecked();
1997 call_recursively_script = v8::Handle<Script>(); 2230 call_recursively_script = v8::Local<Script>();
1998 2231
1999 env->Global()->Set(v8_str("depth"), v8::Integer::New(isolate, 0)); 2232 CHECK(env->Global()
2233 ->Set(env.local(), v8_str("depth"), v8::Integer::New(isolate, 0))
2234 .FromJust());
2000 CompileRun("callFunctionRecursively()"); 2235 CompileRun("callFunctionRecursively()");
2001 } 2236 }
2002 2237
2003 2238
2004 static void ThrowingPropertyHandlerGet( 2239 static void ThrowingPropertyHandlerGet(
2005 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) { 2240 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>& info) {
2006 // Since this interceptor is used on "with" objects, the runtime will look up 2241 // Since this interceptor is used on "with" objects, the runtime will look up
2007 // @@unscopables. Punt. 2242 // @@unscopables. Punt.
2008 if (key->IsSymbol()) return; 2243 if (key->IsSymbol()) return;
2009 ApiTestFuzzer::Fuzz(); 2244 ApiTestFuzzer::Fuzz();
2010 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key)); 2245 info.GetReturnValue().Set(info.GetIsolate()->ThrowException(key));
2011 } 2246 }
2012 2247
2013 2248
2014 static void ThrowingPropertyHandlerSet( 2249 static void ThrowingPropertyHandlerSet(
2015 Local<Name> key, Local<Value>, 2250 Local<Name> key, Local<Value>,
2016 const v8::PropertyCallbackInfo<v8::Value>& info) { 2251 const v8::PropertyCallbackInfo<v8::Value>& info) {
2017 info.GetIsolate()->ThrowException(key); 2252 info.GetIsolate()->ThrowException(key);
2018 info.GetReturnValue().SetUndefined(); // not the same as empty handle 2253 info.GetReturnValue().SetUndefined(); // not the same as empty handle
2019 } 2254 }
2020 2255
2021 2256
2022 THREADED_TEST(CallbackExceptionRegression) { 2257 THREADED_TEST(CallbackExceptionRegression) {
2023 v8::Isolate* isolate = CcTest::isolate(); 2258 v8::Isolate* isolate = CcTest::isolate();
2024 v8::HandleScope scope(isolate); 2259 v8::HandleScope scope(isolate);
2025 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 2260 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
2026 obj->SetHandler(v8::NamedPropertyHandlerConfiguration( 2261 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(
2027 ThrowingPropertyHandlerGet, ThrowingPropertyHandlerSet)); 2262 ThrowingPropertyHandlerGet, ThrowingPropertyHandlerSet));
2028 LocalContext env; 2263 LocalContext env;
2029 env->Global()->Set(v8_str("obj"), obj->NewInstance()); 2264 CHECK(env->Global()
2030 v8::Handle<Value> otto = 2265 ->Set(env.local(), v8_str("obj"),
2266 obj->NewInstance(env.local()).ToLocalChecked())
2267 .FromJust());
2268 v8::Local<Value> otto =
2031 CompileRun("try { with (obj) { otto; } } catch (e) { e; }"); 2269 CompileRun("try { with (obj) { otto; } } catch (e) { e; }");
2032 CHECK(v8_str("otto")->Equals(otto)); 2270 CHECK(v8_str("otto")->Equals(env.local(), otto).FromJust());
2033 v8::Handle<Value> netto = 2271 v8::Local<Value> netto =
2034 CompileRun("try { with (obj) { netto = 4; } } catch (e) { e; }"); 2272 CompileRun("try { with (obj) { netto = 4; } } catch (e) { e; }");
2035 CHECK(v8_str("netto")->Equals(netto)); 2273 CHECK(v8_str("netto")->Equals(env.local(), netto).FromJust());
2036 } 2274 }
2037 2275
2038 2276
2039 THREADED_TEST(FunctionPrototype) { 2277 THREADED_TEST(FunctionPrototype) {
2040 v8::Isolate* isolate = CcTest::isolate(); 2278 v8::Isolate* isolate = CcTest::isolate();
2041 v8::HandleScope scope(isolate); 2279 v8::HandleScope scope(isolate);
2042 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate); 2280 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate);
2043 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); 2281 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321));
2044 LocalContext env; 2282 LocalContext env;
2045 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); 2283 CHECK(env->Global()
2284 ->Set(env.local(), v8_str("Foo"),
2285 Foo->GetFunction(env.local()).ToLocalChecked())
2286 .FromJust());
2046 Local<Script> script = v8_compile("Foo.prototype.plak"); 2287 Local<Script> script = v8_compile("Foo.prototype.plak");
2047 CHECK_EQ(script->Run()->Int32Value(), 321); 2288 CHECK_EQ(v8_run_int32value(script), 321);
2048 } 2289 }
2049 2290
2050 2291
2051 THREADED_TEST(InternalFields) { 2292 THREADED_TEST(InternalFields) {
2052 LocalContext env; 2293 LocalContext env;
2053 v8::Isolate* isolate = env->GetIsolate(); 2294 v8::Isolate* isolate = env->GetIsolate();
2054 v8::HandleScope scope(isolate); 2295 v8::HandleScope scope(isolate);
2055 2296
2056 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 2297 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2057 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2298 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2058 instance_templ->SetInternalFieldCount(1); 2299 instance_templ->SetInternalFieldCount(1);
2059 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2300 Local<v8::Object> obj = templ->GetFunction(env.local())
2301 .ToLocalChecked()
2302 ->NewInstance(env.local())
2303 .ToLocalChecked();
2060 CHECK_EQ(1, obj->InternalFieldCount()); 2304 CHECK_EQ(1, obj->InternalFieldCount());
2061 CHECK(obj->GetInternalField(0)->IsUndefined()); 2305 CHECK(obj->GetInternalField(0)->IsUndefined());
2062 obj->SetInternalField(0, v8_num(17)); 2306 obj->SetInternalField(0, v8_num(17));
2063 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 2307 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value(env.local()).FromJust());
2064 } 2308 }
2065 2309
2066 2310
2067 THREADED_TEST(GlobalObjectInternalFields) { 2311 THREADED_TEST(GlobalObjectInternalFields) {
2068 v8::Isolate* isolate = CcTest::isolate(); 2312 v8::Isolate* isolate = CcTest::isolate();
2069 v8::HandleScope scope(isolate); 2313 v8::HandleScope scope(isolate);
2070 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate); 2314 Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(isolate);
2071 global_template->SetInternalFieldCount(1); 2315 global_template->SetInternalFieldCount(1);
2072 LocalContext env(NULL, global_template); 2316 LocalContext env(NULL, global_template);
2073 v8::Handle<v8::Object> global_proxy = env->Global(); 2317 v8::Local<v8::Object> global_proxy = env->Global();
2074 v8::Handle<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>(); 2318 v8::Local<v8::Object> global = global_proxy->GetPrototype().As<v8::Object>();
2075 CHECK_EQ(1, global->InternalFieldCount()); 2319 CHECK_EQ(1, global->InternalFieldCount());
2076 CHECK(global->GetInternalField(0)->IsUndefined()); 2320 CHECK(global->GetInternalField(0)->IsUndefined());
2077 global->SetInternalField(0, v8_num(17)); 2321 global->SetInternalField(0, v8_num(17));
2078 CHECK_EQ(17, global->GetInternalField(0)->Int32Value()); 2322 CHECK_EQ(17, global->GetInternalField(0)->Int32Value(env.local()).FromJust());
2079 } 2323 }
2080 2324
2081 2325
2082 THREADED_TEST(GlobalObjectHasRealIndexedProperty) { 2326 THREADED_TEST(GlobalObjectHasRealIndexedProperty) {
2083 LocalContext env; 2327 LocalContext env;
2084 v8::HandleScope scope(CcTest::isolate()); 2328 v8::HandleScope scope(CcTest::isolate());
2085 2329
2086 v8::Local<v8::Object> global = env->Global(); 2330 v8::Local<v8::Object> global = env->Global();
2087 global->Set(0, v8::String::NewFromUtf8(CcTest::isolate(), "value")); 2331 CHECK(global->Set(env.local(), 0, v8_str("value")).FromJust());
2088 CHECK(global->HasRealIndexedProperty(0)); 2332 CHECK(global->HasRealIndexedProperty(env.local(), 0).FromJust());
2089 } 2333 }
2090 2334
2091 2335
2092 static void CheckAlignedPointerInInternalField(Handle<v8::Object> obj, 2336 static void CheckAlignedPointerInInternalField(Local<v8::Object> obj,
2093 void* value) { 2337 void* value) {
2094 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2338 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2095 obj->SetAlignedPointerInInternalField(0, value); 2339 obj->SetAlignedPointerInInternalField(0, value);
2096 CcTest::heap()->CollectAllGarbage(); 2340 CcTest::heap()->CollectAllGarbage();
2097 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); 2341 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
2098 } 2342 }
2099 2343
2100 2344
2101 THREADED_TEST(InternalFieldsAlignedPointers) { 2345 THREADED_TEST(InternalFieldsAlignedPointers) {
2102 LocalContext env; 2346 LocalContext env;
2103 v8::Isolate* isolate = env->GetIsolate(); 2347 v8::Isolate* isolate = env->GetIsolate();
2104 v8::HandleScope scope(isolate); 2348 v8::HandleScope scope(isolate);
2105 2349
2106 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 2350 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2107 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2351 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2108 instance_templ->SetInternalFieldCount(1); 2352 instance_templ->SetInternalFieldCount(1);
2109 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2353 Local<v8::Object> obj = templ->GetFunction(env.local())
2354 .ToLocalChecked()
2355 ->NewInstance(env.local())
2356 .ToLocalChecked();
2110 CHECK_EQ(1, obj->InternalFieldCount()); 2357 CHECK_EQ(1, obj->InternalFieldCount());
2111 2358
2112 CheckAlignedPointerInInternalField(obj, NULL); 2359 CheckAlignedPointerInInternalField(obj, NULL);
2113 2360
2114 int* heap_allocated = new int[100]; 2361 int* heap_allocated = new int[100];
2115 CheckAlignedPointerInInternalField(obj, heap_allocated); 2362 CheckAlignedPointerInInternalField(obj, heap_allocated);
2116 delete[] heap_allocated; 2363 delete[] heap_allocated;
2117 2364
2118 int stack_allocated[100]; 2365 int stack_allocated[100];
2119 CheckAlignedPointerInInternalField(obj, stack_allocated); 2366 CheckAlignedPointerInInternalField(obj, stack_allocated);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i)); 2409 env->SetAlignedPointerInEmbedderData(i, AlignedTestPointer(i));
2163 } 2410 }
2164 CcTest::heap()->CollectAllGarbage(); 2411 CcTest::heap()->CollectAllGarbage();
2165 for (int i = 0; i < 100; i++) { 2412 for (int i = 0; i < 100; i++) {
2166 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i)); 2413 CHECK_EQ(AlignedTestPointer(i), env->GetAlignedPointerFromEmbedderData(i));
2167 } 2414 }
2168 } 2415 }
2169 2416
2170 2417
2171 static void CheckEmbedderData(LocalContext* env, int index, 2418 static void CheckEmbedderData(LocalContext* env, int index,
2172 v8::Handle<Value> data) { 2419 v8::Local<Value> data) {
2173 (*env)->SetEmbedderData(index, data); 2420 (*env)->SetEmbedderData(index, data);
2174 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data)); 2421 CHECK((*env)->GetEmbedderData(index)->StrictEquals(data));
2175 } 2422 }
2176 2423
2177 2424
2178 THREADED_TEST(EmbedderData) { 2425 THREADED_TEST(EmbedderData) {
2179 LocalContext env; 2426 LocalContext env;
2180 v8::Isolate* isolate = env->GetIsolate(); 2427 v8::Isolate* isolate = env->GetIsolate();
2181 v8::HandleScope scope(isolate); 2428 v8::HandleScope scope(isolate);
2182 2429
2183 CheckEmbedderData( 2430 CheckEmbedderData(&env, 3, v8_str("The quick brown fox jumps"));
2184 &env, 3, v8::String::NewFromUtf8(isolate, "The quick brown fox jumps")); 2431 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)); 2432 CheckEmbedderData(&env, 1, v8::Number::New(isolate, 1.2345));
2188 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true)); 2433 CheckEmbedderData(&env, 0, v8::Boolean::New(isolate, true));
2189 } 2434 }
2190 2435
2191 2436
2437 // TODO(vogelheim): Does this test even make sense in a post-deprecation world?
2438 /*
2192 THREADED_TEST(GetIsolate) { 2439 THREADED_TEST(GetIsolate) {
2193 LocalContext env; 2440 LocalContext env;
2194 v8::Isolate* isolate = env->GetIsolate(); 2441 v8::Isolate* isolate = env->GetIsolate();
2195 v8::HandleScope scope(isolate); 2442 v8::HandleScope scope(isolate);
2196 Local<v8::Object> obj = v8::Object::New(isolate); 2443 Local<v8::Object> obj = v8::Object::New(isolate);
2197 CHECK_EQ(isolate, obj->GetIsolate()); 2444 CHECK_EQ(isolate, obj->GetIsolate());
2198 CHECK_EQ(isolate, CcTest::global()->GetIsolate()); 2445 CHECK_EQ(isolate, CcTest::global()->GetIsolate());
2199 } 2446 }
2447 */
2200 2448
2201 2449
2202 THREADED_TEST(IdentityHash) { 2450 THREADED_TEST(IdentityHash) {
2203 LocalContext env; 2451 LocalContext env;
2204 v8::Isolate* isolate = env->GetIsolate(); 2452 v8::Isolate* isolate = env->GetIsolate();
2205 v8::HandleScope scope(isolate); 2453 v8::HandleScope scope(isolate);
2206 2454
2207 // Ensure that the test starts with an fresh heap to test whether the hash 2455 // Ensure that the test starts with an fresh heap to test whether the hash
2208 // code is based on the address. 2456 // code is based on the address.
2209 CcTest::heap()->CollectAllGarbage(); 2457 CcTest::heap()->CollectAllGarbage();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash()); 2490 CHECK_NE(o1->GetIdentityHash(), o2->GetIdentityHash());
2243 } 2491 }
2244 } 2492 }
2245 2493
2246 2494
2247 void GlobalProxyIdentityHash(bool set_in_js) { 2495 void GlobalProxyIdentityHash(bool set_in_js) {
2248 LocalContext env; 2496 LocalContext env;
2249 v8::Isolate* isolate = env->GetIsolate(); 2497 v8::Isolate* isolate = env->GetIsolate();
2250 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 2498 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
2251 v8::HandleScope scope(isolate); 2499 v8::HandleScope scope(isolate);
2252 Handle<Object> global_proxy = env->Global(); 2500 Local<Object> global_proxy = env->Global();
2253 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy); 2501 i::Handle<i::Object> i_global_proxy = v8::Utils::OpenHandle(*global_proxy);
2254 env->Global()->Set(v8_str("global"), global_proxy); 2502 CHECK(env->Global()
2503 ->Set(env.local(), v8_str("global"), global_proxy)
2504 .FromJust());
2255 i::Handle<i::Object> original_hash; 2505 i::Handle<i::Object> original_hash;
2256 if (set_in_js) { 2506 if (set_in_js) {
2257 CompileRun("var m = new Set(); m.add(global);"); 2507 CompileRun("var m = new Set(); m.add(global);");
2258 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate); 2508 original_hash = i::Handle<i::Object>(i_global_proxy->GetHash(), i_isolate);
2259 } else { 2509 } else {
2260 original_hash = i::Handle<i::Object>( 2510 original_hash = i::Handle<i::Object>(
2261 i::Object::GetOrCreateHash(i_isolate, i_global_proxy)); 2511 i::Object::GetOrCreateHash(i_isolate, i_global_proxy));
2262 } 2512 }
2263 CHECK(original_hash->IsSmi()); 2513 CHECK(original_hash->IsSmi());
2264 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value(); 2514 int32_t hash1 = i::Handle<i::Smi>::cast(original_hash)->value();
2265 // Hash should be retained after being detached. 2515 // Hash should be retained after being detached.
2266 env->DetachGlobal(); 2516 env->DetachGlobal();
2267 int hash2 = global_proxy->GetIdentityHash(); 2517 int hash2 = global_proxy->GetIdentityHash();
2268 CHECK_EQ(hash1, hash2); 2518 CHECK_EQ(hash1, hash2);
2269 { 2519 {
2270 // Re-attach global proxy to a new context, hash should stay the same. 2520 // Re-attach global proxy to a new context, hash should stay the same.
2271 LocalContext env2(NULL, Handle<ObjectTemplate>(), global_proxy); 2521 LocalContext env2(NULL, Local<ObjectTemplate>(), global_proxy);
2272 int hash3 = global_proxy->GetIdentityHash(); 2522 int hash3 = global_proxy->GetIdentityHash();
2273 CHECK_EQ(hash1, hash3); 2523 CHECK_EQ(hash1, hash3);
2274 } 2524 }
2275 } 2525 }
2276 2526
2277 2527
2278 THREADED_TEST(GlobalProxyIdentityHash) { 2528 THREADED_TEST(GlobalProxyIdentityHash) {
2279 GlobalProxyIdentityHash(true); 2529 GlobalProxyIdentityHash(true);
2280 GlobalProxyIdentityHash(false); 2530 GlobalProxyIdentityHash(false);
2281 } 2531 }
2282 2532
2283 2533
2284 TEST(SymbolIdentityHash) { 2534 TEST(SymbolIdentityHash) {
2285 LocalContext env; 2535 LocalContext env;
2286 v8::Isolate* isolate = env->GetIsolate(); 2536 v8::Isolate* isolate = env->GetIsolate();
2287 v8::HandleScope scope(isolate); 2537 v8::HandleScope scope(isolate);
2288 2538
2289 { 2539 {
2290 Local<v8::Symbol> symbol = v8::Symbol::New(isolate); 2540 Local<v8::Symbol> symbol = v8::Symbol::New(isolate);
2291 int hash = symbol->GetIdentityHash(); 2541 int hash = symbol->GetIdentityHash();
2292 int hash1 = symbol->GetIdentityHash(); 2542 int hash1 = symbol->GetIdentityHash();
2293 CHECK_EQ(hash, hash1); 2543 CHECK_EQ(hash, hash1);
2294 CcTest::heap()->CollectAllGarbage(); 2544 CcTest::heap()->CollectAllGarbage();
2295 int hash3 = symbol->GetIdentityHash(); 2545 int hash3 = symbol->GetIdentityHash();
2296 CHECK_EQ(hash, hash3); 2546 CHECK_EQ(hash, hash3);
2297 } 2547 }
2298 2548
2299 { 2549 {
2300 v8::Handle<v8::Symbol> js_symbol = 2550 v8::Local<v8::Symbol> js_symbol =
2301 CompileRun("Symbol('foo')").As<v8::Symbol>(); 2551 CompileRun("Symbol('foo')").As<v8::Symbol>();
2302 int hash = js_symbol->GetIdentityHash(); 2552 int hash = js_symbol->GetIdentityHash();
2303 int hash1 = js_symbol->GetIdentityHash(); 2553 int hash1 = js_symbol->GetIdentityHash();
2304 CHECK_EQ(hash, hash1); 2554 CHECK_EQ(hash, hash1);
2305 CcTest::heap()->CollectAllGarbage(); 2555 CcTest::heap()->CollectAllGarbage();
2306 int hash3 = js_symbol->GetIdentityHash(); 2556 int hash3 = js_symbol->GetIdentityHash();
2307 CHECK_EQ(hash, hash3); 2557 CHECK_EQ(hash, hash3);
2308 } 2558 }
2309 } 2559 }
2310 2560
2311 2561
2312 TEST(StringIdentityHash) { 2562 TEST(StringIdentityHash) {
2313 LocalContext env; 2563 LocalContext env;
2314 v8::Isolate* isolate = env->GetIsolate(); 2564 v8::Isolate* isolate = env->GetIsolate();
2315 v8::HandleScope scope(isolate); 2565 v8::HandleScope scope(isolate);
2316 2566
2317 Local<v8::String> str = v8::String::NewFromUtf8(isolate, "str1"); 2567 Local<v8::String> str = v8_str("str1");
2318 int hash = str->GetIdentityHash(); 2568 int hash = str->GetIdentityHash();
2319 int hash1 = str->GetIdentityHash(); 2569 int hash1 = str->GetIdentityHash();
2320 CHECK_EQ(hash, hash1); 2570 CHECK_EQ(hash, hash1);
2321 CcTest::heap()->CollectAllGarbage(); 2571 CcTest::heap()->CollectAllGarbage();
2322 int hash3 = str->GetIdentityHash(); 2572 int hash3 = str->GetIdentityHash();
2323 CHECK_EQ(hash, hash3); 2573 CHECK_EQ(hash, hash3);
2324 2574
2325 Local<v8::String> str2 = v8::String::NewFromUtf8(isolate, "str1"); 2575 Local<v8::String> str2 = v8_str("str1");
2326 int hash4 = str2->GetIdentityHash(); 2576 int hash4 = str2->GetIdentityHash();
2327 CHECK_EQ(hash, hash4); 2577 CHECK_EQ(hash, hash4);
2328 } 2578 }
2329 2579
2330 2580
2331 THREADED_TEST(SymbolProperties) { 2581 THREADED_TEST(SymbolProperties) {
2332 LocalContext env; 2582 LocalContext env;
2333 v8::Isolate* isolate = env->GetIsolate(); 2583 v8::Isolate* isolate = env->GetIsolate();
2334 v8::HandleScope scope(isolate); 2584 v8::HandleScope scope(isolate);
2335 2585
2336 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2586 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2337 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); 2587 v8::Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
2338 v8::Local<v8::Symbol> sym2 = v8::Symbol::New(isolate, v8_str("my-symbol")); 2588 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")); 2589 v8::Local<v8::Symbol> sym3 = v8::Symbol::New(isolate, v8_str("sym3"));
2340 2590
2341 CcTest::heap()->CollectAllGarbage(); 2591 CcTest::heap()->CollectAllGarbage();
2342 2592
2343 // Check basic symbol functionality. 2593 // Check basic symbol functionality.
2344 CHECK(sym1->IsSymbol()); 2594 CHECK(sym1->IsSymbol());
2345 CHECK(sym2->IsSymbol()); 2595 CHECK(sym2->IsSymbol());
2346 CHECK(!obj->IsSymbol()); 2596 CHECK(!obj->IsSymbol());
2347 2597
2348 CHECK(sym1->Equals(sym1)); 2598 CHECK(sym1->Equals(env.local(), sym1).FromJust());
2349 CHECK(sym2->Equals(sym2)); 2599 CHECK(sym2->Equals(env.local(), sym2).FromJust());
2350 CHECK(!sym1->Equals(sym2)); 2600 CHECK(!sym1->Equals(env.local(), sym2).FromJust());
2351 CHECK(!sym2->Equals(sym1)); 2601 CHECK(!sym2->Equals(env.local(), sym1).FromJust());
2352 CHECK(sym1->StrictEquals(sym1)); 2602 CHECK(sym1->StrictEquals(sym1));
2353 CHECK(sym2->StrictEquals(sym2)); 2603 CHECK(sym2->StrictEquals(sym2));
2354 CHECK(!sym1->StrictEquals(sym2)); 2604 CHECK(!sym1->StrictEquals(sym2));
2355 CHECK(!sym2->StrictEquals(sym1)); 2605 CHECK(!sym2->StrictEquals(sym1));
2356 2606
2357 CHECK(sym2->Name()->Equals(v8_str("my-symbol"))); 2607 CHECK(sym2->Name()->Equals(env.local(), v8_str("my-symbol")).FromJust());
2358 2608
2359 v8::Local<v8::Value> sym_val = sym2; 2609 v8::Local<v8::Value> sym_val = sym2;
2360 CHECK(sym_val->IsSymbol()); 2610 CHECK(sym_val->IsSymbol());
2361 CHECK(sym_val->Equals(sym2)); 2611 CHECK(sym_val->Equals(env.local(), sym2).FromJust());
2362 CHECK(sym_val->StrictEquals(sym2)); 2612 CHECK(sym_val->StrictEquals(sym2));
2363 CHECK(v8::Symbol::Cast(*sym_val)->Equals(sym2)); 2613 CHECK(v8::Symbol::Cast(*sym_val)->Equals(env.local(), sym2).FromJust());
2364 2614
2365 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2); 2615 v8::Local<v8::Value> sym_obj = v8::SymbolObject::New(isolate, sym2);
2366 CHECK(sym_obj->IsSymbolObject()); 2616 CHECK(sym_obj->IsSymbolObject());
2367 CHECK(!sym2->IsSymbolObject()); 2617 CHECK(!sym2->IsSymbolObject());
2368 CHECK(!obj->IsSymbolObject()); 2618 CHECK(!obj->IsSymbolObject());
2369 CHECK(sym_obj->Equals(sym2)); 2619 CHECK(sym_obj->Equals(env.local(), sym2).FromJust());
2370 CHECK(!sym_obj->StrictEquals(sym2)); 2620 CHECK(!sym_obj->StrictEquals(sym2));
2371 CHECK(v8::SymbolObject::Cast(*sym_obj)->Equals(sym_obj)); 2621 CHECK(v8::SymbolObject::Cast(*sym_obj)
2372 CHECK(v8::SymbolObject::Cast(*sym_obj)->ValueOf()->Equals(sym2)); 2622 ->Equals(env.local(), sym_obj)
2623 .FromJust());
2624 CHECK(v8::SymbolObject::Cast(*sym_obj)
2625 ->ValueOf()
2626 ->Equals(env.local(), sym2)
2627 .FromJust());
2373 2628
2374 // Make sure delete of a non-existent symbol property works. 2629 // Make sure delete of a non-existent symbol property works.
2375 CHECK(obj->Delete(sym1)); 2630 CHECK(obj->Delete(env.local(), sym1).FromJust());
2376 CHECK(!obj->Has(sym1)); 2631 CHECK(!obj->Has(env.local(), sym1).FromJust());
2377 2632
2378 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 1503))); 2633 CHECK(
2379 CHECK(obj->Has(sym1)); 2634 obj->Set(env.local(), sym1, v8::Integer::New(isolate, 1503)).FromJust());
2380 CHECK_EQ(1503, obj->Get(sym1)->Int32Value()); 2635 CHECK(obj->Has(env.local(), sym1).FromJust());
2381 CHECK(obj->Set(sym1, v8::Integer::New(isolate, 2002))); 2636 CHECK_EQ(1503, obj->Get(env.local(), sym1)
2382 CHECK(obj->Has(sym1)); 2637 .ToLocalChecked()
2383 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2638 ->Int32Value(env.local())
2384 CHECK_EQ(v8::None, obj->GetPropertyAttributes(sym1)); 2639 .FromJust());
2640 CHECK(
2641 obj->Set(env.local(), sym1, v8::Integer::New(isolate, 2002)).FromJust());
2642 CHECK(obj->Has(env.local(), sym1).FromJust());
2643 CHECK_EQ(2002, obj->Get(env.local(), sym1)
2644 .ToLocalChecked()
2645 ->Int32Value(env.local())
2646 .FromJust());
2647 CHECK_EQ(v8::None, obj->GetPropertyAttributes(env.local(), sym1).FromJust());
2385 2648
2386 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); 2649 CHECK_EQ(0u,
2387 unsigned num_props = obj->GetPropertyNames()->Length(); 2650 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2388 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), 2651 unsigned num_props =
2389 v8::Integer::New(isolate, 20))); 2652 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length();
2390 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); 2653 CHECK(obj->Set(env.local(), v8_str("bla"), v8::Integer::New(isolate, 20))
2391 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2654 .FromJust());
2655 CHECK_EQ(1u,
2656 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2657 CHECK_EQ(num_props + 1,
2658 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length());
2392 2659
2393 CcTest::heap()->CollectAllGarbage(); 2660 CcTest::heap()->CollectAllGarbage();
2394 2661
2395 CHECK(obj->SetAccessor(sym3, SymbolAccessorGetter, SymbolAccessorSetter)); 2662 CHECK(obj->SetAccessor(env.local(), sym3, SymbolAccessorGetter,
2396 CHECK(obj->Get(sym3)->IsUndefined()); 2663 SymbolAccessorSetter)
2397 CHECK(obj->Set(sym3, v8::Integer::New(isolate, 42))); 2664 .FromJust());
2398 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); 2665 CHECK(obj->Get(env.local(), sym3).ToLocalChecked()->IsUndefined());
2399 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) 2666 CHECK(obj->Set(env.local(), sym3, v8::Integer::New(isolate, 42)).FromJust());
2400 ->Equals(v8::Integer::New(isolate, 42))); 2667 CHECK(obj->Get(env.local(), sym3)
2668 .ToLocalChecked()
2669 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2670 .FromJust());
2671 CHECK(obj->Get(env.local(), v8_str("accessor_sym3"))
2672 .ToLocalChecked()
2673 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2674 .FromJust());
2401 2675
2402 // Add another property and delete it afterwards to force the object in 2676 // Add another property and delete it afterwards to force the object in
2403 // slow case. 2677 // slow case.
2404 CHECK(obj->Set(sym2, v8::Integer::New(isolate, 2008))); 2678 CHECK(
2405 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2679 obj->Set(env.local(), sym2, v8::Integer::New(isolate, 2008)).FromJust());
2406 CHECK_EQ(2008, obj->Get(sym2)->Int32Value()); 2680 CHECK_EQ(2002, obj->Get(env.local(), sym1)
2407 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2681 .ToLocalChecked()
2408 CHECK_EQ(2u, obj->GetOwnPropertyNames()->Length()); 2682 ->Int32Value(env.local())
2683 .FromJust());
2684 CHECK_EQ(2008, obj->Get(env.local(), sym2)
2685 .ToLocalChecked()
2686 ->Int32Value(env.local())
2687 .FromJust());
2688 CHECK_EQ(2002, obj->Get(env.local(), sym1)
2689 .ToLocalChecked()
2690 ->Int32Value(env.local())
2691 .FromJust());
2692 CHECK_EQ(2u,
2693 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2409 2694
2410 CHECK(obj->Has(sym1)); 2695 CHECK(obj->Has(env.local(), sym1).FromJust());
2411 CHECK(obj->Has(sym2)); 2696 CHECK(obj->Has(env.local(), sym2).FromJust());
2412 CHECK(obj->Has(sym3)); 2697 CHECK(obj->Has(env.local(), sym3).FromJust());
2413 CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); 2698 CHECK(obj->Has(env.local(), v8_str("accessor_sym3")).FromJust());
2414 CHECK(obj->Delete(sym2)); 2699 CHECK(obj->Delete(env.local(), sym2).FromJust());
2415 CHECK(obj->Has(sym1)); 2700 CHECK(obj->Has(env.local(), sym1).FromJust());
2416 CHECK(!obj->Has(sym2)); 2701 CHECK(!obj->Has(env.local(), sym2).FromJust());
2417 CHECK(obj->Has(sym3)); 2702 CHECK(obj->Has(env.local(), sym3).FromJust());
2418 CHECK(obj->Has(v8::String::NewFromUtf8(isolate, "accessor_sym3"))); 2703 CHECK(obj->Has(env.local(), v8_str("accessor_sym3")).FromJust());
2419 CHECK_EQ(2002, obj->Get(sym1)->Int32Value()); 2704 CHECK_EQ(2002, obj->Get(env.local(), sym1)
2420 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); 2705 .ToLocalChecked()
2421 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) 2706 ->Int32Value(env.local())
2422 ->Equals(v8::Integer::New(isolate, 42))); 2707 .FromJust());
2423 CHECK_EQ(2u, obj->GetOwnPropertyNames()->Length()); 2708 CHECK(obj->Get(env.local(), sym3)
2709 .ToLocalChecked()
2710 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2711 .FromJust());
2712 CHECK(obj->Get(env.local(), v8_str("accessor_sym3"))
2713 .ToLocalChecked()
2714 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2715 .FromJust());
2716 CHECK_EQ(2u,
2717 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2424 2718
2425 // Symbol properties are inherited. 2719 // Symbol properties are inherited.
2426 v8::Local<v8::Object> child = v8::Object::New(isolate); 2720 v8::Local<v8::Object> child = v8::Object::New(isolate);
2427 child->SetPrototype(obj); 2721 CHECK(child->SetPrototype(env.local(), obj).FromJust());
2428 CHECK(child->Has(sym1)); 2722 CHECK(child->Has(env.local(), sym1).FromJust());
2429 CHECK_EQ(2002, child->Get(sym1)->Int32Value()); 2723 CHECK_EQ(2002, child->Get(env.local(), sym1)
2430 CHECK(obj->Get(sym3)->Equals(v8::Integer::New(isolate, 42))); 2724 .ToLocalChecked()
2431 CHECK(obj->Get(v8::String::NewFromUtf8(isolate, "accessor_sym3")) 2725 ->Int32Value(env.local())
2432 ->Equals(v8::Integer::New(isolate, 42))); 2726 .FromJust());
2433 CHECK_EQ(0u, child->GetOwnPropertyNames()->Length()); 2727 CHECK(obj->Get(env.local(), sym3)
2728 .ToLocalChecked()
2729 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2730 .FromJust());
2731 CHECK(obj->Get(env.local(), v8_str("accessor_sym3"))
2732 .ToLocalChecked()
2733 ->Equals(env.local(), v8::Integer::New(isolate, 42))
2734 .FromJust());
2735 CHECK_EQ(0u,
2736 child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2434 } 2737 }
2435 2738
2436 2739
2437 THREADED_TEST(SymbolTemplateProperties) { 2740 THREADED_TEST(SymbolTemplateProperties) {
2438 LocalContext env; 2741 LocalContext env;
2439 v8::Isolate* isolate = env->GetIsolate(); 2742 v8::Isolate* isolate = env->GetIsolate();
2440 v8::HandleScope scope(isolate); 2743 v8::HandleScope scope(isolate);
2441 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate); 2744 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
2442 v8::Local<v8::Name> name = v8::Symbol::New(isolate); 2745 v8::Local<v8::Name> name = v8::Symbol::New(isolate);
2443 CHECK(!name.IsEmpty()); 2746 CHECK(!name.IsEmpty());
2444 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate)); 2747 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate));
2445 v8::Local<v8::Object> new_instance = foo->InstanceTemplate()->NewInstance(); 2748 v8::Local<v8::Object> new_instance =
2749 foo->InstanceTemplate()->NewInstance(env.local()).ToLocalChecked();
2446 CHECK(!new_instance.IsEmpty()); 2750 CHECK(!new_instance.IsEmpty());
2447 CHECK(new_instance->Has(name)); 2751 CHECK(new_instance->Has(env.local(), name).FromJust());
2448 } 2752 }
2449 2753
2450 2754
2451 THREADED_TEST(PrivateProperties) { 2755 THREADED_TEST(PrivateProperties) {
2452 LocalContext env; 2756 LocalContext env;
2453 v8::Isolate* isolate = env->GetIsolate(); 2757 v8::Isolate* isolate = env->GetIsolate();
2454 v8::HandleScope scope(isolate); 2758 v8::HandleScope scope(isolate);
2455 2759
2456 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2760 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2457 v8::Local<v8::Private> priv1 = v8::Private::New(isolate); 2761 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2458 v8::Local<v8::Private> priv2 = 2762 v8::Local<v8::Private> priv2 =
2459 v8::Private::New(isolate, v8_str("my-private")); 2763 v8::Private::New(isolate, v8_str("my-private"));
2460 2764
2461 CcTest::heap()->CollectAllGarbage(); 2765 CcTest::heap()->CollectAllGarbage();
2462 2766
2463 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private"))); 2767 CHECK(priv2->Name()
2768 ->Equals(env.local(),
2769 v8::String::NewFromUtf8(isolate, "my-private",
2770 v8::NewStringType::kNormal)
2771 .ToLocalChecked())
2772 .FromJust());
2464 2773
2465 // Make sure delete of a non-existent private symbol property works. 2774 // Make sure delete of a non-existent private symbol property works.
2466 obj->DeletePrivate(env.local(), priv1).FromJust(); 2775 obj->DeletePrivate(env.local(), priv1).FromJust();
2467 CHECK(!obj->HasPrivate(env.local(), priv1).FromJust()); 2776 CHECK(!obj->HasPrivate(env.local(), priv1).FromJust());
2468 2777
2469 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503)) 2778 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503))
2470 .FromJust()); 2779 .FromJust());
2471 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); 2780 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2472 CHECK_EQ(1503, 2781 CHECK_EQ(1503, obj->GetPrivate(env.local(), priv1)
2473 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); 2782 .ToLocalChecked()
2783 ->Int32Value(env.local())
2784 .FromJust());
2474 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002)) 2785 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002))
2475 .FromJust()); 2786 .FromJust());
2476 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); 2787 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2477 CHECK_EQ(2002, 2788 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1)
2478 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); 2789 .ToLocalChecked()
2790 ->Int32Value(env.local())
2791 .FromJust());
2479 2792
2480 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length()); 2793 CHECK_EQ(0u,
2481 unsigned num_props = obj->GetPropertyNames()->Length(); 2794 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2482 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"), 2795 unsigned num_props =
2483 v8::Integer::New(isolate, 20))); 2796 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length();
2484 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); 2797 CHECK(obj->Set(env.local(), v8::String::NewFromUtf8(
2485 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length()); 2798 isolate, "bla", v8::NewStringType::kNormal)
2799 .ToLocalChecked(),
2800 v8::Integer::New(isolate, 20))
2801 .FromJust());
2802 CHECK_EQ(1u,
2803 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2804 CHECK_EQ(num_props + 1,
2805 obj->GetPropertyNames(env.local()).ToLocalChecked()->Length());
2486 2806
2487 CcTest::heap()->CollectAllGarbage(); 2807 CcTest::heap()->CollectAllGarbage();
2488 2808
2489 // Add another property and delete it afterwards to force the object in 2809 // Add another property and delete it afterwards to force the object in
2490 // slow case. 2810 // slow case.
2491 CHECK(obj->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008)) 2811 CHECK(obj->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008))
2492 .FromJust()); 2812 .FromJust());
2493 CHECK_EQ(2002, 2813 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1)
2494 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); 2814 .ToLocalChecked()
2495 CHECK_EQ(2008, 2815 ->Int32Value(env.local())
2496 obj->GetPrivate(env.local(), priv2).ToLocalChecked()->Int32Value()); 2816 .FromJust());
2497 CHECK_EQ(2002, 2817 CHECK_EQ(2008, obj->GetPrivate(env.local(), priv2)
2498 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); 2818 .ToLocalChecked()
2499 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); 2819 ->Int32Value(env.local())
2820 .FromJust());
2821 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1)
2822 .ToLocalChecked()
2823 ->Int32Value(env.local())
2824 .FromJust());
2825 CHECK_EQ(1u,
2826 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2500 2827
2501 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); 2828 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2502 CHECK(obj->HasPrivate(env.local(), priv2).FromJust()); 2829 CHECK(obj->HasPrivate(env.local(), priv2).FromJust());
2503 CHECK(obj->DeletePrivate(env.local(), priv2).FromJust()); 2830 CHECK(obj->DeletePrivate(env.local(), priv2).FromJust());
2504 CHECK(obj->HasPrivate(env.local(), priv1).FromJust()); 2831 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2505 CHECK(!obj->HasPrivate(env.local(), priv2).FromJust()); 2832 CHECK(!obj->HasPrivate(env.local(), priv2).FromJust());
2506 CHECK_EQ(2002, 2833 CHECK_EQ(2002, obj->GetPrivate(env.local(), priv1)
2507 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value()); 2834 .ToLocalChecked()
2508 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length()); 2835 ->Int32Value(env.local())
2836 .FromJust());
2837 CHECK_EQ(1u,
2838 obj->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2509 2839
2510 // Private properties are not inherited (for the time being). 2840 // Private properties are not inherited (for the time being).
2511 v8::Local<v8::Object> child = v8::Object::New(isolate); 2841 v8::Local<v8::Object> child = v8::Object::New(isolate);
2512 child->SetPrototype(obj); 2842 CHECK(child->SetPrototype(env.local(), obj).FromJust());
2513 CHECK(!child->HasPrivate(env.local(), priv1).FromJust()); 2843 CHECK(!child->HasPrivate(env.local(), priv1).FromJust());
2514 CHECK_EQ(0u, child->GetOwnPropertyNames()->Length()); 2844 CHECK_EQ(0u,
2845 child->GetOwnPropertyNames(env.local()).ToLocalChecked()->Length());
2515 } 2846 }
2516 2847
2517 2848
2518 THREADED_TEST(GlobalSymbols) { 2849 THREADED_TEST(GlobalSymbols) {
2519 LocalContext env; 2850 LocalContext env;
2520 v8::Isolate* isolate = env->GetIsolate(); 2851 v8::Isolate* isolate = env->GetIsolate();
2521 v8::HandleScope scope(isolate); 2852 v8::HandleScope scope(isolate);
2522 2853
2523 v8::Local<String> name = v8_str("my-symbol"); 2854 v8::Local<String> name = v8_str("my-symbol");
2524 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name); 2855 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name);
2525 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name); 2856 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name);
2526 CHECK(glob2->SameValue(glob)); 2857 CHECK(glob2->SameValue(glob));
2527 2858
2528 v8::Local<v8::Symbol> glob_api = v8::Symbol::ForApi(isolate, name); 2859 v8::Local<v8::Symbol> glob_api = v8::Symbol::ForApi(isolate, name);
2529 v8::Local<v8::Symbol> glob_api2 = v8::Symbol::ForApi(isolate, name); 2860 v8::Local<v8::Symbol> glob_api2 = v8::Symbol::ForApi(isolate, name);
2530 CHECK(glob_api2->SameValue(glob_api)); 2861 CHECK(glob_api2->SameValue(glob_api));
2531 CHECK(!glob_api->SameValue(glob)); 2862 CHECK(!glob_api->SameValue(glob));
2532 2863
2533 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name); 2864 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name);
2534 CHECK(!sym->SameValue(glob)); 2865 CHECK(!sym->SameValue(glob));
2535 2866
2536 CompileRun("var sym2 = Symbol.for('my-symbol')"); 2867 CompileRun("var sym2 = Symbol.for('my-symbol')");
2537 v8::Local<Value> sym2 = env->Global()->Get(v8_str("sym2")); 2868 v8::Local<Value> sym2 =
2869 env->Global()->Get(env.local(), v8_str("sym2")).ToLocalChecked();
2538 CHECK(sym2->SameValue(glob)); 2870 CHECK(sym2->SameValue(glob));
2539 CHECK(!sym2->SameValue(glob_api)); 2871 CHECK(!sym2->SameValue(glob_api));
2540 } 2872 }
2541 2873
2542 2874
2543 static void CheckWellKnownSymbol(v8::Local<v8::Symbol>(*getter)(v8::Isolate*), 2875 static void CheckWellKnownSymbol(v8::Local<v8::Symbol>(*getter)(v8::Isolate*),
2544 const char* name) { 2876 const char* name) {
2545 LocalContext env; 2877 LocalContext env;
2546 v8::Isolate* isolate = env->GetIsolate(); 2878 v8::Isolate* isolate = env->GetIsolate();
2547 v8::HandleScope scope(isolate); 2879 v8::HandleScope scope(isolate);
2548 2880
2549 v8::Local<v8::Symbol> symbol = getter(isolate); 2881 v8::Local<v8::Symbol> symbol = getter(isolate);
2550 std::string script = std::string("var sym = ") + name; 2882 std::string script = std::string("var sym = ") + name;
2551 CompileRun(script.c_str()); 2883 CompileRun(script.c_str());
2552 v8::Local<Value> value = env->Global()->Get(v8_str("sym")); 2884 v8::Local<Value> value =
2885 env->Global()->Get(env.local(), v8_str("sym")).ToLocalChecked();
2553 2886
2554 CHECK(!value.IsEmpty()); 2887 CHECK(!value.IsEmpty());
2555 CHECK(!symbol.IsEmpty()); 2888 CHECK(!symbol.IsEmpty());
2556 CHECK(value->SameValue(symbol)); 2889 CHECK(value->SameValue(symbol));
2557 } 2890 }
2558 2891
2559 2892
2560 THREADED_TEST(WellKnownSymbols) { 2893 THREADED_TEST(WellKnownSymbols) {
2561 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator"); 2894 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator");
2562 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables"); 2895 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables");
(...skipping 12 matching lines...) Expand all
2575 CHECK(obj->SetPrivate(env.local(), glob, v8::Integer::New(isolate, 3)) 2908 CHECK(obj->SetPrivate(env.local(), glob, v8::Integer::New(isolate, 3))
2576 .FromJust()); 2909 .FromJust());
2577 2910
2578 v8::Local<v8::Private> glob2 = v8::Private::ForApi(isolate, name); 2911 v8::Local<v8::Private> glob2 = v8::Private::ForApi(isolate, name);
2579 CHECK(obj->HasPrivate(env.local(), glob2).FromJust()); 2912 CHECK(obj->HasPrivate(env.local(), glob2).FromJust());
2580 2913
2581 v8::Local<v8::Private> priv = v8::Private::New(isolate, name); 2914 v8::Local<v8::Private> priv = v8::Private::New(isolate, name);
2582 CHECK(!obj->HasPrivate(env.local(), priv).FromJust()); 2915 CHECK(!obj->HasPrivate(env.local(), priv).FromJust());
2583 2916
2584 CompileRun("var intern = %CreatePrivateSymbol('my-private')"); 2917 CompileRun("var intern = %CreatePrivateSymbol('my-private')");
2585 v8::Local<Value> intern = env->Global()->Get(v8_str("intern")); 2918 v8::Local<Value> intern =
2586 CHECK(!obj->Has(intern)); 2919 env->Global()->Get(env.local(), v8_str("intern")).ToLocalChecked();
2920 CHECK(!obj->Has(env.local(), intern).FromJust());
2587 } 2921 }
2588 2922
2589 2923
2590 class ScopedArrayBufferContents { 2924 class ScopedArrayBufferContents {
2591 public: 2925 public:
2592 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents) 2926 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents)
2593 : contents_(contents) {} 2927 : contents_(contents) {}
2594 ~ScopedArrayBufferContents() { free(contents_.Data()); } 2928 ~ScopedArrayBufferContents() { free(contents_.Data()); }
2595 void* Data() const { return contents_.Data(); } 2929 void* Data() const { return contents_.Data(); }
2596 size_t ByteLength() const { return contents_.ByteLength(); } 2930 size_t ByteLength() const { return contents_.ByteLength(); }
2597 2931
2598 private: 2932 private:
2599 const v8::ArrayBuffer::Contents contents_; 2933 const v8::ArrayBuffer::Contents contents_;
2600 }; 2934 };
2601 2935
2602 template <typename T> 2936 template <typename T>
2603 static void CheckInternalFieldsAreZero(v8::Handle<T> value) { 2937 static void CheckInternalFieldsAreZero(v8::Local<T> value) {
2604 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount()); 2938 CHECK_EQ(T::kInternalFieldCount, value->InternalFieldCount());
2605 for (int i = 0; i < value->InternalFieldCount(); i++) { 2939 for (int i = 0; i < value->InternalFieldCount(); i++) {
2606 CHECK_EQ(0, value->GetInternalField(i)->Int32Value()); 2940 CHECK_EQ(0, value->GetInternalField(i)
2941 ->Int32Value(CcTest::isolate()->GetCurrentContext())
2942 .FromJust());
2607 } 2943 }
2608 } 2944 }
2609 2945
2610 2946
2611 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) { 2947 THREADED_TEST(ArrayBuffer_ApiInternalToExternal) {
2612 LocalContext env; 2948 LocalContext env;
2613 v8::Isolate* isolate = env->GetIsolate(); 2949 v8::Isolate* isolate = env->GetIsolate();
2614 v8::HandleScope handle_scope(isolate); 2950 v8::HandleScope handle_scope(isolate);
2615 2951
2616 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024); 2952 Local<v8::ArrayBuffer> ab = v8::ArrayBuffer::New(isolate, 1024);
2617 CheckInternalFieldsAreZero(ab); 2953 CheckInternalFieldsAreZero(ab);
2618 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 2954 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2619 CHECK(!ab->IsExternal()); 2955 CHECK(!ab->IsExternal());
2620 CcTest::heap()->CollectAllGarbage(); 2956 CcTest::heap()->CollectAllGarbage();
2621 2957
2622 ScopedArrayBufferContents ab_contents(ab->Externalize()); 2958 ScopedArrayBufferContents ab_contents(ab->Externalize());
2623 CHECK(ab->IsExternal()); 2959 CHECK(ab->IsExternal());
2624 2960
2625 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 2961 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2626 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 2962 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2627 DCHECK(data != NULL); 2963 DCHECK(data != NULL);
2628 env->Global()->Set(v8_str("ab"), ab); 2964 CHECK(env->Global()->Set(env.local(), v8_str("ab"), ab).FromJust());
2629 2965
2630 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); 2966 v8::Local<v8::Value> result = CompileRun("ab.byteLength");
2631 CHECK_EQ(1024, result->Int32Value()); 2967 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust());
2632 2968
2633 result = CompileRun( 2969 result = CompileRun(
2634 "var u8 = new Uint8Array(ab);" 2970 "var u8 = new Uint8Array(ab);"
2635 "u8[0] = 0xFF;" 2971 "u8[0] = 0xFF;"
2636 "u8[1] = 0xAA;" 2972 "u8[1] = 0xAA;"
2637 "u8.length"); 2973 "u8.length");
2638 CHECK_EQ(1024, result->Int32Value()); 2974 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust());
2639 CHECK_EQ(0xFF, data[0]); 2975 CHECK_EQ(0xFF, data[0]);
2640 CHECK_EQ(0xAA, data[1]); 2976 CHECK_EQ(0xAA, data[1]);
2641 data[0] = 0xCC; 2977 data[0] = 0xCC;
2642 data[1] = 0x11; 2978 data[1] = 0x11;
2643 result = CompileRun("u8[0] + u8[1]"); 2979 result = CompileRun("u8[0] + u8[1]");
2644 CHECK_EQ(0xDD, result->Int32Value()); 2980 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
2645 } 2981 }
2646 2982
2647 2983
2648 THREADED_TEST(ArrayBuffer_JSInternalToExternal) { 2984 THREADED_TEST(ArrayBuffer_JSInternalToExternal) {
2649 LocalContext env; 2985 LocalContext env;
2650 v8::Isolate* isolate = env->GetIsolate(); 2986 v8::Isolate* isolate = env->GetIsolate();
2651 v8::HandleScope handle_scope(isolate); 2987 v8::HandleScope handle_scope(isolate);
2652 2988
2653 2989
2654 v8::Local<v8::Value> result = CompileRun( 2990 v8::Local<v8::Value> result = CompileRun(
2655 "var ab1 = new ArrayBuffer(2);" 2991 "var ab1 = new ArrayBuffer(2);"
2656 "var u8_a = new Uint8Array(ab1);" 2992 "var u8_a = new Uint8Array(ab1);"
2657 "u8_a[0] = 0xAA;" 2993 "u8_a[0] = 0xAA;"
2658 "u8_a[1] = 0xFF; u8_a.buffer"); 2994 "u8_a[1] = 0xFF; u8_a.buffer");
2659 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result); 2995 Local<v8::ArrayBuffer> ab1 = Local<v8::ArrayBuffer>::Cast(result);
2660 CheckInternalFieldsAreZero(ab1); 2996 CheckInternalFieldsAreZero(ab1);
2661 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); 2997 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2662 CHECK(!ab1->IsExternal()); 2998 CHECK(!ab1->IsExternal());
2663 ScopedArrayBufferContents ab1_contents(ab1->Externalize()); 2999 ScopedArrayBufferContents ab1_contents(ab1->Externalize());
2664 CHECK(ab1->IsExternal()); 3000 CHECK(ab1->IsExternal());
2665 3001
2666 result = CompileRun("ab1.byteLength"); 3002 result = CompileRun("ab1.byteLength");
2667 CHECK_EQ(2, result->Int32Value()); 3003 CHECK_EQ(2, result->Int32Value(env.local()).FromJust());
2668 result = CompileRun("u8_a[0]"); 3004 result = CompileRun("u8_a[0]");
2669 CHECK_EQ(0xAA, result->Int32Value()); 3005 CHECK_EQ(0xAA, result->Int32Value(env.local()).FromJust());
2670 result = CompileRun("u8_a[1]"); 3006 result = CompileRun("u8_a[1]");
2671 CHECK_EQ(0xFF, result->Int32Value()); 3007 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust());
2672 result = CompileRun( 3008 result = CompileRun(
2673 "var u8_b = new Uint8Array(ab1);" 3009 "var u8_b = new Uint8Array(ab1);"
2674 "u8_b[0] = 0xBB;" 3010 "u8_b[0] = 0xBB;"
2675 "u8_a[0]"); 3011 "u8_a[0]");
2676 CHECK_EQ(0xBB, result->Int32Value()); 3012 CHECK_EQ(0xBB, result->Int32Value(env.local()).FromJust());
2677 result = CompileRun("u8_b[1]"); 3013 result = CompileRun("u8_b[1]");
2678 CHECK_EQ(0xFF, result->Int32Value()); 3014 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust());
2679 3015
2680 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); 3016 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2681 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); 3017 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2682 CHECK_EQ(0xBB, ab1_data[0]); 3018 CHECK_EQ(0xBB, ab1_data[0]);
2683 CHECK_EQ(0xFF, ab1_data[1]); 3019 CHECK_EQ(0xFF, ab1_data[1]);
2684 ab1_data[0] = 0xCC; 3020 ab1_data[0] = 0xCC;
2685 ab1_data[1] = 0x11; 3021 ab1_data[1] = 0x11;
2686 result = CompileRun("u8_a[0] + u8_a[1]"); 3022 result = CompileRun("u8_a[0] + u8_a[1]");
2687 CHECK_EQ(0xDD, result->Int32Value()); 3023 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
2688 } 3024 }
2689 3025
2690 3026
2691 THREADED_TEST(ArrayBuffer_External) { 3027 THREADED_TEST(ArrayBuffer_External) {
2692 LocalContext env; 3028 LocalContext env;
2693 v8::Isolate* isolate = env->GetIsolate(); 3029 v8::Isolate* isolate = env->GetIsolate();
2694 v8::HandleScope handle_scope(isolate); 3030 v8::HandleScope handle_scope(isolate);
2695 3031
2696 i::ScopedVector<uint8_t> my_data(100); 3032 i::ScopedVector<uint8_t> my_data(100);
2697 memset(my_data.start(), 0, 100); 3033 memset(my_data.start(), 0, 100);
2698 Local<v8::ArrayBuffer> ab3 = 3034 Local<v8::ArrayBuffer> ab3 =
2699 v8::ArrayBuffer::New(isolate, my_data.start(), 100); 3035 v8::ArrayBuffer::New(isolate, my_data.start(), 100);
2700 CheckInternalFieldsAreZero(ab3); 3036 CheckInternalFieldsAreZero(ab3);
2701 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); 3037 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2702 CHECK(ab3->IsExternal()); 3038 CHECK(ab3->IsExternal());
2703 3039
2704 env->Global()->Set(v8_str("ab3"), ab3); 3040 CHECK(env->Global()->Set(env.local(), v8_str("ab3"), ab3).FromJust());
2705 3041
2706 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); 3042 v8::Local<v8::Value> result = CompileRun("ab3.byteLength");
2707 CHECK_EQ(100, result->Int32Value()); 3043 CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
2708 3044
2709 result = CompileRun( 3045 result = CompileRun(
2710 "var u8_b = new Uint8Array(ab3);" 3046 "var u8_b = new Uint8Array(ab3);"
2711 "u8_b[0] = 0xBB;" 3047 "u8_b[0] = 0xBB;"
2712 "u8_b[1] = 0xCC;" 3048 "u8_b[1] = 0xCC;"
2713 "u8_b.length"); 3049 "u8_b.length");
2714 CHECK_EQ(100, result->Int32Value()); 3050 CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
2715 CHECK_EQ(0xBB, my_data[0]); 3051 CHECK_EQ(0xBB, my_data[0]);
2716 CHECK_EQ(0xCC, my_data[1]); 3052 CHECK_EQ(0xCC, my_data[1]);
2717 my_data[0] = 0xCC; 3053 my_data[0] = 0xCC;
2718 my_data[1] = 0x11; 3054 my_data[1] = 0x11;
2719 result = CompileRun("u8_b[0] + u8_b[1]"); 3055 result = CompileRun("u8_b[0] + u8_b[1]");
2720 CHECK_EQ(0xDD, result->Int32Value()); 3056 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
2721 } 3057 }
2722 3058
2723 3059
2724 THREADED_TEST(ArrayBuffer_DisableNeuter) { 3060 THREADED_TEST(ArrayBuffer_DisableNeuter) {
2725 LocalContext env; 3061 LocalContext env;
2726 v8::Isolate* isolate = env->GetIsolate(); 3062 v8::Isolate* isolate = env->GetIsolate();
2727 v8::HandleScope handle_scope(isolate); 3063 v8::HandleScope handle_scope(isolate);
2728 3064
2729 i::ScopedVector<uint8_t> my_data(100); 3065 i::ScopedVector<uint8_t> my_data(100);
2730 memset(my_data.start(), 0, 100); 3066 memset(my_data.start(), 0, 100);
2731 Local<v8::ArrayBuffer> ab = 3067 Local<v8::ArrayBuffer> ab =
2732 v8::ArrayBuffer::New(isolate, my_data.start(), 100); 3068 v8::ArrayBuffer::New(isolate, my_data.start(), 100);
2733 CHECK(ab->IsNeuterable()); 3069 CHECK(ab->IsNeuterable());
2734 3070
2735 i::Handle<i::JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab); 3071 i::Handle<i::JSArrayBuffer> buf = v8::Utils::OpenHandle(*ab);
2736 buf->set_is_neuterable(false); 3072 buf->set_is_neuterable(false);
2737 3073
2738 CHECK(!ab->IsNeuterable()); 3074 CHECK(!ab->IsNeuterable());
2739 } 3075 }
2740 3076
2741 3077
2742 static void CheckDataViewIsNeutered(v8::Handle<v8::DataView> dv) { 3078 static void CheckDataViewIsNeutered(v8::Local<v8::DataView> dv) {
2743 CHECK_EQ(0, static_cast<int>(dv->ByteLength())); 3079 CHECK_EQ(0, static_cast<int>(dv->ByteLength()));
2744 CHECK_EQ(0, static_cast<int>(dv->ByteOffset())); 3080 CHECK_EQ(0, static_cast<int>(dv->ByteOffset()));
2745 } 3081 }
2746 3082
2747 3083
2748 static void CheckIsNeutered(v8::Handle<v8::TypedArray> ta) { 3084 static void CheckIsNeutered(v8::Local<v8::TypedArray> ta) {
2749 CHECK_EQ(0, static_cast<int>(ta->ByteLength())); 3085 CHECK_EQ(0, static_cast<int>(ta->ByteLength()));
2750 CHECK_EQ(0, static_cast<int>(ta->Length())); 3086 CHECK_EQ(0, static_cast<int>(ta->Length()));
2751 CHECK_EQ(0, static_cast<int>(ta->ByteOffset())); 3087 CHECK_EQ(0, static_cast<int>(ta->ByteOffset()));
2752 } 3088 }
2753 3089
2754 3090
2755 static void CheckIsTypedArrayVarNeutered(const char* name) { 3091 static void CheckIsTypedArrayVarNeutered(const char* name) {
2756 i::ScopedVector<char> source(1024); 3092 i::ScopedVector<char> source(1024);
2757 i::SNPrintF(source, 3093 i::SNPrintF(source,
2758 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0", 3094 "%s.byteLength == 0 && %s.byteOffset == 0 && %s.length == 0",
2759 name, name, name); 3095 name, name, name);
2760 CHECK(CompileRun(source.start())->IsTrue()); 3096 CHECK(CompileRun(source.start())->IsTrue());
2761 v8::Handle<v8::TypedArray> ta = 3097 v8::Local<v8::TypedArray> ta =
2762 v8::Handle<v8::TypedArray>::Cast(CompileRun(name)); 3098 v8::Local<v8::TypedArray>::Cast(CompileRun(name));
2763 CheckIsNeutered(ta); 3099 CheckIsNeutered(ta);
2764 } 3100 }
2765 3101
2766 3102
2767 template <typename TypedArray, int kElementSize> 3103 template <typename TypedArray, int kElementSize>
2768 static Handle<TypedArray> CreateAndCheck(Handle<v8::ArrayBuffer> ab, 3104 static Local<TypedArray> CreateAndCheck(Local<v8::ArrayBuffer> ab,
2769 int byteOffset, int length) { 3105 int byteOffset, int length) {
2770 v8::Handle<TypedArray> ta = TypedArray::New(ab, byteOffset, length); 3106 v8::Local<TypedArray> ta = TypedArray::New(ab, byteOffset, length);
2771 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta); 3107 CheckInternalFieldsAreZero<v8::ArrayBufferView>(ta);
2772 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset())); 3108 CHECK_EQ(byteOffset, static_cast<int>(ta->ByteOffset()));
2773 CHECK_EQ(length, static_cast<int>(ta->Length())); 3109 CHECK_EQ(length, static_cast<int>(ta->Length()));
2774 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength())); 3110 CHECK_EQ(length * kElementSize, static_cast<int>(ta->ByteLength()));
2775 return ta; 3111 return ta;
2776 } 3112 }
2777 3113
2778 3114
2779 THREADED_TEST(ArrayBuffer_NeuteringApi) { 3115 THREADED_TEST(ArrayBuffer_NeuteringApi) {
2780 LocalContext env; 3116 LocalContext env;
2781 v8::Isolate* isolate = env->GetIsolate(); 3117 v8::Isolate* isolate = env->GetIsolate();
2782 v8::HandleScope handle_scope(isolate); 3118 v8::HandleScope handle_scope(isolate);
2783 3119
2784 v8::Handle<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, 1024); 3120 v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(isolate, 1024);
2785 3121
2786 v8::Handle<v8::Uint8Array> u8a = 3122 v8::Local<v8::Uint8Array> u8a =
2787 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023); 3123 CreateAndCheck<v8::Uint8Array, 1>(buffer, 1, 1023);
2788 v8::Handle<v8::Uint8ClampedArray> u8c = 3124 v8::Local<v8::Uint8ClampedArray> u8c =
2789 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023); 3125 CreateAndCheck<v8::Uint8ClampedArray, 1>(buffer, 1, 1023);
2790 v8::Handle<v8::Int8Array> i8a = 3126 v8::Local<v8::Int8Array> i8a =
2791 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023); 3127 CreateAndCheck<v8::Int8Array, 1>(buffer, 1, 1023);
2792 3128
2793 v8::Handle<v8::Uint16Array> u16a = 3129 v8::Local<v8::Uint16Array> u16a =
2794 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511); 3130 CreateAndCheck<v8::Uint16Array, 2>(buffer, 2, 511);
2795 v8::Handle<v8::Int16Array> i16a = 3131 v8::Local<v8::Int16Array> i16a =
2796 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511); 3132 CreateAndCheck<v8::Int16Array, 2>(buffer, 2, 511);
2797 3133
2798 v8::Handle<v8::Uint32Array> u32a = 3134 v8::Local<v8::Uint32Array> u32a =
2799 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255); 3135 CreateAndCheck<v8::Uint32Array, 4>(buffer, 4, 255);
2800 v8::Handle<v8::Int32Array> i32a = 3136 v8::Local<v8::Int32Array> i32a =
2801 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255); 3137 CreateAndCheck<v8::Int32Array, 4>(buffer, 4, 255);
2802 3138
2803 v8::Handle<v8::Float32Array> f32a = 3139 v8::Local<v8::Float32Array> f32a =
2804 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255); 3140 CreateAndCheck<v8::Float32Array, 4>(buffer, 4, 255);
2805 v8::Handle<v8::Float64Array> f64a = 3141 v8::Local<v8::Float64Array> f64a =
2806 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127); 3142 CreateAndCheck<v8::Float64Array, 8>(buffer, 8, 127);
2807 3143
2808 v8::Handle<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023); 3144 v8::Local<v8::DataView> dv = v8::DataView::New(buffer, 1, 1023);
2809 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); 3145 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
2810 CHECK_EQ(1, static_cast<int>(dv->ByteOffset())); 3146 CHECK_EQ(1, static_cast<int>(dv->ByteOffset()));
2811 CHECK_EQ(1023, static_cast<int>(dv->ByteLength())); 3147 CHECK_EQ(1023, static_cast<int>(dv->ByteLength()));
2812 3148
2813 ScopedArrayBufferContents contents(buffer->Externalize()); 3149 ScopedArrayBufferContents contents(buffer->Externalize());
2814 buffer->Neuter(); 3150 buffer->Neuter();
2815 CHECK_EQ(0, static_cast<int>(buffer->ByteLength())); 3151 CHECK_EQ(0, static_cast<int>(buffer->ByteLength()));
2816 CheckIsNeutered(u8a); 3152 CheckIsNeutered(u8a);
2817 CheckIsNeutered(u8c); 3153 CheckIsNeutered(u8c);
2818 CheckIsNeutered(i8a); 3154 CheckIsNeutered(i8a);
(...skipping 18 matching lines...) Expand all
2837 "var u8c = new Uint8ClampedArray(ab, 1, 1023);" 3173 "var u8c = new Uint8ClampedArray(ab, 1, 1023);"
2838 "var i8a = new Int8Array(ab, 1, 1023);" 3174 "var i8a = new Int8Array(ab, 1, 1023);"
2839 "var u16a = new Uint16Array(ab, 2, 511);" 3175 "var u16a = new Uint16Array(ab, 2, 511);"
2840 "var i16a = new Int16Array(ab, 2, 511);" 3176 "var i16a = new Int16Array(ab, 2, 511);"
2841 "var u32a = new Uint32Array(ab, 4, 255);" 3177 "var u32a = new Uint32Array(ab, 4, 255);"
2842 "var i32a = new Int32Array(ab, 4, 255);" 3178 "var i32a = new Int32Array(ab, 4, 255);"
2843 "var f32a = new Float32Array(ab, 4, 255);" 3179 "var f32a = new Float32Array(ab, 4, 255);"
2844 "var f64a = new Float64Array(ab, 8, 127);" 3180 "var f64a = new Float64Array(ab, 8, 127);"
2845 "var dv = new DataView(ab, 1, 1023);"); 3181 "var dv = new DataView(ab, 1, 1023);");
2846 3182
2847 v8::Handle<v8::ArrayBuffer> ab = 3183 v8::Local<v8::ArrayBuffer> ab =
2848 Local<v8::ArrayBuffer>::Cast(CompileRun("ab")); 3184 Local<v8::ArrayBuffer>::Cast(CompileRun("ab"));
2849 3185
2850 v8::Handle<v8::DataView> dv = 3186 v8::Local<v8::DataView> dv = v8::Local<v8::DataView>::Cast(CompileRun("dv"));
2851 v8::Handle<v8::DataView>::Cast(CompileRun("dv"));
2852 3187
2853 ScopedArrayBufferContents contents(ab->Externalize()); 3188 ScopedArrayBufferContents contents(ab->Externalize());
2854 ab->Neuter(); 3189 ab->Neuter();
2855 CHECK_EQ(0, static_cast<int>(ab->ByteLength())); 3190 CHECK_EQ(0, static_cast<int>(ab->ByteLength()));
2856 CHECK_EQ(0, CompileRun("ab.byteLength")->Int32Value()); 3191 CHECK_EQ(0, v8_run_int32value(v8_compile("ab.byteLength")));
2857 3192
2858 CheckIsTypedArrayVarNeutered("u8a"); 3193 CheckIsTypedArrayVarNeutered("u8a");
2859 CheckIsTypedArrayVarNeutered("u8c"); 3194 CheckIsTypedArrayVarNeutered("u8c");
2860 CheckIsTypedArrayVarNeutered("i8a"); 3195 CheckIsTypedArrayVarNeutered("i8a");
2861 CheckIsTypedArrayVarNeutered("u16a"); 3196 CheckIsTypedArrayVarNeutered("u16a");
2862 CheckIsTypedArrayVarNeutered("i16a"); 3197 CheckIsTypedArrayVarNeutered("i16a");
2863 CheckIsTypedArrayVarNeutered("u32a"); 3198 CheckIsTypedArrayVarNeutered("u32a");
2864 CheckIsTypedArrayVarNeutered("i32a"); 3199 CheckIsTypedArrayVarNeutered("i32a");
2865 CheckIsTypedArrayVarNeutered("f32a"); 3200 CheckIsTypedArrayVarNeutered("f32a");
2866 CheckIsTypedArrayVarNeutered("f64a"); 3201 CheckIsTypedArrayVarNeutered("f64a");
(...skipping 28 matching lines...) Expand all
2895 CHECK_EQ(1024, static_cast<int>(ab->ByteLength())); 3230 CHECK_EQ(1024, static_cast<int>(ab->ByteLength()));
2896 CHECK(!ab->IsExternal()); 3231 CHECK(!ab->IsExternal());
2897 CcTest::heap()->CollectAllGarbage(); 3232 CcTest::heap()->CollectAllGarbage();
2898 3233
2899 ScopedSharedArrayBufferContents ab_contents(ab->Externalize()); 3234 ScopedSharedArrayBufferContents ab_contents(ab->Externalize());
2900 CHECK(ab->IsExternal()); 3235 CHECK(ab->IsExternal());
2901 3236
2902 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength())); 3237 CHECK_EQ(1024, static_cast<int>(ab_contents.ByteLength()));
2903 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data()); 3238 uint8_t* data = static_cast<uint8_t*>(ab_contents.Data());
2904 DCHECK(data != NULL); 3239 DCHECK(data != NULL);
2905 env->Global()->Set(v8_str("ab"), ab); 3240 CHECK(env->Global()->Set(env.local(), v8_str("ab"), ab).FromJust());
2906 3241
2907 v8::Handle<v8::Value> result = CompileRun("ab.byteLength"); 3242 v8::Local<v8::Value> result = CompileRun("ab.byteLength");
2908 CHECK_EQ(1024, result->Int32Value()); 3243 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust());
2909 3244
2910 result = CompileRun( 3245 result = CompileRun(
2911 "var u8 = new Uint8Array(ab);" 3246 "var u8 = new Uint8Array(ab);"
2912 "u8[0] = 0xFF;" 3247 "u8[0] = 0xFF;"
2913 "u8[1] = 0xAA;" 3248 "u8[1] = 0xAA;"
2914 "u8.length"); 3249 "u8.length");
2915 CHECK_EQ(1024, result->Int32Value()); 3250 CHECK_EQ(1024, result->Int32Value(env.local()).FromJust());
2916 CHECK_EQ(0xFF, data[0]); 3251 CHECK_EQ(0xFF, data[0]);
2917 CHECK_EQ(0xAA, data[1]); 3252 CHECK_EQ(0xAA, data[1]);
2918 data[0] = 0xCC; 3253 data[0] = 0xCC;
2919 data[1] = 0x11; 3254 data[1] = 0x11;
2920 result = CompileRun("u8[0] + u8[1]"); 3255 result = CompileRun("u8[0] + u8[1]");
2921 CHECK_EQ(0xDD, result->Int32Value()); 3256 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
2922 } 3257 }
2923 3258
2924 3259
2925 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) { 3260 THREADED_TEST(SharedArrayBuffer_JSInternalToExternal) {
2926 i::FLAG_harmony_sharedarraybuffer = true; 3261 i::FLAG_harmony_sharedarraybuffer = true;
2927 LocalContext env; 3262 LocalContext env;
2928 v8::Isolate* isolate = env->GetIsolate(); 3263 v8::Isolate* isolate = env->GetIsolate();
2929 v8::HandleScope handle_scope(isolate); 3264 v8::HandleScope handle_scope(isolate);
2930 3265
2931 3266
2932 v8::Local<v8::Value> result = CompileRun( 3267 v8::Local<v8::Value> result = CompileRun(
2933 "var ab1 = new SharedArrayBuffer(2);" 3268 "var ab1 = new SharedArrayBuffer(2);"
2934 "var u8_a = new Uint8Array(ab1);" 3269 "var u8_a = new Uint8Array(ab1);"
2935 "u8_a[0] = 0xAA;" 3270 "u8_a[0] = 0xAA;"
2936 "u8_a[1] = 0xFF; u8_a.buffer"); 3271 "u8_a[1] = 0xFF; u8_a.buffer");
2937 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result); 3272 Local<v8::SharedArrayBuffer> ab1 = Local<v8::SharedArrayBuffer>::Cast(result);
2938 CheckInternalFieldsAreZero(ab1); 3273 CheckInternalFieldsAreZero(ab1);
2939 CHECK_EQ(2, static_cast<int>(ab1->ByteLength())); 3274 CHECK_EQ(2, static_cast<int>(ab1->ByteLength()));
2940 CHECK(!ab1->IsExternal()); 3275 CHECK(!ab1->IsExternal());
2941 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize()); 3276 ScopedSharedArrayBufferContents ab1_contents(ab1->Externalize());
2942 CHECK(ab1->IsExternal()); 3277 CHECK(ab1->IsExternal());
2943 3278
2944 result = CompileRun("ab1.byteLength"); 3279 result = CompileRun("ab1.byteLength");
2945 CHECK_EQ(2, result->Int32Value()); 3280 CHECK_EQ(2, result->Int32Value(env.local()).FromJust());
2946 result = CompileRun("u8_a[0]"); 3281 result = CompileRun("u8_a[0]");
2947 CHECK_EQ(0xAA, result->Int32Value()); 3282 CHECK_EQ(0xAA, result->Int32Value(env.local()).FromJust());
2948 result = CompileRun("u8_a[1]"); 3283 result = CompileRun("u8_a[1]");
2949 CHECK_EQ(0xFF, result->Int32Value()); 3284 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust());
2950 result = CompileRun( 3285 result = CompileRun(
2951 "var u8_b = new Uint8Array(ab1);" 3286 "var u8_b = new Uint8Array(ab1);"
2952 "u8_b[0] = 0xBB;" 3287 "u8_b[0] = 0xBB;"
2953 "u8_a[0]"); 3288 "u8_a[0]");
2954 CHECK_EQ(0xBB, result->Int32Value()); 3289 CHECK_EQ(0xBB, result->Int32Value(env.local()).FromJust());
2955 result = CompileRun("u8_b[1]"); 3290 result = CompileRun("u8_b[1]");
2956 CHECK_EQ(0xFF, result->Int32Value()); 3291 CHECK_EQ(0xFF, result->Int32Value(env.local()).FromJust());
2957 3292
2958 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength())); 3293 CHECK_EQ(2, static_cast<int>(ab1_contents.ByteLength()));
2959 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data()); 3294 uint8_t* ab1_data = static_cast<uint8_t*>(ab1_contents.Data());
2960 CHECK_EQ(0xBB, ab1_data[0]); 3295 CHECK_EQ(0xBB, ab1_data[0]);
2961 CHECK_EQ(0xFF, ab1_data[1]); 3296 CHECK_EQ(0xFF, ab1_data[1]);
2962 ab1_data[0] = 0xCC; 3297 ab1_data[0] = 0xCC;
2963 ab1_data[1] = 0x11; 3298 ab1_data[1] = 0x11;
2964 result = CompileRun("u8_a[0] + u8_a[1]"); 3299 result = CompileRun("u8_a[0] + u8_a[1]");
2965 CHECK_EQ(0xDD, result->Int32Value()); 3300 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
2966 } 3301 }
2967 3302
2968 3303
2969 THREADED_TEST(SharedArrayBuffer_External) { 3304 THREADED_TEST(SharedArrayBuffer_External) {
2970 i::FLAG_harmony_sharedarraybuffer = true; 3305 i::FLAG_harmony_sharedarraybuffer = true;
2971 LocalContext env; 3306 LocalContext env;
2972 v8::Isolate* isolate = env->GetIsolate(); 3307 v8::Isolate* isolate = env->GetIsolate();
2973 v8::HandleScope handle_scope(isolate); 3308 v8::HandleScope handle_scope(isolate);
2974 3309
2975 i::ScopedVector<uint8_t> my_data(100); 3310 i::ScopedVector<uint8_t> my_data(100);
2976 memset(my_data.start(), 0, 100); 3311 memset(my_data.start(), 0, 100);
2977 Local<v8::SharedArrayBuffer> ab3 = 3312 Local<v8::SharedArrayBuffer> ab3 =
2978 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100); 3313 v8::SharedArrayBuffer::New(isolate, my_data.start(), 100);
2979 CheckInternalFieldsAreZero(ab3); 3314 CheckInternalFieldsAreZero(ab3);
2980 CHECK_EQ(100, static_cast<int>(ab3->ByteLength())); 3315 CHECK_EQ(100, static_cast<int>(ab3->ByteLength()));
2981 CHECK(ab3->IsExternal()); 3316 CHECK(ab3->IsExternal());
2982 3317
2983 env->Global()->Set(v8_str("ab3"), ab3); 3318 CHECK(env->Global()->Set(env.local(), v8_str("ab3"), ab3).FromJust());
2984 3319
2985 v8::Handle<v8::Value> result = CompileRun("ab3.byteLength"); 3320 v8::Local<v8::Value> result = CompileRun("ab3.byteLength");
2986 CHECK_EQ(100, result->Int32Value()); 3321 CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
2987 3322
2988 result = CompileRun( 3323 result = CompileRun(
2989 "var u8_b = new Uint8Array(ab3);" 3324 "var u8_b = new Uint8Array(ab3);"
2990 "u8_b[0] = 0xBB;" 3325 "u8_b[0] = 0xBB;"
2991 "u8_b[1] = 0xCC;" 3326 "u8_b[1] = 0xCC;"
2992 "u8_b.length"); 3327 "u8_b.length");
2993 CHECK_EQ(100, result->Int32Value()); 3328 CHECK_EQ(100, result->Int32Value(env.local()).FromJust());
2994 CHECK_EQ(0xBB, my_data[0]); 3329 CHECK_EQ(0xBB, my_data[0]);
2995 CHECK_EQ(0xCC, my_data[1]); 3330 CHECK_EQ(0xCC, my_data[1]);
2996 my_data[0] = 0xCC; 3331 my_data[0] = 0xCC;
2997 my_data[1] = 0x11; 3332 my_data[1] = 0x11;
2998 result = CompileRun("u8_b[0] + u8_b[1]"); 3333 result = CompileRun("u8_b[0] + u8_b[1]");
2999 CHECK_EQ(0xDD, result->Int32Value()); 3334 CHECK_EQ(0xDD, result->Int32Value(env.local()).FromJust());
3000 } 3335 }
3001 3336
3002 3337
3003 THREADED_TEST(HiddenProperties) { 3338 THREADED_TEST(HiddenProperties) {
3004 LocalContext env; 3339 LocalContext env;
3005 v8::Isolate* isolate = env->GetIsolate(); 3340 v8::Isolate* isolate = env->GetIsolate();
3006 v8::HandleScope scope(isolate); 3341 v8::HandleScope scope(isolate);
3007 3342
3008 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 3343 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
3009 v8::Local<v8::Private> key = 3344 v8::Local<v8::Private> key =
3010 v8::Private::ForApi(isolate, v8_str("api-test::hidden-key")); 3345 v8::Private::ForApi(isolate, v8_str("api-test::hidden-key"));
3011 v8::Local<v8::String> empty = v8_str(""); 3346 v8::Local<v8::String> empty = v8_str("");
3012 v8::Local<v8::String> prop_name = v8_str("prop_name"); 3347 v8::Local<v8::String> prop_name = v8_str("prop_name");
3013 3348
3014 CcTest::heap()->CollectAllGarbage(); 3349 CcTest::heap()->CollectAllGarbage();
3015 3350
3016 // Make sure delete of a non-existent hidden value works 3351 // Make sure delete of a non-existent hidden value works
3017 obj->DeletePrivate(env.local(), key).FromJust(); 3352 obj->DeletePrivate(env.local(), key).FromJust();
3018 3353
3019 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 1503)) 3354 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 1503))
3020 .FromJust()); 3355 .FromJust());
3021 CHECK_EQ(1503, 3356 CHECK_EQ(1503, obj->GetPrivate(env.local(), key)
3022 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3357 .ToLocalChecked()
3358 ->Int32Value(env.local())
3359 .FromJust());
3023 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) 3360 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002))
3024 .FromJust()); 3361 .FromJust());
3025 CHECK_EQ(2002, 3362 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3026 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3363 .ToLocalChecked()
3364 ->Int32Value(env.local())
3365 .FromJust());
3027 3366
3028 CcTest::heap()->CollectAllGarbage(); 3367 CcTest::heap()->CollectAllGarbage();
3029 3368
3030 // Make sure we do not find the hidden property. 3369 // Make sure we do not find the hidden property.
3031 CHECK(!obj->Has(empty)); 3370 CHECK(!obj->Has(env.local(), empty).FromJust());
3032 CHECK_EQ(2002, 3371 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3033 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3372 .ToLocalChecked()
3034 CHECK(obj->Get(empty)->IsUndefined()); 3373 ->Int32Value(env.local())
3035 CHECK_EQ(2002, 3374 .FromJust());
3036 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3375 CHECK(obj->Get(env.local(), empty).ToLocalChecked()->IsUndefined());
3037 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); 3376 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3038 CHECK_EQ(2002, 3377 .ToLocalChecked()
3039 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3378 ->Int32Value(env.local())
3040 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); 3379 .FromJust());
3380 CHECK(
3381 obj->Set(env.local(), empty, v8::Integer::New(isolate, 2003)).FromJust());
3382 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3383 .ToLocalChecked()
3384 ->Int32Value(env.local())
3385 .FromJust());
3386 CHECK_EQ(2003, obj->Get(env.local(), empty)
3387 .ToLocalChecked()
3388 ->Int32Value(env.local())
3389 .FromJust());
3041 3390
3042 CcTest::heap()->CollectAllGarbage(); 3391 CcTest::heap()->CollectAllGarbage();
3043 3392
3044 // Add another property and delete it afterwards to force the object in 3393 // Add another property and delete it afterwards to force the object in
3045 // slow case. 3394 // slow case.
3046 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); 3395 CHECK(obj->Set(env.local(), prop_name, v8::Integer::New(isolate, 2008))
3047 CHECK_EQ(2002, 3396 .FromJust());
3048 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3397 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3049 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); 3398 .ToLocalChecked()
3050 CHECK_EQ(2002, 3399 ->Int32Value(env.local())
3051 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3400 .FromJust());
3052 CHECK(obj->Delete(prop_name)); 3401 CHECK_EQ(2008, obj->Get(env.local(), prop_name)
3053 CHECK_EQ(2002, 3402 .ToLocalChecked()
3054 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3403 ->Int32Value(env.local())
3404 .FromJust());
3405 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3406 .ToLocalChecked()
3407 ->Int32Value(env.local())
3408 .FromJust());
3409 CHECK(obj->Delete(env.local(), prop_name).FromJust());
3410 CHECK_EQ(2002, obj->GetPrivate(env.local(), key)
3411 .ToLocalChecked()
3412 ->Int32Value(env.local())
3413 .FromJust());
3055 3414
3056 CcTest::heap()->CollectAllGarbage(); 3415 CcTest::heap()->CollectAllGarbage();
3057 3416
3058 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002)) 3417 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002))
3059 .FromJust()); 3418 .FromJust());
3060 CHECK(obj->DeletePrivate(env.local(), key).FromJust()); 3419 CHECK(obj->DeletePrivate(env.local(), key).FromJust());
3061 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); 3420 CHECK(!obj->HasPrivate(env.local(), key).FromJust());
3062 } 3421 }
3063 3422
3064 3423
(...skipping 17 matching lines...) Expand all
3082 " set: function() { set_called = true; }})"); 3441 " set: function() { set_called = true; }})");
3083 3442
3084 CHECK(!obj->HasPrivate(env.local(), key).FromJust()); 3443 CHECK(!obj->HasPrivate(env.local(), key).FromJust());
3085 // Make sure that the getter and setter from Object.prototype is not invoked. 3444 // 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 3445 // If it did we would have full access to the hidden properties in
3087 // the accessor. 3446 // the accessor.
3088 CHECK( 3447 CHECK(
3089 obj->SetPrivate(env.local(), key, v8::Integer::New(env->GetIsolate(), 42)) 3448 obj->SetPrivate(env.local(), key, v8::Integer::New(env->GetIsolate(), 42))
3090 .FromJust()); 3449 .FromJust());
3091 ExpectFalse("set_called"); 3450 ExpectFalse("set_called");
3092 CHECK_EQ(42, 3451 CHECK_EQ(42, obj->GetPrivate(env.local(), key)
3093 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value()); 3452 .ToLocalChecked()
3453 ->Int32Value(env.local())
3454 .FromJust());
3094 } 3455 }
3095 3456
3096 3457
3097 THREADED_TEST(External) { 3458 THREADED_TEST(External) {
3098 v8::HandleScope scope(CcTest::isolate()); 3459 v8::HandleScope scope(CcTest::isolate());
3099 int x = 3; 3460 int x = 3;
3100 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); 3461 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x);
3101 LocalContext env; 3462 LocalContext env;
3102 env->Global()->Set(v8_str("ext"), ext); 3463 CHECK(env->Global()->Set(env.local(), v8_str("ext"), ext).FromJust());
3103 Local<Value> reext_obj = CompileRun("this.ext"); 3464 Local<Value> reext_obj = CompileRun("this.ext");
3104 v8::Handle<v8::External> reext = reext_obj.As<v8::External>(); 3465 v8::Local<v8::External> reext = reext_obj.As<v8::External>();
3105 int* ptr = static_cast<int*>(reext->Value()); 3466 int* ptr = static_cast<int*>(reext->Value());
3106 CHECK_EQ(x, 3); 3467 CHECK_EQ(x, 3);
3107 *ptr = 10; 3468 *ptr = 10;
3108 CHECK_EQ(x, 10); 3469 CHECK_EQ(x, 10);
3109 3470
3110 // Make sure unaligned pointers are wrapped properly. 3471 // Make sure unaligned pointers are wrapped properly.
3111 char* data = i::StrDup("0123456789"); 3472 char* data = i::StrDup("0123456789");
3112 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]); 3473 Local<v8::Value> zero = v8::External::New(CcTest::isolate(), &data[0]);
3113 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]); 3474 Local<v8::Value> one = v8::External::New(CcTest::isolate(), &data[1]);
3114 Local<v8::Value> two = v8::External::New(CcTest::isolate(), &data[2]); 3475 Local<v8::Value> two = v8::External::New(CcTest::isolate(), &data[2]);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 3751
3391 namespace { 3752 namespace {
3392 3753
3393 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); } 3754 void* IntKeyToVoidPointer(int key) { return reinterpret_cast<void*>(key << 1); }
3394 3755
3395 3756
3396 Local<v8::Object> NewObjectForIntKey( 3757 Local<v8::Object> NewObjectForIntKey(
3397 v8::Isolate* isolate, const v8::Global<v8::ObjectTemplate>& templ, 3758 v8::Isolate* isolate, const v8::Global<v8::ObjectTemplate>& templ,
3398 int key) { 3759 int key) {
3399 auto local = Local<v8::ObjectTemplate>::New(isolate, templ); 3760 auto local = Local<v8::ObjectTemplate>::New(isolate, templ);
3400 auto obj = local->NewInstance(); 3761 auto obj = local->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
3401 obj->SetAlignedPointerInInternalField(0, IntKeyToVoidPointer(key)); 3762 obj->SetAlignedPointerInInternalField(0, IntKeyToVoidPointer(key));
3402 return obj; 3763 return obj;
3403 } 3764 }
3404 3765
3405 3766
3406 template <typename K, typename V> 3767 template <typename K, typename V>
3407 class PhantomStdMapTraits : public v8::StdMapTraits<K, V> { 3768 class PhantomStdMapTraits : public v8::StdMapTraits<K, V> {
3408 public: 3769 public:
3409 typedef typename v8::GlobalValueMap<K, V, PhantomStdMapTraits<K, V>> MapType; 3770 typedef typename v8::GlobalValueMap<K, V, PhantomStdMapTraits<K, V>> MapType;
3410 static const v8::PersistentContainerCallbackType kCallbackType = 3771 static const v8::PersistentContainerCallbackType kCallbackType =
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3461 int initial_handle_count = global_handles->global_handles_count(); 3822 int initial_handle_count = global_handles->global_handles_count();
3462 CHECK_EQ(0, static_cast<int>(map.Size())); 3823 CHECK_EQ(0, static_cast<int>(map.Size()));
3463 { 3824 {
3464 HandleScope scope(isolate); 3825 HandleScope scope(isolate);
3465 Local<v8::Object> obj = map.Get(7); 3826 Local<v8::Object> obj = map.Get(7);
3466 CHECK(obj.IsEmpty()); 3827 CHECK(obj.IsEmpty());
3467 Local<v8::Object> expected = v8::Object::New(isolate); 3828 Local<v8::Object> expected = v8::Object::New(isolate);
3468 map.Set(7, expected); 3829 map.Set(7, expected);
3469 CHECK_EQ(1, static_cast<int>(map.Size())); 3830 CHECK_EQ(1, static_cast<int>(map.Size()));
3470 obj = map.Get(7); 3831 obj = map.Get(7);
3471 CHECK(expected->Equals(obj)); 3832 CHECK(expected->Equals(env.local(), obj).FromJust());
3472 { 3833 {
3473 typename Map::PersistentValueReference ref = map.GetReference(7); 3834 typename Map::PersistentValueReference ref = map.GetReference(7);
3474 CHECK(expected->Equals(ref.NewLocal(isolate))); 3835 CHECK(expected->Equals(ref.NewLocal(isolate)));
3475 } 3836 }
3476 v8::Global<v8::Object> removed = map.Remove(7); 3837 v8::Global<v8::Object> removed = map.Remove(7);
3477 CHECK_EQ(0, static_cast<int>(map.Size())); 3838 CHECK_EQ(0, static_cast<int>(map.Size()));
3478 CHECK(expected == removed); 3839 CHECK(expected == removed);
3479 removed = map.Remove(7); 3840 removed = map.Remove(7);
3480 CHECK(removed.IsEmpty()); 3841 CHECK(removed.IsEmpty());
3481 map.Set(8, expected); 3842 map.Set(8, expected);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3546 3907
3547 vector.Append(obj1); 3908 vector.Append(obj1);
3548 vector.Append(obj2); 3909 vector.Append(obj2);
3549 vector.Append(obj1); 3910 vector.Append(obj1);
3550 vector.Append(obj3.Pass()); 3911 vector.Append(obj3.Pass());
3551 vector.Append(obj1); 3912 vector.Append(obj1);
3552 3913
3553 CHECK(!vector.IsEmpty()); 3914 CHECK(!vector.IsEmpty());
3554 CHECK_EQ(5, static_cast<int>(vector.Size())); 3915 CHECK_EQ(5, static_cast<int>(vector.Size()));
3555 CHECK(obj3.IsEmpty()); 3916 CHECK(obj3.IsEmpty());
3556 CHECK(obj1->Equals(vector.Get(0))); 3917 CHECK(obj1->Equals(env.local(), vector.Get(0)).FromJust());
3557 CHECK(obj1->Equals(vector.Get(2))); 3918 CHECK(obj1->Equals(env.local(), vector.Get(2)).FromJust());
3558 CHECK(obj1->Equals(vector.Get(4))); 3919 CHECK(obj1->Equals(env.local(), vector.Get(4)).FromJust());
3559 CHECK(obj2->Equals(vector.Get(1))); 3920 CHECK(obj2->Equals(env.local(), vector.Get(1)).FromJust());
3560 3921
3561 CHECK_EQ(5 + handle_count, global_handles->global_handles_count()); 3922 CHECK_EQ(5 + handle_count, global_handles->global_handles_count());
3562 3923
3563 vector.Clear(); 3924 vector.Clear();
3564 CHECK(vector.IsEmpty()); 3925 CHECK(vector.IsEmpty());
3565 CHECK_EQ(0, static_cast<int>(vector.Size())); 3926 CHECK_EQ(0, static_cast<int>(vector.Size()));
3566 CHECK_EQ(handle_count, global_handles->global_handles_count()); 3927 CHECK_EQ(handle_count, global_handles->global_handles_count());
3567 } 3928 }
3568 3929
3569 3930
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 v8::WeakCallbackType::kParameter); 4061 v8::WeakCallbackType::kParameter);
3701 } 4062 }
3702 4063
3703 WeakCallCounterAndPersistent<Value> root(&counter); 4064 WeakCallCounterAndPersistent<Value> root(&counter);
3704 root.handle.Reset(iso, g1s1.handle); // make a root. 4065 root.handle.Reset(iso, g1s1.handle); // make a root.
3705 4066
3706 // Connect group 1 and 2, make a cycle. 4067 // Connect group 1 and 2, make a cycle.
3707 { 4068 {
3708 HandleScope scope(iso); 4069 HandleScope scope(iso);
3709 CHECK(Local<Object>::New(iso, g1s2.handle.As<Object>()) 4070 CHECK(Local<Object>::New(iso, g1s2.handle.As<Object>())
3710 ->Set(0, Local<Value>::New(iso, g2s2.handle))); 4071 ->Set(env.local(), 0, Local<Value>::New(iso, g2s2.handle))
4072 .FromJust());
3711 CHECK(Local<Object>::New(iso, g2s1.handle.As<Object>()) 4073 CHECK(Local<Object>::New(iso, g2s1.handle.As<Object>())
3712 ->Set(0, Local<Value>::New(iso, g1s1.handle))); 4074 ->Set(env.local(), 0, Local<Value>::New(iso, g1s1.handle))
4075 .FromJust());
3713 } 4076 }
3714 4077
3715 { 4078 {
3716 UniqueId id1 = MakeUniqueId(g1s1.handle); 4079 UniqueId id1 = MakeUniqueId(g1s1.handle);
3717 UniqueId id2 = MakeUniqueId(g2s2.handle); 4080 UniqueId id2 = MakeUniqueId(g2s2.handle);
3718 iso->SetObjectGroupId(g1s1.handle, id1); 4081 iso->SetObjectGroupId(g1s1.handle, id1);
3719 iso->SetObjectGroupId(g1s2.handle, id1); 4082 iso->SetObjectGroupId(g1s2.handle, id1);
3720 iso->SetReferenceFromGroup(id1, g1c1.handle); 4083 iso->SetReferenceFromGroup(id1, g1c1.handle);
3721 iso->SetObjectGroupId(g2s1.handle, id2); 4084 iso->SetObjectGroupId(g2s1.handle, id2);
3722 iso->SetObjectGroupId(g2s2.handle, id2); 4085 iso->SetObjectGroupId(g2s2.handle, id2);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3776 WeakCallCounterAndPersistent<Object> g1s1(&counter); 4139 WeakCallCounterAndPersistent<Object> g1s1(&counter);
3777 WeakCallCounterAndPersistent<String> g1s2(&counter); 4140 WeakCallCounterAndPersistent<String> g1s2(&counter);
3778 WeakCallCounterAndPersistent<String> g1c1(&counter); 4141 WeakCallCounterAndPersistent<String> g1c1(&counter);
3779 WeakCallCounterAndPersistent<Object> g2s1(&counter); 4142 WeakCallCounterAndPersistent<Object> g2s1(&counter);
3780 WeakCallCounterAndPersistent<String> g2s2(&counter); 4143 WeakCallCounterAndPersistent<String> g2s2(&counter);
3781 WeakCallCounterAndPersistent<String> g2c1(&counter); 4144 WeakCallCounterAndPersistent<String> g2c1(&counter);
3782 4145
3783 { 4146 {
3784 HandleScope scope(iso); 4147 HandleScope scope(iso);
3785 g1s1.handle.Reset(iso, Object::New(iso)); 4148 g1s1.handle.Reset(iso, Object::New(iso));
3786 g1s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo1")); 4149 g1s2.handle.Reset(iso, v8_str("foo1"));
3787 g1c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo2")); 4150 g1c1.handle.Reset(iso, v8_str("foo2"));
3788 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback, 4151 g1s1.handle.SetWeak(&g1s1, &WeakPointerCallback,
3789 v8::WeakCallbackType::kParameter); 4152 v8::WeakCallbackType::kParameter);
3790 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback, 4153 g1s2.handle.SetWeak(&g1s2, &WeakPointerCallback,
3791 v8::WeakCallbackType::kParameter); 4154 v8::WeakCallbackType::kParameter);
3792 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback, 4155 g1c1.handle.SetWeak(&g1c1, &WeakPointerCallback,
3793 v8::WeakCallbackType::kParameter); 4156 v8::WeakCallbackType::kParameter);
3794 4157
3795 g2s1.handle.Reset(iso, Object::New(iso)); 4158 g2s1.handle.Reset(iso, Object::New(iso));
3796 g2s2.handle.Reset(iso, String::NewFromUtf8(iso, "foo3")); 4159 g2s2.handle.Reset(iso, v8_str("foo3"));
3797 g2c1.handle.Reset(iso, String::NewFromUtf8(iso, "foo4")); 4160 g2c1.handle.Reset(iso, v8_str("foo4"));
3798 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback, 4161 g2s1.handle.SetWeak(&g2s1, &WeakPointerCallback,
3799 v8::WeakCallbackType::kParameter); 4162 v8::WeakCallbackType::kParameter);
3800 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback, 4163 g2s2.handle.SetWeak(&g2s2, &WeakPointerCallback,
3801 v8::WeakCallbackType::kParameter); 4164 v8::WeakCallbackType::kParameter);
3802 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback, 4165 g2c1.handle.SetWeak(&g2c1, &WeakPointerCallback,
3803 v8::WeakCallbackType::kParameter); 4166 v8::WeakCallbackType::kParameter);
3804 } 4167 }
3805 4168
3806 WeakCallCounterAndPersistent<Value> root(&counter); 4169 WeakCallCounterAndPersistent<Value> root(&counter);
3807 root.handle.Reset(iso, g1s1.handle); // make a root. 4170 root.handle.Reset(iso, g1s1.handle); // make a root.
3808 4171
3809 // Connect group 1 and 2, make a cycle. 4172 // Connect group 1 and 2, make a cycle.
3810 { 4173 {
3811 HandleScope scope(iso); 4174 HandleScope scope(iso);
3812 CHECK(Local<Object>::New(iso, g1s1.handle) 4175 CHECK(Local<Object>::New(iso, g1s1.handle)
3813 ->Set(0, Local<Object>::New(iso, g2s1.handle))); 4176 ->Set(env.local(), 0, Local<Object>::New(iso, g2s1.handle))
4177 .FromJust());
3814 CHECK(Local<Object>::New(iso, g2s1.handle) 4178 CHECK(Local<Object>::New(iso, g2s1.handle)
3815 ->Set(0, Local<Object>::New(iso, g1s1.handle))); 4179 ->Set(env.local(), 0, Local<Object>::New(iso, g1s1.handle))
4180 .FromJust());
3816 } 4181 }
3817 4182
3818 { 4183 {
3819 UniqueId id1 = MakeUniqueId(g1s1.handle); 4184 UniqueId id1 = MakeUniqueId(g1s1.handle);
3820 UniqueId id2 = MakeUniqueId(g2s2.handle); 4185 UniqueId id2 = MakeUniqueId(g2s2.handle);
3821 iso->SetObjectGroupId(g1s1.handle, id1); 4186 iso->SetObjectGroupId(g1s1.handle, id1);
3822 iso->SetObjectGroupId(g1s2.handle, id1); 4187 iso->SetObjectGroupId(g1s2.handle, id1);
3823 iso->SetReference(g1s1.handle, g1c1.handle); 4188 iso->SetReference(g1s1.handle, g1c1.handle);
3824 iso->SetObjectGroupId(g2s1.handle, id2); 4189 iso->SetObjectGroupId(g2s1.handle, id2);
3825 iso->SetObjectGroupId(g2s2.handle, id2); 4190 iso->SetObjectGroupId(g2s2.handle, id2);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
4041 HandleScope handle_scope(iso); 4406 HandleScope handle_scope(iso);
4042 g1s1.handle.MarkPartiallyDependent(); 4407 g1s1.handle.MarkPartiallyDependent();
4043 g1s2.handle.MarkPartiallyDependent(); 4408 g1s2.handle.MarkPartiallyDependent();
4044 g2s1.handle.MarkPartiallyDependent(); 4409 g2s1.handle.MarkPartiallyDependent();
4045 g2s2.handle.MarkPartiallyDependent(); 4410 g2s2.handle.MarkPartiallyDependent();
4046 g3s1.handle.MarkPartiallyDependent(); 4411 g3s1.handle.MarkPartiallyDependent();
4047 g3s2.handle.MarkPartiallyDependent(); 4412 g3s2.handle.MarkPartiallyDependent();
4048 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); 4413 iso->SetObjectGroupId(g1s1.handle, UniqueId(1));
4049 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); 4414 iso->SetObjectGroupId(g1s2.handle, UniqueId(1));
4050 Local<Object>::New(iso, g1s1.handle.As<Object>()) 4415 Local<Object>::New(iso, g1s1.handle.As<Object>())
4051 ->Set(v8_str("x"), Local<Value>::New(iso, g2s1.handle)); 4416 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g2s1.handle))
4417 .FromJust();
4052 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); 4418 iso->SetObjectGroupId(g2s1.handle, UniqueId(2));
4053 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); 4419 iso->SetObjectGroupId(g2s2.handle, UniqueId(2));
4054 Local<Object>::New(iso, g2s1.handle.As<Object>()) 4420 Local<Object>::New(iso, g2s1.handle.As<Object>())
4055 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); 4421 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g3s1.handle))
4422 .FromJust();
4056 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); 4423 iso->SetObjectGroupId(g3s1.handle, UniqueId(3));
4057 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); 4424 iso->SetObjectGroupId(g3s2.handle, UniqueId(3));
4058 Local<Object>::New(iso, g3s1.handle.As<Object>()) 4425 Local<Object>::New(iso, g3s1.handle.As<Object>())
4059 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); 4426 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g1s1.handle))
4427 .FromJust();
4060 } 4428 }
4061 4429
4062 v8::internal::Heap* heap = 4430 v8::internal::Heap* heap =
4063 reinterpret_cast<v8::internal::Isolate*>(iso)->heap(); 4431 reinterpret_cast<v8::internal::Isolate*>(iso)->heap();
4064 heap->CollectAllGarbage(); 4432 heap->CollectAllGarbage();
4065 4433
4066 // All objects should be alive. 4434 // All objects should be alive.
4067 CHECK_EQ(0, counter.NumberOfWeakCalls()); 4435 CHECK_EQ(0, counter.NumberOfWeakCalls());
4068 4436
4069 // Weaken the root. 4437 // Weaken the root.
4070 root.handle.SetWeak(&root, &WeakPointerCallback, 4438 root.handle.SetWeak(&root, &WeakPointerCallback,
4071 v8::WeakCallbackType::kParameter); 4439 v8::WeakCallbackType::kParameter);
4072 root.handle.MarkPartiallyDependent(); 4440 root.handle.MarkPartiallyDependent();
4073 4441
4074 // Groups are deleted, rebuild groups. 4442 // Groups are deleted, rebuild groups.
4075 { 4443 {
4076 HandleScope handle_scope(iso); 4444 HandleScope handle_scope(iso);
4077 g1s1.handle.MarkPartiallyDependent(); 4445 g1s1.handle.MarkPartiallyDependent();
4078 g1s2.handle.MarkPartiallyDependent(); 4446 g1s2.handle.MarkPartiallyDependent();
4079 g2s1.handle.MarkPartiallyDependent(); 4447 g2s1.handle.MarkPartiallyDependent();
4080 g2s2.handle.MarkPartiallyDependent(); 4448 g2s2.handle.MarkPartiallyDependent();
4081 g3s1.handle.MarkPartiallyDependent(); 4449 g3s1.handle.MarkPartiallyDependent();
4082 g3s2.handle.MarkPartiallyDependent(); 4450 g3s2.handle.MarkPartiallyDependent();
4083 iso->SetObjectGroupId(g1s1.handle, UniqueId(1)); 4451 iso->SetObjectGroupId(g1s1.handle, UniqueId(1));
4084 iso->SetObjectGroupId(g1s2.handle, UniqueId(1)); 4452 iso->SetObjectGroupId(g1s2.handle, UniqueId(1));
4085 Local<Object>::New(iso, g1s1.handle.As<Object>()) 4453 Local<Object>::New(iso, g1s1.handle.As<Object>())
4086 ->Set(v8_str("x"), Local<Value>::New(iso, g2s1.handle)); 4454 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g2s1.handle))
4455 .FromJust();
4087 iso->SetObjectGroupId(g2s1.handle, UniqueId(2)); 4456 iso->SetObjectGroupId(g2s1.handle, UniqueId(2));
4088 iso->SetObjectGroupId(g2s2.handle, UniqueId(2)); 4457 iso->SetObjectGroupId(g2s2.handle, UniqueId(2));
4089 Local<Object>::New(iso, g2s1.handle.As<Object>()) 4458 Local<Object>::New(iso, g2s1.handle.As<Object>())
4090 ->Set(v8_str("x"), Local<Value>::New(iso, g3s1.handle)); 4459 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g3s1.handle))
4460 .FromJust();
4091 iso->SetObjectGroupId(g3s1.handle, UniqueId(3)); 4461 iso->SetObjectGroupId(g3s1.handle, UniqueId(3));
4092 iso->SetObjectGroupId(g3s2.handle, UniqueId(3)); 4462 iso->SetObjectGroupId(g3s2.handle, UniqueId(3));
4093 Local<Object>::New(iso, g3s1.handle.As<Object>()) 4463 Local<Object>::New(iso, g3s1.handle.As<Object>())
4094 ->Set(v8_str("x"), Local<Value>::New(iso, g1s1.handle)); 4464 ->Set(env.local(), v8_str("x"), Local<Value>::New(iso, g1s1.handle))
4465 .FromJust();
4095 } 4466 }
4096 4467
4097 heap->CollectAllGarbage(); 4468 heap->CollectAllGarbage();
4098 4469
4099 // All objects should be gone. 7 global handles in total. 4470 // All objects should be gone. 7 global handles in total.
4100 CHECK_EQ(7, counter.NumberOfWeakCalls()); 4471 CHECK_EQ(7, counter.NumberOfWeakCalls());
4101 } 4472 }
4102 4473
4103 4474
4104 THREADED_TEST(ScriptException) { 4475 THREADED_TEST(ScriptException) {
4105 LocalContext env; 4476 LocalContext env;
4106 v8::HandleScope scope(env->GetIsolate()); 4477 v8::HandleScope scope(env->GetIsolate());
4107 Local<Script> script = v8_compile("throw 'panama!';"); 4478 Local<Script> script = v8_compile("throw 'panama!';");
4108 v8::TryCatch try_catch(env->GetIsolate()); 4479 v8::TryCatch try_catch(env->GetIsolate());
4109 Local<Value> result = script->Run(); 4480 v8::MaybeLocal<Value> result = script->Run(env.local());
4110 CHECK(result.IsEmpty()); 4481 CHECK(result.IsEmpty());
4111 CHECK(try_catch.HasCaught()); 4482 CHECK(try_catch.HasCaught());
4112 String::Utf8Value exception_value(try_catch.Exception()); 4483 String::Utf8Value exception_value(try_catch.Exception());
4113 CHECK_EQ(0, strcmp(*exception_value, "panama!")); 4484 CHECK_EQ(0, strcmp(*exception_value, "panama!"));
4114 } 4485 }
4115 4486
4116 4487
4117 TEST(TryCatchCustomException) { 4488 TEST(TryCatchCustomException) {
4118 LocalContext env; 4489 LocalContext env;
4119 v8::Isolate* isolate = env->GetIsolate(); 4490 v8::Isolate* isolate = env->GetIsolate();
4120 v8::HandleScope scope(isolate); 4491 v8::HandleScope scope(isolate);
4121 v8::TryCatch try_catch(isolate); 4492 v8::TryCatch try_catch(isolate);
4122 CompileRun( 4493 CompileRun(
4123 "function CustomError() { this.a = 'b'; }" 4494 "function CustomError() { this.a = 'b'; }"
4124 "(function f() { throw new CustomError(); })();"); 4495 "(function f() { throw new CustomError(); })();");
4125 CHECK(try_catch.HasCaught()); 4496 CHECK(try_catch.HasCaught());
4126 CHECK(try_catch.Exception() 4497 CHECK(try_catch.Exception()
4127 ->ToObject(isolate) 4498 ->ToObject(env.local())
4128 ->Get(v8_str("a")) 4499 .ToLocalChecked()
4129 ->Equals(v8_str("b"))); 4500 ->Get(env.local(), v8_str("a"))
4501 .ToLocalChecked()
4502 ->Equals(env.local(), v8_str("b"))
4503 .FromJust());
4130 } 4504 }
4131 4505
4132 4506
4133 bool message_received; 4507 bool message_received;
4134 4508
4135 4509
4136 static void check_message_0(v8::Handle<v8::Message> message, 4510 static void check_message_0(v8::Local<v8::Message> message,
4137 v8::Handle<Value> data) { 4511 v8::Local<Value> data) {
4138 CHECK_EQ(5.76, data->NumberValue()); 4512 CHECK_EQ(5.76, data->NumberValue(CcTest::isolate()->GetCurrentContext())
4139 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); 4513 .FromJust());
4514 CHECK_EQ(6.75, message->GetScriptOrigin()
4515 .ResourceName()
4516 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4517 .FromJust());
4140 CHECK(!message->IsSharedCrossOrigin()); 4518 CHECK(!message->IsSharedCrossOrigin());
4141 message_received = true; 4519 message_received = true;
4142 } 4520 }
4143 4521
4144 4522
4145 THREADED_TEST(MessageHandler0) { 4523 THREADED_TEST(MessageHandler0) {
4146 message_received = false; 4524 message_received = false;
4147 v8::HandleScope scope(CcTest::isolate()); 4525 v8::HandleScope scope(CcTest::isolate());
4148 CHECK(!message_received); 4526 CHECK(!message_received);
4149 LocalContext context; 4527 LocalContext context;
4150 v8::V8::AddMessageListener(check_message_0, v8_num(5.76)); 4528 CcTest::isolate()->AddMessageListener(check_message_0, v8_num(5.76));
4151 v8::Handle<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75"); 4529 v8::Local<v8::Script> script = CompileWithOrigin("throw 'error'", "6.75");
4152 script->Run(); 4530 CHECK(script->Run(context.local()).IsEmpty());
4153 CHECK(message_received); 4531 CHECK(message_received);
4154 // clear out the message listener 4532 // clear out the message listener
4155 v8::V8::RemoveMessageListeners(check_message_0); 4533 CcTest::isolate()->RemoveMessageListeners(check_message_0);
4156 } 4534 }
4157 4535
4158 4536
4159 static void check_message_1(v8::Handle<v8::Message> message, 4537 static void check_message_1(v8::Local<v8::Message> message,
4160 v8::Handle<Value> data) { 4538 v8::Local<Value> data) {
4161 CHECK(data->IsNumber()); 4539 CHECK(data->IsNumber());
4162 CHECK_EQ(1337, data->Int32Value()); 4540 CHECK_EQ(1337,
4541 data->Int32Value(CcTest::isolate()->GetCurrentContext()).FromJust());
4163 CHECK(!message->IsSharedCrossOrigin()); 4542 CHECK(!message->IsSharedCrossOrigin());
4164 message_received = true; 4543 message_received = true;
4165 } 4544 }
4166 4545
4167 4546
4168 TEST(MessageHandler1) { 4547 TEST(MessageHandler1) {
4169 message_received = false; 4548 message_received = false;
4170 v8::HandleScope scope(CcTest::isolate()); 4549 v8::HandleScope scope(CcTest::isolate());
4171 CHECK(!message_received); 4550 CHECK(!message_received);
4172 v8::V8::AddMessageListener(check_message_1); 4551 CcTest::isolate()->AddMessageListener(check_message_1);
4173 LocalContext context; 4552 LocalContext context;
4174 CompileRun("throw 1337;"); 4553 CompileRun("throw 1337;");
4175 CHECK(message_received); 4554 CHECK(message_received);
4176 // clear out the message listener 4555 // clear out the message listener
4177 v8::V8::RemoveMessageListeners(check_message_1); 4556 CcTest::isolate()->RemoveMessageListeners(check_message_1);
4178 } 4557 }
4179 4558
4180 4559
4181 static void check_message_2(v8::Handle<v8::Message> message, 4560 static void check_message_2(v8::Local<v8::Message> message,
4182 v8::Handle<Value> data) { 4561 v8::Local<Value> data) {
4183 LocalContext context; 4562 LocalContext context;
4184 CHECK(data->IsObject()); 4563 CHECK(data->IsObject());
4185 v8::Local<v8::Value> hidden_property = 4564 v8::Local<v8::Value> hidden_property =
4186 v8::Object::Cast(*data) 4565 v8::Object::Cast(*data)
4187 ->GetPrivate( 4566 ->GetPrivate(
4188 context.local(), 4567 context.local(),
4189 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key"))) 4568 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")))
4190 .ToLocalChecked(); 4569 .ToLocalChecked();
4191 CHECK(v8_str("hidden value")->Equals(hidden_property)); 4570 CHECK(v8_str("hidden value")
4571 ->Equals(context.local(), hidden_property)
4572 .FromJust());
4192 CHECK(!message->IsSharedCrossOrigin()); 4573 CHECK(!message->IsSharedCrossOrigin());
4193 message_received = true; 4574 message_received = true;
4194 } 4575 }
4195 4576
4196 4577
4197 TEST(MessageHandler2) { 4578 TEST(MessageHandler2) {
4198 message_received = false; 4579 message_received = false;
4199 v8::HandleScope scope(CcTest::isolate()); 4580 v8::HandleScope scope(CcTest::isolate());
4200 CHECK(!message_received); 4581 CHECK(!message_received);
4201 v8::V8::AddMessageListener(check_message_2); 4582 CcTest::isolate()->AddMessageListener(check_message_2);
4202 LocalContext context; 4583 LocalContext context;
4203 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); 4584 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
4204 v8::Object::Cast(*error) 4585 v8::Object::Cast(*error)
4205 ->SetPrivate(context.local(), 4586 ->SetPrivate(context.local(),
4206 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")), 4587 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")),
4207 v8_str("hidden value")) 4588 v8_str("hidden value"))
4208 .FromJust(); 4589 .FromJust();
4209 context->Global()->Set(v8_str("error"), error); 4590 CHECK(context->Global()
4591 ->Set(context.local(), v8_str("error"), error)
4592 .FromJust());
4210 CompileRun("throw error;"); 4593 CompileRun("throw error;");
4211 CHECK(message_received); 4594 CHECK(message_received);
4212 // clear out the message listener 4595 // clear out the message listener
4213 v8::V8::RemoveMessageListeners(check_message_2); 4596 CcTest::isolate()->RemoveMessageListeners(check_message_2);
4214 } 4597 }
4215 4598
4216 4599
4217 static void check_message_3(v8::Handle<v8::Message> message, 4600 static void check_message_3(v8::Local<v8::Message> message,
4218 v8::Handle<Value> data) { 4601 v8::Local<Value> data) {
4219 CHECK(message->IsSharedCrossOrigin()); 4602 CHECK(message->IsSharedCrossOrigin());
4220 CHECK(message->GetScriptOrigin().Options().IsSharedCrossOrigin()); 4603 CHECK(message->GetScriptOrigin().Options().IsSharedCrossOrigin());
4221 CHECK(message->GetScriptOrigin().Options().IsEmbedderDebugScript()); 4604 CHECK(message->GetScriptOrigin().Options().IsEmbedderDebugScript());
4222 CHECK(message->GetScriptOrigin().Options().IsOpaque()); 4605 CHECK(message->GetScriptOrigin().Options().IsOpaque());
4223 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); 4606 CHECK_EQ(6.75, message->GetScriptOrigin()
4224 CHECK_EQ(7.40, message->GetScriptOrigin().SourceMapUrl()->NumberValue()); 4607 .ResourceName()
4608 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4609 .FromJust());
4610 CHECK_EQ(7.40, message->GetScriptOrigin()
4611 .SourceMapUrl()
4612 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4613 .FromJust());
4225 message_received = true; 4614 message_received = true;
4226 } 4615 }
4227 4616
4228 4617
4229 TEST(MessageHandler3) { 4618 TEST(MessageHandler3) {
4230 message_received = false; 4619 message_received = false;
4231 v8::Isolate* isolate = CcTest::isolate(); 4620 v8::Isolate* isolate = CcTest::isolate();
4232 v8::HandleScope scope(isolate); 4621 v8::HandleScope scope(isolate);
4233 CHECK(!message_received); 4622 CHECK(!message_received);
4234 v8::V8::AddMessageListener(check_message_3); 4623 isolate->AddMessageListener(check_message_3);
4235 LocalContext context; 4624 LocalContext context;
4236 v8::ScriptOrigin origin = v8::ScriptOrigin( 4625 v8::ScriptOrigin origin = v8::ScriptOrigin(
4237 v8_str("6.75"), v8::Integer::New(isolate, 1), 4626 v8_str("6.75"), v8::Integer::New(isolate, 1),
4238 v8::Integer::New(isolate, 2), v8::True(isolate), Handle<v8::Integer>(), 4627 v8::Integer::New(isolate, 2), v8::True(isolate), Local<v8::Integer>(),
4239 v8::True(isolate), v8_str("7.40"), v8::True(isolate)); 4628 v8::True(isolate), v8_str("7.40"), v8::True(isolate));
4240 v8::Handle<v8::Script> script = 4629 v8::Local<v8::Script> script =
4241 Script::Compile(v8_str("throw 'error'"), &origin); 4630 Script::Compile(context.local(), v8_str("throw 'error'"), &origin)
4242 script->Run(); 4631 .ToLocalChecked();
4632 CHECK(script->Run(context.local()).IsEmpty());
4243 CHECK(message_received); 4633 CHECK(message_received);
4244 // clear out the message listener 4634 // clear out the message listener
4245 v8::V8::RemoveMessageListeners(check_message_3); 4635 isolate->RemoveMessageListeners(check_message_3);
4246 } 4636 }
4247 4637
4248 4638
4249 static void check_message_4(v8::Handle<v8::Message> message, 4639 static void check_message_4(v8::Local<v8::Message> message,
4250 v8::Handle<Value> data) { 4640 v8::Local<Value> data) {
4251 CHECK(!message->IsSharedCrossOrigin()); 4641 CHECK(!message->IsSharedCrossOrigin());
4252 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); 4642 CHECK_EQ(6.75, message->GetScriptOrigin()
4643 .ResourceName()
4644 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4645 .FromJust());
4253 message_received = true; 4646 message_received = true;
4254 } 4647 }
4255 4648
4256 4649
4257 TEST(MessageHandler4) { 4650 TEST(MessageHandler4) {
4258 message_received = false; 4651 message_received = false;
4259 v8::Isolate* isolate = CcTest::isolate(); 4652 v8::Isolate* isolate = CcTest::isolate();
4260 v8::HandleScope scope(isolate); 4653 v8::HandleScope scope(isolate);
4261 CHECK(!message_received); 4654 CHECK(!message_received);
4262 v8::V8::AddMessageListener(check_message_4); 4655 isolate->AddMessageListener(check_message_4);
4263 LocalContext context; 4656 LocalContext context;
4264 v8::ScriptOrigin origin = 4657 v8::ScriptOrigin origin =
4265 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), 4658 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1),
4266 v8::Integer::New(isolate, 2), v8::False(isolate)); 4659 v8::Integer::New(isolate, 2), v8::False(isolate));
4267 v8::Handle<v8::Script> script = 4660 v8::Local<v8::Script> script =
4268 Script::Compile(v8_str("throw 'error'"), &origin); 4661 Script::Compile(context.local(), v8_str("throw 'error'"), &origin)
4269 script->Run(); 4662 .ToLocalChecked();
4663 CHECK(script->Run(context.local()).IsEmpty());
4270 CHECK(message_received); 4664 CHECK(message_received);
4271 // clear out the message listener 4665 // clear out the message listener
4272 v8::V8::RemoveMessageListeners(check_message_4); 4666 isolate->RemoveMessageListeners(check_message_4);
4273 } 4667 }
4274 4668
4275 4669
4276 static void check_message_5a(v8::Handle<v8::Message> message, 4670 static void check_message_5a(v8::Local<v8::Message> message,
4277 v8::Handle<Value> data) { 4671 v8::Local<Value> data) {
4278 CHECK(message->IsSharedCrossOrigin()); 4672 CHECK(message->IsSharedCrossOrigin());
4279 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); 4673 CHECK_EQ(6.75, message->GetScriptOrigin()
4674 .ResourceName()
4675 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4676 .FromJust());
4280 message_received = true; 4677 message_received = true;
4281 } 4678 }
4282 4679
4283 4680
4284 static void check_message_5b(v8::Handle<v8::Message> message, 4681 static void check_message_5b(v8::Local<v8::Message> message,
4285 v8::Handle<Value> data) { 4682 v8::Local<Value> data) {
4286 CHECK(!message->IsSharedCrossOrigin()); 4683 CHECK(!message->IsSharedCrossOrigin());
4287 CHECK_EQ(6.75, message->GetScriptOrigin().ResourceName()->NumberValue()); 4684 CHECK_EQ(6.75, message->GetScriptOrigin()
4685 .ResourceName()
4686 ->NumberValue(CcTest::isolate()->GetCurrentContext())
4687 .FromJust());
4288 message_received = true; 4688 message_received = true;
4289 } 4689 }
4290 4690
4291 4691
4292 TEST(MessageHandler5) { 4692 TEST(MessageHandler5) {
4293 message_received = false; 4693 message_received = false;
4294 v8::Isolate* isolate = CcTest::isolate(); 4694 v8::Isolate* isolate = CcTest::isolate();
4295 v8::HandleScope scope(isolate); 4695 v8::HandleScope scope(isolate);
4296 CHECK(!message_received); 4696 CHECK(!message_received);
4297 v8::V8::AddMessageListener(check_message_5a); 4697 isolate->AddMessageListener(check_message_5a);
4298 LocalContext context; 4698 LocalContext context;
4299 v8::ScriptOrigin origin1 = 4699 v8::ScriptOrigin origin1 =
4300 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), 4700 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1),
4301 v8::Integer::New(isolate, 2), v8::True(isolate)); 4701 v8::Integer::New(isolate, 2), v8::True(isolate));
4302 v8::Handle<v8::Script> script = 4702 v8::Local<v8::Script> script =
4303 Script::Compile(v8_str("throw 'error'"), &origin1); 4703 Script::Compile(context.local(), v8_str("throw 'error'"), &origin1)
4304 script->Run(); 4704 .ToLocalChecked();
4705 CHECK(script->Run(context.local()).IsEmpty());
4305 CHECK(message_received); 4706 CHECK(message_received);
4306 // clear out the message listener 4707 // clear out the message listener
4307 v8::V8::RemoveMessageListeners(check_message_5a); 4708 isolate->RemoveMessageListeners(check_message_5a);
4308 4709
4309 message_received = false; 4710 message_received = false;
4310 v8::V8::AddMessageListener(check_message_5b); 4711 isolate->AddMessageListener(check_message_5b);
4311 v8::ScriptOrigin origin2 = 4712 v8::ScriptOrigin origin2 =
4312 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1), 4713 v8::ScriptOrigin(v8_str("6.75"), v8::Integer::New(isolate, 1),
4313 v8::Integer::New(isolate, 2), v8::False(isolate)); 4714 v8::Integer::New(isolate, 2), v8::False(isolate));
4314 script = Script::Compile(v8_str("throw 'error'"), &origin2); 4715 script = Script::Compile(context.local(), v8_str("throw 'error'"), &origin2)
4315 script->Run(); 4716 .ToLocalChecked();
4717 CHECK(script->Run(context.local()).IsEmpty());
4316 CHECK(message_received); 4718 CHECK(message_received);
4317 // clear out the message listener 4719 // clear out the message listener
4318 v8::V8::RemoveMessageListeners(check_message_5b); 4720 isolate->RemoveMessageListeners(check_message_5b);
4319 } 4721 }
4320 4722
4321 4723
4322 TEST(NativeWeakMap) { 4724 TEST(NativeWeakMap) {
4323 v8::Isolate* isolate = CcTest::isolate(); 4725 v8::Isolate* isolate = CcTest::isolate();
4324 HandleScope scope(isolate); 4726 HandleScope scope(isolate);
4325 Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate)); 4727 Local<v8::NativeWeakMap> weak_map(v8::NativeWeakMap::New(isolate));
4326 CHECK(!weak_map.IsEmpty()); 4728 CHECK(!weak_map.IsEmpty());
4327 4729
4328 LocalContext env; 4730 LocalContext env;
4329 Local<Object> value = v8::Object::New(isolate); 4731 Local<Object> value = v8::Object::New(isolate);
4330 4732
4331 Local<Object> local1 = v8::Object::New(isolate); 4733 Local<Object> local1 = v8::Object::New(isolate);
4332 CHECK(!weak_map->Has(local1)); 4734 CHECK(!weak_map->Has(local1));
4333 CHECK(weak_map->Get(local1)->IsUndefined()); 4735 CHECK(weak_map->Get(local1)->IsUndefined());
4334 weak_map->Set(local1, value); 4736 weak_map->Set(local1, value);
4335 CHECK(weak_map->Has(local1)); 4737 CHECK(weak_map->Has(local1));
4336 CHECK(value->Equals(weak_map->Get(local1))); 4738 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
4337 4739
4338 WeakCallCounter counter(1234); 4740 WeakCallCounter counter(1234);
4339 WeakCallCounterAndPersistent<Value> o1(&counter); 4741 WeakCallCounterAndPersistent<Value> o1(&counter);
4340 WeakCallCounterAndPersistent<Value> o2(&counter); 4742 WeakCallCounterAndPersistent<Value> o2(&counter);
4341 WeakCallCounterAndPersistent<Value> s1(&counter); 4743 WeakCallCounterAndPersistent<Value> s1(&counter);
4342 { 4744 {
4343 HandleScope scope(isolate); 4745 HandleScope scope(isolate);
4344 Local<v8::Object> obj1 = v8::Object::New(isolate); 4746 Local<v8::Object> obj1 = v8::Object::New(isolate);
4345 Local<v8::Object> obj2 = v8::Object::New(isolate); 4747 Local<v8::Object> obj2 = v8::Object::New(isolate);
4346 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate); 4748 Local<v8::Symbol> sym1 = v8::Symbol::New(isolate);
4347 4749
4348 weak_map->Set(obj1, value); 4750 weak_map->Set(obj1, value);
4349 weak_map->Set(obj2, value); 4751 weak_map->Set(obj2, value);
4350 weak_map->Set(sym1, value); 4752 weak_map->Set(sym1, value);
4351 4753
4352 o1.handle.Reset(isolate, obj1); 4754 o1.handle.Reset(isolate, obj1);
4353 o2.handle.Reset(isolate, obj2); 4755 o2.handle.Reset(isolate, obj2);
4354 s1.handle.Reset(isolate, sym1); 4756 s1.handle.Reset(isolate, sym1);
4355 4757
4356 CHECK(weak_map->Has(local1)); 4758 CHECK(weak_map->Has(local1));
4357 CHECK(weak_map->Has(obj1)); 4759 CHECK(weak_map->Has(obj1));
4358 CHECK(weak_map->Has(obj2)); 4760 CHECK(weak_map->Has(obj2));
4359 CHECK(weak_map->Has(sym1)); 4761 CHECK(weak_map->Has(sym1));
4360 4762
4361 CHECK(value->Equals(weak_map->Get(local1))); 4763 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
4362 CHECK(value->Equals(weak_map->Get(obj1))); 4764 CHECK(value->Equals(env.local(), weak_map->Get(obj1)).FromJust());
4363 CHECK(value->Equals(weak_map->Get(obj2))); 4765 CHECK(value->Equals(env.local(), weak_map->Get(obj2)).FromJust());
4364 CHECK(value->Equals(weak_map->Get(sym1))); 4766 CHECK(value->Equals(env.local(), weak_map->Get(sym1)).FromJust());
4365 } 4767 }
4366 CcTest::heap()->CollectAllGarbage(); 4768 CcTest::heap()->CollectAllGarbage();
4367 { 4769 {
4368 HandleScope scope(isolate); 4770 HandleScope scope(isolate);
4369 CHECK(value->Equals(weak_map->Get(local1))); 4771 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
4370 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o1.handle)))); 4772 CHECK(value->Equals(env.local(),
4371 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, o2.handle)))); 4773 weak_map->Get(Local<Value>::New(isolate, o1.handle)))
4372 CHECK(value->Equals(weak_map->Get(Local<Value>::New(isolate, s1.handle)))); 4774 .FromJust());
4775 CHECK(value->Equals(env.local(),
4776 weak_map->Get(Local<Value>::New(isolate, o2.handle)))
4777 .FromJust());
4778 CHECK(value->Equals(env.local(),
4779 weak_map->Get(Local<Value>::New(isolate, s1.handle)))
4780 .FromJust());
4373 } 4781 }
4374 4782
4375 o1.handle.SetWeak(&o1, &WeakPointerCallback, 4783 o1.handle.SetWeak(&o1, &WeakPointerCallback,
4376 v8::WeakCallbackType::kParameter); 4784 v8::WeakCallbackType::kParameter);
4377 o2.handle.SetWeak(&o2, &WeakPointerCallback, 4785 o2.handle.SetWeak(&o2, &WeakPointerCallback,
4378 v8::WeakCallbackType::kParameter); 4786 v8::WeakCallbackType::kParameter);
4379 s1.handle.SetWeak(&s1, &WeakPointerCallback, 4787 s1.handle.SetWeak(&s1, &WeakPointerCallback,
4380 v8::WeakCallbackType::kParameter); 4788 v8::WeakCallbackType::kParameter);
4381 4789
4382 CcTest::heap()->CollectAllGarbage(); 4790 CcTest::heap()->CollectAllGarbage();
4383 CHECK_EQ(3, counter.NumberOfWeakCalls()); 4791 CHECK_EQ(3, counter.NumberOfWeakCalls());
4384 4792
4385 CHECK(o1.handle.IsEmpty()); 4793 CHECK(o1.handle.IsEmpty());
4386 CHECK(o2.handle.IsEmpty()); 4794 CHECK(o2.handle.IsEmpty());
4387 CHECK(s1.handle.IsEmpty()); 4795 CHECK(s1.handle.IsEmpty());
4388 4796
4389 CHECK(value->Equals(weak_map->Get(local1))); 4797 CHECK(value->Equals(env.local(), weak_map->Get(local1)).FromJust());
4390 CHECK(weak_map->Delete(local1)); 4798 CHECK(weak_map->Delete(local1));
4391 CHECK(!weak_map->Has(local1)); 4799 CHECK(!weak_map->Has(local1));
4392 CHECK(weak_map->Get(local1)->IsUndefined()); 4800 CHECK(weak_map->Get(local1)->IsUndefined());
4393 } 4801 }
4394 4802
4395 4803
4396 THREADED_TEST(GetSetProperty) { 4804 THREADED_TEST(GetSetProperty) {
4397 LocalContext context; 4805 LocalContext context;
4398 v8::Isolate* isolate = context->GetIsolate(); 4806 v8::Isolate* isolate = context->GetIsolate();
4399 v8::HandleScope scope(isolate); 4807 v8::HandleScope scope(isolate);
4400 context->Global()->Set(v8_str("foo"), v8_num(14)); 4808 CHECK(context->Global()
4401 context->Global()->Set(v8_str("12"), v8_num(92)); 4809 ->Set(context.local(), v8_str("foo"), v8_num(14))
4402 context->Global()->Set(v8::Integer::New(isolate, 16), v8_num(32)); 4810 .FromJust());
4403 context->Global()->Set(v8_num(13), v8_num(56)); 4811 CHECK(context->Global()
4812 ->Set(context.local(), v8_str("12"), v8_num(92))
4813 .FromJust());
4814 CHECK(context->Global()
4815 ->Set(context.local(), v8::Integer::New(isolate, 16), v8_num(32))
4816 .FromJust());
4817 CHECK(context->Global()
4818 ->Set(context.local(), v8_num(13), v8_num(56))
4819 .FromJust());
4404 Local<Value> foo = CompileRun("this.foo"); 4820 Local<Value> foo = CompileRun("this.foo");
4405 CHECK_EQ(14, foo->Int32Value()); 4821 CHECK_EQ(14, foo->Int32Value(context.local()).FromJust());
4406 Local<Value> twelve = CompileRun("this[12]"); 4822 Local<Value> twelve = CompileRun("this[12]");
4407 CHECK_EQ(92, twelve->Int32Value()); 4823 CHECK_EQ(92, twelve->Int32Value(context.local()).FromJust());
4408 Local<Value> sixteen = CompileRun("this[16]"); 4824 Local<Value> sixteen = CompileRun("this[16]");
4409 CHECK_EQ(32, sixteen->Int32Value()); 4825 CHECK_EQ(32, sixteen->Int32Value(context.local()).FromJust());
4410 Local<Value> thirteen = CompileRun("this[13]"); 4826 Local<Value> thirteen = CompileRun("this[13]");
4411 CHECK_EQ(56, thirteen->Int32Value()); 4827 CHECK_EQ(56, thirteen->Int32Value(context.local()).FromJust());
4412 CHECK_EQ(92, 4828 CHECK_EQ(92, context->Global()
4413 context->Global()->Get(v8::Integer::New(isolate, 12))->Int32Value()); 4829 ->Get(context.local(), v8::Integer::New(isolate, 12))
4414 CHECK_EQ(92, context->Global()->Get(v8_str("12"))->Int32Value()); 4830 .ToLocalChecked()
4415 CHECK_EQ(92, context->Global()->Get(v8_num(12))->Int32Value()); 4831 ->Int32Value(context.local())
4416 CHECK_EQ(32, 4832 .FromJust());
4417 context->Global()->Get(v8::Integer::New(isolate, 16))->Int32Value()); 4833 CHECK_EQ(92, context->Global()
4418 CHECK_EQ(32, context->Global()->Get(v8_str("16"))->Int32Value()); 4834 ->Get(context.local(), v8_str("12"))
4419 CHECK_EQ(32, context->Global()->Get(v8_num(16))->Int32Value()); 4835 .ToLocalChecked()
4420 CHECK_EQ(56, 4836 ->Int32Value(context.local())
4421 context->Global()->Get(v8::Integer::New(isolate, 13))->Int32Value()); 4837 .FromJust());
4422 CHECK_EQ(56, context->Global()->Get(v8_str("13"))->Int32Value()); 4838 CHECK_EQ(92, context->Global()
4423 CHECK_EQ(56, context->Global()->Get(v8_num(13))->Int32Value()); 4839 ->Get(context.local(), v8_num(12))
4840 .ToLocalChecked()
4841 ->Int32Value(context.local())
4842 .FromJust());
4843 CHECK_EQ(32, context->Global()
4844 ->Get(context.local(), v8::Integer::New(isolate, 16))
4845 .ToLocalChecked()
4846 ->Int32Value(context.local())
4847 .FromJust());
4848 CHECK_EQ(32, context->Global()
4849 ->Get(context.local(), v8_str("16"))
4850 .ToLocalChecked()
4851 ->Int32Value(context.local())
4852 .FromJust());
4853 CHECK_EQ(32, context->Global()
4854 ->Get(context.local(), v8_num(16))
4855 .ToLocalChecked()
4856 ->Int32Value(context.local())
4857 .FromJust());
4858 CHECK_EQ(56, context->Global()
4859 ->Get(context.local(), v8::Integer::New(isolate, 13))
4860 .ToLocalChecked()
4861 ->Int32Value(context.local())
4862 .FromJust());
4863 CHECK_EQ(56, context->Global()
4864 ->Get(context.local(), v8_str("13"))
4865 .ToLocalChecked()
4866 ->Int32Value(context.local())
4867 .FromJust());
4868 CHECK_EQ(56, context->Global()
4869 ->Get(context.local(), v8_num(13))
4870 .ToLocalChecked()
4871 ->Int32Value(context.local())
4872 .FromJust());
4424 } 4873 }
4425 4874
4426 4875
4876 /*
4877 TODO(vogelheim): What about ForceSet
4878
4879
4427 THREADED_TEST(PropertyAttributes) { 4880 THREADED_TEST(PropertyAttributes) {
4428 LocalContext context; 4881 LocalContext context;
4429 v8::HandleScope scope(context->GetIsolate()); 4882 v8::HandleScope scope(context->GetIsolate());
4430 // none 4883 // none
4431 Local<String> prop = v8_str("none"); 4884 Local<String> prop = v8_str("none");
4432 context->Global()->Set(prop, v8_num(7)); 4885 CHECK(context->Global()->Set(context.local(), prop, v8_num(7)).FromJust());
4433 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4886 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(),
4887 prop).FromJust());
4434 // read-only 4888 // read-only
4435 prop = v8_str("read_only"); 4889 prop = v8_str("read_only");
4436 context->Global()->ForceSet(prop, v8_num(7), v8::ReadOnly); 4890 context->Global()->ForceSet(context.local(), prop, v8_num(7),
vogelheim 2015/11/23 18:22:15 I can't figure out how to replace ForceSet with no
jochen (gone - plz use gerrit) 2015/11/24 12:42:25 does context->Global()->DefineOwnProperty(context.
vogelheim 2015/11/26 10:57:32 It does. Done.
4437 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4891 v8::ReadOnly).FromJust();
4438 CHECK_EQ(v8::ReadOnly, context->Global()->GetPropertyAttributes(prop)); 4892 CHECK_EQ(7, context->Global()->Get(context.local(),
4893 prop).ToLocalChecked()->Int32Value(context.local()).FromJust());
4894 CHECK_EQ(v8::ReadOnly,
4895 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust());
4439 CompileRun("read_only = 9"); 4896 CompileRun("read_only = 9");
4440 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4897 CHECK_EQ(7, context->Global()->Get(context.local(),
4441 context->Global()->Set(prop, v8_num(10)); 4898 prop).ToLocalChecked()->Int32Value(context.local()).FromJust());
4442 CHECK_EQ(7, context->Global()->Get(prop)->Int32Value()); 4899 CHECK(context->Global()->Set(context.local(), prop, v8_num(10)).FromJust());
4900 CHECK_EQ(7, context->Global()->Get(context.local(),
4901 prop).ToLocalChecked()->Int32Value(context.local()).FromJust());
4443 // dont-delete 4902 // dont-delete
4444 prop = v8_str("dont_delete"); 4903 prop = v8_str("dont_delete");
4445 context->Global()->ForceSet(prop, v8_num(13), v8::DontDelete); 4904 context->Global()->ForceSet(context.local(), prop, v8_num(13),
4446 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4905 v8::DontDelete).FromJust();
4906 CHECK_EQ(13, context->Global()->Get(context.local(),
4907 prop).ToLocalChecked()->Int32Value(context.local()).FromJust());
4447 CompileRun("delete dont_delete"); 4908 CompileRun("delete dont_delete");
4448 CHECK_EQ(13, context->Global()->Get(prop)->Int32Value()); 4909 CHECK_EQ(13, context->Global()->Get(context.local(),
4449 CHECK_EQ(v8::DontDelete, context->Global()->GetPropertyAttributes(prop)); 4910 prop).ToLocalChecked()->Int32Value(context.local()).FromJust());
4911 CHECK_EQ(v8::DontDelete,
4912 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust());
4450 // dont-enum 4913 // dont-enum
4451 prop = v8_str("dont_enum"); 4914 prop = v8_str("dont_enum");
4452 context->Global()->ForceSet(prop, v8_num(28), v8::DontEnum); 4915 context->Global()->ForceSet(prop, v8_num(28), v8::DontEnum);
4453 CHECK_EQ(v8::DontEnum, context->Global()->GetPropertyAttributes(prop)); 4916 CHECK_EQ(v8::DontEnum,
4917 context->Global()->GetPropertyAttributes(context.local(), prop).FromJust());
4454 // absent 4918 // absent
4455 prop = v8_str("absent"); 4919 prop = v8_str("absent");
4456 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(prop)); 4920 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(),
4921 prop).FromJust());
4457 Local<Value> fake_prop = v8_num(1); 4922 Local<Value> fake_prop = v8_num(1);
4458 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(fake_prop)); 4923 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(),
4924 fake_prop).FromJust());
4459 // exception 4925 // exception
4460 TryCatch try_catch(context->GetIsolate()); 4926 TryCatch try_catch(context->GetIsolate());
4461 Local<Value> exception = 4927 Local<Value> exception =
4462 CompileRun("({ toString: function() { throw 'exception';} })"); 4928 CompileRun("({ toString: function() { throw 'exception';} })");
4463 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(exception)); 4929 CHECK_EQ(v8::None, context->Global()->GetPropertyAttributes(context.local(),
4930 exception).FromJust());
4464 CHECK(try_catch.HasCaught()); 4931 CHECK(try_catch.HasCaught());
4465 String::Utf8Value exception_value(try_catch.Exception()); 4932 String::Utf8Value exception_value(try_catch.Exception());
4466 CHECK_EQ(0, strcmp("exception", *exception_value)); 4933 CHECK_EQ(0, strcmp("exception", *exception_value));
4467 try_catch.Reset(); 4934 try_catch.Reset();
4468 } 4935 }
4469 4936 */
4470 4937
4471 THREADED_TEST(Array) { 4938 THREADED_TEST(Array) {
4472 LocalContext context; 4939 LocalContext context;
4473 v8::HandleScope scope(context->GetIsolate()); 4940 v8::HandleScope scope(context->GetIsolate());
4474 Local<v8::Array> array = v8::Array::New(context->GetIsolate()); 4941 Local<v8::Array> array = v8::Array::New(context->GetIsolate());
4475 CHECK_EQ(0u, array->Length()); 4942 CHECK_EQ(0u, array->Length());
4476 CHECK(array->Get(0)->IsUndefined()); 4943 CHECK(array->Get(context.local(), 0).ToLocalChecked()->IsUndefined());
4477 CHECK(!array->Has(0)); 4944 CHECK(!array->Has(context.local(), 0).FromJust());
4478 CHECK(array->Get(100)->IsUndefined()); 4945 CHECK(array->Get(context.local(), 100).ToLocalChecked()->IsUndefined());
4479 CHECK(!array->Has(100)); 4946 CHECK(!array->Has(context.local(), 100).FromJust());
4480 array->Set(2, v8_num(7)); 4947 CHECK(array->Set(context.local(), 2, v8_num(7)).FromJust());
4481 CHECK_EQ(3u, array->Length()); 4948 CHECK_EQ(3u, array->Length());
4482 CHECK(!array->Has(0)); 4949 CHECK(!array->Has(context.local(), 0).FromJust());
4483 CHECK(!array->Has(1)); 4950 CHECK(!array->Has(context.local(), 1).FromJust());
4484 CHECK(array->Has(2)); 4951 CHECK(array->Has(context.local(), 2).FromJust());
4485 CHECK_EQ(7, array->Get(2)->Int32Value()); 4952 CHECK_EQ(7, array->Get(context.local(), 2)
4953 .ToLocalChecked()
4954 ->Int32Value(context.local())
4955 .FromJust());
4486 Local<Value> obj = CompileRun("[1, 2, 3]"); 4956 Local<Value> obj = CompileRun("[1, 2, 3]");
4487 Local<v8::Array> arr = obj.As<v8::Array>(); 4957 Local<v8::Array> arr = obj.As<v8::Array>();
4488 CHECK_EQ(3u, arr->Length()); 4958 CHECK_EQ(3u, arr->Length());
4489 CHECK_EQ(1, arr->Get(0)->Int32Value()); 4959 CHECK_EQ(1, arr->Get(context.local(), 0)
4490 CHECK_EQ(2, arr->Get(1)->Int32Value()); 4960 .ToLocalChecked()
4491 CHECK_EQ(3, arr->Get(2)->Int32Value()); 4961 ->Int32Value(context.local())
4962 .FromJust());
4963 CHECK_EQ(2, arr->Get(context.local(), 1)
4964 .ToLocalChecked()
4965 ->Int32Value(context.local())
4966 .FromJust());
4967 CHECK_EQ(3, arr->Get(context.local(), 2)
4968 .ToLocalChecked()
4969 ->Int32Value(context.local())
4970 .FromJust());
4492 array = v8::Array::New(context->GetIsolate(), 27); 4971 array = v8::Array::New(context->GetIsolate(), 27);
4493 CHECK_EQ(27u, array->Length()); 4972 CHECK_EQ(27u, array->Length());
4494 array = v8::Array::New(context->GetIsolate(), -27); 4973 array = v8::Array::New(context->GetIsolate(), -27);
4495 CHECK_EQ(0u, array->Length()); 4974 CHECK_EQ(0u, array->Length());
4496 } 4975 }
4497 4976
4498 4977
4499 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) { 4978 void HandleF(const v8::FunctionCallbackInfo<v8::Value>& args) {
4500 v8::EscapableHandleScope scope(args.GetIsolate()); 4979 v8::EscapableHandleScope scope(args.GetIsolate());
4501 ApiTestFuzzer::Fuzz(); 4980 ApiTestFuzzer::Fuzz();
4502 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); 4981 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]); 4982 for (int i = 0; i < args.Length(); i++) {
4983 CHECK(result->Set(CcTest::isolate()->GetCurrentContext(), i, args[i])
4984 .FromJust());
4985 }
4504 args.GetReturnValue().Set(scope.Escape(result)); 4986 args.GetReturnValue().Set(scope.Escape(result));
4505 } 4987 }
4506 4988
4507 4989
4508 THREADED_TEST(Vector) { 4990 THREADED_TEST(Vector) {
4509 v8::Isolate* isolate = CcTest::isolate(); 4991 v8::Isolate* isolate = CcTest::isolate();
4510 v8::HandleScope scope(isolate); 4992 v8::HandleScope scope(isolate);
4511 Local<ObjectTemplate> global = ObjectTemplate::New(isolate); 4993 Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
4512 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF)); 4994 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF));
4513 LocalContext context(0, global); 4995 LocalContext context(0, global);
4514 4996
4515 const char* fun = "f()"; 4997 const char* fun = "f()";
4516 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); 4998 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>();
4517 CHECK_EQ(0u, a0->Length()); 4999 CHECK_EQ(0u, a0->Length());
4518 5000
4519 const char* fun2 = "f(11)"; 5001 const char* fun2 = "f(11)";
4520 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); 5002 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>();
4521 CHECK_EQ(1u, a1->Length()); 5003 CHECK_EQ(1u, a1->Length());
4522 CHECK_EQ(11, a1->Get(0)->Int32Value()); 5004 CHECK_EQ(11, a1->Get(context.local(), 0)
5005 .ToLocalChecked()
5006 ->Int32Value(context.local())
5007 .FromJust());
4523 5008
4524 const char* fun3 = "f(12, 13)"; 5009 const char* fun3 = "f(12, 13)";
4525 Local<v8::Array> a2 = CompileRun(fun3).As<v8::Array>(); 5010 Local<v8::Array> a2 = CompileRun(fun3).As<v8::Array>();
4526 CHECK_EQ(2u, a2->Length()); 5011 CHECK_EQ(2u, a2->Length());
4527 CHECK_EQ(12, a2->Get(0)->Int32Value()); 5012 CHECK_EQ(12, a2->Get(context.local(), 0)
4528 CHECK_EQ(13, a2->Get(1)->Int32Value()); 5013 .ToLocalChecked()
5014 ->Int32Value(context.local())
5015 .FromJust());
5016 CHECK_EQ(13, a2->Get(context.local(), 1)
5017 .ToLocalChecked()
5018 ->Int32Value(context.local())
5019 .FromJust());
4529 5020
4530 const char* fun4 = "f(14, 15, 16)"; 5021 const char* fun4 = "f(14, 15, 16)";
4531 Local<v8::Array> a3 = CompileRun(fun4).As<v8::Array>(); 5022 Local<v8::Array> a3 = CompileRun(fun4).As<v8::Array>();
4532 CHECK_EQ(3u, a3->Length()); 5023 CHECK_EQ(3u, a3->Length());
4533 CHECK_EQ(14, a3->Get(0)->Int32Value()); 5024 CHECK_EQ(14, a3->Get(context.local(), 0)
4534 CHECK_EQ(15, a3->Get(1)->Int32Value()); 5025 .ToLocalChecked()
4535 CHECK_EQ(16, a3->Get(2)->Int32Value()); 5026 ->Int32Value(context.local())
5027 .FromJust());
5028 CHECK_EQ(15, a3->Get(context.local(), 1)
5029 .ToLocalChecked()
5030 ->Int32Value(context.local())
5031 .FromJust());
5032 CHECK_EQ(16, a3->Get(context.local(), 2)
5033 .ToLocalChecked()
5034 ->Int32Value(context.local())
5035 .FromJust());
4536 5036
4537 const char* fun5 = "f(17, 18, 19, 20)"; 5037 const char* fun5 = "f(17, 18, 19, 20)";
4538 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>(); 5038 Local<v8::Array> a4 = CompileRun(fun5).As<v8::Array>();
4539 CHECK_EQ(4u, a4->Length()); 5039 CHECK_EQ(4u, a4->Length());
4540 CHECK_EQ(17, a4->Get(0)->Int32Value()); 5040 CHECK_EQ(17, a4->Get(context.local(), 0)
4541 CHECK_EQ(18, a4->Get(1)->Int32Value()); 5041 .ToLocalChecked()
4542 CHECK_EQ(19, a4->Get(2)->Int32Value()); 5042 ->Int32Value(context.local())
4543 CHECK_EQ(20, a4->Get(3)->Int32Value()); 5043 .FromJust());
5044 CHECK_EQ(18, a4->Get(context.local(), 1)
5045 .ToLocalChecked()
5046 ->Int32Value(context.local())
5047 .FromJust());
5048 CHECK_EQ(19, a4->Get(context.local(), 2)
5049 .ToLocalChecked()
5050 ->Int32Value(context.local())
5051 .FromJust());
5052 CHECK_EQ(20, a4->Get(context.local(), 3)
5053 .ToLocalChecked()
5054 ->Int32Value(context.local())
5055 .FromJust());
4544 } 5056 }
4545 5057
4546 5058
4547 THREADED_TEST(FunctionCall) { 5059 THREADED_TEST(FunctionCall) {
4548 LocalContext context; 5060 LocalContext context;
4549 v8::Isolate* isolate = context->GetIsolate(); 5061 v8::Isolate* isolate = context->GetIsolate();
4550 v8::HandleScope scope(isolate); 5062 v8::HandleScope scope(isolate);
4551 CompileRun( 5063 CompileRun(
4552 "function Foo() {" 5064 "function Foo() {"
4553 " var result = [];" 5065 " var result = [];"
4554 " for (var i = 0; i < arguments.length; i++) {" 5066 " for (var i = 0; i < arguments.length; i++) {"
4555 " result.push(arguments[i]);" 5067 " result.push(arguments[i]);"
4556 " }" 5068 " }"
4557 " return result;" 5069 " return result;"
4558 "}" 5070 "}"
4559 "function ReturnThisSloppy() {" 5071 "function ReturnThisSloppy() {"
4560 " return this;" 5072 " return this;"
4561 "}" 5073 "}"
4562 "function ReturnThisStrict() {" 5074 "function ReturnThisStrict() {"
4563 " 'use strict';" 5075 " 'use strict';"
4564 " return this;" 5076 " return this;"
4565 "}"); 5077 "}");
4566 Local<Function> Foo = 5078 Local<Function> Foo = Local<Function>::Cast(
4567 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 5079 context->Global()->Get(context.local(), v8_str("Foo")).ToLocalChecked());
4568 Local<Function> ReturnThisSloppy = 5080 Local<Function> ReturnThisSloppy = Local<Function>::Cast(
4569 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisSloppy"))); 5081 context->Global()
4570 Local<Function> ReturnThisStrict = 5082 ->Get(context.local(), v8_str("ReturnThisSloppy"))
4571 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict"))); 5083 .ToLocalChecked());
5084 Local<Function> ReturnThisStrict = Local<Function>::Cast(
5085 context->Global()
5086 ->Get(context.local(), v8_str("ReturnThisStrict"))
5087 .ToLocalChecked());
4572 5088
4573 v8::Handle<Value>* args0 = NULL; 5089 v8::Local<Value>* args0 = NULL;
4574 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0)); 5090 Local<v8::Array> a0 = Local<v8::Array>::Cast(
5091 Foo->Call(context.local(), Foo, 0, args0).ToLocalChecked());
4575 CHECK_EQ(0u, a0->Length()); 5092 CHECK_EQ(0u, a0->Length());
4576 5093
4577 v8::Handle<Value> args1[] = {v8_num(1.1)}; 5094 v8::Local<Value> args1[] = {v8_num(1.1)};
4578 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1)); 5095 Local<v8::Array> a1 = Local<v8::Array>::Cast(
5096 Foo->Call(context.local(), Foo, 1, args1).ToLocalChecked());
4579 CHECK_EQ(1u, a1->Length()); 5097 CHECK_EQ(1u, a1->Length());
4580 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5098 CHECK_EQ(1.1, a1->Get(context.local(), v8::Integer::New(isolate, 0))
5099 .ToLocalChecked()
5100 ->NumberValue(context.local())
5101 .FromJust());
4581 5102
4582 v8::Handle<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; 5103 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)); 5104 Local<v8::Array> a2 = Local<v8::Array>::Cast(
5105 Foo->Call(context.local(), Foo, 2, args2).ToLocalChecked());
4584 CHECK_EQ(2u, a2->Length()); 5106 CHECK_EQ(2u, a2->Length());
4585 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5107 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()); 5108 .ToLocalChecked()
5109 ->NumberValue(context.local())
5110 .FromJust());
5111 CHECK_EQ(3.3, a2->Get(context.local(), v8::Integer::New(isolate, 1))
5112 .ToLocalChecked()
5113 ->NumberValue(context.local())
5114 .FromJust());
4587 5115
4588 v8::Handle<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; 5116 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)); 5117 Local<v8::Array> a3 = Local<v8::Array>::Cast(
5118 Foo->Call(context.local(), Foo, 3, args3).ToLocalChecked());
4590 CHECK_EQ(3u, a3->Length()); 5119 CHECK_EQ(3u, a3->Length());
4591 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5120 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()); 5121 .ToLocalChecked()
4593 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); 5122 ->NumberValue(context.local())
5123 .FromJust());
5124 CHECK_EQ(5.5, a3->Get(context.local(), v8::Integer::New(isolate, 1))
5125 .ToLocalChecked()
5126 ->NumberValue(context.local())
5127 .FromJust());
5128 CHECK_EQ(6.6, a3->Get(context.local(), v8::Integer::New(isolate, 2))
5129 .ToLocalChecked()
5130 ->NumberValue(context.local())
5131 .FromJust());
4594 5132
4595 v8::Handle<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), 5133 v8::Local<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9),
4596 v8_num(10.11)}; 5134 v8_num(10.11)};
4597 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4)); 5135 Local<v8::Array> a4 = Local<v8::Array>::Cast(
5136 Foo->Call(context.local(), Foo, 4, args4).ToLocalChecked());
4598 CHECK_EQ(4u, a4->Length()); 5137 CHECK_EQ(4u, a4->Length());
4599 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5138 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()); 5139 .ToLocalChecked()
4601 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); 5140 ->NumberValue(context.local())
4602 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); 5141 .FromJust());
5142 CHECK_EQ(8.8, a4->Get(context.local(), v8::Integer::New(isolate, 1))
5143 .ToLocalChecked()
5144 ->NumberValue(context.local())
5145 .FromJust());
5146 CHECK_EQ(9.9, a4->Get(context.local(), v8::Integer::New(isolate, 2))
5147 .ToLocalChecked()
5148 ->NumberValue(context.local())
5149 .FromJust());
5150 CHECK_EQ(10.11, a4->Get(context.local(), v8::Integer::New(isolate, 3))
5151 .ToLocalChecked()
5152 ->NumberValue(context.local())
5153 .FromJust());
4603 5154
4604 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL); 5155 Local<v8::Value> r1 =
5156 ReturnThisSloppy->Call(context.local(), v8::Undefined(isolate), 0, NULL)
5157 .ToLocalChecked();
4605 CHECK(r1->StrictEquals(context->Global())); 5158 CHECK(r1->StrictEquals(context->Global()));
4606 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL); 5159 Local<v8::Value> r2 =
5160 ReturnThisSloppy->Call(context.local(), v8::Null(isolate), 0, NULL)
5161 .ToLocalChecked();
4607 CHECK(r2->StrictEquals(context->Global())); 5162 CHECK(r2->StrictEquals(context->Global()));
4608 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL); 5163 Local<v8::Value> r3 =
5164 ReturnThisSloppy->Call(context.local(), v8_num(42), 0, NULL)
5165 .ToLocalChecked();
4609 CHECK(r3->IsNumberObject()); 5166 CHECK(r3->IsNumberObject());
4610 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf()); 5167 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf());
4611 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL); 5168 Local<v8::Value> r4 =
5169 ReturnThisSloppy->Call(context.local(), v8_str("hello"), 0, NULL)
5170 .ToLocalChecked();
4612 CHECK(r4->IsStringObject()); 5171 CHECK(r4->IsStringObject());
4613 CHECK(r4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello"))); 5172 CHECK(r4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello")));
4614 Local<v8::Value> r5 = ReturnThisSloppy->Call(v8::True(isolate), 0, NULL); 5173 Local<v8::Value> r5 =
5174 ReturnThisSloppy->Call(context.local(), v8::True(isolate), 0, NULL)
5175 .ToLocalChecked();
4615 CHECK(r5->IsBooleanObject()); 5176 CHECK(r5->IsBooleanObject());
4616 CHECK(r5.As<v8::BooleanObject>()->ValueOf()); 5177 CHECK(r5.As<v8::BooleanObject>()->ValueOf());
4617 5178
4618 Local<v8::Value> r6 = ReturnThisStrict->Call(v8::Undefined(isolate), 0, NULL); 5179 Local<v8::Value> r6 =
5180 ReturnThisStrict->Call(context.local(), v8::Undefined(isolate), 0, NULL)
5181 .ToLocalChecked();
4619 CHECK(r6->IsUndefined()); 5182 CHECK(r6->IsUndefined());
4620 Local<v8::Value> r7 = ReturnThisStrict->Call(v8::Null(isolate), 0, NULL); 5183 Local<v8::Value> r7 =
5184 ReturnThisStrict->Call(context.local(), v8::Null(isolate), 0, NULL)
5185 .ToLocalChecked();
4621 CHECK(r7->IsNull()); 5186 CHECK(r7->IsNull());
4622 Local<v8::Value> r8 = ReturnThisStrict->Call(v8_num(42), 0, NULL); 5187 Local<v8::Value> r8 =
5188 ReturnThisStrict->Call(context.local(), v8_num(42), 0, NULL)
5189 .ToLocalChecked();
4623 CHECK(r8->StrictEquals(v8_num(42))); 5190 CHECK(r8->StrictEquals(v8_num(42)));
4624 Local<v8::Value> r9 = ReturnThisStrict->Call(v8_str("hello"), 0, NULL); 5191 Local<v8::Value> r9 =
5192 ReturnThisStrict->Call(context.local(), v8_str("hello"), 0, NULL)
5193 .ToLocalChecked();
4625 CHECK(r9->StrictEquals(v8_str("hello"))); 5194 CHECK(r9->StrictEquals(v8_str("hello")));
4626 Local<v8::Value> r10 = ReturnThisStrict->Call(v8::True(isolate), 0, NULL); 5195 Local<v8::Value> r10 =
5196 ReturnThisStrict->Call(context.local(), v8::True(isolate), 0, NULL)
5197 .ToLocalChecked();
4627 CHECK(r10->StrictEquals(v8::True(isolate))); 5198 CHECK(r10->StrictEquals(v8::True(isolate)));
4628 } 5199 }
4629 5200
4630 5201
4631 THREADED_TEST(ConstructCall) { 5202 THREADED_TEST(ConstructCall) {
4632 LocalContext context; 5203 LocalContext context;
4633 v8::Isolate* isolate = context->GetIsolate(); 5204 v8::Isolate* isolate = context->GetIsolate();
4634 v8::HandleScope scope(isolate); 5205 v8::HandleScope scope(isolate);
4635 CompileRun( 5206 CompileRun(
4636 "function Foo() {" 5207 "function Foo() {"
4637 " var result = [];" 5208 " var result = [];"
4638 " for (var i = 0; i < arguments.length; i++) {" 5209 " for (var i = 0; i < arguments.length; i++) {"
4639 " result.push(arguments[i]);" 5210 " result.push(arguments[i]);"
4640 " }" 5211 " }"
4641 " return result;" 5212 " return result;"
4642 "}"); 5213 "}");
4643 Local<Function> Foo = 5214 Local<Function> Foo = Local<Function>::Cast(
4644 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 5215 context->Global()->Get(context.local(), v8_str("Foo")).ToLocalChecked());
4645 5216
4646 v8::Handle<Value>* args0 = NULL; 5217 v8::Local<Value>* args0 = NULL;
4647 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->NewInstance(0, args0)); 5218 Local<v8::Array> a0 = Local<v8::Array>::Cast(
5219 Foo->NewInstance(context.local(), 0, args0).ToLocalChecked());
4648 CHECK_EQ(0u, a0->Length()); 5220 CHECK_EQ(0u, a0->Length());
4649 5221
4650 v8::Handle<Value> args1[] = {v8_num(1.1)}; 5222 v8::Local<Value> args1[] = {v8_num(1.1)};
4651 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->NewInstance(1, args1)); 5223 Local<v8::Array> a1 = Local<v8::Array>::Cast(
5224 Foo->NewInstance(context.local(), 1, args1).ToLocalChecked());
4652 CHECK_EQ(1u, a1->Length()); 5225 CHECK_EQ(1u, a1->Length());
4653 CHECK_EQ(1.1, a1->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5226 CHECK_EQ(1.1, a1->Get(context.local(), v8::Integer::New(isolate, 0))
5227 .ToLocalChecked()
5228 ->NumberValue(context.local())
5229 .FromJust());
4654 5230
4655 v8::Handle<Value> args2[] = {v8_num(2.2), v8_num(3.3)}; 5231 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)); 5232 Local<v8::Array> a2 = Local<v8::Array>::Cast(
5233 Foo->NewInstance(context.local(), 2, args2).ToLocalChecked());
4657 CHECK_EQ(2u, a2->Length()); 5234 CHECK_EQ(2u, a2->Length());
4658 CHECK_EQ(2.2, a2->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5235 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()); 5236 .ToLocalChecked()
5237 ->NumberValue(context.local())
5238 .FromJust());
5239 CHECK_EQ(3.3, a2->Get(context.local(), v8::Integer::New(isolate, 1))
5240 .ToLocalChecked()
5241 ->NumberValue(context.local())
5242 .FromJust());
4660 5243
4661 v8::Handle<Value> args3[] = {v8_num(4.4), v8_num(5.5), v8_num(6.6)}; 5244 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)); 5245 Local<v8::Array> a3 = Local<v8::Array>::Cast(
5246 Foo->NewInstance(context.local(), 3, args3).ToLocalChecked());
4663 CHECK_EQ(3u, a3->Length()); 5247 CHECK_EQ(3u, a3->Length());
4664 CHECK_EQ(4.4, a3->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5248 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()); 5249 .ToLocalChecked()
4666 CHECK_EQ(6.6, a3->Get(v8::Integer::New(isolate, 2))->NumberValue()); 5250 ->NumberValue(context.local())
5251 .FromJust());
5252 CHECK_EQ(5.5, a3->Get(context.local(), v8::Integer::New(isolate, 1))
5253 .ToLocalChecked()
5254 ->NumberValue(context.local())
5255 .FromJust());
5256 CHECK_EQ(6.6, a3->Get(context.local(), v8::Integer::New(isolate, 2))
5257 .ToLocalChecked()
5258 ->NumberValue(context.local())
5259 .FromJust());
4667 5260
4668 v8::Handle<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9), 5261 v8::Local<Value> args4[] = {v8_num(7.7), v8_num(8.8), v8_num(9.9),
4669 v8_num(10.11)}; 5262 v8_num(10.11)};
4670 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->NewInstance(4, args4)); 5263 Local<v8::Array> a4 = Local<v8::Array>::Cast(
5264 Foo->NewInstance(context.local(), 4, args4).ToLocalChecked());
4671 CHECK_EQ(4u, a4->Length()); 5265 CHECK_EQ(4u, a4->Length());
4672 CHECK_EQ(7.7, a4->Get(v8::Integer::New(isolate, 0))->NumberValue()); 5266 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()); 5267 .ToLocalChecked()
4674 CHECK_EQ(9.9, a4->Get(v8::Integer::New(isolate, 2))->NumberValue()); 5268 ->NumberValue(context.local())
4675 CHECK_EQ(10.11, a4->Get(v8::Integer::New(isolate, 3))->NumberValue()); 5269 .FromJust());
5270 CHECK_EQ(8.8, a4->Get(context.local(), v8::Integer::New(isolate, 1))
5271 .ToLocalChecked()
5272 ->NumberValue(context.local())
5273 .FromJust());
5274 CHECK_EQ(9.9, a4->Get(context.local(), v8::Integer::New(isolate, 2))
5275 .ToLocalChecked()
5276 ->NumberValue(context.local())
5277 .FromJust());
5278 CHECK_EQ(10.11, a4->Get(context.local(), v8::Integer::New(isolate, 3))
5279 .ToLocalChecked()
5280 ->NumberValue(context.local())
5281 .FromJust());
4676 } 5282 }
4677 5283
4678 5284
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) { 5285 THREADED_TEST(ConversionNumber) {
4688 LocalContext env; 5286 LocalContext env;
4689 v8::Isolate* isolate = env->GetIsolate(); 5287 v8::Isolate* isolate = env->GetIsolate();
4690 v8::HandleScope scope(isolate); 5288 v8::HandleScope scope(isolate);
4691 // Very large number. 5289 // Very large number.
4692 CompileRun("var obj = Math.pow(2,32) * 1237;"); 5290 CompileRun("var obj = Math.pow(2,32) * 1237;");
4693 Local<Value> obj = env->Global()->Get(v8_str("obj")); 5291 Local<Value> obj =
4694 CHECK_EQ(5312874545152.0, obj->ToNumber(isolate)->Value()); 5292 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4695 CHECK_EQ(0, obj->ToInt32(isolate)->Value()); 5293 CHECK_EQ(5312874545152.0,
5294 obj->ToNumber(env.local()).ToLocalChecked()->Value());
5295 CHECK_EQ(0, obj->ToInt32(env.local()).ToLocalChecked()->Value());
4696 CHECK(0u == 5296 CHECK(0u ==
4697 obj->ToUint32(isolate)->Value()); // NOLINT - no CHECK_EQ for unsigned. 5297 obj->ToUint32(env.local())
5298 .ToLocalChecked()
5299 ->Value()); // NOLINT - no CHECK_EQ for unsigned.
4698 // Large number. 5300 // Large number.
4699 CompileRun("var obj = -1234567890123;"); 5301 CompileRun("var obj = -1234567890123;");
4700 obj = env->Global()->Get(v8_str("obj")); 5302 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4701 CHECK_EQ(-1234567890123.0, obj->ToNumber(isolate)->Value()); 5303 CHECK_EQ(-1234567890123.0,
4702 CHECK_EQ(-1912276171, obj->ToInt32(isolate)->Value()); 5304 obj->ToNumber(env.local()).ToLocalChecked()->Value());
4703 CHECK(2382691125u == obj->ToUint32(isolate)->Value()); // NOLINT 5305 CHECK_EQ(-1912276171, obj->ToInt32(env.local()).ToLocalChecked()->Value());
5306 CHECK(2382691125u ==
5307 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4704 // Small positive integer. 5308 // Small positive integer.
4705 CompileRun("var obj = 42;"); 5309 CompileRun("var obj = 42;");
4706 obj = env->Global()->Get(v8_str("obj")); 5310 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4707 CHECK_EQ(42.0, obj->ToNumber(isolate)->Value()); 5311 CHECK_EQ(42.0, obj->ToNumber(env.local()).ToLocalChecked()->Value());
4708 CHECK_EQ(42, obj->ToInt32(isolate)->Value()); 5312 CHECK_EQ(42, obj->ToInt32(env.local()).ToLocalChecked()->Value());
4709 CHECK(42u == obj->ToUint32(isolate)->Value()); // NOLINT 5313 CHECK(42u == obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4710 // Negative integer. 5314 // Negative integer.
4711 CompileRun("var obj = -37;"); 5315 CompileRun("var obj = -37;");
4712 obj = env->Global()->Get(v8_str("obj")); 5316 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4713 CHECK_EQ(-37.0, obj->ToNumber(isolate)->Value()); 5317 CHECK_EQ(-37.0, obj->ToNumber(env.local()).ToLocalChecked()->Value());
4714 CHECK_EQ(-37, obj->ToInt32(isolate)->Value()); 5318 CHECK_EQ(-37, obj->ToInt32(env.local()).ToLocalChecked()->Value());
4715 CHECK(4294967259u == obj->ToUint32(isolate)->Value()); // NOLINT 5319 CHECK(4294967259u ==
5320 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4716 // Positive non-int32 integer. 5321 // Positive non-int32 integer.
4717 CompileRun("var obj = 0x81234567;"); 5322 CompileRun("var obj = 0x81234567;");
4718 obj = env->Global()->Get(v8_str("obj")); 5323 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4719 CHECK_EQ(2166572391.0, obj->ToNumber(isolate)->Value()); 5324 CHECK_EQ(2166572391.0, obj->ToNumber(env.local()).ToLocalChecked()->Value());
4720 CHECK_EQ(-2128394905, obj->ToInt32(isolate)->Value()); 5325 CHECK_EQ(-2128394905, obj->ToInt32(env.local()).ToLocalChecked()->Value());
4721 CHECK(2166572391u == obj->ToUint32(isolate)->Value()); // NOLINT 5326 CHECK(2166572391u ==
5327 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4722 // Fraction. 5328 // Fraction.
4723 CompileRun("var obj = 42.3;"); 5329 CompileRun("var obj = 42.3;");
4724 obj = env->Global()->Get(v8_str("obj")); 5330 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4725 CHECK_EQ(42.3, obj->ToNumber(isolate)->Value()); 5331 CHECK_EQ(42.3, obj->ToNumber(env.local()).ToLocalChecked()->Value());
4726 CHECK_EQ(42, obj->ToInt32(isolate)->Value()); 5332 CHECK_EQ(42, obj->ToInt32(env.local()).ToLocalChecked()->Value());
4727 CHECK(42u == obj->ToUint32(isolate)->Value()); // NOLINT 5333 CHECK(42u == obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4728 // Large negative fraction. 5334 // Large negative fraction.
4729 CompileRun("var obj = -5726623061.75;"); 5335 CompileRun("var obj = -5726623061.75;");
4730 obj = env->Global()->Get(v8_str("obj")); 5336 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4731 CHECK_EQ(-5726623061.75, obj->ToNumber(isolate)->Value()); 5337 CHECK_EQ(-5726623061.75,
4732 CHECK_EQ(-1431655765, obj->ToInt32(isolate)->Value()); 5338 obj->ToNumber(env.local()).ToLocalChecked()->Value());
4733 CHECK(2863311531u == obj->ToUint32(isolate)->Value()); // NOLINT 5339 CHECK_EQ(-1431655765, obj->ToInt32(env.local()).ToLocalChecked()->Value());
5340 CHECK(2863311531u ==
5341 obj->ToUint32(env.local()).ToLocalChecked()->Value()); // NOLINT
4734 } 5342 }
4735 5343
4736 5344
4737 THREADED_TEST(isNumberType) { 5345 THREADED_TEST(isNumberType) {
4738 LocalContext env; 5346 LocalContext env;
4739 v8::HandleScope scope(env->GetIsolate()); 5347 v8::HandleScope scope(env->GetIsolate());
4740 // Very large number. 5348 // Very large number.
4741 CompileRun("var obj = Math.pow(2,32) * 1237;"); 5349 CompileRun("var obj = Math.pow(2,32) * 1237;");
4742 Local<Value> obj = env->Global()->Get(v8_str("obj")); 5350 Local<Value> obj =
5351 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4743 CHECK(!obj->IsInt32()); 5352 CHECK(!obj->IsInt32());
4744 CHECK(!obj->IsUint32()); 5353 CHECK(!obj->IsUint32());
4745 // Large negative number. 5354 // Large negative number.
4746 CompileRun("var obj = -1234567890123;"); 5355 CompileRun("var obj = -1234567890123;");
4747 obj = env->Global()->Get(v8_str("obj")); 5356 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4748 CHECK(!obj->IsInt32()); 5357 CHECK(!obj->IsInt32());
4749 CHECK(!obj->IsUint32()); 5358 CHECK(!obj->IsUint32());
4750 // Small positive integer. 5359 // Small positive integer.
4751 CompileRun("var obj = 42;"); 5360 CompileRun("var obj = 42;");
4752 obj = env->Global()->Get(v8_str("obj")); 5361 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4753 CHECK(obj->IsInt32()); 5362 CHECK(obj->IsInt32());
4754 CHECK(obj->IsUint32()); 5363 CHECK(obj->IsUint32());
4755 // Negative integer. 5364 // Negative integer.
4756 CompileRun("var obj = -37;"); 5365 CompileRun("var obj = -37;");
4757 obj = env->Global()->Get(v8_str("obj")); 5366 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4758 CHECK(obj->IsInt32()); 5367 CHECK(obj->IsInt32());
4759 CHECK(!obj->IsUint32()); 5368 CHECK(!obj->IsUint32());
4760 // Positive non-int32 integer. 5369 // Positive non-int32 integer.
4761 CompileRun("var obj = 0x81234567;"); 5370 CompileRun("var obj = 0x81234567;");
4762 obj = env->Global()->Get(v8_str("obj")); 5371 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4763 CHECK(!obj->IsInt32()); 5372 CHECK(!obj->IsInt32());
4764 CHECK(obj->IsUint32()); 5373 CHECK(obj->IsUint32());
4765 // Fraction. 5374 // Fraction.
4766 CompileRun("var obj = 42.3;"); 5375 CompileRun("var obj = 42.3;");
4767 obj = env->Global()->Get(v8_str("obj")); 5376 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4768 CHECK(!obj->IsInt32()); 5377 CHECK(!obj->IsInt32());
4769 CHECK(!obj->IsUint32()); 5378 CHECK(!obj->IsUint32());
4770 // Large negative fraction. 5379 // Large negative fraction.
4771 CompileRun("var obj = -5726623061.75;"); 5380 CompileRun("var obj = -5726623061.75;");
4772 obj = env->Global()->Get(v8_str("obj")); 5381 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4773 CHECK(!obj->IsInt32()); 5382 CHECK(!obj->IsInt32());
4774 CHECK(!obj->IsUint32()); 5383 CHECK(!obj->IsUint32());
4775 // Positive zero 5384 // Positive zero
4776 CompileRun("var obj = 0.0;"); 5385 CompileRun("var obj = 0.0;");
4777 obj = env->Global()->Get(v8_str("obj")); 5386 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4778 CHECK(obj->IsInt32()); 5387 CHECK(obj->IsInt32());
4779 CHECK(obj->IsUint32()); 5388 CHECK(obj->IsUint32());
4780 // Positive zero 5389 // Positive zero
4781 CompileRun("var obj = -0.0;"); 5390 CompileRun("var obj = -0.0;");
4782 obj = env->Global()->Get(v8_str("obj")); 5391 obj = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4783 CHECK(!obj->IsInt32()); 5392 CHECK(!obj->IsInt32());
4784 CHECK(!obj->IsUint32()); 5393 CHECK(!obj->IsUint32());
4785 } 5394 }
4786 5395
4787 5396
5397 static void CheckUncle(v8::TryCatch* try_catch) {
5398 CHECK(try_catch->HasCaught());
5399 String::Utf8Value str_value(try_catch->Exception());
5400 CHECK_EQ(0, strcmp(*str_value, "uncle?"));
5401 try_catch->Reset();
5402 }
5403
5404
4788 THREADED_TEST(ConversionException) { 5405 THREADED_TEST(ConversionException) {
4789 LocalContext env; 5406 LocalContext env;
4790 v8::Isolate* isolate = env->GetIsolate(); 5407 v8::Isolate* isolate = env->GetIsolate();
4791 v8::HandleScope scope(isolate); 5408 v8::HandleScope scope(isolate);
4792 CompileRun( 5409 CompileRun(
4793 "function TestClass() { };" 5410 "function TestClass() { };"
4794 "TestClass.prototype.toString = function () { throw 'uncle?'; };" 5411 "TestClass.prototype.toString = function () { throw 'uncle?'; };"
4795 "var obj = new TestClass();"); 5412 "var obj = new TestClass();");
4796 Local<Value> obj = env->Global()->Get(v8_str("obj")); 5413 Local<Value> obj =
5414 env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
4797 5415
4798 v8::TryCatch try_catch(isolate); 5416 v8::TryCatch try_catch(isolate);
4799 5417
4800 Local<Value> to_string_result = obj->ToString(isolate); 5418 CHECK(obj->ToString(env.local()).IsEmpty());
4801 CHECK(to_string_result.IsEmpty());
4802 CheckUncle(&try_catch); 5419 CheckUncle(&try_catch);
4803 5420
4804 Local<Value> to_number_result = obj->ToNumber(isolate); 5421 CHECK(obj->ToNumber(env.local()).IsEmpty());
4805 CHECK(to_number_result.IsEmpty());
4806 CheckUncle(&try_catch); 5422 CheckUncle(&try_catch);
4807 5423
4808 Local<Value> to_integer_result = obj->ToInteger(isolate); 5424 CHECK(obj->ToInteger(env.local()).IsEmpty());
4809 CHECK(to_integer_result.IsEmpty());
4810 CheckUncle(&try_catch); 5425 CheckUncle(&try_catch);
4811 5426
4812 Local<Value> to_uint32_result = obj->ToUint32(isolate); 5427 CHECK(obj->ToUint32(env.local()).IsEmpty());
4813 CHECK(to_uint32_result.IsEmpty());
4814 CheckUncle(&try_catch); 5428 CheckUncle(&try_catch);
4815 5429
4816 Local<Value> to_int32_result = obj->ToInt32(isolate); 5430 CHECK(obj->ToInt32(env.local()).IsEmpty());
4817 CHECK(to_int32_result.IsEmpty());
4818 CheckUncle(&try_catch); 5431 CheckUncle(&try_catch);
4819 5432
4820 Local<Value> to_object_result = v8::Undefined(isolate)->ToObject(isolate); 5433 CHECK(v8::Undefined(isolate)->ToObject(env.local()).IsEmpty());
4821 CHECK(to_object_result.IsEmpty());
4822 CHECK(try_catch.HasCaught()); 5434 CHECK(try_catch.HasCaught());
4823 try_catch.Reset(); 5435 try_catch.Reset();
4824 5436
4825 int32_t int32_value = obj->Int32Value(); 5437 CHECK(obj->Int32Value(env.local()).IsNothing());
4826 CHECK_EQ(0, int32_value);
4827 CheckUncle(&try_catch); 5438 CheckUncle(&try_catch);
4828 5439
4829 uint32_t uint32_value = obj->Uint32Value(); 5440 CHECK(obj->Uint32Value(env.local()).IsNothing());
4830 CHECK_EQ(0u, uint32_value);
4831 CheckUncle(&try_catch); 5441 CheckUncle(&try_catch);
4832 5442
4833 double number_value = obj->NumberValue(); 5443 CHECK(obj->NumberValue(env.local()).IsNothing());
4834 CHECK(std::isnan(number_value));
4835 CheckUncle(&try_catch); 5444 CheckUncle(&try_catch);
4836 5445
4837 int64_t integer_value = obj->IntegerValue(); 5446 CHECK(obj->IntegerValue(env.local()).IsNothing());
4838 CHECK_EQ(0, integer_value);
4839 CheckUncle(&try_catch); 5447 CheckUncle(&try_catch);
4840 } 5448 }
4841 5449
4842 5450
4843 void ThrowFromC(const v8::FunctionCallbackInfo<v8::Value>& args) { 5451 void ThrowFromC(const v8::FunctionCallbackInfo<v8::Value>& args) {
4844 ApiTestFuzzer::Fuzz(); 5452 ApiTestFuzzer::Fuzz();
4845 args.GetIsolate()->ThrowException(v8_str("konto")); 5453 args.GetIsolate()->ThrowException(v8_str("konto"));
4846 } 5454 }
4847 5455
4848 5456
4849 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) { 5457 void CCatcher(const v8::FunctionCallbackInfo<v8::Value>& args) {
4850 if (args.Length() < 1) { 5458 if (args.Length() < 1) {
4851 args.GetReturnValue().Set(false); 5459 args.GetReturnValue().Set(false);
4852 return; 5460 return;
4853 } 5461 }
4854 v8::HandleScope scope(args.GetIsolate()); 5462 v8::HandleScope scope(args.GetIsolate());
4855 v8::TryCatch try_catch(args.GetIsolate()); 5463 v8::TryCatch try_catch(args.GetIsolate());
4856 Local<Value> result = CompileRun(args[0]->ToString(args.GetIsolate())); 5464 Local<Value> result =
5465 CompileRun(args[0]
5466 ->ToString(args.GetIsolate()->GetCurrentContext())
5467 .ToLocalChecked());
4857 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 5468 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4858 args.GetReturnValue().Set(try_catch.HasCaught()); 5469 args.GetReturnValue().Set(try_catch.HasCaught());
4859 } 5470 }
4860 5471
4861 5472
4862 THREADED_TEST(APICatch) { 5473 THREADED_TEST(APICatch) {
4863 v8::Isolate* isolate = CcTest::isolate(); 5474 v8::Isolate* isolate = CcTest::isolate();
4864 v8::HandleScope scope(isolate); 5475 v8::HandleScope scope(isolate);
4865 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5476 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4866 templ->Set(v8_str("ThrowFromC"), 5477 templ->Set(v8_str("ThrowFromC"),
4867 v8::FunctionTemplate::New(isolate, ThrowFromC)); 5478 v8::FunctionTemplate::New(isolate, ThrowFromC));
4868 LocalContext context(0, templ); 5479 LocalContext context(0, templ);
4869 CompileRun( 5480 CompileRun(
4870 "var thrown = false;" 5481 "var thrown = false;"
4871 "try {" 5482 "try {"
4872 " ThrowFromC();" 5483 " ThrowFromC();"
4873 "} catch (e) {" 5484 "} catch (e) {"
4874 " thrown = true;" 5485 " thrown = true;"
4875 "}"); 5486 "}");
4876 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); 5487 Local<Value> thrown = context->Global()
4877 CHECK(thrown->BooleanValue()); 5488 ->Get(context.local(), v8_str("thrown"))
5489 .ToLocalChecked();
5490 CHECK(thrown->BooleanValue(context.local()).FromJust());
4878 } 5491 }
4879 5492
4880 5493
4881 THREADED_TEST(APIThrowTryCatch) { 5494 THREADED_TEST(APIThrowTryCatch) {
4882 v8::Isolate* isolate = CcTest::isolate(); 5495 v8::Isolate* isolate = CcTest::isolate();
4883 v8::HandleScope scope(isolate); 5496 v8::HandleScope scope(isolate);
4884 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5497 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4885 templ->Set(v8_str("ThrowFromC"), 5498 templ->Set(v8_str("ThrowFromC"),
4886 v8::FunctionTemplate::New(isolate, ThrowFromC)); 5499 v8::FunctionTemplate::New(isolate, ThrowFromC));
4887 LocalContext context(0, templ); 5500 LocalContext context(0, templ);
(...skipping 21 matching lines...) Expand all
4909 " try {" 5522 " try {"
4910 " CCatcher('throw 7;');" 5523 " CCatcher('throw 7;');"
4911 " } finally {" 5524 " } finally {"
4912 " }" 5525 " }"
4913 "} catch (e) {" 5526 "} catch (e) {"
4914 "}"); 5527 "}");
4915 CHECK(result->IsTrue()); 5528 CHECK(result->IsTrue());
4916 } 5529 }
4917 5530
4918 5531
4919 static void check_reference_error_message(v8::Handle<v8::Message> message, 5532 static void check_reference_error_message(v8::Local<v8::Message> message,
4920 v8::Handle<v8::Value> data) { 5533 v8::Local<v8::Value> data) {
4921 const char* reference_error = "Uncaught ReferenceError: asdf is not defined"; 5534 const char* reference_error = "Uncaught ReferenceError: asdf is not defined";
4922 CHECK(message->Get()->Equals(v8_str(reference_error))); 5535 CHECK(message->Get()
5536 ->Equals(CcTest::isolate()->GetCurrentContext(),
5537 v8_str(reference_error))
5538 .FromJust());
4923 } 5539 }
4924 5540
4925 5541
4926 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { 5542 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
4927 ApiTestFuzzer::Fuzz(); 5543 ApiTestFuzzer::Fuzz();
4928 CHECK(false); 5544 CHECK(false);
4929 } 5545 }
4930 5546
4931 5547
4932 // Test that overwritten methods are not invoked on uncaught exception 5548 // Test that overwritten methods are not invoked on uncaught exception
4933 // formatting. However, they are invoked when performing normal error 5549 // formatting. However, they are invoked when performing normal error
4934 // string conversions. 5550 // string conversions.
4935 TEST(APIThrowMessageOverwrittenToString) { 5551 TEST(APIThrowMessageOverwrittenToString) {
4936 v8::Isolate* isolate = CcTest::isolate(); 5552 v8::Isolate* isolate = CcTest::isolate();
4937 v8::HandleScope scope(isolate); 5553 v8::HandleScope scope(isolate);
4938 v8::V8::AddMessageListener(check_reference_error_message); 5554 isolate->AddMessageListener(check_reference_error_message);
4939 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5555 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
4940 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); 5556 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail));
4941 LocalContext context(NULL, templ); 5557 LocalContext context(NULL, templ);
4942 CompileRun("asdf;"); 5558 CompileRun("asdf;");
4943 CompileRun( 5559 CompileRun(
4944 "var limit = {};" 5560 "var limit = {};"
4945 "limit.valueOf = fail;" 5561 "limit.valueOf = fail;"
4946 "Error.stackTraceLimit = limit;"); 5562 "Error.stackTraceLimit = limit;");
4947 CompileRun("asdf"); 5563 CompileRun("asdf");
4948 CompileRun("Array.prototype.pop = fail;"); 5564 CompileRun("Array.prototype.pop = fail;");
4949 CompileRun("Object.prototype.hasOwnProperty = fail;"); 5565 CompileRun("Object.prototype.hasOwnProperty = fail;");
4950 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); 5566 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
4951 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); 5567 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
4952 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }"); 5568 CompileRun("String.prototype.toString = function f() { return 'Yikes'; }");
4953 CompileRun( 5569 CompileRun(
4954 "ReferenceError.prototype.toString =" 5570 "ReferenceError.prototype.toString ="
4955 " function() { return 'Whoops' }"); 5571 " function() { return 'Whoops' }");
4956 CompileRun("asdf;"); 5572 CompileRun("asdf;");
4957 CompileRun("ReferenceError.prototype.constructor.name = void 0;"); 5573 CompileRun("ReferenceError.prototype.constructor.name = void 0;");
4958 CompileRun("asdf;"); 5574 CompileRun("asdf;");
4959 CompileRun("ReferenceError.prototype.constructor = void 0;"); 5575 CompileRun("ReferenceError.prototype.constructor = void 0;");
4960 CompileRun("asdf;"); 5576 CompileRun("asdf;");
4961 CompileRun("ReferenceError.prototype.__proto__ = new Object();"); 5577 CompileRun("ReferenceError.prototype.__proto__ = new Object();");
4962 CompileRun("asdf;"); 5578 CompileRun("asdf;");
4963 CompileRun("ReferenceError.prototype = new Object();"); 5579 CompileRun("ReferenceError.prototype = new Object();");
4964 CompileRun("asdf;"); 5580 CompileRun("asdf;");
4965 v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }"); 5581 v8::Local<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }");
4966 CHECK(string->Equals(v8_str("Whoops"))); 5582 CHECK(string->Equals(context.local(), v8_str("Whoops")).FromJust());
4967 CompileRun( 5583 CompileRun(
4968 "ReferenceError.prototype.constructor = new Object();" 5584 "ReferenceError.prototype.constructor = new Object();"
4969 "ReferenceError.prototype.constructor.name = 1;" 5585 "ReferenceError.prototype.constructor.name = 1;"
4970 "Number.prototype.toString = function() { return 'Whoops'; };" 5586 "Number.prototype.toString = function() { return 'Whoops'; };"
4971 "ReferenceError.prototype.toString = Object.prototype.toString;"); 5587 "ReferenceError.prototype.toString = Object.prototype.toString;");
4972 CompileRun("asdf;"); 5588 CompileRun("asdf;");
4973 v8::V8::RemoveMessageListeners(check_reference_error_message); 5589 isolate->RemoveMessageListeners(check_reference_error_message);
4974 } 5590 }
4975 5591
4976 5592
4977 static void check_custom_error_tostring(v8::Handle<v8::Message> message, 5593 static void check_custom_error_tostring(v8::Local<v8::Message> message,
4978 v8::Handle<v8::Value> data) { 5594 v8::Local<v8::Value> data) {
4979 const char* uncaught_error = "Uncaught MyError toString"; 5595 const char* uncaught_error = "Uncaught MyError toString";
4980 CHECK(message->Get()->Equals(v8_str(uncaught_error))); 5596 CHECK(message->Get()
5597 ->Equals(CcTest::isolate()->GetCurrentContext(),
5598 v8_str(uncaught_error))
5599 .FromJust());
4981 } 5600 }
4982 5601
4983 5602
4984 TEST(CustomErrorToString) { 5603 TEST(CustomErrorToString) {
4985 LocalContext context; 5604 LocalContext context;
4986 v8::HandleScope scope(context->GetIsolate()); 5605 v8::HandleScope scope(context->GetIsolate());
4987 v8::V8::AddMessageListener(check_custom_error_tostring); 5606 context->GetIsolate()->AddMessageListener(check_custom_error_tostring);
4988 CompileRun( 5607 CompileRun(
4989 "function MyError(name, message) { " 5608 "function MyError(name, message) { "
4990 " this.name = name; " 5609 " this.name = name; "
4991 " this.message = message; " 5610 " this.message = message; "
4992 "} " 5611 "} "
4993 "MyError.prototype = Object.create(Error.prototype); " 5612 "MyError.prototype = Object.create(Error.prototype); "
4994 "MyError.prototype.toString = function() { " 5613 "MyError.prototype.toString = function() { "
4995 " return 'MyError toString'; " 5614 " return 'MyError toString'; "
4996 "}; " 5615 "}; "
4997 "throw new MyError('my name', 'my message'); "); 5616 "throw new MyError('my name', 'my message'); ");
4998 v8::V8::RemoveMessageListeners(check_custom_error_tostring); 5617 context->GetIsolate()->RemoveMessageListeners(check_custom_error_tostring);
4999 } 5618 }
5000 5619
5001 5620
5002 static void check_custom_error_message(v8::Handle<v8::Message> message, 5621 static void check_custom_error_message(v8::Local<v8::Message> message,
5003 v8::Handle<v8::Value> data) { 5622 v8::Local<v8::Value> data) {
5004 const char* uncaught_error = "Uncaught MyError: my message"; 5623 const char* uncaught_error = "Uncaught MyError: my message";
5005 printf("%s\n", *v8::String::Utf8Value(message->Get())); 5624 printf("%s\n", *v8::String::Utf8Value(message->Get()));
5006 CHECK(message->Get()->Equals(v8_str(uncaught_error))); 5625 CHECK(message->Get()
5626 ->Equals(CcTest::isolate()->GetCurrentContext(),
5627 v8_str(uncaught_error))
5628 .FromJust());
5007 } 5629 }
5008 5630
5009 5631
5010 TEST(CustomErrorMessage) { 5632 TEST(CustomErrorMessage) {
5011 LocalContext context; 5633 LocalContext context;
5012 v8::HandleScope scope(context->GetIsolate()); 5634 v8::HandleScope scope(context->GetIsolate());
5013 v8::V8::AddMessageListener(check_custom_error_message); 5635 context->GetIsolate()->AddMessageListener(check_custom_error_message);
5014 5636
5015 // Handlebars. 5637 // Handlebars.
5016 CompileRun( 5638 CompileRun(
5017 "function MyError(msg) { " 5639 "function MyError(msg) { "
5018 " this.name = 'MyError'; " 5640 " this.name = 'MyError'; "
5019 " this.message = msg; " 5641 " this.message = msg; "
5020 "} " 5642 "} "
5021 "MyError.prototype = new Error(); " 5643 "MyError.prototype = new Error(); "
5022 "throw new MyError('my message'); "); 5644 "throw new MyError('my message'); ");
5023 5645
(...skipping 15 matching lines...) Expand all
5039 5661
5040 // Object.create. 5662 // Object.create.
5041 CompileRun( 5663 CompileRun(
5042 "function MyError(msg) { " 5664 "function MyError(msg) { "
5043 " this.name = 'MyError'; " 5665 " this.name = 'MyError'; "
5044 " this.message = msg; " 5666 " this.message = msg; "
5045 "} " 5667 "} "
5046 "MyError.prototype = Object.create(Error.prototype); " 5668 "MyError.prototype = Object.create(Error.prototype); "
5047 "throw new MyError('my message'); "); 5669 "throw new MyError('my message'); ");
5048 5670
5049 v8::V8::RemoveMessageListeners(check_custom_error_message); 5671 context->GetIsolate()->RemoveMessageListeners(check_custom_error_message);
5050 } 5672 }
5051 5673
5052 5674
5053 static void check_custom_rethrowing_message(v8::Handle<v8::Message> message, 5675 static void check_custom_rethrowing_message(v8::Local<v8::Message> message,
5054 v8::Handle<v8::Value> data) { 5676 v8::Local<v8::Value> data) {
5055 const char* uncaught_error = "Uncaught exception"; 5677 const char* uncaught_error = "Uncaught exception";
5056 CHECK(message->Get()->Equals(v8_str(uncaught_error))); 5678 CHECK(message->Get()
5679 ->Equals(CcTest::isolate()->GetCurrentContext(),
5680 v8_str(uncaught_error))
5681 .FromJust());
5057 } 5682 }
5058 5683
5059 5684
5060 TEST(CustomErrorRethrowsOnToString) { 5685 TEST(CustomErrorRethrowsOnToString) {
5061 LocalContext context; 5686 LocalContext context;
5062 v8::HandleScope scope(context->GetIsolate()); 5687 v8::HandleScope scope(context->GetIsolate());
5063 v8::V8::AddMessageListener(check_custom_rethrowing_message); 5688 context->GetIsolate()->AddMessageListener(check_custom_rethrowing_message);
5064 5689
5065 CompileRun( 5690 CompileRun(
5066 "var e = { toString: function() { throw e; } };" 5691 "var e = { toString: function() { throw e; } };"
5067 "try { throw e; } finally {}"); 5692 "try { throw e; } finally {}");
5068 5693
5069 v8::V8::RemoveMessageListeners(check_custom_rethrowing_message); 5694 context->GetIsolate()->RemoveMessageListeners(
5695 check_custom_rethrowing_message);
5070 } 5696 }
5071 5697
5072 5698
5073 static void receive_message(v8::Handle<v8::Message> message, 5699 static void receive_message(v8::Local<v8::Message> message,
5074 v8::Handle<v8::Value> data) { 5700 v8::Local<v8::Value> data) {
5075 message->Get(); 5701 message->Get();
5076 message_received = true; 5702 message_received = true;
5077 } 5703 }
5078 5704
5079 5705
5080 TEST(APIThrowMessage) { 5706 TEST(APIThrowMessage) {
5081 message_received = false; 5707 message_received = false;
5082 v8::Isolate* isolate = CcTest::isolate(); 5708 v8::Isolate* isolate = CcTest::isolate();
5083 v8::HandleScope scope(isolate); 5709 v8::HandleScope scope(isolate);
5084 v8::V8::AddMessageListener(receive_message); 5710 isolate->AddMessageListener(receive_message);
5085 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5711 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5086 templ->Set(v8_str("ThrowFromC"), 5712 templ->Set(v8_str("ThrowFromC"),
5087 v8::FunctionTemplate::New(isolate, ThrowFromC)); 5713 v8::FunctionTemplate::New(isolate, ThrowFromC));
5088 LocalContext context(0, templ); 5714 LocalContext context(0, templ);
5089 CompileRun("ThrowFromC();"); 5715 CompileRun("ThrowFromC();");
5090 CHECK(message_received); 5716 CHECK(message_received);
5091 v8::V8::RemoveMessageListeners(receive_message); 5717 isolate->RemoveMessageListeners(receive_message);
5092 } 5718 }
5093 5719
5094 5720
5095 TEST(APIThrowMessageAndVerboseTryCatch) { 5721 TEST(APIThrowMessageAndVerboseTryCatch) {
5096 message_received = false; 5722 message_received = false;
5097 v8::Isolate* isolate = CcTest::isolate(); 5723 v8::Isolate* isolate = CcTest::isolate();
5098 v8::HandleScope scope(isolate); 5724 v8::HandleScope scope(isolate);
5099 v8::V8::AddMessageListener(receive_message); 5725 isolate->AddMessageListener(receive_message);
5100 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5726 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5101 templ->Set(v8_str("ThrowFromC"), 5727 templ->Set(v8_str("ThrowFromC"),
5102 v8::FunctionTemplate::New(isolate, ThrowFromC)); 5728 v8::FunctionTemplate::New(isolate, ThrowFromC));
5103 LocalContext context(0, templ); 5729 LocalContext context(0, templ);
5104 v8::TryCatch try_catch(isolate); 5730 v8::TryCatch try_catch(isolate);
5105 try_catch.SetVerbose(true); 5731 try_catch.SetVerbose(true);
5106 Local<Value> result = CompileRun("ThrowFromC();"); 5732 Local<Value> result = CompileRun("ThrowFromC();");
5107 CHECK(try_catch.HasCaught()); 5733 CHECK(try_catch.HasCaught());
5108 CHECK(result.IsEmpty()); 5734 CHECK(result.IsEmpty());
5109 CHECK(message_received); 5735 CHECK(message_received);
5110 v8::V8::RemoveMessageListeners(receive_message); 5736 isolate->RemoveMessageListeners(receive_message);
5111 } 5737 }
5112 5738
5113 5739
5114 TEST(APIStackOverflowAndVerboseTryCatch) { 5740 TEST(APIStackOverflowAndVerboseTryCatch) {
5115 message_received = false; 5741 message_received = false;
5116 LocalContext context; 5742 LocalContext context;
5117 v8::HandleScope scope(context->GetIsolate()); 5743 v8::HandleScope scope(context->GetIsolate());
5118 v8::V8::AddMessageListener(receive_message); 5744 context->GetIsolate()->AddMessageListener(receive_message);
5119 v8::TryCatch try_catch(context->GetIsolate()); 5745 v8::TryCatch try_catch(context->GetIsolate());
5120 try_catch.SetVerbose(true); 5746 try_catch.SetVerbose(true);
5121 Local<Value> result = CompileRun("function foo() { foo(); } foo();"); 5747 Local<Value> result = CompileRun("function foo() { foo(); } foo();");
5122 CHECK(try_catch.HasCaught()); 5748 CHECK(try_catch.HasCaught());
5123 CHECK(result.IsEmpty()); 5749 CHECK(result.IsEmpty());
5124 CHECK(message_received); 5750 CHECK(message_received);
5125 v8::V8::RemoveMessageListeners(receive_message); 5751 context->GetIsolate()->RemoveMessageListeners(receive_message);
5126 } 5752 }
5127 5753
5128 5754
5129 THREADED_TEST(ExternalScriptException) { 5755 THREADED_TEST(ExternalScriptException) {
5130 v8::Isolate* isolate = CcTest::isolate(); 5756 v8::Isolate* isolate = CcTest::isolate();
5131 v8::HandleScope scope(isolate); 5757 v8::HandleScope scope(isolate);
5132 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5758 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5133 templ->Set(v8_str("ThrowFromC"), 5759 templ->Set(v8_str("ThrowFromC"),
5134 v8::FunctionTemplate::New(isolate, ThrowFromC)); 5760 v8::FunctionTemplate::New(isolate, ThrowFromC));
5135 LocalContext context(0, templ); 5761 LocalContext context(0, templ);
5136 5762
5137 v8::TryCatch try_catch(isolate); 5763 v8::TryCatch try_catch(isolate);
5138 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';"); 5764 Local<Value> result = CompileRun("ThrowFromC(); throw 'panama';");
5139 CHECK(result.IsEmpty()); 5765 CHECK(result.IsEmpty());
5140 CHECK(try_catch.HasCaught()); 5766 CHECK(try_catch.HasCaught());
5141 String::Utf8Value exception_value(try_catch.Exception()); 5767 String::Utf8Value exception_value(try_catch.Exception());
5142 CHECK_EQ(0, strcmp("konto", *exception_value)); 5768 CHECK_EQ(0, strcmp("konto", *exception_value));
5143 } 5769 }
5144 5770
5145 5771
5146 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) { 5772 void CThrowCountDown(const v8::FunctionCallbackInfo<v8::Value>& args) {
5147 ApiTestFuzzer::Fuzz(); 5773 ApiTestFuzzer::Fuzz();
5148 CHECK_EQ(4, args.Length()); 5774 CHECK_EQ(4, args.Length());
5149 int count = args[0]->Int32Value(); 5775 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
5150 int cInterval = args[2]->Int32Value(); 5776 int count = args[0]->Int32Value(context).FromJust();
5777 int cInterval = args[2]->Int32Value(context).FromJust();
5151 if (count == 0) { 5778 if (count == 0) {
5152 args.GetIsolate()->ThrowException(v8_str("FromC")); 5779 args.GetIsolate()->ThrowException(v8_str("FromC"));
5153 return; 5780 return;
5154 } else { 5781 } else {
5155 Local<v8::Object> global = args.GetIsolate()->GetCurrentContext()->Global(); 5782 Local<v8::Object> global = context->Global();
5156 Local<Value> fun = global->Get(v8_str("JSThrowCountDown")); 5783 Local<Value> fun =
5157 v8::Handle<Value> argv[] = {v8_num(count - 1), args[1], args[2], args[3]}; 5784 global->Get(context, v8_str("JSThrowCountDown")).ToLocalChecked();
5785 v8::Local<Value> argv[] = {v8_num(count - 1), args[1], args[2], args[3]};
5158 if (count % cInterval == 0) { 5786 if (count % cInterval == 0) {
5159 v8::TryCatch try_catch(args.GetIsolate()); 5787 v8::TryCatch try_catch(args.GetIsolate());
5160 Local<Value> result = fun.As<Function>()->Call(global, 4, argv); 5788 Local<Value> result = fun.As<Function>()
5161 int expected = args[3]->Int32Value(); 5789 ->Call(context, global, 4, argv)
5790 .FromMaybe(Local<Value>());
5791 int expected = args[3]->Int32Value(context).FromJust();
5162 if (try_catch.HasCaught()) { 5792 if (try_catch.HasCaught()) {
5163 CHECK_EQ(expected, count); 5793 CHECK_EQ(expected, count);
5164 CHECK(result.IsEmpty()); 5794 CHECK(result.IsEmpty());
5165 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); 5795 CHECK(!CcTest::i_isolate()->has_scheduled_exception());
5166 } else { 5796 } else {
5167 CHECK_NE(expected, count); 5797 CHECK_NE(expected, count);
5168 } 5798 }
5169 args.GetReturnValue().Set(result); 5799 args.GetReturnValue().Set(result);
5170 return; 5800 return;
5171 } else { 5801 } else {
5172 args.GetReturnValue().Set(fun.As<Function>()->Call(global, 4, argv)); 5802 args.GetReturnValue().Set(fun.As<Function>()
5803 ->Call(context, global, 4, argv)
5804 .FromMaybe(v8::Local<v8::Value>()));
5173 return; 5805 return;
5174 } 5806 }
5175 } 5807 }
5176 } 5808 }
5177 5809
5178 5810
5179 void JSCheck(const v8::FunctionCallbackInfo<v8::Value>& args) { 5811 void JSCheck(const v8::FunctionCallbackInfo<v8::Value>& args) {
5180 ApiTestFuzzer::Fuzz(); 5812 ApiTestFuzzer::Fuzz();
5181 CHECK_EQ(3, args.Length()); 5813 CHECK_EQ(3, args.Length());
5182 bool equality = args[0]->BooleanValue(); 5814 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
5183 int count = args[1]->Int32Value(); 5815 bool equality = args[0]->BooleanValue(context).FromJust();
5184 int expected = args[2]->Int32Value(); 5816 int count = args[1]->Int32Value(context).FromJust();
5817 int expected = args[2]->Int32Value(context).FromJust();
5185 if (equality) { 5818 if (equality) {
5186 CHECK_EQ(count, expected); 5819 CHECK_EQ(count, expected);
5187 } else { 5820 } else {
5188 CHECK_NE(count, expected); 5821 CHECK_NE(count, expected);
5189 } 5822 }
5190 } 5823 }
5191 5824
5192 5825
5193 THREADED_TEST(EvalInTryFinally) { 5826 THREADED_TEST(EvalInTryFinally) {
5194 LocalContext context; 5827 LocalContext context;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
5245 " expected);" 5878 " expected);"
5246 " check(false, count, expected);" 5879 " check(false, count, expected);"
5247 " return value;" 5880 " return value;"
5248 " } catch (e) {" 5881 " } catch (e) {"
5249 " check(true, count, expected);" 5882 " check(true, count, expected);"
5250 " }" 5883 " }"
5251 " } else {" 5884 " } else {"
5252 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);" 5885 " return CThrowCountDown(count - 1, jsInterval, cInterval, expected);"
5253 " }" 5886 " }"
5254 "}"); 5887 "}");
5255 Local<Function> fun = 5888 Local<Function> fun = Local<Function>::Cast(
5256 Local<Function>::Cast(context->Global()->Get(v8_str("JSThrowCountDown"))); 5889 context->Global()
5890 ->Get(context.local(), v8_str("JSThrowCountDown"))
5891 .ToLocalChecked());
5257 5892
5258 const int argc = 4; 5893 const int argc = 4;
5259 // count jsInterval cInterval expected 5894 // count jsInterval cInterval expected
5260 5895
5261 // *JS[4] *C[3] @JS[2] C[1] JS[0] 5896 // *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)}; 5897 v8::Local<Value> a0[argc] = {v8_num(4), v8_num(2), v8_num(3), v8_num(2)};
5263 fun->Call(fun, argc, a0); 5898 fun->Call(context.local(), fun, argc, a0).ToLocalChecked();
5264 5899
5265 // JS[5] *C[4] JS[3] @C[2] JS[1] C[0] 5900 // 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)}; 5901 v8::Local<Value> a1[argc] = {v8_num(5), v8_num(6), v8_num(1), v8_num(2)};
5267 fun->Call(fun, argc, a1); 5902 fun->Call(context.local(), fun, argc, a1).ToLocalChecked();
5268 5903
5269 // 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]
5270 v8::Handle<Value> a2[argc] = {v8_num(6), v8_num(7), v8_num(5), v8_num(5)}; 5905 v8::Local<Value> a2[argc] = {v8_num(6), v8_num(7), v8_num(5), v8_num(5)};
5271 fun->Call(fun, argc, a2); 5906 fun->Call(context.local(), fun, argc, a2).ToLocalChecked();
5272 5907
5273 // @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]
5274 v8::Handle<Value> a3[argc] = {v8_num(6), v8_num(6), v8_num(7), v8_num(6)}; 5909 v8::Local<Value> a3[argc] = {v8_num(6), v8_num(6), v8_num(7), v8_num(6)};
5275 fun->Call(fun, argc, a3); 5910 fun->Call(context.local(), fun, argc, a3).ToLocalChecked();
5276 5911
5277 // JS[6] *C[5] @JS[4] C[3] JS[2] C[1] JS[0] 5912 // 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)}; 5913 v8::Local<Value> a4[argc] = {v8_num(6), v8_num(4), v8_num(5), v8_num(4)};
5279 fun->Call(fun, argc, a4); 5914 fun->Call(context.local(), fun, argc, a4).ToLocalChecked();
5280 5915
5281 // JS[6] C[5] *JS[4] @C[3] JS[2] C[1] JS[0] 5916 // 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)}; 5917 v8::Local<Value> a5[argc] = {v8_num(6), v8_num(4), v8_num(3), v8_num(3)};
5283 fun->Call(fun, argc, a5); 5918 fun->Call(context.local(), fun, argc, a5).ToLocalChecked();
5284 } 5919 }
5285 5920
5286 5921
5287 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { 5922 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
5288 ApiTestFuzzer::Fuzz(); 5923 ApiTestFuzzer::Fuzz();
5289 CHECK_EQ(1, args.Length()); 5924 CHECK_EQ(1, args.Length());
5290 args.GetIsolate()->ThrowException(args[0]); 5925 args.GetIsolate()->ThrowException(args[0]);
5291 } 5926 }
5292 5927
5293 5928
5294 THREADED_TEST(ThrowValues) { 5929 THREADED_TEST(ThrowValues) {
5295 v8::Isolate* isolate = CcTest::isolate(); 5930 v8::Isolate* isolate = CcTest::isolate();
5296 v8::HandleScope scope(isolate); 5931 v8::HandleScope scope(isolate);
5297 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5932 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5298 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue)); 5933 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue));
5299 LocalContext context(0, templ); 5934 LocalContext context(0, templ);
5300 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 5935 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast(
5301 "function Run(obj) {" 5936 CompileRun("function Run(obj) {"
5302 " try {" 5937 " try {"
5303 " Throw(obj);" 5938 " Throw(obj);"
5304 " } catch (e) {" 5939 " } catch (e) {"
5305 " return e;" 5940 " return e;"
5306 " }" 5941 " }"
5307 " return 'no exception';" 5942 " return 'no exception';"
5308 "}" 5943 "}"
5309 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];")); 5944 "[Run('str'), Run(1), Run(0), Run(null), Run(void 0)];"));
5310 CHECK_EQ(5u, result->Length()); 5945 CHECK_EQ(5u, result->Length());
5311 CHECK(result->Get(v8::Integer::New(isolate, 0))->IsString()); 5946 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 0))
5312 CHECK(result->Get(v8::Integer::New(isolate, 1))->IsNumber()); 5947 .ToLocalChecked()
5313 CHECK_EQ(1, result->Get(v8::Integer::New(isolate, 1))->Int32Value()); 5948 ->IsString());
5314 CHECK(result->Get(v8::Integer::New(isolate, 2))->IsNumber()); 5949 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 1))
5315 CHECK_EQ(0, result->Get(v8::Integer::New(isolate, 2))->Int32Value()); 5950 .ToLocalChecked()
5316 CHECK(result->Get(v8::Integer::New(isolate, 3))->IsNull()); 5951 ->IsNumber());
5317 CHECK(result->Get(v8::Integer::New(isolate, 4))->IsUndefined()); 5952 CHECK_EQ(1, result->Get(context.local(), v8::Integer::New(isolate, 1))
5953 .ToLocalChecked()
5954 ->Int32Value(context.local())
5955 .FromJust());
5956 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 2))
5957 .ToLocalChecked()
5958 ->IsNumber());
5959 CHECK_EQ(0, result->Get(context.local(), v8::Integer::New(isolate, 2))
5960 .ToLocalChecked()
5961 ->Int32Value(context.local())
5962 .FromJust());
5963 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 3))
5964 .ToLocalChecked()
5965 ->IsNull());
5966 CHECK(result->Get(context.local(), v8::Integer::New(isolate, 4))
5967 .ToLocalChecked()
5968 ->IsUndefined());
5318 } 5969 }
5319 5970
5320 5971
5321 THREADED_TEST(CatchZero) { 5972 THREADED_TEST(CatchZero) {
5322 LocalContext context; 5973 LocalContext context;
5323 v8::HandleScope scope(context->GetIsolate()); 5974 v8::HandleScope scope(context->GetIsolate());
5324 v8::TryCatch try_catch(context->GetIsolate()); 5975 v8::TryCatch try_catch(context->GetIsolate());
5325 CHECK(!try_catch.HasCaught()); 5976 CHECK(!try_catch.HasCaught());
5326 CompileRun("throw 10"); 5977 CompileRun("throw 10");
5327 CHECK(try_catch.HasCaught()); 5978 CHECK(try_catch.HasCaught());
5328 CHECK_EQ(10, try_catch.Exception()->Int32Value()); 5979 CHECK_EQ(10, try_catch.Exception()->Int32Value(context.local()).FromJust());
5329 try_catch.Reset(); 5980 try_catch.Reset();
5330 CHECK(!try_catch.HasCaught()); 5981 CHECK(!try_catch.HasCaught());
5331 CompileRun("throw 0"); 5982 CompileRun("throw 0");
5332 CHECK(try_catch.HasCaught()); 5983 CHECK(try_catch.HasCaught());
5333 CHECK_EQ(0, try_catch.Exception()->Int32Value()); 5984 CHECK_EQ(0, try_catch.Exception()->Int32Value(context.local()).FromJust());
5334 } 5985 }
5335 5986
5336 5987
5337 THREADED_TEST(CatchExceptionFromWith) { 5988 THREADED_TEST(CatchExceptionFromWith) {
5338 LocalContext context; 5989 LocalContext context;
5339 v8::HandleScope scope(context->GetIsolate()); 5990 v8::HandleScope scope(context->GetIsolate());
5340 v8::TryCatch try_catch(context->GetIsolate()); 5991 v8::TryCatch try_catch(context->GetIsolate());
5341 CHECK(!try_catch.HasCaught()); 5992 CHECK(!try_catch.HasCaught());
5342 CompileRun("var o = {}; with (o) { throw 42; }"); 5993 CompileRun("var o = {}; with (o) { throw 42; }");
5343 CHECK(try_catch.HasCaught()); 5994 CHECK(try_catch.HasCaught());
(...skipping 13 matching lines...) Expand all
5357 6008
5358 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { 6009 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
5359 v8::TryCatch try_catch(args.GetIsolate()); 6010 v8::TryCatch try_catch(args.GetIsolate());
5360 } 6011 }
5361 6012
5362 6013
5363 THREADED_TEST(TryCatchAndFinally) { 6014 THREADED_TEST(TryCatchAndFinally) {
5364 LocalContext context; 6015 LocalContext context;
5365 v8::Isolate* isolate = context->GetIsolate(); 6016 v8::Isolate* isolate = context->GetIsolate();
5366 v8::HandleScope scope(isolate); 6017 v8::HandleScope scope(isolate);
5367 context->Global()->Set( 6018 CHECK(context->Global()
5368 v8_str("native_with_try_catch"), 6019 ->Set(context.local(), v8_str("native_with_try_catch"),
5369 v8::FunctionTemplate::New(isolate, WithTryCatch)->GetFunction()); 6020 v8::FunctionTemplate::New(isolate, WithTryCatch)
6021 ->GetFunction(context.local())
6022 .ToLocalChecked())
6023 .FromJust());
5370 v8::TryCatch try_catch(isolate); 6024 v8::TryCatch try_catch(isolate);
5371 CHECK(!try_catch.HasCaught()); 6025 CHECK(!try_catch.HasCaught());
5372 CompileRun( 6026 CompileRun(
5373 "try {\n" 6027 "try {\n"
5374 " throw new Error('a');\n" 6028 " throw new Error('a');\n"
5375 "} finally {\n" 6029 "} finally {\n"
5376 " native_with_try_catch();\n" 6030 " native_with_try_catch();\n"
5377 "}\n"); 6031 "}\n");
5378 CHECK(try_catch.HasCaught()); 6032 CHECK(try_catch.HasCaught());
5379 } 6033 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5423 v8::TryCatch try_catch(context->GetIsolate()); 6077 v8::TryCatch try_catch(context->GetIsolate());
5424 TryCatchNested2Helper(5); 6078 TryCatchNested2Helper(5);
5425 CHECK(try_catch.HasCaught()); 6079 CHECK(try_catch.HasCaught());
5426 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2")); 6080 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2"));
5427 } 6081 }
5428 } 6082 }
5429 6083
5430 6084
5431 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { 6085 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
5432 CHECK(try_catch->HasCaught()); 6086 CHECK(try_catch->HasCaught());
5433 Handle<Message> message = try_catch->Message(); 6087 Local<Message> message = try_catch->Message();
5434 Handle<Value> resource = message->GetScriptOrigin().ResourceName(); 6088 Local<Value> resource = message->GetScriptOrigin().ResourceName();
5435 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); 6089 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner"));
5436 CHECK_EQ(0, 6090 CHECK_EQ(0,
5437 strcmp(*v8::String::Utf8Value(message->Get()), "Uncaught Error: a")); 6091 strcmp(*v8::String::Utf8Value(message->Get()), "Uncaught Error: a"));
5438 CHECK_EQ(1, message->GetLineNumber()); 6092 CHECK_EQ(1, message->GetLineNumber(CcTest::isolate()->GetCurrentContext())
5439 CHECK_EQ(0, message->GetStartColumn()); 6093 .FromJust());
6094 CHECK_EQ(0, message->GetStartColumn(CcTest::isolate()->GetCurrentContext())
6095 .FromJust());
5440 } 6096 }
5441 6097
5442 6098
5443 void TryCatchMixedNestingHelper( 6099 void TryCatchMixedNestingHelper(
5444 const v8::FunctionCallbackInfo<v8::Value>& args) { 6100 const v8::FunctionCallbackInfo<v8::Value>& args) {
5445 ApiTestFuzzer::Fuzz(); 6101 ApiTestFuzzer::Fuzz();
5446 v8::TryCatch try_catch(args.GetIsolate()); 6102 v8::TryCatch try_catch(args.GetIsolate());
5447 CompileRunWithOrigin("throw new Error('a');\n", "inner", 0, 0); 6103 CompileRunWithOrigin("throw new Error('a');\n", "inner", 0, 0);
5448 CHECK(try_catch.HasCaught()); 6104 CHECK(try_catch.HasCaught());
5449 TryCatchMixedNestingCheck(&try_catch); 6105 TryCatchMixedNestingCheck(&try_catch);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
5515 CompileRun("TryCatchNativeResetHelper();"); 6171 CompileRun("TryCatchNativeResetHelper();");
5516 CHECK(!try_catch.HasCaught()); 6172 CHECK(!try_catch.HasCaught());
5517 } 6173 }
5518 6174
5519 6175
5520 THREADED_TEST(Equality) { 6176 THREADED_TEST(Equality) {
5521 LocalContext context; 6177 LocalContext context;
5522 v8::Isolate* isolate = context->GetIsolate(); 6178 v8::Isolate* isolate = context->GetIsolate();
5523 v8::HandleScope scope(context->GetIsolate()); 6179 v8::HandleScope scope(context->GetIsolate());
5524 // Check that equality works at all before relying on CHECK_EQ 6180 // Check that equality works at all before relying on CHECK_EQ
5525 CHECK(v8_str("a")->Equals(v8_str("a"))); 6181 CHECK(v8_str("a")->Equals(context.local(), v8_str("a")).FromJust());
5526 CHECK(!v8_str("a")->Equals(v8_str("b"))); 6182 CHECK(!v8_str("a")->Equals(context.local(), v8_str("b")).FromJust());
5527 6183
5528 CHECK(v8_str("a")->Equals(v8_str("a"))); 6184 CHECK(v8_str("a")->Equals(context.local(), v8_str("a")).FromJust());
5529 CHECK(!v8_str("a")->Equals(v8_str("b"))); 6185 CHECK(!v8_str("a")->Equals(context.local(), v8_str("b")).FromJust());
5530 CHECK(v8_num(1)->Equals(v8_num(1))); 6186 CHECK(v8_num(1)->Equals(context.local(), v8_num(1)).FromJust());
5531 CHECK(v8_num(1.00)->Equals(v8_num(1))); 6187 CHECK(v8_num(1.00)->Equals(context.local(), v8_num(1)).FromJust());
5532 CHECK(!v8_num(1)->Equals(v8_num(2))); 6188 CHECK(!v8_num(1)->Equals(context.local(), v8_num(2)).FromJust());
5533 6189
5534 // Assume String is not internalized. 6190 // Assume String is not internalized.
5535 CHECK(v8_str("a")->StrictEquals(v8_str("a"))); 6191 CHECK(v8_str("a")->StrictEquals(v8_str("a")));
5536 CHECK(!v8_str("a")->StrictEquals(v8_str("b"))); 6192 CHECK(!v8_str("a")->StrictEquals(v8_str("b")));
5537 CHECK(!v8_str("5")->StrictEquals(v8_num(5))); 6193 CHECK(!v8_str("5")->StrictEquals(v8_num(5)));
5538 CHECK(v8_num(1)->StrictEquals(v8_num(1))); 6194 CHECK(v8_num(1)->StrictEquals(v8_num(1)));
5539 CHECK(!v8_num(1)->StrictEquals(v8_num(2))); 6195 CHECK(!v8_num(1)->StrictEquals(v8_num(2)));
5540 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0))); 6196 CHECK(v8_num(0.0)->StrictEquals(v8_num(-0.0)));
5541 Local<Value> not_a_number = v8_num(std::numeric_limits<double>::quiet_NaN()); 6197 Local<Value> not_a_number = v8_num(std::numeric_limits<double>::quiet_NaN());
5542 CHECK(!not_a_number->StrictEquals(not_a_number)); 6198 CHECK(!not_a_number->StrictEquals(not_a_number));
5543 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate))); 6199 CHECK(v8::False(isolate)->StrictEquals(v8::False(isolate)));
5544 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate))); 6200 CHECK(!v8::False(isolate)->StrictEquals(v8::Undefined(isolate)));
5545 6201
5546 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 6202 v8::Local<v8::Object> obj = v8::Object::New(isolate);
5547 v8::Persistent<v8::Object> alias(isolate, obj); 6203 v8::Persistent<v8::Object> alias(isolate, obj);
5548 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj)); 6204 CHECK(v8::Local<v8::Object>::New(isolate, alias)->StrictEquals(obj));
5549 alias.Reset(); 6205 alias.Reset();
5550 6206
5551 CHECK(v8_str("a")->SameValue(v8_str("a"))); 6207 CHECK(v8_str("a")->SameValue(v8_str("a")));
5552 CHECK(!v8_str("a")->SameValue(v8_str("b"))); 6208 CHECK(!v8_str("a")->SameValue(v8_str("b")));
5553 CHECK(!v8_str("5")->SameValue(v8_num(5))); 6209 CHECK(!v8_str("5")->SameValue(v8_num(5)));
5554 CHECK(v8_num(1)->SameValue(v8_num(1))); 6210 CHECK(v8_num(1)->SameValue(v8_num(1)));
5555 CHECK(!v8_num(1)->SameValue(v8_num(2))); 6211 CHECK(!v8_num(1)->SameValue(v8_num(2)));
5556 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0))); 6212 CHECK(!v8_num(0.0)->SameValue(v8_num(-0.0)));
5557 CHECK(not_a_number->SameValue(not_a_number)); 6213 CHECK(not_a_number->SameValue(not_a_number));
5558 CHECK(v8::False(isolate)->SameValue(v8::False(isolate))); 6214 CHECK(v8::False(isolate)->SameValue(v8::False(isolate)));
5559 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate))); 6215 CHECK(!v8::False(isolate)->SameValue(v8::Undefined(isolate)));
5560 } 6216 }
5561 6217
5562 6218
5563 THREADED_TEST(MultiRun) { 6219 THREADED_TEST(MultiRun) {
5564 LocalContext context; 6220 LocalContext context;
5565 v8::HandleScope scope(context->GetIsolate()); 6221 v8::HandleScope scope(context->GetIsolate());
5566 Local<Script> script = v8_compile("x"); 6222 Local<Script> script = v8_compile("x");
5567 for (int i = 0; i < 10; i++) script->Run(); 6223 for (int i = 0; i < 10; i++) {
6224 script->Run(context.local()).IsEmpty();
6225 }
5568 } 6226 }
5569 6227
5570 6228
5571 static void GetXValue(Local<String> name, 6229 static void GetXValue(Local<Name> name,
5572 const v8::PropertyCallbackInfo<v8::Value>& info) { 6230 const v8::PropertyCallbackInfo<v8::Value>& info) {
5573 ApiTestFuzzer::Fuzz(); 6231 ApiTestFuzzer::Fuzz();
5574 CHECK(info.Data()->Equals(v8_str("donut"))); 6232 CHECK(info.Data()
5575 CHECK(name->Equals(v8_str("x"))); 6233 ->Equals(CcTest::isolate()->GetCurrentContext(), v8_str("donut"))
6234 .FromJust());
6235 CHECK(name->Equals(CcTest::isolate()->GetCurrentContext(), v8_str("x"))
6236 .FromJust());
5576 info.GetReturnValue().Set(name); 6237 info.GetReturnValue().Set(name);
5577 } 6238 }
5578 6239
5579 6240
5580 THREADED_TEST(SimplePropertyRead) { 6241 THREADED_TEST(SimplePropertyRead) {
5581 LocalContext context; 6242 LocalContext context;
5582 v8::Isolate* isolate = context->GetIsolate(); 6243 v8::Isolate* isolate = context->GetIsolate();
5583 v8::HandleScope scope(isolate); 6244 v8::HandleScope scope(isolate);
5584 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6245 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5585 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 6246 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5586 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6247 CHECK(context->Global()
6248 ->Set(context.local(), v8_str("obj"),
6249 templ->NewInstance(context.local()).ToLocalChecked())
6250 .FromJust());
5587 Local<Script> script = v8_compile("obj.x"); 6251 Local<Script> script = v8_compile("obj.x");
5588 for (int i = 0; i < 10; i++) { 6252 for (int i = 0; i < 10; i++) {
5589 Local<Value> result = script->Run(); 6253 Local<Value> result = script->Run(context.local()).ToLocalChecked();
5590 CHECK(result->Equals(v8_str("x"))); 6254 CHECK(result->Equals(context.local(), v8_str("x")).FromJust());
5591 } 6255 }
5592 } 6256 }
5593 6257
5594 6258
5595 THREADED_TEST(DefinePropertyOnAPIAccessor) { 6259 THREADED_TEST(DefinePropertyOnAPIAccessor) {
5596 LocalContext context; 6260 LocalContext context;
5597 v8::Isolate* isolate = context->GetIsolate(); 6261 v8::Isolate* isolate = context->GetIsolate();
5598 v8::HandleScope scope(isolate); 6262 v8::HandleScope scope(isolate);
5599 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6263 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5600 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 6264 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5601 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6265 CHECK(context->Global()
6266 ->Set(context.local(), v8_str("obj"),
6267 templ->NewInstance(context.local()).ToLocalChecked())
6268 .FromJust());
5602 6269
5603 // Uses getOwnPropertyDescriptor to check the configurable status 6270 // Uses getOwnPropertyDescriptor to check the configurable status
5604 Local<Script> script_desc = v8_compile( 6271 Local<Script> script_desc = v8_compile(
5605 "var prop = Object.getOwnPropertyDescriptor( " 6272 "var prop = Object.getOwnPropertyDescriptor( "
5606 "obj, 'x');" 6273 "obj, 'x');"
5607 "prop.configurable;"); 6274 "prop.configurable;");
5608 Local<Value> result = script_desc->Run(); 6275 Local<Value> result = script_desc->Run(context.local()).ToLocalChecked();
5609 CHECK_EQ(result->BooleanValue(), true); 6276 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true);
5610 6277
5611 // Redefine get - but still configurable 6278 // Redefine get - but still configurable
5612 Local<Script> script_define = v8_compile( 6279 Local<Script> script_define = v8_compile(
5613 "var desc = { get: function(){return 42; }," 6280 "var desc = { get: function(){return 42; },"
5614 " configurable: true };" 6281 " configurable: true };"
5615 "Object.defineProperty(obj, 'x', desc);" 6282 "Object.defineProperty(obj, 'x', desc);"
5616 "obj.x"); 6283 "obj.x");
5617 result = script_define->Run(); 6284 result = script_define->Run(context.local()).ToLocalChecked();
5618 CHECK(result->Equals(v8_num(42))); 6285 CHECK(result->Equals(context.local(), v8_num(42)).FromJust());
5619 6286
5620 // Check that the accessor is still configurable 6287 // Check that the accessor is still configurable
5621 result = script_desc->Run(); 6288 result = script_desc->Run(context.local()).ToLocalChecked();
5622 CHECK_EQ(result->BooleanValue(), true); 6289 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true);
5623 6290
5624 // Redefine to a non-configurable 6291 // Redefine to a non-configurable
5625 script_define = v8_compile( 6292 script_define = v8_compile(
5626 "var desc = { get: function(){return 43; }," 6293 "var desc = { get: function(){return 43; },"
5627 " configurable: false };" 6294 " configurable: false };"
5628 "Object.defineProperty(obj, 'x', desc);" 6295 "Object.defineProperty(obj, 'x', desc);"
5629 "obj.x"); 6296 "obj.x");
5630 result = script_define->Run(); 6297 result = script_define->Run(context.local()).ToLocalChecked();
5631 CHECK(result->Equals(v8_num(43))); 6298 CHECK(result->Equals(context.local(), v8_num(43)).FromJust());
5632 result = script_desc->Run(); 6299 result = script_desc->Run(context.local()).ToLocalChecked();
5633 CHECK_EQ(result->BooleanValue(), false); 6300 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), false);
5634 6301
5635 // Make sure that it is not possible to redefine again 6302 // Make sure that it is not possible to redefine again
5636 v8::TryCatch try_catch(isolate); 6303 v8::TryCatch try_catch(isolate);
5637 result = script_define->Run(); 6304 CHECK(script_define->Run(context.local()).IsEmpty());
5638 CHECK(try_catch.HasCaught()); 6305 CHECK(try_catch.HasCaught());
5639 String::Utf8Value exception_value(try_catch.Exception()); 6306 String::Utf8Value exception_value(try_catch.Exception());
5640 CHECK_EQ(0, 6307 CHECK_EQ(0,
5641 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); 6308 strcmp(*exception_value, "TypeError: Cannot redefine property: x"));
5642 } 6309 }
5643 6310
5644 6311
5645 THREADED_TEST(DefinePropertyOnDefineGetterSetter) { 6312 THREADED_TEST(DefinePropertyOnDefineGetterSetter) {
5646 v8::Isolate* isolate = CcTest::isolate(); 6313 v8::Isolate* isolate = CcTest::isolate();
5647 v8::HandleScope scope(isolate); 6314 v8::HandleScope scope(isolate);
5648 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6315 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5649 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut")); 6316 templ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"));
5650 LocalContext context; 6317 LocalContext context;
5651 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6318 CHECK(context->Global()
6319 ->Set(context.local(), v8_str("obj"),
6320 templ->NewInstance(context.local()).ToLocalChecked())
6321 .FromJust());
5652 6322
5653 Local<Script> script_desc = v8_compile( 6323 Local<Script> script_desc = v8_compile(
5654 "var prop =" 6324 "var prop ="
5655 "Object.getOwnPropertyDescriptor( " 6325 "Object.getOwnPropertyDescriptor( "
5656 "obj, 'x');" 6326 "obj, 'x');"
5657 "prop.configurable;"); 6327 "prop.configurable;");
5658 Local<Value> result = script_desc->Run(); 6328 Local<Value> result = script_desc->Run(context.local()).ToLocalChecked();
5659 CHECK_EQ(result->BooleanValue(), true); 6329 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true);
5660 6330
5661 Local<Script> script_define = v8_compile( 6331 Local<Script> script_define = v8_compile(
5662 "var desc = {get: function(){return 42; }," 6332 "var desc = {get: function(){return 42; },"
5663 " configurable: true };" 6333 " configurable: true };"
5664 "Object.defineProperty(obj, 'x', desc);" 6334 "Object.defineProperty(obj, 'x', desc);"
5665 "obj.x"); 6335 "obj.x");
5666 result = script_define->Run(); 6336 result = script_define->Run(context.local()).ToLocalChecked();
5667 CHECK(result->Equals(v8_num(42))); 6337 CHECK(result->Equals(context.local(), v8_num(42)).FromJust());
5668 6338
5669 6339 result = script_desc->Run(context.local()).ToLocalChecked();
5670 result = script_desc->Run(); 6340 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), true);
5671 CHECK_EQ(result->BooleanValue(), true);
5672
5673 6341
5674 script_define = v8_compile( 6342 script_define = v8_compile(
5675 "var desc = {get: function(){return 43; }," 6343 "var desc = {get: function(){return 43; },"
5676 " configurable: false };" 6344 " configurable: false };"
5677 "Object.defineProperty(obj, 'x', desc);" 6345 "Object.defineProperty(obj, 'x', desc);"
5678 "obj.x"); 6346 "obj.x");
5679 result = script_define->Run(); 6347 result = script_define->Run(context.local()).ToLocalChecked();
5680 CHECK(result->Equals(v8_num(43))); 6348 CHECK(result->Equals(context.local(), v8_num(43)).FromJust());
5681 result = script_desc->Run();
5682 6349
5683 CHECK_EQ(result->BooleanValue(), false); 6350 result = script_desc->Run(context.local()).ToLocalChecked();
6351 CHECK_EQ(result->BooleanValue(context.local()).FromJust(), false);
5684 6352
5685 v8::TryCatch try_catch(isolate); 6353 v8::TryCatch try_catch(isolate);
5686 result = script_define->Run(); 6354 CHECK(script_define->Run(context.local()).IsEmpty());
5687 CHECK(try_catch.HasCaught()); 6355 CHECK(try_catch.HasCaught());
5688 String::Utf8Value exception_value(try_catch.Exception()); 6356 String::Utf8Value exception_value(try_catch.Exception());
5689 CHECK_EQ(0, 6357 CHECK_EQ(0,
5690 strcmp(*exception_value, "TypeError: Cannot redefine property: x")); 6358 strcmp(*exception_value, "TypeError: Cannot redefine property: x"));
5691 } 6359 }
5692 6360
5693 6361
5694 static v8::Handle<v8::Object> GetGlobalProperty(LocalContext* context, 6362 static v8::Local<v8::Object> GetGlobalProperty(LocalContext* context,
5695 char const* name) { 6363 char const* name) {
5696 return v8::Handle<v8::Object>::Cast((*context)->Global()->Get(v8_str(name))); 6364 return v8::Local<v8::Object>::Cast(
6365 (*context)
6366 ->Global()
6367 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str(name))
6368 .ToLocalChecked());
5697 } 6369 }
5698 6370
5699 6371
5700 THREADED_TEST(DefineAPIAccessorOnObject) { 6372 THREADED_TEST(DefineAPIAccessorOnObject) {
5701 v8::Isolate* isolate = CcTest::isolate(); 6373 v8::Isolate* isolate = CcTest::isolate();
5702 v8::HandleScope scope(isolate); 6374 v8::HandleScope scope(isolate);
5703 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6375 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5704 LocalContext context; 6376 LocalContext context;
5705 6377
5706 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 6378 CHECK(context->Global()
6379 ->Set(context.local(), v8_str("obj1"),
6380 templ->NewInstance(context.local()).ToLocalChecked())
6381 .FromJust());
5707 CompileRun("var obj2 = {};"); 6382 CompileRun("var obj2 = {};");
5708 6383
5709 CHECK(CompileRun("obj1.x")->IsUndefined()); 6384 CHECK(CompileRun("obj1.x")->IsUndefined());
5710 CHECK(CompileRun("obj2.x")->IsUndefined()); 6385 CHECK(CompileRun("obj2.x")->IsUndefined());
5711 6386
5712 CHECK(GetGlobalProperty(&context, "obj1") 6387 CHECK(GetGlobalProperty(&context, "obj1")
5713 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6388 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6389 v8_str("donut"))
6390 .FromJust());
5714 6391
5715 ExpectString("obj1.x", "x"); 6392 ExpectString("obj1.x", "x");
5716 CHECK(CompileRun("obj2.x")->IsUndefined()); 6393 CHECK(CompileRun("obj2.x")->IsUndefined());
5717 6394
5718 CHECK(GetGlobalProperty(&context, "obj2") 6395 CHECK(GetGlobalProperty(&context, "obj2")
5719 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6396 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6397 v8_str("donut"))
6398 .FromJust());
5720 6399
5721 ExpectString("obj1.x", "x"); 6400 ExpectString("obj1.x", "x");
5722 ExpectString("obj2.x", "x"); 6401 ExpectString("obj2.x", "x");
5723 6402
5724 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); 6403 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5725 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); 6404 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5726 6405
5727 CompileRun( 6406 CompileRun(
5728 "Object.defineProperty(obj1, 'x'," 6407 "Object.defineProperty(obj1, 'x',"
5729 "{ get: function() { return 'y'; }, configurable: true })"); 6408 "{ get: function() { return 'y'; }, configurable: true })");
5730 6409
5731 ExpectString("obj1.x", "y"); 6410 ExpectString("obj1.x", "y");
5732 ExpectString("obj2.x", "x"); 6411 ExpectString("obj2.x", "x");
5733 6412
5734 CompileRun( 6413 CompileRun(
5735 "Object.defineProperty(obj2, 'x'," 6414 "Object.defineProperty(obj2, 'x',"
5736 "{ get: function() { return 'y'; }, configurable: true })"); 6415 "{ get: function() { return 'y'; }, configurable: true })");
5737 6416
5738 ExpectString("obj1.x", "y"); 6417 ExpectString("obj1.x", "y");
5739 ExpectString("obj2.x", "y"); 6418 ExpectString("obj2.x", "y");
5740 6419
5741 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); 6420 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5742 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); 6421 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5743 6422
5744 CHECK(GetGlobalProperty(&context, "obj1") 6423 CHECK(GetGlobalProperty(&context, "obj1")
5745 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6424 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6425 v8_str("donut"))
6426 .FromJust());
5746 CHECK(GetGlobalProperty(&context, "obj2") 6427 CHECK(GetGlobalProperty(&context, "obj2")
5747 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6428 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6429 v8_str("donut"))
6430 .FromJust());
5748 6431
5749 ExpectString("obj1.x", "x"); 6432 ExpectString("obj1.x", "x");
5750 ExpectString("obj2.x", "x"); 6433 ExpectString("obj2.x", "x");
5751 6434
5752 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); 6435 ExpectTrue("Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5753 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); 6436 ExpectTrue("Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5754 6437
5755 // Define getters/setters, but now make them not configurable. 6438 // Define getters/setters, but now make them not configurable.
5756 CompileRun( 6439 CompileRun(
5757 "Object.defineProperty(obj1, 'x'," 6440 "Object.defineProperty(obj1, 'x',"
5758 "{ get: function() { return 'z'; }, configurable: false })"); 6441 "{ get: function() { return 'z'; }, configurable: false })");
5759 CompileRun( 6442 CompileRun(
5760 "Object.defineProperty(obj2, 'x'," 6443 "Object.defineProperty(obj2, 'x',"
5761 "{ get: function() { return 'z'; }, configurable: false })"); 6444 "{ get: function() { return 'z'; }, configurable: false })");
5762
5763 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); 6445 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5764 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); 6446 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5765 6447
5766 ExpectString("obj1.x", "z"); 6448 ExpectString("obj1.x", "z");
5767 ExpectString("obj2.x", "z"); 6449 ExpectString("obj2.x", "z");
5768 6450
5769 CHECK(!GetGlobalProperty(&context, "obj1") 6451 CHECK(GetGlobalProperty(&context, "obj1")
5770 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6452 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
5771 CHECK(!GetGlobalProperty(&context, "obj2") 6453 v8_str("donut"))
5772 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6454 .IsNothing());
6455 CHECK(GetGlobalProperty(&context, "obj2")
6456 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6457 v8_str("donut"))
6458 .IsNothing());
5773 6459
5774 ExpectString("obj1.x", "z"); 6460 ExpectString("obj1.x", "z");
5775 ExpectString("obj2.x", "z"); 6461 ExpectString("obj2.x", "z");
5776 } 6462 }
5777 6463
5778 6464
5779 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) { 6465 THREADED_TEST(DontDeleteAPIAccessorsCannotBeOverriden) {
5780 v8::Isolate* isolate = CcTest::isolate(); 6466 v8::Isolate* isolate = CcTest::isolate();
5781 v8::HandleScope scope(isolate); 6467 v8::HandleScope scope(isolate);
5782 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6468 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5783 LocalContext context; 6469 LocalContext context;
5784 6470
5785 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 6471 CHECK(context->Global()
6472 ->Set(context.local(), v8_str("obj1"),
6473 templ->NewInstance(context.local()).ToLocalChecked())
6474 .FromJust());
5786 CompileRun("var obj2 = {};"); 6475 CompileRun("var obj2 = {};");
5787 6476
5788 CHECK(GetGlobalProperty(&context, "obj1") 6477 CHECK(GetGlobalProperty(&context, "obj1")
5789 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"), 6478 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
5790 v8::DEFAULT, v8::DontDelete)); 6479 v8_str("donut"), v8::DEFAULT, v8::DontDelete)
6480 .FromJust());
5791 CHECK(GetGlobalProperty(&context, "obj2") 6481 CHECK(GetGlobalProperty(&context, "obj2")
5792 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"), 6482 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
5793 v8::DEFAULT, v8::DontDelete)); 6483 v8_str("donut"), v8::DEFAULT, v8::DontDelete)
6484 .FromJust());
5794 6485
5795 ExpectString("obj1.x", "x"); 6486 ExpectString("obj1.x", "x");
5796 ExpectString("obj2.x", "x"); 6487 ExpectString("obj2.x", "x");
5797 6488
5798 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable"); 6489 ExpectTrue("!Object.getOwnPropertyDescriptor(obj1, 'x').configurable");
5799 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable"); 6490 ExpectTrue("!Object.getOwnPropertyDescriptor(obj2, 'x').configurable");
5800 6491
5801 CHECK(!GetGlobalProperty(&context, "obj1") 6492 CHECK(GetGlobalProperty(&context, "obj1")
5802 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6493 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
5803 CHECK(!GetGlobalProperty(&context, "obj2") 6494 v8_str("donut"))
5804 ->SetAccessor(v8_str("x"), GetXValue, NULL, v8_str("donut"))); 6495 .IsNothing());
6496 CHECK(GetGlobalProperty(&context, "obj2")
6497 ->SetAccessor(context.local(), v8_str("x"), GetXValue, NULL,
6498 v8_str("donut"))
6499 .IsNothing());
5805 6500
5806 { 6501 {
5807 v8::TryCatch try_catch(isolate); 6502 v8::TryCatch try_catch(isolate);
5808 CompileRun( 6503 CompileRun(
5809 "Object.defineProperty(obj1, 'x'," 6504 "Object.defineProperty(obj1, 'x',"
5810 "{get: function() { return 'func'; }})"); 6505 "{get: function() { return 'func'; }})");
5811 CHECK(try_catch.HasCaught()); 6506 CHECK(try_catch.HasCaught());
5812 String::Utf8Value exception_value(try_catch.Exception()); 6507 String::Utf8Value exception_value(try_catch.Exception());
5813 CHECK_EQ( 6508 CHECK_EQ(
5814 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); 6509 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x"));
5815 } 6510 }
5816 { 6511 {
5817 v8::TryCatch try_catch(isolate); 6512 v8::TryCatch try_catch(isolate);
5818 CompileRun( 6513 CompileRun(
5819 "Object.defineProperty(obj2, 'x'," 6514 "Object.defineProperty(obj2, 'x',"
5820 "{get: function() { return 'func'; }})"); 6515 "{get: function() { return 'func'; }})");
5821 CHECK(try_catch.HasCaught()); 6516 CHECK(try_catch.HasCaught());
5822 String::Utf8Value exception_value(try_catch.Exception()); 6517 String::Utf8Value exception_value(try_catch.Exception());
5823 CHECK_EQ( 6518 CHECK_EQ(
5824 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x")); 6519 0, strcmp(*exception_value, "TypeError: Cannot redefine property: x"));
5825 } 6520 }
5826 } 6521 }
5827 6522
5828 6523
5829 static void Get239Value(Local<String> name, 6524 static void Get239Value(Local<Name> name,
5830 const v8::PropertyCallbackInfo<v8::Value>& info) { 6525 const v8::PropertyCallbackInfo<v8::Value>& info) {
5831 ApiTestFuzzer::Fuzz(); 6526 ApiTestFuzzer::Fuzz();
5832 CHECK(info.Data()->Equals(v8_str("donut"))); 6527 CHECK(info.Data()
5833 CHECK(name->Equals(v8_str("239"))); 6528 ->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("donut"))
6529 .FromJust());
6530 CHECK(name->Equals(info.GetIsolate()->GetCurrentContext(), v8_str("239"))
6531 .FromJust());
5834 info.GetReturnValue().Set(name); 6532 info.GetReturnValue().Set(name);
5835 } 6533 }
5836 6534
5837 6535
5838 THREADED_TEST(ElementAPIAccessor) { 6536 THREADED_TEST(ElementAPIAccessor) {
5839 v8::Isolate* isolate = CcTest::isolate(); 6537 v8::Isolate* isolate = CcTest::isolate();
5840 v8::HandleScope scope(isolate); 6538 v8::HandleScope scope(isolate);
5841 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6539 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5842 LocalContext context; 6540 LocalContext context;
5843 6541
5844 context->Global()->Set(v8_str("obj1"), templ->NewInstance()); 6542 CHECK(context->Global()
6543 ->Set(context.local(), v8_str("obj1"),
6544 templ->NewInstance(context.local()).ToLocalChecked())
6545 .FromJust());
5845 CompileRun("var obj2 = {};"); 6546 CompileRun("var obj2 = {};");
5846 6547
5847 CHECK(GetGlobalProperty(&context, "obj1") 6548 CHECK(GetGlobalProperty(&context, "obj1")
5848 ->SetAccessor(v8_str("239"), Get239Value, NULL, v8_str("donut"))); 6549 ->SetAccessor(context.local(), v8_str("239"), Get239Value, NULL,
6550 v8_str("donut"))
6551 .FromJust());
5849 CHECK(GetGlobalProperty(&context, "obj2") 6552 CHECK(GetGlobalProperty(&context, "obj2")
5850 ->SetAccessor(v8_str("239"), Get239Value, NULL, v8_str("donut"))); 6553 ->SetAccessor(context.local(), v8_str("239"), Get239Value, NULL,
6554 v8_str("donut"))
6555 .FromJust());
5851 6556
5852 ExpectString("obj1[239]", "239"); 6557 ExpectString("obj1[239]", "239");
5853 ExpectString("obj2[239]", "239"); 6558 ExpectString("obj2[239]", "239");
5854 ExpectString("obj1['239']", "239"); 6559 ExpectString("obj1['239']", "239");
5855 ExpectString("obj2['239']", "239"); 6560 ExpectString("obj2['239']", "239");
5856 } 6561 }
5857 6562
5858 6563
5859 v8::Persistent<Value> xValue; 6564 v8::Persistent<Value> xValue;
5860 6565
5861 6566
5862 static void SetXValue(Local<String> name, Local<Value> value, 6567 static void SetXValue(Local<Name> name, Local<Value> value,
5863 const v8::PropertyCallbackInfo<void>& info) { 6568 const v8::PropertyCallbackInfo<void>& info) {
5864 CHECK(value->Equals(v8_num(4))); 6569 Local<Context> context = info.GetIsolate()->GetCurrentContext();
5865 CHECK(info.Data()->Equals(v8_str("donut"))); 6570 CHECK(value->Equals(context, v8_num(4)).FromJust());
5866 CHECK(name->Equals(v8_str("x"))); 6571 CHECK(info.Data()->Equals(context, v8_str("donut")).FromJust());
6572 CHECK(name->Equals(context, v8_str("x")).FromJust());
5867 CHECK(xValue.IsEmpty()); 6573 CHECK(xValue.IsEmpty());
5868 xValue.Reset(info.GetIsolate(), value); 6574 xValue.Reset(info.GetIsolate(), value);
5869 } 6575 }
5870 6576
5871 6577
5872 THREADED_TEST(SimplePropertyWrite) { 6578 THREADED_TEST(SimplePropertyWrite) {
5873 v8::Isolate* isolate = CcTest::isolate(); 6579 v8::Isolate* isolate = CcTest::isolate();
5874 v8::HandleScope scope(isolate); 6580 v8::HandleScope scope(isolate);
5875 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6581 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5876 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut")); 6582 templ->SetAccessor(v8_str("x"), GetXValue, SetXValue, v8_str("donut"));
5877 LocalContext context; 6583 LocalContext context;
5878 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6584 CHECK(context->Global()
6585 ->Set(context.local(), v8_str("obj"),
6586 templ->NewInstance(context.local()).ToLocalChecked())
6587 .FromJust());
5879 Local<Script> script = v8_compile("obj.x = 4"); 6588 Local<Script> script = v8_compile("obj.x = 4");
5880 for (int i = 0; i < 10; i++) { 6589 for (int i = 0; i < 10; i++) {
5881 CHECK(xValue.IsEmpty()); 6590 CHECK(xValue.IsEmpty());
5882 script->Run(); 6591 script->Run(context.local()).ToLocalChecked();
5883 CHECK(v8_num(4)->Equals(Local<Value>::New(CcTest::isolate(), xValue))); 6592 CHECK(v8_num(4)
6593 ->Equals(context.local(),
6594 Local<Value>::New(CcTest::isolate(), xValue))
6595 .FromJust());
5884 xValue.Reset(); 6596 xValue.Reset();
5885 } 6597 }
5886 } 6598 }
5887 6599
5888 6600
5889 THREADED_TEST(SetterOnly) { 6601 THREADED_TEST(SetterOnly) {
5890 v8::Isolate* isolate = CcTest::isolate(); 6602 v8::Isolate* isolate = CcTest::isolate();
5891 v8::HandleScope scope(isolate); 6603 v8::HandleScope scope(isolate);
5892 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6604 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5893 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut")); 6605 templ->SetAccessor(v8_str("x"), NULL, SetXValue, v8_str("donut"));
5894 LocalContext context; 6606 LocalContext context;
5895 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6607 CHECK(context->Global()
6608 ->Set(context.local(), v8_str("obj"),
6609 templ->NewInstance(context.local()).ToLocalChecked())
6610 .FromJust());
5896 Local<Script> script = v8_compile("obj.x = 4; obj.x"); 6611 Local<Script> script = v8_compile("obj.x = 4; obj.x");
5897 for (int i = 0; i < 10; i++) { 6612 for (int i = 0; i < 10; i++) {
5898 CHECK(xValue.IsEmpty()); 6613 CHECK(xValue.IsEmpty());
5899 script->Run(); 6614 script->Run(context.local()).ToLocalChecked();
5900 CHECK(v8_num(4)->Equals(Local<Value>::New(CcTest::isolate(), xValue))); 6615 CHECK(v8_num(4)
6616 ->Equals(context.local(),
6617 Local<Value>::New(CcTest::isolate(), xValue))
6618 .FromJust());
5901 xValue.Reset(); 6619 xValue.Reset();
5902 } 6620 }
5903 } 6621 }
5904 6622
5905 6623
5906 THREADED_TEST(NoAccessors) { 6624 THREADED_TEST(NoAccessors) {
5907 v8::Isolate* isolate = CcTest::isolate(); 6625 v8::Isolate* isolate = CcTest::isolate();
5908 v8::HandleScope scope(isolate); 6626 v8::HandleScope scope(isolate);
5909 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6627 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5910 templ->SetAccessor(v8_str("x"), static_cast<v8::AccessorGetterCallback>(NULL), 6628 templ->SetAccessor(v8_str("x"), static_cast<v8::AccessorGetterCallback>(NULL),
5911 NULL, v8_str("donut")); 6629 NULL, v8_str("donut"));
5912 LocalContext context; 6630 LocalContext context;
5913 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 6631 CHECK(context->Global()
6632 ->Set(context.local(), v8_str("obj"),
6633 templ->NewInstance(context.local()).ToLocalChecked())
6634 .FromJust());
5914 Local<Script> script = v8_compile("obj.x = 4; obj.x"); 6635 Local<Script> script = v8_compile("obj.x = 4; obj.x");
5915 for (int i = 0; i < 10; i++) { 6636 for (int i = 0; i < 10; i++) {
5916 script->Run(); 6637 script->Run(context.local()).ToLocalChecked();
5917 } 6638 }
5918 } 6639 }
5919 6640
5920 6641
5921 THREADED_TEST(MultiContexts) { 6642 THREADED_TEST(MultiContexts) {
5922 v8::Isolate* isolate = CcTest::isolate(); 6643 v8::Isolate* isolate = CcTest::isolate();
5923 v8::HandleScope scope(isolate); 6644 v8::HandleScope scope(isolate);
5924 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 6645 v8::Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5925 templ->Set(v8_str("dummy"), 6646 templ->Set(v8_str("dummy"),
5926 v8::FunctionTemplate::New(isolate, DummyCallHandler)); 6647 v8::FunctionTemplate::New(isolate, DummyCallHandler));
5927 6648
5928 Local<String> password = v8_str("Password"); 6649 Local<String> password = v8_str("Password");
5929 6650
5930 // Create an environment 6651 // Create an environment
5931 LocalContext context0(0, templ); 6652 LocalContext context0(0, templ);
5932 context0->SetSecurityToken(password); 6653 context0->SetSecurityToken(password);
5933 v8::Handle<v8::Object> global0 = context0->Global(); 6654 v8::Local<v8::Object> global0 = context0->Global();
5934 global0->Set(v8_str("custom"), v8_num(1234)); 6655 CHECK(global0->Set(context0.local(), v8_str("custom"), v8_num(1234))
5935 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); 6656 .FromJust());
6657 CHECK_EQ(1234, global0->Get(context0.local(), v8_str("custom"))
6658 .ToLocalChecked()
6659 ->Int32Value(context0.local())
6660 .FromJust());
5936 6661
5937 // Create an independent environment 6662 // Create an independent environment
5938 LocalContext context1(0, templ); 6663 LocalContext context1(0, templ);
5939 context1->SetSecurityToken(password); 6664 context1->SetSecurityToken(password);
5940 v8::Handle<v8::Object> global1 = context1->Global(); 6665 v8::Local<v8::Object> global1 = context1->Global();
5941 global1->Set(v8_str("custom"), v8_num(1234)); 6666 CHECK(global1->Set(context1.local(), v8_str("custom"), v8_num(1234))
5942 CHECK(!global0->Equals(global1)); 6667 .FromJust());
5943 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); 6668 CHECK(!global0->Equals(context1.local(), global1).FromJust());
5944 CHECK_EQ(1234, global1->Get(v8_str("custom"))->Int32Value()); 6669 CHECK_EQ(1234, global0->Get(context1.local(), v8_str("custom"))
6670 .ToLocalChecked()
6671 ->Int32Value(context0.local())
6672 .FromJust());
6673 CHECK_EQ(1234, global1->Get(context1.local(), v8_str("custom"))
6674 .ToLocalChecked()
6675 ->Int32Value(context1.local())
6676 .FromJust());
5945 6677
5946 // Now create a new context with the old global 6678 // Now create a new context with the old global
5947 LocalContext context2(0, templ, global1); 6679 LocalContext context2(0, templ, global1);
5948 context2->SetSecurityToken(password); 6680 context2->SetSecurityToken(password);
5949 v8::Handle<v8::Object> global2 = context2->Global(); 6681 v8::Local<v8::Object> global2 = context2->Global();
5950 CHECK(global1->Equals(global2)); 6682 CHECK(global1->Equals(context2.local(), global2).FromJust());
5951 CHECK_EQ(0, global1->Get(v8_str("custom"))->Int32Value()); 6683 CHECK_EQ(0, global1->Get(context2.local(), v8_str("custom"))
5952 CHECK_EQ(0, global2->Get(v8_str("custom"))->Int32Value()); 6684 .ToLocalChecked()
6685 ->Int32Value(context1.local())
6686 .FromJust());
6687 CHECK_EQ(0, global2->Get(context2.local(), v8_str("custom"))
6688 .ToLocalChecked()
6689 ->Int32Value(context2.local())
6690 .FromJust());
5953 } 6691 }
5954 6692
5955 6693
5956 THREADED_TEST(FunctionPrototypeAcrossContexts) { 6694 THREADED_TEST(FunctionPrototypeAcrossContexts) {
5957 // Make sure that functions created by cloning boilerplates cannot 6695 // Make sure that functions created by cloning boilerplates cannot
5958 // communicate through their __proto__ field. 6696 // communicate through their __proto__ field.
5959 6697
5960 v8::HandleScope scope(CcTest::isolate()); 6698 v8::HandleScope scope(CcTest::isolate());
5961 6699
5962 LocalContext env0; 6700 LocalContext env0;
5963 v8::Handle<v8::Object> global0 = env0->Global(); 6701 v8::Local<v8::Object> global0 = env0->Global();
5964 v8::Handle<v8::Object> object0 = 6702 v8::Local<v8::Object> object0 = global0->Get(env0.local(), v8_str("Object"))
5965 global0->Get(v8_str("Object")).As<v8::Object>(); 6703 .ToLocalChecked()
5966 v8::Handle<v8::Object> tostring0 = 6704 .As<v8::Object>();
5967 object0->Get(v8_str("toString")).As<v8::Object>(); 6705 v8::Local<v8::Object> tostring0 =
5968 v8::Handle<v8::Object> proto0 = 6706 object0->Get(env0.local(), v8_str("toString"))
5969 tostring0->Get(v8_str("__proto__")).As<v8::Object>(); 6707 .ToLocalChecked()
5970 proto0->Set(v8_str("custom"), v8_num(1234)); 6708 .As<v8::Object>();
6709 v8::Local<v8::Object> proto0 =
6710 tostring0->Get(env0.local(), v8_str("__proto__"))
6711 .ToLocalChecked()
6712 .As<v8::Object>();
6713 CHECK(proto0->Set(env0.local(), v8_str("custom"), v8_num(1234)).FromJust());
5971 6714
5972 LocalContext env1; 6715 LocalContext env1;
5973 v8::Handle<v8::Object> global1 = env1->Global(); 6716 v8::Local<v8::Object> global1 = env1->Global();
5974 v8::Handle<v8::Object> object1 = 6717 v8::Local<v8::Object> object1 = global1->Get(env1.local(), v8_str("Object"))
5975 global1->Get(v8_str("Object")).As<v8::Object>(); 6718 .ToLocalChecked()
5976 v8::Handle<v8::Object> tostring1 = 6719 .As<v8::Object>();
5977 object1->Get(v8_str("toString")).As<v8::Object>(); 6720 v8::Local<v8::Object> tostring1 =
5978 v8::Handle<v8::Object> proto1 = 6721 object1->Get(env1.local(), v8_str("toString"))
5979 tostring1->Get(v8_str("__proto__")).As<v8::Object>(); 6722 .ToLocalChecked()
5980 CHECK(!proto1->Has(v8_str("custom"))); 6723 .As<v8::Object>();
6724 v8::Local<v8::Object> proto1 =
6725 tostring1->Get(env1.local(), v8_str("__proto__"))
6726 .ToLocalChecked()
6727 .As<v8::Object>();
6728 CHECK(!proto1->Has(env1.local(), v8_str("custom")).FromJust());
5981 } 6729 }
5982 6730
5983 6731
5984 THREADED_TEST(Regress892105) { 6732 THREADED_TEST(Regress892105) {
5985 // Make sure that object and array literals created by cloning 6733 // Make sure that object and array literals created by cloning
5986 // boilerplates cannot communicate through their __proto__ 6734 // boilerplates cannot communicate through their __proto__
5987 // field. This is rather difficult to check, but we try to add stuff 6735 // field. This is rather difficult to check, but we try to add stuff
5988 // to Object.prototype and Array.prototype and create a new 6736 // to Object.prototype and Array.prototype and create a new
5989 // environment. This should succeed. 6737 // environment. This should succeed.
5990 6738
5991 v8::HandleScope scope(CcTest::isolate()); 6739 v8::HandleScope scope(CcTest::isolate());
5992 6740
5993 Local<String> source = v8_str( 6741 Local<String> source = v8_str(
5994 "Object.prototype.obj = 1234;" 6742 "Object.prototype.obj = 1234;"
5995 "Array.prototype.arr = 4567;" 6743 "Array.prototype.arr = 4567;"
5996 "8901"); 6744 "8901");
5997 6745
5998 LocalContext env0; 6746 LocalContext env0;
5999 Local<Script> script0 = v8_compile(source); 6747 Local<Script> script0 = v8_compile(source);
6000 CHECK_EQ(8901.0, script0->Run()->NumberValue()); 6748 CHECK_EQ(8901.0, script0->Run(env0.local())
6749 .ToLocalChecked()
6750 ->NumberValue(env0.local())
6751 .FromJust());
6001 6752
6002 LocalContext env1; 6753 LocalContext env1;
6003 Local<Script> script1 = v8_compile(source); 6754 Local<Script> script1 = v8_compile(source);
6004 CHECK_EQ(8901.0, script1->Run()->NumberValue()); 6755 CHECK_EQ(8901.0, script1->Run(env1.local())
6756 .ToLocalChecked()
6757 ->NumberValue(env1.local())
6758 .FromJust());
6005 } 6759 }
6006 6760
6007 6761
6008 THREADED_TEST(UndetectableObject) { 6762 THREADED_TEST(UndetectableObject) {
6009 LocalContext env; 6763 LocalContext env;
6010 v8::HandleScope scope(env->GetIsolate()); 6764 v8::HandleScope scope(env->GetIsolate());
6011 6765
6012 Local<v8::FunctionTemplate> desc = 6766 Local<v8::FunctionTemplate> desc =
6013 v8::FunctionTemplate::New(env->GetIsolate()); 6767 v8::FunctionTemplate::New(env->GetIsolate());
6014 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6768 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6015 6769
6016 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6770 Local<v8::Object> obj = desc->GetFunction(env.local())
6017 env->Global()->Set(v8_str("undetectable"), obj); 6771 .ToLocalChecked()
6772 ->NewInstance(env.local())
6773 .ToLocalChecked();
6774 CHECK(
6775 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust());
6018 6776
6019 ExpectString("undetectable.toString()", "[object Object]"); 6777 ExpectString("undetectable.toString()", "[object Object]");
6020 ExpectString("typeof undetectable", "undefined"); 6778 ExpectString("typeof undetectable", "undefined");
6021 ExpectString("typeof(undetectable)", "undefined"); 6779 ExpectString("typeof(undetectable)", "undefined");
6022 ExpectBoolean("typeof undetectable == 'undefined'", true); 6780 ExpectBoolean("typeof undetectable == 'undefined'", true);
6023 ExpectBoolean("typeof undetectable == 'object'", false); 6781 ExpectBoolean("typeof undetectable == 'object'", false);
6024 ExpectBoolean("if (undetectable) { true; } else { false; }", false); 6782 ExpectBoolean("if (undetectable) { true; } else { false; }", false);
6025 ExpectBoolean("!undetectable", true); 6783 ExpectBoolean("!undetectable", true);
6026 6784
6027 ExpectObject("true&&undetectable", obj); 6785 ExpectObject("true&&undetectable", obj);
(...skipping 22 matching lines...) Expand all
6050 6808
6051 6809
6052 THREADED_TEST(VoidLiteral) { 6810 THREADED_TEST(VoidLiteral) {
6053 LocalContext env; 6811 LocalContext env;
6054 v8::Isolate* isolate = env->GetIsolate(); 6812 v8::Isolate* isolate = env->GetIsolate();
6055 v8::HandleScope scope(isolate); 6813 v8::HandleScope scope(isolate);
6056 6814
6057 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); 6815 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
6058 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6816 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6059 6817
6060 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6818 Local<v8::Object> obj = desc->GetFunction(env.local())
6061 env->Global()->Set(v8_str("undetectable"), obj); 6819 .ToLocalChecked()
6820 ->NewInstance(env.local())
6821 .ToLocalChecked();
6822 CHECK(
6823 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust());
6062 6824
6063 ExpectBoolean("undefined == void 0", true); 6825 ExpectBoolean("undefined == void 0", true);
6064 ExpectBoolean("undetectable == void 0", true); 6826 ExpectBoolean("undetectable == void 0", true);
6065 ExpectBoolean("null == void 0", true); 6827 ExpectBoolean("null == void 0", true);
6066 ExpectBoolean("undefined === void 0", true); 6828 ExpectBoolean("undefined === void 0", true);
6067 ExpectBoolean("undetectable === void 0", false); 6829 ExpectBoolean("undetectable === void 0", false);
6068 ExpectBoolean("null === void 0", false); 6830 ExpectBoolean("null === void 0", false);
6069 6831
6070 ExpectBoolean("void 0 == undefined", true); 6832 ExpectBoolean("void 0 == undefined", true);
6071 ExpectBoolean("void 0 == undetectable", true); 6833 ExpectBoolean("void 0 == undetectable", true);
(...skipping 24 matching lines...) Expand all
6096 6858
6097 6859
6098 THREADED_TEST(ExtensibleOnUndetectable) { 6860 THREADED_TEST(ExtensibleOnUndetectable) {
6099 LocalContext env; 6861 LocalContext env;
6100 v8::Isolate* isolate = env->GetIsolate(); 6862 v8::Isolate* isolate = env->GetIsolate();
6101 v8::HandleScope scope(isolate); 6863 v8::HandleScope scope(isolate);
6102 6864
6103 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate); 6865 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
6104 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6866 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6105 6867
6106 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6868 Local<v8::Object> obj = desc->GetFunction(env.local())
6107 env->Global()->Set(v8_str("undetectable"), obj); 6869 .ToLocalChecked()
6870 ->NewInstance(env.local())
6871 .ToLocalChecked();
6872 CHECK(
6873 env->Global()->Set(env.local(), v8_str("undetectable"), obj).FromJust());
6108 6874
6109 Local<String> source = v8_str( 6875 Local<String> source = v8_str(
6110 "undetectable.x = 42;" 6876 "undetectable.x = 42;"
6111 "undetectable.x"); 6877 "undetectable.x");
6112 6878
6113 Local<Script> script = v8_compile(source); 6879 Local<Script> script = v8_compile(source);
6114 6880
6115 CHECK(v8::Integer::New(isolate, 42)->Equals(script->Run())); 6881 CHECK(v8::Integer::New(isolate, 42)
6882 ->Equals(env.local(), script->Run(env.local()).ToLocalChecked())
6883 .FromJust());
6116 6884
6117 ExpectBoolean("Object.isExtensible(undetectable)", true); 6885 ExpectBoolean("Object.isExtensible(undetectable)", true);
6118 6886
6119 source = v8_str("Object.preventExtensions(undetectable);"); 6887 source = v8_str("Object.preventExtensions(undetectable);");
6120 script = v8_compile(source); 6888 script = v8_compile(source);
6121 script->Run(); 6889 script->Run(env.local()).ToLocalChecked();
6122 ExpectBoolean("Object.isExtensible(undetectable)", false); 6890 ExpectBoolean("Object.isExtensible(undetectable)", false);
6123 6891
6124 source = v8_str("undetectable.y = 2000;"); 6892 source = v8_str("undetectable.y = 2000;");
6125 script = v8_compile(source); 6893 script = v8_compile(source);
6126 script->Run(); 6894 script->Run(env.local()).ToLocalChecked();
6127 ExpectBoolean("undetectable.y == undefined", true); 6895 ExpectBoolean("undetectable.y == undefined", true);
6128 } 6896 }
6129 6897
6130 6898
6131 // The point of this test is type checking. We run it only so compilers 6899 // The point of this test is type checking. We run it only so compilers
6132 // don't complain about an unused function. 6900 // don't complain about an unused function.
6133 TEST(PersistentHandles) { 6901 TEST(PersistentHandles) {
6134 LocalContext env; 6902 LocalContext env;
6135 v8::Isolate* isolate = CcTest::isolate(); 6903 v8::Isolate* isolate = CcTest::isolate();
6136 v8::HandleScope scope(isolate); 6904 v8::HandleScope scope(isolate);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
6168 "function Foo() {" 6936 "function Foo() {"
6169 " return 4;" 6937 " return 4;"
6170 "}"; 6938 "}";
6171 6939
6172 6940
6173 TEST(SimpleExtensions) { 6941 TEST(SimpleExtensions) {
6174 v8::HandleScope handle_scope(CcTest::isolate()); 6942 v8::HandleScope handle_scope(CcTest::isolate());
6175 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource)); 6943 v8::RegisterExtension(new Extension("simpletest", kSimpleExtensionSource));
6176 const char* extension_names[] = {"simpletest"}; 6944 const char* extension_names[] = {"simpletest"};
6177 v8::ExtensionConfiguration extensions(1, extension_names); 6945 v8::ExtensionConfiguration extensions(1, extension_names);
6178 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 6946 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6179 Context::Scope lock(context); 6947 Context::Scope lock(context);
6180 v8::Handle<Value> result = CompileRun("Foo()"); 6948 v8::Local<Value> result = CompileRun("Foo()");
6181 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); 6949 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4))
6950 .FromJust());
6182 } 6951 }
6183 6952
6184 6953
6185 static const char* kStackTraceFromExtensionSource = 6954 static const char* kStackTraceFromExtensionSource =
6186 "function foo() {" 6955 "function foo() {"
6187 " throw new Error();" 6956 " throw new Error();"
6188 "}" 6957 "}"
6189 "function bar() {" 6958 "function bar() {"
6190 " foo();" 6959 " foo();"
6191 "}"; 6960 "}";
6192 6961
6193 6962
6194 TEST(StackTraceInExtension) { 6963 TEST(StackTraceInExtension) {
6195 v8::HandleScope handle_scope(CcTest::isolate()); 6964 v8::HandleScope handle_scope(CcTest::isolate());
6196 v8::RegisterExtension( 6965 v8::RegisterExtension(
6197 new Extension("stacktracetest", kStackTraceFromExtensionSource)); 6966 new Extension("stacktracetest", kStackTraceFromExtensionSource));
6198 const char* extension_names[] = {"stacktracetest"}; 6967 const char* extension_names[] = {"stacktracetest"};
6199 v8::ExtensionConfiguration extensions(1, extension_names); 6968 v8::ExtensionConfiguration extensions(1, extension_names);
6200 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 6969 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6201 Context::Scope lock(context); 6970 Context::Scope lock(context);
6202 CompileRun( 6971 CompileRun(
6203 "function user() { bar(); }" 6972 "function user() { bar(); }"
6204 "var error;" 6973 "var error;"
6205 "try{ user(); } catch (e) { error = e; }"); 6974 "try{ user(); } catch (e) { error = e; }");
6206 CHECK_EQ(-1, CompileRun("error.stack.indexOf('foo')")->Int32Value()); 6975 CHECK_EQ(-1, v8_run_int32value(v8_compile("error.stack.indexOf('foo')")));
6207 CHECK_EQ(-1, CompileRun("error.stack.indexOf('bar')")->Int32Value()); 6976 CHECK_EQ(-1, v8_run_int32value(v8_compile("error.stack.indexOf('bar')")));
6208 CHECK_NE(-1, CompileRun("error.stack.indexOf('user')")->Int32Value()); 6977 CHECK_NE(-1, v8_run_int32value(v8_compile("error.stack.indexOf('user')")));
6209 } 6978 }
6210 6979
6211 6980
6212 TEST(NullExtensions) { 6981 TEST(NullExtensions) {
6213 v8::HandleScope handle_scope(CcTest::isolate()); 6982 v8::HandleScope handle_scope(CcTest::isolate());
6214 v8::RegisterExtension(new Extension("nulltest", NULL)); 6983 v8::RegisterExtension(new Extension("nulltest", NULL));
6215 const char* extension_names[] = {"nulltest"}; 6984 const char* extension_names[] = {"nulltest"};
6216 v8::ExtensionConfiguration extensions(1, extension_names); 6985 v8::ExtensionConfiguration extensions(1, extension_names);
6217 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 6986 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6218 Context::Scope lock(context); 6987 Context::Scope lock(context);
6219 v8::Handle<Value> result = CompileRun("1+3"); 6988 v8::Local<Value> result = CompileRun("1+3");
6220 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); 6989 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4))
6990 .FromJust());
6221 } 6991 }
6222 6992
6223 6993
6224 static const char* kEmbeddedExtensionSource = 6994 static const char* kEmbeddedExtensionSource =
6225 "function Ret54321(){return 54321;}~~@@$" 6995 "function Ret54321(){return 54321;}~~@@$"
6226 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS."; 6996 "$%% THIS IS A SERIES OF NON-NULL-TERMINATED STRINGS.";
6227 static const int kEmbeddedExtensionSourceValidLen = 34; 6997 static const int kEmbeddedExtensionSourceValidLen = 34;
6228 6998
6229 6999
6230 TEST(ExtensionMissingSourceLength) { 7000 TEST(ExtensionMissingSourceLength) {
6231 v8::HandleScope handle_scope(CcTest::isolate()); 7001 v8::HandleScope handle_scope(CcTest::isolate());
6232 v8::RegisterExtension( 7002 v8::RegisterExtension(
6233 new Extension("srclentest_fail", kEmbeddedExtensionSource)); 7003 new Extension("srclentest_fail", kEmbeddedExtensionSource));
6234 const char* extension_names[] = {"srclentest_fail"}; 7004 const char* extension_names[] = {"srclentest_fail"};
6235 v8::ExtensionConfiguration extensions(1, extension_names); 7005 v8::ExtensionConfiguration extensions(1, extension_names);
6236 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7006 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6237 CHECK(0 == *context); 7007 CHECK(0 == *context);
6238 } 7008 }
6239 7009
6240 7010
6241 TEST(ExtensionWithSourceLength) { 7011 TEST(ExtensionWithSourceLength) {
6242 for (int source_len = kEmbeddedExtensionSourceValidLen - 1; 7012 for (int source_len = kEmbeddedExtensionSourceValidLen - 1;
6243 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) { 7013 source_len <= kEmbeddedExtensionSourceValidLen + 1; ++source_len) {
6244 v8::HandleScope handle_scope(CcTest::isolate()); 7014 v8::HandleScope handle_scope(CcTest::isolate());
6245 i::ScopedVector<char> extension_name(32); 7015 i::ScopedVector<char> extension_name(32);
6246 i::SNPrintF(extension_name, "ext #%d", source_len); 7016 i::SNPrintF(extension_name, "ext #%d", source_len);
6247 v8::RegisterExtension(new Extension( 7017 v8::RegisterExtension(new Extension(
6248 extension_name.start(), kEmbeddedExtensionSource, 0, 0, source_len)); 7018 extension_name.start(), kEmbeddedExtensionSource, 0, 0, source_len));
6249 const char* extension_names[1] = {extension_name.start()}; 7019 const char* extension_names[1] = {extension_name.start()};
6250 v8::ExtensionConfiguration extensions(1, extension_names); 7020 v8::ExtensionConfiguration extensions(1, extension_names);
6251 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7021 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6252 if (source_len == kEmbeddedExtensionSourceValidLen) { 7022 if (source_len == kEmbeddedExtensionSourceValidLen) {
6253 Context::Scope lock(context); 7023 Context::Scope lock(context);
6254 v8::Handle<Value> result = CompileRun("Ret54321()"); 7024 v8::Local<Value> result = CompileRun("Ret54321()");
6255 CHECK(v8::Integer::New(CcTest::isolate(), 54321)->Equals(result)); 7025 CHECK(v8::Integer::New(CcTest::isolate(), 54321)
7026 ->Equals(context, result)
7027 .FromJust());
6256 } else { 7028 } else {
6257 // Anything but exactly the right length should fail to compile. 7029 // Anything but exactly the right length should fail to compile.
6258 CHECK(0 == *context); 7030 CHECK(0 == *context);
6259 } 7031 }
6260 } 7032 }
6261 } 7033 }
6262 7034
6263 7035
6264 static const char* kEvalExtensionSource1 = 7036 static const char* kEvalExtensionSource1 =
6265 "function UseEval1() {" 7037 "function UseEval1() {"
(...skipping 11 matching lines...) Expand all
6277 " this.UseEval2 = e;" 7049 " this.UseEval2 = e;"
6278 "})()"; 7050 "})()";
6279 7051
6280 7052
6281 TEST(UseEvalFromExtension) { 7053 TEST(UseEvalFromExtension) {
6282 v8::HandleScope handle_scope(CcTest::isolate()); 7054 v8::HandleScope handle_scope(CcTest::isolate());
6283 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1)); 7055 v8::RegisterExtension(new Extension("evaltest1", kEvalExtensionSource1));
6284 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2)); 7056 v8::RegisterExtension(new Extension("evaltest2", kEvalExtensionSource2));
6285 const char* extension_names[] = {"evaltest1", "evaltest2"}; 7057 const char* extension_names[] = {"evaltest1", "evaltest2"};
6286 v8::ExtensionConfiguration extensions(2, extension_names); 7058 v8::ExtensionConfiguration extensions(2, extension_names);
6287 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7059 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6288 Context::Scope lock(context); 7060 Context::Scope lock(context);
6289 v8::Handle<Value> result = CompileRun("UseEval1()"); 7061 v8::Local<Value> result = CompileRun("UseEval1()");
6290 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); 7062 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42))
7063 .FromJust());
6291 result = CompileRun("UseEval2()"); 7064 result = CompileRun("UseEval2()");
6292 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); 7065 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42))
7066 .FromJust());
6293 } 7067 }
6294 7068
6295 7069
6296 static const char* kWithExtensionSource1 = 7070 static const char* kWithExtensionSource1 =
6297 "function UseWith1() {" 7071 "function UseWith1() {"
6298 " var x = 42;" 7072 " var x = 42;"
6299 " with({x:87}) { return x; }" 7073 " with({x:87}) { return x; }"
6300 "}"; 7074 "}";
6301 7075
6302 7076
6303 static const char* kWithExtensionSource2 = 7077 static const char* kWithExtensionSource2 =
6304 "(function() {" 7078 "(function() {"
6305 " var x = 42;" 7079 " var x = 42;"
6306 " function e() {" 7080 " function e() {"
6307 " with ({x:87}) { return x; }" 7081 " with ({x:87}) { return x; }"
6308 " }" 7082 " }"
6309 " this.UseWith2 = e;" 7083 " this.UseWith2 = e;"
6310 "})()"; 7084 "})()";
6311 7085
6312 7086
6313 TEST(UseWithFromExtension) { 7087 TEST(UseWithFromExtension) {
6314 v8::HandleScope handle_scope(CcTest::isolate()); 7088 v8::HandleScope handle_scope(CcTest::isolate());
6315 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1)); 7089 v8::RegisterExtension(new Extension("withtest1", kWithExtensionSource1));
6316 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2)); 7090 v8::RegisterExtension(new Extension("withtest2", kWithExtensionSource2));
6317 const char* extension_names[] = {"withtest1", "withtest2"}; 7091 const char* extension_names[] = {"withtest1", "withtest2"};
6318 v8::ExtensionConfiguration extensions(2, extension_names); 7092 v8::ExtensionConfiguration extensions(2, extension_names);
6319 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7093 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6320 Context::Scope lock(context); 7094 Context::Scope lock(context);
6321 v8::Handle<Value> result = CompileRun("UseWith1()"); 7095 v8::Local<Value> result = CompileRun("UseWith1()");
6322 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 87))); 7096 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 87))
7097 .FromJust());
6323 result = CompileRun("UseWith2()"); 7098 result = CompileRun("UseWith2()");
6324 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 87))); 7099 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 87))
7100 .FromJust());
6325 } 7101 }
6326 7102
6327 7103
6328 TEST(AutoExtensions) { 7104 TEST(AutoExtensions) {
6329 v8::HandleScope handle_scope(CcTest::isolate()); 7105 v8::HandleScope handle_scope(CcTest::isolate());
6330 Extension* extension = new Extension("autotest", kSimpleExtensionSource); 7106 Extension* extension = new Extension("autotest", kSimpleExtensionSource);
6331 extension->set_auto_enable(true); 7107 extension->set_auto_enable(true);
6332 v8::RegisterExtension(extension); 7108 v8::RegisterExtension(extension);
6333 v8::Handle<Context> context = Context::New(CcTest::isolate()); 7109 v8::Local<Context> context = Context::New(CcTest::isolate());
6334 Context::Scope lock(context); 7110 Context::Scope lock(context);
6335 v8::Handle<Value> result = CompileRun("Foo()"); 7111 v8::Local<Value> result = CompileRun("Foo()");
6336 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 4))); 7112 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 4))
7113 .FromJust());
6337 } 7114 }
6338 7115
6339 7116
6340 static const char* kSyntaxErrorInExtensionSource = "["; 7117 static const char* kSyntaxErrorInExtensionSource = "[";
6341 7118
6342 7119
6343 // Test that a syntax error in an extension does not cause a fatal 7120 // Test that a syntax error in an extension does not cause a fatal
6344 // error but results in an empty context. 7121 // error but results in an empty context.
6345 TEST(SyntaxErrorExtensions) { 7122 TEST(SyntaxErrorExtensions) {
6346 v8::HandleScope handle_scope(CcTest::isolate()); 7123 v8::HandleScope handle_scope(CcTest::isolate());
6347 v8::RegisterExtension( 7124 v8::RegisterExtension(
6348 new Extension("syntaxerror", kSyntaxErrorInExtensionSource)); 7125 new Extension("syntaxerror", kSyntaxErrorInExtensionSource));
6349 const char* extension_names[] = {"syntaxerror"}; 7126 const char* extension_names[] = {"syntaxerror"};
6350 v8::ExtensionConfiguration extensions(1, extension_names); 7127 v8::ExtensionConfiguration extensions(1, extension_names);
6351 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7128 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6352 CHECK(context.IsEmpty()); 7129 CHECK(context.IsEmpty());
6353 } 7130 }
6354 7131
6355 7132
6356 static const char* kExceptionInExtensionSource = "throw 42"; 7133 static const char* kExceptionInExtensionSource = "throw 42";
6357 7134
6358 7135
6359 // Test that an exception when installing an extension does not cause 7136 // Test that an exception when installing an extension does not cause
6360 // a fatal error but results in an empty context. 7137 // a fatal error but results in an empty context.
6361 TEST(ExceptionExtensions) { 7138 TEST(ExceptionExtensions) {
6362 v8::HandleScope handle_scope(CcTest::isolate()); 7139 v8::HandleScope handle_scope(CcTest::isolate());
6363 v8::RegisterExtension( 7140 v8::RegisterExtension(
6364 new Extension("exception", kExceptionInExtensionSource)); 7141 new Extension("exception", kExceptionInExtensionSource));
6365 const char* extension_names[] = {"exception"}; 7142 const char* extension_names[] = {"exception"};
6366 v8::ExtensionConfiguration extensions(1, extension_names); 7143 v8::ExtensionConfiguration extensions(1, extension_names);
6367 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7144 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6368 CHECK(context.IsEmpty()); 7145 CHECK(context.IsEmpty());
6369 } 7146 }
6370 7147
6371 7148
6372 static const char* kNativeCallInExtensionSource = 7149 static const char* kNativeCallInExtensionSource =
6373 "function call_runtime_last_index_of(x) {" 7150 "function call_runtime_last_index_of(x) {"
6374 " return %StringLastIndexOf(x, 'bob', 10);" 7151 " return %StringLastIndexOf(x, 'bob', 10);"
6375 "}"; 7152 "}";
6376 7153
6377 7154
6378 static const char* kNativeCallTest = 7155 static const char* kNativeCallTest =
6379 "call_runtime_last_index_of('bobbobboellebobboellebobbob');"; 7156 "call_runtime_last_index_of('bobbobboellebobboellebobbob');";
6380 7157
6381 // Test that a native runtime calls are supported in extensions. 7158 // Test that a native runtime calls are supported in extensions.
6382 TEST(NativeCallInExtensions) { 7159 TEST(NativeCallInExtensions) {
6383 v8::HandleScope handle_scope(CcTest::isolate()); 7160 v8::HandleScope handle_scope(CcTest::isolate());
6384 v8::RegisterExtension( 7161 v8::RegisterExtension(
6385 new Extension("nativecall", kNativeCallInExtensionSource)); 7162 new Extension("nativecall", kNativeCallInExtensionSource));
6386 const char* extension_names[] = {"nativecall"}; 7163 const char* extension_names[] = {"nativecall"};
6387 v8::ExtensionConfiguration extensions(1, extension_names); 7164 v8::ExtensionConfiguration extensions(1, extension_names);
6388 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7165 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6389 Context::Scope lock(context); 7166 Context::Scope lock(context);
6390 v8::Handle<Value> result = CompileRun(kNativeCallTest); 7167 v8::Local<Value> result = CompileRun(kNativeCallTest);
6391 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 3))); 7168 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 3))
7169 .FromJust());
6392 } 7170 }
6393 7171
6394 7172
6395 class NativeFunctionExtension : public Extension { 7173 class NativeFunctionExtension : public Extension {
6396 public: 7174 public:
6397 NativeFunctionExtension(const char* name, const char* source, 7175 NativeFunctionExtension(const char* name, const char* source,
6398 v8::FunctionCallback fun = &Echo) 7176 v8::FunctionCallback fun = &Echo)
6399 : Extension(name, source), function_(fun) {} 7177 : Extension(name, source), function_(fun) {}
6400 7178
6401 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( 7179 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
6402 v8::Isolate* isolate, v8::Handle<v8::String> name) { 7180 v8::Isolate* isolate, v8::Local<v8::String> name) {
6403 return v8::FunctionTemplate::New(isolate, function_); 7181 return v8::FunctionTemplate::New(isolate, function_);
6404 } 7182 }
6405 7183
6406 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { 7184 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) {
6407 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); 7185 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]);
6408 } 7186 }
6409 7187
6410 private: 7188 private:
6411 v8::FunctionCallback function_; 7189 v8::FunctionCallback function_;
6412 }; 7190 };
6413 7191
6414 7192
6415 TEST(NativeFunctionDeclaration) { 7193 TEST(NativeFunctionDeclaration) {
6416 v8::HandleScope handle_scope(CcTest::isolate()); 7194 v8::HandleScope handle_scope(CcTest::isolate());
6417 const char* name = "nativedecl"; 7195 const char* name = "nativedecl";
6418 v8::RegisterExtension( 7196 v8::RegisterExtension(
6419 new NativeFunctionExtension(name, "native function foo();")); 7197 new NativeFunctionExtension(name, "native function foo();"));
6420 const char* extension_names[] = {name}; 7198 const char* extension_names[] = {name};
6421 v8::ExtensionConfiguration extensions(1, extension_names); 7199 v8::ExtensionConfiguration extensions(1, extension_names);
6422 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7200 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6423 Context::Scope lock(context); 7201 Context::Scope lock(context);
6424 v8::Handle<Value> result = CompileRun("foo(42);"); 7202 v8::Local<Value> result = CompileRun("foo(42);");
6425 CHECK(result->Equals(v8::Integer::New(CcTest::isolate(), 42))); 7203 CHECK(result->Equals(context, v8::Integer::New(CcTest::isolate(), 42))
7204 .FromJust());
6426 } 7205 }
6427 7206
6428 7207
6429 TEST(NativeFunctionDeclarationError) { 7208 TEST(NativeFunctionDeclarationError) {
6430 v8::HandleScope handle_scope(CcTest::isolate()); 7209 v8::HandleScope handle_scope(CcTest::isolate());
6431 const char* name = "nativedeclerr"; 7210 const char* name = "nativedeclerr";
6432 // Syntax error in extension code. 7211 // Syntax error in extension code.
6433 v8::RegisterExtension( 7212 v8::RegisterExtension(
6434 new NativeFunctionExtension(name, "native\nfunction foo();")); 7213 new NativeFunctionExtension(name, "native\nfunction foo();"));
6435 const char* extension_names[] = {name}; 7214 const char* extension_names[] = {name};
6436 v8::ExtensionConfiguration extensions(1, extension_names); 7215 v8::ExtensionConfiguration extensions(1, extension_names);
6437 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7216 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6438 CHECK(context.IsEmpty()); 7217 CHECK(context.IsEmpty());
6439 } 7218 }
6440 7219
6441 7220
6442 TEST(NativeFunctionDeclarationErrorEscape) { 7221 TEST(NativeFunctionDeclarationErrorEscape) {
6443 v8::HandleScope handle_scope(CcTest::isolate()); 7222 v8::HandleScope handle_scope(CcTest::isolate());
6444 const char* name = "nativedeclerresc"; 7223 const char* name = "nativedeclerresc";
6445 // Syntax error in extension code - escape code in "native" means that 7224 // Syntax error in extension code - escape code in "native" means that
6446 // it's not treated as a keyword. 7225 // it's not treated as a keyword.
6447 v8::RegisterExtension( 7226 v8::RegisterExtension(
6448 new NativeFunctionExtension(name, "nativ\\u0065 function foo();")); 7227 new NativeFunctionExtension(name, "nativ\\u0065 function foo();"));
6449 const char* extension_names[] = {name}; 7228 const char* extension_names[] = {name};
6450 v8::ExtensionConfiguration extensions(1, extension_names); 7229 v8::ExtensionConfiguration extensions(1, extension_names);
6451 v8::Handle<Context> context = Context::New(CcTest::isolate(), &extensions); 7230 v8::Local<Context> context = Context::New(CcTest::isolate(), &extensions);
6452 CHECK(context.IsEmpty()); 7231 CHECK(context.IsEmpty());
6453 } 7232 }
6454 7233
6455 7234
6456 static void CheckDependencies(const char* name, const char* expected) { 7235 static void CheckDependencies(const char* name, const char* expected) {
6457 v8::HandleScope handle_scope(CcTest::isolate()); 7236 v8::HandleScope handle_scope(CcTest::isolate());
6458 v8::ExtensionConfiguration config(1, &name); 7237 v8::ExtensionConfiguration config(1, &name);
6459 LocalContext context(&config); 7238 LocalContext context(&config);
6460 CHECK(String::NewFromUtf8(CcTest::isolate(), expected) 7239 CHECK(
6461 ->Equals(context->Global()->Get(v8_str("loaded")))); 7240 v8_str(expected)
7241 ->Equals(context.local(), context->Global()
7242 ->Get(context.local(), v8_str("loaded"))
7243 .ToLocalChecked())
7244 .FromJust());
6462 } 7245 }
6463 7246
6464 7247
6465 /* 7248 /*
6466 * Configuration: 7249 * Configuration:
6467 * 7250 *
6468 * /-- B <--\ 7251 * /-- B <--\
6469 * A <- -- D <-- E 7252 * A <- -- D <-- E
6470 * \-- C <--/ 7253 * \-- C <--/
6471 */ 7254 */
6472 THREADED_TEST(ExtensionDependency) { 7255 THREADED_TEST(ExtensionDependency) {
6473 static const char* kEDeps[] = {"D"}; 7256 static const char* kEDeps[] = {"D"};
6474 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps)); 7257 v8::RegisterExtension(new Extension("E", "this.loaded += 'E';", 1, kEDeps));
6475 static const char* kDDeps[] = {"B", "C"}; 7258 static const char* kDDeps[] = {"B", "C"};
6476 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps)); 7259 v8::RegisterExtension(new Extension("D", "this.loaded += 'D';", 2, kDDeps));
6477 static const char* kBCDeps[] = {"A"}; 7260 static const char* kBCDeps[] = {"A"};
6478 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps)); 7261 v8::RegisterExtension(new Extension("B", "this.loaded += 'B';", 1, kBCDeps));
6479 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps)); 7262 v8::RegisterExtension(new Extension("C", "this.loaded += 'C';", 1, kBCDeps));
6480 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';")); 7263 v8::RegisterExtension(new Extension("A", "this.loaded += 'A';"));
6481 CheckDependencies("A", "undefinedA"); 7264 CheckDependencies("A", "undefinedA");
6482 CheckDependencies("B", "undefinedAB"); 7265 CheckDependencies("B", "undefinedAB");
6483 CheckDependencies("C", "undefinedAC"); 7266 CheckDependencies("C", "undefinedAC");
6484 CheckDependencies("D", "undefinedABCD"); 7267 CheckDependencies("D", "undefinedABCD");
6485 CheckDependencies("E", "undefinedABCDE"); 7268 CheckDependencies("E", "undefinedABCDE");
6486 v8::HandleScope handle_scope(CcTest::isolate()); 7269 v8::HandleScope handle_scope(CcTest::isolate());
6487 static const char* exts[2] = {"C", "E"}; 7270 static const char* exts[2] = {"C", "E"};
6488 v8::ExtensionConfiguration config(2, exts); 7271 v8::ExtensionConfiguration config(2, exts);
6489 LocalContext context(&config); 7272 LocalContext context(&config);
6490 CHECK(v8_str("undefinedACBDE") 7273 CHECK(
6491 ->Equals(context->Global()->Get(v8_str("loaded")))); 7274 v8_str("undefinedACBDE")
7275 ->Equals(context.local(), context->Global()
7276 ->Get(context.local(), v8_str("loaded"))
7277 .ToLocalChecked())
7278 .FromJust());
6492 } 7279 }
6493 7280
6494 7281
6495 static const char* kExtensionTestScript = 7282 static const char* kExtensionTestScript =
6496 "native function A();" 7283 "native function A();"
6497 "native function B();" 7284 "native function B();"
6498 "native function C();" 7285 "native function C();"
6499 "function Foo(i) {" 7286 "function Foo(i) {"
6500 " if (i == 0) return A();" 7287 " if (i == 0) return A();"
6501 " if (i == 1) return B();" 7288 " if (i == 1) return B();"
6502 " if (i == 2) return C();" 7289 " if (i == 2) return C();"
6503 "}"; 7290 "}";
6504 7291
6505 7292
6506 static void CallFun(const v8::FunctionCallbackInfo<v8::Value>& args) { 7293 static void CallFun(const v8::FunctionCallbackInfo<v8::Value>& args) {
6507 ApiTestFuzzer::Fuzz(); 7294 ApiTestFuzzer::Fuzz();
6508 if (args.IsConstructCall()) { 7295 if (args.IsConstructCall()) {
6509 args.This()->Set(v8_str("data"), args.Data()); 7296 CHECK(args.This()
7297 ->Set(args.GetIsolate()->GetCurrentContext(), v8_str("data"),
7298 args.Data())
7299 .FromJust());
6510 args.GetReturnValue().SetNull(); 7300 args.GetReturnValue().SetNull();
6511 return; 7301 return;
6512 } 7302 }
6513 args.GetReturnValue().Set(args.Data()); 7303 args.GetReturnValue().Set(args.Data());
6514 } 7304 }
6515 7305
6516 7306
6517 class FunctionExtension : public Extension { 7307 class FunctionExtension : public Extension {
6518 public: 7308 public:
6519 FunctionExtension() : Extension("functiontest", kExtensionTestScript) {} 7309 FunctionExtension() : Extension("functiontest", kExtensionTestScript) {}
6520 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( 7310 virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
6521 v8::Isolate* isolate, v8::Handle<String> name); 7311 v8::Isolate* isolate, v8::Local<String> name);
6522 }; 7312 };
6523 7313
6524 7314
6525 static int lookup_count = 0; 7315 static int lookup_count = 0;
6526 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( 7316 v8::Local<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
6527 v8::Isolate* isolate, v8::Handle<String> name) { 7317 v8::Isolate* isolate, v8::Local<String> name) {
6528 lookup_count++; 7318 lookup_count++;
6529 if (name->Equals(v8_str("A"))) { 7319 if (name->Equals(isolate->GetCurrentContext(), v8_str("A")).FromJust()) {
6530 return v8::FunctionTemplate::New(isolate, CallFun, 7320 return v8::FunctionTemplate::New(isolate, CallFun,
6531 v8::Integer::New(isolate, 8)); 7321 v8::Integer::New(isolate, 8));
6532 } else if (name->Equals(v8_str("B"))) { 7322 } else if (name->Equals(isolate->GetCurrentContext(), v8_str("B"))
7323 .FromJust()) {
6533 return v8::FunctionTemplate::New(isolate, CallFun, 7324 return v8::FunctionTemplate::New(isolate, CallFun,
6534 v8::Integer::New(isolate, 7)); 7325 v8::Integer::New(isolate, 7));
6535 } else if (name->Equals(v8_str("C"))) { 7326 } else if (name->Equals(isolate->GetCurrentContext(), v8_str("C"))
7327 .FromJust()) {
6536 return v8::FunctionTemplate::New(isolate, CallFun, 7328 return v8::FunctionTemplate::New(isolate, CallFun,
6537 v8::Integer::New(isolate, 6)); 7329 v8::Integer::New(isolate, 6));
6538 } else { 7330 } else {
6539 return v8::Handle<v8::FunctionTemplate>(); 7331 return v8::Local<v8::FunctionTemplate>();
6540 } 7332 }
6541 } 7333 }
6542 7334
6543 7335
6544 THREADED_TEST(FunctionLookup) { 7336 THREADED_TEST(FunctionLookup) {
6545 v8::RegisterExtension(new FunctionExtension()); 7337 v8::RegisterExtension(new FunctionExtension());
6546 v8::HandleScope handle_scope(CcTest::isolate()); 7338 v8::HandleScope handle_scope(CcTest::isolate());
6547 static const char* exts[1] = {"functiontest"}; 7339 static const char* exts[1] = {"functiontest"};
6548 v8::ExtensionConfiguration config(1, exts); 7340 v8::ExtensionConfiguration config(1, exts);
6549 LocalContext context(&config); 7341 LocalContext context(&config);
6550 CHECK_EQ(3, lookup_count); 7342 CHECK_EQ(3, lookup_count);
6551 CHECK(v8::Integer::New(CcTest::isolate(), 8)->Equals(CompileRun("Foo(0)"))); 7343 CHECK(v8::Integer::New(CcTest::isolate(), 8)
6552 CHECK(v8::Integer::New(CcTest::isolate(), 7)->Equals(CompileRun("Foo(1)"))); 7344 ->Equals(context.local(), CompileRun("Foo(0)"))
6553 CHECK(v8::Integer::New(CcTest::isolate(), 6)->Equals(CompileRun("Foo(2)"))); 7345 .FromJust());
7346 CHECK(v8::Integer::New(CcTest::isolate(), 7)
7347 ->Equals(context.local(), CompileRun("Foo(1)"))
7348 .FromJust());
7349 CHECK(v8::Integer::New(CcTest::isolate(), 6)
7350 ->Equals(context.local(), CompileRun("Foo(2)"))
7351 .FromJust());
6554 } 7352 }
6555 7353
6556 7354
6557 THREADED_TEST(NativeFunctionConstructCall) { 7355 THREADED_TEST(NativeFunctionConstructCall) {
6558 v8::RegisterExtension(new FunctionExtension()); 7356 v8::RegisterExtension(new FunctionExtension());
6559 v8::HandleScope handle_scope(CcTest::isolate()); 7357 v8::HandleScope handle_scope(CcTest::isolate());
6560 static const char* exts[1] = {"functiontest"}; 7358 static const char* exts[1] = {"functiontest"};
6561 v8::ExtensionConfiguration config(1, exts); 7359 v8::ExtensionConfiguration config(1, exts);
6562 LocalContext context(&config); 7360 LocalContext context(&config);
6563 for (int i = 0; i < 10; i++) { 7361 for (int i = 0; i < 10; i++) {
6564 // Run a few times to ensure that allocation of objects doesn't 7362 // Run a few times to ensure that allocation of objects doesn't
6565 // change behavior of a constructor function. 7363 // change behavior of a constructor function.
6566 CHECK(v8::Integer::New(CcTest::isolate(), 8) 7364 CHECK(v8::Integer::New(CcTest::isolate(), 8)
6567 ->Equals(CompileRun("(new A()).data"))); 7365 ->Equals(context.local(), CompileRun("(new A()).data"))
7366 .FromJust());
6568 CHECK(v8::Integer::New(CcTest::isolate(), 7) 7367 CHECK(v8::Integer::New(CcTest::isolate(), 7)
6569 ->Equals(CompileRun("(new B()).data"))); 7368 ->Equals(context.local(), CompileRun("(new B()).data"))
7369 .FromJust());
6570 CHECK(v8::Integer::New(CcTest::isolate(), 6) 7370 CHECK(v8::Integer::New(CcTest::isolate(), 6)
6571 ->Equals(CompileRun("(new C()).data"))); 7371 ->Equals(context.local(), CompileRun("(new C()).data"))
7372 .FromJust());
6572 } 7373 }
6573 } 7374 }
6574 7375
6575 7376
6576 static const char* last_location; 7377 static const char* last_location;
6577 static const char* last_message; 7378 static const char* last_message;
6578 void StoringErrorCallback(const char* location, const char* message) { 7379 void StoringErrorCallback(const char* location, const char* message) {
6579 if (last_location == NULL) { 7380 if (last_location == NULL) {
6580 last_location = location; 7381 last_location = location;
6581 last_message = message; 7382 last_message = message;
6582 } 7383 }
6583 } 7384 }
6584 7385
6585 7386
6586 // ErrorReporting creates a circular extensions configuration and 7387 // ErrorReporting creates a circular extensions configuration and
6587 // tests that the fatal error handler gets called. This renders V8 7388 // tests that the fatal error handler gets called. This renders V8
6588 // unusable and therefore this test cannot be run in parallel. 7389 // unusable and therefore this test cannot be run in parallel.
6589 TEST(ErrorReporting) { 7390 TEST(ErrorReporting) {
6590 v8::V8::SetFatalErrorHandler(StoringErrorCallback); 7391 CcTest::isolate()->SetFatalErrorHandler(StoringErrorCallback);
6591 static const char* aDeps[] = {"B"}; 7392 static const char* aDeps[] = {"B"};
6592 v8::RegisterExtension(new Extension("A", "", 1, aDeps)); 7393 v8::RegisterExtension(new Extension("A", "", 1, aDeps));
6593 static const char* bDeps[] = {"A"}; 7394 static const char* bDeps[] = {"A"};
6594 v8::RegisterExtension(new Extension("B", "", 1, bDeps)); 7395 v8::RegisterExtension(new Extension("B", "", 1, bDeps));
6595 last_location = NULL; 7396 last_location = NULL;
6596 v8::ExtensionConfiguration config(1, bDeps); 7397 v8::ExtensionConfiguration config(1, bDeps);
6597 v8::Handle<Context> context = Context::New(CcTest::isolate(), &config); 7398 v8::Local<Context> context = Context::New(CcTest::isolate(), &config);
6598 CHECK(context.IsEmpty()); 7399 CHECK(context.IsEmpty());
6599 CHECK(last_location); 7400 CHECK(last_location);
6600 } 7401 }
6601 7402
6602 7403
6603 static void MissingScriptInfoMessageListener(v8::Handle<v8::Message> message, 7404 static void MissingScriptInfoMessageListener(v8::Local<v8::Message> message,
6604 v8::Handle<Value> data) { 7405 v8::Local<Value> data) {
7406 v8::Isolate* isolate = CcTest::isolate();
7407 Local<Context> context = isolate->GetCurrentContext();
6605 CHECK(message->GetScriptOrigin().ResourceName()->IsUndefined()); 7408 CHECK(message->GetScriptOrigin().ResourceName()->IsUndefined());
6606 CHECK(v8::Undefined(CcTest::isolate()) 7409 CHECK(v8::Undefined(isolate)
6607 ->Equals(message->GetScriptOrigin().ResourceName())); 7410 ->Equals(context, message->GetScriptOrigin().ResourceName())
6608 message->GetLineNumber(); 7411 .FromJust());
6609 message->GetSourceLine(); 7412 message->GetLineNumber(context).FromJust();
7413 message->GetSourceLine(context).ToLocalChecked();
6610 } 7414 }
6611 7415
6612 7416
6613 THREADED_TEST(ErrorWithMissingScriptInfo) { 7417 THREADED_TEST(ErrorWithMissingScriptInfo) {
6614 LocalContext context; 7418 LocalContext context;
6615 v8::HandleScope scope(context->GetIsolate()); 7419 v8::HandleScope scope(context->GetIsolate());
6616 v8::V8::AddMessageListener(MissingScriptInfoMessageListener); 7420 context->GetIsolate()->AddMessageListener(MissingScriptInfoMessageListener);
6617 CompileRun("throw Error()"); 7421 CompileRun("throw Error()");
6618 v8::V8::RemoveMessageListeners(MissingScriptInfoMessageListener); 7422 context->GetIsolate()->RemoveMessageListeners(
7423 MissingScriptInfoMessageListener);
6619 } 7424 }
6620 7425
6621 7426
6622 struct FlagAndPersistent { 7427 struct FlagAndPersistent {
6623 bool flag; 7428 bool flag;
6624 v8::Global<v8::Object> handle; 7429 v8::Global<v8::Object> handle;
6625 }; 7430 };
6626 7431
6627 7432
6628 static void SetFlag(const v8::WeakCallbackInfo<FlagAndPersistent>& data) { 7433 static void SetFlag(const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
6629 data.GetParameter()->flag = true; 7434 data.GetParameter()->flag = true;
6630 data.GetParameter()->handle.Reset(); 7435 data.GetParameter()->handle.Reset();
6631 } 7436 }
6632 7437
6633 7438
6634 static void IndependentWeakHandle(bool global_gc, bool interlinked) { 7439 static void IndependentWeakHandle(bool global_gc, bool interlinked) {
6635 v8::Isolate* iso = CcTest::isolate(); 7440 v8::Isolate* iso = CcTest::isolate();
6636 v8::HandleScope scope(iso); 7441 v8::HandleScope scope(iso);
6637 v8::Handle<Context> context = Context::New(iso); 7442 v8::Local<Context> context = Context::New(iso);
6638 Context::Scope context_scope(context); 7443 Context::Scope context_scope(context);
6639 7444
6640 FlagAndPersistent object_a, object_b; 7445 FlagAndPersistent object_a, object_b;
6641 7446
6642 intptr_t big_heap_size; 7447 intptr_t big_heap_size;
6643 7448
6644 { 7449 {
6645 v8::HandleScope handle_scope(iso); 7450 v8::HandleScope handle_scope(iso);
6646 Local<Object> a(v8::Object::New(iso)); 7451 Local<Object> a(v8::Object::New(iso));
6647 Local<Object> b(v8::Object::New(iso)); 7452 Local<Object> b(v8::Object::New(iso));
6648 object_a.handle.Reset(iso, a); 7453 object_a.handle.Reset(iso, a);
6649 object_b.handle.Reset(iso, b); 7454 object_b.handle.Reset(iso, b);
6650 if (interlinked) { 7455 if (interlinked) {
6651 a->Set(v8_str("x"), b); 7456 a->Set(context, v8_str("x"), b).FromJust();
6652 b->Set(v8_str("x"), a); 7457 b->Set(context, v8_str("x"), a).FromJust();
6653 } 7458 }
6654 if (global_gc) { 7459 if (global_gc) {
6655 CcTest::heap()->CollectAllGarbage(); 7460 CcTest::heap()->CollectAllGarbage();
6656 } else { 7461 } else {
6657 CcTest::heap()->CollectGarbage(i::NEW_SPACE); 7462 CcTest::heap()->CollectGarbage(i::NEW_SPACE);
6658 } 7463 }
6659 // We are relying on this creating a big flag array and reserving the space 7464 // We are relying on this creating a big flag array and reserving the space
6660 // up front. 7465 // up front.
6661 v8::Handle<Value> big_array = CompileRun("new Array(5000)"); 7466 v8::Local<Value> big_array = CompileRun("new Array(5000)");
6662 a->Set(v8_str("y"), big_array); 7467 a->Set(context, v8_str("y"), big_array).FromJust();
6663 big_heap_size = CcTest::heap()->SizeOfObjects(); 7468 big_heap_size = CcTest::heap()->SizeOfObjects();
6664 } 7469 }
6665 7470
6666 object_a.flag = false; 7471 object_a.flag = false;
6667 object_b.flag = false; 7472 object_b.flag = false;
6668 object_a.handle.SetWeak(&object_a, &SetFlag, 7473 object_a.handle.SetWeak(&object_a, &SetFlag,
6669 v8::WeakCallbackType::kParameter); 7474 v8::WeakCallbackType::kParameter);
6670 object_b.handle.SetWeak(&object_b, &SetFlag, 7475 object_b.handle.SetWeak(&object_b, &SetFlag,
6671 v8::WeakCallbackType::kParameter); 7476 v8::WeakCallbackType::kParameter);
6672 CHECK(!object_b.handle.IsIndependent()); 7477 CHECK(!object_b.handle.IsIndependent());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6719 private: 7524 private:
6720 int y_; 7525 int y_;
6721 int x_; 7526 int x_;
6722 }; 7527 };
6723 7528
6724 7529
6725 void CheckInternalFields( 7530 void CheckInternalFields(
6726 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) { 7531 const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
6727 v8::Persistent<v8::Object>* handle = data.GetParameter(); 7532 v8::Persistent<v8::Object>* handle = data.GetParameter();
6728 handle->Reset(); 7533 handle->Reset();
6729 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField1()); 7534 Trivial* t1 = reinterpret_cast<Trivial*>(data.GetInternalField(0));
6730 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField2()); 7535 Trivial2* t2 = reinterpret_cast<Trivial2*>(data.GetInternalField(1));
6731 CHECK_EQ(42, t1->x()); 7536 CHECK_EQ(42, t1->x());
6732 CHECK_EQ(103, t2->x()); 7537 CHECK_EQ(103, t2->x());
6733 t1->set_x(1729); 7538 t1->set_x(1729);
6734 t2->set_x(33550336); 7539 t2->set_x(33550336);
6735 } 7540 }
6736 7541
6737 7542
6738 void InternalFieldCallback(bool global_gc) { 7543 void InternalFieldCallback(bool global_gc) {
6739 LocalContext env; 7544 LocalContext env;
6740 v8::Isolate* isolate = env->GetIsolate(); 7545 v8::Isolate* isolate = env->GetIsolate();
6741 v8::HandleScope scope(isolate); 7546 v8::HandleScope scope(isolate);
6742 7547
6743 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 7548 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
6744 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 7549 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
6745 Trivial* t1; 7550 Trivial* t1;
6746 Trivial2* t2; 7551 Trivial2* t2;
6747 instance_templ->SetInternalFieldCount(2); 7552 instance_templ->SetInternalFieldCount(2);
6748 { 7553 {
6749 v8::HandleScope scope(isolate); 7554 v8::HandleScope scope(isolate);
6750 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 7555 Local<v8::Object> obj = templ->GetFunction(env.local())
7556 .ToLocalChecked()
7557 ->NewInstance(env.local())
7558 .ToLocalChecked();
6751 v8::Persistent<v8::Object> handle(isolate, obj); 7559 v8::Persistent<v8::Object> handle(isolate, obj);
6752 CHECK_EQ(2, obj->InternalFieldCount()); 7560 CHECK_EQ(2, obj->InternalFieldCount());
6753 CHECK(obj->GetInternalField(0)->IsUndefined()); 7561 CHECK(obj->GetInternalField(0)->IsUndefined());
6754 t1 = new Trivial(42); 7562 t1 = new Trivial(42);
6755 t2 = new Trivial2(103, 9); 7563 t2 = new Trivial2(103, 9);
6756 7564
6757 obj->SetAlignedPointerInInternalField(0, t1); 7565 obj->SetAlignedPointerInInternalField(0, t1);
6758 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0)); 7566 t1 = reinterpret_cast<Trivial*>(obj->GetAlignedPointerFromInternalField(0));
6759 CHECK_EQ(42, t1->x()); 7567 CHECK_EQ(42, t1->x());
6760 7568
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
6798 } 7606 }
6799 7607
6800 7608
6801 void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) { 7609 void v8::internal::HeapTester::ResetWeakHandle(bool global_gc) {
6802 using v8::Context; 7610 using v8::Context;
6803 using v8::Local; 7611 using v8::Local;
6804 using v8::Object; 7612 using v8::Object;
6805 7613
6806 v8::Isolate* iso = CcTest::isolate(); 7614 v8::Isolate* iso = CcTest::isolate();
6807 v8::HandleScope scope(iso); 7615 v8::HandleScope scope(iso);
6808 v8::Handle<Context> context = Context::New(iso); 7616 v8::Local<Context> context = Context::New(iso);
6809 Context::Scope context_scope(context); 7617 Context::Scope context_scope(context);
6810 7618
6811 FlagAndPersistent object_a, object_b; 7619 FlagAndPersistent object_a, object_b;
6812 7620
6813 { 7621 {
6814 v8::HandleScope handle_scope(iso); 7622 v8::HandleScope handle_scope(iso);
6815 Local<Object> a(v8::Object::New(iso)); 7623 Local<Object> a(v8::Object::New(iso));
6816 Local<Object> b(v8::Object::New(iso)); 7624 Local<Object> b(v8::Object::New(iso));
6817 object_a.handle.Reset(iso, a); 7625 object_a.handle.Reset(iso, a);
6818 object_b.handle.Reset(iso, b); 7626 object_b.handle.Reset(iso, b);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
6879 const v8::WeakCallbackInfo<FlagAndPersistent>& data) { 7687 const v8::WeakCallbackInfo<FlagAndPersistent>& data) {
6880 data.GetParameter()->handle.Reset(); 7688 data.GetParameter()->handle.Reset();
6881 data.SetSecondPassCallback(ForceMarkSweep2); 7689 data.SetSecondPassCallback(ForceMarkSweep2);
6882 } 7690 }
6883 7691
6884 7692
6885 THREADED_TEST(GCFromWeakCallbacks) { 7693 THREADED_TEST(GCFromWeakCallbacks) {
6886 v8::Isolate* isolate = CcTest::isolate(); 7694 v8::Isolate* isolate = CcTest::isolate();
6887 v8::Locker locker(CcTest::isolate()); 7695 v8::Locker locker(CcTest::isolate());
6888 v8::HandleScope scope(isolate); 7696 v8::HandleScope scope(isolate);
6889 v8::Handle<Context> context = Context::New(isolate); 7697 v8::Local<Context> context = Context::New(isolate);
6890 Context::Scope context_scope(context); 7698 Context::Scope context_scope(context);
6891 7699
6892 static const int kNumberOfGCTypes = 2; 7700 static const int kNumberOfGCTypes = 2;
6893 typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback; 7701 typedef v8::WeakCallbackInfo<FlagAndPersistent>::Callback Callback;
6894 Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1, 7702 Callback gc_forcing_callback[kNumberOfGCTypes] = {&ForceScavenge1,
6895 &ForceMarkSweep1}; 7703 &ForceMarkSweep1};
6896 7704
6897 typedef void (*GCInvoker)(); 7705 typedef void (*GCInvoker)();
6898 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep}; 7706 GCInvoker invoke_gc[kNumberOfGCTypes] = {&InvokeScavenge, &InvokeMarkSweep};
6899 7707
6900 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) { 7708 for (int outer_gc = 0; outer_gc < kNumberOfGCTypes; outer_gc++) {
6901 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) { 7709 for (int inner_gc = 0; inner_gc < kNumberOfGCTypes; inner_gc++) {
6902 FlagAndPersistent object; 7710 FlagAndPersistent object;
6903 { 7711 {
6904 v8::HandleScope handle_scope(isolate); 7712 v8::HandleScope handle_scope(isolate);
6905 object.handle.Reset(isolate, v8::Object::New(isolate)); 7713 object.handle.Reset(isolate, v8::Object::New(isolate));
6906 } 7714 }
6907 object.flag = false; 7715 object.flag = false;
6908 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc], 7716 object.handle.SetWeak(&object, gc_forcing_callback[inner_gc],
6909 v8::WeakCallbackType::kParameter); 7717 v8::WeakCallbackType::kParameter);
6910 object.handle.MarkIndependent(); 7718 object.handle.MarkIndependent();
6911 invoke_gc[outer_gc](); 7719 invoke_gc[outer_gc]();
6912 EmptyMessageQueues(isolate); 7720 EmptyMessageQueues(isolate);
6913 CHECK(object.flag); 7721 CHECK(object.flag);
6914 } 7722 }
6915 } 7723 }
6916 } 7724 }
6917 7725
6918 7726
6919 v8::Handle<Function> args_fun; 7727 v8::Local<Function> args_fun;
6920 7728
6921 7729
6922 static void ArgumentsTestCallback( 7730 static void ArgumentsTestCallback(
6923 const v8::FunctionCallbackInfo<v8::Value>& args) { 7731 const v8::FunctionCallbackInfo<v8::Value>& args) {
6924 ApiTestFuzzer::Fuzz(); 7732 ApiTestFuzzer::Fuzz();
6925 v8::Isolate* isolate = args.GetIsolate(); 7733 v8::Isolate* isolate = args.GetIsolate();
6926 CHECK(args_fun->Equals(args.Callee())); 7734 Local<Context> context = isolate->GetCurrentContext();
7735 CHECK(args_fun->Equals(context, args.Callee()).FromJust());
6927 CHECK_EQ(3, args.Length()); 7736 CHECK_EQ(3, args.Length());
6928 CHECK(v8::Integer::New(isolate, 1)->Equals(args[0])); 7737 CHECK(v8::Integer::New(isolate, 1)->Equals(context, args[0]).FromJust());
6929 CHECK(v8::Integer::New(isolate, 2)->Equals(args[1])); 7738 CHECK(v8::Integer::New(isolate, 2)->Equals(context, args[1]).FromJust());
6930 CHECK(v8::Integer::New(isolate, 3)->Equals(args[2])); 7739 CHECK(v8::Integer::New(isolate, 3)->Equals(context, args[2]).FromJust());
6931 CHECK(v8::Undefined(isolate)->Equals(args[3])); 7740 CHECK(v8::Undefined(isolate)->Equals(context, args[3]).FromJust());
6932 v8::HandleScope scope(args.GetIsolate()); 7741 v8::HandleScope scope(args.GetIsolate());
6933 CcTest::heap()->CollectAllGarbage(); 7742 CcTest::heap()->CollectAllGarbage();
6934 } 7743 }
6935 7744
6936 7745
6937 THREADED_TEST(Arguments) { 7746 THREADED_TEST(Arguments) {
6938 v8::Isolate* isolate = CcTest::isolate(); 7747 v8::Isolate* isolate = CcTest::isolate();
6939 v8::HandleScope scope(isolate); 7748 v8::HandleScope scope(isolate);
6940 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(isolate); 7749 v8::Local<v8::ObjectTemplate> global = ObjectTemplate::New(isolate);
6941 global->Set(v8_str("f"), 7750 global->Set(v8_str("f"),
6942 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback)); 7751 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback));
6943 LocalContext context(NULL, global); 7752 LocalContext context(NULL, global);
6944 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 7753 args_fun = context->Global()
6945 v8_compile("f(1, 2, 3)")->Run(); 7754 ->Get(context.local(), v8_str("f"))
7755 .ToLocalChecked()
7756 .As<Function>();
7757 v8_compile("f(1, 2, 3)")->Run(context.local()).ToLocalChecked();
6946 } 7758 }
6947 7759
6948 7760
6949 static int p_getter_count; 7761 static int p_getter_count;
6950 static int p_getter_count2; 7762 static int p_getter_count2;
6951 7763
6952 7764
6953 static void PGetter(Local<String> name, 7765 static void PGetter(Local<Name> name,
6954 const v8::PropertyCallbackInfo<v8::Value>& info) { 7766 const v8::PropertyCallbackInfo<v8::Value>& info) {
6955 ApiTestFuzzer::Fuzz(); 7767 ApiTestFuzzer::Fuzz();
6956 p_getter_count++; 7768 p_getter_count++;
6957 v8::Handle<v8::Object> global = 7769 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
6958 info.GetIsolate()->GetCurrentContext()->Global(); 7770 v8::Local<v8::Object> global = context->Global();
6959 CHECK(info.Holder()->Equals(global->Get(v8_str("o1")))); 7771 CHECK(
6960 if (name->Equals(v8_str("p1"))) { 7772 info.Holder()
6961 CHECK(info.This()->Equals(global->Get(v8_str("o1")))); 7773 ->Equals(context, global->Get(context, v8_str("o1")).ToLocalChecked())
6962 } else if (name->Equals(v8_str("p2"))) { 7774 .FromJust());
6963 CHECK(info.This()->Equals(global->Get(v8_str("o2")))); 7775 if (name->Equals(context, v8_str("p1")).FromJust()) {
6964 } else if (name->Equals(v8_str("p3"))) { 7776 CHECK(info.This()
6965 CHECK(info.This()->Equals(global->Get(v8_str("o3")))); 7777 ->Equals(context,
6966 } else if (name->Equals(v8_str("p4"))) { 7778 global->Get(context, v8_str("o1")).ToLocalChecked())
6967 CHECK(info.This()->Equals(global->Get(v8_str("o4")))); 7779 .FromJust());
7780 } else if (name->Equals(context, v8_str("p2")).FromJust()) {
7781 CHECK(info.This()
7782 ->Equals(context,
7783 global->Get(context, v8_str("o2")).ToLocalChecked())
7784 .FromJust());
7785 } else if (name->Equals(context, v8_str("p3")).FromJust()) {
7786 CHECK(info.This()
7787 ->Equals(context,
7788 global->Get(context, v8_str("o3")).ToLocalChecked())
7789 .FromJust());
7790 } else if (name->Equals(context, v8_str("p4")).FromJust()) {
7791 CHECK(info.This()
7792 ->Equals(context,
7793 global->Get(context, v8_str("o4")).ToLocalChecked())
7794 .FromJust());
6968 } 7795 }
6969 } 7796 }
6970 7797
6971 7798
6972 static void RunHolderTest(v8::Handle<v8::ObjectTemplate> obj) { 7799 static void RunHolderTest(v8::Local<v8::ObjectTemplate> obj) {
6973 ApiTestFuzzer::Fuzz(); 7800 ApiTestFuzzer::Fuzz();
6974 LocalContext context; 7801 LocalContext context;
6975 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 7802 CHECK(context->Global()
7803 ->Set(context.local(), v8_str("o1"),
7804 obj->NewInstance(context.local()).ToLocalChecked())
7805 .FromJust());
6976 CompileRun( 7806 CompileRun(
6977 "o1.__proto__ = { };" 7807 "o1.__proto__ = { };"
6978 "var o2 = { __proto__: o1 };" 7808 "var o2 = { __proto__: o1 };"
6979 "var o3 = { __proto__: o2 };" 7809 "var o3 = { __proto__: o2 };"
6980 "var o4 = { __proto__: o3 };" 7810 "var o4 = { __proto__: o3 };"
6981 "for (var i = 0; i < 10; i++) o4.p4;" 7811 "for (var i = 0; i < 10; i++) o4.p4;"
6982 "for (var i = 0; i < 10; i++) o3.p3;" 7812 "for (var i = 0; i < 10; i++) o3.p3;"
6983 "for (var i = 0; i < 10; i++) o2.p2;" 7813 "for (var i = 0; i < 10; i++) o2.p2;"
6984 "for (var i = 0; i < 10; i++) o1.p1;"); 7814 "for (var i = 0; i < 10; i++) o1.p1;");
6985 } 7815 }
6986 7816
6987 7817
6988 static void PGetter2(Local<Name> name, 7818 static void PGetter2(Local<Name> name,
6989 const v8::PropertyCallbackInfo<v8::Value>& info) { 7819 const v8::PropertyCallbackInfo<v8::Value>& info) {
6990 ApiTestFuzzer::Fuzz(); 7820 ApiTestFuzzer::Fuzz();
6991 p_getter_count2++; 7821 p_getter_count2++;
6992 v8::Handle<v8::Object> global = 7822 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
6993 info.GetIsolate()->GetCurrentContext()->Global(); 7823 v8::Local<v8::Object> global = context->Global();
6994 CHECK(info.Holder()->Equals(global->Get(v8_str("o1")))); 7824 CHECK(
6995 if (name->Equals(v8_str("p1"))) { 7825 info.Holder()
6996 CHECK(info.This()->Equals(global->Get(v8_str("o1")))); 7826 ->Equals(context, global->Get(context, v8_str("o1")).ToLocalChecked())
6997 } else if (name->Equals(v8_str("p2"))) { 7827 .FromJust());
6998 CHECK(info.This()->Equals(global->Get(v8_str("o2")))); 7828 if (name->Equals(context, v8_str("p1")).FromJust()) {
6999 } else if (name->Equals(v8_str("p3"))) { 7829 CHECK(info.This()
7000 CHECK(info.This()->Equals(global->Get(v8_str("o3")))); 7830 ->Equals(context,
7001 } else if (name->Equals(v8_str("p4"))) { 7831 global->Get(context, v8_str("o1")).ToLocalChecked())
7002 CHECK(info.This()->Equals(global->Get(v8_str("o4")))); 7832 .FromJust());
7833 } else if (name->Equals(context, v8_str("p2")).FromJust()) {
7834 CHECK(info.This()
7835 ->Equals(context,
7836 global->Get(context, v8_str("o2")).ToLocalChecked())
7837 .FromJust());
7838 } else if (name->Equals(context, v8_str("p3")).FromJust()) {
7839 CHECK(info.This()
7840 ->Equals(context,
7841 global->Get(context, v8_str("o3")).ToLocalChecked())
7842 .FromJust());
7843 } else if (name->Equals(context, v8_str("p4")).FromJust()) {
7844 CHECK(info.This()
7845 ->Equals(context,
7846 global->Get(context, v8_str("o4")).ToLocalChecked())
7847 .FromJust());
7003 } 7848 }
7004 } 7849 }
7005 7850
7006 7851
7007 THREADED_TEST(GetterHolders) { 7852 THREADED_TEST(GetterHolders) {
7008 v8::Isolate* isolate = CcTest::isolate(); 7853 v8::Isolate* isolate = CcTest::isolate();
7009 v8::HandleScope scope(isolate); 7854 v8::HandleScope scope(isolate);
7010 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 7855 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7011 obj->SetAccessor(v8_str("p1"), PGetter); 7856 obj->SetAccessor(v8_str("p1"), PGetter);
7012 obj->SetAccessor(v8_str("p2"), PGetter); 7857 obj->SetAccessor(v8_str("p2"), PGetter);
7013 obj->SetAccessor(v8_str("p3"), PGetter); 7858 obj->SetAccessor(v8_str("p3"), PGetter);
7014 obj->SetAccessor(v8_str("p4"), PGetter); 7859 obj->SetAccessor(v8_str("p4"), PGetter);
7015 p_getter_count = 0; 7860 p_getter_count = 0;
7016 RunHolderTest(obj); 7861 RunHolderTest(obj);
7017 CHECK_EQ(40, p_getter_count); 7862 CHECK_EQ(40, p_getter_count);
7018 } 7863 }
7019 7864
7020 7865
7021 THREADED_TEST(PreInterceptorHolders) { 7866 THREADED_TEST(PreInterceptorHolders) {
7022 v8::Isolate* isolate = CcTest::isolate(); 7867 v8::Isolate* isolate = CcTest::isolate();
7023 v8::HandleScope scope(isolate); 7868 v8::HandleScope scope(isolate);
7024 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 7869 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7025 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(PGetter2)); 7870 obj->SetHandler(v8::NamedPropertyHandlerConfiguration(PGetter2));
7026 p_getter_count2 = 0; 7871 p_getter_count2 = 0;
7027 RunHolderTest(obj); 7872 RunHolderTest(obj);
7028 CHECK_EQ(40, p_getter_count2); 7873 CHECK_EQ(40, p_getter_count2);
7029 } 7874 }
7030 7875
7031 7876
7032 THREADED_TEST(ObjectInstantiation) { 7877 THREADED_TEST(ObjectInstantiation) {
7033 v8::Isolate* isolate = CcTest::isolate(); 7878 v8::Isolate* isolate = CcTest::isolate();
7034 v8::HandleScope scope(isolate); 7879 v8::HandleScope scope(isolate);
7035 v8::Handle<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate); 7880 v8::Local<v8::ObjectTemplate> templ = ObjectTemplate::New(isolate);
7036 templ->SetAccessor(v8_str("t"), PGetter2); 7881 templ->SetAccessor(v8_str("t"), PGetter2);
7037 LocalContext context; 7882 LocalContext context;
7038 context->Global()->Set(v8_str("o"), templ->NewInstance()); 7883 CHECK(context->Global()
7884 ->Set(context.local(), v8_str("o"),
7885 templ->NewInstance(context.local()).ToLocalChecked())
7886 .FromJust());
7039 for (int i = 0; i < 100; i++) { 7887 for (int i = 0; i < 100; i++) {
7040 v8::HandleScope inner_scope(CcTest::isolate()); 7888 v8::HandleScope inner_scope(CcTest::isolate());
7041 v8::Handle<v8::Object> obj = templ->NewInstance(); 7889 v8::Local<v8::Object> obj =
7042 CHECK(!obj->Equals(context->Global()->Get(v8_str("o")))); 7890 templ->NewInstance(context.local()).ToLocalChecked();
7043 context->Global()->Set(v8_str("o2"), obj); 7891 CHECK(!obj->Equals(context.local(), context->Global()
7044 v8::Handle<Value> value = 7892 ->Get(context.local(), v8_str("o"))
7045 CompileRun("o.__proto__ === o2.__proto__"); 7893 .ToLocalChecked())
7046 CHECK(v8::True(isolate)->Equals(value)); 7894 .FromJust());
7047 context->Global()->Set(v8_str("o"), obj); 7895 CHECK(
7896 context->Global()->Set(context.local(), v8_str("o2"), obj).FromJust());
7897 v8::Local<Value> value = CompileRun("o.__proto__ === o2.__proto__");
7898 CHECK(v8::True(isolate)->Equals(context.local(), value).FromJust());
7899 CHECK(context->Global()->Set(context.local(), v8_str("o"), obj).FromJust());
7048 } 7900 }
7049 } 7901 }
7050 7902
7051 7903
7052 static int StrCmp16(uint16_t* a, uint16_t* b) { 7904 static int StrCmp16(uint16_t* a, uint16_t* b) {
7053 while (true) { 7905 while (true) {
7054 if (*a == 0 && *b == 0) return 0; 7906 if (*a == 0 && *b == 0) return 0;
7055 if (*a != *b) return 0 + *a - *b; 7907 if (*a != *b) return 0 + *a - *b;
7056 a++; 7908 a++;
7057 b++; 7909 b++;
7058 } 7910 }
7059 } 7911 }
7060 7912
7061 7913
7062 static int StrNCmp16(uint16_t* a, uint16_t* b, int n) { 7914 static int StrNCmp16(uint16_t* a, uint16_t* b, int n) {
7063 while (true) { 7915 while (true) {
7064 if (n-- == 0) return 0; 7916 if (n-- == 0) return 0;
7065 if (*a == 0 && *b == 0) return 0; 7917 if (*a == 0 && *b == 0) return 0;
7066 if (*a != *b) return 0 + *a - *b; 7918 if (*a != *b) return 0 + *a - *b;
7067 a++; 7919 a++;
7068 b++; 7920 b++;
7069 } 7921 }
7070 } 7922 }
7071 7923
7072 7924
7073 int GetUtf8Length(Handle<String> str) { 7925 int GetUtf8Length(Local<String> str) {
7074 int len = str->Utf8Length(); 7926 int len = str->Utf8Length();
7075 if (len < 0) { 7927 if (len < 0) {
7076 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str)); 7928 i::Handle<i::String> istr(v8::Utils::OpenHandle(*str));
7077 i::String::Flatten(istr); 7929 i::String::Flatten(istr);
7078 len = str->Utf8Length(); 7930 len = str->Utf8Length();
7079 } 7931 }
7080 return len; 7932 return len;
7081 } 7933 }
7082 7934
7083 7935
7084 THREADED_TEST(StringWrite) { 7936 THREADED_TEST(StringWrite) {
7085 LocalContext context; 7937 LocalContext context;
7086 v8::HandleScope scope(context->GetIsolate()); 7938 v8::HandleScope scope(context->GetIsolate());
7087 v8::Handle<String> str = v8_str("abcde"); 7939 v8::Local<String> str = v8_str("abcde");
7088 // abc<Icelandic eth><Unicode snowman>. 7940 // abc<Icelandic eth><Unicode snowman>.
7089 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203"); 7941 v8::Local<String> str2 = v8_str("abc\303\260\342\230\203");
7090 v8::Handle<String> str3 = v8::String::NewFromUtf8( 7942 v8::Local<String> str3 =
7091 context->GetIsolate(), "abc\0def", v8::String::kNormalString, 7); 7943 v8::String::NewFromUtf8(context->GetIsolate(), "abc\0def",
7944 v8::NewStringType::kNormal, 7)
7945 .ToLocalChecked();
7092 // "ab" + lead surrogate + "cd" + trail surrogate + "ef" 7946 // "ab" + lead surrogate + "cd" + trail surrogate + "ef"
7093 uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 }; 7947 uint16_t orphans[8] = { 0x61, 0x62, 0xd800, 0x63, 0x64, 0xdc00, 0x65, 0x66 };
7094 v8::Handle<String> orphans_str = v8::String::NewFromTwoByte( 7948 v8::Local<String> orphans_str =
7095 context->GetIsolate(), orphans, v8::String::kNormalString, 8); 7949 v8::String::NewFromTwoByte(context->GetIsolate(), orphans,
7950 v8::NewStringType::kNormal, 8)
7951 .ToLocalChecked();
7096 // single lead surrogate 7952 // single lead surrogate
7097 uint16_t lead[1] = { 0xd800 }; 7953 uint16_t lead[1] = { 0xd800 };
7098 v8::Handle<String> lead_str = v8::String::NewFromTwoByte( 7954 v8::Local<String> lead_str =
7099 context->GetIsolate(), lead, v8::String::kNormalString, 1); 7955 v8::String::NewFromTwoByte(context->GetIsolate(), lead,
7956 v8::NewStringType::kNormal, 1)
7957 .ToLocalChecked();
7100 // single trail surrogate 7958 // single trail surrogate
7101 uint16_t trail[1] = { 0xdc00 }; 7959 uint16_t trail[1] = { 0xdc00 };
7102 v8::Handle<String> trail_str = v8::String::NewFromTwoByte( 7960 v8::Local<String> trail_str =
7103 context->GetIsolate(), trail, v8::String::kNormalString, 1); 7961 v8::String::NewFromTwoByte(context->GetIsolate(), trail,
7962 v8::NewStringType::kNormal, 1)
7963 .ToLocalChecked();
7104 // surrogate pair 7964 // surrogate pair
7105 uint16_t pair[2] = { 0xd800, 0xdc00 }; 7965 uint16_t pair[2] = { 0xd800, 0xdc00 };
7106 v8::Handle<String> pair_str = v8::String::NewFromTwoByte( 7966 v8::Local<String> pair_str =
7107 context->GetIsolate(), pair, v8::String::kNormalString, 2); 7967 v8::String::NewFromTwoByte(context->GetIsolate(), pair,
7968 v8::NewStringType::kNormal, 2)
7969 .ToLocalChecked();
7108 const int kStride = 4; // Must match stride in for loops in JS below. 7970 const int kStride = 4; // Must match stride in for loops in JS below.
7109 CompileRun( 7971 CompileRun(
7110 "var left = '';" 7972 "var left = '';"
7111 "for (var i = 0; i < 0xd800; i += 4) {" 7973 "for (var i = 0; i < 0xd800; i += 4) {"
7112 " left = left + String.fromCharCode(i);" 7974 " left = left + String.fromCharCode(i);"
7113 "}"); 7975 "}");
7114 CompileRun( 7976 CompileRun(
7115 "var right = '';" 7977 "var right = '';"
7116 "for (var i = 0; i < 0xd800; i += 4) {" 7978 "for (var i = 0; i < 0xd800; i += 4) {"
7117 " right = String.fromCharCode(i) + right;" 7979 " right = String.fromCharCode(i) + right;"
7118 "}"); 7980 "}");
7119 v8::Handle<v8::Object> global = context->Global(); 7981 v8::Local<v8::Object> global = context->Global();
7120 Handle<String> left_tree = global->Get(v8_str("left")).As<String>(); 7982 Local<String> left_tree = global->Get(context.local(), v8_str("left"))
7121 Handle<String> right_tree = global->Get(v8_str("right")).As<String>(); 7983 .ToLocalChecked()
7984 .As<String>();
7985 Local<String> right_tree = global->Get(context.local(), v8_str("right"))
7986 .ToLocalChecked()
7987 .As<String>();
7122 7988
7123 CHECK_EQ(5, str2->Length()); 7989 CHECK_EQ(5, str2->Length());
7124 CHECK_EQ(0xd800 / kStride, left_tree->Length()); 7990 CHECK_EQ(0xd800 / kStride, left_tree->Length());
7125 CHECK_EQ(0xd800 / kStride, right_tree->Length()); 7991 CHECK_EQ(0xd800 / kStride, right_tree->Length());
7126 7992
7127 char buf[100]; 7993 char buf[100];
7128 char utf8buf[0xd800 * 3]; 7994 char utf8buf[0xd800 * 3];
7129 uint16_t wbuf[100]; 7995 uint16_t wbuf[100];
7130 int len; 7996 int len;
7131 int charlen; 7997 int charlen;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
7387 CHECK_EQ(0, str->WriteUtf8(NULL, 0, 0, String::NO_NULL_TERMINATION)); 8253 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)); 8254 CHECK_EQ(0, str->Write(NULL, 0, 0, String::NO_NULL_TERMINATION));
7389 } 8255 }
7390 8256
7391 8257
7392 static void Utf16Helper( 8258 static void Utf16Helper(
7393 LocalContext& context, // NOLINT 8259 LocalContext& context, // NOLINT
7394 const char* name, 8260 const char* name,
7395 const char* lengths_name, 8261 const char* lengths_name,
7396 int len) { 8262 int len) {
7397 Local<v8::Array> a = 8263 Local<v8::Array> a = Local<v8::Array>::Cast(
7398 Local<v8::Array>::Cast(context->Global()->Get(v8_str(name))); 8264 context->Global()->Get(context.local(), v8_str(name)).ToLocalChecked());
7399 Local<v8::Array> alens = 8265 Local<v8::Array> alens =
7400 Local<v8::Array>::Cast(context->Global()->Get(v8_str(lengths_name))); 8266 Local<v8::Array>::Cast(context->Global()
8267 ->Get(context.local(), v8_str(lengths_name))
8268 .ToLocalChecked());
7401 for (int i = 0; i < len; i++) { 8269 for (int i = 0; i < len; i++) {
7402 Local<v8::String> string = 8270 Local<v8::String> string =
7403 Local<v8::String>::Cast(a->Get(i)); 8271 Local<v8::String>::Cast(a->Get(context.local(), i).ToLocalChecked());
7404 Local<v8::Number> expected_len = 8272 Local<v8::Number> expected_len = Local<v8::Number>::Cast(
7405 Local<v8::Number>::Cast(alens->Get(i)); 8273 alens->Get(context.local(), i).ToLocalChecked());
7406 int length = GetUtf8Length(string); 8274 int length = GetUtf8Length(string);
7407 CHECK_EQ(static_cast<int>(expected_len->Value()), length); 8275 CHECK_EQ(static_cast<int>(expected_len->Value()), length);
7408 } 8276 }
7409 } 8277 }
7410 8278
7411 8279
7412 THREADED_TEST(Utf16) { 8280 THREADED_TEST(Utf16) {
7413 LocalContext context; 8281 LocalContext context;
7414 v8::HandleScope scope(context->GetIsolate()); 8282 v8::HandleScope scope(context->GetIsolate());
7415 CompileRun( 8283 CompileRun(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
7451 // The 'm's that end with 0xd8.. are 1, 4 and 7 8319 // The 'm's that end with 0xd8.. are 1, 4 and 7
7452 " if ((m % 3) == 1 && n >= 6) utf -= 2;" 8320 " if ((m % 3) == 1 && n >= 6) utf -= 2;"
7453 " a2lens.push(utf);" 8321 " a2lens.push(utf);"
7454 " }" 8322 " }"
7455 "}"); 8323 "}");
7456 Utf16Helper(context, "a", "alens", 9); 8324 Utf16Helper(context, "a", "alens", 9);
7457 Utf16Helper(context, "a2", "a2lens", 81); 8325 Utf16Helper(context, "a2", "a2lens", 81);
7458 } 8326 }
7459 8327
7460 8328
7461 static bool SameSymbol(Handle<String> s1, Handle<String> s2) { 8329 static bool SameSymbol(Local<String> s1, Local<String> s2) {
7462 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1)); 8330 i::Handle<i::String> is1(v8::Utils::OpenHandle(*s1));
7463 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2)); 8331 i::Handle<i::String> is2(v8::Utils::OpenHandle(*s2));
7464 return *is1 == *is2; 8332 return *is1 == *is2;
7465 } 8333 }
7466 8334
7467 8335
7468 THREADED_TEST(Utf16Symbol) { 8336 THREADED_TEST(Utf16Symbol) {
7469 LocalContext context; 8337 LocalContext context;
7470 v8::HandleScope scope(context->GetIsolate()); 8338 v8::HandleScope scope(context->GetIsolate());
7471 8339
7472 Handle<String> symbol1 = v8::String::NewFromUtf8( 8340 Local<String> symbol1 =
7473 context->GetIsolate(), "abc", v8::String::kInternalizedString); 8341 v8::String::NewFromUtf8(context->GetIsolate(), "abc",
7474 Handle<String> symbol2 = v8::String::NewFromUtf8( 8342 v8::NewStringType::kInternalized)
7475 context->GetIsolate(), "abc", v8::String::kInternalizedString); 8343 .ToLocalChecked();
8344 Local<String> symbol2 =
8345 v8::String::NewFromUtf8(context->GetIsolate(), "abc",
8346 v8::NewStringType::kInternalized)
8347 .ToLocalChecked();
7476 CHECK(SameSymbol(symbol1, symbol2)); 8348 CHECK(SameSymbol(symbol1, symbol2));
7477 8349
7478 CompileRun( 8350 CompileRun(
7479 "var sym0 = 'benedictus';" 8351 "var sym0 = 'benedictus';"
7480 "var sym0b = 'S\303\270ren';" 8352 "var sym0b = 'S\303\270ren';"
7481 "var sym1 = '\355\240\201\355\260\207';" 8353 "var sym1 = '\355\240\201\355\260\207';"
7482 "var sym2 = '\360\220\220\210';" 8354 "var sym2 = '\360\220\220\210';"
7483 "var sym3 = 'x\355\240\201\355\260\207';" 8355 "var sym3 = 'x\355\240\201\355\260\207';"
7484 "var sym4 = 'x\360\220\220\210';" 8356 "var sym4 = 'x\360\220\220\210';"
7485 "if (sym1.length != 2) throw sym1;" 8357 "if (sym1.length != 2) throw sym1;"
7486 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);" 8358 "if (sym1.charCodeAt(1) != 0xdc07) throw sym1.charCodeAt(1);"
7487 "if (sym2.length != 2) throw sym2;" 8359 "if (sym2.length != 2) throw sym2;"
7488 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);" 8360 "if (sym2.charCodeAt(1) != 0xdc08) throw sym2.charCodeAt(2);"
7489 "if (sym3.length != 3) throw sym3;" 8361 "if (sym3.length != 3) throw sym3;"
7490 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);" 8362 "if (sym3.charCodeAt(2) != 0xdc07) throw sym1.charCodeAt(2);"
7491 "if (sym4.length != 3) throw sym4;" 8363 "if (sym4.length != 3) throw sym4;"
7492 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);"); 8364 "if (sym4.charCodeAt(2) != 0xdc08) throw sym2.charCodeAt(2);");
7493 Handle<String> sym0 = v8::String::NewFromUtf8( 8365 Local<String> sym0 =
7494 context->GetIsolate(), "benedictus", v8::String::kInternalizedString); 8366 v8::String::NewFromUtf8(context->GetIsolate(), "benedictus",
7495 Handle<String> sym0b = v8::String::NewFromUtf8( 8367 v8::NewStringType::kInternalized)
7496 context->GetIsolate(), "S\303\270ren", v8::String::kInternalizedString); 8368 .ToLocalChecked();
7497 Handle<String> sym1 = 8369 Local<String> sym0b =
8370 v8::String::NewFromUtf8(context->GetIsolate(), "S\303\270ren",
8371 v8::NewStringType::kInternalized)
8372 .ToLocalChecked();
8373 Local<String> sym1 =
7498 v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207", 8374 v8::String::NewFromUtf8(context->GetIsolate(), "\355\240\201\355\260\207",
7499 v8::String::kInternalizedString); 8375 v8::NewStringType::kInternalized)
7500 Handle<String> sym2 = 8376 .ToLocalChecked();
8377 Local<String> sym2 =
7501 v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210", 8378 v8::String::NewFromUtf8(context->GetIsolate(), "\360\220\220\210",
7502 v8::String::kInternalizedString); 8379 v8::NewStringType::kInternalized)
7503 Handle<String> sym3 = v8::String::NewFromUtf8( 8380 .ToLocalChecked();
7504 context->GetIsolate(), "x\355\240\201\355\260\207", 8381 Local<String> sym3 = v8::String::NewFromUtf8(context->GetIsolate(),
7505 v8::String::kInternalizedString); 8382 "x\355\240\201\355\260\207",
7506 Handle<String> sym4 = 8383 v8::NewStringType::kInternalized)
8384 .ToLocalChecked();
8385 Local<String> sym4 =
7507 v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210", 8386 v8::String::NewFromUtf8(context->GetIsolate(), "x\360\220\220\210",
7508 v8::String::kInternalizedString); 8387 v8::NewStringType::kInternalized)
8388 .ToLocalChecked();
7509 v8::Local<v8::Object> global = context->Global(); 8389 v8::Local<v8::Object> global = context->Global();
7510 Local<Value> s0 = global->Get(v8_str("sym0")); 8390 Local<Value> s0 =
7511 Local<Value> s0b = global->Get(v8_str("sym0b")); 8391 global->Get(context.local(), v8_str("sym0")).ToLocalChecked();
7512 Local<Value> s1 = global->Get(v8_str("sym1")); 8392 Local<Value> s0b =
7513 Local<Value> s2 = global->Get(v8_str("sym2")); 8393 global->Get(context.local(), v8_str("sym0b")).ToLocalChecked();
7514 Local<Value> s3 = global->Get(v8_str("sym3")); 8394 Local<Value> s1 =
7515 Local<Value> s4 = global->Get(v8_str("sym4")); 8395 global->Get(context.local(), v8_str("sym1")).ToLocalChecked();
7516 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); 8396 Local<Value> s2 =
7517 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); 8397 global->Get(context.local(), v8_str("sym2")).ToLocalChecked();
7518 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); 8398 Local<Value> s3 =
7519 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); 8399 global->Get(context.local(), v8_str("sym3")).ToLocalChecked();
7520 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); 8400 Local<Value> s4 =
7521 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); 8401 global->Get(context.local(), v8_str("sym4")).ToLocalChecked();
8402 CHECK(SameSymbol(sym0, Local<String>::Cast(s0)));
8403 CHECK(SameSymbol(sym0b, Local<String>::Cast(s0b)));
8404 CHECK(SameSymbol(sym1, Local<String>::Cast(s1)));
8405 CHECK(SameSymbol(sym2, Local<String>::Cast(s2)));
8406 CHECK(SameSymbol(sym3, Local<String>::Cast(s3)));
8407 CHECK(SameSymbol(sym4, Local<String>::Cast(s4)));
7522 } 8408 }
7523 8409
7524 8410
7525 THREADED_TEST(Utf16MissingTrailing) { 8411 THREADED_TEST(Utf16MissingTrailing) {
7526 LocalContext context; 8412 LocalContext context;
7527 v8::HandleScope scope(context->GetIsolate()); 8413 v8::HandleScope scope(context->GetIsolate());
7528 8414
7529 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` 8415 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow`
7530 int size = 1024 * 64; 8416 int size = 1024 * 64;
7531 uint8_t* buffer = new uint8_t[size]; 8417 uint8_t* buffer = new uint8_t[size];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7571 8457
7572 delete[] buffer; 8458 delete[] buffer;
7573 } 8459 }
7574 8460
7575 8461
7576 THREADED_TEST(ToArrayIndex) { 8462 THREADED_TEST(ToArrayIndex) {
7577 LocalContext context; 8463 LocalContext context;
7578 v8::Isolate* isolate = context->GetIsolate(); 8464 v8::Isolate* isolate = context->GetIsolate();
7579 v8::HandleScope scope(isolate); 8465 v8::HandleScope scope(isolate);
7580 8466
7581 v8::Handle<String> str = v8_str("42"); 8467 v8::Local<String> str = v8_str("42");
7582 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 8468 v8::MaybeLocal<v8::Uint32> index = str->ToArrayIndex(context.local());
7583 CHECK(!index.IsEmpty()); 8469 CHECK(!index.IsEmpty());
7584 CHECK_EQ(42.0, index->Uint32Value()); 8470 CHECK_EQ(42.0,
8471 index.ToLocalChecked()->Uint32Value(context.local()).FromJust());
7585 str = v8_str("42asdf"); 8472 str = v8_str("42asdf");
7586 index = str->ToArrayIndex(); 8473 index = str->ToArrayIndex(context.local());
7587 CHECK(index.IsEmpty()); 8474 CHECK(index.IsEmpty());
7588 str = v8_str("-42"); 8475 str = v8_str("-42");
7589 index = str->ToArrayIndex(); 8476 index = str->ToArrayIndex(context.local());
7590 CHECK(index.IsEmpty()); 8477 CHECK(index.IsEmpty());
7591 str = v8_str("4294967294"); 8478 str = v8_str("4294967294");
7592 index = str->ToArrayIndex(); 8479 index = str->ToArrayIndex(context.local());
7593 CHECK(!index.IsEmpty()); 8480 CHECK(!index.IsEmpty());
7594 CHECK_EQ(4294967294.0, index->Uint32Value()); 8481 CHECK_EQ(4294967294.0,
7595 v8::Handle<v8::Number> num = v8::Number::New(isolate, 1); 8482 index.ToLocalChecked()->Uint32Value(context.local()).FromJust());
7596 index = num->ToArrayIndex(); 8483 v8::Local<v8::Number> num = v8::Number::New(isolate, 1);
8484 index = num->ToArrayIndex(context.local());
7597 CHECK(!index.IsEmpty()); 8485 CHECK(!index.IsEmpty());
7598 CHECK_EQ(1.0, index->Uint32Value()); 8486 CHECK_EQ(1.0,
8487 index.ToLocalChecked()->Uint32Value(context.local()).FromJust());
7599 num = v8::Number::New(isolate, -1); 8488 num = v8::Number::New(isolate, -1);
7600 index = num->ToArrayIndex(); 8489 index = num->ToArrayIndex(context.local());
7601 CHECK(index.IsEmpty()); 8490 CHECK(index.IsEmpty());
7602 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 8491 v8::Local<v8::Object> obj = v8::Object::New(isolate);
7603 index = obj->ToArrayIndex(); 8492 index = obj->ToArrayIndex(context.local());
7604 CHECK(index.IsEmpty()); 8493 CHECK(index.IsEmpty());
7605 } 8494 }
7606 8495
7607 8496
7608 THREADED_TEST(ErrorConstruction) { 8497 THREADED_TEST(ErrorConstruction) {
7609 LocalContext context; 8498 LocalContext context;
7610 v8::HandleScope scope(context->GetIsolate()); 8499 v8::HandleScope scope(context->GetIsolate());
7611 8500
7612 v8::Handle<String> foo = v8_str("foo"); 8501 v8::Local<String> foo = v8_str("foo");
7613 v8::Handle<String> message = v8_str("message"); 8502 v8::Local<String> message = v8_str("message");
7614 v8::Handle<Value> range_error = v8::Exception::RangeError(foo); 8503 v8::Local<Value> range_error = v8::Exception::RangeError(foo);
7615 CHECK(range_error->IsObject()); 8504 CHECK(range_error->IsObject());
7616 CHECK(range_error.As<v8::Object>()->Get(message)->Equals(foo)); 8505 CHECK(range_error.As<v8::Object>()
7617 v8::Handle<Value> reference_error = v8::Exception::ReferenceError(foo); 8506 ->Get(context.local(), message)
8507 .ToLocalChecked()
8508 ->Equals(context.local(), foo)
8509 .FromJust());
8510 v8::Local<Value> reference_error = v8::Exception::ReferenceError(foo);
7618 CHECK(reference_error->IsObject()); 8511 CHECK(reference_error->IsObject());
7619 CHECK(reference_error.As<v8::Object>()->Get(message)->Equals(foo)); 8512 CHECK(reference_error.As<v8::Object>()
7620 v8::Handle<Value> syntax_error = v8::Exception::SyntaxError(foo); 8513 ->Get(context.local(), message)
8514 .ToLocalChecked()
8515 ->Equals(context.local(), foo)
8516 .FromJust());
8517 v8::Local<Value> syntax_error = v8::Exception::SyntaxError(foo);
7621 CHECK(syntax_error->IsObject()); 8518 CHECK(syntax_error->IsObject());
7622 CHECK(syntax_error.As<v8::Object>()->Get(message)->Equals(foo)); 8519 CHECK(syntax_error.As<v8::Object>()
7623 v8::Handle<Value> type_error = v8::Exception::TypeError(foo); 8520 ->Get(context.local(), message)
8521 .ToLocalChecked()
8522 ->Equals(context.local(), foo)
8523 .FromJust());
8524 v8::Local<Value> type_error = v8::Exception::TypeError(foo);
7624 CHECK(type_error->IsObject()); 8525 CHECK(type_error->IsObject());
7625 CHECK(type_error.As<v8::Object>()->Get(message)->Equals(foo)); 8526 CHECK(type_error.As<v8::Object>()
7626 v8::Handle<Value> error = v8::Exception::Error(foo); 8527 ->Get(context.local(), message)
8528 .ToLocalChecked()
8529 ->Equals(context.local(), foo)
8530 .FromJust());
8531 v8::Local<Value> error = v8::Exception::Error(foo);
7627 CHECK(error->IsObject()); 8532 CHECK(error->IsObject());
7628 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 8533 CHECK(error.As<v8::Object>()
8534 ->Get(context.local(), message)
8535 .ToLocalChecked()
8536 ->Equals(context.local(), foo)
8537 .FromJust());
7629 } 8538 }
7630 8539
7631 8540
7632 static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) { 8541 static void ThrowV8Exception(const v8::FunctionCallbackInfo<v8::Value>& info) {
7633 ApiTestFuzzer::Fuzz(); 8542 ApiTestFuzzer::Fuzz();
7634 v8::Handle<String> foo = v8_str("foo"); 8543 v8::Local<String> foo = v8_str("foo");
7635 v8::Handle<String> message = v8_str("message"); 8544 v8::Local<String> message = v8_str("message");
7636 v8::Handle<Value> error = v8::Exception::Error(foo); 8545 v8::Local<Value> error = v8::Exception::Error(foo);
7637 CHECK(error->IsObject()); 8546 CHECK(error->IsObject());
7638 CHECK(error.As<v8::Object>()->Get(message)->Equals(foo)); 8547 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
8548 CHECK(error.As<v8::Object>()
8549 ->Get(context, message)
8550 .ToLocalChecked()
8551 ->Equals(context, foo)
8552 .FromJust());
7639 info.GetIsolate()->ThrowException(error); 8553 info.GetIsolate()->ThrowException(error);
7640 info.GetReturnValue().SetUndefined(); 8554 info.GetReturnValue().SetUndefined();
7641 } 8555 }
7642 8556
7643 8557
7644 THREADED_TEST(ExceptionCreateMessage) { 8558 THREADED_TEST(ExceptionCreateMessage) {
7645 LocalContext context; 8559 LocalContext context;
7646 v8::HandleScope scope(context->GetIsolate()); 8560 v8::HandleScope scope(context->GetIsolate());
7647 v8::Handle<String> foo_str = v8_str("foo"); 8561 v8::Local<String> foo_str = v8_str("foo");
7648 v8::Handle<String> message_str = v8_str("message"); 8562 v8::Local<String> message_str = v8_str("message");
7649 8563
7650 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 8564 context->GetIsolate()->SetCaptureStackTraceForUncaughtExceptions(true);
7651 8565
7652 Local<v8::FunctionTemplate> fun = 8566 Local<v8::FunctionTemplate> fun =
7653 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception); 8567 v8::FunctionTemplate::New(context->GetIsolate(), ThrowV8Exception);
7654 v8::Local<v8::Object> global = context->Global(); 8568 v8::Local<v8::Object> global = context->Global();
7655 global->Set(v8_str("throwV8Exception"), fun->GetFunction()); 8569 CHECK(global->Set(context.local(), v8_str("throwV8Exception"),
8570 fun->GetFunction(context.local()).ToLocalChecked())
8571 .FromJust());
7656 8572
7657 TryCatch try_catch(context->GetIsolate()); 8573 TryCatch try_catch(context->GetIsolate());
7658 CompileRun( 8574 CompileRun(
7659 "function f1() {\n" 8575 "function f1() {\n"
7660 " throwV8Exception();\n" 8576 " throwV8Exception();\n"
7661 "};\n" 8577 "};\n"
7662 "f1();"); 8578 "f1();");
7663 CHECK(try_catch.HasCaught()); 8579 CHECK(try_catch.HasCaught());
7664 8580
7665 v8::Handle<v8::Value> error = try_catch.Exception(); 8581 v8::Local<v8::Value> error = try_catch.Exception();
7666 CHECK(error->IsObject()); 8582 CHECK(error->IsObject());
7667 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); 8583 CHECK(error.As<v8::Object>()
8584 ->Get(context.local(), message_str)
8585 .ToLocalChecked()
8586 ->Equals(context.local(), foo_str)
8587 .FromJust());
7668 8588
7669 v8::Handle<v8::Message> message = v8::Exception::CreateMessage(error); 8589 v8::Local<v8::Message> message = v8::Exception::CreateMessage(error);
7670 CHECK(!message.IsEmpty()); 8590 CHECK(!message.IsEmpty());
7671 CHECK_EQ(2, message->GetLineNumber()); 8591 CHECK_EQ(2, message->GetLineNumber(context.local()).FromJust());
7672 CHECK_EQ(2, message->GetStartColumn()); 8592 CHECK_EQ(2, message->GetStartColumn(context.local()).FromJust());
7673 8593
7674 v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); 8594 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
7675 CHECK(!stackTrace.IsEmpty()); 8595 CHECK(!stackTrace.IsEmpty());
7676 CHECK_EQ(2, stackTrace->GetFrameCount()); 8596 CHECK_EQ(2, stackTrace->GetFrameCount());
7677 8597
7678 stackTrace = v8::Exception::GetStackTrace(error); 8598 stackTrace = v8::Exception::GetStackTrace(error);
7679 CHECK(!stackTrace.IsEmpty()); 8599 CHECK(!stackTrace.IsEmpty());
7680 CHECK_EQ(2, stackTrace->GetFrameCount()); 8600 CHECK_EQ(2, stackTrace->GetFrameCount());
7681 8601
7682 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 8602 context->GetIsolate()->SetCaptureStackTraceForUncaughtExceptions(false);
7683 8603
7684 // Now check message location when SetCaptureStackTraceForUncaughtExceptions 8604 // Now check message location when SetCaptureStackTraceForUncaughtExceptions
7685 // is false. 8605 // is false.
7686 try_catch.Reset(); 8606 try_catch.Reset();
7687 8607
7688 CompileRun( 8608 CompileRun(
7689 "function f2() {\n" 8609 "function f2() {\n"
7690 " return throwV8Exception();\n" 8610 " return throwV8Exception();\n"
7691 "};\n" 8611 "};\n"
7692 "f2();"); 8612 "f2();");
7693 CHECK(try_catch.HasCaught()); 8613 CHECK(try_catch.HasCaught());
7694 8614
7695 error = try_catch.Exception(); 8615 error = try_catch.Exception();
7696 CHECK(error->IsObject()); 8616 CHECK(error->IsObject());
7697 CHECK(error.As<v8::Object>()->Get(message_str)->Equals(foo_str)); 8617 CHECK(error.As<v8::Object>()
8618 ->Get(context.local(), message_str)
8619 .ToLocalChecked()
8620 ->Equals(context.local(), foo_str)
8621 .FromJust());
7698 8622
7699 message = v8::Exception::CreateMessage(error); 8623 message = v8::Exception::CreateMessage(error);
7700 CHECK(!message.IsEmpty()); 8624 CHECK(!message.IsEmpty());
7701 CHECK_EQ(2, message->GetLineNumber()); 8625 CHECK_EQ(2, message->GetLineNumber(context.local()).FromJust());
7702 CHECK_EQ(9, message->GetStartColumn()); 8626 CHECK_EQ(9, message->GetStartColumn(context.local()).FromJust());
7703 8627
7704 // Should be empty stack trace. 8628 // Should be empty stack trace.
7705 stackTrace = message->GetStackTrace(); 8629 stackTrace = message->GetStackTrace();
7706 CHECK(stackTrace.IsEmpty()); 8630 CHECK(stackTrace.IsEmpty());
7707 CHECK(v8::Exception::GetStackTrace(error).IsEmpty()); 8631 CHECK(v8::Exception::GetStackTrace(error).IsEmpty());
7708 } 8632 }
7709 8633
7710 8634
7711 THREADED_TEST(ExceptionCreateMessageLength) { 8635 THREADED_TEST(ExceptionCreateMessageLength) {
7712 LocalContext context; 8636 LocalContext context;
(...skipping 15 matching lines...) Expand all
7728 const v8::PropertyCallbackInfo<v8::Value>& info) { 8652 const v8::PropertyCallbackInfo<v8::Value>& info) {
7729 ApiTestFuzzer::Fuzz(); 8653 ApiTestFuzzer::Fuzz();
7730 info.GetReturnValue().Set(v8_num(10)); 8654 info.GetReturnValue().Set(v8_num(10));
7731 } 8655 }
7732 8656
7733 8657
7734 static void YSetter(Local<String> name, 8658 static void YSetter(Local<String> name,
7735 Local<Value> value, 8659 Local<Value> value,
7736 const v8::PropertyCallbackInfo<void>& info) { 8660 const v8::PropertyCallbackInfo<void>& info) {
7737 Local<Object> this_obj = Local<Object>::Cast(info.This()); 8661 Local<Object> this_obj = Local<Object>::Cast(info.This());
7738 if (this_obj->Has(name)) this_obj->Delete(name); 8662 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
7739 this_obj->Set(name, value); 8663 if (this_obj->Has(context, name).FromJust())
8664 this_obj->Delete(context, name).FromJust();
8665 CHECK(this_obj->Set(context, name, value).FromJust());
7740 } 8666 }
7741 8667
7742 8668
7743 THREADED_TEST(DeleteAccessor) { 8669 THREADED_TEST(DeleteAccessor) {
7744 v8::Isolate* isolate = CcTest::isolate(); 8670 v8::Isolate* isolate = CcTest::isolate();
7745 v8::HandleScope scope(isolate); 8671 v8::HandleScope scope(isolate);
7746 v8::Handle<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate); 8672 v8::Local<v8::ObjectTemplate> obj = ObjectTemplate::New(isolate);
7747 obj->SetAccessor(v8_str("y"), YGetter, YSetter); 8673 obj->SetAccessor(v8_str("y"), YGetter, YSetter);
7748 LocalContext context; 8674 LocalContext context;
7749 v8::Handle<v8::Object> holder = obj->NewInstance(); 8675 v8::Local<v8::Object> holder =
7750 context->Global()->Set(v8_str("holder"), holder); 8676 obj->NewInstance(context.local()).ToLocalChecked();
7751 v8::Handle<Value> result = CompileRun( 8677 CHECK(context->Global()
7752 "holder.y = 11; holder.y = 12; holder.y"); 8678 ->Set(context.local(), v8_str("holder"), holder)
7753 CHECK_EQ(12u, result->Uint32Value()); 8679 .FromJust());
8680 v8::Local<Value> result =
8681 CompileRun("holder.y = 11; holder.y = 12; holder.y");
8682 CHECK_EQ(12u, result->Uint32Value(context.local()).FromJust());
7754 } 8683 }
7755 8684
7756 8685
7757 THREADED_TEST(TypeSwitch) { 8686 THREADED_TEST(TypeSwitch) {
7758 v8::Isolate* isolate = CcTest::isolate(); 8687 v8::Isolate* isolate = CcTest::isolate();
7759 v8::HandleScope scope(isolate); 8688 v8::HandleScope scope(isolate);
7760 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate); 8689 v8::Local<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate);
7761 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate); 8690 v8::Local<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate);
7762 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate); 8691 v8::Local<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate);
7763 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 8692 v8::Local<v8::FunctionTemplate> templs[3] = {templ1, templ2, templ3};
7764 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 8693 v8::Local<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
7765 LocalContext context; 8694 LocalContext context;
7766 v8::Handle<v8::Object> obj0 = v8::Object::New(isolate); 8695 v8::Local<v8::Object> obj0 = v8::Object::New(isolate);
7767 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 8696 v8::Local<v8::Object> obj1 = templ1->GetFunction(context.local())
7768 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 8697 .ToLocalChecked()
7769 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 8698 ->NewInstance(context.local())
8699 .ToLocalChecked();
8700 v8::Local<v8::Object> obj2 = templ2->GetFunction(context.local())
8701 .ToLocalChecked()
8702 ->NewInstance(context.local())
8703 .ToLocalChecked();
8704 v8::Local<v8::Object> obj3 = templ3->GetFunction(context.local())
8705 .ToLocalChecked()
8706 ->NewInstance(context.local())
8707 .ToLocalChecked();
7770 for (int i = 0; i < 10; i++) { 8708 for (int i = 0; i < 10; i++) {
7771 CHECK_EQ(0, type_switch->match(obj0)); 8709 CHECK_EQ(0, type_switch->match(obj0));
7772 CHECK_EQ(1, type_switch->match(obj1)); 8710 CHECK_EQ(1, type_switch->match(obj1));
7773 CHECK_EQ(2, type_switch->match(obj2)); 8711 CHECK_EQ(2, type_switch->match(obj2));
7774 CHECK_EQ(3, type_switch->match(obj3)); 8712 CHECK_EQ(3, type_switch->match(obj3));
7775 CHECK_EQ(3, type_switch->match(obj3)); 8713 CHECK_EQ(3, type_switch->match(obj3));
7776 CHECK_EQ(2, type_switch->match(obj2)); 8714 CHECK_EQ(2, type_switch->match(obj2));
7777 CHECK_EQ(1, type_switch->match(obj1)); 8715 CHECK_EQ(1, type_switch->match(obj1));
7778 CHECK_EQ(0, type_switch->match(obj0)); 8716 CHECK_EQ(0, type_switch->match(obj0));
7779 } 8717 }
7780 } 8718 }
7781 8719
7782 8720
7783 static int trouble_nesting = 0; 8721 static int trouble_nesting = 0;
7784 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 8722 static void TroubleCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
7785 ApiTestFuzzer::Fuzz(); 8723 ApiTestFuzzer::Fuzz();
7786 trouble_nesting++; 8724 trouble_nesting++;
7787 8725
7788 // Call a JS function that throws an uncaught exception. 8726 // Call a JS function that throws an uncaught exception.
7789 Local<v8::Object> arg_this = 8727 Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
7790 args.GetIsolate()->GetCurrentContext()->Global(); 8728 Local<v8::Object> arg_this = context->Global();
7791 Local<Value> trouble_callee = (trouble_nesting == 3) ? 8729 Local<Value> trouble_callee =
7792 arg_this->Get(v8_str("trouble_callee")) : 8730 (trouble_nesting == 3)
7793 arg_this->Get(v8_str("trouble_caller")); 8731 ? arg_this->Get(context, v8_str("trouble_callee")).ToLocalChecked()
8732 : arg_this->Get(context, v8_str("trouble_caller")).ToLocalChecked();
7794 CHECK(trouble_callee->IsFunction()); 8733 CHECK(trouble_callee->IsFunction());
7795 args.GetReturnValue().Set( 8734 args.GetReturnValue().Set(Function::Cast(*trouble_callee)
7796 Function::Cast(*trouble_callee)->Call(arg_this, 0, NULL)); 8735 ->Call(context, arg_this, 0, NULL)
8736 .FromMaybe(v8::Local<v8::Value>()));
7797 } 8737 }
7798 8738
7799 8739
7800 static int report_count = 0; 8740 static int report_count = 0;
7801 static void ApiUncaughtExceptionTestListener(v8::Handle<v8::Message>, 8741 static void ApiUncaughtExceptionTestListener(v8::Local<v8::Message>,
7802 v8::Handle<Value>) { 8742 v8::Local<Value>) {
7803 report_count++; 8743 report_count++;
7804 } 8744 }
7805 8745
7806 8746
7807 // Counts uncaught exceptions, but other tests running in parallel 8747 // Counts uncaught exceptions, but other tests running in parallel
7808 // also have uncaught exceptions. 8748 // also have uncaught exceptions.
7809 TEST(ApiUncaughtException) { 8749 TEST(ApiUncaughtException) {
7810 report_count = 0; 8750 report_count = 0;
7811 LocalContext env; 8751 LocalContext env;
7812 v8::Isolate* isolate = env->GetIsolate(); 8752 v8::Isolate* isolate = env->GetIsolate();
7813 v8::HandleScope scope(isolate); 8753 v8::HandleScope scope(isolate);
7814 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 8754 isolate->AddMessageListener(ApiUncaughtExceptionTestListener);
7815 8755
7816 Local<v8::FunctionTemplate> fun = 8756 Local<v8::FunctionTemplate> fun =
7817 v8::FunctionTemplate::New(isolate, TroubleCallback); 8757 v8::FunctionTemplate::New(isolate, TroubleCallback);
7818 v8::Local<v8::Object> global = env->Global(); 8758 v8::Local<v8::Object> global = env->Global();
7819 global->Set(v8_str("trouble"), fun->GetFunction()); 8759 CHECK(global->Set(env.local(), v8_str("trouble"),
8760 fun->GetFunction(env.local()).ToLocalChecked())
8761 .FromJust());
7820 8762
7821 CompileRun( 8763 CompileRun(
7822 "function trouble_callee() {" 8764 "function trouble_callee() {"
7823 " var x = null;" 8765 " var x = null;"
7824 " return x.foo;" 8766 " return x.foo;"
7825 "};" 8767 "};"
7826 "function trouble_caller() {" 8768 "function trouble_caller() {"
7827 " trouble();" 8769 " trouble();"
7828 "};"); 8770 "};");
7829 Local<Value> trouble = global->Get(v8_str("trouble")); 8771 Local<Value> trouble =
8772 global->Get(env.local(), v8_str("trouble")).ToLocalChecked();
7830 CHECK(trouble->IsFunction()); 8773 CHECK(trouble->IsFunction());
7831 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); 8774 Local<Value> trouble_callee =
8775 global->Get(env.local(), v8_str("trouble_callee")).ToLocalChecked();
7832 CHECK(trouble_callee->IsFunction()); 8776 CHECK(trouble_callee->IsFunction());
7833 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); 8777 Local<Value> trouble_caller =
8778 global->Get(env.local(), v8_str("trouble_caller")).ToLocalChecked();
7834 CHECK(trouble_caller->IsFunction()); 8779 CHECK(trouble_caller->IsFunction());
7835 Function::Cast(*trouble_caller)->Call(global, 0, NULL); 8780 Function::Cast(*trouble_caller)
8781 ->Call(env.local(), global, 0, NULL)
8782 .FromMaybe(v8::Local<v8::Value>());
7836 CHECK_EQ(1, report_count); 8783 CHECK_EQ(1, report_count);
7837 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); 8784 isolate->RemoveMessageListeners(ApiUncaughtExceptionTestListener);
7838 } 8785 }
7839 8786
7840 8787
7841 TEST(ApiUncaughtExceptionInObjectObserve) { 8788 TEST(ApiUncaughtExceptionInObjectObserve) {
7842 v8::internal::FLAG_stack_size = 150; 8789 v8::internal::FLAG_stack_size = 150;
7843 report_count = 0; 8790 report_count = 0;
7844 LocalContext env; 8791 LocalContext env;
7845 v8::Isolate* isolate = env->GetIsolate(); 8792 v8::Isolate* isolate = env->GetIsolate();
7846 v8::HandleScope scope(isolate); 8793 v8::HandleScope scope(isolate);
7847 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 8794 isolate->AddMessageListener(ApiUncaughtExceptionTestListener);
7848 CompileRun( 8795 CompileRun(
7849 "var obj = {};" 8796 "var obj = {};"
7850 "var observe_count = 0;" 8797 "var observe_count = 0;"
7851 "function observer1() { ++observe_count; };" 8798 "function observer1() { ++observe_count; };"
7852 "function observer2() { ++observe_count; };" 8799 "function observer2() { ++observe_count; };"
7853 "function observer_throws() { throw new Error(); };" 8800 "function observer_throws() { throw new Error(); };"
7854 "function stack_overflow() { return (function f(x) { f(x+1); })(0); };" 8801 "function stack_overflow() { return (function f(x) { f(x+1); })(0); };"
7855 "Object.observe(obj, observer_throws.bind());" 8802 "Object.observe(obj, observer_throws.bind());"
7856 "Object.observe(obj, observer1);" 8803 "Object.observe(obj, observer1);"
7857 "Object.observe(obj, stack_overflow);" 8804 "Object.observe(obj, stack_overflow);"
7858 "Object.observe(obj, observer2);" 8805 "Object.observe(obj, observer2);"
7859 "Object.observe(obj, observer_throws.bind());" 8806 "Object.observe(obj, observer_throws.bind());"
7860 "obj.foo = 'bar';"); 8807 "obj.foo = 'bar';");
7861 CHECK_EQ(3, report_count); 8808 CHECK_EQ(3, report_count);
7862 ExpectInt32("observe_count", 2); 8809 ExpectInt32("observe_count", 2);
7863 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); 8810 isolate->RemoveMessageListeners(ApiUncaughtExceptionTestListener);
7864 } 8811 }
7865 8812
7866 8813
7867 static const char* script_resource_name = "ExceptionInNativeScript.js"; 8814 static const char* script_resource_name = "ExceptionInNativeScript.js";
7868 static void ExceptionInNativeScriptTestListener(v8::Handle<v8::Message> message, 8815 static void ExceptionInNativeScriptTestListener(v8::Local<v8::Message> message,
7869 v8::Handle<Value>) { 8816 v8::Local<Value>) {
7870 v8::Handle<v8::Value> name_val = message->GetScriptOrigin().ResourceName(); 8817 v8::Local<v8::Value> name_val = message->GetScriptOrigin().ResourceName();
7871 CHECK(!name_val.IsEmpty() && name_val->IsString()); 8818 CHECK(!name_val.IsEmpty() && name_val->IsString());
7872 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); 8819 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName());
7873 CHECK_EQ(0, strcmp(script_resource_name, *name)); 8820 CHECK_EQ(0, strcmp(script_resource_name, *name));
7874 CHECK_EQ(3, message->GetLineNumber()); 8821 v8::Local<v8::Context> context =
7875 v8::String::Utf8Value source_line(message->GetSourceLine()); 8822 v8::Isolate::GetCurrent()->GetCurrentContext();
8823 CHECK_EQ(3, message->GetLineNumber(context).FromJust());
8824 v8::String::Utf8Value source_line(
8825 message->GetSourceLine(context).ToLocalChecked());
7876 CHECK_EQ(0, strcmp(" new o.foo();", *source_line)); 8826 CHECK_EQ(0, strcmp(" new o.foo();", *source_line));
7877 } 8827 }
7878 8828
7879 8829
7880 TEST(ExceptionInNativeScript) { 8830 TEST(ExceptionInNativeScript) {
7881 LocalContext env; 8831 LocalContext env;
7882 v8::Isolate* isolate = env->GetIsolate(); 8832 v8::Isolate* isolate = env->GetIsolate();
7883 v8::HandleScope scope(isolate); 8833 v8::HandleScope scope(isolate);
7884 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 8834 isolate->AddMessageListener(ExceptionInNativeScriptTestListener);
7885 8835
7886 Local<v8::FunctionTemplate> fun = 8836 Local<v8::FunctionTemplate> fun =
7887 v8::FunctionTemplate::New(isolate, TroubleCallback); 8837 v8::FunctionTemplate::New(isolate, TroubleCallback);
7888 v8::Local<v8::Object> global = env->Global(); 8838 v8::Local<v8::Object> global = env->Global();
7889 global->Set(v8_str("trouble"), fun->GetFunction()); 8839 CHECK(global->Set(env.local(), v8_str("trouble"),
8840 fun->GetFunction(env.local()).ToLocalChecked())
8841 .FromJust());
7890 8842
7891 CompileRunWithOrigin( 8843 CompileRunWithOrigin(
7892 "function trouble() {\n" 8844 "function trouble() {\n"
7893 " var o = {};\n" 8845 " var o = {};\n"
7894 " new o.foo();\n" 8846 " new o.foo();\n"
7895 "};", 8847 "};",
7896 script_resource_name); 8848 script_resource_name);
7897 Local<Value> trouble = global->Get(v8_str("trouble")); 8849 Local<Value> trouble =
8850 global->Get(env.local(), v8_str("trouble")).ToLocalChecked();
7898 CHECK(trouble->IsFunction()); 8851 CHECK(trouble->IsFunction());
7899 Function::Cast(*trouble)->Call(global, 0, NULL); 8852 CHECK(Function::Cast(*trouble)->Call(env.local(), global, 0, NULL).IsEmpty());
7900 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 8853 isolate->RemoveMessageListeners(ExceptionInNativeScriptTestListener);
7901 } 8854 }
7902 8855
7903 8856
7904 TEST(CompilationErrorUsingTryCatchHandler) { 8857 TEST(CompilationErrorUsingTryCatchHandler) {
7905 LocalContext env; 8858 LocalContext env;
7906 v8::HandleScope scope(env->GetIsolate()); 8859 v8::HandleScope scope(env->GetIsolate());
7907 v8::TryCatch try_catch(env->GetIsolate()); 8860 v8::TryCatch try_catch(env->GetIsolate());
7908 v8_compile("This doesn't &*&@#$&*^ compile."); 8861 v8_compile("This doesn't &*&@#$&*^ compile.");
7909 CHECK(*try_catch.Exception()); 8862 CHECK(*try_catch.Exception());
7910 CHECK(try_catch.HasCaught()); 8863 CHECK(try_catch.HasCaught());
(...skipping 17 matching lines...) Expand all
7928 CompileRun( 8881 CompileRun(
7929 "(function()" 8882 "(function()"
7930 " { try { throw ''; } finally { throw 0; }" 8883 " { try { throw ''; } finally { throw 0; }"
7931 "})()"); 8884 "})()");
7932 CHECK(try_catch.HasCaught()); 8885 CHECK(try_catch.HasCaught());
7933 } 8886 }
7934 8887
7935 8888
7936 void CEvaluate(const v8::FunctionCallbackInfo<v8::Value>& args) { 8889 void CEvaluate(const v8::FunctionCallbackInfo<v8::Value>& args) {
7937 v8::HandleScope scope(args.GetIsolate()); 8890 v8::HandleScope scope(args.GetIsolate());
7938 CompileRun(args[0]->ToString(args.GetIsolate())); 8891 CompileRun(args[0]
8892 ->ToString(args.GetIsolate()->GetCurrentContext())
8893 .ToLocalChecked());
7939 } 8894 }
7940 8895
7941 8896
7942 TEST(TryCatchFinallyStoresMessageUsingTryCatchHandler) { 8897 TEST(TryCatchFinallyStoresMessageUsingTryCatchHandler) {
7943 v8::Isolate* isolate = CcTest::isolate(); 8898 v8::Isolate* isolate = CcTest::isolate();
7944 v8::HandleScope scope(isolate); 8899 v8::HandleScope scope(isolate);
7945 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 8900 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
7946 templ->Set(v8_str("CEvaluate"), 8901 templ->Set(v8_str("CEvaluate"),
7947 v8::FunctionTemplate::New(isolate, CEvaluate)); 8902 v8::FunctionTemplate::New(isolate, CEvaluate));
7948 LocalContext context(0, templ); 8903 LocalContext context(0, templ);
(...skipping 22 matching lines...) Expand all
7971 // For use within the TestSecurityHandler() test. 8926 // For use within the TestSecurityHandler() test.
7972 static bool g_security_callback_result = false; 8927 static bool g_security_callback_result = false;
7973 static bool SecurityTestCallback(Local<v8::Context> accessing_context, 8928 static bool SecurityTestCallback(Local<v8::Context> accessing_context,
7974 Local<v8::Object> accessed_object) { 8929 Local<v8::Object> accessed_object) {
7975 printf("a\n"); 8930 printf("a\n");
7976 return g_security_callback_result; 8931 return g_security_callback_result;
7977 } 8932 }
7978 8933
7979 8934
7980 // SecurityHandler can't be run twice 8935 // SecurityHandler can't be run twice
7981 TEST(SecurityHandler) { 8936 TEST(SecurityHandler) {
vogelheim 2015/11/23 18:22:15 Here & below: I was having a really hard time with
7982 v8::Isolate* isolate = CcTest::isolate(); 8937 v8::Isolate* isolate = CcTest::isolate();
7983 v8::HandleScope scope0(isolate); 8938 v8::HandleScope scope0(isolate);
7984 v8::Handle<v8::ObjectTemplate> global_template = 8939 v8::Local<v8::ObjectTemplate> global_template =
7985 v8::ObjectTemplate::New(isolate); 8940 v8::ObjectTemplate::New(isolate);
7986 global_template->SetAccessCheckCallback(SecurityTestCallback); 8941 global_template->SetAccessCheckCallback(SecurityTestCallback);
7987 // Create an environment 8942 // Create an environment
7988 v8::Handle<Context> context0 = Context::New(isolate, NULL, global_template); 8943 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
7989 context0->Enter(); 8944 context0->Enter();
7990 8945
7991 v8::Handle<v8::Object> global0 = context0->Global(); 8946 v8::Local<v8::Object> global0 = context0->Global();
7992 v8::Handle<Script> script0 = v8_compile("foo = 111"); 8947 v8::Local<Script> script0 = v8_compile("foo = 111");
7993 script0->Run(); 8948 script0->Run(context0).ToLocalChecked();
7994 global0->Set(v8_str("0"), v8_num(999)); 8949 CHECK(global0->Set(context0, v8_str("0"), v8_num(999)).FromJust());
7995 v8::Handle<Value> foo0 = global0->Get(v8_str("foo")); 8950 v8::Local<Value> foo0 =
7996 CHECK_EQ(111, foo0->Int32Value()); 8951 global0->Get(context0, v8_str("foo")).ToLocalChecked();
7997 v8::Handle<Value> z0 = global0->Get(v8_str("0")); 8952 CHECK_EQ(111, foo0->Int32Value(context0).FromJust());
7998 CHECK_EQ(999, z0->Int32Value()); 8953 v8::Local<Value> z0 = global0->Get(context0, v8_str("0")).ToLocalChecked();
8954 CHECK_EQ(999, z0->Int32Value(context0).FromJust());
7999 8955
8000 // Create another environment, should fail security checks. 8956 // Create another environment, should fail security checks.
8001 v8::HandleScope scope1(isolate); 8957 v8::HandleScope scope1(isolate);
8002 8958
8003 v8::Handle<Context> context1 = 8959 v8::Local<Context> context1 = Context::New(isolate, NULL, global_template);
8004 Context::New(isolate, NULL, global_template);
8005 context1->Enter(); 8960 context1->Enter();
8006 8961
8007 v8::Handle<v8::Object> global1 = context1->Global(); 8962 v8::Local<v8::Object> global1 = context1->Global();
8008 global1->Set(v8_str("othercontext"), global0); 8963 global1->Set(context1, v8_str("othercontext"), global0).FromJust();
8009 // This set will fail the security check. 8964 // This set will fail the security check.
8010 v8::Handle<Script> script1 = 8965 v8::Local<Script> script1 =
8011 v8_compile("othercontext.foo = 222; othercontext[0] = 888;"); 8966 v8_compile("othercontext.foo = 222; othercontext[0] = 888;");
8012 script1->Run(); 8967 CHECK(script1->Run(context1).IsEmpty());
8013 g_security_callback_result = true; 8968 g_security_callback_result = true;
8014 // This read will pass the security check. 8969 // This read will pass the security check.
8015 v8::Handle<Value> foo1 = global0->Get(v8_str("foo")); 8970 v8::Local<Value> foo1 =
8016 CHECK_EQ(111, foo1->Int32Value()); 8971 global0->Get(context0, v8_str("foo")).ToLocalChecked();
jochen (gone - plz use gerrit) 2015/11/24 12:42:25 in line 8005/8960 context1 is entered, so we shoul
vogelheim 2015/11/26 10:57:32 Done.
8972 CHECK_EQ(111, foo1->Int32Value(context0).FromJust());
8017 // This read will pass the security check. 8973 // This read will pass the security check.
8018 v8::Handle<Value> z1 = global0->Get(v8_str("0")); 8974 v8::Local<Value> z1 = global0->Get(context0, v8_str("0")).ToLocalChecked();
8019 CHECK_EQ(999, z1->Int32Value()); 8975 CHECK_EQ(999, z1->Int32Value(context0).FromJust());
8020 8976
8021 // Create another environment, should pass security checks. 8977 // Create another environment, should pass security checks.
8022 { 8978 {
8023 v8::HandleScope scope2(isolate); 8979 v8::HandleScope scope2(isolate);
8024 LocalContext context2; 8980 LocalContext context2;
8025 v8::Handle<v8::Object> global2 = context2->Global(); 8981 v8::Local<v8::Object> global2 = context2->Global();
8026 global2->Set(v8_str("othercontext"), global0); 8982 CHECK(global2->Set(context2.local(), v8_str("othercontext"), global0)
8027 v8::Handle<Script> script2 = 8983 .FromJust());
8984 v8::Local<Script> script2 =
8028 v8_compile("othercontext.foo = 333; othercontext[0] = 888;"); 8985 v8_compile("othercontext.foo = 333; othercontext[0] = 888;");
8029 script2->Run(); 8986 script2->Run(context2.local()).ToLocalChecked();
8030 v8::Handle<Value> foo2 = global0->Get(v8_str("foo")); 8987 v8::Local<Value> foo2 =
8031 CHECK_EQ(333, foo2->Int32Value()); 8988 global0->Get(context2.local(), v8_str("foo")).ToLocalChecked();
8032 v8::Handle<Value> z2 = global0->Get(v8_str("0")); 8989 CHECK_EQ(333, foo2->Int32Value(context2.local()).FromJust());
8033 CHECK_EQ(888, z2->Int32Value()); 8990 v8::Local<Value> z2 =
8991 global0->Get(context2.local(), v8_str("0")).ToLocalChecked();
8992 CHECK_EQ(888, z2->Int32Value(context2.local()).FromJust());
8034 } 8993 }
8035 8994
8036 context1->Exit(); 8995 context1->Exit();
8037 context0->Exit(); 8996 context0->Exit();
8038 } 8997 }
8039 8998
8040 8999
8041 THREADED_TEST(SecurityChecks) { 9000 THREADED_TEST(SecurityChecks) {
8042 LocalContext env1; 9001 LocalContext env1;
8043 v8::HandleScope handle_scope(env1->GetIsolate()); 9002 v8::HandleScope handle_scope(env1->GetIsolate());
8044 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9003 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8045 9004
8046 Local<Value> foo = v8_str("foo"); 9005 Local<Value> foo = v8_str("foo");
8047 Local<Value> bar = v8_str("bar"); 9006 Local<Value> bar = v8_str("bar");
8048 9007
8049 // Set to the same domain. 9008 // Set to the same domain.
8050 env1->SetSecurityToken(foo); 9009 env1->SetSecurityToken(foo);
8051 9010
8052 // Create a function in env1. 9011 // Create a function in env1.
8053 CompileRun("spy=function(){return spy;}"); 9012 CompileRun("spy=function(){return spy;}");
8054 Local<Value> spy = env1->Global()->Get(v8_str("spy")); 9013 Local<Value> spy =
9014 env1->Global()->Get(env1.local(), v8_str("spy")).ToLocalChecked();
8055 CHECK(spy->IsFunction()); 9015 CHECK(spy->IsFunction());
8056 9016
8057 // Create another function accessing global objects. 9017 // Create another function accessing global objects.
8058 CompileRun("spy2=function(){return new this.Array();}"); 9018 CompileRun("spy2=function(){return new this.Array();}");
8059 Local<Value> spy2 = env1->Global()->Get(v8_str("spy2")); 9019 Local<Value> spy2 =
9020 env1->Global()->Get(env1.local(), v8_str("spy2")).ToLocalChecked();
8060 CHECK(spy2->IsFunction()); 9021 CHECK(spy2->IsFunction());
8061 9022
8062 // Switch to env2 in the same domain and invoke spy on env2. 9023 // Switch to env2 in the same domain and invoke spy on env2.
8063 { 9024 {
8064 env2->SetSecurityToken(foo); 9025 env2->SetSecurityToken(foo);
8065 // Enter env2 9026 // Enter env2
8066 Context::Scope scope_env2(env2); 9027 Context::Scope scope_env2(env2);
8067 Local<Value> result = Function::Cast(*spy)->Call(env2->Global(), 0, NULL); 9028 Local<Value> result = Function::Cast(*spy)
9029 ->Call(env2, env2->Global(), 0, NULL)
9030 .ToLocalChecked();
8068 CHECK(result->IsFunction()); 9031 CHECK(result->IsFunction());
8069 } 9032 }
8070 9033
8071 { 9034 {
8072 env2->SetSecurityToken(bar); 9035 env2->SetSecurityToken(bar);
8073 Context::Scope scope_env2(env2); 9036 Context::Scope scope_env2(env2);
8074 9037
8075 // Call cross_domain_call, it should throw an exception 9038 // Call cross_domain_call, it should throw an exception
8076 v8::TryCatch try_catch(env1->GetIsolate()); 9039 v8::TryCatch try_catch(env1->GetIsolate());
8077 Function::Cast(*spy2)->Call(env2->Global(), 0, NULL); 9040 CHECK(Function::Cast(*spy2)->Call(env2, env2->Global(), 0, NULL).IsEmpty());
8078 CHECK(try_catch.HasCaught()); 9041 CHECK(try_catch.HasCaught());
8079 } 9042 }
8080 } 9043 }
8081 9044
8082 9045
8083 // Regression test case for issue 1183439. 9046 // Regression test case for issue 1183439.
8084 THREADED_TEST(SecurityChecksForPrototypeChain) { 9047 THREADED_TEST(SecurityChecksForPrototypeChain) {
8085 LocalContext current; 9048 LocalContext current;
8086 v8::HandleScope scope(current->GetIsolate()); 9049 v8::HandleScope scope(current->GetIsolate());
8087 v8::Handle<Context> other = Context::New(current->GetIsolate()); 9050 v8::Local<Context> other = Context::New(current->GetIsolate());
8088 9051
8089 // Change context to be able to get to the Object function in the 9052 // Change context to be able to get to the Object function in the
8090 // other context without hitting the security checks. 9053 // other context without hitting the security checks.
8091 v8::Local<Value> other_object; 9054 v8::Local<Value> other_object;
8092 { Context::Scope scope(other); 9055 { Context::Scope scope(other);
8093 other_object = other->Global()->Get(v8_str("Object")); 9056 other_object =
8094 other->Global()->Set(v8_num(42), v8_num(87)); 9057 other->Global()->Get(other, v8_str("Object")).ToLocalChecked();
9058 CHECK(other->Global()->Set(other, v8_num(42), v8_num(87)).FromJust());
8095 } 9059 }
8096 9060
8097 current->Global()->Set(v8_str("other"), other->Global()); 9061 CHECK(current->Global()
8098 CHECK(v8_compile("other")->Run()->Equals(other->Global())); 9062 ->Set(current.local(), v8_str("other"), other->Global())
9063 .FromJust());
9064 CHECK(v8_compile("other")
9065 ->Run(current.local())
9066 .ToLocalChecked()
9067 ->Equals(current.local(), other->Global())
9068 .FromJust());
8099 9069
8100 // Make sure the security check fails here and we get an undefined 9070 // Make sure the security check fails here and we get an undefined
8101 // result instead of getting the Object function. Repeat in a loop 9071 // result instead of getting the Object function. Repeat in a loop
8102 // to make sure to exercise the IC code. 9072 // to make sure to exercise the IC code.
8103 v8::Local<Script> access_other0 = v8_compile("other.Object"); 9073 v8::Local<Script> access_other0 = v8_compile("other.Object");
8104 v8::Local<Script> access_other1 = v8_compile("other[42]"); 9074 v8::Local<Script> access_other1 = v8_compile("other[42]");
8105 for (int i = 0; i < 5; i++) { 9075 for (int i = 0; i < 5; i++) {
8106 CHECK(access_other0->Run().IsEmpty()); 9076 CHECK(access_other0->Run(current.local()).IsEmpty());
8107 CHECK(access_other1->Run().IsEmpty()); 9077 CHECK(access_other1->Run(current.local()).IsEmpty());
8108 } 9078 }
8109 9079
8110 // Create an object that has 'other' in its prototype chain and make 9080 // Create an object that has 'other' in its prototype chain and make
8111 // sure we cannot access the Object function indirectly through 9081 // sure we cannot access the Object function indirectly through
8112 // that. Repeat in a loop to make sure to exercise the IC code. 9082 // that. Repeat in a loop to make sure to exercise the IC code.
8113 v8_compile("function F() { };" 9083 v8_compile(
8114 "F.prototype = other;" 9084 "function F() { };"
8115 "var f = new F();")->Run(); 9085 "F.prototype = other;"
9086 "var f = new F();")
9087 ->Run(current.local())
9088 .ToLocalChecked();
8116 v8::Local<Script> access_f0 = v8_compile("f.Object"); 9089 v8::Local<Script> access_f0 = v8_compile("f.Object");
8117 v8::Local<Script> access_f1 = v8_compile("f[42]"); 9090 v8::Local<Script> access_f1 = v8_compile("f[42]");
8118 for (int j = 0; j < 5; j++) { 9091 for (int j = 0; j < 5; j++) {
8119 CHECK(access_f0->Run().IsEmpty()); 9092 CHECK(access_f0->Run(current.local()).IsEmpty());
8120 CHECK(access_f1->Run().IsEmpty()); 9093 CHECK(access_f1->Run(current.local()).IsEmpty());
8121 } 9094 }
8122 9095
8123 // Now it gets hairy: Set the prototype for the other global object 9096 // 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 9097 // to be the current global object. The prototype chain for 'f' now
8125 // goes through 'other' but ends up in the current global object. 9098 // goes through 'other' but ends up in the current global object.
8126 { Context::Scope scope(other); 9099 { Context::Scope scope(other);
8127 other->Global()->Set(v8_str("__proto__"), current->Global()); 9100 CHECK(other->Global()
9101 ->Set(other, v8_str("__proto__"), current->Global())
9102 .FromJust());
8128 } 9103 }
8129 // Set a named and an index property on the current global 9104 // Set a named and an index property on the current global
8130 // object. To force the lookup to go through the other global object, 9105 // object. To force the lookup to go through the other global object,
8131 // the properties must not exist in the other global object. 9106 // the properties must not exist in the other global object.
8132 current->Global()->Set(v8_str("foo"), v8_num(100)); 9107 CHECK(current->Global()
8133 current->Global()->Set(v8_num(99), v8_num(101)); 9108 ->Set(current.local(), v8_str("foo"), v8_num(100))
9109 .FromJust());
9110 CHECK(current->Global()
9111 ->Set(current.local(), v8_num(99), v8_num(101))
9112 .FromJust());
8134 // Try to read the properties from f and make sure that the access 9113 // 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. 9114 // gets stopped by the security checks on the other global object.
8136 Local<Script> access_f2 = v8_compile("f.foo"); 9115 Local<Script> access_f2 = v8_compile("f.foo");
8137 Local<Script> access_f3 = v8_compile("f[99]"); 9116 Local<Script> access_f3 = v8_compile("f[99]");
8138 for (int k = 0; k < 5; k++) { 9117 for (int k = 0; k < 5; k++) {
8139 CHECK(access_f2->Run().IsEmpty()); 9118 CHECK(access_f2->Run(current.local()).IsEmpty());
8140 CHECK(access_f3->Run().IsEmpty()); 9119 CHECK(access_f3->Run(current.local()).IsEmpty());
8141 } 9120 }
8142 } 9121 }
8143 9122
8144 9123
8145 static bool security_check_with_gc_called; 9124 static bool security_check_with_gc_called;
8146 9125
8147 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context, 9126 static bool SecurityTestCallbackWithGC(Local<v8::Context> accessing_context,
8148 Local<v8::Object> accessed_object) { 9127 Local<v8::Object> accessed_object) {
8149 CcTest::heap()->CollectAllGarbage(); 9128 CcTest::heap()->CollectAllGarbage();
8150 security_check_with_gc_called = true; 9129 security_check_with_gc_called = true;
8151 return true; 9130 return true;
8152 } 9131 }
8153 9132
8154 9133
8155 TEST(SecurityTestGCAllowed) { 9134 TEST(SecurityTestGCAllowed) {
8156 v8::Isolate* isolate = CcTest::isolate(); 9135 v8::Isolate* isolate = CcTest::isolate();
8157 v8::HandleScope handle_scope(isolate); 9136 v8::HandleScope handle_scope(isolate);
8158 v8::Handle<v8::ObjectTemplate> object_template = 9137 v8::Local<v8::ObjectTemplate> object_template =
8159 v8::ObjectTemplate::New(isolate); 9138 v8::ObjectTemplate::New(isolate);
8160 object_template->SetAccessCheckCallback(SecurityTestCallbackWithGC); 9139 object_template->SetAccessCheckCallback(SecurityTestCallbackWithGC);
8161 9140
8162 v8::Handle<Context> context = Context::New(isolate); 9141 v8::Local<Context> context = Context::New(isolate);
8163 v8::Context::Scope context_scope(context); 9142 v8::Context::Scope context_scope(context);
8164 9143
8165 context->Global()->Set(v8_str("obj"), object_template->NewInstance()); 9144 CHECK(context->Global()
9145 ->Set(context, v8_str("obj"),
9146 object_template->NewInstance(context).ToLocalChecked())
9147 .FromJust());
8166 9148
8167 security_check_with_gc_called = false; 9149 security_check_with_gc_called = false;
8168 CompileRun("obj[0] = new String(1002);"); 9150 CompileRun("obj[0] = new String(1002);");
8169 CHECK(security_check_with_gc_called); 9151 CHECK(security_check_with_gc_called);
8170 9152
8171 security_check_with_gc_called = false; 9153 security_check_with_gc_called = false;
8172 CHECK(CompileRun("obj[0]")->ToString(isolate)->Equals(v8_str("1002"))); 9154 CHECK(CompileRun("obj[0]")
9155 ->ToString(context)
9156 .ToLocalChecked()
9157 ->Equals(context, v8_str("1002"))
9158 .FromJust());
8173 CHECK(security_check_with_gc_called); 9159 CHECK(security_check_with_gc_called);
8174 } 9160 }
8175 9161
8176 9162
8177 THREADED_TEST(CrossDomainDelete) { 9163 THREADED_TEST(CrossDomainDelete) {
8178 LocalContext env1; 9164 LocalContext env1;
8179 v8::HandleScope handle_scope(env1->GetIsolate()); 9165 v8::HandleScope handle_scope(env1->GetIsolate());
8180 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9166 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8181 9167
8182 Local<Value> foo = v8_str("foo"); 9168 Local<Value> foo = v8_str("foo");
8183 Local<Value> bar = v8_str("bar"); 9169 Local<Value> bar = v8_str("bar");
8184 9170
8185 // Set to the same domain. 9171 // Set to the same domain.
8186 env1->SetSecurityToken(foo); 9172 env1->SetSecurityToken(foo);
8187 env2->SetSecurityToken(foo); 9173 env2->SetSecurityToken(foo);
8188 9174
8189 env1->Global()->Set(v8_str("prop"), v8_num(3)); 9175 CHECK(env1->Global()->Set(env2, v8_str("prop"), v8_num(3)).FromJust());
8190 env2->Global()->Set(v8_str("env1"), env1->Global()); 9176 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust());
8191 9177
8192 // Change env2 to a different domain and delete env1.prop. 9178 // Change env2 to a different domain and delete env1.prop.
8193 env2->SetSecurityToken(bar); 9179 env2->SetSecurityToken(bar);
8194 { 9180 {
8195 Context::Scope scope_env2(env2); 9181 Context::Scope scope_env2(env2);
8196 Local<Value> result = 9182 Local<Value> result =
8197 CompileRun("delete env1.prop"); 9183 CompileRun("delete env1.prop");
8198 CHECK(result.IsEmpty()); 9184 CHECK(result.IsEmpty());
8199 } 9185 }
8200 9186
8201 // Check that env1.prop still exists. 9187 // Check that env1.prop still exists.
8202 Local<Value> v = env1->Global()->Get(v8_str("prop")); 9188 Local<Value> v =
9189 env1->Global()->Get(env1.local(), v8_str("prop")).ToLocalChecked();
8203 CHECK(v->IsNumber()); 9190 CHECK(v->IsNumber());
8204 CHECK_EQ(3, v->Int32Value()); 9191 CHECK_EQ(3, v->Int32Value(env1.local()).FromJust());
8205 } 9192 }
8206 9193
8207 9194
8208 THREADED_TEST(CrossDomainIsPropertyEnumerable) { 9195 THREADED_TEST(CrossDomainIsPropertyEnumerable) {
8209 LocalContext env1; 9196 LocalContext env1;
8210 v8::HandleScope handle_scope(env1->GetIsolate()); 9197 v8::HandleScope handle_scope(env1->GetIsolate());
8211 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9198 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8212 9199
8213 Local<Value> foo = v8_str("foo"); 9200 Local<Value> foo = v8_str("foo");
8214 Local<Value> bar = v8_str("bar"); 9201 Local<Value> bar = v8_str("bar");
8215 9202
8216 // Set to the same domain. 9203 // Set to the same domain.
8217 env1->SetSecurityToken(foo); 9204 env1->SetSecurityToken(foo);
8218 env2->SetSecurityToken(foo); 9205 env2->SetSecurityToken(foo);
8219 9206
8220 env1->Global()->Set(v8_str("prop"), v8_num(3)); 9207 CHECK(
8221 env2->Global()->Set(v8_str("env1"), env1->Global()); 9208 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust());
9209 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust());
8222 9210
8223 // env1.prop is enumerable in env2. 9211 // env1.prop is enumerable in env2.
8224 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')"); 9212 Local<String> test = v8_str("propertyIsEnumerable.call(env1, 'prop')");
8225 { 9213 {
8226 Context::Scope scope_env2(env2); 9214 Context::Scope scope_env2(env2);
8227 Local<Value> result = CompileRun(test); 9215 Local<Value> result = CompileRun(test);
8228 CHECK(result->IsTrue()); 9216 CHECK(result->IsTrue());
8229 } 9217 }
8230 9218
8231 // Change env2 to a different domain and test again. 9219 // Change env2 to a different domain and test again.
8232 env2->SetSecurityToken(bar); 9220 env2->SetSecurityToken(bar);
8233 { 9221 {
8234 Context::Scope scope_env2(env2); 9222 Context::Scope scope_env2(env2);
8235 Local<Value> result = CompileRun(test); 9223 Local<Value> result = CompileRun(test);
8236 CHECK(result.IsEmpty()); 9224 CHECK(result.IsEmpty());
8237 } 9225 }
8238 } 9226 }
8239 9227
8240 9228
8241 THREADED_TEST(CrossDomainFor) { 9229 THREADED_TEST(CrossDomainFor) {
8242 LocalContext env1; 9230 LocalContext env1;
8243 v8::HandleScope handle_scope(env1->GetIsolate()); 9231 v8::HandleScope handle_scope(env1->GetIsolate());
8244 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9232 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8245 9233
8246 Local<Value> foo = v8_str("foo"); 9234 Local<Value> foo = v8_str("foo");
8247 Local<Value> bar = v8_str("bar"); 9235 Local<Value> bar = v8_str("bar");
8248 9236
8249 // Set to the same domain. 9237 // Set to the same domain.
8250 env1->SetSecurityToken(foo); 9238 env1->SetSecurityToken(foo);
8251 env2->SetSecurityToken(foo); 9239 env2->SetSecurityToken(foo);
8252 9240
8253 env1->Global()->Set(v8_str("prop"), v8_num(3)); 9241 CHECK(
8254 env2->Global()->Set(v8_str("env1"), env1->Global()); 9242 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust());
9243 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust());
8255 9244
8256 // Change env2 to a different domain and set env1's global object 9245 // Change env2 to a different domain and set env1's global object
8257 // as the __proto__ of an object in env2 and enumerate properties 9246 // as the __proto__ of an object in env2 and enumerate properties
8258 // in for-in. It shouldn't enumerate properties on env1's global 9247 // in for-in. It shouldn't enumerate properties on env1's global
8259 // object. 9248 // object.
8260 env2->SetSecurityToken(bar); 9249 env2->SetSecurityToken(bar);
8261 { 9250 {
8262 Context::Scope scope_env2(env2); 9251 Context::Scope scope_env2(env2);
8263 Local<Value> result = CompileRun( 9252 Local<Value> result = CompileRun(
8264 "(function() {" 9253 "(function() {"
8265 " try {" 9254 " try {"
8266 " for (var p in env1) {" 9255 " for (var p in env1) {"
8267 " if (p == 'prop') return false;" 9256 " if (p == 'prop') return false;"
8268 " }" 9257 " }"
8269 " return true;" 9258 " return true;"
8270 " } catch (e) {" 9259 " } catch (e) {"
8271 " return false;" 9260 " return false;"
8272 " }" 9261 " }"
8273 "})()"); 9262 "})()");
8274 CHECK(result->IsTrue()); 9263 CHECK(result->IsTrue());
8275 } 9264 }
8276 } 9265 }
8277 9266
8278 9267
8279 THREADED_TEST(CrossDomainForInOnPrototype) { 9268 THREADED_TEST(CrossDomainForInOnPrototype) {
8280 LocalContext env1; 9269 LocalContext env1;
8281 v8::HandleScope handle_scope(env1->GetIsolate()); 9270 v8::HandleScope handle_scope(env1->GetIsolate());
8282 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9271 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8283 9272
8284 Local<Value> foo = v8_str("foo"); 9273 Local<Value> foo = v8_str("foo");
8285 Local<Value> bar = v8_str("bar"); 9274 Local<Value> bar = v8_str("bar");
8286 9275
8287 // Set to the same domain. 9276 // Set to the same domain.
8288 env1->SetSecurityToken(foo); 9277 env1->SetSecurityToken(foo);
8289 env2->SetSecurityToken(foo); 9278 env2->SetSecurityToken(foo);
8290 9279
8291 env1->Global()->Set(v8_str("prop"), v8_num(3)); 9280 CHECK(
8292 env2->Global()->Set(v8_str("env1"), env1->Global()); 9281 env1->Global()->Set(env1.local(), v8_str("prop"), v8_num(3)).FromJust());
9282 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust());
8293 9283
8294 // Change env2 to a different domain and set env1's global object 9284 // Change env2 to a different domain and set env1's global object
8295 // as the __proto__ of an object in env2 and enumerate properties 9285 // as the __proto__ of an object in env2 and enumerate properties
8296 // in for-in. It shouldn't enumerate properties on env1's global 9286 // in for-in. It shouldn't enumerate properties on env1's global
8297 // object. 9287 // object.
8298 env2->SetSecurityToken(bar); 9288 env2->SetSecurityToken(bar);
8299 { 9289 {
8300 Context::Scope scope_env2(env2); 9290 Context::Scope scope_env2(env2);
8301 Local<Value> result = CompileRun( 9291 Local<Value> result = CompileRun(
8302 "(function() {" 9292 "(function() {"
8303 " var obj = { '__proto__': env1 };" 9293 " var obj = { '__proto__': env1 };"
8304 " try {" 9294 " try {"
8305 " for (var p in obj) {" 9295 " for (var p in obj) {"
8306 " if (p == 'prop') return false;" 9296 " if (p == 'prop') return false;"
8307 " }" 9297 " }"
8308 " return false;" 9298 " return false;"
8309 " } catch (e) {" 9299 " } catch (e) {"
8310 " return true;" 9300 " return true;"
8311 " }" 9301 " }"
8312 "})()"); 9302 "})()");
8313 CHECK(result->IsTrue()); 9303 CHECK(result->IsTrue());
8314 } 9304 }
8315 } 9305 }
8316 9306
8317 9307
8318 TEST(ContextDetachGlobal) { 9308 TEST(ContextDetachGlobal) {
8319 LocalContext env1; 9309 LocalContext env1;
8320 v8::HandleScope handle_scope(env1->GetIsolate()); 9310 v8::HandleScope handle_scope(env1->GetIsolate());
8321 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9311 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8322 9312
8323 Local<v8::Object> global1 = env1->Global();
8324 9313
8325 Local<Value> foo = v8_str("foo"); 9314 Local<Value> foo = v8_str("foo");
8326 9315
8327 // Set to the same domain. 9316 // Set to the same domain.
8328 env1->SetSecurityToken(foo); 9317 env1->SetSecurityToken(foo);
8329 env2->SetSecurityToken(foo); 9318 env2->SetSecurityToken(foo);
8330 9319
8331 // Enter env2 9320 // Enter env2
8332 env2->Enter(); 9321 env2->Enter();
8333 9322
8334 // Create a function in env2 and add a reference to it in env1. 9323 // Create a function in env2 and add a reference to it in env1.
8335 Local<v8::Object> global2 = env2->Global(); 9324 Local<v8::Object> global2 = env2->Global();
8336 global2->Set(v8_str("prop"), v8::Integer::New(env2->GetIsolate(), 1)); 9325 CHECK(global2->Set(env2, v8_str("prop"),
9326 v8::Integer::New(env2->GetIsolate(), 1))
9327 .FromJust());
8337 CompileRun("function getProp() {return prop;}"); 9328 CompileRun("function getProp() {return prop;}");
8338 9329
8339 env1->Global()->Set(v8_str("getProp"), 9330 CHECK(env1->Global()
8340 global2->Get(v8_str("getProp"))); 9331 ->Set(env1.local(), v8_str("getProp"),
9332 global2->Get(env2, v8_str("getProp")).ToLocalChecked())
9333 .FromJust());
8341 9334
8342 // Detach env2's global, and reuse the global object of env2 9335 // Detach env2's global, and reuse the global object of env2
8343 env2->Exit(); 9336 env2->Exit();
8344 env2->DetachGlobal(); 9337 env2->DetachGlobal();
8345 9338
8346 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), 9339 v8::Local<Context> env3 = Context::New(
8347 0, 9340 env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(), global2);
8348 v8::Handle<v8::ObjectTemplate>(),
8349 global2);
8350 env3->SetSecurityToken(v8_str("bar")); 9341 env3->SetSecurityToken(v8_str("bar"));
9342
8351 env3->Enter(); 9343 env3->Enter();
8352
8353 Local<v8::Object> global3 = env3->Global(); 9344 Local<v8::Object> global3 = env3->Global();
8354 CHECK(global2->Equals(global3)); 9345 CHECK(global2->Equals(env3, global3).FromJust());
8355 CHECK(global3->Get(v8_str("prop"))->IsUndefined()); 9346 CHECK(global3->Get(env3, v8_str("prop")).ToLocalChecked()->IsUndefined());
8356 CHECK(global3->Get(v8_str("getProp"))->IsUndefined()); 9347 CHECK(global3->Get(env3, v8_str("getProp")).ToLocalChecked()->IsUndefined());
8357 global3->Set(v8_str("prop"), v8::Integer::New(env3->GetIsolate(), -1)); 9348 CHECK(global3->Set(env3, v8_str("prop"),
8358 global3->Set(v8_str("prop2"), v8::Integer::New(env3->GetIsolate(), 2)); 9349 v8::Integer::New(env3->GetIsolate(), -1))
9350 .FromJust());
9351 CHECK(global3->Set(env3, v8_str("prop2"),
9352 v8::Integer::New(env3->GetIsolate(), 2))
9353 .FromJust());
8359 env3->Exit(); 9354 env3->Exit();
8360 9355
8361 // Call getProp in env1, and it should return the value 1 9356 // Call getProp in env1, and it should return the value 1
8362 { 9357 {
8363 Local<Value> get_prop = global1->Get(v8_str("getProp")); 9358 Local<v8::Object> global1 = env1->Global();
9359 Local<Value> get_prop =
9360 global1->Get(env1.local(), v8_str("getProp")).ToLocalChecked();
8364 CHECK(get_prop->IsFunction()); 9361 CHECK(get_prop->IsFunction());
8365 v8::TryCatch try_catch(env1->GetIsolate()); 9362 v8::TryCatch try_catch(env1->GetIsolate());
8366 Local<Value> r = Function::Cast(*get_prop)->Call(global1, 0, NULL); 9363 Local<Value> r = Function::Cast(*get_prop)
9364 ->Call(env1.local(), global1, 0, NULL)
9365 .ToLocalChecked();
8367 CHECK(!try_catch.HasCaught()); 9366 CHECK(!try_catch.HasCaught());
8368 CHECK_EQ(1, r->Int32Value()); 9367 CHECK_EQ(1, r->Int32Value(env1.local()).FromJust());
8369 } 9368 }
8370 9369
8371 // Check that env3 is not accessible from env1 9370 // Check that env3 is not accessible from env1
8372 { 9371 {
8373 Local<Value> r = global3->Get(v8_str("prop2")); 9372 v8::MaybeLocal<Value> r = global3->Get(env1.local(), v8_str("prop2"));
8374 CHECK(r.IsEmpty()); 9373 CHECK(r.IsEmpty());
8375 } 9374 }
8376 } 9375 }
8377 9376
8378 9377
8379 TEST(DetachGlobal) { 9378 TEST(DetachGlobal) {
8380 LocalContext env1; 9379 LocalContext env1;
8381 v8::HandleScope scope(env1->GetIsolate()); 9380 v8::HandleScope scope(env1->GetIsolate());
8382 9381
8383 // Create second environment. 9382 // Create second environment.
8384 v8::Handle<Context> env2 = Context::New(env1->GetIsolate()); 9383 v8::Local<Context> env2 = Context::New(env1->GetIsolate());
8385 9384
8386 Local<Value> foo = v8_str("foo"); 9385 Local<Value> foo = v8_str("foo");
8387 9386
8388 // Set same security token for env1 and env2. 9387 // Set same security token for env1 and env2.
8389 env1->SetSecurityToken(foo); 9388 env1->SetSecurityToken(foo);
8390 env2->SetSecurityToken(foo); 9389 env2->SetSecurityToken(foo);
8391 9390
8392 // Create a property on the global object in env2. 9391 // Create a property on the global object in env2.
8393 { 9392 {
8394 v8::Context::Scope scope(env2); 9393 v8::Context::Scope scope(env2);
8395 env2->Global()->Set(v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42)); 9394 CHECK(env2->Global()
9395 ->Set(env2, v8_str("p"), v8::Integer::New(env2->GetIsolate(), 42))
9396 .FromJust());
8396 } 9397 }
8397 9398
8398 // Create a reference to env2 global from env1 global. 9399 // Create a reference to env2 global from env1 global.
8399 env1->Global()->Set(v8_str("other"), env2->Global()); 9400 CHECK(env1->Global()
9401 ->Set(env1.local(), v8_str("other"), env2->Global())
9402 .FromJust());
8400 9403
8401 // Check that we have access to other.p in env2 from env1. 9404 // Check that we have access to other.p in env2 from env1.
8402 Local<Value> result = CompileRun("other.p"); 9405 Local<Value> result = CompileRun("other.p");
8403 CHECK(result->IsInt32()); 9406 CHECK(result->IsInt32());
8404 CHECK_EQ(42, result->Int32Value()); 9407 CHECK_EQ(42, result->Int32Value(env1.local()).FromJust());
8405 9408
8406 // Hold on to global from env2 and detach global from env2. 9409 // Hold on to global from env2 and detach global from env2.
8407 Local<v8::Object> global2 = env2->Global(); 9410 Local<v8::Object> global2 = env2->Global();
8408 env2->DetachGlobal(); 9411 env2->DetachGlobal();
8409 9412
8410 // Check that the global has been detached. No other.p property can 9413 // Check that the global has been detached. No other.p property can
8411 // be found. 9414 // be found.
8412 result = CompileRun("other.p"); 9415 result = CompileRun("other.p");
8413 CHECK(result.IsEmpty()); 9416 CHECK(result.IsEmpty());
8414 9417
8415 // Reuse global2 for env3. 9418 // Reuse global2 for env3.
8416 v8::Handle<Context> env3 = Context::New(env1->GetIsolate(), 9419 v8::Local<Context> env3 = Context::New(
8417 0, 9420 env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(), global2);
8418 v8::Handle<v8::ObjectTemplate>(), 9421 CHECK(global2->Equals(env1.local(), env3->Global()).FromJust());
8419 global2);
8420 CHECK(global2->Equals(env3->Global()));
8421 9422
8422 // Start by using the same security token for env3 as for env1 and env2. 9423 // Start by using the same security token for env3 as for env1 and env2.
8423 env3->SetSecurityToken(foo); 9424 env3->SetSecurityToken(foo);
8424 9425
8425 // Create a property on the global object in env3. 9426 // Create a property on the global object in env3.
8426 { 9427 {
8427 v8::Context::Scope scope(env3); 9428 v8::Context::Scope scope(env3);
8428 env3->Global()->Set(v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24)); 9429 CHECK(env3->Global()
9430 ->Set(env3, v8_str("p"), v8::Integer::New(env3->GetIsolate(), 24))
9431 .FromJust());
8429 } 9432 }
8430 9433
8431 // Check that other.p is now the property in env3 and that we have access. 9434 // Check that other.p is now the property in env3 and that we have access.
8432 result = CompileRun("other.p"); 9435 result = CompileRun("other.p");
8433 CHECK(result->IsInt32()); 9436 CHECK(result->IsInt32());
8434 CHECK_EQ(24, result->Int32Value()); 9437 CHECK_EQ(24, result->Int32Value(env3).FromJust());
8435 9438
8436 // Change security token for env3 to something different from env1 and env2. 9439 // Change security token for env3 to something different from env1 and env2.
8437 env3->SetSecurityToken(v8_str("bar")); 9440 env3->SetSecurityToken(v8_str("bar"));
8438 9441
8439 // Check that we do not have access to other.p in env1. |other| is now 9442 // 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, 9443 // the global object for env3 which has a different security token,
8441 // so access should be blocked. 9444 // so access should be blocked.
8442 result = CompileRun("other.p"); 9445 result = CompileRun("other.p");
8443 CHECK(result.IsEmpty()); 9446 CHECK(result.IsEmpty());
8444 } 9447 }
8445 9448
8446 9449
8447 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) { 9450 void GetThisX(const v8::FunctionCallbackInfo<v8::Value>& info) {
9451 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
8448 info.GetReturnValue().Set( 9452 info.GetReturnValue().Set(
8449 info.GetIsolate()->GetCurrentContext()->Global()->Get(v8_str("x"))); 9453 context->Global()->Get(context, v8_str("x")).ToLocalChecked());
8450 } 9454 }
8451 9455
8452 9456
8453 TEST(DetachedAccesses) { 9457 TEST(DetachedAccesses) {
8454 LocalContext env1; 9458 LocalContext env1;
8455 v8::HandleScope scope(env1->GetIsolate()); 9459 v8::HandleScope scope(env1->GetIsolate());
8456 9460
8457 // Create second environment. 9461 // Create second environment.
8458 Local<ObjectTemplate> inner_global_template = 9462 Local<ObjectTemplate> inner_global_template =
8459 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate(); 9463 FunctionTemplate::New(env1->GetIsolate())->InstanceTemplate();
8460 inner_global_template ->SetAccessorProperty( 9464 inner_global_template ->SetAccessorProperty(
8461 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX)); 9465 v8_str("this_x"), FunctionTemplate::New(env1->GetIsolate(), GetThisX));
8462 v8::Local<Context> env2 = 9466 v8::Local<Context> env2 =
8463 Context::New(env1->GetIsolate(), NULL, inner_global_template); 9467 Context::New(env1->GetIsolate(), NULL, inner_global_template);
8464 9468
8465 Local<Value> foo = v8_str("foo"); 9469 Local<Value> foo = v8_str("foo");
8466 9470
8467 // Set same security token for env1 and env2. 9471 // Set same security token for env1 and env2.
8468 env1->SetSecurityToken(foo); 9472 env1->SetSecurityToken(foo);
8469 env2->SetSecurityToken(foo); 9473 env2->SetSecurityToken(foo);
8470 9474
8471 env1->Global()->Set(v8_str("x"), v8_str("env1_x")); 9475 CHECK(env1->Global()
9476 ->Set(env1.local(), v8_str("x"), v8_str("env1_x"))
9477 .FromJust());
8472 9478
8473 { 9479 {
8474 v8::Context::Scope scope(env2); 9480 v8::Context::Scope scope(env2);
8475 env2->Global()->Set(v8_str("x"), v8_str("env2_x")); 9481 CHECK(env2->Global()->Set(env2, v8_str("x"), v8_str("env2_x")).FromJust());
8476 CompileRun( 9482 CompileRun(
8477 "function bound_x() { return x; }" 9483 "function bound_x() { return x; }"
8478 "function get_x() { return this.x; }" 9484 "function get_x() { return this.x; }"
8479 "function get_x_w() { return (function() {return this.x;})(); }"); 9485 "function get_x_w() { return (function() {return this.x;})(); }");
8480 env1->Global()->Set(v8_str("bound_x"), CompileRun("bound_x")); 9486 // SHOULD BE env2 ???
8481 env1->Global()->Set(v8_str("get_x"), CompileRun("get_x")); 9487 CHECK(env1->Global()
8482 env1->Global()->Set(v8_str("get_x_w"), CompileRun("get_x_w")); 9488 ->Set(env1.local(), v8_str("bound_x"), CompileRun("bound_x"))
8483 env1->Global()->Set( 9489 .FromJust());
8484 v8_str("this_x"), 9490 CHECK(env1->Global()
8485 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get")); 9491 ->Set(env1.local(), v8_str("get_x"), CompileRun("get_x"))
9492 .FromJust());
9493 CHECK(env1->Global()
9494 ->Set(env1.local(), v8_str("get_x_w"), CompileRun("get_x_w"))
9495 .FromJust());
9496 env1->Global()
9497 ->Set(env1.local(), v8_str("this_x"),
9498 CompileRun("Object.getOwnPropertyDescriptor(this, 'this_x').get"))
9499 .FromJust();
8486 } 9500 }
8487 9501
8488 Local<Object> env2_global = env2->Global(); 9502 Local<Object> env2_global = env2->Global();
8489 env2->DetachGlobal(); 9503 env2->DetachGlobal();
8490 9504
8491 Local<Value> result; 9505 Local<Value> result;
8492 result = CompileRun("bound_x()"); 9506 result = CompileRun("bound_x()");
8493 CHECK(v8_str("env2_x")->Equals(result)); 9507 CHECK(v8_str("env2_x")->Equals(env1.local(), result).FromJust());
8494 result = CompileRun("get_x()"); 9508 result = CompileRun("get_x()");
8495 CHECK(result.IsEmpty()); 9509 CHECK(result.IsEmpty());
8496 result = CompileRun("get_x_w()"); 9510 result = CompileRun("get_x_w()");
8497 CHECK(result.IsEmpty()); 9511 CHECK(result.IsEmpty());
8498 result = CompileRun("this_x()"); 9512 result = CompileRun("this_x()");
8499 CHECK(v8_str("env2_x")->Equals(result)); 9513 CHECK(v8_str("env2_x")->Equals(env1.local(), result).FromJust());
8500 9514
8501 // Reattach env2's proxy 9515 // Reattach env2's proxy
8502 env2 = Context::New(env1->GetIsolate(), 9516 env2 = Context::New(env1->GetIsolate(), 0, v8::Local<v8::ObjectTemplate>(),
8503 0,
8504 v8::Handle<v8::ObjectTemplate>(),
8505 env2_global); 9517 env2_global);
8506 env2->SetSecurityToken(foo); 9518 env2->SetSecurityToken(foo);
8507 { 9519 {
8508 v8::Context::Scope scope(env2); 9520 v8::Context::Scope scope(env2);
8509 env2->Global()->Set(v8_str("x"), v8_str("env3_x")); 9521 CHECK(env2->Global()->Set(env2, v8_str("x"), v8_str("env3_x")).FromJust());
8510 env2->Global()->Set(v8_str("env1"), env1->Global()); 9522 CHECK(env2->Global()->Set(env2, v8_str("env1"), env1->Global()).FromJust());
8511 result = CompileRun( 9523 result = CompileRun(
8512 "results = [];" 9524 "results = [];"
8513 "for (var i = 0; i < 4; i++ ) {" 9525 "for (var i = 0; i < 4; i++ ) {"
8514 " results.push(env1.bound_x());" 9526 " results.push(env1.bound_x());"
8515 " results.push(env1.get_x());" 9527 " results.push(env1.get_x());"
8516 " results.push(env1.get_x_w());" 9528 " results.push(env1.get_x_w());"
8517 " results.push(env1.this_x());" 9529 " results.push(env1.this_x());"
8518 "}" 9530 "}"
8519 "results"); 9531 "results");
8520 Local<v8::Array> results = Local<v8::Array>::Cast(result); 9532 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8521 CHECK_EQ(16u, results->Length()); 9533 CHECK_EQ(16u, results->Length());
8522 for (int i = 0; i < 16; i += 4) { 9534 for (int i = 0; i < 16; i += 4) {
8523 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); 9535 CHECK(v8_str("env2_x")
8524 CHECK(v8_str("env1_x")->Equals(results->Get(i + 1))); 9536 ->Equals(env2, results->Get(env2, i + 0).ToLocalChecked())
8525 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); 9537 .FromJust());
8526 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); 9538 CHECK(v8_str("env1_x")
9539 ->Equals(env2, results->Get(env2, i + 1).ToLocalChecked())
9540 .FromJust());
9541 CHECK(v8_str("env3_x")
9542 ->Equals(env2, results->Get(env2, i + 2).ToLocalChecked())
9543 .FromJust());
9544 CHECK(v8_str("env2_x")
9545 ->Equals(env2, results->Get(env2, i + 3).ToLocalChecked())
9546 .FromJust());
8527 } 9547 }
8528 } 9548 }
8529 9549
8530 result = CompileRun( 9550 result = CompileRun(
8531 "results = [];" 9551 "results = [];"
8532 "for (var i = 0; i < 4; i++ ) {" 9552 "for (var i = 0; i < 4; i++ ) {"
8533 " results.push(bound_x());" 9553 " results.push(bound_x());"
8534 " results.push(get_x());" 9554 " results.push(get_x());"
8535 " results.push(get_x_w());" 9555 " results.push(get_x_w());"
8536 " results.push(this_x());" 9556 " results.push(this_x());"
8537 "}" 9557 "}"
8538 "results"); 9558 "results");
8539 Local<v8::Array> results = Local<v8::Array>::Cast(result); 9559 Local<v8::Array> results = Local<v8::Array>::Cast(result);
8540 CHECK_EQ(16u, results->Length()); 9560 CHECK_EQ(16u, results->Length());
8541 for (int i = 0; i < 16; i += 4) { 9561 for (int i = 0; i < 16; i += 4) {
8542 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); 9562 CHECK(v8_str("env2_x")
8543 CHECK(v8_str("env3_x")->Equals(results->Get(i + 1))); 9563 ->Equals(env1.local(),
8544 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); 9564 results->Get(env1.local(), i + 0).ToLocalChecked())
8545 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); 9565 .FromJust());
9566 CHECK(v8_str("env3_x")
9567 ->Equals(env1.local(),
9568 results->Get(env1.local(), i + 1).ToLocalChecked())
9569 .FromJust());
9570 CHECK(v8_str("env3_x")
9571 ->Equals(env1.local(),
9572 results->Get(env1.local(), i + 2).ToLocalChecked())
9573 .FromJust());
9574 CHECK(v8_str("env2_x")
9575 ->Equals(env1.local(),
9576 results->Get(env1.local(), i + 3).ToLocalChecked())
9577 .FromJust());
8546 } 9578 }
8547 9579
8548 result = CompileRun( 9580 result = CompileRun(
8549 "results = [];" 9581 "results = [];"
8550 "for (var i = 0; i < 4; i++ ) {" 9582 "for (var i = 0; i < 4; i++ ) {"
8551 " results.push(this.bound_x());" 9583 " results.push(this.bound_x());"
8552 " results.push(this.get_x());" 9584 " results.push(this.get_x());"
8553 " results.push(this.get_x_w());" 9585 " results.push(this.get_x_w());"
8554 " results.push(this.this_x());" 9586 " results.push(this.this_x());"
8555 "}" 9587 "}"
8556 "results"); 9588 "results");
8557 results = Local<v8::Array>::Cast(result); 9589 results = Local<v8::Array>::Cast(result);
8558 CHECK_EQ(16u, results->Length()); 9590 CHECK_EQ(16u, results->Length());
8559 for (int i = 0; i < 16; i += 4) { 9591 for (int i = 0; i < 16; i += 4) {
8560 CHECK(v8_str("env2_x")->Equals(results->Get(i + 0))); 9592 CHECK(v8_str("env2_x")
8561 CHECK(v8_str("env1_x")->Equals(results->Get(i + 1))); 9593 ->Equals(env1.local(),
8562 CHECK(v8_str("env3_x")->Equals(results->Get(i + 2))); 9594 results->Get(env1.local(), i + 0).ToLocalChecked())
8563 CHECK(v8_str("env2_x")->Equals(results->Get(i + 3))); 9595 .FromJust());
9596 CHECK(v8_str("env1_x")
9597 ->Equals(env1.local(),
9598 results->Get(env1.local(), i + 1).ToLocalChecked())
9599 .FromJust());
9600 CHECK(v8_str("env3_x")
9601 ->Equals(env1.local(),
9602 results->Get(env1.local(), i + 2).ToLocalChecked())
9603 .FromJust());
9604 CHECK(v8_str("env2_x")
9605 ->Equals(env1.local(),
9606 results->Get(env1.local(), i + 3).ToLocalChecked())
9607 .FromJust());
8564 } 9608 }
8565 } 9609 }
8566 9610
8567 9611
8568 static bool allowed_access = false; 9612 static bool allowed_access = false;
8569 static bool AccessBlocker(Local<v8::Context> accessing_context, 9613 static bool AccessBlocker(Local<v8::Context> accessing_context,
8570 Local<v8::Object> accessed_object) { 9614 Local<v8::Object> accessed_object) {
8571 return CcTest::isolate()->GetCurrentContext()->Global()->Equals( 9615 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
8572 accessed_object) || 9616 return context->Global()->Equals(context, accessed_object).FromJust() ||
8573 allowed_access; 9617 allowed_access;
8574 } 9618 }
8575 9619
8576 9620
8577 static int g_echo_value = -1; 9621 static int g_echo_value = -1;
8578 9622
8579 9623
8580 static void EchoGetter( 9624 static void EchoGetter(
8581 Local<String> name, 9625 Local<String> name,
8582 const v8::PropertyCallbackInfo<v8::Value>& info) { 9626 const v8::PropertyCallbackInfo<v8::Value>& info) {
8583 info.GetReturnValue().Set(v8_num(g_echo_value)); 9627 info.GetReturnValue().Set(v8_num(g_echo_value));
8584 } 9628 }
8585 9629
8586 9630
8587 static void EchoSetter(Local<String> name, 9631 static void EchoSetter(Local<String> name, Local<Value> value,
8588 Local<Value> value, 9632 const v8::PropertyCallbackInfo<void>& args) {
8589 const v8::PropertyCallbackInfo<void>&) {
8590 if (value->IsNumber()) 9633 if (value->IsNumber())
8591 g_echo_value = value->Int32Value(); 9634 g_echo_value =
9635 value->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust();
8592 } 9636 }
8593 9637
8594 9638
8595 static void UnreachableGetter( 9639 static void UnreachableGetter(
8596 Local<String> name, 9640 Local<String> name,
8597 const v8::PropertyCallbackInfo<v8::Value>& info) { 9641 const v8::PropertyCallbackInfo<v8::Value>& info) {
8598 CHECK(false); // This function should not be called.. 9642 CHECK(false); // This function should not be called..
8599 } 9643 }
8600 9644
8601 9645
8602 static void UnreachableSetter(Local<String>, 9646 static void UnreachableSetter(Local<String>,
8603 Local<Value>, 9647 Local<Value>,
8604 const v8::PropertyCallbackInfo<void>&) { 9648 const v8::PropertyCallbackInfo<void>&) {
8605 CHECK(false); // This function should nto be called. 9649 CHECK(false); // This function should nto be called.
8606 } 9650 }
8607 9651
8608 9652
8609 static void UnreachableFunction( 9653 static void UnreachableFunction(
8610 const v8::FunctionCallbackInfo<v8::Value>& info) { 9654 const v8::FunctionCallbackInfo<v8::Value>& info) {
8611 CHECK(false); // This function should not be called.. 9655 CHECK(false); // This function should not be called..
8612 } 9656 }
8613 9657
8614 9658
8615 TEST(AccessControl) { 9659 TEST(AccessControl) {
8616 v8::Isolate* isolate = CcTest::isolate(); 9660 v8::Isolate* isolate = CcTest::isolate();
8617 v8::HandleScope handle_scope(isolate); 9661 v8::HandleScope handle_scope(isolate);
8618 v8::Handle<v8::ObjectTemplate> global_template = 9662 v8::Local<v8::ObjectTemplate> global_template =
8619 v8::ObjectTemplate::New(isolate); 9663 v8::ObjectTemplate::New(isolate);
8620 9664
8621 global_template->SetAccessCheckCallback(AccessBlocker); 9665 global_template->SetAccessCheckCallback(AccessBlocker);
8622 9666
8623 // Add an accessor accessible by cross-domain JS code. 9667 // Add an accessor accessible by cross-domain JS code.
8624 global_template->SetAccessor( 9668 global_template->SetAccessor(
8625 v8_str("accessible_prop"), 9669 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)); 9670 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8629 9671
8630 9672
8631 // Add an accessor that is not accessible by cross-domain JS code. 9673 // Add an accessor that is not accessible by cross-domain JS code.
8632 global_template->SetAccessor(v8_str("blocked_prop"), 9674 global_template->SetAccessor(v8_str("blocked_prop"), UnreachableGetter,
8633 UnreachableGetter, UnreachableSetter, 9675 UnreachableSetter, v8::Local<Value>(),
8634 v8::Handle<Value>(),
8635 v8::DEFAULT); 9676 v8::DEFAULT);
8636 9677
8637 global_template->SetAccessorProperty( 9678 global_template->SetAccessorProperty(
8638 v8_str("blocked_js_prop"), 9679 v8_str("blocked_js_prop"),
8639 v8::FunctionTemplate::New(isolate, UnreachableFunction), 9680 v8::FunctionTemplate::New(isolate, UnreachableFunction),
8640 v8::FunctionTemplate::New(isolate, UnreachableFunction), 9681 v8::FunctionTemplate::New(isolate, UnreachableFunction),
8641 v8::None, 9682 v8::None,
8642 v8::DEFAULT); 9683 v8::DEFAULT);
8643 9684
8644 // Create an environment 9685 // Create an environment
8645 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 9686 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8646 context0->Enter(); 9687 context0->Enter();
8647 9688
8648 v8::Handle<v8::Object> global0 = context0->Global(); 9689 v8::Local<v8::Object> global0 = context0->Global();
8649 9690
8650 // Define a property with JS getter and setter. 9691 // Define a property with JS getter and setter.
8651 CompileRun( 9692 CompileRun(
8652 "function getter() { return 'getter'; };\n" 9693 "function getter() { return 'getter'; };\n"
8653 "function setter() { return 'setter'; }\n" 9694 "function setter() { return 'setter'; }\n"
8654 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})"); 9695 "Object.defineProperty(this, 'js_accessor_p', {get:getter, set:setter})");
8655 9696
8656 Local<Value> getter = global0->Get(v8_str("getter")); 9697 Local<Value> getter =
8657 Local<Value> setter = global0->Get(v8_str("setter")); 9698 global0->Get(context0, v8_str("getter")).ToLocalChecked();
9699 Local<Value> setter =
9700 global0->Get(context0, v8_str("setter")).ToLocalChecked();
8658 9701
8659 // And define normal element. 9702 // And define normal element.
8660 global0->Set(239, v8_str("239")); 9703 CHECK(global0->Set(context0, 239, v8_str("239")).FromJust());
8661 9704
8662 // Define an element with JS getter and setter. 9705 // Define an element with JS getter and setter.
8663 CompileRun( 9706 CompileRun(
8664 "function el_getter() { return 'el_getter'; };\n" 9707 "function el_getter() { return 'el_getter'; };\n"
8665 "function el_setter() { return 'el_setter'; };\n" 9708 "function el_setter() { return 'el_setter'; };\n"
8666 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});"); 9709 "Object.defineProperty(this, '42', {get: el_getter, set: el_setter});");
8667 9710
8668 Local<Value> el_getter = global0->Get(v8_str("el_getter")); 9711 Local<Value> el_getter =
8669 Local<Value> el_setter = global0->Get(v8_str("el_setter")); 9712 global0->Get(context0, v8_str("el_getter")).ToLocalChecked();
9713 Local<Value> el_setter =
9714 global0->Get(context0, v8_str("el_setter")).ToLocalChecked();
8670 9715
8671 v8::HandleScope scope1(isolate); 9716 v8::HandleScope scope1(isolate);
8672 9717
8673 v8::Local<Context> context1 = Context::New(isolate); 9718 v8::Local<Context> context1 = Context::New(isolate);
8674 context1->Enter(); 9719 context1->Enter();
8675 9720
8676 v8::Handle<v8::Object> global1 = context1->Global(); 9721 v8::Local<v8::Object> global1 = context1->Global();
8677 global1->Set(v8_str("other"), global0); 9722 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust());
8678 9723
8679 // Access blocked property. 9724 // Access blocked property.
8680 CompileRun("other.blocked_prop = 1"); 9725 CompileRun("other.blocked_prop = 1");
8681 9726
8682 CHECK(CompileRun("other.blocked_prop").IsEmpty()); 9727 CHECK(CompileRun("other.blocked_prop").IsEmpty());
8683 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") 9728 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')")
8684 .IsEmpty()); 9729 .IsEmpty());
8685 CHECK( 9730 CHECK(
8686 CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')").IsEmpty()); 9731 CompileRun("propertyIsEnumerable.call(other, 'blocked_prop')").IsEmpty());
8687 9732
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
8724 9769
8725 allowed_access = true; 9770 allowed_access = true;
8726 9771
8727 ExpectString("other[42]", "el_getter"); 9772 ExpectString("other[42]", "el_getter");
8728 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter); 9773 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').get", el_getter);
8729 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter); 9774 ExpectObject("Object.getOwnPropertyDescriptor(other, '42').set", el_setter);
8730 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value"); 9775 ExpectUndefined("Object.getOwnPropertyDescriptor(other, '42').value");
8731 9776
8732 allowed_access = false; 9777 allowed_access = false;
8733 9778
8734 v8::Handle<Value> value; 9779 v8::Local<Value> value;
8735 9780
8736 // Access accessible property 9781 // Access accessible property
8737 value = CompileRun("other.accessible_prop = 3"); 9782 value = CompileRun("other.accessible_prop = 3");
8738 CHECK(value->IsNumber()); 9783 CHECK(value->IsNumber());
8739 CHECK_EQ(3, value->Int32Value()); 9784 CHECK_EQ(3, value->Int32Value(context1).FromJust());
8740 CHECK_EQ(3, g_echo_value); 9785 CHECK_EQ(3, g_echo_value);
8741 9786
8742 value = CompileRun("other.accessible_prop"); 9787 value = CompileRun("other.accessible_prop");
8743 CHECK(value->IsNumber()); 9788 CHECK(value->IsNumber());
8744 CHECK_EQ(3, value->Int32Value()); 9789 CHECK_EQ(3, value->Int32Value(context1).FromJust());
8745 9790
8746 value = CompileRun( 9791 value = CompileRun(
8747 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value"); 9792 "Object.getOwnPropertyDescriptor(other, 'accessible_prop').value");
8748 CHECK(value->IsNumber()); 9793 CHECK(value->IsNumber());
8749 CHECK_EQ(3, value->Int32Value()); 9794 CHECK_EQ(3, value->Int32Value(context1).FromJust());
8750 9795
8751 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')"); 9796 value = CompileRun("propertyIsEnumerable.call(other, 'accessible_prop')");
8752 CHECK(value->IsTrue()); 9797 CHECK(value->IsTrue());
8753 9798
8754 // Enumeration doesn't enumerate accessors from inaccessible objects in 9799 // Enumeration doesn't enumerate accessors from inaccessible objects in
8755 // the prototype chain even if the accessors are in themselves accessible. 9800 // the prototype chain even if the accessors are in themselves accessible.
8756 value = CompileRun( 9801 value = CompileRun(
8757 "(function() {" 9802 "(function() {"
8758 " var obj = { '__proto__': other };" 9803 " var obj = { '__proto__': other };"
8759 " try {" 9804 " try {"
8760 " for (var p in obj) {" 9805 " for (var p in obj) {"
8761 " if (p == 'accessible_prop' ||" 9806 " if (p == 'accessible_prop' ||"
8762 " p == 'blocked_js_prop' ||" 9807 " p == 'blocked_js_prop' ||"
8763 " p == 'blocked_js_prop') {" 9808 " p == 'blocked_js_prop') {"
8764 " return false;" 9809 " return false;"
8765 " }" 9810 " }"
8766 " }" 9811 " }"
8767 " return false;" 9812 " return false;"
8768 " } catch (e) {" 9813 " } catch (e) {"
8769 " return true;" 9814 " return true;"
8770 " }" 9815 " }"
8771 "})()"); 9816 "})()");
8772 CHECK(value->IsTrue()); 9817 CHECK(value->IsTrue());
8773 9818
8774 // Test that preventExtensions fails on a non-accessible object even if that 9819 // Test that preventExtensions fails on a non-accessible object even if that
8775 // object is already non-extensible. 9820 // object is already non-extensible.
8776 global1->Set(v8_str("checked_object"), global_template->NewInstance()); 9821 CHECK(global1->Set(context1, v8_str("checked_object"),
9822 global_template->NewInstance(context1).ToLocalChecked())
9823 .FromJust());
8777 allowed_access = true; 9824 allowed_access = true;
8778 CompileRun("Object.preventExtensions(checked_object)"); 9825 CompileRun("Object.preventExtensions(checked_object)");
8779 ExpectFalse("Object.isExtensible(checked_object)"); 9826 ExpectFalse("Object.isExtensible(checked_object)");
8780 allowed_access = false; 9827 allowed_access = false;
8781 CHECK(CompileRun("Object.preventExtensions(checked_object)").IsEmpty()); 9828 CHECK(CompileRun("Object.preventExtensions(checked_object)").IsEmpty());
8782 9829
8783 context1->Exit(); 9830 context1->Exit();
8784 context0->Exit(); 9831 context0->Exit();
8785 } 9832 }
8786 9833
8787 9834
8788 TEST(AccessControlES5) { 9835 TEST(AccessControlES5) {
8789 v8::Isolate* isolate = CcTest::isolate(); 9836 v8::Isolate* isolate = CcTest::isolate();
8790 v8::HandleScope handle_scope(isolate); 9837 v8::HandleScope handle_scope(isolate);
8791 v8::Handle<v8::ObjectTemplate> global_template = 9838 v8::Local<v8::ObjectTemplate> global_template =
8792 v8::ObjectTemplate::New(isolate); 9839 v8::ObjectTemplate::New(isolate);
8793 9840
8794 global_template->SetAccessCheckCallback(AccessBlocker); 9841 global_template->SetAccessCheckCallback(AccessBlocker);
8795 9842
8796 // Add accessible accessor. 9843 // Add accessible accessor.
8797 global_template->SetAccessor( 9844 global_template->SetAccessor(
8798 v8_str("accessible_prop"), 9845 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)); 9846 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8802 9847
8803 9848
8804 // Add an accessor that is not accessible by cross-domain JS code. 9849 // Add an accessor that is not accessible by cross-domain JS code.
8805 global_template->SetAccessor(v8_str("blocked_prop"), 9850 global_template->SetAccessor(v8_str("blocked_prop"), UnreachableGetter,
8806 UnreachableGetter, UnreachableSetter, 9851 UnreachableSetter, v8::Local<Value>(),
8807 v8::Handle<Value>(),
8808 v8::DEFAULT); 9852 v8::DEFAULT);
8809 9853
8810 // Create an environment 9854 // Create an environment
8811 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 9855 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8812 context0->Enter(); 9856 context0->Enter();
8813 9857
8814 v8::Handle<v8::Object> global0 = context0->Global(); 9858 v8::Local<v8::Object> global0 = context0->Global();
8815 9859
8816 v8::Local<Context> context1 = Context::New(isolate); 9860 v8::Local<Context> context1 = Context::New(isolate);
8817 context1->Enter(); 9861 context1->Enter();
8818 v8::Handle<v8::Object> global1 = context1->Global(); 9862 v8::Local<v8::Object> global1 = context1->Global();
8819 global1->Set(v8_str("other"), global0); 9863 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust());
8820 9864
8821 // Regression test for issue 1154. 9865 // Regression test for issue 1154.
8822 CHECK(CompileRun("Object.keys(other).length == 0")->BooleanValue()); 9866 CHECK(CompileRun("Object.keys(other).length == 0")
9867 ->BooleanValue(context1)
9868 .FromJust());
8823 CHECK(CompileRun("other.blocked_prop").IsEmpty()); 9869 CHECK(CompileRun("other.blocked_prop").IsEmpty());
8824 9870
8825 // Regression test for issue 1027. 9871 // Regression test for issue 1027.
8826 CompileRun("Object.defineProperty(\n" 9872 CompileRun("Object.defineProperty(\n"
8827 " other, 'blocked_prop', {configurable: false})"); 9873 " other, 'blocked_prop', {configurable: false})");
8828 CHECK(CompileRun("other.blocked_prop").IsEmpty()); 9874 CHECK(CompileRun("other.blocked_prop").IsEmpty());
8829 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')") 9875 CHECK(CompileRun("Object.getOwnPropertyDescriptor(other, 'blocked_prop')")
8830 .IsEmpty()); 9876 .IsEmpty());
8831 9877
8832 // Regression test for issue 1171. 9878 // Regression test for issue 1171.
(...skipping 26 matching lines...) Expand all
8859 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context, 9905 static bool AccessAlwaysBlocked(Local<v8::Context> accessing_context,
8860 Local<v8::Object> global) { 9906 Local<v8::Object> global) {
8861 i::PrintF("Access blocked.\n"); 9907 i::PrintF("Access blocked.\n");
8862 return false; 9908 return false;
8863 } 9909 }
8864 9910
8865 9911
8866 THREADED_TEST(AccessControlGetOwnPropertyNames) { 9912 THREADED_TEST(AccessControlGetOwnPropertyNames) {
8867 v8::Isolate* isolate = CcTest::isolate(); 9913 v8::Isolate* isolate = CcTest::isolate();
8868 v8::HandleScope handle_scope(isolate); 9914 v8::HandleScope handle_scope(isolate);
8869 v8::Handle<v8::ObjectTemplate> obj_template = 9915 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
8870 v8::ObjectTemplate::New(isolate);
8871 9916
8872 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 9917 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
8873 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); 9918 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked);
8874 9919
8875 // Add an accessor accessible by cross-domain JS code. 9920 // Add an accessor accessible by cross-domain JS code.
8876 obj_template->SetAccessor( 9921 obj_template->SetAccessor(
8877 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Handle<Value>(), 9922 v8_str("accessible_prop"), EchoGetter, EchoSetter, v8::Local<Value>(),
8878 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 9923 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8879 9924
8880 // Create an environment 9925 // Create an environment
8881 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 9926 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
8882 context0->Enter(); 9927 context0->Enter();
8883 9928
8884 v8::Handle<v8::Object> global0 = context0->Global(); 9929 v8::Local<v8::Object> global0 = context0->Global();
8885 9930
8886 v8::HandleScope scope1(CcTest::isolate()); 9931 v8::HandleScope scope1(CcTest::isolate());
8887 9932
8888 v8::Local<Context> context1 = Context::New(isolate); 9933 v8::Local<Context> context1 = Context::New(isolate);
8889 context1->Enter(); 9934 context1->Enter();
8890 9935
8891 v8::Handle<v8::Object> global1 = context1->Global(); 9936 v8::Local<v8::Object> global1 = context1->Global();
8892 global1->Set(v8_str("other"), global0); 9937 CHECK(global1->Set(context1, v8_str("other"), global0).FromJust());
8893 global1->Set(v8_str("object"), obj_template->NewInstance()); 9938 CHECK(global1->Set(context1, v8_str("object"),
9939 obj_template->NewInstance(context1).ToLocalChecked())
9940 .FromJust());
8894 9941
8895 v8::Handle<Value> value; 9942 v8::Local<Value> value;
8896 9943
8897 // Attempt to get the property names of the other global object and 9944 // Attempt to get the property names of the other global object and
8898 // of an object that requires access checks. Accessing the other 9945 // of an object that requires access checks. Accessing the other
8899 // global object should be blocked by access checks on the global 9946 // global object should be blocked by access checks on the global
8900 // proxy object. Accessing the object that requires access checks 9947 // proxy object. Accessing the object that requires access checks
8901 // is blocked by the access checks on the object itself. 9948 // is blocked by the access checks on the object itself.
8902 value = CompileRun( 9949 value = CompileRun(
8903 "var names = Object.getOwnPropertyNames(other);" 9950 "var names = Object.getOwnPropertyNames(other);"
8904 "names.length == 1 && names[0] == 'accessible_prop';"); 9951 "names.length == 1 && names[0] == 'accessible_prop';");
8905 CHECK(value->BooleanValue()); 9952 CHECK(value->BooleanValue(context1).FromJust());
8906 9953
8907 value = CompileRun( 9954 value = CompileRun(
8908 "var names = Object.getOwnPropertyNames(object);" 9955 "var names = Object.getOwnPropertyNames(object);"
8909 "names.length == 1 && names[0] == 'accessible_prop';"); 9956 "names.length == 1 && names[0] == 'accessible_prop';");
8910 CHECK(value->BooleanValue()); 9957 CHECK(value->BooleanValue(context1).FromJust());
8911 9958
8912 context1->Exit(); 9959 context1->Exit();
8913 context0->Exit(); 9960 context0->Exit();
8914 } 9961 }
8915 9962
8916 9963
8917 TEST(Regress470113) { 9964 TEST(Regress470113) {
8918 v8::Isolate* isolate = CcTest::isolate(); 9965 v8::Isolate* isolate = CcTest::isolate();
8919 v8::HandleScope handle_scope(isolate); 9966 v8::HandleScope handle_scope(isolate);
8920 v8::Handle<v8::ObjectTemplate> obj_template = 9967 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
8921 v8::ObjectTemplate::New(isolate);
8922 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); 9968 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked);
8923 LocalContext env; 9969 LocalContext env;
8924 env->Global()->Set(v8_str("prohibited"), obj_template->NewInstance()); 9970 CHECK(env->Global()
9971 ->Set(env.local(), v8_str("prohibited"),
9972 obj_template->NewInstance(env.local()).ToLocalChecked())
9973 .FromJust());
8925 9974
8926 { 9975 {
8927 v8::TryCatch try_catch(isolate); 9976 v8::TryCatch try_catch(isolate);
8928 CompileRun( 9977 CompileRun(
8929 "'use strict';\n" 9978 "'use strict';\n"
8930 "class C extends Object {\n" 9979 "class C extends Object {\n"
8931 " m() { super.powned = 'Powned!'; }\n" 9980 " m() { super.powned = 'Powned!'; }\n"
8932 "}\n" 9981 "}\n"
8933 "let c = new C();\n" 9982 "let c = new C();\n"
8934 "c.m.call(prohibited)"); 9983 "c.m.call(prohibited)");
8935 9984
8936 CHECK(try_catch.HasCaught()); 9985 CHECK(try_catch.HasCaught());
8937 } 9986 }
8938 } 9987 }
8939 9988
8940 9989
8941 static void ConstTenGetter(Local<String> name, 9990 static void ConstTenGetter(Local<String> name,
8942 const v8::PropertyCallbackInfo<v8::Value>& info) { 9991 const v8::PropertyCallbackInfo<v8::Value>& info) {
8943 info.GetReturnValue().Set(v8_num(10)); 9992 info.GetReturnValue().Set(v8_num(10));
8944 } 9993 }
8945 9994
8946 9995
8947 THREADED_TEST(CrossDomainAccessors) { 9996 THREADED_TEST(CrossDomainAccessors) {
8948 v8::Isolate* isolate = CcTest::isolate(); 9997 v8::Isolate* isolate = CcTest::isolate();
8949 v8::HandleScope handle_scope(isolate); 9998 v8::HandleScope handle_scope(isolate);
8950 9999
8951 v8::Handle<v8::FunctionTemplate> func_template = 10000 v8::Local<v8::FunctionTemplate> func_template =
8952 v8::FunctionTemplate::New(isolate); 10001 v8::FunctionTemplate::New(isolate);
8953 10002
8954 v8::Handle<v8::ObjectTemplate> global_template = 10003 v8::Local<v8::ObjectTemplate> global_template =
8955 func_template->InstanceTemplate(); 10004 func_template->InstanceTemplate();
8956 10005
8957 v8::Handle<v8::ObjectTemplate> proto_template = 10006 v8::Local<v8::ObjectTemplate> proto_template =
8958 func_template->PrototypeTemplate(); 10007 func_template->PrototypeTemplate();
8959 10008
8960 // Add an accessor to proto that's accessible by cross-domain JS code. 10009 // Add an accessor to proto that's accessible by cross-domain JS code.
8961 proto_template->SetAccessor(v8_str("accessible"), 10010 proto_template->SetAccessor(v8_str("accessible"), ConstTenGetter, 0,
8962 ConstTenGetter, 0, 10011 v8::Local<Value>(), v8::ALL_CAN_READ);
8963 v8::Handle<Value>(),
8964 v8::ALL_CAN_READ);
8965 10012
8966 // Add an accessor that is not accessible by cross-domain JS code. 10013 // Add an accessor that is not accessible by cross-domain JS code.
8967 global_template->SetAccessor(v8_str("unreachable"), 10014 global_template->SetAccessor(v8_str("unreachable"), UnreachableGetter, 0,
8968 UnreachableGetter, 0, 10015 v8::Local<Value>(), v8::DEFAULT);
8969 v8::Handle<Value>(),
8970 v8::DEFAULT);
8971 10016
8972 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 10017 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8973 context0->Enter(); 10018 context0->Enter();
8974 10019
8975 Local<v8::Object> global = context0->Global(); 10020 Local<v8::Object> global = context0->Global();
8976 // Add a normal property that shadows 'accessible' 10021 // Add a normal property that shadows 'accessible'
8977 global->Set(v8_str("accessible"), v8_num(11)); 10022 CHECK(global->Set(context0, v8_str("accessible"), v8_num(11)).FromJust());
8978 10023
8979 // Enter a new context. 10024 // Enter a new context.
8980 v8::HandleScope scope1(CcTest::isolate()); 10025 v8::HandleScope scope1(CcTest::isolate());
8981 v8::Local<Context> context1 = Context::New(isolate); 10026 v8::Local<Context> context1 = Context::New(isolate);
8982 context1->Enter(); 10027 context1->Enter();
8983 10028
8984 v8::Handle<v8::Object> global1 = context1->Global(); 10029 v8::Local<v8::Object> global1 = context1->Global();
8985 global1->Set(v8_str("other"), global); 10030 CHECK(global1->Set(context1, v8_str("other"), global).FromJust());
8986 10031
8987 // Should return 10, instead of 11 10032 // Should return 10, instead of 11
8988 v8::Handle<Value> value = v8_compile("other.accessible")->Run(); 10033 v8::Local<Value> value =
10034 v8_compile("other.accessible")->Run(context1).ToLocalChecked();
8989 CHECK(value->IsNumber()); 10035 CHECK(value->IsNumber());
8990 CHECK_EQ(10, value->Int32Value()); 10036 CHECK_EQ(10, value->Int32Value(context1).FromJust());
8991 10037
8992 value = v8_compile("other.unreachable")->Run(); 10038 v8::MaybeLocal<v8::Value> maybe_value =
8993 CHECK(value.IsEmpty()); 10039 v8_compile("other.unreachable")->Run(context1);
10040 CHECK(maybe_value.IsEmpty());
8994 10041
8995 context1->Exit(); 10042 context1->Exit();
8996 context0->Exit(); 10043 context0->Exit();
8997 } 10044 }
8998 10045
8999 10046
9000 static int access_count = 0; 10047 static int access_count = 0;
9001 10048
9002 static bool AccessCounter(Local<v8::Context> accessing_context, 10049 static bool AccessCounter(Local<v8::Context> accessing_context,
9003 Local<v8::Object> accessed_object) { 10050 Local<v8::Object> accessed_object) {
9004 access_count++; 10051 access_count++;
9005 return true; 10052 return true;
9006 } 10053 }
9007 10054
9008 10055
9009 // This one is too easily disturbed by other tests. 10056 // This one is too easily disturbed by other tests.
9010 TEST(AccessControlIC) { 10057 TEST(AccessControlIC) {
9011 access_count = 0; 10058 access_count = 0;
9012 10059
9013 v8::Isolate* isolate = CcTest::isolate(); 10060 v8::Isolate* isolate = CcTest::isolate();
9014 v8::HandleScope handle_scope(isolate); 10061 v8::HandleScope handle_scope(isolate);
9015 10062
9016 // Create an environment. 10063 // Create an environment.
9017 v8::Local<Context> context0 = Context::New(isolate); 10064 v8::Local<Context> context0 = Context::New(isolate);
9018 context0->Enter(); 10065 context0->Enter();
9019 10066
9020 // Create an object that requires access-check functions to be 10067 // Create an object that requires access-check functions to be
9021 // called for cross-domain access. 10068 // called for cross-domain access.
9022 v8::Handle<v8::ObjectTemplate> object_template = 10069 v8::Local<v8::ObjectTemplate> object_template =
9023 v8::ObjectTemplate::New(isolate); 10070 v8::ObjectTemplate::New(isolate);
9024 object_template->SetAccessCheckCallback(AccessCounter); 10071 object_template->SetAccessCheckCallback(AccessCounter);
9025 Local<v8::Object> object = object_template->NewInstance(); 10072 Local<v8::Object> object =
10073 object_template->NewInstance(context0).ToLocalChecked();
9026 10074
9027 v8::HandleScope scope1(isolate); 10075 v8::HandleScope scope1(isolate);
9028 10076
9029 // Create another environment. 10077 // Create another environment.
9030 v8::Local<Context> context1 = Context::New(isolate); 10078 v8::Local<Context> context1 = Context::New(isolate);
9031 context1->Enter(); 10079 context1->Enter();
9032 10080
9033 // Make easy access to the object from the other environment. 10081 // Make easy access to the object from the other environment.
9034 v8::Handle<v8::Object> global1 = context1->Global(); 10082 v8::Local<v8::Object> global1 = context1->Global();
9035 global1->Set(v8_str("obj"), object); 10083 CHECK(global1->Set(context1, v8_str("obj"), object).FromJust());
9036 10084
9037 v8::Handle<Value> value; 10085 v8::Local<Value> value;
9038 10086
9039 // Check that the named access-control function is called every time. 10087 // Check that the named access-control function is called every time.
9040 CompileRun("function testProp(obj) {" 10088 CompileRun("function testProp(obj) {"
9041 " for (var i = 0; i < 10; i++) obj.prop = 1;" 10089 " for (var i = 0; i < 10; i++) obj.prop = 1;"
9042 " for (var j = 0; j < 10; j++) obj.prop;" 10090 " for (var j = 0; j < 10; j++) obj.prop;"
9043 " return obj.prop" 10091 " return obj.prop"
9044 "}"); 10092 "}");
9045 value = CompileRun("testProp(obj)"); 10093 value = CompileRun("testProp(obj)");
9046 CHECK(value->IsNumber()); 10094 CHECK(value->IsNumber());
9047 CHECK_EQ(1, value->Int32Value()); 10095 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9048 CHECK_EQ(21, access_count); 10096 CHECK_EQ(21, access_count);
9049 10097
9050 // Check that the named access-control function is called every time. 10098 // Check that the named access-control function is called every time.
9051 CompileRun("var p = 'prop';" 10099 CompileRun("var p = 'prop';"
9052 "function testKeyed(obj) {" 10100 "function testKeyed(obj) {"
9053 " for (var i = 0; i < 10; i++) obj[p] = 1;" 10101 " for (var i = 0; i < 10; i++) obj[p] = 1;"
9054 " for (var j = 0; j < 10; j++) obj[p];" 10102 " for (var j = 0; j < 10; j++) obj[p];"
9055 " return obj[p];" 10103 " return obj[p];"
9056 "}"); 10104 "}");
9057 // Use obj which requires access checks. No inline caching is used 10105 // Use obj which requires access checks. No inline caching is used
9058 // in that case. 10106 // in that case.
9059 value = CompileRun("testKeyed(obj)"); 10107 value = CompileRun("testKeyed(obj)");
9060 CHECK(value->IsNumber()); 10108 CHECK(value->IsNumber());
9061 CHECK_EQ(1, value->Int32Value()); 10109 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9062 CHECK_EQ(42, access_count); 10110 CHECK_EQ(42, access_count);
9063 // Force the inline caches into generic state and try again. 10111 // Force the inline caches into generic state and try again.
9064 CompileRun("testKeyed({ a: 0 })"); 10112 CompileRun("testKeyed({ a: 0 })");
9065 CompileRun("testKeyed({ b: 0 })"); 10113 CompileRun("testKeyed({ b: 0 })");
9066 value = CompileRun("testKeyed(obj)"); 10114 value = CompileRun("testKeyed(obj)");
9067 CHECK(value->IsNumber()); 10115 CHECK(value->IsNumber());
9068 CHECK_EQ(1, value->Int32Value()); 10116 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9069 CHECK_EQ(63, access_count); 10117 CHECK_EQ(63, access_count);
9070 10118
9071 // Check that the indexed access-control function is called every time. 10119 // Check that the indexed access-control function is called every time.
9072 access_count = 0; 10120 access_count = 0;
9073 10121
9074 CompileRun("function testIndexed(obj) {" 10122 CompileRun("function testIndexed(obj) {"
9075 " for (var i = 0; i < 10; i++) obj[0] = 1;" 10123 " for (var i = 0; i < 10; i++) obj[0] = 1;"
9076 " for (var j = 0; j < 10; j++) obj[0];" 10124 " for (var j = 0; j < 10; j++) obj[0];"
9077 " return obj[0]" 10125 " return obj[0]"
9078 "}"); 10126 "}");
9079 value = CompileRun("testIndexed(obj)"); 10127 value = CompileRun("testIndexed(obj)");
9080 CHECK(value->IsNumber()); 10128 CHECK(value->IsNumber());
9081 CHECK_EQ(1, value->Int32Value()); 10129 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9082 CHECK_EQ(21, access_count); 10130 CHECK_EQ(21, access_count);
9083 // Force the inline caches into generic state. 10131 // Force the inline caches into generic state.
9084 CompileRun("testIndexed(new Array(1))"); 10132 CompileRun("testIndexed(new Array(1))");
9085 // Test that the indexed access check is called. 10133 // Test that the indexed access check is called.
9086 value = CompileRun("testIndexed(obj)"); 10134 value = CompileRun("testIndexed(obj)");
9087 CHECK(value->IsNumber()); 10135 CHECK(value->IsNumber());
9088 CHECK_EQ(1, value->Int32Value()); 10136 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9089 CHECK_EQ(42, access_count); 10137 CHECK_EQ(42, access_count);
9090 10138
9091 access_count = 0; 10139 access_count = 0;
9092 // Check that the named access check is called when invoking 10140 // Check that the named access check is called when invoking
9093 // functions on an object that requires access checks. 10141 // functions on an object that requires access checks.
9094 CompileRun("obj.f = function() {}"); 10142 CompileRun("obj.f = function() {}");
9095 CompileRun("function testCallNormal(obj) {" 10143 CompileRun("function testCallNormal(obj) {"
9096 " for (var i = 0; i < 10; i++) obj.f();" 10144 " for (var i = 0; i < 10; i++) obj.f();"
9097 "}"); 10145 "}");
9098 CompileRun("testCallNormal(obj)"); 10146 CompileRun("testCallNormal(obj)");
9099 printf("%i\n", access_count); 10147 printf("%i\n", access_count);
9100 CHECK_EQ(11, access_count); 10148 CHECK_EQ(11, access_count);
9101 10149
9102 // Force obj into slow case. 10150 // Force obj into slow case.
9103 value = CompileRun("delete obj.prop"); 10151 value = CompileRun("delete obj.prop");
9104 CHECK(value->BooleanValue()); 10152 CHECK(value->BooleanValue(context1).FromJust());
9105 // Force inline caches into dictionary probing mode. 10153 // Force inline caches into dictionary probing mode.
9106 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);"); 10154 CompileRun("var o = { x: 0 }; delete o.x; testProp(o);");
9107 // Test that the named access check is called. 10155 // Test that the named access check is called.
9108 value = CompileRun("testProp(obj);"); 10156 value = CompileRun("testProp(obj);");
9109 CHECK(value->IsNumber()); 10157 CHECK(value->IsNumber());
9110 CHECK_EQ(1, value->Int32Value()); 10158 CHECK_EQ(1, value->Int32Value(context1).FromJust());
9111 CHECK_EQ(33, access_count); 10159 CHECK_EQ(33, access_count);
9112 10160
9113 // Force the call inline cache into dictionary probing mode. 10161 // Force the call inline cache into dictionary probing mode.
9114 CompileRun("o.f = function() {}; testCallNormal(o)"); 10162 CompileRun("o.f = function() {}; testCallNormal(o)");
9115 // Test that the named access check is still called for each 10163 // Test that the named access check is still called for each
9116 // invocation of the function. 10164 // invocation of the function.
9117 value = CompileRun("testCallNormal(obj)"); 10165 value = CompileRun("testCallNormal(obj)");
9118 CHECK_EQ(43, access_count); 10166 CHECK_EQ(43, access_count);
9119 10167
9120 context1->Exit(); 10168 context1->Exit();
(...skipping 16 matching lines...) Expand all
9137 v8::Isolate* isolate = context->GetIsolate(); 10185 v8::Isolate* isolate = context->GetIsolate();
9138 v8::HandleScope handle_scope(isolate); 10186 v8::HandleScope handle_scope(isolate);
9139 10187
9140 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 10188 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9141 Local<ObjectTemplate> instance = t->InstanceTemplate(); 10189 Local<ObjectTemplate> instance = t->InstanceTemplate();
9142 10190
9143 instance->Set(v8_str("x"), v8_num(42)); 10191 instance->Set(v8_str("x"), v8_num(42));
9144 instance->Set(v8_str("f"), 10192 instance->Set(v8_str("f"),
9145 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback)); 10193 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback));
9146 10194
9147 Local<Value> o = t->GetFunction()->NewInstance(); 10195 Local<Value> o = t->GetFunction(context.local())
10196 .ToLocalChecked()
10197 ->NewInstance(context.local())
10198 .ToLocalChecked();
9148 10199
9149 context->Global()->Set(v8_str("i"), o); 10200 CHECK(context->Global()->Set(context.local(), v8_str("i"), o).FromJust());
9150 Local<Value> value = CompileRun("i.x"); 10201 Local<Value> value = CompileRun("i.x");
9151 CHECK_EQ(42, value->Int32Value()); 10202 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
9152 10203
9153 value = CompileRun("i.f()"); 10204 value = CompileRun("i.f()");
9154 CHECK_EQ(12, value->Int32Value()); 10205 CHECK_EQ(12, value->Int32Value(context.local()).FromJust());
9155 } 10206 }
9156 10207
9157 10208
9158 static void GlobalObjectInstancePropertiesGet( 10209 static void GlobalObjectInstancePropertiesGet(
9159 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) { 10210 Local<Name> key, const v8::PropertyCallbackInfo<v8::Value>&) {
9160 ApiTestFuzzer::Fuzz(); 10211 ApiTestFuzzer::Fuzz();
9161 } 10212 }
9162 10213
9163 10214
9164 THREADED_TEST(GlobalObjectInstanceProperties) { 10215 THREADED_TEST(GlobalObjectInstanceProperties) {
(...skipping 27 matching lines...) Expand all
9192 "try { wrapper(true); } catch (e) { thrown = 1; };" 10243 "try { wrapper(true); } catch (e) { thrown = 1; };"
9193 "thrown"; 10244 "thrown";
9194 10245
9195 { 10246 {
9196 LocalContext env(NULL, instance_template); 10247 LocalContext env(NULL, instance_template);
9197 // Hold on to the global object so it can be used again in another 10248 // Hold on to the global object so it can be used again in another
9198 // environment initialization. 10249 // environment initialization.
9199 global_object = env->Global(); 10250 global_object = env->Global();
9200 10251
9201 Local<Value> value = CompileRun("x"); 10252 Local<Value> value = CompileRun("x");
9202 CHECK_EQ(42, value->Int32Value()); 10253 CHECK_EQ(42, value->Int32Value(env.local()).FromJust());
9203 value = CompileRun("f()"); 10254 value = CompileRun("f()");
9204 CHECK_EQ(12, value->Int32Value()); 10255 CHECK_EQ(12, value->Int32Value(env.local()).FromJust());
9205 value = CompileRun(script); 10256 value = CompileRun(script);
9206 CHECK_EQ(1, value->Int32Value()); 10257 CHECK_EQ(1, value->Int32Value(env.local()).FromJust());
9207 } 10258 }
9208 10259
9209 { 10260 {
9210 // Create new environment reusing the global object. 10261 // Create new environment reusing the global object.
9211 LocalContext env(NULL, instance_template, global_object); 10262 LocalContext env(NULL, instance_template, global_object);
9212 Local<Value> value = CompileRun("x"); 10263 Local<Value> value = CompileRun("x");
9213 CHECK_EQ(42, value->Int32Value()); 10264 CHECK_EQ(42, value->Int32Value(env.local()).FromJust());
9214 value = CompileRun("f()"); 10265 value = CompileRun("f()");
9215 CHECK_EQ(12, value->Int32Value()); 10266 CHECK_EQ(12, value->Int32Value(env.local()).FromJust());
9216 value = CompileRun(script); 10267 value = CompileRun(script);
9217 CHECK_EQ(1, value->Int32Value()); 10268 CHECK_EQ(1, value->Int32Value(env.local()).FromJust());
9218 } 10269 }
9219 } 10270 }
9220 10271
9221 10272
9222 THREADED_TEST(CallKnownGlobalReceiver) { 10273 THREADED_TEST(CallKnownGlobalReceiver) {
9223 v8::Isolate* isolate = CcTest::isolate(); 10274 v8::Isolate* isolate = CcTest::isolate();
9224 v8::HandleScope handle_scope(isolate); 10275 v8::HandleScope handle_scope(isolate);
9225 10276
9226 Local<Value> global_object; 10277 Local<Value> global_object;
9227 10278
(...skipping 19 matching lines...) Expand all
9247 LocalContext env(NULL, instance_template); 10298 LocalContext env(NULL, instance_template);
9248 // Hold on to the global object so it can be used again in another 10299 // Hold on to the global object so it can be used again in another
9249 // environment initialization. 10300 // environment initialization.
9250 global_object = env->Global(); 10301 global_object = env->Global();
9251 foo = CompileRun(script); 10302 foo = CompileRun(script);
9252 } 10303 }
9253 10304
9254 { 10305 {
9255 // Create new environment reusing the global object. 10306 // Create new environment reusing the global object.
9256 LocalContext env(NULL, instance_template, global_object); 10307 LocalContext env(NULL, instance_template, global_object);
9257 env->Global()->Set(v8_str("foo"), foo); 10308 CHECK(env->Global()->Set(env.local(), v8_str("foo"), foo).FromJust());
9258 CompileRun("foo()"); 10309 CompileRun("foo()");
9259 } 10310 }
9260 } 10311 }
9261 10312
9262 10313
9263 static void ShadowFunctionCallback( 10314 static void ShadowFunctionCallback(
9264 const v8::FunctionCallbackInfo<v8::Value>& args) { 10315 const v8::FunctionCallbackInfo<v8::Value>& args) {
9265 ApiTestFuzzer::Fuzz(); 10316 ApiTestFuzzer::Fuzz();
9266 args.GetReturnValue().Set(v8_num(42)); 10317 args.GetReturnValue().Set(v8_num(42));
9267 } 10318 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
9314 Local<ObjectTemplate> instance = t->InstanceTemplate(); 10365 Local<ObjectTemplate> instance = t->InstanceTemplate();
9315 10366
9316 proto->Set(v8_str("f"), 10367 proto->Set(v8_str("f"),
9317 v8::FunctionTemplate::New(isolate, 10368 v8::FunctionTemplate::New(isolate,
9318 ShadowFunctionCallback, 10369 ShadowFunctionCallback,
9319 Local<Value>())); 10370 Local<Value>()));
9320 proto->Set(v8_str("x"), v8_num(12)); 10371 proto->Set(v8_str("x"), v8_num(12));
9321 10372
9322 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); 10373 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter);
9323 10374
9324 Local<Value> o = t->GetFunction()->NewInstance(); 10375 Local<Value> o = t->GetFunction(context.local())
9325 context->Global()->Set(v8_str("__proto__"), o); 10376 .ToLocalChecked()
10377 ->NewInstance(context.local())
10378 .ToLocalChecked();
10379 CHECK(context->Global()
10380 ->Set(context.local(), v8_str("__proto__"), o)
10381 .FromJust());
9326 10382
9327 Local<Value> value = 10383 Local<Value> value =
9328 CompileRun("this.propertyIsEnumerable(0)"); 10384 CompileRun("this.propertyIsEnumerable(0)");
9329 CHECK(value->IsBoolean()); 10385 CHECK(value->IsBoolean());
9330 CHECK(!value->BooleanValue()); 10386 CHECK(!value->BooleanValue(context.local()).FromJust());
9331 10387
9332 value = CompileRun("x"); 10388 value = CompileRun("x");
9333 CHECK_EQ(12, value->Int32Value()); 10389 CHECK_EQ(12, value->Int32Value(context.local()).FromJust());
9334 10390
9335 value = CompileRun("f()"); 10391 value = CompileRun("f()");
9336 CHECK_EQ(42, value->Int32Value()); 10392 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
9337 10393
9338 CompileRun("y = 43"); 10394 CompileRun("y = 43");
9339 CHECK_EQ(1, shadow_y_setter_call_count); 10395 CHECK_EQ(1, shadow_y_setter_call_count);
9340 value = CompileRun("y"); 10396 value = CompileRun("y");
9341 CHECK_EQ(1, shadow_y_getter_call_count); 10397 CHECK_EQ(1, shadow_y_getter_call_count);
9342 CHECK_EQ(42, value->Int32Value()); 10398 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
9343 } 10399 }
9344 10400
9345 10401
9346 THREADED_TEST(HiddenPrototype) { 10402 THREADED_TEST(HiddenPrototype) {
9347 LocalContext context; 10403 LocalContext context;
9348 v8::Isolate* isolate = context->GetIsolate(); 10404 v8::Isolate* isolate = context->GetIsolate();
9349 v8::HandleScope handle_scope(isolate); 10405 v8::HandleScope handle_scope(isolate);
9350 10406
9351 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); 10407 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
9352 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 10408 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9353 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10409 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9354 t1->SetHiddenPrototype(true); 10410 t1->SetHiddenPrototype(true);
9355 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 10411 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
9356 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10412 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9357 t2->SetHiddenPrototype(true); 10413 t2->SetHiddenPrototype(true);
9358 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 10414 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
9359 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10415 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
9360 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); 10416 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3));
9361 10417
9362 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); 10418 Local<v8::Object> o0 = t0->GetFunction(context.local())
9363 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10419 .ToLocalChecked()
9364 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10420 ->NewInstance(context.local())
9365 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 10421 .ToLocalChecked();
10422 Local<v8::Object> o1 = t1->GetFunction(context.local())
10423 .ToLocalChecked()
10424 ->NewInstance(context.local())
10425 .ToLocalChecked();
10426 Local<v8::Object> o2 = t2->GetFunction(context.local())
10427 .ToLocalChecked()
10428 ->NewInstance(context.local())
10429 .ToLocalChecked();
10430 Local<v8::Object> o3 = t3->GetFunction(context.local())
10431 .ToLocalChecked()
10432 ->NewInstance(context.local())
10433 .ToLocalChecked();
9366 10434
9367 // Setting the prototype on an object skips hidden prototypes. 10435 // Setting the prototype on an object skips hidden prototypes.
9368 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10436 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
9369 o0->Set(v8_str("__proto__"), o1); 10437 .ToLocalChecked()
9370 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10438 ->Int32Value(context.local())
9371 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10439 .FromJust());
9372 o0->Set(v8_str("__proto__"), o2); 10440 CHECK(o0->Set(context.local(), v8_str("__proto__"), o1).FromJust());
9373 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10441 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
9374 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10442 .ToLocalChecked()
9375 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); 10443 ->Int32Value(context.local())
9376 o0->Set(v8_str("__proto__"), o3); 10444 .FromJust());
9377 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10445 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
9378 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10446 .ToLocalChecked()
9379 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); 10447 ->Int32Value(context.local())
9380 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); 10448 .FromJust());
10449 CHECK(o0->Set(context.local(), v8_str("__proto__"), o2).FromJust());
10450 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
10451 .ToLocalChecked()
10452 ->Int32Value(context.local())
10453 .FromJust());
10454 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
10455 .ToLocalChecked()
10456 ->Int32Value(context.local())
10457 .FromJust());
10458 CHECK_EQ(2, o0->Get(context.local(), v8_str("z"))
10459 .ToLocalChecked()
10460 ->Int32Value(context.local())
10461 .FromJust());
10462 CHECK(o0->Set(context.local(), v8_str("__proto__"), o3).FromJust());
10463 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
10464 .ToLocalChecked()
10465 ->Int32Value(context.local())
10466 .FromJust());
10467 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
10468 .ToLocalChecked()
10469 ->Int32Value(context.local())
10470 .FromJust());
10471 CHECK_EQ(2, o0->Get(context.local(), v8_str("z"))
10472 .ToLocalChecked()
10473 ->Int32Value(context.local())
10474 .FromJust());
10475 CHECK_EQ(3, o0->Get(context.local(), v8_str("u"))
10476 .ToLocalChecked()
10477 ->Int32Value(context.local())
10478 .FromJust());
9381 10479
9382 // Getting the prototype of o0 should get the first visible one 10480 // Getting the prototype of o0 should get the first visible one
9383 // which is o3. Therefore, z should not be defined on the prototype 10481 // which is o3. Therefore, z should not be defined on the prototype
9384 // object. 10482 // object.
9385 Local<Value> proto = o0->Get(v8_str("__proto__")); 10483 Local<Value> proto =
10484 o0->Get(context.local(), v8_str("__proto__")).ToLocalChecked();
9386 CHECK(proto->IsObject()); 10485 CHECK(proto->IsObject());
9387 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); 10486 CHECK(proto.As<v8::Object>()
10487 ->Get(context.local(), v8_str("z"))
10488 .ToLocalChecked()
10489 ->IsUndefined());
9388 } 10490 }
9389 10491
9390 10492
9391 THREADED_TEST(HiddenPrototypeSet) { 10493 THREADED_TEST(HiddenPrototypeSet) {
9392 LocalContext context; 10494 LocalContext context;
9393 v8::Isolate* isolate = context->GetIsolate(); 10495 v8::Isolate* isolate = context->GetIsolate();
9394 v8::HandleScope handle_scope(isolate); 10496 v8::HandleScope handle_scope(isolate);
9395 10497
9396 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate); 10498 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate);
9397 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate); 10499 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate);
9398 ht->SetHiddenPrototype(true); 10500 ht->SetHiddenPrototype(true);
9399 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate); 10501 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate);
9400 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 10502 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9401 10503
9402 Local<v8::Object> o = ot->GetFunction()->NewInstance(); 10504 Local<v8::Object> o = ot->GetFunction(context.local())
9403 Local<v8::Object> h = ht->GetFunction()->NewInstance(); 10505 .ToLocalChecked()
9404 Local<v8::Object> p = pt->GetFunction()->NewInstance(); 10506 ->NewInstance(context.local())
9405 o->Set(v8_str("__proto__"), h); 10507 .ToLocalChecked();
9406 h->Set(v8_str("__proto__"), p); 10508 Local<v8::Object> h = ht->GetFunction(context.local())
10509 .ToLocalChecked()
10510 ->NewInstance(context.local())
10511 .ToLocalChecked();
10512 Local<v8::Object> p = pt->GetFunction(context.local())
10513 .ToLocalChecked()
10514 ->NewInstance(context.local())
10515 .ToLocalChecked();
10516 CHECK(o->Set(context.local(), v8_str("__proto__"), h).FromJust());
10517 CHECK(h->Set(context.local(), v8_str("__proto__"), p).FromJust());
9407 10518
9408 // Setting a property that exists on the hidden prototype goes there. 10519 // Setting a property that exists on the hidden prototype goes there.
9409 o->Set(v8_str("x"), v8_num(7)); 10520 CHECK(o->Set(context.local(), v8_str("x"), v8_num(7)).FromJust());
9410 CHECK_EQ(7, o->Get(v8_str("x"))->Int32Value()); 10521 CHECK_EQ(7, o->Get(context.local(), v8_str("x"))
9411 CHECK_EQ(7, h->Get(v8_str("x"))->Int32Value()); 10522 .ToLocalChecked()
9412 CHECK(p->Get(v8_str("x"))->IsUndefined()); 10523 ->Int32Value(context.local())
10524 .FromJust());
10525 CHECK_EQ(7, h->Get(context.local(), v8_str("x"))
10526 .ToLocalChecked()
10527 ->Int32Value(context.local())
10528 .FromJust());
10529 CHECK(p->Get(context.local(), v8_str("x")).ToLocalChecked()->IsUndefined());
9413 10530
9414 // Setting a new property should not be forwarded to the hidden prototype. 10531 // Setting a new property should not be forwarded to the hidden prototype.
9415 o->Set(v8_str("y"), v8_num(6)); 10532 CHECK(o->Set(context.local(), v8_str("y"), v8_num(6)).FromJust());
9416 CHECK_EQ(6, o->Get(v8_str("y"))->Int32Value()); 10533 CHECK_EQ(6, o->Get(context.local(), v8_str("y"))
9417 CHECK(h->Get(v8_str("y"))->IsUndefined()); 10534 .ToLocalChecked()
9418 CHECK(p->Get(v8_str("y"))->IsUndefined()); 10535 ->Int32Value(context.local())
10536 .FromJust());
10537 CHECK(h->Get(context.local(), v8_str("y")).ToLocalChecked()->IsUndefined());
10538 CHECK(p->Get(context.local(), v8_str("y")).ToLocalChecked()->IsUndefined());
9419 10539
9420 // Setting a property that only exists on a prototype of the hidden prototype 10540 // Setting a property that only exists on a prototype of the hidden prototype
9421 // is treated normally again. 10541 // is treated normally again.
9422 p->Set(v8_str("z"), v8_num(8)); 10542 CHECK(p->Set(context.local(), v8_str("z"), v8_num(8)).FromJust());
9423 CHECK_EQ(8, o->Get(v8_str("z"))->Int32Value()); 10543 CHECK_EQ(8, o->Get(context.local(), v8_str("z"))
9424 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); 10544 .ToLocalChecked()
9425 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 10545 ->Int32Value(context.local())
9426 o->Set(v8_str("z"), v8_num(9)); 10546 .FromJust());
9427 CHECK_EQ(9, o->Get(v8_str("z"))->Int32Value()); 10547 CHECK_EQ(8, h->Get(context.local(), v8_str("z"))
9428 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); 10548 .ToLocalChecked()
9429 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 10549 ->Int32Value(context.local())
10550 .FromJust());
10551 CHECK_EQ(8, p->Get(context.local(), v8_str("z"))
10552 .ToLocalChecked()
10553 ->Int32Value(context.local())
10554 .FromJust());
10555 CHECK(o->Set(context.local(), v8_str("z"), v8_num(9)).FromJust());
10556 CHECK_EQ(9, o->Get(context.local(), v8_str("z"))
10557 .ToLocalChecked()
10558 ->Int32Value(context.local())
10559 .FromJust());
10560 CHECK_EQ(8, h->Get(context.local(), v8_str("z"))
10561 .ToLocalChecked()
10562 ->Int32Value(context.local())
10563 .FromJust());
10564 CHECK_EQ(8, p->Get(context.local(), v8_str("z"))
10565 .ToLocalChecked()
10566 ->Int32Value(context.local())
10567 .FromJust());
9430 } 10568 }
9431 10569
9432 10570
9433 // Regression test for issue 2457. 10571 // Regression test for issue 2457.
9434 THREADED_TEST(HiddenPrototypeIdentityHash) { 10572 THREADED_TEST(HiddenPrototypeIdentityHash) {
9435 LocalContext context; 10573 LocalContext context;
9436 v8::HandleScope handle_scope(context->GetIsolate()); 10574 v8::HandleScope handle_scope(context->GetIsolate());
9437 10575
9438 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate()); 10576 Local<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate());
9439 t->SetHiddenPrototype(true); 10577 t->SetHiddenPrototype(true);
9440 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 10578 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
9441 Handle<Object> p = t->GetFunction()->NewInstance(); 10579 Local<Object> p = t->GetFunction(context.local())
9442 Handle<Object> o = Object::New(context->GetIsolate()); 10580 .ToLocalChecked()
9443 o->SetPrototype(p); 10581 ->NewInstance(context.local())
10582 .ToLocalChecked();
10583 Local<Object> o = Object::New(context->GetIsolate());
10584 CHECK(o->SetPrototype(context.local(), p).FromJust());
9444 10585
9445 int hash = o->GetIdentityHash(); 10586 int hash = o->GetIdentityHash();
9446 USE(hash); 10587 USE(hash);
9447 o->Set(v8_str("foo"), v8_num(42)); 10588 CHECK(o->Set(context.local(), v8_str("foo"), v8_num(42)).FromJust());
9448 DCHECK_EQ(hash, o->GetIdentityHash()); 10589 DCHECK_EQ(hash, o->GetIdentityHash());
9449 } 10590 }
9450 10591
9451 10592
9452 THREADED_TEST(SetPrototype) { 10593 THREADED_TEST(SetPrototype) {
9453 LocalContext context; 10594 LocalContext context;
9454 v8::Isolate* isolate = context->GetIsolate(); 10595 v8::Isolate* isolate = context->GetIsolate();
9455 v8::HandleScope handle_scope(isolate); 10596 v8::HandleScope handle_scope(isolate);
9456 10597
9457 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate); 10598 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
9458 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 10599 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9459 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10600 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9460 t1->SetHiddenPrototype(true); 10601 t1->SetHiddenPrototype(true);
9461 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 10602 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
9462 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10603 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9463 t2->SetHiddenPrototype(true); 10604 t2->SetHiddenPrototype(true);
9464 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 10605 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
9465 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate); 10606 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
9466 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); 10607 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3));
9467 10608
9468 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); 10609 Local<v8::Object> o0 = t0->GetFunction(context.local())
9469 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10610 .ToLocalChecked()
9470 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10611 ->NewInstance(context.local())
9471 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 10612 .ToLocalChecked();
10613 Local<v8::Object> o1 = t1->GetFunction(context.local())
10614 .ToLocalChecked()
10615 ->NewInstance(context.local())
10616 .ToLocalChecked();
10617 Local<v8::Object> o2 = t2->GetFunction(context.local())
10618 .ToLocalChecked()
10619 ->NewInstance(context.local())
10620 .ToLocalChecked();
10621 Local<v8::Object> o3 = t3->GetFunction(context.local())
10622 .ToLocalChecked()
10623 ->NewInstance(context.local())
10624 .ToLocalChecked();
9472 10625
9473 // Setting the prototype on an object does not skip hidden prototypes. 10626 // Setting the prototype on an object does not skip hidden prototypes.
9474 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10627 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
9475 CHECK(o0->SetPrototype(o1)); 10628 .ToLocalChecked()
9476 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10629 ->Int32Value(context.local())
9477 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10630 .FromJust());
9478 CHECK(o1->SetPrototype(o2)); 10631 CHECK(o0->SetPrototype(context.local(), o1).FromJust());
9479 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10632 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
9480 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10633 .ToLocalChecked()
9481 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); 10634 ->Int32Value(context.local())
9482 CHECK(o2->SetPrototype(o3)); 10635 .FromJust());
9483 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 10636 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
9484 CHECK_EQ(1, o0->Get(v8_str("y"))->Int32Value()); 10637 .ToLocalChecked()
9485 CHECK_EQ(2, o0->Get(v8_str("z"))->Int32Value()); 10638 ->Int32Value(context.local())
9486 CHECK_EQ(3, o0->Get(v8_str("u"))->Int32Value()); 10639 .FromJust());
10640 CHECK(o1->SetPrototype(context.local(), o2).FromJust());
10641 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
10642 .ToLocalChecked()
10643 ->Int32Value(context.local())
10644 .FromJust());
10645 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
10646 .ToLocalChecked()
10647 ->Int32Value(context.local())
10648 .FromJust());
10649 CHECK_EQ(2, o0->Get(context.local(), v8_str("z"))
10650 .ToLocalChecked()
10651 ->Int32Value(context.local())
10652 .FromJust());
10653 CHECK(o2->SetPrototype(context.local(), o3).FromJust());
10654 CHECK_EQ(0, o0->Get(context.local(), v8_str("x"))
10655 .ToLocalChecked()
10656 ->Int32Value(context.local())
10657 .FromJust());
10658 CHECK_EQ(1, o0->Get(context.local(), v8_str("y"))
10659 .ToLocalChecked()
10660 ->Int32Value(context.local())
10661 .FromJust());
10662 CHECK_EQ(2, o0->Get(context.local(), v8_str("z"))
10663 .ToLocalChecked()
10664 ->Int32Value(context.local())
10665 .FromJust());
10666 CHECK_EQ(3, o0->Get(context.local(), v8_str("u"))
10667 .ToLocalChecked()
10668 ->Int32Value(context.local())
10669 .FromJust());
9487 10670
9488 // Getting the prototype of o0 should get the first visible one 10671 // Getting the prototype of o0 should get the first visible one
9489 // which is o3. Therefore, z should not be defined on the prototype 10672 // which is o3. Therefore, z should not be defined on the prototype
9490 // object. 10673 // object.
9491 Local<Value> proto = o0->Get(v8_str("__proto__")); 10674 Local<Value> proto =
10675 o0->Get(context.local(), v8_str("__proto__")).ToLocalChecked();
9492 CHECK(proto->IsObject()); 10676 CHECK(proto->IsObject());
9493 CHECK(proto.As<v8::Object>()->Equals(o3)); 10677 CHECK(proto.As<v8::Object>()->Equals(context.local(), o3).FromJust());
9494 10678
9495 // However, Object::GetPrototype ignores hidden prototype. 10679 // However, Object::GetPrototype ignores hidden prototype.
9496 Local<Value> proto0 = o0->GetPrototype(); 10680 Local<Value> proto0 = o0->GetPrototype();
9497 CHECK(proto0->IsObject()); 10681 CHECK(proto0->IsObject());
9498 CHECK(proto0.As<v8::Object>()->Equals(o1)); 10682 CHECK(proto0.As<v8::Object>()->Equals(context.local(), o1).FromJust());
9499 10683
9500 Local<Value> proto1 = o1->GetPrototype(); 10684 Local<Value> proto1 = o1->GetPrototype();
9501 CHECK(proto1->IsObject()); 10685 CHECK(proto1->IsObject());
9502 CHECK(proto1.As<v8::Object>()->Equals(o2)); 10686 CHECK(proto1.As<v8::Object>()->Equals(context.local(), o2).FromJust());
9503 10687
9504 Local<Value> proto2 = o2->GetPrototype(); 10688 Local<Value> proto2 = o2->GetPrototype();
9505 CHECK(proto2->IsObject()); 10689 CHECK(proto2->IsObject());
9506 CHECK(proto2.As<v8::Object>()->Equals(o3)); 10690 CHECK(proto2.As<v8::Object>()->Equals(context.local(), o3).FromJust());
9507 } 10691 }
9508 10692
9509 10693
9510 // Getting property names of an object with a prototype chain that 10694 // Getting property names of an object with a prototype chain that
9511 // triggers dictionary elements in GetOwnPropertyNames() shouldn't 10695 // triggers dictionary elements in GetOwnPropertyNames() shouldn't
9512 // crash the runtime. 10696 // crash the runtime.
9513 THREADED_TEST(Regress91517) { 10697 THREADED_TEST(Regress91517) {
9514 i::FLAG_allow_natives_syntax = true; 10698 i::FLAG_allow_natives_syntax = true;
9515 LocalContext context; 10699 LocalContext context;
9516 v8::Isolate* isolate = context->GetIsolate(); 10700 v8::Isolate* isolate = context->GetIsolate();
(...skipping 13 matching lines...) Expand all
9530 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate); 10714 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
9531 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10715 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
9532 10716
9533 // Force dictionary-based properties. 10717 // Force dictionary-based properties.
9534 i::ScopedVector<char> name_buf(1024); 10718 i::ScopedVector<char> name_buf(1024);
9535 for (int i = 1; i <= 1000; i++) { 10719 for (int i = 1; i <= 1000; i++) {
9536 i::SNPrintF(name_buf, "sdf%d", i); 10720 i::SNPrintF(name_buf, "sdf%d", i);
9537 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); 10721 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2));
9538 } 10722 }
9539 10723
9540 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10724 Local<v8::Object> o1 = t1->GetFunction(context.local())
9541 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10725 .ToLocalChecked()
9542 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 10726 ->NewInstance(context.local())
9543 Local<v8::Object> o4 = t4->GetFunction()->NewInstance(); 10727 .ToLocalChecked();
10728 Local<v8::Object> o2 = t2->GetFunction(context.local())
10729 .ToLocalChecked()
10730 ->NewInstance(context.local())
10731 .ToLocalChecked();
10732 Local<v8::Object> o3 = t3->GetFunction(context.local())
10733 .ToLocalChecked()
10734 ->NewInstance(context.local())
10735 .ToLocalChecked();
10736 Local<v8::Object> o4 = t4->GetFunction(context.local())
10737 .ToLocalChecked()
10738 ->NewInstance(context.local())
10739 .ToLocalChecked();
9544 10740
9545 // Create prototype chain of hidden prototypes. 10741 // Create prototype chain of hidden prototypes.
9546 CHECK(o4->SetPrototype(o3)); 10742 CHECK(o4->SetPrototype(context.local(), o3).FromJust());
9547 CHECK(o3->SetPrototype(o2)); 10743 CHECK(o3->SetPrototype(context.local(), o2).FromJust());
9548 CHECK(o2->SetPrototype(o1)); 10744 CHECK(o2->SetPrototype(context.local(), o1).FromJust());
9549 10745
9550 // Call the runtime version of GetOwnPropertyNames() on the natively 10746 // Call the runtime version of GetOwnPropertyNames() on the natively
9551 // created object through JavaScript. 10747 // created object through JavaScript.
9552 context->Global()->Set(v8_str("obj"), o4); 10748 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o4).FromJust());
9553 // PROPERTY_ATTRIBUTES_NONE = 0 10749 // PROPERTY_ATTRIBUTES_NONE = 0
9554 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); 10750 CompileRun("var names = %GetOwnPropertyNames(obj, 0);");
9555 10751
9556 ExpectInt32("names.length", 1006); 10752 ExpectInt32("names.length", 1006);
9557 ExpectTrue("names.indexOf(\"baz\") >= 0"); 10753 ExpectTrue("names.indexOf(\"baz\") >= 0");
9558 ExpectTrue("names.indexOf(\"boo\") >= 0"); 10754 ExpectTrue("names.indexOf(\"boo\") >= 0");
9559 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10755 ExpectTrue("names.indexOf(\"foo\") >= 0");
9560 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 10756 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
9561 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 10757 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
9562 ExpectFalse("names[1005] == undefined"); 10758 ExpectFalse("names[1005] == undefined");
(...skipping 14 matching lines...) Expand all
9577 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate(); 10773 Local<v8::ObjectTemplate> i1 = t1->InstanceTemplate();
9578 i1->SetAccessor(v8_str("foo"), 10774 i1->SetAccessor(v8_str("foo"),
9579 SimpleAccessorGetter, SimpleAccessorSetter); 10775 SimpleAccessorGetter, SimpleAccessorSetter);
9580 i1->SetAccessor(v8_str("bar"), 10776 i1->SetAccessor(v8_str("bar"),
9581 SimpleAccessorGetter, SimpleAccessorSetter); 10777 SimpleAccessorGetter, SimpleAccessorSetter);
9582 i1->SetAccessor(v8_str("baz"), 10778 i1->SetAccessor(v8_str("baz"),
9583 SimpleAccessorGetter, SimpleAccessorSetter); 10779 SimpleAccessorGetter, SimpleAccessorSetter);
9584 i1->Set(v8_str("n1"), v8_num(1)); 10780 i1->Set(v8_str("n1"), v8_num(1));
9585 i1->Set(v8_str("n2"), v8_num(2)); 10781 i1->Set(v8_str("n2"), v8_num(2));
9586 10782
9587 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10783 Local<v8::Object> o1 = t1->GetFunction(context.local())
10784 .ToLocalChecked()
10785 ->NewInstance(context.local())
10786 .ToLocalChecked();
9588 Local<v8::FunctionTemplate> t2 = 10787 Local<v8::FunctionTemplate> t2 =
9589 v8::FunctionTemplate::New(context->GetIsolate()); 10788 v8::FunctionTemplate::New(context->GetIsolate());
9590 t2->SetHiddenPrototype(true); 10789 t2->SetHiddenPrototype(true);
9591 10790
9592 // Inherit from t1 and mark prototype as hidden. 10791 // Inherit from t1 and mark prototype as hidden.
9593 t2->Inherit(t1); 10792 t2->Inherit(t1);
9594 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4)); 10793 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4));
9595 10794
9596 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 10795 Local<v8::Object> o2 = t2->GetFunction(context.local())
9597 CHECK(o2->SetPrototype(o1)); 10796 .ToLocalChecked()
10797 ->NewInstance(context.local())
10798 .ToLocalChecked();
10799 CHECK(o2->SetPrototype(context.local(), o1).FromJust());
9598 10800
9599 v8::Local<v8::Symbol> sym = 10801 v8::Local<v8::Symbol> sym =
9600 v8::Symbol::New(context->GetIsolate(), v8_str("s1")); 10802 v8::Symbol::New(context->GetIsolate(), v8_str("s1"));
9601 o1->Set(sym, v8_num(3)); 10803 CHECK(o1->Set(context.local(), sym, v8_num(3)).FromJust());
9602 o1->SetPrivate(context.local(), 10804 o1->SetPrivate(context.local(),
9603 v8::Private::New(context->GetIsolate(), v8_str("h1")), 10805 v8::Private::New(context->GetIsolate(), v8_str("h1")),
9604 v8::Integer::New(context->GetIsolate(), 2013)) 10806 v8::Integer::New(context->GetIsolate(), 2013))
9605 .FromJust(); 10807 .FromJust();
9606 10808
9607 // Call the runtime version of GetOwnPropertyNames() on 10809 // Call the runtime version of GetOwnPropertyNames() on
9608 // the natively created object through JavaScript. 10810 // the natively created object through JavaScript.
9609 context->Global()->Set(v8_str("obj"), o2); 10811 CHECK(context->Global()->Set(context.local(), v8_str("obj"), o2).FromJust());
9610 context->Global()->Set(v8_str("sym"), sym); 10812 CHECK(context->Global()->Set(context.local(), v8_str("sym"), sym).FromJust());
9611 // PROPERTY_ATTRIBUTES_NONE = 0 10813 // PROPERTY_ATTRIBUTES_NONE = 0
9612 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); 10814 CompileRun("var names = %GetOwnPropertyNames(obj, 0);");
9613 10815
9614 ExpectInt32("names.length", 7); 10816 ExpectInt32("names.length", 7);
9615 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10817 ExpectTrue("names.indexOf(\"foo\") >= 0");
9616 ExpectTrue("names.indexOf(\"bar\") >= 0"); 10818 ExpectTrue("names.indexOf(\"bar\") >= 0");
9617 ExpectTrue("names.indexOf(\"baz\") >= 0"); 10819 ExpectTrue("names.indexOf(\"baz\") >= 0");
9618 ExpectTrue("names.indexOf(\"n1\") >= 0"); 10820 ExpectTrue("names.indexOf(\"n1\") >= 0");
9619 ExpectTrue("names.indexOf(\"n2\") >= 0"); 10821 ExpectTrue("names.indexOf(\"n2\") >= 0");
9620 ExpectTrue("names.indexOf(sym) >= 0"); 10822 ExpectTrue("names.indexOf(sym) >= 0");
9621 ExpectTrue("names.indexOf(\"mine\") >= 0"); 10823 ExpectTrue("names.indexOf(\"mine\") >= 0");
9622 } 10824 }
9623 10825
9624 10826
9625 THREADED_TEST(FunctionReadOnlyPrototype) { 10827 THREADED_TEST(FunctionReadOnlyPrototype) {
9626 LocalContext context; 10828 LocalContext context;
9627 v8::Isolate* isolate = context->GetIsolate(); 10829 v8::Isolate* isolate = context->GetIsolate();
9628 v8::HandleScope handle_scope(isolate); 10830 v8::HandleScope handle_scope(isolate);
9629 10831
9630 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10832 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9631 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 10833 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42));
9632 t1->ReadOnlyPrototype(); 10834 t1->ReadOnlyPrototype();
9633 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 10835 CHECK(context->Global()
10836 ->Set(context.local(), v8_str("func1"),
10837 t1->GetFunction(context.local()).ToLocalChecked())
10838 .FromJust());
9634 // Configured value of ReadOnly flag. 10839 // Configured value of ReadOnly flag.
9635 CHECK(CompileRun( 10840 CHECK(
9636 "(function() {" 10841 CompileRun(
9637 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 10842 "(function() {"
9638 " return (descriptor['writable'] == false);" 10843 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
9639 "})()")->BooleanValue()); 10844 " return (descriptor['writable'] == false);"
9640 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 10845 "})()")
9641 CHECK_EQ(42, 10846 ->BooleanValue(context.local())
9642 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 10847 .FromJust());
10848 CHECK_EQ(
10849 42,
10850 CompileRun("func1.prototype.x")->Int32Value(context.local()).FromJust());
10851 CHECK_EQ(42, CompileRun("func1.prototype = {}; func1.prototype.x")
10852 ->Int32Value(context.local())
10853 .FromJust());
9643 10854
9644 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate); 10855 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9645 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 10856 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(isolate, 42));
9646 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 10857 CHECK(context->Global()
10858 ->Set(context.local(), v8_str("func2"),
10859 t2->GetFunction(context.local()).ToLocalChecked())
10860 .FromJust());
9647 // Default value of ReadOnly flag. 10861 // Default value of ReadOnly flag.
9648 CHECK(CompileRun( 10862 CHECK(
9649 "(function() {" 10863 CompileRun(
9650 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 10864 "(function() {"
9651 " return (descriptor['writable'] == true);" 10865 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
9652 "})()")->BooleanValue()); 10866 " return (descriptor['writable'] == true);"
9653 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 10867 "})()")
10868 ->BooleanValue(context.local())
10869 .FromJust());
10870 CHECK_EQ(
10871 42,
10872 CompileRun("func2.prototype.x")->Int32Value(context.local()).FromJust());
9654 } 10873 }
9655 10874
9656 10875
9657 THREADED_TEST(SetPrototypeThrows) { 10876 THREADED_TEST(SetPrototypeThrows) {
9658 LocalContext context; 10877 LocalContext context;
9659 v8::Isolate* isolate = context->GetIsolate(); 10878 v8::Isolate* isolate = context->GetIsolate();
9660 v8::HandleScope handle_scope(isolate); 10879 v8::HandleScope handle_scope(isolate);
9661 10880
9662 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 10881 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9663 10882
9664 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 10883 Local<v8::Object> o0 = t->GetFunction(context.local())
9665 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 10884 .ToLocalChecked()
10885 ->NewInstance(context.local())
10886 .ToLocalChecked();
10887 Local<v8::Object> o1 = t->GetFunction(context.local())
10888 .ToLocalChecked()
10889 ->NewInstance(context.local())
10890 .ToLocalChecked();
9666 10891
9667 CHECK(o0->SetPrototype(o1)); 10892 CHECK(o0->SetPrototype(context.local(), o1).FromJust());
9668 // If setting the prototype leads to the cycle, SetPrototype should 10893 // If setting the prototype leads to the cycle, SetPrototype should
9669 // return false and keep VM in sane state. 10894 // return false and keep VM in sane state.
9670 v8::TryCatch try_catch(isolate); 10895 v8::TryCatch try_catch(isolate);
9671 CHECK(!o1->SetPrototype(o0)); 10896 CHECK(o1->SetPrototype(context.local(), o0).IsNothing());
9672 CHECK(!try_catch.HasCaught()); 10897 CHECK(!try_catch.HasCaught());
9673 DCHECK(!CcTest::i_isolate()->has_pending_exception()); 10898 DCHECK(!CcTest::i_isolate()->has_pending_exception());
9674 10899
9675 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 10900 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")
10901 ->Int32Value(context.local())
10902 .FromJust());
9676 } 10903 }
9677 10904
9678 10905
9679 THREADED_TEST(FunctionRemovePrototype) { 10906 THREADED_TEST(FunctionRemovePrototype) {
9680 LocalContext context; 10907 LocalContext context;
9681 v8::Isolate* isolate = context->GetIsolate(); 10908 v8::Isolate* isolate = context->GetIsolate();
9682 v8::HandleScope handle_scope(isolate); 10909 v8::HandleScope handle_scope(isolate);
9683 10910
9684 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate); 10911 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9685 t1->RemovePrototype(); 10912 t1->RemovePrototype();
9686 Local<v8::Function> fun = t1->GetFunction(); 10913 Local<v8::Function> fun = t1->GetFunction(context.local()).ToLocalChecked();
9687 context->Global()->Set(v8_str("fun"), fun); 10914 CHECK(context->Global()->Set(context.local(), v8_str("fun"), fun).FromJust());
9688 CHECK(!CompileRun("'prototype' in fun")->BooleanValue()); 10915 CHECK(!CompileRun("'prototype' in fun")
10916 ->BooleanValue(context.local())
10917 .FromJust());
9689 10918
9690 v8::TryCatch try_catch(isolate); 10919 v8::TryCatch try_catch(isolate);
9691 CompileRun("new fun()"); 10920 CompileRun("new fun()");
9692 CHECK(try_catch.HasCaught()); 10921 CHECK(try_catch.HasCaught());
9693 10922
9694 try_catch.Reset(); 10923 try_catch.Reset();
9695 fun->NewInstance(); 10924 CHECK(fun->NewInstance(context.local()).IsEmpty());
9696 CHECK(try_catch.HasCaught()); 10925 CHECK(try_catch.HasCaught());
9697 } 10926 }
9698 10927
9699 10928
9700 THREADED_TEST(GetterSetterExceptions) { 10929 THREADED_TEST(GetterSetterExceptions) {
9701 LocalContext context; 10930 LocalContext context;
9702 v8::Isolate* isolate = context->GetIsolate(); 10931 v8::Isolate* isolate = context->GetIsolate();
9703 v8::HandleScope handle_scope(isolate); 10932 v8::HandleScope handle_scope(isolate);
9704 CompileRun( 10933 CompileRun(
9705 "function Foo() { };" 10934 "function Foo() { };"
9706 "function Throw() { throw 5; };" 10935 "function Throw() { throw 5; };"
9707 "var x = { };" 10936 "var x = { };"
9708 "x.__defineSetter__('set', Throw);" 10937 "x.__defineSetter__('set', Throw);"
9709 "x.__defineGetter__('get', Throw);"); 10938 "x.__defineGetter__('get', Throw);");
9710 Local<v8::Object> x = 10939 Local<v8::Object> x = Local<v8::Object>::Cast(
9711 Local<v8::Object>::Cast(context->Global()->Get(v8_str("x"))); 10940 context->Global()->Get(context.local(), v8_str("x")).ToLocalChecked());
9712 v8::TryCatch try_catch(isolate); 10941 v8::TryCatch try_catch(isolate);
9713 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10942 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8))
9714 x->Get(v8_str("get")); 10943 .IsNothing());
9715 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10944 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty());
9716 x->Get(v8_str("get")); 10945 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8))
9717 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10946 .IsNothing());
9718 x->Get(v8_str("get")); 10947 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty());
9719 x->Set(v8_str("set"), v8::Integer::New(isolate, 8)); 10948 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8))
9720 x->Get(v8_str("get")); 10949 .IsNothing());
10950 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty());
10951 CHECK(x->Set(context.local(), v8_str("set"), v8::Integer::New(isolate, 8))
10952 .IsNothing());
10953 CHECK(x->Get(context.local(), v8_str("get")).IsEmpty());
9721 } 10954 }
9722 10955
9723 10956
9724 THREADED_TEST(Constructor) { 10957 THREADED_TEST(Constructor) {
9725 LocalContext context; 10958 LocalContext context;
9726 v8::Isolate* isolate = context->GetIsolate(); 10959 v8::Isolate* isolate = context->GetIsolate();
9727 v8::HandleScope handle_scope(isolate); 10960 v8::HandleScope handle_scope(isolate);
9728 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 10961 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
9729 templ->SetClassName(v8_str("Fun")); 10962 templ->SetClassName(v8_str("Fun"));
9730 Local<Function> cons = templ->GetFunction(); 10963 Local<Function> cons = templ->GetFunction(context.local()).ToLocalChecked();
9731 context->Global()->Set(v8_str("Fun"), cons); 10964 CHECK(
9732 Local<v8::Object> inst = cons->NewInstance(); 10965 context->Global()->Set(context.local(), v8_str("Fun"), cons).FromJust());
10966 Local<v8::Object> inst = cons->NewInstance(context.local()).ToLocalChecked();
9733 i::Handle<i::JSReceiver> obj(v8::Utils::OpenHandle(*inst)); 10967 i::Handle<i::JSReceiver> obj(v8::Utils::OpenHandle(*inst));
9734 CHECK(obj->IsJSObject()); 10968 CHECK(obj->IsJSObject());
9735 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 10969 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
9736 CHECK(value->BooleanValue()); 10970 CHECK(value->BooleanValue(context.local()).FromJust());
9737 } 10971 }
9738 10972
9739 10973
9740 static void ConstructorCallback( 10974 static void ConstructorCallback(
9741 const v8::FunctionCallbackInfo<v8::Value>& args) { 10975 const v8::FunctionCallbackInfo<v8::Value>& args) {
9742 ApiTestFuzzer::Fuzz(); 10976 ApiTestFuzzer::Fuzz();
9743 Local<Object> This; 10977 Local<Object> This;
9744 10978
10979 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
9745 if (args.IsConstructCall()) { 10980 if (args.IsConstructCall()) {
9746 Local<Object> Holder = args.Holder(); 10981 Local<Object> Holder = args.Holder();
9747 This = Object::New(args.GetIsolate()); 10982 This = Object::New(args.GetIsolate());
9748 Local<Value> proto = Holder->GetPrototype(); 10983 Local<Value> proto = Holder->GetPrototype();
9749 if (proto->IsObject()) { 10984 if (proto->IsObject()) {
9750 This->SetPrototype(proto); 10985 This->SetPrototype(context, proto).FromJust();
9751 } 10986 }
9752 } else { 10987 } else {
9753 This = args.This(); 10988 This = args.This();
9754 } 10989 }
9755 10990
9756 This->Set(v8_str("a"), args[0]); 10991 This->Set(context, v8_str("a"), args[0]).FromJust();
9757 args.GetReturnValue().Set(This); 10992 args.GetReturnValue().Set(This);
9758 } 10993 }
9759 10994
9760 10995
9761 static void FakeConstructorCallback( 10996 static void FakeConstructorCallback(
9762 const v8::FunctionCallbackInfo<v8::Value>& args) { 10997 const v8::FunctionCallbackInfo<v8::Value>& args) {
9763 ApiTestFuzzer::Fuzz(); 10998 ApiTestFuzzer::Fuzz();
9764 args.GetReturnValue().Set(args[0]); 10999 args.GetReturnValue().Set(args[0]);
9765 } 11000 }
9766 11001
9767 11002
9768 THREADED_TEST(ConstructorForObject) { 11003 THREADED_TEST(ConstructorForObject) {
9769 LocalContext context; 11004 LocalContext context;
9770 v8::Isolate* isolate = context->GetIsolate(); 11005 v8::Isolate* isolate = context->GetIsolate();
9771 v8::HandleScope handle_scope(isolate); 11006 v8::HandleScope handle_scope(isolate);
9772 11007
9773 { 11008 {
9774 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11009 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
9775 instance_template->SetCallAsFunctionHandler(ConstructorCallback); 11010 instance_template->SetCallAsFunctionHandler(ConstructorCallback);
9776 Local<Object> instance = instance_template->NewInstance(); 11011 Local<Object> instance =
9777 context->Global()->Set(v8_str("obj"), instance); 11012 instance_template->NewInstance(context.local()).ToLocalChecked();
11013 CHECK(context->Global()
11014 ->Set(context.local(), v8_str("obj"), instance)
11015 .FromJust());
9778 v8::TryCatch try_catch(isolate); 11016 v8::TryCatch try_catch(isolate);
9779 Local<Value> value; 11017 Local<Value> value;
9780 CHECK(!try_catch.HasCaught()); 11018 CHECK(!try_catch.HasCaught());
9781 11019
9782 // Call the Object's constructor with a 32-bit signed integer. 11020 // Call the Object's constructor with a 32-bit signed integer.
9783 value = CompileRun("(function() { var o = new obj(28); return o.a; })()"); 11021 value = CompileRun("(function() { var o = new obj(28); return o.a; })()");
9784 CHECK(!try_catch.HasCaught()); 11022 CHECK(!try_catch.HasCaught());
9785 CHECK(value->IsInt32()); 11023 CHECK(value->IsInt32());
9786 CHECK_EQ(28, value->Int32Value()); 11024 CHECK_EQ(28, value->Int32Value(context.local()).FromJust());
9787 11025
9788 Local<Value> args1[] = {v8_num(28)}; 11026 Local<Value> args1[] = {v8_num(28)};
9789 Local<Value> value_obj1 = instance->CallAsConstructor(1, args1); 11027 Local<Value> value_obj1 =
11028 instance->CallAsConstructor(context.local(), 1, args1).ToLocalChecked();
9790 CHECK(value_obj1->IsObject()); 11029 CHECK(value_obj1->IsObject());
9791 Local<Object> object1 = Local<Object>::Cast(value_obj1); 11030 Local<Object> object1 = Local<Object>::Cast(value_obj1);
9792 value = object1->Get(v8_str("a")); 11031 value = object1->Get(context.local(), v8_str("a")).ToLocalChecked();
9793 CHECK(value->IsInt32()); 11032 CHECK(value->IsInt32());
9794 CHECK(!try_catch.HasCaught()); 11033 CHECK(!try_catch.HasCaught());
9795 CHECK_EQ(28, value->Int32Value()); 11034 CHECK_EQ(28, value->Int32Value(context.local()).FromJust());
9796 11035
9797 // Call the Object's constructor with a String. 11036 // Call the Object's constructor with a String.
9798 value = 11037 value =
9799 CompileRun("(function() { var o = new obj('tipli'); return o.a; })()"); 11038 CompileRun("(function() { var o = new obj('tipli'); return o.a; })()");
9800 CHECK(!try_catch.HasCaught()); 11039 CHECK(!try_catch.HasCaught());
9801 CHECK(value->IsString()); 11040 CHECK(value->IsString());
9802 String::Utf8Value string_value1(value->ToString(isolate)); 11041 String::Utf8Value string_value1(
11042 value->ToString(context.local()).ToLocalChecked());
9803 CHECK_EQ(0, strcmp("tipli", *string_value1)); 11043 CHECK_EQ(0, strcmp("tipli", *string_value1));
9804 11044
9805 Local<Value> args2[] = {v8_str("tipli")}; 11045 Local<Value> args2[] = {v8_str("tipli")};
9806 Local<Value> value_obj2 = instance->CallAsConstructor(1, args2); 11046 Local<Value> value_obj2 =
11047 instance->CallAsConstructor(context.local(), 1, args2).ToLocalChecked();
9807 CHECK(value_obj2->IsObject()); 11048 CHECK(value_obj2->IsObject());
9808 Local<Object> object2 = Local<Object>::Cast(value_obj2); 11049 Local<Object> object2 = Local<Object>::Cast(value_obj2);
9809 value = object2->Get(v8_str("a")); 11050 value = object2->Get(context.local(), v8_str("a")).ToLocalChecked();
9810 CHECK(!try_catch.HasCaught()); 11051 CHECK(!try_catch.HasCaught());
9811 CHECK(value->IsString()); 11052 CHECK(value->IsString());
9812 String::Utf8Value string_value2(value->ToString(isolate)); 11053 String::Utf8Value string_value2(
11054 value->ToString(context.local()).ToLocalChecked());
9813 CHECK_EQ(0, strcmp("tipli", *string_value2)); 11055 CHECK_EQ(0, strcmp("tipli", *string_value2));
9814 11056
9815 // Call the Object's constructor with a Boolean. 11057 // Call the Object's constructor with a Boolean.
9816 value = CompileRun("(function() { var o = new obj(true); return o.a; })()"); 11058 value = CompileRun("(function() { var o = new obj(true); return o.a; })()");
9817 CHECK(!try_catch.HasCaught()); 11059 CHECK(!try_catch.HasCaught());
9818 CHECK(value->IsBoolean()); 11060 CHECK(value->IsBoolean());
9819 CHECK_EQ(true, value->BooleanValue()); 11061 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
9820 11062
9821 Handle<Value> args3[] = {v8::True(isolate)}; 11063 Local<Value> args3[] = {v8::True(isolate)};
9822 Local<Value> value_obj3 = instance->CallAsConstructor(1, args3); 11064 Local<Value> value_obj3 =
11065 instance->CallAsConstructor(context.local(), 1, args3).ToLocalChecked();
9823 CHECK(value_obj3->IsObject()); 11066 CHECK(value_obj3->IsObject());
9824 Local<Object> object3 = Local<Object>::Cast(value_obj3); 11067 Local<Object> object3 = Local<Object>::Cast(value_obj3);
9825 value = object3->Get(v8_str("a")); 11068 value = object3->Get(context.local(), v8_str("a")).ToLocalChecked();
9826 CHECK(!try_catch.HasCaught()); 11069 CHECK(!try_catch.HasCaught());
9827 CHECK(value->IsBoolean()); 11070 CHECK(value->IsBoolean());
9828 CHECK_EQ(true, value->BooleanValue()); 11071 CHECK_EQ(true, value->BooleanValue(context.local()).FromJust());
9829 11072
9830 // Call the Object's constructor with undefined. 11073 // Call the Object's constructor with undefined.
9831 Handle<Value> args4[] = {v8::Undefined(isolate)}; 11074 Local<Value> args4[] = {v8::Undefined(isolate)};
9832 Local<Value> value_obj4 = instance->CallAsConstructor(1, args4); 11075 Local<Value> value_obj4 =
11076 instance->CallAsConstructor(context.local(), 1, args4).ToLocalChecked();
9833 CHECK(value_obj4->IsObject()); 11077 CHECK(value_obj4->IsObject());
9834 Local<Object> object4 = Local<Object>::Cast(value_obj4); 11078 Local<Object> object4 = Local<Object>::Cast(value_obj4);
9835 value = object4->Get(v8_str("a")); 11079 value = object4->Get(context.local(), v8_str("a")).ToLocalChecked();
9836 CHECK(!try_catch.HasCaught()); 11080 CHECK(!try_catch.HasCaught());
9837 CHECK(value->IsUndefined()); 11081 CHECK(value->IsUndefined());
9838 11082
9839 // Call the Object's constructor with null. 11083 // Call the Object's constructor with null.
9840 Handle<Value> args5[] = {v8::Null(isolate)}; 11084 Local<Value> args5[] = {v8::Null(isolate)};
9841 Local<Value> value_obj5 = instance->CallAsConstructor(1, args5); 11085 Local<Value> value_obj5 =
11086 instance->CallAsConstructor(context.local(), 1, args5).ToLocalChecked();
9842 CHECK(value_obj5->IsObject()); 11087 CHECK(value_obj5->IsObject());
9843 Local<Object> object5 = Local<Object>::Cast(value_obj5); 11088 Local<Object> object5 = Local<Object>::Cast(value_obj5);
9844 value = object5->Get(v8_str("a")); 11089 value = object5->Get(context.local(), v8_str("a")).ToLocalChecked();
9845 CHECK(!try_catch.HasCaught()); 11090 CHECK(!try_catch.HasCaught());
9846 CHECK(value->IsNull()); 11091 CHECK(value->IsNull());
9847 } 11092 }
9848 11093
9849 // Check exception handling when there is no constructor set for the Object. 11094 // Check exception handling when there is no constructor set for the Object.
9850 { 11095 {
9851 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11096 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
9852 Local<Object> instance = instance_template->NewInstance(); 11097 Local<Object> instance =
9853 context->Global()->Set(v8_str("obj2"), instance); 11098 instance_template->NewInstance(context.local()).ToLocalChecked();
11099 CHECK(context->Global()
11100 ->Set(context.local(), v8_str("obj2"), instance)
11101 .FromJust());
9854 v8::TryCatch try_catch(isolate); 11102 v8::TryCatch try_catch(isolate);
9855 Local<Value> value; 11103 Local<Value> value;
9856 CHECK(!try_catch.HasCaught()); 11104 CHECK(!try_catch.HasCaught());
9857 11105
9858 value = CompileRun("new obj2(28)"); 11106 value = CompileRun("new obj2(28)");
9859 CHECK(try_catch.HasCaught()); 11107 CHECK(try_catch.HasCaught());
9860 String::Utf8Value exception_value1(try_catch.Exception()); 11108 String::Utf8Value exception_value1(try_catch.Exception());
9861 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); 11109 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1));
9862 try_catch.Reset(); 11110 try_catch.Reset();
9863 11111
9864 Local<Value> args[] = {v8_num(29)}; 11112 Local<Value> args[] = {v8_num(29)};
9865 value = instance->CallAsConstructor(1, args); 11113 CHECK(instance->CallAsConstructor(context.local(), 1, args).IsEmpty());
9866 CHECK(try_catch.HasCaught()); 11114 CHECK(try_catch.HasCaught());
9867 String::Utf8Value exception_value2(try_catch.Exception()); 11115 String::Utf8Value exception_value2(try_catch.Exception());
9868 CHECK_EQ(0, 11116 CHECK_EQ(0,
9869 strcmp("TypeError: object is not a function", *exception_value2)); 11117 strcmp("TypeError: object is not a function", *exception_value2));
9870 try_catch.Reset(); 11118 try_catch.Reset();
9871 } 11119 }
9872 11120
9873 // Check the case when constructor throws exception. 11121 // Check the case when constructor throws exception.
9874 { 11122 {
9875 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11123 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
9876 instance_template->SetCallAsFunctionHandler(ThrowValue); 11124 instance_template->SetCallAsFunctionHandler(ThrowValue);
9877 Local<Object> instance = instance_template->NewInstance(); 11125 Local<Object> instance =
9878 context->Global()->Set(v8_str("obj3"), instance); 11126 instance_template->NewInstance(context.local()).ToLocalChecked();
11127 CHECK(context->Global()
11128 ->Set(context.local(), v8_str("obj3"), instance)
11129 .FromJust());
9879 v8::TryCatch try_catch(isolate); 11130 v8::TryCatch try_catch(isolate);
9880 Local<Value> value; 11131 Local<Value> value;
9881 CHECK(!try_catch.HasCaught()); 11132 CHECK(!try_catch.HasCaught());
9882 11133
9883 value = CompileRun("new obj3(22)"); 11134 value = CompileRun("new obj3(22)");
9884 CHECK(try_catch.HasCaught()); 11135 CHECK(try_catch.HasCaught());
9885 String::Utf8Value exception_value1(try_catch.Exception()); 11136 String::Utf8Value exception_value1(try_catch.Exception());
9886 CHECK_EQ(0, strcmp("22", *exception_value1)); 11137 CHECK_EQ(0, strcmp("22", *exception_value1));
9887 try_catch.Reset(); 11138 try_catch.Reset();
9888 11139
9889 Local<Value> args[] = {v8_num(23)}; 11140 Local<Value> args[] = {v8_num(23)};
9890 value = instance->CallAsConstructor(1, args); 11141 CHECK(instance->CallAsConstructor(context.local(), 1, args).IsEmpty());
9891 CHECK(try_catch.HasCaught()); 11142 CHECK(try_catch.HasCaught());
9892 String::Utf8Value exception_value2(try_catch.Exception()); 11143 String::Utf8Value exception_value2(try_catch.Exception());
9893 CHECK_EQ(0, strcmp("23", *exception_value2)); 11144 CHECK_EQ(0, strcmp("23", *exception_value2));
9894 try_catch.Reset(); 11145 try_catch.Reset();
9895 } 11146 }
9896 11147
9897 // Check whether constructor returns with an object or non-object. 11148 // Check whether constructor returns with an object or non-object.
9898 { 11149 {
9899 Local<FunctionTemplate> function_template = 11150 Local<FunctionTemplate> function_template =
9900 FunctionTemplate::New(isolate, FakeConstructorCallback); 11151 FunctionTemplate::New(isolate, FakeConstructorCallback);
9901 Local<Function> function = function_template->GetFunction(); 11152 Local<Function> function =
11153 function_template->GetFunction(context.local()).ToLocalChecked();
9902 Local<Object> instance1 = function; 11154 Local<Object> instance1 = function;
9903 context->Global()->Set(v8_str("obj4"), instance1); 11155 CHECK(context->Global()
11156 ->Set(context.local(), v8_str("obj4"), instance1)
11157 .FromJust());
9904 v8::TryCatch try_catch(isolate); 11158 v8::TryCatch try_catch(isolate);
9905 Local<Value> value; 11159 Local<Value> value;
9906 CHECK(!try_catch.HasCaught()); 11160 CHECK(!try_catch.HasCaught());
9907 11161
9908 CHECK(instance1->IsObject()); 11162 CHECK(instance1->IsObject());
9909 CHECK(instance1->IsFunction()); 11163 CHECK(instance1->IsFunction());
9910 11164
9911 value = CompileRun("new obj4(28)"); 11165 value = CompileRun("new obj4(28)");
9912 CHECK(!try_catch.HasCaught()); 11166 CHECK(!try_catch.HasCaught());
9913 CHECK(value->IsObject()); 11167 CHECK(value->IsObject());
9914 11168
9915 Local<Value> args1[] = {v8_num(28)}; 11169 Local<Value> args1[] = {v8_num(28)};
9916 value = instance1->CallAsConstructor(1, args1); 11170 value = instance1->CallAsConstructor(context.local(), 1, args1)
11171 .ToLocalChecked();
9917 CHECK(!try_catch.HasCaught()); 11172 CHECK(!try_catch.HasCaught());
9918 CHECK(value->IsObject()); 11173 CHECK(value->IsObject());
9919 11174
9920 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11175 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
9921 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback); 11176 instance_template->SetCallAsFunctionHandler(FakeConstructorCallback);
9922 Local<Object> instance2 = instance_template->NewInstance(); 11177 Local<Object> instance2 =
9923 context->Global()->Set(v8_str("obj5"), instance2); 11178 instance_template->NewInstance(context.local()).ToLocalChecked();
11179 CHECK(context->Global()
11180 ->Set(context.local(), v8_str("obj5"), instance2)
11181 .FromJust());
9924 CHECK(!try_catch.HasCaught()); 11182 CHECK(!try_catch.HasCaught());
9925 11183
9926 CHECK(instance2->IsObject()); 11184 CHECK(instance2->IsObject());
9927 CHECK(instance2->IsFunction()); 11185 CHECK(instance2->IsFunction());
9928 11186
9929 value = CompileRun("new obj5(28)"); 11187 value = CompileRun("new obj5(28)");
9930 CHECK(!try_catch.HasCaught()); 11188 CHECK(!try_catch.HasCaught());
9931 CHECK(!value->IsObject()); 11189 CHECK(!value->IsObject());
9932 11190
9933 Local<Value> args2[] = {v8_num(28)}; 11191 Local<Value> args2[] = {v8_num(28)};
9934 value = instance2->CallAsConstructor(1, args2); 11192 value = instance2->CallAsConstructor(context.local(), 1, args2)
11193 .ToLocalChecked();
9935 CHECK(!try_catch.HasCaught()); 11194 CHECK(!try_catch.HasCaught());
9936 CHECK(!value->IsObject()); 11195 CHECK(!value->IsObject());
9937 } 11196 }
9938 } 11197 }
9939 11198
9940 11199
9941 THREADED_TEST(FunctionDescriptorException) { 11200 THREADED_TEST(FunctionDescriptorException) {
9942 LocalContext context; 11201 LocalContext context;
9943 v8::Isolate* isolate = context->GetIsolate(); 11202 v8::Isolate* isolate = context->GetIsolate();
9944 v8::HandleScope handle_scope(isolate); 11203 v8::HandleScope handle_scope(isolate);
9945 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 11204 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
9946 templ->SetClassName(v8_str("Fun")); 11205 templ->SetClassName(v8_str("Fun"));
9947 Local<Function> cons = templ->GetFunction(); 11206 Local<Function> cons = templ->GetFunction(context.local()).ToLocalChecked();
9948 context->Global()->Set(v8_str("Fun"), cons); 11207 CHECK(
11208 context->Global()->Set(context.local(), v8_str("Fun"), cons).FromJust());
9949 Local<Value> value = CompileRun( 11209 Local<Value> value = CompileRun(
9950 "function test() {" 11210 "function test() {"
9951 " try {" 11211 " try {"
9952 " (new Fun()).blah()" 11212 " (new Fun()).blah()"
9953 " } catch (e) {" 11213 " } catch (e) {"
9954 " var str = String(e);" 11214 " var str = String(e);"
9955 // " if (str.indexOf('TypeError') == -1) return 1;" 11215 // " if (str.indexOf('TypeError') == -1) return 1;"
9956 // " if (str.indexOf('[object Fun]') != -1) return 2;" 11216 // " if (str.indexOf('[object Fun]') != -1) return 2;"
9957 // " if (str.indexOf('#<Fun>') == -1) return 3;" 11217 // " if (str.indexOf('#<Fun>') == -1) return 3;"
9958 " return 0;" 11218 " return 0;"
9959 " }" 11219 " }"
9960 " return 4;" 11220 " return 4;"
9961 "}" 11221 "}"
9962 "test();"); 11222 "test();");
9963 CHECK_EQ(0, value->Int32Value()); 11223 CHECK_EQ(0, value->Int32Value(context.local()).FromJust());
9964 } 11224 }
9965 11225
9966 11226
9967 THREADED_TEST(EvalAliasedDynamic) { 11227 THREADED_TEST(EvalAliasedDynamic) {
9968 LocalContext current; 11228 LocalContext current;
9969 v8::HandleScope scope(current->GetIsolate()); 11229 v8::HandleScope scope(current->GetIsolate());
9970 11230
9971 // Tests where aliased eval can only be resolved dynamically. 11231 // Tests where aliased eval can only be resolved dynamically.
9972 Local<Script> script = v8_compile( 11232 Local<Script> script = v8_compile(
9973 "function f(x) { " 11233 "function f(x) { "
9974 " var foo = 2;" 11234 " var foo = 2;"
9975 " with (x) { return eval('foo'); }" 11235 " with (x) { return eval('foo'); }"
9976 "}" 11236 "}"
9977 "foo = 0;" 11237 "foo = 0;"
9978 "result1 = f(new Object());" 11238 "result1 = f(new Object());"
9979 "result2 = f(this);" 11239 "result2 = f(this);"
9980 "var x = new Object();" 11240 "var x = new Object();"
9981 "x.eval = function(x) { return 1; };" 11241 "x.eval = function(x) { return 1; };"
9982 "result3 = f(x);"); 11242 "result3 = f(x);");
9983 script->Run(); 11243 script->Run(current.local()).ToLocalChecked();
9984 CHECK_EQ(2, current->Global()->Get(v8_str("result1"))->Int32Value()); 11244 CHECK_EQ(2, current->Global()
9985 CHECK_EQ(0, current->Global()->Get(v8_str("result2"))->Int32Value()); 11245 ->Get(current.local(), v8_str("result1"))
9986 CHECK_EQ(1, current->Global()->Get(v8_str("result3"))->Int32Value()); 11246 .ToLocalChecked()
11247 ->Int32Value(current.local())
11248 .FromJust());
11249 CHECK_EQ(0, current->Global()
11250 ->Get(current.local(), v8_str("result2"))
11251 .ToLocalChecked()
11252 ->Int32Value(current.local())
11253 .FromJust());
11254 CHECK_EQ(1, current->Global()
11255 ->Get(current.local(), v8_str("result3"))
11256 .ToLocalChecked()
11257 ->Int32Value(current.local())
11258 .FromJust());
9987 11259
9988 v8::TryCatch try_catch(current->GetIsolate()); 11260 v8::TryCatch try_catch(current->GetIsolate());
9989 script = v8_compile( 11261 script = v8_compile(
9990 "function f(x) { " 11262 "function f(x) { "
9991 " var bar = 2;" 11263 " var bar = 2;"
9992 " with (x) { return eval('bar'); }" 11264 " with (x) { return eval('bar'); }"
9993 "}" 11265 "}"
9994 "result4 = f(this)"); 11266 "result4 = f(this)");
9995 script->Run(); 11267 script->Run(current.local()).ToLocalChecked();
9996 CHECK(!try_catch.HasCaught()); 11268 CHECK(!try_catch.HasCaught());
9997 CHECK_EQ(2, current->Global()->Get(v8_str("result4"))->Int32Value()); 11269 CHECK_EQ(2, current->Global()
11270 ->Get(current.local(), v8_str("result4"))
11271 .ToLocalChecked()
11272 ->Int32Value(current.local())
11273 .FromJust());
9998 11274
9999 try_catch.Reset(); 11275 try_catch.Reset();
10000 } 11276 }
10001 11277
10002 11278
10003 THREADED_TEST(CrossEval) { 11279 THREADED_TEST(CrossEval) {
10004 v8::HandleScope scope(CcTest::isolate()); 11280 v8::HandleScope scope(CcTest::isolate());
10005 LocalContext other; 11281 LocalContext other;
10006 LocalContext current; 11282 LocalContext current;
10007 11283
10008 Local<String> token = v8_str("<security token>"); 11284 Local<String> token = v8_str("<security token>");
10009 other->SetSecurityToken(token); 11285 other->SetSecurityToken(token);
10010 current->SetSecurityToken(token); 11286 current->SetSecurityToken(token);
10011 11287
10012 // Set up reference from current to other. 11288 // Set up reference from current to other.
10013 current->Global()->Set(v8_str("other"), other->Global()); 11289 CHECK(current->Global()
11290 ->Set(current.local(), v8_str("other"), other->Global())
11291 .FromJust());
10014 11292
10015 // Check that new variables are introduced in other context. 11293 // Check that new variables are introduced in other context.
10016 Local<Script> script = v8_compile("other.eval('var foo = 1234')"); 11294 Local<Script> script = v8_compile("other.eval('var foo = 1234')");
10017 script->Run(); 11295 script->Run(current.local()).ToLocalChecked();
10018 Local<Value> foo = other->Global()->Get(v8_str("foo")); 11296 Local<Value> foo = other->Global()->Get(v8_str("foo"));
10019 CHECK_EQ(1234, foo->Int32Value()); 11297 CHECK_EQ(1234, foo->Int32Value(other.local()).FromJust());
10020 CHECK(!current->Global()->Has(v8_str("foo"))); 11298 CHECK(!current->Global()->Has(v8_str("foo")));
10021 11299
10022 // Check that writing to non-existing properties introduces them in 11300 // Check that writing to non-existing properties introduces them in
10023 // the other context. 11301 // the other context.
10024 script = v8_compile("other.eval('na = 1234')"); 11302 script = v8_compile("other.eval('na = 1234')");
10025 script->Run(); 11303 script->Run();
10026 CHECK_EQ(1234, other->Global()->Get(v8_str("na"))->Int32Value()); 11304 CHECK_EQ(
11305 1234,
11306 other->Global()->Get(v8_str("na"))->Int32Value(other.local()).FromJust());
10027 CHECK(!current->Global()->Has(v8_str("na"))); 11307 CHECK(!current->Global()->Has(v8_str("na")));
10028 11308
10029 // Check that global variables in current context are not visible in other 11309 // Check that global variables in current context are not visible in other
10030 // context. 11310 // context.
10031 v8::TryCatch try_catch(CcTest::isolate()); 11311 v8::TryCatch try_catch(CcTest::isolate());
10032 script = v8_compile("var bar = 42; other.eval('bar');"); 11312 script = v8_compile("var bar = 42; other.eval('bar');");
10033 Local<Value> result = script->Run(); 11313 Local<Value> result = script->Run();
10034 CHECK(try_catch.HasCaught()); 11314 CHECK(try_catch.HasCaught());
10035 try_catch.Reset(); 11315 try_catch.Reset();
10036 11316
10037 // Check that local variables in current context are not visible in other 11317 // Check that local variables in current context are not visible in other
10038 // context. 11318 // context.
10039 script = v8_compile( 11319 script = v8_compile(
10040 "(function() { " 11320 "(function() { "
10041 " var baz = 87;" 11321 " var baz = 87;"
10042 " return other.eval('baz');" 11322 " return other.eval('baz');"
10043 "})();"); 11323 "})();");
10044 result = script->Run(); 11324 result = script->Run();
10045 CHECK(try_catch.HasCaught()); 11325 CHECK(try_catch.HasCaught());
10046 try_catch.Reset(); 11326 try_catch.Reset();
10047 11327
10048 // Check that global variables in the other environment are visible 11328 // Check that global variables in the other environment are visible
10049 // when evaluting code. 11329 // when evaluting code.
10050 other->Global()->Set(v8_str("bis"), v8_num(1234)); 11330 CHECK(other->Global()
11331 ->Set(other.local(), v8_str("bis"), v8_num(1234))
11332 .FromJust());
10051 script = v8_compile("other.eval('bis')"); 11333 script = v8_compile("other.eval('bis')");
10052 CHECK_EQ(1234, script->Run()->Int32Value()); 11334 CHECK_EQ(1234, script->Run()->Int32Value(other.local()).FromJust());
10053 CHECK(!try_catch.HasCaught()); 11335 CHECK(!try_catch.HasCaught());
10054 11336
10055 // Check that the 'this' pointer points to the global object evaluating 11337 // Check that the 'this' pointer points to the global object evaluating
10056 // code. 11338 // code.
10057 other->Global()->Set(v8_str("t"), other->Global()); 11339 CHECK(other->Global()
11340 ->Set(other.local(), v8_str("t"), other->Global())
11341 .FromJust());
10058 script = v8_compile("other.eval('this == t')"); 11342 script = v8_compile("other.eval('this == t')");
10059 result = script->Run(); 11343 result = script->Run();
10060 CHECK(result->IsTrue()); 11344 CHECK(result->IsTrue());
10061 CHECK(!try_catch.HasCaught()); 11345 CHECK(!try_catch.HasCaught());
10062 11346
10063 // Check that variables introduced in with-statement are not visible in 11347 // Check that variables introduced in with-statement are not visible in
10064 // other context. 11348 // other context.
10065 script = v8_compile("with({x:2}){other.eval('x')}"); 11349 script = v8_compile("with({x:2}){other.eval('x')}");
10066 result = script->Run(); 11350 result = script->Run();
10067 CHECK(try_catch.HasCaught()); 11351 CHECK(try_catch.HasCaught());
(...skipping 11 matching lines...) Expand all
10079 // its global proxy works. 11363 // its global proxy works.
10080 THREADED_TEST(EvalInDetachedGlobal) { 11364 THREADED_TEST(EvalInDetachedGlobal) {
10081 v8::Isolate* isolate = CcTest::isolate(); 11365 v8::Isolate* isolate = CcTest::isolate();
10082 v8::HandleScope scope(isolate); 11366 v8::HandleScope scope(isolate);
10083 11367
10084 v8::Local<Context> context0 = Context::New(isolate); 11368 v8::Local<Context> context0 = Context::New(isolate);
10085 v8::Local<Context> context1 = Context::New(isolate); 11369 v8::Local<Context> context1 = Context::New(isolate);
10086 11370
10087 // Set up function in context0 that uses eval from context0. 11371 // Set up function in context0 that uses eval from context0.
10088 context0->Enter(); 11372 context0->Enter();
10089 v8::Handle<v8::Value> fun = CompileRun( 11373 v8::Local<v8::Value> fun = CompileRun(
10090 "var x = 42;" 11374 "var x = 42;"
10091 "(function() {" 11375 "(function() {"
10092 " var e = eval;" 11376 " var e = eval;"
10093 " return function(s) { return e(s); }" 11377 " return function(s) { return e(s); }"
10094 "})()"); 11378 "})()");
10095 context0->Exit(); 11379 context0->Exit();
10096 11380
10097 // Put the function into context1 and call it before and after 11381 // Put the function into context1 and call it before and after
10098 // detaching the global. Before detaching, the call succeeds and 11382 // detaching the global. Before detaching, the call succeeds and
10099 // after detaching and exception is thrown. 11383 // after detaching and exception is thrown.
10100 context1->Enter(); 11384 context1->Enter();
10101 context1->Global()->Set(v8_str("fun"), fun); 11385 CHECK(context1->Global()->Set(context1, v8_str("fun"), fun).FromJust());
10102 v8::Handle<v8::Value> x_value = CompileRun("fun('x')"); 11386 v8::Local<v8::Value> x_value = CompileRun("fun('x')");
10103 CHECK_EQ(42, x_value->Int32Value()); 11387 CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
10104 context0->DetachGlobal(); 11388 context0->DetachGlobal();
10105 v8::TryCatch catcher(isolate); 11389 v8::TryCatch catcher(isolate);
10106 x_value = CompileRun("fun('x')"); 11390 x_value = CompileRun("fun('x')");
10107 CHECK_EQ(42, x_value->Int32Value()); 11391 CHECK_EQ(42, x_value->Int32Value(context1).FromJust());
10108 context1->Exit(); 11392 context1->Exit();
10109 } 11393 }
10110 11394
10111 11395
10112 THREADED_TEST(CrossLazyLoad) { 11396 THREADED_TEST(CrossLazyLoad) {
10113 v8::HandleScope scope(CcTest::isolate()); 11397 v8::HandleScope scope(CcTest::isolate());
10114 LocalContext other; 11398 LocalContext other;
10115 LocalContext current; 11399 LocalContext current;
10116 11400
10117 Local<String> token = v8_str("<security token>"); 11401 Local<String> token = v8_str("<security token>");
10118 other->SetSecurityToken(token); 11402 other->SetSecurityToken(token);
10119 current->SetSecurityToken(token); 11403 current->SetSecurityToken(token);
10120 11404
10121 // Set up reference from current to other. 11405 // Set up reference from current to other.
10122 current->Global()->Set(v8_str("other"), other->Global()); 11406 CHECK(current->Global()
11407 ->Set(current.local(), v8_str("other"), other->Global())
11408 .FromJust());
10123 11409
10124 // Trigger lazy loading in other context. 11410 // Trigger lazy loading in other context.
10125 Local<Script> script = v8_compile("other.eval('new Date(42)')"); 11411 Local<Script> script = v8_compile("other.eval('new Date(42)')");
10126 Local<Value> value = script->Run(); 11412 Local<Value> value = script->Run();
10127 CHECK_EQ(42.0, value->NumberValue()); 11413 CHECK_EQ(42.0, value->NumberValue());
10128 } 11414 }
10129 11415
10130 11416
10131 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) { 11417 static void call_as_function(const v8::FunctionCallbackInfo<v8::Value>& args) {
10132 ApiTestFuzzer::Fuzz(); 11418 ApiTestFuzzer::Fuzz();
10133 if (args.IsConstructCall()) { 11419 if (args.IsConstructCall()) {
10134 if (args[0]->IsInt32()) { 11420 if (args[0]->IsInt32()) {
10135 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); 11421 args.GetReturnValue().Set(
11422 v8_num(-args[0]
11423 ->Int32Value(args.GetIsolate()->GetCurrentContext())
11424 .FromJust()));
10136 return; 11425 return;
10137 } 11426 }
10138 } 11427 }
10139 11428
10140 args.GetReturnValue().Set(args[0]); 11429 args.GetReturnValue().Set(args[0]);
10141 } 11430 }
10142 11431
10143 11432
10144 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { 11433 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
10145 args.GetReturnValue().Set(args.This()); 11434 args.GetReturnValue().Set(args.This());
10146 } 11435 }
10147 11436
10148 11437
10149 // Test that a call handler can be set for objects which will allow 11438 // 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 11439 // non-function objects created through the API to be called as
10151 // functions. 11440 // functions.
10152 THREADED_TEST(CallAsFunction) { 11441 THREADED_TEST(CallAsFunction) {
10153 LocalContext context; 11442 LocalContext context;
10154 v8::Isolate* isolate = context->GetIsolate(); 11443 v8::Isolate* isolate = context->GetIsolate();
10155 v8::HandleScope scope(isolate); 11444 v8::HandleScope scope(isolate);
10156 11445
10157 { 11446 {
10158 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 11447 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10159 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 11448 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10160 instance_template->SetCallAsFunctionHandler(call_as_function); 11449 instance_template->SetCallAsFunctionHandler(call_as_function);
10161 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 11450 Local<v8::Object> instance = t->GetFunction(context.local())
10162 context->Global()->Set(v8_str("obj"), instance); 11451 .ToLocalChecked()
11452 ->NewInstance(context.local())
11453 .ToLocalChecked();
11454 CHECK(context->Global()
11455 ->Set(context.local(), v8_str("obj"), instance)
11456 .FromJust());
10163 v8::TryCatch try_catch(isolate); 11457 v8::TryCatch try_catch(isolate);
10164 Local<Value> value; 11458 Local<Value> value;
10165 CHECK(!try_catch.HasCaught()); 11459 CHECK(!try_catch.HasCaught());
10166 11460
10167 value = CompileRun("obj(42)"); 11461 value = CompileRun("obj(42)");
10168 CHECK(!try_catch.HasCaught()); 11462 CHECK(!try_catch.HasCaught());
10169 CHECK_EQ(42, value->Int32Value()); 11463 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
10170 11464
10171 value = CompileRun("(function(o){return o(49)})(obj)"); 11465 value = CompileRun("(function(o){return o(49)})(obj)");
10172 CHECK(!try_catch.HasCaught()); 11466 CHECK(!try_catch.HasCaught());
10173 CHECK_EQ(49, value->Int32Value()); 11467 CHECK_EQ(49, value->Int32Value(context.local()).FromJust());
10174 11468
10175 // test special case of call as function 11469 // test special case of call as function
10176 value = CompileRun("[obj]['0'](45)"); 11470 value = CompileRun("[obj]['0'](45)");
10177 CHECK(!try_catch.HasCaught()); 11471 CHECK(!try_catch.HasCaught());
10178 CHECK_EQ(45, value->Int32Value()); 11472 CHECK_EQ(45, value->Int32Value(context.local()).FromJust());
10179 11473
10180 value = CompileRun( 11474 value = CompileRun(
10181 "obj.call = Function.prototype.call;" 11475 "obj.call = Function.prototype.call;"
10182 "obj.call(null, 87)"); 11476 "obj.call(null, 87)");
10183 CHECK(!try_catch.HasCaught()); 11477 CHECK(!try_catch.HasCaught());
10184 CHECK_EQ(87, value->Int32Value()); 11478 CHECK_EQ(87, value->Int32Value(context.local()).FromJust());
10185 11479
10186 // Regression tests for bug #1116356: Calling call through call/apply 11480 // Regression tests for bug #1116356: Calling call through call/apply
10187 // must work for non-function receivers. 11481 // must work for non-function receivers.
10188 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])"; 11482 const char* apply_99 = "Function.prototype.call.apply(obj, [this, 99])";
10189 value = CompileRun(apply_99); 11483 value = CompileRun(apply_99);
10190 CHECK(!try_catch.HasCaught()); 11484 CHECK(!try_catch.HasCaught());
10191 CHECK_EQ(99, value->Int32Value()); 11485 CHECK_EQ(99, value->Int32Value(context.local()).FromJust());
10192 11486
10193 const char* call_17 = "Function.prototype.call.call(obj, this, 17)"; 11487 const char* call_17 = "Function.prototype.call.call(obj, this, 17)";
10194 value = CompileRun(call_17); 11488 value = CompileRun(call_17);
10195 CHECK(!try_catch.HasCaught()); 11489 CHECK(!try_catch.HasCaught());
10196 CHECK_EQ(17, value->Int32Value()); 11490 CHECK_EQ(17, value->Int32Value(context.local()).FromJust());
10197 11491
10198 // Check that the call-as-function handler can be called through 11492 // Check that the call-as-function handler can be called through
10199 // new. 11493 // new.
10200 value = CompileRun("new obj(43)"); 11494 value = CompileRun("new obj(43)");
10201 CHECK(!try_catch.HasCaught()); 11495 CHECK(!try_catch.HasCaught());
10202 CHECK_EQ(-43, value->Int32Value()); 11496 CHECK_EQ(-43, value->Int32Value(context.local()).FromJust());
10203 11497
10204 // Check that the call-as-function handler can be called through 11498 // Check that the call-as-function handler can be called through
10205 // the API. 11499 // the API.
10206 v8::Handle<Value> args[] = {v8_num(28)}; 11500 v8::Local<Value> args[] = {v8_num(28)};
10207 value = instance->CallAsFunction(instance, 1, args); 11501 value = instance->CallAsFunction(instance, 1, args);
10208 CHECK(!try_catch.HasCaught()); 11502 CHECK(!try_catch.HasCaught());
10209 CHECK_EQ(28, value->Int32Value()); 11503 CHECK_EQ(28, value->Int32Value(context.local()).FromJust());
10210 } 11504 }
10211 11505
10212 { 11506 {
10213 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 11507 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10214 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); 11508 Local<ObjectTemplate> instance_template(t->InstanceTemplate());
10215 USE(instance_template); 11509 USE(instance_template);
10216 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 11510 Local<v8::Object> instance = t->GetFunction(context.local())
10217 context->Global()->Set(v8_str("obj2"), instance); 11511 .ToLocalChecked()
11512 ->NewInstance(context.local())
11513 .ToLocalChecked();
11514 CHECK(context->Global()
11515 ->Set(context.local(), v8_str("obj2"), instance)
11516 .FromJust());
10218 v8::TryCatch try_catch(isolate); 11517 v8::TryCatch try_catch(isolate);
10219 Local<Value> value; 11518 Local<Value> value;
10220 CHECK(!try_catch.HasCaught()); 11519 CHECK(!try_catch.HasCaught());
10221 11520
10222 // Call an object without call-as-function handler through the JS 11521 // Call an object without call-as-function handler through the JS
10223 value = CompileRun("obj2(28)"); 11522 value = CompileRun("obj2(28)");
10224 CHECK(value.IsEmpty()); 11523 CHECK(value.IsEmpty());
10225 CHECK(try_catch.HasCaught()); 11524 CHECK(try_catch.HasCaught());
10226 String::Utf8Value exception_value1(try_catch.Exception()); 11525 String::Utf8Value exception_value1(try_catch.Exception());
10227 // TODO(verwaest): Better message 11526 // TODO(verwaest): Better message
10228 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1)); 11527 CHECK_EQ(0, strcmp("TypeError: obj2 is not a function", *exception_value1));
10229 try_catch.Reset(); 11528 try_catch.Reset();
10230 11529
10231 // Call an object without call-as-function handler through the API 11530 // Call an object without call-as-function handler through the API
10232 value = CompileRun("obj2(28)"); 11531 value = CompileRun("obj2(28)");
10233 v8::Handle<Value> args[] = {v8_num(28)}; 11532 v8::Local<Value> args[] = {v8_num(28)};
10234 value = instance->CallAsFunction(instance, 1, args); 11533 value = instance->CallAsFunction(instance, 1, args);
10235 CHECK(value.IsEmpty()); 11534 CHECK(value.IsEmpty());
10236 CHECK(try_catch.HasCaught()); 11535 CHECK(try_catch.HasCaught());
10237 String::Utf8Value exception_value2(try_catch.Exception()); 11536 String::Utf8Value exception_value2(try_catch.Exception());
10238 CHECK_EQ(0, 11537 CHECK_EQ(0,
10239 strcmp("TypeError: object is not a function", *exception_value2)); 11538 strcmp("TypeError: object is not a function", *exception_value2));
10240 try_catch.Reset(); 11539 try_catch.Reset();
10241 } 11540 }
10242 11541
10243 { 11542 {
10244 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 11543 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10245 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 11544 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10246 instance_template->SetCallAsFunctionHandler(ThrowValue); 11545 instance_template->SetCallAsFunctionHandler(ThrowValue);
10247 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 11546 Local<v8::Object> instance = t->GetFunction(context.local())
10248 context->Global()->Set(v8_str("obj3"), instance); 11547 .ToLocalChecked()
11548 ->NewInstance(context.local())
11549 .ToLocalChecked();
11550 CHECK(context->Global()
11551 ->Set(context.local(), v8_str("obj3"), instance)
11552 .FromJust());
10249 v8::TryCatch try_catch(isolate); 11553 v8::TryCatch try_catch(isolate);
10250 Local<Value> value; 11554 Local<Value> value;
10251 CHECK(!try_catch.HasCaught()); 11555 CHECK(!try_catch.HasCaught());
10252 11556
10253 // Catch the exception which is thrown by call-as-function handler 11557 // Catch the exception which is thrown by call-as-function handler
10254 value = CompileRun("obj3(22)"); 11558 value = CompileRun("obj3(22)");
10255 CHECK(try_catch.HasCaught()); 11559 CHECK(try_catch.HasCaught());
10256 String::Utf8Value exception_value1(try_catch.Exception()); 11560 String::Utf8Value exception_value1(try_catch.Exception());
10257 CHECK_EQ(0, strcmp("22", *exception_value1)); 11561 CHECK_EQ(0, strcmp("22", *exception_value1));
10258 try_catch.Reset(); 11562 try_catch.Reset();
10259 11563
10260 v8::Handle<Value> args[] = {v8_num(23)}; 11564 v8::Local<Value> args[] = {v8_num(23)};
10261 value = instance->CallAsFunction(instance, 1, args); 11565 value = instance->CallAsFunction(instance, 1, args);
10262 CHECK(try_catch.HasCaught()); 11566 CHECK(try_catch.HasCaught());
10263 String::Utf8Value exception_value2(try_catch.Exception()); 11567 String::Utf8Value exception_value2(try_catch.Exception());
10264 CHECK_EQ(0, strcmp("23", *exception_value2)); 11568 CHECK_EQ(0, strcmp("23", *exception_value2));
10265 try_catch.Reset(); 11569 try_catch.Reset();
10266 } 11570 }
10267 11571
10268 { 11572 {
10269 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate); 11573 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10270 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 11574 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10271 instance_template->SetCallAsFunctionHandler(ReturnThis); 11575 instance_template->SetCallAsFunctionHandler(ReturnThis);
10272 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 11576 Local<v8::Object> instance = t->GetFunction(context.local())
11577 .ToLocalChecked()
11578 ->NewInstance(context.local())
11579 .ToLocalChecked();
10273 11580
10274 Local<v8::Value> a1 = 11581 Local<v8::Value> a1 =
10275 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); 11582 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL);
10276 CHECK(a1->StrictEquals(instance)); 11583 CHECK(a1->StrictEquals(instance));
10277 Local<v8::Value> a2 = instance->CallAsFunction(v8::Null(isolate), 0, NULL); 11584 Local<v8::Value> a2 = instance->CallAsFunction(v8::Null(isolate), 0, NULL);
10278 CHECK(a2->StrictEquals(instance)); 11585 CHECK(a2->StrictEquals(instance));
10279 Local<v8::Value> a3 = instance->CallAsFunction(v8_num(42), 0, NULL); 11586 Local<v8::Value> a3 = instance->CallAsFunction(v8_num(42), 0, NULL);
10280 CHECK(a3->StrictEquals(instance)); 11587 CHECK(a3->StrictEquals(instance));
10281 Local<v8::Value> a4 = instance->CallAsFunction(v8_str("hello"), 0, NULL); 11588 Local<v8::Value> a4 = instance->CallAsFunction(v8_str("hello"), 0, NULL);
10282 CHECK(a4->StrictEquals(instance)); 11589 CHECK(a4->StrictEquals(instance));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
10336 11643
10337 // Check whether a non-function object is callable. 11644 // Check whether a non-function object is callable.
10338 THREADED_TEST(CallableObject) { 11645 THREADED_TEST(CallableObject) {
10339 LocalContext context; 11646 LocalContext context;
10340 v8::Isolate* isolate = context->GetIsolate(); 11647 v8::Isolate* isolate = context->GetIsolate();
10341 v8::HandleScope scope(isolate); 11648 v8::HandleScope scope(isolate);
10342 11649
10343 { 11650 {
10344 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11651 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10345 instance_template->SetCallAsFunctionHandler(call_as_function); 11652 instance_template->SetCallAsFunctionHandler(call_as_function);
10346 Local<Object> instance = instance_template->NewInstance(); 11653 Local<Object> instance =
11654 instance_template->NewInstance(context.local()).ToLocalChecked();
10347 v8::TryCatch try_catch(isolate); 11655 v8::TryCatch try_catch(isolate);
10348 11656
10349 CHECK(instance->IsCallable()); 11657 CHECK(instance->IsCallable());
10350 CHECK(!try_catch.HasCaught()); 11658 CHECK(!try_catch.HasCaught());
10351 } 11659 }
10352 11660
10353 { 11661 {
10354 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate); 11662 Local<ObjectTemplate> instance_template = ObjectTemplate::New(isolate);
10355 Local<Object> instance = instance_template->NewInstance(); 11663 Local<Object> instance =
11664 instance_template->NewInstance(context.local()).ToLocalChecked();
10356 v8::TryCatch try_catch(isolate); 11665 v8::TryCatch try_catch(isolate);
10357 11666
10358 CHECK(!instance->IsCallable()); 11667 CHECK(!instance->IsCallable());
10359 CHECK(!try_catch.HasCaught()); 11668 CHECK(!try_catch.HasCaught());
10360 } 11669 }
10361 11670
10362 { 11671 {
10363 Local<FunctionTemplate> function_template = 11672 Local<FunctionTemplate> function_template =
10364 FunctionTemplate::New(isolate, call_as_function); 11673 FunctionTemplate::New(isolate, call_as_function);
10365 Local<Function> function = function_template->GetFunction(); 11674 Local<Function> function =
11675 function_template->GetFunction(context.local()).ToLocalChecked();
10366 Local<Object> instance = function; 11676 Local<Object> instance = function;
10367 v8::TryCatch try_catch(isolate); 11677 v8::TryCatch try_catch(isolate);
10368 11678
10369 CHECK(instance->IsCallable()); 11679 CHECK(instance->IsCallable());
10370 CHECK(!try_catch.HasCaught()); 11680 CHECK(!try_catch.HasCaught());
10371 } 11681 }
10372 11682
10373 { 11683 {
10374 Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate); 11684 Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate);
10375 Local<Function> function = function_template->GetFunction(); 11685 Local<Function> function =
11686 function_template->GetFunction(context.local()).ToLocalChecked();
10376 Local<Object> instance = function; 11687 Local<Object> instance = function;
10377 v8::TryCatch try_catch(isolate); 11688 v8::TryCatch try_catch(isolate);
10378 11689
10379 CHECK(instance->IsCallable()); 11690 CHECK(instance->IsCallable());
10380 CHECK(!try_catch.HasCaught()); 11691 CHECK(!try_catch.HasCaught());
10381 } 11692 }
10382 } 11693 }
10383 11694
10384 11695
10385 static int Recurse(v8::Isolate* isolate, int depth, int iterations) { 11696 static int Recurse(v8::Isolate* isolate, int depth, int iterations) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
10436 } 11747 }
10437 11748
10438 static void FastApiCallback_TrivialSignature( 11749 static void FastApiCallback_TrivialSignature(
10439 const v8::FunctionCallbackInfo<v8::Value>& args) { 11750 const v8::FunctionCallbackInfo<v8::Value>& args) {
10440 ApiTestFuzzer::Fuzz(); 11751 ApiTestFuzzer::Fuzz();
10441 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature)); 11752 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_TrivialSignature));
10442 v8::Isolate* isolate = CcTest::isolate(); 11753 v8::Isolate* isolate = CcTest::isolate();
10443 CHECK_EQ(isolate, args.GetIsolate()); 11754 CHECK_EQ(isolate, args.GetIsolate());
10444 CHECK(args.This()->Equals(args.Holder())); 11755 CHECK(args.This()->Equals(args.Holder()));
10445 CHECK(args.Data()->Equals(v8_str("method_data"))); 11756 CHECK(args.Data()->Equals(v8_str("method_data")));
10446 args.GetReturnValue().Set(args[0]->Int32Value() + 1); 11757 args.GetReturnValue().Set(
11758 args[0]->Int32Value(isolate->GetCurrentContext()).FromJust() + 1);
10447 } 11759 }
10448 11760
10449 static void FastApiCallback_SimpleSignature( 11761 static void FastApiCallback_SimpleSignature(
10450 const v8::FunctionCallbackInfo<v8::Value>& args) { 11762 const v8::FunctionCallbackInfo<v8::Value>& args) {
10451 ApiTestFuzzer::Fuzz(); 11763 ApiTestFuzzer::Fuzz();
10452 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature)); 11764 CheckReturnValue(args, FUNCTION_ADDR(FastApiCallback_SimpleSignature));
10453 v8::Isolate* isolate = CcTest::isolate(); 11765 v8::Isolate* isolate = CcTest::isolate();
10454 CHECK_EQ(isolate, args.GetIsolate()); 11766 CHECK_EQ(isolate, args.GetIsolate());
10455 CHECK(args.This()->GetPrototype()->Equals(args.Holder())); 11767 CHECK(args.This()->GetPrototype()->Equals(args.Holder()));
10456 CHECK(args.Data()->Equals(v8_str("method_data"))); 11768 CHECK(args.Data()->Equals(v8_str("method_data")));
10457 // Note, we're using HasRealNamedProperty instead of Has to avoid 11769 // Note, we're using HasRealNamedProperty instead of Has to avoid
10458 // invoking the interceptor again. 11770 // invoking the interceptor again.
10459 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo"))); 11771 CHECK(args.Holder()->HasRealNamedProperty(v8_str("foo")));
10460 args.GetReturnValue().Set(args[0]->Int32Value() + 1); 11772 args.GetReturnValue().Set(
11773 args[0]->Int32Value(isolate->GetCurrentContext()).FromJust() + 1);
10461 } 11774 }
10462 11775
10463 11776
10464 // Helper to maximize the odds of object moving. 11777 // Helper to maximize the odds of object moving.
10465 static void GenerateSomeGarbage() { 11778 static void GenerateSomeGarbage() {
10466 CompileRun( 11779 CompileRun(
10467 "var garbage;" 11780 "var garbage;"
10468 "for (var i = 0; i < 1000; i++) {" 11781 "for (var i = 0; i < 1000; i++) {"
10469 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];" 11782 " garbage = [1/i, \"garbage\" + i, garbage, {foo: garbage}];"
10470 "}" 11783 "}"
10471 "garbage = undefined;"); 11784 "garbage = undefined;");
10472 } 11785 }
10473 11786
10474 11787
10475 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) { 11788 void DirectApiCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
10476 static int count = 0; 11789 static int count = 0;
10477 if (count++ % 3 == 0) { 11790 if (count++ % 3 == 0) {
10478 CcTest::heap()->CollectAllGarbage(); 11791 CcTest::heap()->CollectAllGarbage();
10479 // This should move the stub 11792 // This should move the stub
10480 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 11793 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
10481 } 11794 }
10482 } 11795 }
10483 11796
10484 11797
10485 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 11798 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
10486 LocalContext context; 11799 LocalContext context;
10487 v8::Isolate* isolate = context->GetIsolate(); 11800 v8::Isolate* isolate = context->GetIsolate();
10488 v8::HandleScope scope(isolate); 11801 v8::HandleScope scope(isolate);
10489 v8::Handle<v8::ObjectTemplate> nativeobject_templ = 11802 v8::Local<v8::ObjectTemplate> nativeobject_templ =
10490 v8::ObjectTemplate::New(isolate); 11803 v8::ObjectTemplate::New(isolate);
10491 nativeobject_templ->Set(isolate, "callback", 11804 nativeobject_templ->Set(isolate, "callback",
10492 v8::FunctionTemplate::New(isolate, 11805 v8::FunctionTemplate::New(isolate,
10493 DirectApiCallback)); 11806 DirectApiCallback));
10494 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11807 v8::Local<v8::Object> nativeobject_obj =
10495 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11808 nativeobject_templ->NewInstance(context.local()).ToLocalChecked();
11809 CHECK(context->Global()
11810 ->Set(context.local(), v8_str("nativeobject"), nativeobject_obj)
11811 .FromJust());
10496 // call the api function multiple times to ensure direct call stub creation. 11812 // call the api function multiple times to ensure direct call stub creation.
10497 CompileRun( 11813 CompileRun(
10498 "function f() {" 11814 "function f() {"
10499 " for (var i = 1; i <= 30; i++) {" 11815 " for (var i = 1; i <= 30; i++) {"
10500 " nativeobject.callback();" 11816 " nativeobject.callback();"
10501 " }" 11817 " }"
10502 "}" 11818 "}"
10503 "f();"); 11819 "f();");
10504 } 11820 }
10505 11821
10506 11822
10507 void ThrowingDirectApiCallback( 11823 void ThrowingDirectApiCallback(
10508 const v8::FunctionCallbackInfo<v8::Value>& args) { 11824 const v8::FunctionCallbackInfo<v8::Value>& args) {
10509 args.GetIsolate()->ThrowException(v8_str("g")); 11825 args.GetIsolate()->ThrowException(v8_str("g"));
10510 } 11826 }
10511 11827
10512 11828
10513 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 11829 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
10514 LocalContext context; 11830 LocalContext context;
10515 v8::Isolate* isolate = context->GetIsolate(); 11831 v8::Isolate* isolate = context->GetIsolate();
10516 v8::HandleScope scope(isolate); 11832 v8::HandleScope scope(isolate);
10517 v8::Handle<v8::ObjectTemplate> nativeobject_templ = 11833 v8::Local<v8::ObjectTemplate> nativeobject_templ =
10518 v8::ObjectTemplate::New(isolate); 11834 v8::ObjectTemplate::New(isolate);
10519 nativeobject_templ->Set(isolate, "callback", 11835 nativeobject_templ->Set(isolate, "callback",
10520 v8::FunctionTemplate::New(isolate, 11836 v8::FunctionTemplate::New(isolate,
10521 ThrowingDirectApiCallback)); 11837 ThrowingDirectApiCallback));
10522 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11838 v8::Local<v8::Object> nativeobject_obj =
10523 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11839 nativeobject_templ->NewInstance(context.local()).ToLocalChecked();
11840 CHECK(context->Global()
11841 ->Set(context.local(), v8_str("nativeobject"), nativeobject_obj)
11842 .FromJust());
10524 // call the api function multiple times to ensure direct call stub creation. 11843 // call the api function multiple times to ensure direct call stub creation.
10525 v8::Handle<Value> result = CompileRun( 11844 v8::Local<Value> result = CompileRun(
10526 "var result = '';" 11845 "var result = '';"
10527 "function f() {" 11846 "function f() {"
10528 " for (var i = 1; i <= 5; i++) {" 11847 " for (var i = 1; i <= 5; i++) {"
10529 " try { nativeobject.callback(); } catch (e) { result += e; }" 11848 " try { nativeobject.callback(); } catch (e) { result += e; }"
10530 " }" 11849 " }"
10531 "}" 11850 "}"
10532 "f(); result;"); 11851 "f(); result;");
10533 CHECK(v8_str("ggggg")->Equals(result)); 11852 CHECK(v8_str("ggggg")->Equals(result));
10534 } 11853 }
10535 11854
10536 11855
10537 static int p_getter_count_3; 11856 static int p_getter_count_3;
10538 11857
10539 11858
10540 static Handle<Value> DoDirectGetter() { 11859 static Local<Value> DoDirectGetter() {
10541 if (++p_getter_count_3 % 3 == 0) { 11860 if (++p_getter_count_3 % 3 == 0) {
10542 CcTest::heap()->CollectAllGarbage(); 11861 CcTest::heap()->CollectAllGarbage();
10543 GenerateSomeGarbage(); 11862 GenerateSomeGarbage();
10544 } 11863 }
10545 return v8_str("Direct Getter Result"); 11864 return v8_str("Direct Getter Result");
10546 } 11865 }
10547 11866
10548 11867
10549 static void DirectGetterCallback( 11868 static void DirectGetterCallback(
10550 Local<String> name, 11869 Local<String> name,
10551 const v8::PropertyCallbackInfo<v8::Value>& info) { 11870 const v8::PropertyCallbackInfo<v8::Value>& info) {
10552 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback)); 11871 CheckReturnValue(info, FUNCTION_ADDR(DirectGetterCallback));
10553 info.GetReturnValue().Set(DoDirectGetter()); 11872 info.GetReturnValue().Set(DoDirectGetter());
10554 } 11873 }
10555 11874
10556 11875
10557 template<typename Accessor> 11876 template<typename Accessor>
10558 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) { 11877 static void LoadICFastApi_DirectCall_GCMoveStub(Accessor accessor) {
10559 LocalContext context; 11878 LocalContext context;
10560 v8::Isolate* isolate = context->GetIsolate(); 11879 v8::Isolate* isolate = context->GetIsolate();
10561 v8::HandleScope scope(isolate); 11880 v8::HandleScope scope(isolate);
10562 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); 11881 v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate);
10563 obj->SetAccessor(v8_str("p1"), accessor); 11882 obj->SetAccessor(v8_str("p1"), accessor);
10564 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 11883 CHECK(context->Global()
11884 ->Set(context.local(), v8_str("o1"),
11885 obj->NewInstance(context.local()).ToLocalChecked())
11886 .FromJust());
10565 p_getter_count_3 = 0; 11887 p_getter_count_3 = 0;
10566 v8::Handle<v8::Value> result = CompileRun( 11888 v8::Local<v8::Value> result = CompileRun(
10567 "function f() {" 11889 "function f() {"
10568 " for (var i = 0; i < 30; i++) o1.p1;" 11890 " for (var i = 0; i < 30; i++) o1.p1;"
10569 " return o1.p1" 11891 " return o1.p1"
10570 "}" 11892 "}"
10571 "f();"); 11893 "f();");
10572 CHECK(v8_str("Direct Getter Result")->Equals(result)); 11894 CHECK(v8_str("Direct Getter Result")->Equals(result));
10573 CHECK_EQ(31, p_getter_count_3); 11895 CHECK_EQ(31, p_getter_count_3);
10574 } 11896 }
10575 11897
10576 11898
10577 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) { 11899 THREADED_PROFILED_TEST(LoadICFastApi_DirectCall_GCMoveStub) {
10578 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback); 11900 LoadICFastApi_DirectCall_GCMoveStub(DirectGetterCallback);
10579 } 11901 }
10580 11902
10581 11903
10582 void ThrowingDirectGetterCallback( 11904 void ThrowingDirectGetterCallback(
10583 Local<String> name, 11905 Local<String> name,
10584 const v8::PropertyCallbackInfo<v8::Value>& info) { 11906 const v8::PropertyCallbackInfo<v8::Value>& info) {
10585 info.GetIsolate()->ThrowException(v8_str("g")); 11907 info.GetIsolate()->ThrowException(v8_str("g"));
10586 } 11908 }
10587 11909
10588 11910
10589 THREADED_TEST(LoadICFastApi_DirectCall_Throw) { 11911 THREADED_TEST(LoadICFastApi_DirectCall_Throw) {
10590 LocalContext context; 11912 LocalContext context;
10591 v8::Isolate* isolate = context->GetIsolate(); 11913 v8::Isolate* isolate = context->GetIsolate();
10592 v8::HandleScope scope(isolate); 11914 v8::HandleScope scope(isolate);
10593 v8::Handle<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate); 11915 v8::Local<v8::ObjectTemplate> obj = v8::ObjectTemplate::New(isolate);
10594 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback); 11916 obj->SetAccessor(v8_str("p1"), ThrowingDirectGetterCallback);
10595 context->Global()->Set(v8_str("o1"), obj->NewInstance()); 11917 CHECK(context->Global()
10596 v8::Handle<Value> result = CompileRun( 11918 ->Set(context.local(), v8_str("o1"),
11919 obj->NewInstance(context.local()).ToLocalChecked())
11920 .FromJust());
11921 v8::Local<Value> result = CompileRun(
10597 "var result = '';" 11922 "var result = '';"
10598 "for (var i = 0; i < 5; i++) {" 11923 "for (var i = 0; i < 5; i++) {"
10599 " try { o1.p1; } catch (e) { result += e; }" 11924 " try { o1.p1; } catch (e) { result += e; }"
10600 "}" 11925 "}"
10601 "result;"); 11926 "result;");
10602 CHECK(v8_str("ggggg")->Equals(result)); 11927 CHECK(v8_str("ggggg")->Equals(result));
10603 } 11928 }
10604 11929
10605 11930
10606 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { 11931 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) {
10607 int interceptor_call_count = 0; 11932 int interceptor_call_count = 0;
10608 v8::Isolate* isolate = CcTest::isolate(); 11933 v8::Isolate* isolate = CcTest::isolate();
10609 v8::HandleScope scope(isolate); 11934 v8::HandleScope scope(isolate);
10610 v8::Handle<v8::FunctionTemplate> fun_templ = 11935 v8::Local<v8::FunctionTemplate> fun_templ =
10611 v8::FunctionTemplate::New(isolate); 11936 v8::FunctionTemplate::New(isolate);
10612 v8::Handle<v8::FunctionTemplate> method_templ = 11937 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10613 v8::FunctionTemplate::New(isolate, 11938 isolate, FastApiCallback_TrivialSignature, v8_str("method_data"),
10614 FastApiCallback_TrivialSignature, 11939 v8::Local<v8::Signature>());
10615 v8_str("method_data"), 11940 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); 11941 proto_templ->Set(v8_str("method"), method_templ);
10619 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11942 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10620 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 11943 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10621 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11944 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10622 v8::External::New(isolate, &interceptor_call_count))); 11945 v8::External::New(isolate, &interceptor_call_count)));
10623 LocalContext context; 11946 LocalContext context;
10624 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11947 v8::Local<v8::Function> fun =
11948 fun_templ->GetFunction(context.local()).ToLocalChecked();
10625 GenerateSomeGarbage(); 11949 GenerateSomeGarbage();
10626 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11950 CHECK(context->Global()
11951 ->Set(context.local(), v8_str("o"),
11952 fun->NewInstance(context.local()).ToLocalChecked())
11953 .FromJust());
10627 CompileRun( 11954 CompileRun(
10628 "var result = 0;" 11955 "var result = 0;"
10629 "for (var i = 0; i < 100; i++) {" 11956 "for (var i = 0; i < 100; i++) {"
10630 " result = o.method(41);" 11957 " result = o.method(41);"
10631 "}"); 11958 "}");
10632 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11959 CHECK_EQ(42, context->Global()
11960 ->Get(v8_str("result"))
11961 ->Int32Value(context.local())
11962 .FromJust());
10633 CHECK_EQ(100, interceptor_call_count); 11963 CHECK_EQ(100, interceptor_call_count);
10634 } 11964 }
10635 11965
10636 11966
10637 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { 11967 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) {
10638 int interceptor_call_count = 0; 11968 int interceptor_call_count = 0;
10639 v8::Isolate* isolate = CcTest::isolate(); 11969 v8::Isolate* isolate = CcTest::isolate();
10640 v8::HandleScope scope(isolate); 11970 v8::HandleScope scope(isolate);
10641 v8::Handle<v8::FunctionTemplate> fun_templ = 11971 v8::Local<v8::FunctionTemplate> fun_templ =
10642 v8::FunctionTemplate::New(isolate); 11972 v8::FunctionTemplate::New(isolate);
10643 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 11973 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10644 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 11974 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10645 v8::Signature::New(isolate, fun_templ)); 11975 v8::Signature::New(isolate, fun_templ));
10646 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11976 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10647 proto_templ->Set(v8_str("method"), method_templ); 11977 proto_templ->Set(v8_str("method"), method_templ);
10648 fun_templ->SetHiddenPrototype(true); 11978 fun_templ->SetHiddenPrototype(true);
10649 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11979 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10650 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 11980 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10651 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11981 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10652 v8::External::New(isolate, &interceptor_call_count))); 11982 v8::External::New(isolate, &interceptor_call_count)));
10653 LocalContext context; 11983 LocalContext context;
10654 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11984 v8::Local<v8::Function> fun =
11985 fun_templ->GetFunction(context.local()).ToLocalChecked();
10655 GenerateSomeGarbage(); 11986 GenerateSomeGarbage();
10656 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11987 CHECK(context->Global()
11988 ->Set(context.local(), v8_str("o"),
11989 fun->NewInstance(context.local()).ToLocalChecked())
11990 .FromJust());
10657 CompileRun( 11991 CompileRun(
10658 "o.foo = 17;" 11992 "o.foo = 17;"
10659 "var receiver = {};" 11993 "var receiver = {};"
10660 "receiver.__proto__ = o;" 11994 "receiver.__proto__ = o;"
10661 "var result = 0;" 11995 "var result = 0;"
10662 "for (var i = 0; i < 100; i++) {" 11996 "for (var i = 0; i < 100; i++) {"
10663 " result = receiver.method(41);" 11997 " result = receiver.method(41);"
10664 "}"); 11998 "}");
10665 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11999 CHECK_EQ(42, context->Global()
12000 ->Get(v8_str("result"))
12001 ->Int32Value(context.local())
12002 .FromJust());
10666 CHECK_EQ(100, interceptor_call_count); 12003 CHECK_EQ(100, interceptor_call_count);
10667 } 12004 }
10668 12005
10669 12006
10670 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 12007 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
10671 int interceptor_call_count = 0; 12008 int interceptor_call_count = 0;
10672 v8::Isolate* isolate = CcTest::isolate(); 12009 v8::Isolate* isolate = CcTest::isolate();
10673 v8::HandleScope scope(isolate); 12010 v8::HandleScope scope(isolate);
10674 v8::Handle<v8::FunctionTemplate> fun_templ = 12011 v8::Local<v8::FunctionTemplate> fun_templ =
10675 v8::FunctionTemplate::New(isolate); 12012 v8::FunctionTemplate::New(isolate);
10676 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12013 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10677 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12014 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10678 v8::Signature::New(isolate, fun_templ)); 12015 v8::Signature::New(isolate, fun_templ));
10679 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12016 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10680 proto_templ->Set(v8_str("method"), method_templ); 12017 proto_templ->Set(v8_str("method"), method_templ);
10681 fun_templ->SetHiddenPrototype(true); 12018 fun_templ->SetHiddenPrototype(true);
10682 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12019 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10683 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 12020 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10684 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12021 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10685 v8::External::New(isolate, &interceptor_call_count))); 12022 v8::External::New(isolate, &interceptor_call_count)));
10686 LocalContext context; 12023 LocalContext context;
10687 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12024 v8::Local<v8::Function> fun =
12025 fun_templ->GetFunction(context.local()).ToLocalChecked();
10688 GenerateSomeGarbage(); 12026 GenerateSomeGarbage();
10689 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12027 CHECK(context->Global()
12028 ->Set(context.local(), v8_str("o"),
12029 fun->NewInstance(context.local()).ToLocalChecked())
12030 .FromJust());
10690 CompileRun( 12031 CompileRun(
10691 "o.foo = 17;" 12032 "o.foo = 17;"
10692 "var receiver = {};" 12033 "var receiver = {};"
10693 "receiver.__proto__ = o;" 12034 "receiver.__proto__ = o;"
10694 "var result = 0;" 12035 "var result = 0;"
10695 "var saved_result = 0;" 12036 "var saved_result = 0;"
10696 "for (var i = 0; i < 100; i++) {" 12037 "for (var i = 0; i < 100; i++) {"
10697 " result = receiver.method(41);" 12038 " result = receiver.method(41);"
10698 " if (i == 50) {" 12039 " if (i == 50) {"
10699 " saved_result = result;" 12040 " saved_result = result;"
10700 " receiver = {method: function(x) { return x - 1 }};" 12041 " receiver = {method: function(x) { return x - 1 }};"
10701 " }" 12042 " }"
10702 "}"); 12043 "}");
10703 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 12044 CHECK_EQ(40, context->Global()
10704 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12045 ->Get(v8_str("result"))
12046 ->Int32Value(context.local())
12047 .FromJust());
12048 CHECK_EQ(42, context->Global()
12049 ->Get(v8_str("saved_result"))
12050 ->Int32Value(context.local())
12051 .FromJust());
10705 CHECK_GE(interceptor_call_count, 50); 12052 CHECK_GE(interceptor_call_count, 50);
10706 } 12053 }
10707 12054
10708 12055
10709 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 12056 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
10710 int interceptor_call_count = 0; 12057 int interceptor_call_count = 0;
10711 v8::Isolate* isolate = CcTest::isolate(); 12058 v8::Isolate* isolate = CcTest::isolate();
10712 v8::HandleScope scope(isolate); 12059 v8::HandleScope scope(isolate);
10713 v8::Handle<v8::FunctionTemplate> fun_templ = 12060 v8::Local<v8::FunctionTemplate> fun_templ =
10714 v8::FunctionTemplate::New(isolate); 12061 v8::FunctionTemplate::New(isolate);
10715 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12062 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10716 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12063 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10717 v8::Signature::New(isolate, fun_templ)); 12064 v8::Signature::New(isolate, fun_templ));
10718 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12065 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10719 proto_templ->Set(v8_str("method"), method_templ); 12066 proto_templ->Set(v8_str("method"), method_templ);
10720 fun_templ->SetHiddenPrototype(true); 12067 fun_templ->SetHiddenPrototype(true);
10721 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12068 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10722 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 12069 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10723 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12070 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10724 v8::External::New(isolate, &interceptor_call_count))); 12071 v8::External::New(isolate, &interceptor_call_count)));
10725 LocalContext context; 12072 LocalContext context;
10726 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12073 v8::Local<v8::Function> fun =
12074 fun_templ->GetFunction(context.local()).ToLocalChecked();
10727 GenerateSomeGarbage(); 12075 GenerateSomeGarbage();
10728 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12076 CHECK(context->Global()
12077 ->Set(context.local(), v8_str("o"),
12078 fun->NewInstance(context.local()).ToLocalChecked())
12079 .FromJust());
10729 CompileRun( 12080 CompileRun(
10730 "o.foo = 17;" 12081 "o.foo = 17;"
10731 "var receiver = {};" 12082 "var receiver = {};"
10732 "receiver.__proto__ = o;" 12083 "receiver.__proto__ = o;"
10733 "var result = 0;" 12084 "var result = 0;"
10734 "var saved_result = 0;" 12085 "var saved_result = 0;"
10735 "for (var i = 0; i < 100; i++) {" 12086 "for (var i = 0; i < 100; i++) {"
10736 " result = receiver.method(41);" 12087 " result = receiver.method(41);"
10737 " if (i == 50) {" 12088 " if (i == 50) {"
10738 " saved_result = result;" 12089 " saved_result = result;"
10739 " o.method = function(x) { return x - 1 };" 12090 " o.method = function(x) { return x - 1 };"
10740 " }" 12091 " }"
10741 "}"); 12092 "}");
10742 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 12093 CHECK_EQ(40, context->Global()
10743 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12094 ->Get(v8_str("result"))
12095 ->Int32Value(context.local())
12096 .FromJust());
12097 CHECK_EQ(42, context->Global()
12098 ->Get(v8_str("saved_result"))
12099 ->Int32Value(context.local())
12100 .FromJust());
10744 CHECK_GE(interceptor_call_count, 50); 12101 CHECK_GE(interceptor_call_count, 50);
10745 } 12102 }
10746 12103
10747 12104
10748 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 12105 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
10749 int interceptor_call_count = 0; 12106 int interceptor_call_count = 0;
10750 v8::Isolate* isolate = CcTest::isolate(); 12107 v8::Isolate* isolate = CcTest::isolate();
10751 v8::HandleScope scope(isolate); 12108 v8::HandleScope scope(isolate);
10752 v8::Handle<v8::FunctionTemplate> fun_templ = 12109 v8::Local<v8::FunctionTemplate> fun_templ =
10753 v8::FunctionTemplate::New(isolate); 12110 v8::FunctionTemplate::New(isolate);
10754 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12111 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10755 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12112 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10756 v8::Signature::New(isolate, fun_templ)); 12113 v8::Signature::New(isolate, fun_templ));
10757 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12114 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10758 proto_templ->Set(v8_str("method"), method_templ); 12115 proto_templ->Set(v8_str("method"), method_templ);
10759 fun_templ->SetHiddenPrototype(true); 12116 fun_templ->SetHiddenPrototype(true);
10760 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12117 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10761 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 12118 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10762 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12119 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10763 v8::External::New(isolate, &interceptor_call_count))); 12120 v8::External::New(isolate, &interceptor_call_count)));
10764 LocalContext context; 12121 LocalContext context;
10765 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12122 v8::Local<v8::Function> fun =
12123 fun_templ->GetFunction(context.local()).ToLocalChecked();
10766 GenerateSomeGarbage(); 12124 GenerateSomeGarbage();
10767 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12125 CHECK(context->Global()
12126 ->Set(context.local(), v8_str("o"),
12127 fun->NewInstance(context.local()).ToLocalChecked())
12128 .FromJust());
10768 v8::TryCatch try_catch(isolate); 12129 v8::TryCatch try_catch(isolate);
10769 CompileRun( 12130 CompileRun(
10770 "o.foo = 17;" 12131 "o.foo = 17;"
10771 "var receiver = {};" 12132 "var receiver = {};"
10772 "receiver.__proto__ = o;" 12133 "receiver.__proto__ = o;"
10773 "var result = 0;" 12134 "var result = 0;"
10774 "var saved_result = 0;" 12135 "var saved_result = 0;"
10775 "for (var i = 0; i < 100; i++) {" 12136 "for (var i = 0; i < 100; i++) {"
10776 " result = receiver.method(41);" 12137 " result = receiver.method(41);"
10777 " if (i == 50) {" 12138 " if (i == 50) {"
10778 " saved_result = result;" 12139 " saved_result = result;"
10779 " receiver = 333;" 12140 " receiver = 333;"
10780 " }" 12141 " }"
10781 "}"); 12142 "}");
10782 CHECK(try_catch.HasCaught()); 12143 CHECK(try_catch.HasCaught());
10783 // TODO(verwaest): Adjust message. 12144 // TODO(verwaest): Adjust message.
10784 CHECK(v8_str("TypeError: receiver.method is not a function") 12145 CHECK(v8_str("TypeError: receiver.method is not a function")
10785 ->Equals(try_catch.Exception()->ToString(isolate))); 12146 ->Equals(try_catch.Exception()->ToString(isolate)));
10786 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12147 CHECK_EQ(42, context->Global()
12148 ->Get(v8_str("saved_result"))
12149 ->Int32Value(context.local())
12150 .FromJust());
10787 CHECK_GE(interceptor_call_count, 50); 12151 CHECK_GE(interceptor_call_count, 50);
10788 } 12152 }
10789 12153
10790 12154
10791 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 12155 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
10792 int interceptor_call_count = 0; 12156 int interceptor_call_count = 0;
10793 v8::Isolate* isolate = CcTest::isolate(); 12157 v8::Isolate* isolate = CcTest::isolate();
10794 v8::HandleScope scope(isolate); 12158 v8::HandleScope scope(isolate);
10795 v8::Handle<v8::FunctionTemplate> fun_templ = 12159 v8::Local<v8::FunctionTemplate> fun_templ =
10796 v8::FunctionTemplate::New(isolate); 12160 v8::FunctionTemplate::New(isolate);
10797 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12161 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10798 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12162 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10799 v8::Signature::New(isolate, fun_templ)); 12163 v8::Signature::New(isolate, fun_templ));
10800 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12164 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10801 proto_templ->Set(v8_str("method"), method_templ); 12165 proto_templ->Set(v8_str("method"), method_templ);
10802 fun_templ->SetHiddenPrototype(true); 12166 fun_templ->SetHiddenPrototype(true);
10803 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12167 v8::Local<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
10804 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 12168 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
10805 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12169 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
10806 v8::External::New(isolate, &interceptor_call_count))); 12170 v8::External::New(isolate, &interceptor_call_count)));
10807 LocalContext context; 12171 LocalContext context;
10808 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12172 v8::Local<v8::Function> fun =
12173 fun_templ->GetFunction(context.local()).ToLocalChecked();
10809 GenerateSomeGarbage(); 12174 GenerateSomeGarbage();
10810 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12175 CHECK(context->Global()
12176 ->Set(context.local(), v8_str("o"),
12177 fun->NewInstance(context.local()).ToLocalChecked())
12178 .FromJust());
10811 v8::TryCatch try_catch(isolate); 12179 v8::TryCatch try_catch(isolate);
10812 CompileRun( 12180 CompileRun(
10813 "o.foo = 17;" 12181 "o.foo = 17;"
10814 "var receiver = {};" 12182 "var receiver = {};"
10815 "receiver.__proto__ = o;" 12183 "receiver.__proto__ = o;"
10816 "var result = 0;" 12184 "var result = 0;"
10817 "var saved_result = 0;" 12185 "var saved_result = 0;"
10818 "for (var i = 0; i < 100; i++) {" 12186 "for (var i = 0; i < 100; i++) {"
10819 " result = receiver.method(41);" 12187 " result = receiver.method(41);"
10820 " if (i == 50) {" 12188 " if (i == 50) {"
10821 " saved_result = result;" 12189 " saved_result = result;"
10822 " receiver = {method: receiver.method};" 12190 " receiver = {method: receiver.method};"
10823 " }" 12191 " }"
10824 "}"); 12192 "}");
10825 CHECK(try_catch.HasCaught()); 12193 CHECK(try_catch.HasCaught());
10826 CHECK(v8_str("TypeError: Illegal invocation") 12194 CHECK(v8_str("TypeError: Illegal invocation")
10827 ->Equals(try_catch.Exception()->ToString(isolate))); 12195 ->Equals(try_catch.Exception()->ToString(isolate)));
10828 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12196 CHECK_EQ(42, context->Global()
12197 ->Get(v8_str("saved_result"))
12198 ->Int32Value(context.local())
12199 .FromJust());
10829 CHECK_GE(interceptor_call_count, 50); 12200 CHECK_GE(interceptor_call_count, 50);
10830 } 12201 }
10831 12202
10832 12203
10833 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { 12204 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) {
10834 v8::Isolate* isolate = CcTest::isolate(); 12205 v8::Isolate* isolate = CcTest::isolate();
10835 v8::HandleScope scope(isolate); 12206 v8::HandleScope scope(isolate);
10836 v8::Handle<v8::FunctionTemplate> fun_templ = 12207 v8::Local<v8::FunctionTemplate> fun_templ =
10837 v8::FunctionTemplate::New(isolate); 12208 v8::FunctionTemplate::New(isolate);
10838 v8::Handle<v8::FunctionTemplate> method_templ = 12209 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10839 v8::FunctionTemplate::New(isolate, 12210 isolate, FastApiCallback_TrivialSignature, v8_str("method_data"),
10840 FastApiCallback_TrivialSignature, 12211 v8::Local<v8::Signature>());
10841 v8_str("method_data"), 12212 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); 12213 proto_templ->Set(v8_str("method"), method_templ);
10845 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12214 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10846 USE(templ); 12215 USE(templ);
10847 LocalContext context; 12216 LocalContext context;
10848 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12217 v8::Local<v8::Function> fun =
12218 fun_templ->GetFunction(context.local()).ToLocalChecked();
10849 GenerateSomeGarbage(); 12219 GenerateSomeGarbage();
10850 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12220 CHECK(context->Global()
12221 ->Set(context.local(), v8_str("o"),
12222 fun->NewInstance(context.local()).ToLocalChecked())
12223 .FromJust());
10851 CompileRun( 12224 CompileRun(
10852 "var result = 0;" 12225 "var result = 0;"
10853 "for (var i = 0; i < 100; i++) {" 12226 "for (var i = 0; i < 100; i++) {"
10854 " result = o.method(41);" 12227 " result = o.method(41);"
10855 "}"); 12228 "}");
10856 12229
10857 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 12230 CHECK_EQ(42, context->Global()
12231 ->Get(v8_str("result"))
12232 ->Int32Value(context.local())
12233 .FromJust());
10858 } 12234 }
10859 12235
10860 12236
10861 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { 12237 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) {
10862 v8::Isolate* isolate = CcTest::isolate(); 12238 v8::Isolate* isolate = CcTest::isolate();
10863 v8::HandleScope scope(isolate); 12239 v8::HandleScope scope(isolate);
10864 v8::Handle<v8::FunctionTemplate> fun_templ = 12240 v8::Local<v8::FunctionTemplate> fun_templ =
10865 v8::FunctionTemplate::New(isolate); 12241 v8::FunctionTemplate::New(isolate);
10866 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12242 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10867 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12243 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10868 v8::Signature::New(isolate, fun_templ)); 12244 v8::Signature::New(isolate, fun_templ));
10869 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12245 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10870 proto_templ->Set(v8_str("method"), method_templ); 12246 proto_templ->Set(v8_str("method"), method_templ);
10871 fun_templ->SetHiddenPrototype(true); 12247 fun_templ->SetHiddenPrototype(true);
10872 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12248 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10873 CHECK(!templ.IsEmpty()); 12249 CHECK(!templ.IsEmpty());
10874 LocalContext context; 12250 LocalContext context;
10875 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12251 v8::Local<v8::Function> fun =
12252 fun_templ->GetFunction(context.local()).ToLocalChecked();
10876 GenerateSomeGarbage(); 12253 GenerateSomeGarbage();
10877 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12254 CHECK(context->Global()
12255 ->Set(context.local(), v8_str("o"),
12256 fun->NewInstance(context.local()).ToLocalChecked())
12257 .FromJust());
10878 CompileRun( 12258 CompileRun(
10879 "o.foo = 17;" 12259 "o.foo = 17;"
10880 "var receiver = {};" 12260 "var receiver = {};"
10881 "receiver.__proto__ = o;" 12261 "receiver.__proto__ = o;"
10882 "var result = 0;" 12262 "var result = 0;"
10883 "for (var i = 0; i < 100; i++) {" 12263 "for (var i = 0; i < 100; i++) {"
10884 " result = receiver.method(41);" 12264 " result = receiver.method(41);"
10885 "}"); 12265 "}");
10886 12266
10887 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 12267 CHECK_EQ(42, context->Global()
12268 ->Get(v8_str("result"))
12269 ->Int32Value(context.local())
12270 .FromJust());
10888 } 12271 }
10889 12272
10890 12273
10891 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { 12274 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) {
10892 v8::Isolate* isolate = CcTest::isolate(); 12275 v8::Isolate* isolate = CcTest::isolate();
10893 v8::HandleScope scope(isolate); 12276 v8::HandleScope scope(isolate);
10894 v8::Handle<v8::FunctionTemplate> fun_templ = 12277 v8::Local<v8::FunctionTemplate> fun_templ =
10895 v8::FunctionTemplate::New(isolate); 12278 v8::FunctionTemplate::New(isolate);
10896 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12279 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10897 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12280 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10898 v8::Signature::New(isolate, fun_templ)); 12281 v8::Signature::New(isolate, fun_templ));
10899 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12282 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10900 proto_templ->Set(v8_str("method"), method_templ); 12283 proto_templ->Set(v8_str("method"), method_templ);
10901 fun_templ->SetHiddenPrototype(true); 12284 fun_templ->SetHiddenPrototype(true);
10902 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12285 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10903 CHECK(!templ.IsEmpty()); 12286 CHECK(!templ.IsEmpty());
10904 LocalContext context; 12287 LocalContext context;
10905 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12288 v8::Local<v8::Function> fun =
12289 fun_templ->GetFunction(context.local()).ToLocalChecked();
10906 GenerateSomeGarbage(); 12290 GenerateSomeGarbage();
10907 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12291 CHECK(context->Global()
12292 ->Set(context.local(), v8_str("o"),
12293 fun->NewInstance(context.local()).ToLocalChecked())
12294 .FromJust());
10908 CompileRun( 12295 CompileRun(
10909 "o.foo = 17;" 12296 "o.foo = 17;"
10910 "var receiver = {};" 12297 "var receiver = {};"
10911 "receiver.__proto__ = o;" 12298 "receiver.__proto__ = o;"
10912 "var result = 0;" 12299 "var result = 0;"
10913 "var saved_result = 0;" 12300 "var saved_result = 0;"
10914 "for (var i = 0; i < 100; i++) {" 12301 "for (var i = 0; i < 100; i++) {"
10915 " result = receiver.method(41);" 12302 " result = receiver.method(41);"
10916 " if (i == 50) {" 12303 " if (i == 50) {"
10917 " saved_result = result;" 12304 " saved_result = result;"
10918 " receiver = {method: function(x) { return x - 1 }};" 12305 " receiver = {method: function(x) { return x - 1 }};"
10919 " }" 12306 " }"
10920 "}"); 12307 "}");
10921 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 12308 CHECK_EQ(40, context->Global()
10922 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12309 ->Get(v8_str("result"))
12310 ->Int32Value(context.local())
12311 .FromJust());
12312 CHECK_EQ(42, context->Global()
12313 ->Get(v8_str("saved_result"))
12314 ->Int32Value(context.local())
12315 .FromJust());
10923 } 12316 }
10924 12317
10925 12318
10926 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { 12319 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
10927 v8::Isolate* isolate = CcTest::isolate(); 12320 v8::Isolate* isolate = CcTest::isolate();
10928 v8::HandleScope scope(isolate); 12321 v8::HandleScope scope(isolate);
10929 v8::Handle<v8::FunctionTemplate> fun_templ = 12322 v8::Local<v8::FunctionTemplate> fun_templ =
10930 v8::FunctionTemplate::New(isolate); 12323 v8::FunctionTemplate::New(isolate);
10931 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12324 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10932 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12325 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10933 v8::Signature::New(isolate, fun_templ)); 12326 v8::Signature::New(isolate, fun_templ));
10934 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12327 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10935 proto_templ->Set(v8_str("method"), method_templ); 12328 proto_templ->Set(v8_str("method"), method_templ);
10936 fun_templ->SetHiddenPrototype(true); 12329 fun_templ->SetHiddenPrototype(true);
10937 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12330 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10938 CHECK(!templ.IsEmpty()); 12331 CHECK(!templ.IsEmpty());
10939 LocalContext context; 12332 LocalContext context;
10940 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12333 v8::Local<v8::Function> fun =
12334 fun_templ->GetFunction(context.local()).ToLocalChecked();
10941 GenerateSomeGarbage(); 12335 GenerateSomeGarbage();
10942 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12336 CHECK(context->Global()
12337 ->Set(context.local(), v8_str("o"),
12338 fun->NewInstance(context.local()).ToLocalChecked())
12339 .FromJust());
10943 v8::TryCatch try_catch(isolate); 12340 v8::TryCatch try_catch(isolate);
10944 CompileRun( 12341 CompileRun(
10945 "o.foo = 17;" 12342 "o.foo = 17;"
10946 "var receiver = {};" 12343 "var receiver = {};"
10947 "receiver.__proto__ = o;" 12344 "receiver.__proto__ = o;"
10948 "var result = 0;" 12345 "var result = 0;"
10949 "var saved_result = 0;" 12346 "var saved_result = 0;"
10950 "for (var i = 0; i < 100; i++) {" 12347 "for (var i = 0; i < 100; i++) {"
10951 " result = receiver.method(41);" 12348 " result = receiver.method(41);"
10952 " if (i == 50) {" 12349 " if (i == 50) {"
10953 " saved_result = result;" 12350 " saved_result = result;"
10954 " receiver = 333;" 12351 " receiver = 333;"
10955 " }" 12352 " }"
10956 "}"); 12353 "}");
10957 CHECK(try_catch.HasCaught()); 12354 CHECK(try_catch.HasCaught());
10958 // TODO(verwaest): Adjust message. 12355 // TODO(verwaest): Adjust message.
10959 CHECK(v8_str("TypeError: receiver.method is not a function") 12356 CHECK(v8_str("TypeError: receiver.method is not a function")
10960 ->Equals(try_catch.Exception()->ToString(isolate))); 12357 ->Equals(try_catch.Exception()->ToString(isolate)));
10961 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12358 CHECK_EQ(42, context->Global()
12359 ->Get(v8_str("saved_result"))
12360 ->Int32Value(context.local())
12361 .FromJust());
10962 } 12362 }
10963 12363
10964 12364
10965 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { 12365 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) {
10966 v8::Isolate* isolate = CcTest::isolate(); 12366 v8::Isolate* isolate = CcTest::isolate();
10967 v8::HandleScope scope(isolate); 12367 v8::HandleScope scope(isolate);
10968 v8::Handle<v8::FunctionTemplate> fun_templ = 12368 v8::Local<v8::FunctionTemplate> fun_templ =
10969 v8::FunctionTemplate::New(isolate); 12369 v8::FunctionTemplate::New(isolate);
10970 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12370 v8::Local<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
10971 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"), 12371 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
10972 v8::Signature::New(isolate, fun_templ)); 12372 v8::Signature::New(isolate, fun_templ));
10973 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12373 v8::Local<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
10974 proto_templ->Set(v8_str("method"), method_templ); 12374 proto_templ->Set(v8_str("method"), method_templ);
10975 fun_templ->SetHiddenPrototype(true); 12375 fun_templ->SetHiddenPrototype(true);
10976 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12376 v8::Local<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
10977 CHECK(!templ.IsEmpty()); 12377 CHECK(!templ.IsEmpty());
10978 LocalContext context; 12378 LocalContext context;
10979 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12379 v8::Local<v8::Function> fun =
12380 fun_templ->GetFunction(context.local()).ToLocalChecked();
10980 GenerateSomeGarbage(); 12381 GenerateSomeGarbage();
10981 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12382 CHECK(context->Global()
12383 ->Set(context.local(), v8_str("o"),
12384 fun->NewInstance(context.local()).ToLocalChecked())
12385 .FromJust());
10982 v8::TryCatch try_catch(isolate); 12386 v8::TryCatch try_catch(isolate);
10983 CompileRun( 12387 CompileRun(
10984 "o.foo = 17;" 12388 "o.foo = 17;"
10985 "var receiver = {};" 12389 "var receiver = {};"
10986 "receiver.__proto__ = o;" 12390 "receiver.__proto__ = o;"
10987 "var result = 0;" 12391 "var result = 0;"
10988 "var saved_result = 0;" 12392 "var saved_result = 0;"
10989 "for (var i = 0; i < 100; i++) {" 12393 "for (var i = 0; i < 100; i++) {"
10990 " result = receiver.method(41);" 12394 " result = receiver.method(41);"
10991 " if (i == 50) {" 12395 " if (i == 50) {"
10992 " saved_result = result;" 12396 " saved_result = result;"
10993 " receiver = Object.create(receiver);" 12397 " receiver = Object.create(receiver);"
10994 " }" 12398 " }"
10995 "}"); 12399 "}");
10996 CHECK(try_catch.HasCaught()); 12400 CHECK(try_catch.HasCaught());
10997 CHECK(v8_str("TypeError: Illegal invocation") 12401 CHECK(v8_str("TypeError: Illegal invocation")
10998 ->Equals(try_catch.Exception()->ToString(isolate))); 12402 ->Equals(try_catch.Exception()->ToString(isolate)));
10999 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12403 CHECK_EQ(42, context->Global()
12404 ->Get(v8_str("saved_result"))
12405 ->Int32Value(context.local())
12406 .FromJust());
11000 } 12407 }
11001 12408
11002 12409
11003 static void ThrowingGetter(Local<String> name, 12410 static void ThrowingGetter(Local<String> name,
11004 const v8::PropertyCallbackInfo<v8::Value>& info) { 12411 const v8::PropertyCallbackInfo<v8::Value>& info) {
11005 ApiTestFuzzer::Fuzz(); 12412 ApiTestFuzzer::Fuzz();
11006 info.GetIsolate()->ThrowException(Handle<Value>()); 12413 info.GetIsolate()->ThrowException(Local<Value>());
11007 info.GetReturnValue().SetUndefined(); 12414 info.GetReturnValue().SetUndefined();
11008 } 12415 }
11009 12416
11010 12417
11011 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 12418 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
11012 LocalContext context; 12419 LocalContext context;
11013 HandleScope scope(context->GetIsolate()); 12420 HandleScope scope(context->GetIsolate());
11014 12421
11015 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 12422 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
11016 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 12423 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
11017 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 12424 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
11018 12425
11019 Local<Object> instance = templ->GetFunction()->NewInstance(); 12426 Local<Object> instance = templ->GetFunction(context.local())
12427 .ToLocalChecked()
12428 ->NewInstance(context.local())
12429 .ToLocalChecked();
11020 12430
11021 Local<Object> another = Object::New(context->GetIsolate()); 12431 Local<Object> another = Object::New(context->GetIsolate());
11022 another->SetPrototype(instance); 12432 another->SetPrototype(instance);
11023 12433
11024 Local<Object> with_js_getter = CompileRun( 12434 Local<Object> with_js_getter = CompileRun(
11025 "o = {};\n" 12435 "o = {};\n"
11026 "o.__defineGetter__('f', function() { throw undefined; });\n" 12436 "o.__defineGetter__('f', function() { throw undefined; });\n"
11027 "o\n").As<Object>(); 12437 "o\n").As<Object>();
11028 CHECK(!with_js_getter.IsEmpty()); 12438 CHECK(!with_js_getter.IsEmpty());
11029 12439
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
11087 CompileRun("throw 'from JS';"); 12497 CompileRun("throw 'from JS';");
11088 CHECK(try_catch.HasCaught()); 12498 CHECK(try_catch.HasCaught());
11089 CHECK(!CcTest::i_isolate()->has_pending_exception()); 12499 CHECK(!CcTest::i_isolate()->has_pending_exception());
11090 CHECK(!CcTest::i_isolate()->has_scheduled_exception()); 12500 CHECK(!CcTest::i_isolate()->has_scheduled_exception());
11091 } 12501 }
11092 12502
11093 12503
11094 static int call_depth; 12504 static int call_depth;
11095 12505
11096 12506
11097 static void WithTryCatch(Handle<Message> message, Handle<Value> data) { 12507 static void WithTryCatch(Local<Message> message, Local<Value> data) {
11098 TryCatch try_catch(CcTest::isolate()); 12508 TryCatch try_catch(CcTest::isolate());
11099 } 12509 }
11100 12510
11101 12511
11102 static void ThrowFromJS(Handle<Message> message, Handle<Value> data) { 12512 static void ThrowFromJS(Local<Message> message, Local<Value> data) {
11103 if (--call_depth) CompileRun("throw 'ThrowInJS';"); 12513 if (--call_depth) CompileRun("throw 'ThrowInJS';");
11104 } 12514 }
11105 12515
11106 12516
11107 static void ThrowViaApi(Handle<Message> message, Handle<Value> data) { 12517 static void ThrowViaApi(Local<Message> message, Local<Value> data) {
11108 if (--call_depth) CcTest::isolate()->ThrowException(v8_str("ThrowViaApi")); 12518 if (--call_depth) CcTest::isolate()->ThrowException(v8_str("ThrowViaApi"));
11109 } 12519 }
11110 12520
11111 12521
11112 static void WebKitLike(Handle<Message> message, Handle<Value> data) { 12522 static void WebKitLike(Local<Message> message, Local<Value> data) {
11113 Handle<String> errorMessageString = message->Get(); 12523 Local<String> errorMessageString = message->Get();
11114 CHECK(!errorMessageString.IsEmpty()); 12524 CHECK(!errorMessageString.IsEmpty());
11115 message->GetStackTrace(); 12525 message->GetStackTrace();
11116 message->GetScriptOrigin().ResourceName(); 12526 message->GetScriptOrigin().ResourceName();
11117 } 12527 }
11118 12528
11119 12529
11120 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { 12530 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
11121 LocalContext context; 12531 LocalContext context;
11122 v8::Isolate* isolate = context->GetIsolate(); 12532 v8::Isolate* isolate = context->GetIsolate();
11123 HandleScope scope(isolate); 12533 HandleScope scope(isolate);
11124 12534
11125 Local<Function> func = 12535 Local<Function> func =
11126 FunctionTemplate::New(isolate, 12536 FunctionTemplate::New(isolate, ThrowingCallbackWithTryCatch)
11127 ThrowingCallbackWithTryCatch)->GetFunction(); 12537 ->GetFunction(context.local())
11128 context->Global()->Set(v8_str("func"), func); 12538 .ToLocalChecked();
12539 CHECK(
12540 context->Global()->Set(context.local(), v8_str("func"), func).FromJust());
11129 12541
11130 MessageCallback callbacks[] = 12542 MessageCallback callbacks[] =
11131 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; 12543 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
11132 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { 12544 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
11133 MessageCallback callback = callbacks[i]; 12545 MessageCallback callback = callbacks[i];
11134 if (callback != NULL) { 12546 if (callback != NULL) {
11135 V8::AddMessageListener(callback); 12547 V8::AddMessageListener(callback);
11136 } 12548 }
11137 // Some small number to control number of times message handler should 12549 // Some small number to control number of times message handler should
11138 // throw an exception. 12550 // throw an exception.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
11182 // instances. 12594 // instances.
11183 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); 12595 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter);
11184 // Add 'g' twice. The 'g' added last should get called for instances. 12596 // Add 'g' twice. The 'g' added last should get called for instances.
11185 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); 12597 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter);
11186 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); 12598 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter);
11187 12599
11188 // Add 'h' as an accessor to the proto template with ReadOnly attributes 12600 // Add 'h' as an accessor to the proto template with ReadOnly attributes
11189 // so 'h' can be shadowed on the instance object. 12601 // so 'h' can be shadowed on the instance object.
11190 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate(); 12602 Local<ObjectTemplate> child_proto_templ = child_templ->PrototypeTemplate();
11191 child_proto_templ->SetAccessor(v8_str("h"), ParentGetter, 0, 12603 child_proto_templ->SetAccessor(v8_str("h"), ParentGetter, 0,
11192 v8::Handle<Value>(), v8::DEFAULT, v8::ReadOnly); 12604 v8::Local<Value>(), v8::DEFAULT, v8::ReadOnly);
11193 12605
11194 // Add 'i' as an accessor to the instance template with ReadOnly attributes 12606 // 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 12607 // but the attribute does not have effect because it is duplicated with
11196 // NULL setter. 12608 // NULL setter.
11197 child_instance_templ->SetAccessor(v8_str("i"), ChildGetter, 0, 12609 child_instance_templ->SetAccessor(v8_str("i"), ChildGetter, 0,
11198 v8::Handle<Value>(), v8::DEFAULT, v8::ReadOnly); 12610 v8::Local<Value>(), v8::DEFAULT,
11199 12611 v8::ReadOnly);
11200 12612
11201 12613
11202 // Instantiate the child template. 12614 // Instantiate the child template.
11203 Local<v8::Object> instance = child_templ->GetFunction()->NewInstance(); 12615 Local<v8::Object> instance = child_templ->GetFunction(context.local())
12616 .ToLocalChecked()
12617 ->NewInstance(context.local())
12618 .ToLocalChecked();
11204 12619
11205 // Check that the child function overrides the parent one. 12620 // Check that the child function overrides the parent one.
11206 context->Global()->Set(v8_str("o"), instance); 12621 CHECK(context->Global()
12622 ->Set(context.local(), v8_str("o"), instance)
12623 .FromJust());
11207 Local<Value> value = v8_compile("o.f")->Run(); 12624 Local<Value> value = v8_compile("o.f")->Run();
11208 // Check that the 'g' that was added last is hit. 12625 // Check that the 'g' that was added last is hit.
11209 CHECK_EQ(42, value->Int32Value()); 12626 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
11210 value = v8_compile("o.g")->Run(); 12627 value = v8_compile("o.g")->Run();
11211 CHECK_EQ(42, value->Int32Value()); 12628 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
11212 12629
11213 // Check that 'h' cannot be shadowed. 12630 // Check that 'h' cannot be shadowed.
11214 value = v8_compile("o.h = 3; o.h")->Run(); 12631 value = v8_compile("o.h = 3; o.h")->Run();
11215 CHECK_EQ(1, value->Int32Value()); 12632 CHECK_EQ(1, value->Int32Value(context.local()).FromJust());
11216 12633
11217 // Check that 'i' cannot be shadowed or changed. 12634 // Check that 'i' cannot be shadowed or changed.
11218 value = v8_compile("o.i = 3; o.i")->Run(); 12635 value = v8_compile("o.i = 3; o.i")->Run();
11219 CHECK_EQ(42, value->Int32Value()); 12636 CHECK_EQ(42, value->Int32Value(context.local()).FromJust());
11220 } 12637 }
11221 12638
11222 12639
11223 static void IsConstructHandler( 12640 static void IsConstructHandler(
11224 const v8::FunctionCallbackInfo<v8::Value>& args) { 12641 const v8::FunctionCallbackInfo<v8::Value>& args) {
11225 ApiTestFuzzer::Fuzz(); 12642 ApiTestFuzzer::Fuzz();
11226 args.GetReturnValue().Set(args.IsConstructCall()); 12643 args.GetReturnValue().Set(args.IsConstructCall());
11227 } 12644 }
11228 12645
11229 12646
11230 THREADED_TEST(IsConstructCall) { 12647 THREADED_TEST(IsConstructCall) {
11231 v8::Isolate* isolate = CcTest::isolate(); 12648 v8::Isolate* isolate = CcTest::isolate();
11232 v8::HandleScope scope(isolate); 12649 v8::HandleScope scope(isolate);
11233 12650
11234 // Function template with call handler. 12651 // Function template with call handler.
11235 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 12652 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
11236 templ->SetCallHandler(IsConstructHandler); 12653 templ->SetCallHandler(IsConstructHandler);
11237 12654
11238 LocalContext context; 12655 LocalContext context;
11239 12656
11240 context->Global()->Set(v8_str("f"), templ->GetFunction()); 12657 CHECK(context->Global()
12658 ->Set(context.local(), v8_str("f"),
12659 templ->GetFunction(context.local()).ToLocalChecked())
12660 .FromJust());
11241 Local<Value> value = v8_compile("f()")->Run(); 12661 Local<Value> value = v8_compile("f()")->Run();
11242 CHECK(!value->BooleanValue()); 12662 CHECK(!value->BooleanValue());
11243 value = v8_compile("new f()")->Run(); 12663 value = v8_compile("new f()")->Run();
11244 CHECK(value->BooleanValue()); 12664 CHECK(value->BooleanValue());
11245 } 12665 }
11246 12666
11247 12667
11248 THREADED_TEST(ObjectProtoToString) { 12668 THREADED_TEST(ObjectProtoToString) {
11249 v8::Isolate* isolate = CcTest::isolate(); 12669 v8::Isolate* isolate = CcTest::isolate();
11250 v8::HandleScope scope(isolate); 12670 v8::HandleScope scope(isolate);
11251 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate); 12671 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
11252 templ->SetClassName(v8_str("MyClass")); 12672 templ->SetClassName(v8_str("MyClass"));
11253 12673
11254 LocalContext context; 12674 LocalContext context;
11255 12675
11256 Local<String> customized_tostring = v8_str("customized toString"); 12676 Local<String> customized_tostring = v8_str("customized toString");
11257 12677
11258 // Replace Object.prototype.toString 12678 // Replace Object.prototype.toString
11259 v8_compile("Object.prototype.toString = function() {" 12679 v8_compile("Object.prototype.toString = function() {"
11260 " return 'customized toString';" 12680 " return 'customized toString';"
11261 "}")->Run(); 12681 "}")->Run();
11262 12682
11263 // Normal ToString call should call replaced Object.prototype.toString 12683 // Normal ToString call should call replaced Object.prototype.toString
11264 Local<v8::Object> instance = templ->GetFunction()->NewInstance(); 12684 Local<v8::Object> instance = templ->GetFunction(context.local())
12685 .ToLocalChecked()
12686 ->NewInstance(context.local())
12687 .ToLocalChecked();
11265 Local<String> value = instance->ToString(isolate); 12688 Local<String> value = instance->ToString(isolate);
11266 CHECK(value->IsString() && value->Equals(customized_tostring)); 12689 CHECK(value->IsString() && value->Equals(customized_tostring));
11267 12690
11268 // ObjectProtoToString should not call replace toString function. 12691 // ObjectProtoToString should not call replace toString function.
11269 value = instance->ObjectProtoToString(); 12692 value = instance->ObjectProtoToString();
11270 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); 12693 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]")));
11271 12694
11272 // Check global 12695 // Check global
11273 value = context->Global()->ObjectProtoToString(); 12696 value = context->Global()->ObjectProtoToString();
11274 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); 12697 CHECK(value->IsString() && value->Equals(v8_str("[object global]")));
(...skipping 16 matching lines...) Expand all
11291 12714
11292 Local<String> customized_tostring = v8_str("customized toString"); 12715 Local<String> customized_tostring = v8_str("customized toString");
11293 12716
11294 // Replace Object.prototype.toString 12717 // Replace Object.prototype.toString
11295 CompileRun( 12718 CompileRun(
11296 "Object.prototype.toString = function() {" 12719 "Object.prototype.toString = function() {"
11297 " return 'customized toString';" 12720 " return 'customized toString';"
11298 "}"); 12721 "}");
11299 12722
11300 // Normal ToString call should call replaced Object.prototype.toString 12723 // Normal ToString call should call replaced Object.prototype.toString
11301 Local<v8::Object> instance = templ->GetFunction()->NewInstance(); 12724 Local<v8::Object> instance = templ->GetFunction(context.local())
12725 .ToLocalChecked()
12726 ->NewInstance(context.local())
12727 .ToLocalChecked();
11302 Local<String> value = instance->ToString(isolate); 12728 Local<String> value = instance->ToString(isolate);
11303 CHECK(value->IsString() && value->Equals(customized_tostring)); 12729 CHECK(value->IsString() && value->Equals(customized_tostring));
11304 12730
11305 // ObjectProtoToString should not call replace toString function. 12731 // ObjectProtoToString should not call replace toString function.
11306 value = instance->ObjectProtoToString(); 12732 value = instance->ObjectProtoToString();
11307 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]"))); 12733 CHECK(value->IsString() && value->Equals(v8_str("[object MyClass]")));
11308 12734
11309 // Check global 12735 // Check global
11310 value = context->Global()->ObjectProtoToString(); 12736 value = context->Global()->ObjectProtoToString();
11311 CHECK(value->IsString() && value->Equals(v8_str("[object global]"))); 12737 CHECK(value->IsString() && value->Equals(v8_str("[object global]")));
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
11634 13060
11635 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) { 13061 static void ThrowInJS(const v8::FunctionCallbackInfo<v8::Value>& args) {
11636 v8::Isolate* isolate = args.GetIsolate(); 13062 v8::Isolate* isolate = args.GetIsolate();
11637 CHECK(v8::Locker::IsLocked(isolate)); 13063 CHECK(v8::Locker::IsLocked(isolate));
11638 ApiTestFuzzer::Fuzz(); 13064 ApiTestFuzzer::Fuzz();
11639 v8::Unlocker unlocker(isolate); 13065 v8::Unlocker unlocker(isolate);
11640 const char* code = "throw 7;"; 13066 const char* code = "throw 7;";
11641 { 13067 {
11642 v8::Locker nested_locker(isolate); 13068 v8::Locker nested_locker(isolate);
11643 v8::HandleScope scope(isolate); 13069 v8::HandleScope scope(isolate);
11644 v8::Handle<Value> exception; 13070 v8::Local<Value> exception;
11645 { 13071 {
11646 v8::TryCatch try_catch(isolate); 13072 v8::TryCatch try_catch(isolate);
11647 v8::Handle<Value> value = CompileRun(code); 13073 v8::Local<Value> value = CompileRun(code);
11648 CHECK(value.IsEmpty()); 13074 CHECK(value.IsEmpty());
11649 CHECK(try_catch.HasCaught()); 13075 CHECK(try_catch.HasCaught());
11650 // Make sure to wrap the exception in a new handle because 13076 // Make sure to wrap the exception in a new handle because
11651 // the handle returned from the TryCatch is destroyed 13077 // the handle returned from the TryCatch is destroyed
11652 // when the TryCatch is destroyed. 13078 // when the TryCatch is destroyed.
11653 exception = Local<Value>::New(isolate, try_catch.Exception()); 13079 exception = Local<Value>::New(isolate, try_catch.Exception());
11654 } 13080 }
11655 args.GetIsolate()->ThrowException(exception); 13081 args.GetIsolate()->ThrowException(exception);
11656 } 13082 }
11657 } 13083 }
11658 13084
11659 13085
11660 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { 13086 static void ThrowInJSNoCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
11661 CHECK(v8::Locker::IsLocked(CcTest::isolate())); 13087 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
11662 ApiTestFuzzer::Fuzz(); 13088 ApiTestFuzzer::Fuzz();
11663 v8::Unlocker unlocker(CcTest::isolate()); 13089 v8::Unlocker unlocker(CcTest::isolate());
11664 const char* code = "throw 7;"; 13090 const char* code = "throw 7;";
11665 { 13091 {
11666 v8::Locker nested_locker(CcTest::isolate()); 13092 v8::Locker nested_locker(CcTest::isolate());
11667 v8::HandleScope scope(args.GetIsolate()); 13093 v8::HandleScope scope(args.GetIsolate());
11668 v8::Handle<Value> value = CompileRun(code); 13094 v8::Local<Value> value = CompileRun(code);
11669 CHECK(value.IsEmpty()); 13095 CHECK(value.IsEmpty());
11670 args.GetReturnValue().Set(v8_str("foo")); 13096 args.GetReturnValue().Set(v8_str("foo"));
11671 } 13097 }
11672 } 13098 }
11673 13099
11674 13100
11675 // These are locking tests that don't need to be run again 13101 // These are locking tests that don't need to be run again
11676 // as part of the locking aggregation tests. 13102 // as part of the locking aggregation tests.
11677 TEST(NestedLockers) { 13103 TEST(NestedLockers) {
11678 v8::Isolate* isolate = CcTest::isolate(); 13104 v8::Isolate* isolate = CcTest::isolate();
11679 v8::Locker locker(isolate); 13105 v8::Locker locker(isolate);
11680 CHECK(v8::Locker::IsLocked(isolate)); 13106 CHECK(v8::Locker::IsLocked(isolate));
11681 LocalContext env; 13107 LocalContext env;
11682 v8::HandleScope scope(env->GetIsolate()); 13108 v8::HandleScope scope(env->GetIsolate());
11683 Local<v8::FunctionTemplate> fun_templ = 13109 Local<v8::FunctionTemplate> fun_templ =
11684 v8::FunctionTemplate::New(isolate, ThrowInJS); 13110 v8::FunctionTemplate::New(isolate, ThrowInJS);
11685 Local<Function> fun = fun_templ->GetFunction(); 13111 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
11686 env->Global()->Set(v8_str("throw_in_js"), fun); 13112 CHECK(env->Global()->Set(env.local(), v8_str("throw_in_js"), fun).FromJust());
11687 Local<Script> script = v8_compile("(function () {" 13113 Local<Script> script = v8_compile("(function () {"
11688 " try {" 13114 " try {"
11689 " throw_in_js();" 13115 " throw_in_js();"
11690 " return 42;" 13116 " return 42;"
11691 " } catch (e) {" 13117 " } catch (e) {"
11692 " return e * 13;" 13118 " return e * 13;"
11693 " }" 13119 " }"
11694 "})();"); 13120 "})();");
11695 CHECK_EQ(91, script->Run()->Int32Value()); 13121 CHECK_EQ(91, script->Run()->Int32Value(env.local()).FromJust());
11696 } 13122 }
11697 13123
11698 13124
11699 // These are locking tests that don't need to be run again 13125 // These are locking tests that don't need to be run again
11700 // as part of the locking aggregation tests. 13126 // as part of the locking aggregation tests.
11701 TEST(NestedLockersNoTryCatch) { 13127 TEST(NestedLockersNoTryCatch) {
11702 v8::Locker locker(CcTest::isolate()); 13128 v8::Locker locker(CcTest::isolate());
11703 LocalContext env; 13129 LocalContext env;
11704 v8::HandleScope scope(env->GetIsolate()); 13130 v8::HandleScope scope(env->GetIsolate());
11705 Local<v8::FunctionTemplate> fun_templ = 13131 Local<v8::FunctionTemplate> fun_templ =
11706 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch); 13132 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch);
11707 Local<Function> fun = fun_templ->GetFunction(); 13133 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
11708 env->Global()->Set(v8_str("throw_in_js"), fun); 13134 CHECK(env->Global()->Set(env.local(), v8_str("throw_in_js"), fun).FromJust());
11709 Local<Script> script = v8_compile("(function () {" 13135 Local<Script> script = v8_compile("(function () {"
11710 " try {" 13136 " try {"
11711 " throw_in_js();" 13137 " throw_in_js();"
11712 " return 42;" 13138 " return 42;"
11713 " } catch (e) {" 13139 " } catch (e) {"
11714 " return e * 13;" 13140 " return e * 13;"
11715 " }" 13141 " }"
11716 "})();"); 13142 "})();");
11717 CHECK_EQ(91, script->Run()->Int32Value()); 13143 CHECK_EQ(91, script->Run()->Int32Value(env.local()).FromJust());
11718 } 13144 }
11719 13145
11720 13146
11721 THREADED_TEST(RecursiveLocking) { 13147 THREADED_TEST(RecursiveLocking) {
11722 v8::Locker locker(CcTest::isolate()); 13148 v8::Locker locker(CcTest::isolate());
11723 { 13149 {
11724 v8::Locker locker2(CcTest::isolate()); 13150 v8::Locker locker2(CcTest::isolate());
11725 CHECK(v8::Locker::IsLocked(CcTest::isolate())); 13151 CHECK(v8::Locker::IsLocked(CcTest::isolate()));
11726 } 13152 }
11727 } 13153 }
11728 13154
11729 13155
11730 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) { 13156 static void UnlockForAMoment(const v8::FunctionCallbackInfo<v8::Value>& args) {
11731 ApiTestFuzzer::Fuzz(); 13157 ApiTestFuzzer::Fuzz();
11732 v8::Unlocker unlocker(CcTest::isolate()); 13158 v8::Unlocker unlocker(CcTest::isolate());
11733 } 13159 }
11734 13160
11735 13161
11736 THREADED_TEST(LockUnlockLock) { 13162 THREADED_TEST(LockUnlockLock) {
11737 { 13163 {
11738 v8::Locker locker(CcTest::isolate()); 13164 v8::Locker locker(CcTest::isolate());
11739 v8::HandleScope scope(CcTest::isolate()); 13165 v8::HandleScope scope(CcTest::isolate());
11740 LocalContext env; 13166 LocalContext env;
11741 Local<v8::FunctionTemplate> fun_templ = 13167 Local<v8::FunctionTemplate> fun_templ =
11742 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); 13168 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment);
11743 Local<Function> fun = fun_templ->GetFunction(); 13169 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
11744 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 13170 CHECK(env->Global()
13171 ->Set(env.local(), v8_str("unlock_for_a_moment"), fun)
13172 .FromJust());
11745 Local<Script> script = v8_compile("(function () {" 13173 Local<Script> script = v8_compile("(function () {"
11746 " unlock_for_a_moment();" 13174 " unlock_for_a_moment();"
11747 " return 42;" 13175 " return 42;"
11748 "})();"); 13176 "})();");
11749 CHECK_EQ(42, script->Run()->Int32Value()); 13177 CHECK_EQ(42, script->Run()->Int32Value(env.local()).FromJust());
11750 } 13178 }
11751 { 13179 {
11752 v8::Locker locker(CcTest::isolate()); 13180 v8::Locker locker(CcTest::isolate());
11753 v8::HandleScope scope(CcTest::isolate()); 13181 v8::HandleScope scope(CcTest::isolate());
11754 LocalContext env; 13182 LocalContext env;
11755 Local<v8::FunctionTemplate> fun_templ = 13183 Local<v8::FunctionTemplate> fun_templ =
11756 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment); 13184 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment);
11757 Local<Function> fun = fun_templ->GetFunction(); 13185 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
11758 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 13186 CHECK(env->Global()
13187 ->Set(env.local(), v8_str("unlock_for_a_moment"), fun)
13188 .FromJust());
11759 Local<Script> script = v8_compile("(function () {" 13189 Local<Script> script = v8_compile("(function () {"
11760 " unlock_for_a_moment();" 13190 " unlock_for_a_moment();"
11761 " return 42;" 13191 " return 42;"
11762 "})();"); 13192 "})();");
11763 CHECK_EQ(42, script->Run()->Int32Value()); 13193 CHECK_EQ(42, script->Run()->Int32Value(env.local()).FromJust());
11764 } 13194 }
11765 } 13195 }
11766 13196
11767 13197
11768 static int GetGlobalObjectsCount() { 13198 static int GetGlobalObjectsCount() {
11769 int count = 0; 13199 int count = 0;
11770 i::HeapIterator it(CcTest::heap()); 13200 i::HeapIterator it(CcTest::heap());
11771 for (i::HeapObject* object = it.next(); object != NULL; object = it.next()) 13201 for (i::HeapObject* object = it.next(); object != NULL; object = it.next())
11772 if (object->IsJSGlobalObject()) { 13202 if (object->IsJSGlobalObject()) {
11773 i::JSGlobalObject* g = i::JSGlobalObject::cast(object); 13203 i::JSGlobalObject* g = i::JSGlobalObject::cast(object);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
12022 CompileRun(source); 13452 CompileRun(source);
12023 } 13453 }
12024 { v8::HandleScope scope(CcTest::isolate()); 13454 { v8::HandleScope scope(CcTest::isolate());
12025 LocalContext context; 13455 LocalContext context;
12026 CompileRun(source); 13456 CompileRun(source);
12027 } 13457 }
12028 } 13458 }
12029 } 13459 }
12030 13460
12031 13461
12032 static v8::Handle<Value> NestedScope(v8::Local<Context> env) { 13462 static v8::Local<Value> NestedScope(v8::Local<Context> env) {
12033 v8::EscapableHandleScope inner(env->GetIsolate()); 13463 v8::EscapableHandleScope inner(env->GetIsolate());
12034 env->Enter(); 13464 env->Enter();
12035 v8::Local<Value> three = v8_num(3); 13465 v8::Local<Value> three = v8_num(3);
12036 v8::Local<Value> value = inner.Escape(three); 13466 v8::Local<Value> value = inner.Escape(three);
12037 env->Exit(); 13467 env->Exit();
12038 return value; 13468 return value;
12039 } 13469 }
12040 13470
12041 13471
12042 THREADED_TEST(NestedHandleScopeAndContexts) { 13472 THREADED_TEST(NestedHandleScopeAndContexts) {
12043 v8::Isolate* isolate = CcTest::isolate(); 13473 v8::Isolate* isolate = CcTest::isolate();
12044 v8::HandleScope outer(isolate); 13474 v8::HandleScope outer(isolate);
12045 v8::Local<Context> env = Context::New(isolate); 13475 v8::Local<Context> env = Context::New(isolate);
12046 env->Enter(); 13476 env->Enter();
12047 v8::Handle<Value> value = NestedScope(env); 13477 v8::Local<Value> value = NestedScope(env);
12048 v8::Handle<String> str(value->ToString(isolate)); 13478 v8::Local<String> str(value->ToString(isolate));
12049 CHECK(!str.IsEmpty()); 13479 CHECK(!str.IsEmpty());
12050 env->Exit(); 13480 env->Exit();
12051 } 13481 }
12052 13482
12053 13483
12054 static bool MatchPointers(void* key1, void* key2) { 13484 static bool MatchPointers(void* key1, void* key2) {
12055 return key1 == key2; 13485 return key1 == key2;
12056 } 13486 }
12057 13487
12058 13488
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
12285 } 13715 }
12286 13716
12287 13717
12288 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { 13718 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) {
12289 v8::HandleScope outer(isolate); 13719 v8::HandleScope outer(isolate);
12290 v8::Local<Context> env = Context::New(isolate); 13720 v8::Local<Context> env = Context::New(isolate);
12291 env->Enter(); 13721 env->Enter();
12292 13722
12293 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); 13723 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
12294 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback)); 13724 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback));
12295 env->Global()->Set(v8_str("obj"), t->NewInstance()); 13725 CHECK(env->Global()
13726 ->Set(env, v8_str("obj"), t->NewInstance(env).ToLocalChecked())
13727 .FromJust());
12296 13728
12297 const char* script = 13729 const char* script =
12298 "function bar() {\n" 13730 "function bar() {\n"
12299 " var sum = 0;\n" 13731 " var sum = 0;\n"
12300 " for (i = 0; i < 100; ++i)\n" 13732 " for (i = 0; i < 100; ++i)\n"
12301 " sum = foo(i);\n" 13733 " sum = foo(i);\n"
12302 " return sum;\n" 13734 " return sum;\n"
12303 "}\n" 13735 "}\n"
12304 "function foo(i) { return i * i; }\n" 13736 "function foo(i) { return i * i; }\n"
12305 "// Invoke on the runtime function.\n" 13737 "// Invoke on the runtime function.\n"
12306 "obj.asdf()"; 13738 "obj.asdf()";
12307 CompileRun(script); 13739 CompileRun(script);
12308 bar_func_ = i::Handle<i::JSFunction>::cast( 13740 bar_func_ = i::Handle<i::JSFunction>::cast(
12309 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar")))); 13741 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("bar"))));
12310 DCHECK(!bar_func_.is_null()); 13742 DCHECK(!bar_func_.is_null());
12311 13743
12312 foo_func_ = 13744 foo_func_ =
12313 i::Handle<i::JSFunction>::cast( 13745 i::Handle<i::JSFunction>::cast(
12314 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo")))); 13746 v8::Utils::OpenHandle(*env->Global()->Get(v8_str("foo"))));
12315 DCHECK(!foo_func_.is_null()); 13747 DCHECK(!foo_func_.is_null());
12316 13748
12317 v8::Handle<v8::Value> value = CompileRun("bar();"); 13749 v8::Local<v8::Value> value = CompileRun("bar();");
12318 CHECK(value->IsNumber()); 13750 CHECK(value->IsNumber());
12319 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); 13751 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value());
12320 13752
12321 // Test the optimized codegen path. 13753 // Test the optimized codegen path.
12322 value = CompileRun("%OptimizeFunctionOnNextCall(foo);" 13754 value = CompileRun("%OptimizeFunctionOnNextCall(foo);"
12323 "bar();"); 13755 "bar();");
12324 CHECK(value->IsNumber()); 13756 CHECK(value->IsNumber());
12325 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value()); 13757 CHECK_EQ(9801.0, v8::Number::Cast(*value)->Value());
12326 13758
12327 env->Exit(); 13759 env->Exit();
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
12672 LocalContext context; 14104 LocalContext context;
12673 v8::Isolate* isolate = context->GetIsolate(); 14105 v8::Isolate* isolate = context->GetIsolate();
12674 v8::HandleScope outer(isolate); 14106 v8::HandleScope outer(isolate);
12675 static v8::Persistent<v8::ObjectTemplate> templ; 14107 static v8::Persistent<v8::ObjectTemplate> templ;
12676 if (templ.IsEmpty()) { 14108 if (templ.IsEmpty()) {
12677 v8::EscapableHandleScope inner(isolate); 14109 v8::EscapableHandleScope inner(isolate);
12678 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate); 14110 v8::Local<v8::ObjectTemplate> local = v8::ObjectTemplate::New(isolate);
12679 local->SetInternalFieldCount(1); 14111 local->SetInternalFieldCount(1);
12680 templ.Reset(isolate, inner.Escape(local)); 14112 templ.Reset(isolate, inner.Escape(local));
12681 } 14113 }
12682 v8::Handle<v8::Object> result = 14114 v8::Local<v8::Object> result =
12683 v8::Local<v8::ObjectTemplate>::New(isolate, templ)->NewInstance(); 14115 v8::Local<v8::ObjectTemplate>::New(isolate, templ)
14116 ->NewInstance(context.local())
14117 .ToLocalChecked();
12684 CHECK_EQ(1, result->InternalFieldCount()); 14118 CHECK_EQ(1, result->InternalFieldCount());
12685 } 14119 }
12686 14120
12687 14121
12688 // If part of the threaded tests, this test makes ThreadingTest fail 14122 // If part of the threaded tests, this test makes ThreadingTest fail
12689 // on mac. 14123 // on mac.
12690 TEST(CatchStackOverflow) { 14124 TEST(CatchStackOverflow) {
12691 LocalContext context; 14125 LocalContext context;
12692 v8::HandleScope scope(context->GetIsolate()); 14126 v8::HandleScope scope(context->GetIsolate());
12693 v8::TryCatch try_catch(context->GetIsolate()); 14127 v8::TryCatch try_catch(context->GetIsolate());
12694 v8::Handle<v8::Value> result = CompileRun( 14128 v8::Local<v8::Value> result = CompileRun(
12695 "function f() {" 14129 "function f() {"
12696 " return f();" 14130 " return f();"
12697 "}" 14131 "}"
12698 "" 14132 ""
12699 "f();"); 14133 "f();");
12700 CHECK(result.IsEmpty()); 14134 CHECK(result.IsEmpty());
12701 } 14135 }
12702 14136
12703 14137
12704 static void CheckTryCatchSourceInfo(v8::Handle<v8::Script> script, 14138 static void CheckTryCatchSourceInfo(v8::Local<v8::Script> script,
12705 const char* resource_name, 14139 const char* resource_name,
12706 int line_offset) { 14140 int line_offset) {
12707 v8::HandleScope scope(CcTest::isolate()); 14141 v8::HandleScope scope(CcTest::isolate());
12708 v8::TryCatch try_catch(CcTest::isolate()); 14142 v8::TryCatch try_catch(CcTest::isolate());
12709 v8::Handle<v8::Value> result = script->Run(); 14143 v8::Local<v8::Value> result = script->Run();
12710 CHECK(result.IsEmpty()); 14144 CHECK(result.IsEmpty());
12711 CHECK(try_catch.HasCaught()); 14145 CHECK(try_catch.HasCaught());
12712 v8::Handle<v8::Message> message = try_catch.Message(); 14146 v8::Local<v8::Message> message = try_catch.Message();
12713 CHECK(!message.IsEmpty()); 14147 CHECK(!message.IsEmpty());
12714 CHECK_EQ(10 + line_offset, message->GetLineNumber()); 14148 CHECK_EQ(10 + line_offset, message->GetLineNumber());
12715 CHECK_EQ(91, message->GetStartPosition()); 14149 CHECK_EQ(91, message->GetStartPosition());
12716 CHECK_EQ(92, message->GetEndPosition()); 14150 CHECK_EQ(92, message->GetEndPosition());
12717 CHECK_EQ(2, message->GetStartColumn()); 14151 CHECK_EQ(2, message->GetStartColumn());
12718 CHECK_EQ(3, message->GetEndColumn()); 14152 CHECK_EQ(3, message->GetEndColumn());
12719 v8::String::Utf8Value line(message->GetSourceLine()); 14153 v8::String::Utf8Value line(message->GetSourceLine());
12720 CHECK_EQ(0, strcmp(" throw 'nirk';", *line)); 14154 CHECK_EQ(0, strcmp(" throw 'nirk';", *line));
12721 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName()); 14155 v8::String::Utf8Value name(message->GetScriptOrigin().ResourceName());
12722 CHECK_EQ(0, strcmp(resource_name, *name)); 14156 CHECK_EQ(0, strcmp(resource_name, *name));
(...skipping 12 matching lines...) Expand all
12735 " return Baz();\n" 14169 " return Baz();\n"
12736 "}\n" 14170 "}\n"
12737 "\n" 14171 "\n"
12738 "function Baz() {\n" 14172 "function Baz() {\n"
12739 " throw 'nirk';\n" 14173 " throw 'nirk';\n"
12740 "}\n" 14174 "}\n"
12741 "\n" 14175 "\n"
12742 "Foo();\n"); 14176 "Foo();\n");
12743 14177
12744 const char* resource_name; 14178 const char* resource_name;
12745 v8::Handle<v8::Script> script; 14179 v8::Local<v8::Script> script;
12746 resource_name = "test.js"; 14180 resource_name = "test.js";
12747 script = CompileWithOrigin(source, resource_name); 14181 script = CompileWithOrigin(source, resource_name);
12748 CheckTryCatchSourceInfo(script, resource_name, 0); 14182 CheckTryCatchSourceInfo(script, resource_name, 0);
12749 14183
12750 resource_name = "test1.js"; 14184 resource_name = "test1.js";
12751 v8::ScriptOrigin origin1( 14185 v8::ScriptOrigin origin1(v8_str(resource_name));
12752 v8::String::NewFromUtf8(context->GetIsolate(), resource_name));
12753 script = v8::Script::Compile(source, &origin1); 14186 script = v8::Script::Compile(source, &origin1);
12754 CheckTryCatchSourceInfo(script, resource_name, 0); 14187 CheckTryCatchSourceInfo(script, resource_name, 0);
12755 14188
12756 resource_name = "test2.js"; 14189 resource_name = "test2.js";
12757 v8::ScriptOrigin origin2( 14190 v8::ScriptOrigin origin2(v8_str(resource_name),
12758 v8::String::NewFromUtf8(context->GetIsolate(), resource_name), 14191 v8::Integer::New(context->GetIsolate(), 7));
12759 v8::Integer::New(context->GetIsolate(), 7));
12760 script = v8::Script::Compile(source, &origin2); 14192 script = v8::Script::Compile(source, &origin2);
12761 CheckTryCatchSourceInfo(script, resource_name, 7); 14193 CheckTryCatchSourceInfo(script, resource_name, 7);
12762 } 14194 }
12763 14195
12764 14196
12765 THREADED_TEST(TryCatchSourceInfoForEOSError) { 14197 THREADED_TEST(TryCatchSourceInfoForEOSError) {
12766 LocalContext context; 14198 LocalContext context;
12767 v8::HandleScope scope(context->GetIsolate()); 14199 v8::HandleScope scope(context->GetIsolate());
12768 v8::TryCatch try_catch(context->GetIsolate()); 14200 v8::TryCatch try_catch(context->GetIsolate());
12769 v8::Script::Compile(v8_str("!\n")); 14201 v8::Script::Compile(v8_str("!\n"));
12770 CHECK(try_catch.HasCaught()); 14202 CHECK(try_catch.HasCaught());
12771 v8::Handle<v8::Message> message = try_catch.Message(); 14203 v8::Local<v8::Message> message = try_catch.Message();
12772 CHECK_EQ(1, message->GetLineNumber()); 14204 CHECK_EQ(1, message->GetLineNumber());
12773 CHECK_EQ(0, message->GetStartColumn()); 14205 CHECK_EQ(0, message->GetStartColumn());
12774 } 14206 }
12775 14207
12776 14208
12777 THREADED_TEST(CompilationCache) { 14209 THREADED_TEST(CompilationCache) {
12778 LocalContext context; 14210 LocalContext context;
12779 v8::HandleScope scope(context->GetIsolate()); 14211 v8::HandleScope scope(context->GetIsolate());
12780 v8::Handle<v8::String> source0 = 14212 v8::Local<v8::String> source0 = v8_str("1234");
12781 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14213 v8::Local<v8::String> source1 = v8_str("1234");
12782 v8::Handle<v8::String> source1 = 14214 v8::Local<v8::Script> script0 = CompileWithOrigin(source0, "test.js");
12783 v8::String::NewFromUtf8(context->GetIsolate(), "1234"); 14215 v8::Local<v8::Script> script1 = CompileWithOrigin(source1, "test.js");
12784 v8::Handle<v8::Script> script0 = CompileWithOrigin(source0, "test.js"); 14216 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 14217 v8::Script::Compile(source0); // different origin
12788 CHECK_EQ(1234, script0->Run()->Int32Value()); 14218 CHECK_EQ(1234, script0->Run()->Int32Value(context.local()).FromJust());
12789 CHECK_EQ(1234, script1->Run()->Int32Value()); 14219 CHECK_EQ(1234, script1->Run()->Int32Value(context.local()).FromJust());
12790 CHECK_EQ(1234, script2->Run()->Int32Value()); 14220 CHECK_EQ(1234, script2->Run()->Int32Value(context.local()).FromJust());
12791 } 14221 }
12792 14222
12793 14223
12794 static void FunctionNameCallback( 14224 static void FunctionNameCallback(
12795 const v8::FunctionCallbackInfo<v8::Value>& args) { 14225 const v8::FunctionCallbackInfo<v8::Value>& args) {
12796 ApiTestFuzzer::Fuzz(); 14226 ApiTestFuzzer::Fuzz();
12797 args.GetReturnValue().Set(v8_num(42)); 14227 args.GetReturnValue().Set(v8_num(42));
12798 } 14228 }
12799 14229
12800 14230
12801 THREADED_TEST(CallbackFunctionName) { 14231 THREADED_TEST(CallbackFunctionName) {
12802 LocalContext context; 14232 LocalContext context;
12803 v8::Isolate* isolate = context->GetIsolate(); 14233 v8::Isolate* isolate = context->GetIsolate();
12804 v8::HandleScope scope(isolate); 14234 v8::HandleScope scope(isolate);
12805 Local<ObjectTemplate> t = ObjectTemplate::New(isolate); 14235 Local<ObjectTemplate> t = ObjectTemplate::New(isolate);
12806 t->Set(v8_str("asdf"), 14236 t->Set(v8_str("asdf"),
12807 v8::FunctionTemplate::New(isolate, FunctionNameCallback)); 14237 v8::FunctionTemplate::New(isolate, FunctionNameCallback));
12808 context->Global()->Set(v8_str("obj"), t->NewInstance()); 14238 CHECK(context->Global()
12809 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 14239 ->Set(context.local(), v8_str("obj"),
14240 t->NewInstance(context.local()).ToLocalChecked())
14241 .FromJust());
14242 v8::Local<v8::Value> value = CompileRun("obj.asdf.name");
12810 CHECK(value->IsString()); 14243 CHECK(value->IsString());
12811 v8::String::Utf8Value name(value); 14244 v8::String::Utf8Value name(value);
12812 CHECK_EQ(0, strcmp("asdf", *name)); 14245 CHECK_EQ(0, strcmp("asdf", *name));
12813 } 14246 }
12814 14247
12815 14248
12816 THREADED_TEST(DateAccess) { 14249 THREADED_TEST(DateAccess) {
12817 LocalContext context; 14250 LocalContext context;
12818 v8::HandleScope scope(context->GetIsolate()); 14251 v8::HandleScope scope(context->GetIsolate());
12819 v8::Handle<v8::Value> date = 14252 v8::Local<v8::Value> date =
12820 v8::Date::New(context->GetIsolate(), 1224744689038.0); 14253 v8::Date::New(context->GetIsolate(), 1224744689038.0);
12821 CHECK(date->IsDate()); 14254 CHECK(date->IsDate());
12822 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf()); 14255 CHECK_EQ(1224744689038.0, date.As<v8::Date>()->ValueOf());
12823 } 14256 }
12824 14257
12825 14258
12826 void CheckProperties(v8::Isolate* isolate, v8::Handle<v8::Value> val, 14259 void CheckProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
12827 unsigned elmc, const char* elmv[]) { 14260 unsigned elmc, const char* elmv[]) {
12828 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14261 v8::Local<v8::Object> obj = val.As<v8::Object>();
12829 v8::Handle<v8::Array> props = obj->GetPropertyNames(); 14262 v8::Local<v8::Array> props = obj->GetPropertyNames();
12830 CHECK_EQ(elmc, props->Length()); 14263 CHECK_EQ(elmc, props->Length());
12831 for (unsigned i = 0; i < elmc; i++) { 14264 for (unsigned i = 0; i < elmc; i++) {
12832 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); 14265 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i)));
12833 CHECK_EQ(0, strcmp(elmv[i], *elm)); 14266 CHECK_EQ(0, strcmp(elmv[i], *elm));
12834 } 14267 }
12835 } 14268 }
12836 14269
12837 14270
12838 void CheckOwnProperties(v8::Isolate* isolate, v8::Handle<v8::Value> val, 14271 void CheckOwnProperties(v8::Isolate* isolate, v8::Local<v8::Value> val,
12839 unsigned elmc, const char* elmv[]) { 14272 unsigned elmc, const char* elmv[]) {
12840 v8::Handle<v8::Object> obj = val.As<v8::Object>(); 14273 v8::Local<v8::Object> obj = val.As<v8::Object>();
12841 v8::Handle<v8::Array> props = obj->GetOwnPropertyNames(); 14274 v8::Local<v8::Array> props = obj->GetOwnPropertyNames();
12842 CHECK_EQ(elmc, props->Length()); 14275 CHECK_EQ(elmc, props->Length());
12843 for (unsigned i = 0; i < elmc; i++) { 14276 for (unsigned i = 0; i < elmc; i++) {
12844 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i))); 14277 v8::String::Utf8Value elm(props->Get(v8::Integer::New(isolate, i)));
12845 CHECK_EQ(0, strcmp(elmv[i], *elm)); 14278 CHECK_EQ(0, strcmp(elmv[i], *elm));
12846 } 14279 }
12847 } 14280 }
12848 14281
12849 14282
12850 THREADED_TEST(PropertyEnumeration) { 14283 THREADED_TEST(PropertyEnumeration) {
12851 LocalContext context; 14284 LocalContext context;
12852 v8::Isolate* isolate = context->GetIsolate(); 14285 v8::Isolate* isolate = context->GetIsolate();
12853 v8::HandleScope scope(isolate); 14286 v8::HandleScope scope(isolate);
12854 v8::Handle<v8::Value> obj = CompileRun( 14287 v8::Local<v8::Value> obj = CompileRun(
12855 "var result = [];" 14288 "var result = [];"
12856 "result[0] = {};" 14289 "result[0] = {};"
12857 "result[1] = {a: 1, b: 2};" 14290 "result[1] = {a: 1, b: 2};"
12858 "result[2] = [1, 2, 3];" 14291 "result[2] = [1, 2, 3];"
12859 "var proto = {x: 1, y: 2, z: 3};" 14292 "var proto = {x: 1, y: 2, z: 3};"
12860 "var x = { __proto__: proto, w: 0, z: 1 };" 14293 "var x = { __proto__: proto, w: 0, z: 1 };"
12861 "result[3] = x;" 14294 "result[3] = x;"
12862 "result;"); 14295 "result;");
12863 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14296 v8::Local<v8::Array> elms = obj.As<v8::Array>();
12864 CHECK_EQ(4u, elms->Length()); 14297 CHECK_EQ(4u, elms->Length());
12865 int elmc0 = 0; 14298 int elmc0 = 0;
12866 const char** elmv0 = NULL; 14299 const char** elmv0 = NULL;
12867 CheckProperties( 14300 CheckProperties(
12868 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14301 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
12869 CheckOwnProperties( 14302 CheckOwnProperties(
12870 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14303 isolate, elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
12871 int elmc1 = 2; 14304 int elmc1 = 2;
12872 const char* elmv1[] = {"a", "b"}; 14305 const char* elmv1[] = {"a", "b"};
12873 CheckProperties( 14306 CheckProperties(
(...skipping 14 matching lines...) Expand all
12888 const char* elmv4[] = {"w", "z"}; 14321 const char* elmv4[] = {"w", "z"};
12889 CheckOwnProperties( 14322 CheckOwnProperties(
12890 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4); 14323 isolate, elms->Get(v8::Integer::New(isolate, 3)), elmc4, elmv4);
12891 } 14324 }
12892 14325
12893 14326
12894 THREADED_TEST(PropertyEnumeration2) { 14327 THREADED_TEST(PropertyEnumeration2) {
12895 LocalContext context; 14328 LocalContext context;
12896 v8::Isolate* isolate = context->GetIsolate(); 14329 v8::Isolate* isolate = context->GetIsolate();
12897 v8::HandleScope scope(isolate); 14330 v8::HandleScope scope(isolate);
12898 v8::Handle<v8::Value> obj = CompileRun( 14331 v8::Local<v8::Value> obj = CompileRun(
12899 "var result = [];" 14332 "var result = [];"
12900 "result[0] = {};" 14333 "result[0] = {};"
12901 "result[1] = {a: 1, b: 2};" 14334 "result[1] = {a: 1, b: 2};"
12902 "result[2] = [1, 2, 3];" 14335 "result[2] = [1, 2, 3];"
12903 "var proto = {x: 1, y: 2, z: 3};" 14336 "var proto = {x: 1, y: 2, z: 3};"
12904 "var x = { __proto__: proto, w: 0, z: 1 };" 14337 "var x = { __proto__: proto, w: 0, z: 1 };"
12905 "result[3] = x;" 14338 "result[3] = x;"
12906 "result;"); 14339 "result;");
12907 v8::Handle<v8::Array> elms = obj.As<v8::Array>(); 14340 v8::Local<v8::Array> elms = obj.As<v8::Array>();
12908 CHECK_EQ(4u, elms->Length()); 14341 CHECK_EQ(4u, elms->Length());
12909 int elmc0 = 0; 14342 int elmc0 = 0;
12910 const char** elmv0 = NULL; 14343 const char** elmv0 = NULL;
12911 CheckProperties(isolate, 14344 CheckProperties(isolate,
12912 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0); 14345 elms->Get(v8::Integer::New(isolate, 0)), elmc0, elmv0);
12913 14346
12914 v8::Handle<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0)); 14347 v8::Local<v8::Value> val = elms->Get(v8::Integer::New(isolate, 0));
12915 v8::Handle<v8::Array> props = val.As<v8::Object>()->GetPropertyNames(); 14348 v8::Local<v8::Array> props = val.As<v8::Object>()->GetPropertyNames();
12916 CHECK_EQ(0u, props->Length()); 14349 CHECK_EQ(0u, props->Length());
12917 for (uint32_t i = 0; i < props->Length(); i++) { 14350 for (uint32_t i = 0; i < props->Length(); i++) {
12918 printf("p[%u]\n", i); 14351 printf("p[%u]\n", i);
12919 } 14352 }
12920 } 14353 }
12921 14354
12922 14355
12923 THREADED_TEST(AccessChecksReenabledCorrectly) { 14356 THREADED_TEST(AccessChecksReenabledCorrectly) {
12924 LocalContext context; 14357 LocalContext context;
12925 v8::Isolate* isolate = context->GetIsolate(); 14358 v8::Isolate* isolate = context->GetIsolate();
(...skipping 10 matching lines...) Expand all
12936 for (char j = '0'; j <= '9'; j++) { 14369 for (char j = '0'; j <= '9'; j++) {
12937 buf[1] = j; 14370 buf[1] = j;
12938 for (char k = '0'; k <= '9'; k++) { 14371 for (char k = '0'; k <= '9'; k++) {
12939 buf[2] = k; 14372 buf[2] = k;
12940 buf[3] = 0; 14373 buf[3] = 0;
12941 templ->Set(v8_str(buf), v8::Number::New(isolate, k)); 14374 templ->Set(v8_str(buf), v8::Number::New(isolate, k));
12942 } 14375 }
12943 } 14376 }
12944 } 14377 }
12945 14378
12946 Local<v8::Object> instance_1 = templ->NewInstance(); 14379 Local<v8::Object> instance_1 =
12947 context->Global()->Set(v8_str("obj_1"), instance_1); 14380 templ->NewInstance(context.local()).ToLocalChecked();
14381 CHECK(context->Global()
14382 ->Set(context.local(), v8_str("obj_1"), instance_1)
14383 .FromJust());
12948 14384
12949 Local<Value> value_1 = CompileRun("obj_1.a"); 14385 Local<Value> value_1 = CompileRun("obj_1.a");
12950 CHECK(value_1.IsEmpty()); 14386 CHECK(value_1.IsEmpty());
12951 14387
12952 Local<v8::Object> instance_2 = templ->NewInstance(); 14388 Local<v8::Object> instance_2 =
12953 context->Global()->Set(v8_str("obj_2"), instance_2); 14389 templ->NewInstance(context.local()).ToLocalChecked();
14390 CHECK(context->Global()
14391 ->Set(context.local(), v8_str("obj_2"), instance_2)
14392 .FromJust());
12954 14393
12955 Local<Value> value_2 = CompileRun("obj_2.a"); 14394 Local<Value> value_2 = CompileRun("obj_2.a");
12956 CHECK(value_2.IsEmpty()); 14395 CHECK(value_2.IsEmpty());
12957 } 14396 }
12958 14397
12959 14398
12960 // Tests that ScriptData can be serialized and deserialized. 14399 // Tests that ScriptData can be serialized and deserialized.
12961 TEST(PreCompileSerialization) { 14400 TEST(PreCompileSerialization) {
12962 v8::V8::Initialize(); 14401 v8::V8::Initialize();
12963 LocalContext env; 14402 LocalContext env;
(...skipping 25 matching lines...) Expand all
12989 // This tests that we do not allow dictionary load/call inline caches 14428 // This tests that we do not allow dictionary load/call inline caches
12990 // to use functions that have not yet been compiled. The potential 14429 // to use functions that have not yet been compiled. The potential
12991 // problem of loading a function that has not yet been compiled can 14430 // problem of loading a function that has not yet been compiled can
12992 // arise because we share code between contexts via the compilation 14431 // arise because we share code between contexts via the compilation
12993 // cache. 14432 // cache.
12994 THREADED_TEST(DictionaryICLoadedFunction) { 14433 THREADED_TEST(DictionaryICLoadedFunction) {
12995 v8::HandleScope scope(CcTest::isolate()); 14434 v8::HandleScope scope(CcTest::isolate());
12996 // Test LoadIC. 14435 // Test LoadIC.
12997 for (int i = 0; i < 2; i++) { 14436 for (int i = 0; i < 2; i++) {
12998 LocalContext context; 14437 LocalContext context;
12999 context->Global()->Set(v8_str("tmp"), v8::True(CcTest::isolate())); 14438 CHECK(context->Global()
14439 ->Set(context.local(), v8_str("tmp"), v8::True(CcTest::isolate()))
14440 .FromJust());
13000 context->Global()->Delete(v8_str("tmp")); 14441 context->Global()->Delete(v8_str("tmp"));
13001 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); 14442 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');");
13002 } 14443 }
13003 // Test CallIC. 14444 // Test CallIC.
13004 for (int i = 0; i < 2; i++) { 14445 for (int i = 0; i < 2; i++) {
13005 LocalContext context; 14446 LocalContext context;
13006 context->Global()->Set(v8_str("tmp"), v8::True(CcTest::isolate())); 14447 CHECK(context->Global()
14448 ->Set(context.local(), v8_str("tmp"), v8::True(CcTest::isolate()))
14449 .FromJust());
13007 context->Global()->Delete(v8_str("tmp")); 14450 context->Global()->Delete(v8_str("tmp"));
13008 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); 14451 CompileRun("for (var j = 0; j < 10; j++) RegExp('')");
13009 } 14452 }
13010 } 14453 }
13011 14454
13012 14455
13013 // Test that cross-context new calls use the context of the callee to 14456 // Test that cross-context new calls use the context of the callee to
13014 // create the new JavaScript object. 14457 // create the new JavaScript object.
13015 THREADED_TEST(CrossContextNew) { 14458 THREADED_TEST(CrossContextNew) {
13016 v8::Isolate* isolate = CcTest::isolate(); 14459 v8::Isolate* isolate = CcTest::isolate();
13017 v8::HandleScope scope(isolate); 14460 v8::HandleScope scope(isolate);
13018 v8::Local<Context> context0 = Context::New(isolate); 14461 v8::Local<Context> context0 = Context::New(isolate);
13019 v8::Local<Context> context1 = Context::New(isolate); 14462 v8::Local<Context> context1 = Context::New(isolate);
13020 14463
13021 // Allow cross-domain access. 14464 // Allow cross-domain access.
13022 Local<String> token = v8_str("<security token>"); 14465 Local<String> token = v8_str("<security token>");
13023 context0->SetSecurityToken(token); 14466 context0->SetSecurityToken(token);
13024 context1->SetSecurityToken(token); 14467 context1->SetSecurityToken(token);
13025 14468
13026 // Set an 'x' property on the Object prototype and define a 14469 // Set an 'x' property on the Object prototype and define a
13027 // constructor function in context0. 14470 // constructor function in context0.
13028 context0->Enter(); 14471 context0->Enter();
13029 CompileRun("Object.prototype.x = 42; function C() {};"); 14472 CompileRun("Object.prototype.x = 42; function C() {};");
13030 context0->Exit(); 14473 context0->Exit();
13031 14474
13032 // Call the constructor function from context0 and check that the 14475 // Call the constructor function from context0 and check that the
13033 // result has the 'x' property. 14476 // result has the 'x' property.
13034 context1->Enter(); 14477 context1->Enter();
13035 context1->Global()->Set(v8_str("other"), context0->Global()); 14478 CHECK(context1->Global()
14479 ->Set(context1, v8_str("other"), context0->Global())
14480 .FromJust());
13036 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); 14481 Local<Value> value = CompileRun("var instance = new other.C(); instance.x");
13037 CHECK(value->IsInt32()); 14482 CHECK(value->IsInt32());
13038 CHECK_EQ(42, value->Int32Value()); 14483 CHECK_EQ(42, value->Int32Value(context1).FromJust());
13039 context1->Exit(); 14484 context1->Exit();
13040 } 14485 }
13041 14486
13042 14487
13043 // Verify that we can clone an object 14488 // Verify that we can clone an object
13044 TEST(ObjectClone) { 14489 TEST(ObjectClone) {
13045 LocalContext env; 14490 LocalContext env;
13046 v8::Isolate* isolate = env->GetIsolate(); 14491 v8::Isolate* isolate = env->GetIsolate();
13047 v8::HandleScope scope(isolate); 14492 v8::HandleScope scope(isolate);
13048 14493
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
13139 i::Vector<const uint16_t>(two_byte_string, 14584 i::Vector<const uint16_t>(two_byte_string,
13140 i::StrLength(c_string))); 14585 i::StrLength(c_string)));
13141 14586
13142 Local<String> lhs( 14587 Local<String> lhs(
13143 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( 14588 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte(
13144 &one_byte_resource).ToHandleChecked())); 14589 &one_byte_resource).ToHandleChecked()));
13145 Local<String> rhs( 14590 Local<String> rhs(
13146 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte( 14591 v8::Utils::ToLocal(factory->NewExternalStringFromOneByte(
13147 &one_byte_resource).ToHandleChecked())); 14592 &one_byte_resource).ToHandleChecked()));
13148 14593
13149 env->Global()->Set(v8_str("lhs"), lhs); 14594 CHECK(env->Global()->Set(env.local(), v8_str("lhs"), lhs).FromJust());
13150 env->Global()->Set(v8_str("rhs"), rhs); 14595 CHECK(env->Global()->Set(env.local(), v8_str("rhs"), rhs).FromJust());
13151 14596
13152 CompileRun( 14597 CompileRun(
13153 "var cons = lhs + rhs;" 14598 "var cons = lhs + rhs;"
13154 "var slice = lhs.substring(1, lhs.length - 1);" 14599 "var slice = lhs.substring(1, lhs.length - 1);"
13155 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);"); 14600 "var slice_on_cons = (lhs + rhs).substring(1, lhs.length *2 - 1);");
13156 14601
13157 CHECK(lhs->IsOneByte()); 14602 CHECK(lhs->IsOneByte());
13158 CHECK(rhs->IsOneByte()); 14603 CHECK(rhs->IsOneByte());
13159 14604
13160 MorphAString(*v8::Utils::OpenHandle(*lhs), &one_byte_resource, 14605 MorphAString(*v8::Utils::OpenHandle(*lhs), &one_byte_resource,
13161 &uc16_resource); 14606 &uc16_resource);
13162 MorphAString(*v8::Utils::OpenHandle(*rhs), &one_byte_resource, 14607 MorphAString(*v8::Utils::OpenHandle(*rhs), &one_byte_resource,
13163 &uc16_resource); 14608 &uc16_resource);
13164 14609
13165 // This should UTF-8 without flattening, since everything is ASCII. 14610 // This should UTF-8 without flattening, since everything is ASCII.
13166 Handle<String> cons = v8_compile("cons")->Run().As<String>(); 14611 Local<String> cons = v8_compile("cons")->Run().As<String>();
13167 CHECK_EQ(128, cons->Utf8Length()); 14612 CHECK_EQ(128, cons->Utf8Length());
13168 int nchars = -1; 14613 int nchars = -1;
13169 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars)); 14614 CHECK_EQ(129, cons->WriteUtf8(utf_buffer, -1, &nchars));
13170 CHECK_EQ(128, nchars); 14615 CHECK_EQ(128, nchars);
13171 CHECK_EQ(0, strcmp( 14616 CHECK_EQ(0, strcmp(
13172 utf_buffer, 14617 utf_buffer,
13173 "Now is the time for all good men to come to the aid of the party" 14618 "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")); 14619 "Now is the time for all good men to come to the aid of the party"));
13175 14620
13176 // Now do some stuff to make sure the strings are flattened, etc. 14621 // Now do some stuff to make sure the strings are flattened, etc.
13177 CompileRun( 14622 CompileRun(
13178 "/[^a-z]/.test(cons);" 14623 "/[^a-z]/.test(cons);"
13179 "/[^a-z]/.test(slice);" 14624 "/[^a-z]/.test(slice);"
13180 "/[^a-z]/.test(slice_on_cons);"); 14625 "/[^a-z]/.test(slice_on_cons);");
13181 const char* expected_cons = 14626 const char* expected_cons =
13182 "Now is the time for all good men to come to the aid of the party" 14627 "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"; 14628 "Now is the time for all good men to come to the aid of the party";
13184 const char* expected_slice = 14629 const char* expected_slice =
13185 "ow is the time for all good men to come to the aid of the part"; 14630 "ow is the time for all good men to come to the aid of the part";
13186 const char* expected_slice_on_cons = 14631 const char* expected_slice_on_cons =
13187 "ow is the time for all good men to come to the aid of the party" 14632 "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"; 14633 "Now is the time for all good men to come to the aid of the part";
13189 CHECK(String::NewFromUtf8(env->GetIsolate(), expected_cons) 14634 CHECK(v8_str(expected_cons)->Equals(env->Global()->Get(v8_str("cons"))));
13190 ->Equals(env->Global()->Get(v8_str("cons")))); 14635 CHECK(v8_str(expected_slice)->Equals(env->Global()->Get(v8_str("slice"))));
13191 CHECK(String::NewFromUtf8(env->GetIsolate(), expected_slice) 14636 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")))); 14637 ->Equals(env->Global()->Get(v8_str("slice_on_cons"))));
13195 } 14638 }
13196 i::DeleteArray(two_byte_string); 14639 i::DeleteArray(two_byte_string);
13197 } 14640 }
13198 14641
13199 14642
13200 TEST(CompileExternalTwoByteSource) { 14643 TEST(CompileExternalTwoByteSource) {
13201 LocalContext context; 14644 LocalContext context;
13202 v8::HandleScope scope(context->GetIsolate()); 14645 v8::HandleScope scope(context->GetIsolate());
13203 14646
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
13297 } 14740 }
13298 14741
13299 #endif // V8_INTERPRETED_REGEXP 14742 #endif // V8_INTERPRETED_REGEXP
13300 14743
13301 14744
13302 // Test that we cannot set a property on the global object if there 14745 // Test that we cannot set a property on the global object if there
13303 // is a read-only property in the prototype chain. 14746 // is a read-only property in the prototype chain.
13304 TEST(ReadOnlyPropertyInGlobalProto) { 14747 TEST(ReadOnlyPropertyInGlobalProto) {
13305 v8::Isolate* isolate = CcTest::isolate(); 14748 v8::Isolate* isolate = CcTest::isolate();
13306 v8::HandleScope scope(isolate); 14749 v8::HandleScope scope(isolate);
13307 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 14750 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
13308 LocalContext context(0, templ); 14751 LocalContext context(0, templ);
13309 v8::Handle<v8::Object> global = context->Global(); 14752 v8::Local<v8::Object> global = context->Global();
13310 v8::Handle<v8::Object> global_proto = 14753 v8::Local<v8::Object> global_proto =
13311 v8::Handle<v8::Object>::Cast(global->Get(v8_str("__proto__"))); 14754 v8::Local<v8::Object>::Cast(global->Get(v8_str("__proto__")));
13312 global_proto->ForceSet(v8_str("x"), v8::Integer::New(isolate, 0), 14755 global_proto->ForceSet(v8_str("x"), v8::Integer::New(isolate, 0),
13313 v8::ReadOnly); 14756 v8::ReadOnly);
13314 global_proto->ForceSet(v8_str("y"), v8::Integer::New(isolate, 0), 14757 global_proto->ForceSet(v8_str("y"), v8::Integer::New(isolate, 0),
13315 v8::ReadOnly); 14758 v8::ReadOnly);
13316 // Check without 'eval' or 'with'. 14759 // Check without 'eval' or 'with'.
13317 v8::Handle<v8::Value> res = 14760 v8::Local<v8::Value> res =
13318 CompileRun("function f() { x = 42; return x; }; f()"); 14761 CompileRun("function f() { x = 42; return x; }; f()");
13319 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); 14762 CHECK(v8::Integer::New(isolate, 0)->Equals(res));
13320 // Check with 'eval'. 14763 // Check with 'eval'.
13321 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()"); 14764 res = CompileRun("function f() { eval('1'); y = 43; return y; }; f()");
13322 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); 14765 CHECK(v8::Integer::New(isolate, 0)->Equals(res));
13323 // Check with 'with'. 14766 // Check with 'with'.
13324 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()"); 14767 res = CompileRun("function f() { with (this) { y = 44 }; return y; }; f()");
13325 CHECK(v8::Integer::New(isolate, 0)->Equals(res)); 14768 CHECK(v8::Integer::New(isolate, 0)->Equals(res));
13326 } 14769 }
13327 14770
(...skipping 30 matching lines...) Expand all
13358 } 14801 }
13359 14802
13360 14803
13361 TEST(ForceSet) { 14804 TEST(ForceSet) {
13362 force_set_get_count = 0; 14805 force_set_get_count = 0;
13363 force_set_set_count = 0; 14806 force_set_set_count = 0;
13364 pass_on_get = false; 14807 pass_on_get = false;
13365 14808
13366 v8::Isolate* isolate = CcTest::isolate(); 14809 v8::Isolate* isolate = CcTest::isolate();
13367 v8::HandleScope scope(isolate); 14810 v8::HandleScope scope(isolate);
13368 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 14811 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
13369 v8::Handle<v8::String> access_property = 14812 v8::Local<v8::String> access_property = v8_str("a");
13370 v8::String::NewFromUtf8(isolate, "a");
13371 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter); 14813 templ->SetAccessor(access_property, ForceSetGetter, ForceSetSetter);
13372 LocalContext context(NULL, templ); 14814 LocalContext context(NULL, templ);
13373 v8::Handle<v8::Object> global = context->Global(); 14815 v8::Local<v8::Object> global = context->Global();
13374 14816
13375 // Ordinary properties 14817 // Ordinary properties
13376 v8::Handle<v8::String> simple_property = 14818 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); 14819 global->ForceSet(simple_property, v8::Int32::New(isolate, 4), v8::ReadOnly);
13379 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14820 CHECK_EQ(
14821 4, global->Get(simple_property)->Int32Value(context.local()).FromJust());
13380 // This should fail because the property is read-only 14822 // This should fail because the property is read-only
13381 global->Set(simple_property, v8::Int32::New(isolate, 5)); 14823 global->Set(simple_property, v8::Int32::New(isolate, 5));
13382 CHECK_EQ(4, global->Get(simple_property)->Int32Value()); 14824 CHECK_EQ(
14825 4, global->Get(simple_property)->Int32Value(context.local()).FromJust());
13383 // This should succeed even though the property is read-only 14826 // This should succeed even though the property is read-only
13384 global->ForceSet(simple_property, v8::Int32::New(isolate, 6)); 14827 global->ForceSet(simple_property, v8::Int32::New(isolate, 6));
13385 CHECK_EQ(6, global->Get(simple_property)->Int32Value()); 14828 CHECK_EQ(
14829 6, global->Get(simple_property)->Int32Value(context.local()).FromJust());
13386 14830
13387 // Accessors 14831 // Accessors
13388 CHECK_EQ(0, force_set_set_count); 14832 CHECK_EQ(0, force_set_set_count);
13389 CHECK_EQ(0, force_set_get_count); 14833 CHECK_EQ(0, force_set_get_count);
13390 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 14834 CHECK_EQ(
14835 3, global->Get(access_property)->Int32Value(context.local()).FromJust());
13391 // CHECK_EQ the property shouldn't override it, just call the setter 14836 // CHECK_EQ the property shouldn't override it, just call the setter
13392 // which in this case does nothing. 14837 // which in this case does nothing.
13393 global->Set(access_property, v8::Int32::New(isolate, 7)); 14838 global->Set(access_property, v8::Int32::New(isolate, 7));
13394 CHECK_EQ(3, global->Get(access_property)->Int32Value()); 14839 CHECK_EQ(
14840 3, global->Get(access_property)->Int32Value(context.local()).FromJust());
13395 CHECK_EQ(1, force_set_set_count); 14841 CHECK_EQ(1, force_set_set_count);
13396 CHECK_EQ(2, force_set_get_count); 14842 CHECK_EQ(2, force_set_get_count);
13397 // ForceSet doesn't call the accessors for now. 14843 // ForceSet doesn't call the accessors for now.
13398 // TODO(verwaest): Update once blink doesn't rely on ForceSet to delete api 14844 // TODO(verwaest): Update once blink doesn't rely on ForceSet to delete api
13399 // accessors. 14845 // accessors.
13400 global->ForceSet(access_property, v8::Int32::New(isolate, 8)); 14846 global->ForceSet(access_property, v8::Int32::New(isolate, 8));
13401 CHECK_EQ(8, global->Get(access_property)->Int32Value()); 14847 CHECK_EQ(
14848 8, global->Get(access_property)->Int32Value(context.local()).FromJust());
13402 CHECK_EQ(1, force_set_set_count); 14849 CHECK_EQ(1, force_set_set_count);
13403 CHECK_EQ(2, force_set_get_count); 14850 CHECK_EQ(2, force_set_get_count);
13404 } 14851 }
13405 14852
13406 14853
13407 TEST(ForceSetWithInterceptor) { 14854 TEST(ForceSetWithInterceptor) {
13408 v8::Isolate* isolate = CcTest::isolate(); 14855 v8::Isolate* isolate = CcTest::isolate();
13409 v8::HandleScope scope(isolate); 14856 v8::HandleScope scope(isolate);
13410 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 14857 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
13411 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 14858 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
13412 ForceSetInterceptGetter, ForceSetInterceptSetter)); 14859 ForceSetInterceptGetter, ForceSetInterceptSetter));
13413 pass_on_get = true; 14860 pass_on_get = true;
13414 LocalContext context(NULL, templ); 14861 LocalContext context(NULL, templ);
13415 v8::Handle<v8::Object> global = context->Global(); 14862 v8::Local<v8::Object> global = context->Global();
13416 14863
13417 force_set_get_count = 0; 14864 force_set_get_count = 0;
13418 force_set_set_count = 0; 14865 force_set_set_count = 0;
13419 pass_on_get = false; 14866 pass_on_get = false;
13420 14867
13421 v8::Handle<v8::String> some_property = 14868 v8::Local<v8::String> some_property = v8_str("a");
13422 v8::String::NewFromUtf8(isolate, "a");
13423 CHECK_EQ(0, force_set_set_count); 14869 CHECK_EQ(0, force_set_set_count);
13424 CHECK_EQ(0, force_set_get_count); 14870 CHECK_EQ(0, force_set_get_count);
13425 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14871 CHECK_EQ(3,
14872 global->Get(some_property)->Int32Value(context.local()).FromJust());
13426 // Setting the property shouldn't override it, just call the setter 14873 // Setting the property shouldn't override it, just call the setter
13427 // which in this case does nothing. 14874 // which in this case does nothing.
13428 global->Set(some_property, v8::Int32::New(isolate, 7)); 14875 global->Set(some_property, v8::Int32::New(isolate, 7));
13429 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14876 CHECK_EQ(3,
14877 global->Get(some_property)->Int32Value(context.local()).FromJust());
13430 CHECK_EQ(1, force_set_set_count); 14878 CHECK_EQ(1, force_set_set_count);
13431 CHECK_EQ(2, force_set_get_count); 14879 CHECK_EQ(2, force_set_get_count);
13432 // Getting the property when the interceptor returns an empty handle 14880 // Getting the property when the interceptor returns an empty handle
13433 // should yield undefined, since the property isn't present on the 14881 // should yield undefined, since the property isn't present on the
13434 // object itself yet. 14882 // object itself yet.
13435 pass_on_get = true; 14883 pass_on_get = true;
13436 CHECK(global->Get(some_property)->IsUndefined()); 14884 CHECK(global->Get(some_property)->IsUndefined());
13437 CHECK_EQ(1, force_set_set_count); 14885 CHECK_EQ(1, force_set_set_count);
13438 CHECK_EQ(3, force_set_get_count); 14886 CHECK_EQ(3, force_set_get_count);
13439 // Forcing the property to be set should cause the value to be 14887 // Forcing the property to be set should cause the value to be
13440 // set locally without calling the interceptor. 14888 // set locally without calling the interceptor.
13441 global->ForceSet(some_property, v8::Int32::New(isolate, 8)); 14889 global->ForceSet(some_property, v8::Int32::New(isolate, 8));
13442 CHECK_EQ(8, global->Get(some_property)->Int32Value()); 14890 CHECK_EQ(8,
14891 global->Get(some_property)->Int32Value(context.local()).FromJust());
13443 CHECK_EQ(1, force_set_set_count); 14892 CHECK_EQ(1, force_set_set_count);
13444 CHECK_EQ(4, force_set_get_count); 14893 CHECK_EQ(4, force_set_get_count);
13445 // Reenabling the interceptor should cause it to take precedence over 14894 // Reenabling the interceptor should cause it to take precedence over
13446 // the property 14895 // the property
13447 pass_on_get = false; 14896 pass_on_get = false;
13448 CHECK_EQ(3, global->Get(some_property)->Int32Value()); 14897 CHECK_EQ(3,
14898 global->Get(some_property)->Int32Value(context.local()).FromJust());
13449 CHECK_EQ(1, force_set_set_count); 14899 CHECK_EQ(1, force_set_set_count);
13450 CHECK_EQ(5, force_set_get_count); 14900 CHECK_EQ(5, force_set_get_count);
13451 // The interceptor should also work for other properties 14901 // The interceptor should also work for other properties
13452 CHECK_EQ(3, global->Get(v8::String::NewFromUtf8(isolate, "b")) 14902 CHECK_EQ(3, global->Get(v8_str("b"))->Int32Value(context.local()).FromJust());
13453 ->Int32Value());
13454 CHECK_EQ(1, force_set_set_count); 14903 CHECK_EQ(1, force_set_set_count);
13455 CHECK_EQ(6, force_set_get_count); 14904 CHECK_EQ(6, force_set_get_count);
13456 } 14905 }
13457 14906
13458 14907
13459 TEST(CreateDataProperty) { 14908 TEST(CreateDataProperty) {
13460 LocalContext env; 14909 LocalContext env;
13461 v8::Isolate* isolate = env->GetIsolate(); 14910 v8::Isolate* isolate = env->GetIsolate();
13462 v8::HandleScope handle_scope(isolate); 14911 v8::HandleScope handle_scope(isolate);
13463 14912
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
13690 } 15139 }
13691 15140
13692 15141
13693 // Check that a variable declaration with no explicit initialization 15142 // Check that a variable declaration with no explicit initialization
13694 // value does shadow an existing property in the prototype chain. 15143 // value does shadow an existing property in the prototype chain.
13695 THREADED_TEST(InitGlobalVarInProtoChain) { 15144 THREADED_TEST(InitGlobalVarInProtoChain) {
13696 LocalContext context; 15145 LocalContext context;
13697 v8::HandleScope scope(context->GetIsolate()); 15146 v8::HandleScope scope(context->GetIsolate());
13698 // Introduce a variable in the prototype chain. 15147 // Introduce a variable in the prototype chain.
13699 CompileRun("__proto__.x = 42"); 15148 CompileRun("__proto__.x = 42");
13700 v8::Handle<v8::Value> result = CompileRun("var x = 43; x"); 15149 v8::Local<v8::Value> result = CompileRun("var x = 43; x");
13701 CHECK(!result->IsUndefined()); 15150 CHECK(!result->IsUndefined());
13702 CHECK_EQ(43, result->Int32Value()); 15151 CHECK_EQ(43, result->Int32Value(context.local()).FromJust());
13703 } 15152 }
13704 15153
13705 15154
13706 // Regression test for issue 398. 15155 // Regression test for issue 398.
13707 // If a function is added to an object, creating a constant function 15156 // 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 15157 // field, and the result is cloned, replacing the constant function on the
13709 // original should not affect the clone. 15158 // original should not affect the clone.
13710 // See http://code.google.com/p/v8/issues/detail?id=398 15159 // See http://code.google.com/p/v8/issues/detail?id=398
13711 THREADED_TEST(ReplaceConstantFunction) { 15160 THREADED_TEST(ReplaceConstantFunction) {
13712 LocalContext context; 15161 LocalContext context;
13713 v8::Isolate* isolate = context->GetIsolate(); 15162 v8::Isolate* isolate = context->GetIsolate();
13714 v8::HandleScope scope(isolate); 15163 v8::HandleScope scope(isolate);
13715 v8::Handle<v8::Object> obj = v8::Object::New(isolate); 15164 v8::Local<v8::Object> obj = v8::Object::New(isolate);
13716 v8::Handle<v8::FunctionTemplate> func_templ = 15165 v8::Local<v8::FunctionTemplate> func_templ =
13717 v8::FunctionTemplate::New(isolate); 15166 v8::FunctionTemplate::New(isolate);
13718 v8::Handle<v8::String> foo_string = 15167 v8::Local<v8::String> foo_string = v8_str("foo");
13719 v8::String::NewFromUtf8(isolate, "foo"); 15168 obj->Set(foo_string,
13720 obj->Set(foo_string, func_templ->GetFunction()); 15169 func_templ->GetFunction(context.local()).ToLocalChecked());
13721 v8::Handle<v8::Object> obj_clone = obj->Clone(); 15170 v8::Local<v8::Object> obj_clone = obj->Clone();
13722 obj_clone->Set(foo_string, 15171 obj_clone->Set(foo_string, v8_str("Hello"));
13723 v8::String::NewFromUtf8(isolate, "Hello"));
13724 CHECK(!obj->Get(foo_string)->IsUndefined()); 15172 CHECK(!obj->Get(foo_string)->IsUndefined());
13725 } 15173 }
13726 15174
13727 15175
13728 static void CheckElementValue(i::Isolate* isolate, 15176 static void CheckElementValue(i::Isolate* isolate,
13729 int expected, 15177 int expected,
13730 i::Handle<i::Object> obj, 15178 i::Handle<i::Object> obj,
13731 int offset) { 15179 int offset) {
13732 i::Object* element = 15180 i::Object* element =
13733 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked(); 15181 *i::Object::GetElement(isolate, obj, offset).ToHandleChecked();
13734 CHECK_EQ(expected, i::Smi::cast(element)->value()); 15182 CHECK_EQ(expected, i::Smi::cast(element)->value());
13735 } 15183 }
13736 15184
13737 15185
13738 template <class ExternalArrayClass, class ElementType> 15186 template <class ExternalArrayClass, class ElementType>
13739 static void ObjectWithExternalArrayTestHelper(Handle<Context> context, 15187 static void ObjectWithExternalArrayTestHelper(Local<Context> context,
13740 v8::Handle<Object> obj, 15188 v8::Local<Object> obj,
13741 int element_count, 15189 int element_count,
13742 i::ExternalArrayType array_type, 15190 i::ExternalArrayType array_type,
13743 int64_t low, int64_t high) { 15191 int64_t low, int64_t high) {
13744 i::Handle<i::JSReceiver> jsobj = v8::Utils::OpenHandle(*obj); 15192 i::Handle<i::JSReceiver> jsobj = v8::Utils::OpenHandle(*obj);
13745 i::Isolate* isolate = jsobj->GetIsolate(); 15193 i::Isolate* isolate = jsobj->GetIsolate();
13746 obj->Set(v8_str("field"), 15194 obj->Set(v8_str("field"),
13747 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503)); 15195 v8::Int32::New(reinterpret_cast<v8::Isolate*>(isolate), 1503));
13748 context->Global()->Set(v8_str("ext_array"), obj); 15196 CHECK(context->Global()->Set(context, v8_str("ext_array"), obj).FromJust());
13749 v8::Handle<v8::Value> result = CompileRun("ext_array.field"); 15197 v8::Local<v8::Value> result = CompileRun("ext_array.field");
13750 CHECK_EQ(1503, result->Int32Value()); 15198 CHECK_EQ(1503, result->Int32Value(context).FromJust());
13751 result = CompileRun("ext_array[1]"); 15199 result = CompileRun("ext_array[1]");
13752 CHECK_EQ(1, result->Int32Value()); 15200 CHECK_EQ(1, result->Int32Value(context).FromJust());
13753 15201
13754 // Check assigned smis 15202 // Check assigned smis
13755 result = CompileRun("for (var i = 0; i < 8; i++) {" 15203 result = CompileRun("for (var i = 0; i < 8; i++) {"
13756 " ext_array[i] = i;" 15204 " ext_array[i] = i;"
13757 "}" 15205 "}"
13758 "var sum = 0;" 15206 "var sum = 0;"
13759 "for (var i = 0; i < 8; i++) {" 15207 "for (var i = 0; i < 8; i++) {"
13760 " sum += ext_array[i];" 15208 " sum += ext_array[i];"
13761 "}" 15209 "}"
13762 "sum;"); 15210 "sum;");
13763 15211
13764 CHECK_EQ(28, result->Int32Value()); 15212 CHECK_EQ(28, result->Int32Value(context).FromJust());
13765 // Check pass through of assigned smis 15213 // Check pass through of assigned smis
13766 result = CompileRun("var sum = 0;" 15214 result = CompileRun("var sum = 0;"
13767 "for (var i = 0; i < 8; i++) {" 15215 "for (var i = 0; i < 8; i++) {"
13768 " sum += ext_array[i] = ext_array[i] = -i;" 15216 " sum += ext_array[i] = ext_array[i] = -i;"
13769 "}" 15217 "}"
13770 "sum;"); 15218 "sum;");
13771 CHECK_EQ(-28, result->Int32Value()); 15219 CHECK_EQ(-28, result->Int32Value(context).FromJust());
13772 15220
13773 15221
13774 // Check assigned smis in reverse order 15222 // Check assigned smis in reverse order
13775 result = CompileRun("for (var i = 8; --i >= 0; ) {" 15223 result = CompileRun("for (var i = 8; --i >= 0; ) {"
13776 " ext_array[i] = i;" 15224 " ext_array[i] = i;"
13777 "}" 15225 "}"
13778 "var sum = 0;" 15226 "var sum = 0;"
13779 "for (var i = 0; i < 8; i++) {" 15227 "for (var i = 0; i < 8; i++) {"
13780 " sum += ext_array[i];" 15228 " sum += ext_array[i];"
13781 "}" 15229 "}"
13782 "sum;"); 15230 "sum;");
13783 CHECK_EQ(28, result->Int32Value()); 15231 CHECK_EQ(28, result->Int32Value(context).FromJust());
13784 15232
13785 // Check pass through of assigned HeapNumbers 15233 // Check pass through of assigned HeapNumbers
13786 result = CompileRun("var sum = 0;" 15234 result = CompileRun("var sum = 0;"
13787 "for (var i = 0; i < 16; i+=2) {" 15235 "for (var i = 0; i < 16; i+=2) {"
13788 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);" 15236 " sum += ext_array[i] = ext_array[i] = (-i * 0.5);"
13789 "}" 15237 "}"
13790 "sum;"); 15238 "sum;");
13791 CHECK_EQ(-28, result->Int32Value()); 15239 CHECK_EQ(-28, result->Int32Value(context).FromJust());
13792 15240
13793 // Check assigned HeapNumbers 15241 // Check assigned HeapNumbers
13794 result = CompileRun("for (var i = 0; i < 16; i+=2) {" 15242 result = CompileRun("for (var i = 0; i < 16; i+=2) {"
13795 " ext_array[i] = (i * 0.5);" 15243 " ext_array[i] = (i * 0.5);"
13796 "}" 15244 "}"
13797 "var sum = 0;" 15245 "var sum = 0;"
13798 "for (var i = 0; i < 16; i+=2) {" 15246 "for (var i = 0; i < 16; i+=2) {"
13799 " sum += ext_array[i];" 15247 " sum += ext_array[i];"
13800 "}" 15248 "}"
13801 "sum;"); 15249 "sum;");
13802 CHECK_EQ(28, result->Int32Value()); 15250 CHECK_EQ(28, result->Int32Value(context).FromJust());
13803 15251
13804 // Check assigned HeapNumbers in reverse order 15252 // Check assigned HeapNumbers in reverse order
13805 result = CompileRun("for (var i = 14; i >= 0; i-=2) {" 15253 result = CompileRun("for (var i = 14; i >= 0; i-=2) {"
13806 " ext_array[i] = (i * 0.5);" 15254 " ext_array[i] = (i * 0.5);"
13807 "}" 15255 "}"
13808 "var sum = 0;" 15256 "var sum = 0;"
13809 "for (var i = 0; i < 16; i+=2) {" 15257 "for (var i = 0; i < 16; i+=2) {"
13810 " sum += ext_array[i];" 15258 " sum += ext_array[i];"
13811 "}" 15259 "}"
13812 "sum;"); 15260 "sum;");
13813 CHECK_EQ(28, result->Int32Value()); 15261 CHECK_EQ(28, result->Int32Value(context).FromJust());
13814 15262
13815 i::ScopedVector<char> test_buf(1024); 15263 i::ScopedVector<char> test_buf(1024);
13816 15264
13817 // Check legal boundary conditions. 15265 // Check legal boundary conditions.
13818 // The repeated loads and stores ensure the ICs are exercised. 15266 // The repeated loads and stores ensure the ICs are exercised.
13819 const char* boundary_program = 15267 const char* boundary_program =
13820 "var res = 0;" 15268 "var res = 0;"
13821 "for (var i = 0; i < 16; i++) {" 15269 "for (var i = 0; i < 16; i++) {"
13822 " ext_array[i] = %lld;" 15270 " ext_array[i] = %lld;"
13823 " if (i > 8) {" 15271 " if (i > 8) {"
(...skipping 19 matching lines...) Expand all
13843 "for (var i = 0; i < 8; i++) {" 15291 "for (var i = 0; i < 8; i++) {"
13844 " tmp_array[i] = i;" 15292 " tmp_array[i] = i;"
13845 " sum += tmp_array[i];" 15293 " sum += tmp_array[i];"
13846 " if (i == 4) {" 15294 " if (i == 4) {"
13847 " tmp_array = {};" 15295 " tmp_array = {};"
13848 " }" 15296 " }"
13849 "}" 15297 "}"
13850 "sum;"); 15298 "sum;");
13851 // Force GC to trigger verification. 15299 // Force GC to trigger verification.
13852 CcTest::heap()->CollectAllGarbage(); 15300 CcTest::heap()->CollectAllGarbage();
13853 CHECK_EQ(28, result->Int32Value()); 15301 CHECK_EQ(28, result->Int32Value(context).FromJust());
13854 15302
13855 // Make sure out-of-range loads do not throw. 15303 // Make sure out-of-range loads do not throw.
13856 i::SNPrintF(test_buf, 15304 i::SNPrintF(test_buf,
13857 "var caught_exception = false;" 15305 "var caught_exception = false;"
13858 "try {" 15306 "try {"
13859 " ext_array[%d];" 15307 " ext_array[%d];"
13860 "} catch (e) {" 15308 "} catch (e) {"
13861 " caught_exception = true;" 15309 " caught_exception = true;"
13862 "}" 15310 "}"
13863 "caught_exception;", 15311 "caught_exception;",
(...skipping 12 matching lines...) Expand all
13876 "caught_exception;", 15324 "caught_exception;",
13877 element_count); 15325 element_count);
13878 result = CompileRun(test_buf.start()); 15326 result = CompileRun(test_buf.start());
13879 CHECK_EQ(false, result->BooleanValue()); 15327 CHECK_EQ(false, result->BooleanValue());
13880 15328
13881 // Check other boundary conditions, values and operations. 15329 // Check other boundary conditions, values and operations.
13882 result = CompileRun("for (var i = 0; i < 8; i++) {" 15330 result = CompileRun("for (var i = 0; i < 8; i++) {"
13883 " ext_array[7] = undefined;" 15331 " ext_array[7] = undefined;"
13884 "}" 15332 "}"
13885 "ext_array[7];"); 15333 "ext_array[7];");
13886 CHECK_EQ(0, result->Int32Value()); 15334 CHECK_EQ(0, result->Int32Value(context).FromJust());
13887 if (array_type == i::kExternalFloat64Array || 15335 if (array_type == i::kExternalFloat64Array ||
13888 array_type == i::kExternalFloat32Array) { 15336 array_type == i::kExternalFloat32Array) {
13889 CHECK(std::isnan( 15337 CHECK(std::isnan(
13890 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number())); 15338 i::Object::GetElement(isolate, jsobj, 7).ToHandleChecked()->Number()));
13891 } else { 15339 } else {
13892 CheckElementValue(isolate, 0, jsobj, 7); 15340 CheckElementValue(isolate, 0, jsobj, 7);
13893 } 15341 }
13894 15342
13895 result = CompileRun("for (var i = 0; i < 8; i++) {" 15343 result = CompileRun("for (var i = 0; i < 8; i++) {"
13896 " ext_array[6] = '2.3';" 15344 " ext_array[6] = '2.3';"
13897 "}" 15345 "}"
13898 "ext_array[6];"); 15346 "ext_array[6];");
13899 CHECK_EQ(2, result->Int32Value()); 15347 CHECK_EQ(2, result->Int32Value(context).FromJust());
13900 CHECK_EQ(2, 15348 CHECK_EQ(2,
13901 static_cast<int>( 15349 static_cast<int>(
13902 i::Object::GetElement( 15350 i::Object::GetElement(
13903 isolate, jsobj, 6).ToHandleChecked()->Number())); 15351 isolate, jsobj, 6).ToHandleChecked()->Number()));
13904 15352
13905 if (array_type != i::kExternalFloat32Array && 15353 if (array_type != i::kExternalFloat32Array &&
13906 array_type != i::kExternalFloat64Array) { 15354 array_type != i::kExternalFloat64Array) {
13907 // Though the specification doesn't state it, be explicit about 15355 // Though the specification doesn't state it, be explicit about
13908 // converting NaNs and +/-Infinity to zero. 15356 // converting NaNs and +/-Infinity to zero.
13909 result = CompileRun("for (var i = 0; i < 8; i++) {" 15357 result = CompileRun("for (var i = 0; i < 8; i++) {"
13910 " ext_array[i] = 5;" 15358 " ext_array[i] = 5;"
13911 "}" 15359 "}"
13912 "for (var i = 0; i < 8; i++) {" 15360 "for (var i = 0; i < 8; i++) {"
13913 " ext_array[i] = NaN;" 15361 " ext_array[i] = NaN;"
13914 "}" 15362 "}"
13915 "ext_array[5];"); 15363 "ext_array[5];");
13916 CHECK_EQ(0, result->Int32Value()); 15364 CHECK_EQ(0, result->Int32Value(context).FromJust());
13917 CheckElementValue(isolate, 0, jsobj, 5); 15365 CheckElementValue(isolate, 0, jsobj, 5);
13918 15366
13919 result = CompileRun("for (var i = 0; i < 8; i++) {" 15367 result = CompileRun("for (var i = 0; i < 8; i++) {"
13920 " ext_array[i] = 5;" 15368 " ext_array[i] = 5;"
13921 "}" 15369 "}"
13922 "for (var i = 0; i < 8; i++) {" 15370 "for (var i = 0; i < 8; i++) {"
13923 " ext_array[i] = Infinity;" 15371 " ext_array[i] = Infinity;"
13924 "}" 15372 "}"
13925 "ext_array[5];"); 15373 "ext_array[5];");
13926 int expected_value = 15374 int expected_value =
13927 (array_type == i::kExternalUint8ClampedArray) ? 255 : 0; 15375 (array_type == i::kExternalUint8ClampedArray) ? 255 : 0;
13928 CHECK_EQ(expected_value, result->Int32Value()); 15376 CHECK_EQ(expected_value, result->Int32Value(context).FromJust());
13929 CheckElementValue(isolate, expected_value, jsobj, 5); 15377 CheckElementValue(isolate, expected_value, jsobj, 5);
13930 15378
13931 result = CompileRun("for (var i = 0; i < 8; i++) {" 15379 result = CompileRun("for (var i = 0; i < 8; i++) {"
13932 " ext_array[i] = 5;" 15380 " ext_array[i] = 5;"
13933 "}" 15381 "}"
13934 "for (var i = 0; i < 8; i++) {" 15382 "for (var i = 0; i < 8; i++) {"
13935 " ext_array[i] = -Infinity;" 15383 " ext_array[i] = -Infinity;"
13936 "}" 15384 "}"
13937 "ext_array[5];"); 15385 "ext_array[5];");
13938 CHECK_EQ(0, result->Int32Value()); 15386 CHECK_EQ(0, result->Int32Value(context).FromJust());
13939 CheckElementValue(isolate, 0, jsobj, 5); 15387 CheckElementValue(isolate, 0, jsobj, 5);
13940 15388
13941 // Check truncation behavior of integral arrays. 15389 // Check truncation behavior of integral arrays.
13942 const char* unsigned_data = 15390 const char* unsigned_data =
13943 "var source_data = [0.6, 10.6];" 15391 "var source_data = [0.6, 10.6];"
13944 "var expected_results = [0, 10];"; 15392 "var expected_results = [0, 10];";
13945 const char* signed_data = 15393 const char* signed_data =
13946 "var source_data = [0.6, 10.6, -0.6, -10.6];" 15394 "var source_data = [0.6, 10.6, -0.6, -10.6];"
13947 "var expected_results = [0, 10, 0, -10];"; 15395 "var expected_results = [0, 10, 0, -10];";
13948 const char* pixel_data = 15396 const char* pixel_data =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
13983 " sum += (ext_array[i] += 1);" 15431 " sum += (ext_array[i] += 1);"
13984 " sum += (ext_array[i] -= 1);" 15432 " sum += (ext_array[i] -= 1);"
13985 " } " 15433 " } "
13986 " return sum;" 15434 " return sum;"
13987 "}" 15435 "}"
13988 "sum=0;" 15436 "sum=0;"
13989 "for (var i=0;i<10000;++i) {" 15437 "for (var i=0;i<10000;++i) {"
13990 " sum=ee_op_test_complex_func(sum);" 15438 " sum=ee_op_test_complex_func(sum);"
13991 "}" 15439 "}"
13992 "sum;"); 15440 "sum;");
13993 CHECK_EQ(16000000, result->Int32Value()); 15441 CHECK_EQ(16000000, result->Int32Value(context).FromJust());
13994 15442
13995 // Test count operations 15443 // Test count operations
13996 result = CompileRun("function ee_op_test_count_func(sum) {" 15444 result = CompileRun("function ee_op_test_count_func(sum) {"
13997 " for (var i = 0; i < 40; ++i) {" 15445 " for (var i = 0; i < 40; ++i) {"
13998 " sum += (++ext_array[i]);" 15446 " sum += (++ext_array[i]);"
13999 " sum += (--ext_array[i]);" 15447 " sum += (--ext_array[i]);"
14000 " } " 15448 " } "
14001 " return sum;" 15449 " return sum;"
14002 "}" 15450 "}"
14003 "sum=0;" 15451 "sum=0;"
14004 "for (var i=0;i<10000;++i) {" 15452 "for (var i=0;i<10000;++i) {"
14005 " sum=ee_op_test_count_func(sum);" 15453 " sum=ee_op_test_count_func(sum);"
14006 "}" 15454 "}"
14007 "sum;"); 15455 "sum;");
14008 CHECK_EQ(16000000, result->Int32Value()); 15456 CHECK_EQ(16000000, result->Int32Value(context).FromJust());
14009 15457
14010 result = CompileRun("ext_array[3] = 33;" 15458 result = CompileRun("ext_array[3] = 33;"
14011 "delete ext_array[3];" 15459 "delete ext_array[3];"
14012 "ext_array[3];"); 15460 "ext_array[3];");
14013 CHECK_EQ(33, result->Int32Value()); 15461 CHECK_EQ(33, result->Int32Value(context).FromJust());
14014 15462
14015 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;" 15463 result = CompileRun("ext_array[0] = 10; ext_array[1] = 11;"
14016 "ext_array[2] = 12; ext_array[3] = 13;" 15464 "ext_array[2] = 12; ext_array[3] = 13;"
14017 "ext_array.__defineGetter__('2'," 15465 "ext_array.__defineGetter__('2',"
14018 "function() { return 120; });" 15466 "function() { return 120; });"
14019 "ext_array[2];"); 15467 "ext_array[2];");
14020 CHECK_EQ(12, result->Int32Value()); 15468 CHECK_EQ(12, result->Int32Value(context).FromJust());
14021 15469
14022 result = CompileRun("var js_array = new Array(40);" 15470 result = CompileRun("var js_array = new Array(40);"
14023 "js_array[0] = 77;" 15471 "js_array[0] = 77;"
14024 "js_array;"); 15472 "js_array;");
14025 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); 15473 CHECK_EQ(77, v8::Object::Cast(*result)
15474 ->Get(v8_str("0"))
15475 ->Int32Value(context)
15476 .FromJust());
14026 15477
14027 result = CompileRun("ext_array[1] = 23;" 15478 result = CompileRun("ext_array[1] = 23;"
14028 "ext_array.__proto__ = [];" 15479 "ext_array.__proto__ = [];"
14029 "js_array.__proto__ = ext_array;" 15480 "js_array.__proto__ = ext_array;"
14030 "js_array.concat(ext_array);"); 15481 "js_array.concat(ext_array);");
14031 CHECK_EQ(77, v8::Object::Cast(*result)->Get(v8_str("0"))->Int32Value()); 15482 CHECK_EQ(77, v8::Object::Cast(*result)
14032 CHECK_EQ(23, v8::Object::Cast(*result)->Get(v8_str("1"))->Int32Value()); 15483 ->Get(v8_str("0"))
15484 ->Int32Value(context)
15485 .FromJust());
15486 CHECK_EQ(23, v8::Object::Cast(*result)
15487 ->Get(v8_str("1"))
15488 ->Int32Value(context)
15489 .FromJust());
14033 15490
14034 result = CompileRun("ext_array[1] = 23;"); 15491 result = CompileRun("ext_array[1] = 23;");
14035 CHECK_EQ(23, result->Int32Value()); 15492 CHECK_EQ(23, result->Int32Value(context).FromJust());
14036 } 15493 }
14037 15494
14038 15495
14039 template <class FixedTypedArrayClass, i::ElementsKind elements_kind, 15496 template <class FixedTypedArrayClass, i::ElementsKind elements_kind,
14040 class ElementType> 15497 class ElementType>
14041 static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type, 15498 static void FixedTypedArrayTestHelper(i::ExternalArrayType array_type,
14042 ElementType low, ElementType high) { 15499 ElementType low, ElementType high) {
14043 i::FLAG_allow_natives_syntax = true; 15500 i::FLAG_allow_natives_syntax = true;
14044 LocalContext context; 15501 LocalContext context;
14045 i::Isolate* isolate = CcTest::i_isolate(); 15502 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 10 matching lines...) Expand all
14056 CcTest::heap()->CollectAllGarbage(); 15513 CcTest::heap()->CollectAllGarbage();
14057 for (int i = 0; i < kElementCount; i++) { 15514 for (int i = 0; i < kElementCount; i++) {
14058 fixed_array->set(i, static_cast<ElementType>(i)); 15515 fixed_array->set(i, static_cast<ElementType>(i));
14059 } 15516 }
14060 // Force GC to trigger verification. 15517 // Force GC to trigger verification.
14061 CcTest::heap()->CollectAllGarbage(); 15518 CcTest::heap()->CollectAllGarbage();
14062 for (int i = 0; i < kElementCount; i++) { 15519 for (int i = 0; i < kElementCount; i++) {
14063 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)), 15520 CHECK_EQ(static_cast<int64_t>(static_cast<ElementType>(i)),
14064 static_cast<int64_t>(fixed_array->get_scalar(i))); 15521 static_cast<int64_t>(fixed_array->get_scalar(i)));
14065 } 15522 }
14066 v8::Handle<v8::Object> obj = v8::Utils::ToLocal(jsobj); 15523 v8::Local<v8::Object> obj = v8::Utils::ToLocal(jsobj);
14067 15524
14068 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>( 15525 ObjectWithExternalArrayTestHelper<FixedTypedArrayClass, ElementType>(
14069 context.local(), obj, kElementCount, array_type, 15526 context.local(), obj, kElementCount, array_type,
14070 static_cast<int64_t>(low), 15527 static_cast<int64_t>(low),
14071 static_cast<int64_t>(high)); 15528 static_cast<int64_t>(high));
14072 } 15529 }
14073 15530
14074 15531
14075 THREADED_TEST(FixedUint8Array) { 15532 THREADED_TEST(FixedUint8Array) {
14076 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>( 15533 FixedTypedArrayTestHelper<i::FixedUint8Array, i::UINT8_ELEMENTS, uint8_t>(
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
14369 v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize); 15826 v8::SharedArrayBuffer::New(isolate, backing_store.start(), 2 + kSize);
14370 Local<v8::DataView> dv = 15827 Local<v8::DataView> dv =
14371 v8::DataView::New(ab, 2, kSize); 15828 v8::DataView::New(ab, 2, kSize);
14372 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv); 15829 CheckInternalFieldsAreZero<v8::ArrayBufferView>(dv);
14373 CHECK_EQ(2u, dv->ByteOffset()); 15830 CHECK_EQ(2u, dv->ByteOffset());
14374 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength())); 15831 CHECK_EQ(kSize, static_cast<int>(dv->ByteLength()));
14375 CHECK(ab->Equals(dv->Buffer())); 15832 CHECK(ab->Equals(dv->Buffer()));
14376 } 15833 }
14377 15834
14378 15835
14379 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \ 15836 #define IS_ARRAY_BUFFER_VIEW_TEST(View) \
14380 THREADED_TEST(Is##View) { \ 15837 THREADED_TEST(Is##View) { \
14381 LocalContext env; \ 15838 LocalContext env; \
14382 v8::Isolate* isolate = env->GetIsolate(); \ 15839 v8::Isolate* isolate = env->GetIsolate(); \
14383 v8::HandleScope handle_scope(isolate); \ 15840 v8::HandleScope handle_scope(isolate); \
14384 \ 15841 \
14385 Handle<Value> result = CompileRun( \ 15842 Local<Value> result = CompileRun( \
14386 "var ab = new ArrayBuffer(128);" \ 15843 "var ab = new ArrayBuffer(128);" \
14387 "new " #View "(ab)"); \ 15844 "new " #View "(ab)"); \
14388 CHECK(result->IsArrayBufferView()); \ 15845 CHECK(result->IsArrayBufferView()); \
14389 CHECK(result->Is##View()); \ 15846 CHECK(result->Is##View()); \
14390 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \ 15847 CheckInternalFieldsAreZero<v8::ArrayBufferView>(result.As<v8::View>()); \
14391 } 15848 }
14392 15849
14393 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array) 15850 IS_ARRAY_BUFFER_VIEW_TEST(Uint8Array)
14394 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array) 15851 IS_ARRAY_BUFFER_VIEW_TEST(Int8Array)
14395 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array) 15852 IS_ARRAY_BUFFER_VIEW_TEST(Uint16Array)
14396 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array) 15853 IS_ARRAY_BUFFER_VIEW_TEST(Int16Array)
14397 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array) 15854 IS_ARRAY_BUFFER_VIEW_TEST(Uint32Array)
14398 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array) 15855 IS_ARRAY_BUFFER_VIEW_TEST(Int32Array)
14399 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array) 15856 IS_ARRAY_BUFFER_VIEW_TEST(Float32Array)
14400 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array) 15857 IS_ARRAY_BUFFER_VIEW_TEST(Float64Array)
14401 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray) 15858 IS_ARRAY_BUFFER_VIEW_TEST(Uint8ClampedArray)
14402 IS_ARRAY_BUFFER_VIEW_TEST(DataView) 15859 IS_ARRAY_BUFFER_VIEW_TEST(DataView)
14403 15860
14404 #undef IS_ARRAY_BUFFER_VIEW_TEST 15861 #undef IS_ARRAY_BUFFER_VIEW_TEST
14405 15862
14406 15863
14407 15864
14408 THREADED_TEST(ScriptContextDependence) { 15865 THREADED_TEST(ScriptContextDependence) {
14409 LocalContext c1; 15866 LocalContext c1;
14410 v8::HandleScope scope(c1->GetIsolate()); 15867 v8::HandleScope scope(c1->GetIsolate());
14411 const char *source = "foo"; 15868 const char *source = "foo";
14412 v8::Handle<v8::Script> dep = v8_compile(source); 15869 v8::Local<v8::Script> dep = v8_compile(source);
14413 v8::ScriptCompiler::Source script_source(v8::String::NewFromUtf8( 15870 v8::ScriptCompiler::Source script_source(
14414 c1->GetIsolate(), source)); 15871 v8::String::NewFromUtf8(c1->GetIsolate(), source,
14415 v8::Handle<v8::UnboundScript> indep = 15872 v8::NewStringType::kNormal)
15873 .ToLocalChecked());
15874 v8::Local<v8::UnboundScript> indep =
14416 v8::ScriptCompiler::CompileUnbound(c1->GetIsolate(), &script_source); 15875 v8::ScriptCompiler::CompileUnbound(c1->GetIsolate(), &script_source);
14417 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo"), 15876 c1->Global()->Set(v8::String::NewFromUtf8(c1->GetIsolate(), "foo",
15877 v8::NewStringType::kNormal)
15878 .ToLocalChecked(),
14418 v8::Integer::New(c1->GetIsolate(), 100)); 15879 v8::Integer::New(c1->GetIsolate(), 100));
14419 CHECK_EQ(dep->Run()->Int32Value(), 100); 15880 CHECK_EQ(dep->Run()->Int32Value(c1.local()).FromJust(), 100);
14420 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 100); 15881 CHECK_EQ(
15882 indep->BindToCurrentContext()->Run()->Int32Value(c1.local()).FromJust(),
15883 100);
14421 LocalContext c2; 15884 LocalContext c2;
14422 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo"), 15885 c2->Global()->Set(v8::String::NewFromUtf8(c2->GetIsolate(), "foo",
15886 v8::NewStringType::kNormal)
15887 .ToLocalChecked(),
14423 v8::Integer::New(c2->GetIsolate(), 101)); 15888 v8::Integer::New(c2->GetIsolate(), 101));
14424 CHECK_EQ(dep->Run()->Int32Value(), 100); 15889 CHECK_EQ(dep->Run()->Int32Value(c2.local()).FromJust(), 100);
14425 CHECK_EQ(indep->BindToCurrentContext()->Run()->Int32Value(), 101); 15890 CHECK_EQ(
15891 indep->BindToCurrentContext()->Run()->Int32Value(c2.local()).FromJust(),
15892 101);
14426 } 15893 }
14427 15894
14428 15895
14429 THREADED_TEST(StackTrace) { 15896 THREADED_TEST(StackTrace) {
14430 LocalContext context; 15897 LocalContext context;
14431 v8::HandleScope scope(context->GetIsolate()); 15898 v8::HandleScope scope(context->GetIsolate());
14432 v8::TryCatch try_catch(context->GetIsolate()); 15899 v8::TryCatch try_catch(context->GetIsolate());
14433 const char *source = "function foo() { FAIL.FAIL; }; foo();"; 15900 const char *source = "function foo() { FAIL.FAIL; }; foo();";
14434 v8::Handle<v8::String> src = 15901 v8::Local<v8::String> src = v8_str(source);
14435 v8::String::NewFromUtf8(context->GetIsolate(), source); 15902 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)); 15903 v8::ScriptCompiler::Source script_source(src, v8::ScriptOrigin(origin));
14439 v8::ScriptCompiler::CompileUnbound(context->GetIsolate(), &script_source) 15904 v8::ScriptCompiler::CompileUnbound(context->GetIsolate(), &script_source)
14440 ->BindToCurrentContext() 15905 ->BindToCurrentContext()
14441 ->Run(); 15906 ->Run();
14442 CHECK(try_catch.HasCaught()); 15907 CHECK(try_catch.HasCaught());
14443 v8::String::Utf8Value stack(try_catch.StackTrace()); 15908 v8::String::Utf8Value stack(try_catch.StackTrace());
14444 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL); 15909 CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
14445 } 15910 }
14446 15911
14447 15912
14448 // Checks that a StackFrame has certain expected values. 15913 // Checks that a StackFrame has certain expected values.
14449 void checkStackFrame(const char* expected_script_name, 15914 void checkStackFrame(const char* expected_script_name,
14450 const char* expected_func_name, int expected_line_number, 15915 const char* expected_func_name, int expected_line_number,
14451 int expected_column, bool is_eval, bool is_constructor, 15916 int expected_column, bool is_eval, bool is_constructor,
14452 v8::Handle<v8::StackFrame> frame) { 15917 v8::Local<v8::StackFrame> frame) {
14453 v8::HandleScope scope(CcTest::isolate()); 15918 v8::HandleScope scope(CcTest::isolate());
14454 v8::String::Utf8Value func_name(frame->GetFunctionName()); 15919 v8::String::Utf8Value func_name(frame->GetFunctionName());
14455 v8::String::Utf8Value script_name(frame->GetScriptName()); 15920 v8::String::Utf8Value script_name(frame->GetScriptName());
14456 if (*script_name == NULL) { 15921 if (*script_name == NULL) {
14457 // The situation where there is no associated script, like for evals. 15922 // The situation where there is no associated script, like for evals.
14458 CHECK(expected_script_name == NULL); 15923 CHECK(expected_script_name == NULL);
14459 } else { 15924 } else {
14460 CHECK(strstr(*script_name, expected_script_name) != NULL); 15925 CHECK(strstr(*script_name, expected_script_name) != NULL);
14461 } 15926 }
14462 CHECK(strstr(*func_name, expected_func_name) != NULL); 15927 CHECK(strstr(*func_name, expected_func_name) != NULL);
(...skipping 10 matching lines...) Expand all
14473 const int kOverviewTest = 1; 15938 const int kOverviewTest = 1;
14474 const int kDetailedTest = 2; 15939 const int kDetailedTest = 2;
14475 const int kFunctionName = 3; 15940 const int kFunctionName = 3;
14476 const int kDisplayName = 4; 15941 const int kDisplayName = 4;
14477 const int kFunctionNameAndDisplayName = 5; 15942 const int kFunctionNameAndDisplayName = 5;
14478 const int kDisplayNameIsNotString = 6; 15943 const int kDisplayNameIsNotString = 6;
14479 const int kFunctionNameIsNotString = 7; 15944 const int kFunctionNameIsNotString = 7;
14480 15945
14481 DCHECK(args.Length() == 1); 15946 DCHECK(args.Length() == 1);
14482 15947
14483 int testGroup = args[0]->Int32Value(); 15948 v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext();
15949 int testGroup = args[0]->Int32Value(context).FromJust();
14484 if (testGroup == kOverviewTest) { 15950 if (testGroup == kOverviewTest) {
14485 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 15951 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
14486 args.GetIsolate(), 10, v8::StackTrace::kOverview); 15952 args.GetIsolate(), 10, v8::StackTrace::kOverview);
14487 CHECK_EQ(4, stackTrace->GetFrameCount()); 15953 CHECK_EQ(4, stackTrace->GetFrameCount());
14488 checkStackFrame(origin, "bar", 2, 10, false, false, 15954 checkStackFrame(origin, "bar", 2, 10, false, false,
14489 stackTrace->GetFrame(0)); 15955 stackTrace->GetFrame(0));
14490 checkStackFrame(origin, "foo", 6, 3, false, false, 15956 checkStackFrame(origin, "foo", 6, 3, false, false,
14491 stackTrace->GetFrame(1)); 15957 stackTrace->GetFrame(1));
14492 // This is the source string inside the eval which has the call to foo. 15958 // This is the source string inside the eval which has the call to foo.
14493 checkStackFrame(NULL, "", 1, 1, false, false, stackTrace->GetFrame(2)); 15959 checkStackFrame(NULL, "", 1, 1, false, false, stackTrace->GetFrame(2));
14494 // The last frame is an anonymous function which has the initial eval call. 15960 // The last frame is an anonymous function which has the initial eval call.
14495 checkStackFrame(origin, "", 8, 7, false, false, stackTrace->GetFrame(3)); 15961 checkStackFrame(origin, "", 8, 7, false, false, stackTrace->GetFrame(3));
14496 15962
14497 CHECK(stackTrace->AsArray()->IsArray()); 15963 CHECK(stackTrace->AsArray()->IsArray());
14498 } else if (testGroup == kDetailedTest) { 15964 } else if (testGroup == kDetailedTest) {
14499 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 15965 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
14500 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 15966 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
14501 CHECK_EQ(4, stackTrace->GetFrameCount()); 15967 CHECK_EQ(4, stackTrace->GetFrameCount());
14502 checkStackFrame(origin, "bat", 4, 22, false, false, 15968 checkStackFrame(origin, "bat", 4, 22, false, false,
14503 stackTrace->GetFrame(0)); 15969 stackTrace->GetFrame(0));
14504 checkStackFrame(origin, "baz", 8, 3, false, true, 15970 checkStackFrame(origin, "baz", 8, 3, false, true,
14505 stackTrace->GetFrame(1)); 15971 stackTrace->GetFrame(1));
14506 bool is_eval = true; 15972 bool is_eval = true;
14507 // This is the source string inside the eval which has the call to baz. 15973 // 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)); 15974 checkStackFrame(NULL, "", 1, 1, is_eval, false, stackTrace->GetFrame(2));
14509 // The last frame is an anonymous function which has the initial eval call. 15975 // 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
14542 } 16008 }
14543 } 16009 }
14544 16010
14545 16011
14546 // Tests the C++ StackTrace API. 16012 // Tests the C++ StackTrace API.
14547 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 16013 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
14548 // THREADED_TEST(CaptureStackTrace) { 16014 // THREADED_TEST(CaptureStackTrace) {
14549 TEST(CaptureStackTrace) { 16015 TEST(CaptureStackTrace) {
14550 v8::Isolate* isolate = CcTest::isolate(); 16016 v8::Isolate* isolate = CcTest::isolate();
14551 v8::HandleScope scope(isolate); 16017 v8::HandleScope scope(isolate);
14552 v8::Handle<v8::String> origin = 16018 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); 16019 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
14555 templ->Set(v8_str("AnalyzeStackInNativeCode"), 16020 templ->Set(v8_str("AnalyzeStackInNativeCode"),
14556 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode)); 16021 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode));
14557 LocalContext context(0, templ); 16022 LocalContext context(0, templ);
14558 16023
14559 // Test getting OVERVIEW information. Should ignore information that is not 16024 // Test getting OVERVIEW information. Should ignore information that is not
14560 // script name, function name, line number, and column offset. 16025 // script name, function name, line number, and column offset.
14561 const char *overview_source = 16026 const char *overview_source =
14562 "function bar() {\n" 16027 "function bar() {\n"
14563 " var y; AnalyzeStackInNativeCode(1);\n" 16028 " var y; AnalyzeStackInNativeCode(1);\n"
14564 "}\n" 16029 "}\n"
14565 "function foo() {\n" 16030 "function foo() {\n"
14566 "\n" 16031 "\n"
14567 " bar();\n" 16032 " bar();\n"
14568 "}\n" 16033 "}\n"
14569 "var x;eval('new foo();');"; 16034 "var x;eval('new foo();');";
14570 v8::Handle<v8::String> overview_src = 16035 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, 16036 v8::ScriptCompiler::Source script_source(overview_src,
14573 v8::ScriptOrigin(origin)); 16037 v8::ScriptOrigin(origin));
14574 v8::Handle<Value> overview_result( 16038 v8::Local<Value> overview_result(
14575 v8::ScriptCompiler::CompileUnbound(isolate, &script_source) 16039 v8::ScriptCompiler::CompileUnbound(isolate, &script_source)
14576 ->BindToCurrentContext() 16040 ->BindToCurrentContext()
14577 ->Run()); 16041 ->Run());
14578 CHECK(!overview_result.IsEmpty()); 16042 CHECK(!overview_result.IsEmpty());
14579 CHECK(overview_result->IsObject()); 16043 CHECK(overview_result->IsObject());
14580 16044
14581 // Test getting DETAILED information. 16045 // Test getting DETAILED information.
14582 const char *detailed_source = 16046 const char *detailed_source =
14583 "function bat() {AnalyzeStackInNativeCode(2);\n" 16047 "function bat() {AnalyzeStackInNativeCode(2);\n"
14584 "}\n" 16048 "}\n"
14585 "\n" 16049 "\n"
14586 "function baz() {\n" 16050 "function baz() {\n"
14587 " bat();\n" 16051 " bat();\n"
14588 "}\n" 16052 "}\n"
14589 "eval('new baz();');"; 16053 "eval('new baz();');";
14590 v8::Handle<v8::String> detailed_src = 16054 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. 16055 // Make the script using a non-zero line and column offset.
14593 v8::Handle<v8::Integer> line_offset = v8::Integer::New(isolate, 3); 16056 v8::Local<v8::Integer> line_offset = v8::Integer::New(isolate, 3);
14594 v8::Handle<v8::Integer> column_offset = v8::Integer::New(isolate, 5); 16057 v8::Local<v8::Integer> column_offset = v8::Integer::New(isolate, 5);
14595 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 16058 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
14596 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin); 16059 v8::ScriptCompiler::Source script_source2(detailed_src, detailed_origin);
14597 v8::Handle<v8::UnboundScript> detailed_script( 16060 v8::Local<v8::UnboundScript> detailed_script(
14598 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2)); 16061 v8::ScriptCompiler::CompileUnbound(isolate, &script_source2));
14599 v8::Handle<Value> detailed_result( 16062 v8::Local<Value> detailed_result(
14600 detailed_script->BindToCurrentContext()->Run()); 16063 detailed_script->BindToCurrentContext()->Run());
14601 CHECK(!detailed_result.IsEmpty()); 16064 CHECK(!detailed_result.IsEmpty());
14602 CHECK(detailed_result->IsObject()); 16065 CHECK(detailed_result->IsObject());
14603 16066
14604 // Test using function.name and function.displayName in stack trace 16067 // Test using function.name and function.displayName in stack trace
14605 const char* function_name_source = 16068 const char* function_name_source =
14606 "function bar(function_name, display_name, testGroup) {\n" 16069 "function bar(function_name, display_name, testGroup) {\n"
14607 " var f = function() { AnalyzeStackInNativeCode(testGroup); };\n" 16070 " var f = function() { AnalyzeStackInNativeCode(testGroup); };\n"
14608 " if (function_name) {\n" 16071 " if (function_name) {\n"
14609 " Object.defineProperty(f, 'name', { value: function_name });\n" 16072 " Object.defineProperty(f, 'name', { value: function_name });\n"
(...skipping 14 matching lines...) Expand all
14624 v8::ScriptOrigin(origin)); 16087 v8::ScriptOrigin(origin));
14625 v8::Handle<Value> function_name_result( 16088 v8::Handle<Value> function_name_result(
14626 v8::ScriptCompiler::CompileUnbound(isolate, &script_source3) 16089 v8::ScriptCompiler::CompileUnbound(isolate, &script_source3)
14627 ->BindToCurrentContext() 16090 ->BindToCurrentContext()
14628 ->Run()); 16091 ->Run());
14629 CHECK(!function_name_result.IsEmpty()); 16092 CHECK(!function_name_result.IsEmpty());
14630 } 16093 }
14631 16094
14632 16095
14633 static void StackTraceForUncaughtExceptionListener( 16096 static void StackTraceForUncaughtExceptionListener(
14634 v8::Handle<v8::Message> message, 16097 v8::Local<v8::Message> message, v8::Local<Value>) {
14635 v8::Handle<Value>) {
14636 report_count++; 16098 report_count++;
14637 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16099 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14638 CHECK_EQ(2, stack_trace->GetFrameCount()); 16100 CHECK_EQ(2, stack_trace->GetFrameCount());
14639 checkStackFrame("origin", "foo", 2, 3, false, false, 16101 checkStackFrame("origin", "foo", 2, 3, false, false,
14640 stack_trace->GetFrame(0)); 16102 stack_trace->GetFrame(0));
14641 checkStackFrame("origin", "bar", 5, 3, false, false, 16103 checkStackFrame("origin", "bar", 5, 3, false, false,
14642 stack_trace->GetFrame(1)); 16104 stack_trace->GetFrame(1));
14643 } 16105 }
14644 16106
14645 16107
14646 TEST(CaptureStackTraceForUncaughtException) { 16108 TEST(CaptureStackTraceForUncaughtException) {
14647 report_count = 0; 16109 report_count = 0;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
14712 " 'isConstructor'];\n" 16174 " 'isConstructor'];\n"
14713 "for (var i = 0; i < setters.length; i++) {\n" 16175 "for (var i = 0; i < setters.length; i++) {\n"
14714 " var prop = setters[i];\n" 16176 " var prop = setters[i];\n"
14715 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n" 16177 " Object.prototype.__defineSetter__(prop, function() { throw prop; });\n"
14716 "}\n"); 16178 "}\n");
14717 CompileRun("throw 'exception';"); 16179 CompileRun("throw 'exception';");
14718 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16180 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14719 } 16181 }
14720 16182
14721 16183
14722 static void StackTraceFunctionNameListener(v8::Handle<v8::Message> message, 16184 static void StackTraceFunctionNameListener(v8::Local<v8::Message> message,
14723 v8::Handle<Value>) { 16185 v8::Local<Value>) {
14724 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16186 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14725 CHECK_EQ(5, stack_trace->GetFrameCount()); 16187 CHECK_EQ(5, stack_trace->GetFrameCount());
14726 checkStackFrame("origin", "foo:0", 4, 7, false, false, 16188 checkStackFrame("origin", "foo:0", 4, 7, false, false,
14727 stack_trace->GetFrame(0)); 16189 stack_trace->GetFrame(0));
14728 checkStackFrame("origin", "foo:1", 5, 27, false, false, 16190 checkStackFrame("origin", "foo:1", 5, 27, false, false,
14729 stack_trace->GetFrame(1)); 16191 stack_trace->GetFrame(1));
14730 checkStackFrame("origin", "foo", 5, 27, false, false, 16192 checkStackFrame("origin", "foo", 5, 27, false, false,
14731 stack_trace->GetFrame(2)); 16193 stack_trace->GetFrame(2));
14732 checkStackFrame("origin", "foo", 5, 27, false, false, 16194 checkStackFrame("origin", "foo", 5, 27, false, false,
14733 stack_trace->GetFrame(3)); 16195 stack_trace->GetFrame(3));
14734 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(4)); 16196 checkStackFrame("origin", "", 1, 14, false, false, stack_trace->GetFrame(4));
(...skipping 25 matching lines...) Expand all
14760 "origin"); 16222 "origin");
14761 16223
14762 v8::V8::AddMessageListener(StackTraceFunctionNameListener); 16224 v8::V8::AddMessageListener(StackTraceFunctionNameListener);
14763 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 16225 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14764 CompileRunWithOrigin("gen('foo', 3)();", "origin"); 16226 CompileRunWithOrigin("gen('foo', 3)();", "origin");
14765 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16227 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14766 v8::V8::RemoveMessageListeners(StackTraceFunctionNameListener); 16228 v8::V8::RemoveMessageListeners(StackTraceFunctionNameListener);
14767 } 16229 }
14768 16230
14769 16231
14770 static void RethrowStackTraceHandler(v8::Handle<v8::Message> message, 16232 static void RethrowStackTraceHandler(v8::Local<v8::Message> message,
14771 v8::Handle<v8::Value> data) { 16233 v8::Local<v8::Value> data) {
14772 // Use the frame where JavaScript is called from. 16234 // Use the frame where JavaScript is called from.
14773 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16235 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14774 CHECK(!stack_trace.IsEmpty()); 16236 CHECK(!stack_trace.IsEmpty());
14775 int frame_count = stack_trace->GetFrameCount(); 16237 int frame_count = stack_trace->GetFrameCount();
14776 CHECK_EQ(3, frame_count); 16238 CHECK_EQ(3, frame_count);
14777 int line_number[] = {1, 2, 5}; 16239 int line_number[] = {1, 2, 5};
14778 for (int i = 0; i < frame_count; i++) { 16240 for (int i = 0; i < frame_count; i++) {
14779 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 16241 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14780 } 16242 }
14781 } 16243 }
14782 16244
14783 16245
(...skipping 20 matching lines...) Expand all
14804 " } \n" 16266 " } \n"
14805 "} \n"; 16267 "} \n";
14806 v8::V8::AddMessageListener(RethrowStackTraceHandler); 16268 v8::V8::AddMessageListener(RethrowStackTraceHandler);
14807 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 16269 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14808 CompileRun(source); 16270 CompileRun(source);
14809 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16271 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14810 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler); 16272 v8::V8::RemoveMessageListeners(RethrowStackTraceHandler);
14811 } 16273 }
14812 16274
14813 16275
14814 static void RethrowPrimitiveStackTraceHandler(v8::Handle<v8::Message> message, 16276 static void RethrowPrimitiveStackTraceHandler(v8::Local<v8::Message> message,
14815 v8::Handle<v8::Value> data) { 16277 v8::Local<v8::Value> data) {
14816 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16278 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14817 CHECK(!stack_trace.IsEmpty()); 16279 CHECK(!stack_trace.IsEmpty());
14818 int frame_count = stack_trace->GetFrameCount(); 16280 int frame_count = stack_trace->GetFrameCount();
14819 CHECK_EQ(2, frame_count); 16281 CHECK_EQ(2, frame_count);
14820 int line_number[] = {3, 7}; 16282 int line_number[] = {3, 7};
14821 for (int i = 0; i < frame_count; i++) { 16283 for (int i = 0; i < frame_count; i++) {
14822 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber()); 16284 CHECK_EQ(line_number[i], stack_trace->GetFrame(i)->GetLineNumber());
14823 } 16285 }
14824 } 16286 }
14825 16287
14826 16288
(...skipping 13 matching lines...) Expand all
14840 " t(e1) \n" 16302 " t(e1) \n"
14841 "} \n"; 16303 "} \n";
14842 v8::V8::AddMessageListener(RethrowPrimitiveStackTraceHandler); 16304 v8::V8::AddMessageListener(RethrowPrimitiveStackTraceHandler);
14843 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 16305 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14844 CompileRun(source); 16306 CompileRun(source);
14845 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16307 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14846 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler); 16308 v8::V8::RemoveMessageListeners(RethrowPrimitiveStackTraceHandler);
14847 } 16309 }
14848 16310
14849 16311
14850 static void RethrowExistingStackTraceHandler(v8::Handle<v8::Message> message, 16312 static void RethrowExistingStackTraceHandler(v8::Local<v8::Message> message,
14851 v8::Handle<v8::Value> data) { 16313 v8::Local<v8::Value> data) {
14852 // Use the frame where JavaScript is called from. 16314 // Use the frame where JavaScript is called from.
14853 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16315 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14854 CHECK(!stack_trace.IsEmpty()); 16316 CHECK(!stack_trace.IsEmpty());
14855 CHECK_EQ(1, stack_trace->GetFrameCount()); 16317 CHECK_EQ(1, stack_trace->GetFrameCount());
14856 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber()); 16318 CHECK_EQ(1, stack_trace->GetFrame(0)->GetLineNumber());
14857 } 16319 }
14858 16320
14859 16321
14860 // Test that the stack trace is captured when the error object is created and 16322 // Test that the stack trace is captured when the error object is created and
14861 // not where it is thrown. 16323 // not where it is thrown.
14862 TEST(RethrowExistingStackTrace) { 16324 TEST(RethrowExistingStackTrace) {
14863 LocalContext env; 16325 LocalContext env;
14864 v8::HandleScope scope(env->GetIsolate()); 16326 v8::HandleScope scope(env->GetIsolate());
14865 const char* source = 16327 const char* source =
14866 "var e = new Error(); \n" 16328 "var e = new Error(); \n"
14867 "throw e; \n"; 16329 "throw e; \n";
14868 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler); 16330 v8::V8::AddMessageListener(RethrowExistingStackTraceHandler);
14869 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); 16331 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
14870 CompileRun(source); 16332 CompileRun(source);
14871 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false); 16333 v8::V8::SetCaptureStackTraceForUncaughtExceptions(false);
14872 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler); 16334 v8::V8::RemoveMessageListeners(RethrowExistingStackTraceHandler);
14873 } 16335 }
14874 16336
14875 16337
14876 static void RethrowBogusErrorStackTraceHandler(v8::Handle<v8::Message> message, 16338 static void RethrowBogusErrorStackTraceHandler(v8::Local<v8::Message> message,
14877 v8::Handle<v8::Value> data) { 16339 v8::Local<v8::Value> data) {
14878 // Use the frame where JavaScript is called from. 16340 // Use the frame where JavaScript is called from.
14879 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16341 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14880 CHECK(!stack_trace.IsEmpty()); 16342 CHECK(!stack_trace.IsEmpty());
14881 CHECK_EQ(1, stack_trace->GetFrameCount()); 16343 CHECK_EQ(1, stack_trace->GetFrameCount());
14882 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber()); 16344 CHECK_EQ(2, stack_trace->GetFrame(0)->GetLineNumber());
14883 } 16345 }
14884 16346
14885 16347
14886 // Test that the stack trace is captured where the bogus Error object is thrown. 16348 // Test that the stack trace is captured where the bogus Error object is thrown.
14887 TEST(RethrowBogusErrorStackTrace) { 16349 TEST(RethrowBogusErrorStackTrace) {
14888 LocalContext env; 16350 LocalContext env;
14889 v8::HandleScope scope(env->GetIsolate()); 16351 v8::HandleScope scope(env->GetIsolate());
(...skipping 15 matching lines...) Expand all
14905 int promise_reject_msg_column_number = -1; 16367 int promise_reject_msg_column_number = -1;
14906 int promise_reject_line_number = -1; 16368 int promise_reject_line_number = -1;
14907 int promise_reject_column_number = -1; 16369 int promise_reject_column_number = -1;
14908 int promise_reject_frame_count = -1; 16370 int promise_reject_frame_count = -1;
14909 16371
14910 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) { 16372 void PromiseRejectCallback(v8::PromiseRejectMessage reject_message) {
14911 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) { 16373 if (reject_message.GetEvent() == v8::kPromiseRejectWithNoHandler) {
14912 promise_reject_counter++; 16374 promise_reject_counter++;
14913 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise()); 16375 CcTest::global()->Set(v8_str("rejected"), reject_message.GetPromise());
14914 CcTest::global()->Set(v8_str("value"), reject_message.GetValue()); 16376 CcTest::global()->Set(v8_str("value"), reject_message.GetValue());
14915 v8::Handle<v8::Message> message = 16377 v8::Local<v8::Message> message =
14916 v8::Exception::CreateMessage(reject_message.GetValue()); 16378 v8::Exception::CreateMessage(reject_message.GetValue());
14917 v8::Handle<v8::StackTrace> stack_trace = message->GetStackTrace(); 16379 v8::Local<v8::StackTrace> stack_trace = message->GetStackTrace();
14918 16380
14919 promise_reject_msg_line_number = message->GetLineNumber(); 16381 promise_reject_msg_line_number = message->GetLineNumber();
14920 promise_reject_msg_column_number = message->GetStartColumn() + 1; 16382 promise_reject_msg_column_number = message->GetStartColumn() + 1;
14921 16383
14922 if (!stack_trace.IsEmpty()) { 16384 if (!stack_trace.IsEmpty()) {
14923 promise_reject_frame_count = stack_trace->GetFrameCount(); 16385 promise_reject_frame_count = stack_trace->GetFrameCount();
14924 if (promise_reject_frame_count > 0) { 16386 if (promise_reject_frame_count > 0) {
14925 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro"))); 16387 CHECK(stack_trace->GetFrame(0)->GetScriptName()->Equals(v8_str("pro")));
14926 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber(); 16388 promise_reject_line_number = stack_trace->GetFrame(0)->GetLineNumber();
14927 promise_reject_column_number = stack_trace->GetFrame(0)->GetColumn(); 16389 promise_reject_column_number = stack_trace->GetFrame(0)->GetColumn();
14928 } else { 16390 } else {
14929 promise_reject_line_number = -1; 16391 promise_reject_line_number = -1;
14930 promise_reject_column_number = -1; 16392 promise_reject_column_number = -1;
14931 } 16393 }
14932 } 16394 }
14933 } else { 16395 } else {
14934 promise_revoke_counter++; 16396 promise_revoke_counter++;
14935 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise()); 16397 CcTest::global()->Set(v8_str("revoked"), reject_message.GetPromise());
14936 CHECK(reject_message.GetValue().IsEmpty()); 16398 CHECK(reject_message.GetValue().IsEmpty());
14937 } 16399 }
14938 } 16400 }
14939 16401
14940 16402
14941 v8::Handle<v8::Promise> GetPromise(const char* name) { 16403 v8::Local<v8::Promise> GetPromise(const char* name) {
14942 return v8::Handle<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name))); 16404 return v8::Local<v8::Promise>::Cast(CcTest::global()->Get(v8_str(name)));
14943 } 16405 }
14944 16406
14945 16407
14946 v8::Handle<v8::Value> RejectValue() { 16408 v8::Local<v8::Value> RejectValue() {
14947 return CcTest::global()->Get(v8_str("value")); 16409 return CcTest::global()->Get(v8_str("value"));
14948 } 16410 }
14949 16411
14950 16412
14951 void ResetPromiseStates() { 16413 void ResetPromiseStates() {
14952 promise_reject_counter = 0; 16414 promise_reject_counter = 0;
14953 promise_revoke_counter = 0; 16415 promise_revoke_counter = 0;
14954 promise_reject_msg_line_number = -1; 16416 promise_reject_msg_line_number = -1;
14955 promise_reject_msg_column_number = -1; 16417 promise_reject_msg_column_number = -1;
14956 promise_reject_line_number = -1; 16418 promise_reject_line_number = -1;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
15275 CHECK_EQ(5, promise_reject_line_number); 16737 CHECK_EQ(5, promise_reject_line_number);
15276 CHECK_EQ(10, promise_reject_column_number); 16738 CHECK_EQ(10, promise_reject_column_number);
15277 CHECK_EQ(2, promise_reject_msg_line_number); 16739 CHECK_EQ(2, promise_reject_msg_line_number);
15278 CHECK_EQ(7, promise_reject_msg_column_number); 16740 CHECK_EQ(7, promise_reject_msg_column_number);
15279 } 16741 }
15280 16742
15281 16743
15282 void AnalyzeStackOfEvalWithSourceURL( 16744 void AnalyzeStackOfEvalWithSourceURL(
15283 const v8::FunctionCallbackInfo<v8::Value>& args) { 16745 const v8::FunctionCallbackInfo<v8::Value>& args) {
15284 v8::HandleScope scope(args.GetIsolate()); 16746 v8::HandleScope scope(args.GetIsolate());
15285 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 16747 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
15286 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 16748 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
15287 CHECK_EQ(5, stackTrace->GetFrameCount()); 16749 CHECK_EQ(5, stackTrace->GetFrameCount());
15288 v8::Handle<v8::String> url = v8_str("eval_url"); 16750 v8::Local<v8::String> url = v8_str("eval_url");
15289 for (int i = 0; i < 3; i++) { 16751 for (int i = 0; i < 3; i++) {
15290 v8::Handle<v8::String> name = 16752 v8::Local<v8::String> name =
15291 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16753 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15292 CHECK(!name.IsEmpty()); 16754 CHECK(!name.IsEmpty());
15293 CHECK(url->Equals(name)); 16755 CHECK(url->Equals(name));
15294 } 16756 }
15295 } 16757 }
15296 16758
15297 16759
15298 TEST(SourceURLInStackTrace) { 16760 TEST(SourceURLInStackTrace) {
15299 v8::Isolate* isolate = CcTest::isolate(); 16761 v8::Isolate* isolate = CcTest::isolate();
15300 v8::HandleScope scope(isolate); 16762 v8::HandleScope scope(isolate);
(...skipping 22 matching lines...) Expand all
15323 i::SNPrintF(code, source, "//@ sourceURL=eval_url"); 16785 i::SNPrintF(code, source, "//@ sourceURL=eval_url");
15324 CHECK(CompileRun(code.start())->IsUndefined()); 16786 CHECK(CompileRun(code.start())->IsUndefined());
15325 } 16787 }
15326 16788
15327 16789
15328 static int scriptIdInStack[2]; 16790 static int scriptIdInStack[2];
15329 16791
15330 void AnalyzeScriptIdInStack( 16792 void AnalyzeScriptIdInStack(
15331 const v8::FunctionCallbackInfo<v8::Value>& args) { 16793 const v8::FunctionCallbackInfo<v8::Value>& args) {
15332 v8::HandleScope scope(args.GetIsolate()); 16794 v8::HandleScope scope(args.GetIsolate());
15333 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 16795 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
15334 args.GetIsolate(), 10, v8::StackTrace::kScriptId); 16796 args.GetIsolate(), 10, v8::StackTrace::kScriptId);
15335 CHECK_EQ(2, stackTrace->GetFrameCount()); 16797 CHECK_EQ(2, stackTrace->GetFrameCount());
15336 for (int i = 0; i < 2; i++) { 16798 for (int i = 0; i < 2; i++) {
15337 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); 16799 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
15338 } 16800 }
15339 } 16801 }
15340 16802
15341 16803
15342 TEST(ScriptIdInStackTrace) { 16804 TEST(ScriptIdInStackTrace) {
15343 v8::Isolate* isolate = CcTest::isolate(); 16805 v8::Isolate* isolate = CcTest::isolate();
15344 v8::HandleScope scope(isolate); 16806 v8::HandleScope scope(isolate);
15345 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 16807 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
15346 templ->Set(v8_str("AnalyzeScriptIdInStack"), 16808 templ->Set(v8_str("AnalyzeScriptIdInStack"),
15347 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack)); 16809 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack));
15348 LocalContext context(0, templ); 16810 LocalContext context(0, templ);
15349 16811
15350 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 16812 v8::Local<v8::String> scriptSource = v8_str(
15351 isolate, 16813 "function foo() {\n"
15352 "function foo() {\n" 16814 " AnalyzeScriptIdInStack();"
15353 " AnalyzeScriptIdInStack();" 16815 "}\n"
15354 "}\n" 16816 "foo();\n");
15355 "foo();\n");
15356 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test"); 16817 v8::Local<v8::Script> script = CompileWithOrigin(scriptSource, "test");
15357 script->Run(); 16818 script->Run();
15358 for (int i = 0; i < 2; i++) { 16819 for (int i = 0; i < 2; i++) {
15359 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); 16820 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
15360 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId()); 16821 CHECK_EQ(scriptIdInStack[i], script->GetUnboundScript()->GetId());
15361 } 16822 }
15362 } 16823 }
15363 16824
15364 16825
15365 void AnalyzeStackOfInlineScriptWithSourceURL( 16826 void AnalyzeStackOfInlineScriptWithSourceURL(
15366 const v8::FunctionCallbackInfo<v8::Value>& args) { 16827 const v8::FunctionCallbackInfo<v8::Value>& args) {
15367 v8::HandleScope scope(args.GetIsolate()); 16828 v8::HandleScope scope(args.GetIsolate());
15368 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 16829 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
15369 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 16830 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
15370 CHECK_EQ(4, stackTrace->GetFrameCount()); 16831 CHECK_EQ(4, stackTrace->GetFrameCount());
15371 v8::Handle<v8::String> url = v8_str("source_url"); 16832 v8::Local<v8::String> url = v8_str("source_url");
15372 for (int i = 0; i < 3; i++) { 16833 for (int i = 0; i < 3; i++) {
15373 v8::Handle<v8::String> name = 16834 v8::Local<v8::String> name =
15374 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16835 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15375 CHECK(!name.IsEmpty()); 16836 CHECK(!name.IsEmpty());
15376 CHECK(url->Equals(name)); 16837 CHECK(url->Equals(name));
15377 } 16838 }
15378 } 16839 }
15379 16840
15380 16841
15381 TEST(InlineScriptWithSourceURLInStackTrace) { 16842 TEST(InlineScriptWithSourceURLInStackTrace) {
15382 v8::Isolate* isolate = CcTest::isolate(); 16843 v8::Isolate* isolate = CcTest::isolate();
15383 v8::HandleScope scope(isolate); 16844 v8::HandleScope scope(isolate);
(...skipping 20 matching lines...) Expand all
15404 i::SNPrintF(code, source, "//# sourceURL=source_url"); 16865 i::SNPrintF(code, source, "//# sourceURL=source_url");
15405 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16866 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
15406 i::SNPrintF(code, source, "//@ sourceURL=source_url"); 16867 i::SNPrintF(code, source, "//@ sourceURL=source_url");
15407 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined()); 16868 CHECK(CompileRunWithOrigin(code.start(), "url", 0, 1)->IsUndefined());
15408 } 16869 }
15409 16870
15410 16871
15411 void AnalyzeStackOfDynamicScriptWithSourceURL( 16872 void AnalyzeStackOfDynamicScriptWithSourceURL(
15412 const v8::FunctionCallbackInfo<v8::Value>& args) { 16873 const v8::FunctionCallbackInfo<v8::Value>& args) {
15413 v8::HandleScope scope(args.GetIsolate()); 16874 v8::HandleScope scope(args.GetIsolate());
15414 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 16875 v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
15415 args.GetIsolate(), 10, v8::StackTrace::kDetailed); 16876 args.GetIsolate(), 10, v8::StackTrace::kDetailed);
15416 CHECK_EQ(4, stackTrace->GetFrameCount()); 16877 CHECK_EQ(4, stackTrace->GetFrameCount());
15417 v8::Handle<v8::String> url = v8_str("source_url"); 16878 v8::Local<v8::String> url = v8_str("source_url");
15418 for (int i = 0; i < 3; i++) { 16879 for (int i = 0; i < 3; i++) {
15419 v8::Handle<v8::String> name = 16880 v8::Local<v8::String> name =
15420 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 16881 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
15421 CHECK(!name.IsEmpty()); 16882 CHECK(!name.IsEmpty());
15422 CHECK(url->Equals(name)); 16883 CHECK(url->Equals(name));
15423 } 16884 }
15424 } 16885 }
15425 16886
15426 16887
15427 TEST(DynamicWithSourceURLInStackTrace) { 16888 TEST(DynamicWithSourceURLInStackTrace) {
15428 v8::Isolate* isolate = CcTest::isolate(); 16889 v8::Isolate* isolate = CcTest::isolate();
15429 v8::HandleScope scope(isolate); 16890 v8::HandleScope scope(isolate);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
15488 " eval(scriptContents);\n" 16949 " eval(scriptContents);\n"
15489 " foo(); }\n" 16950 " foo(); }\n"
15490 "outer();\n" 16951 "outer();\n"
15491 "//# sourceURL=outer_url"; 16952 "//# sourceURL=outer_url";
15492 16953
15493 v8::TryCatch try_catch(context->GetIsolate()); 16954 v8::TryCatch try_catch(context->GetIsolate());
15494 CompileRun(source); 16955 CompileRun(source);
15495 CHECK(try_catch.HasCaught()); 16956 CHECK(try_catch.HasCaught());
15496 16957
15497 Local<v8::Message> message = try_catch.Message(); 16958 Local<v8::Message> message = try_catch.Message();
15498 Handle<Value> sourceURL = 16959 Local<Value> sourceURL = message->GetScriptOrigin().ResourceName();
15499 message->GetScriptOrigin().ResourceName();
15500 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); 16960 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url"));
15501 } 16961 }
15502 16962
15503 16963
15504 TEST(RecursionWithSourceURLInMessageScriptResourceNameOrSourceURL) { 16964 TEST(RecursionWithSourceURLInMessageScriptResourceNameOrSourceURL) {
15505 LocalContext context; 16965 LocalContext context;
15506 v8::HandleScope scope(context->GetIsolate()); 16966 v8::HandleScope scope(context->GetIsolate());
15507 16967
15508 const char *source = 16968 const char *source =
15509 "function outer() {\n" 16969 "function outer() {\n"
15510 " var scriptContents = \"function boo(){ boo(); }\\\n" 16970 " var scriptContents = \"function boo(){ boo(); }\\\n"
15511 " //# sourceURL=source_url\";\n" 16971 " //# sourceURL=source_url\";\n"
15512 " eval(scriptContents);\n" 16972 " eval(scriptContents);\n"
15513 " boo(); }\n" 16973 " boo(); }\n"
15514 "outer();\n" 16974 "outer();\n"
15515 "//# sourceURL=outer_url"; 16975 "//# sourceURL=outer_url";
15516 16976
15517 v8::TryCatch try_catch(context->GetIsolate()); 16977 v8::TryCatch try_catch(context->GetIsolate());
15518 CompileRun(source); 16978 CompileRun(source);
15519 CHECK(try_catch.HasCaught()); 16979 CHECK(try_catch.HasCaught());
15520 16980
15521 Local<v8::Message> message = try_catch.Message(); 16981 Local<v8::Message> message = try_catch.Message();
15522 Handle<Value> sourceURL = 16982 Local<Value> sourceURL = message->GetScriptOrigin().ResourceName();
15523 message->GetScriptOrigin().ResourceName();
15524 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url")); 16983 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(sourceURL), "source_url"));
15525 } 16984 }
15526 16985
15527 16986
15528 static void CreateGarbageInOldSpace() { 16987 static void CreateGarbageInOldSpace() {
15529 i::Factory* factory = CcTest::i_isolate()->factory(); 16988 i::Factory* factory = CcTest::i_isolate()->factory();
15530 v8::HandleScope scope(CcTest::isolate()); 16989 v8::HandleScope scope(CcTest::isolate());
15531 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate()); 16990 i::AlwaysAllocateScope always_allocate(CcTest::i_isolate());
15532 for (int i = 0; i < 1000; i++) { 16991 for (int i = 0; i < 1000; i++) {
15533 factory->NewFixedArray(1000, i::TENURED); 16992 factory->NewFixedArray(1000, i::TENURED);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
15603 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room); 17062 uint32_t* set_limit = ComputeStackLimit(stack_breathing_room);
15604 17063
15605 // Set stack limit. 17064 // Set stack limit.
15606 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); 17065 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit));
15607 17066
15608 // Execute a script. 17067 // Execute a script.
15609 LocalContext env; 17068 LocalContext env;
15610 v8::HandleScope scope(env->GetIsolate()); 17069 v8::HandleScope scope(env->GetIsolate());
15611 Local<v8::FunctionTemplate> fun_templ = 17070 Local<v8::FunctionTemplate> fun_templ =
15612 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback); 17071 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback);
15613 Local<Function> fun = fun_templ->GetFunction(); 17072 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
15614 env->Global()->Set(v8_str("get_stack_limit"), fun); 17073 CHECK(env->Global()
17074 ->Set(env.local(), v8_str("get_stack_limit"), fun)
17075 .FromJust());
15615 CompileRun("get_stack_limit();"); 17076 CompileRun("get_stack_limit();");
15616 17077
15617 CHECK(stack_limit == set_limit); 17078 CHECK(stack_limit == set_limit);
15618 } 17079 }
15619 17080
15620 17081
15621 TEST(SetStackLimitInThread) { 17082 TEST(SetStackLimitInThread) {
15622 uint32_t* set_limit; 17083 uint32_t* set_limit;
15623 { 17084 {
15624 v8::Locker locker(CcTest::isolate()); 17085 v8::Locker locker(CcTest::isolate());
15625 set_limit = ComputeStackLimit(stack_breathing_room); 17086 set_limit = ComputeStackLimit(stack_breathing_room);
15626 17087
15627 // Set stack limit. 17088 // Set stack limit.
15628 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit)); 17089 CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit));
15629 17090
15630 // Execute a script. 17091 // Execute a script.
15631 v8::HandleScope scope(CcTest::isolate()); 17092 v8::HandleScope scope(CcTest::isolate());
15632 LocalContext env; 17093 LocalContext env;
15633 Local<v8::FunctionTemplate> fun_templ = 17094 Local<v8::FunctionTemplate> fun_templ =
15634 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback); 17095 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback);
15635 Local<Function> fun = fun_templ->GetFunction(); 17096 Local<Function> fun = fun_templ->GetFunction(env.local()).ToLocalChecked();
15636 env->Global()->Set(v8_str("get_stack_limit"), fun); 17097 CHECK(env->Global()
17098 ->Set(env.local(), v8_str("get_stack_limit"), fun)
17099 .FromJust());
15637 CompileRun("get_stack_limit();"); 17100 CompileRun("get_stack_limit();");
15638 17101
15639 CHECK(stack_limit == set_limit); 17102 CHECK(stack_limit == set_limit);
15640 } 17103 }
15641 { 17104 {
15642 v8::Locker locker(CcTest::isolate()); 17105 v8::Locker locker(CcTest::isolate());
15643 CHECK(stack_limit == set_limit); 17106 CHECK(stack_limit == set_limit);
15644 } 17107 }
15645 } 17108 }
15646 17109
(...skipping 12 matching lines...) Expand all
15659 17122
15660 class VisitorImpl : public v8::ExternalResourceVisitor { 17123 class VisitorImpl : public v8::ExternalResourceVisitor {
15661 public: 17124 public:
15662 explicit VisitorImpl(TestResource** resource) { 17125 explicit VisitorImpl(TestResource** resource) {
15663 for (int i = 0; i < 4; i++) { 17126 for (int i = 0; i < 4; i++) {
15664 resource_[i] = resource[i]; 17127 resource_[i] = resource[i];
15665 found_resource_[i] = false; 17128 found_resource_[i] = false;
15666 } 17129 }
15667 } 17130 }
15668 virtual ~VisitorImpl() {} 17131 virtual ~VisitorImpl() {}
15669 virtual void VisitExternalString(v8::Handle<v8::String> string) { 17132 virtual void VisitExternalString(v8::Local<v8::String> string) {
15670 if (!string->IsExternal()) { 17133 if (!string->IsExternal()) {
15671 CHECK(string->IsExternalOneByte()); 17134 CHECK(string->IsExternalOneByte());
15672 return; 17135 return;
15673 } 17136 }
15674 v8::String::ExternalStringResource* resource = 17137 v8::String::ExternalStringResource* resource =
15675 string->GetExternalStringResource(); 17138 string->GetExternalStringResource();
15676 CHECK(resource); 17139 CHECK(resource);
15677 for (int i = 0; i < 4; i++) { 17140 for (int i = 0; i < 4; i++) {
15678 if (resource_[i] == resource) { 17141 if (resource_[i] == resource) {
15679 CHECK(!found_resource_[i]); 17142 CHECK(!found_resource_[i]);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
15746 TestResource* resource[4]; 17209 TestResource* resource[4];
15747 resource[0] = new TestResource(two_byte_string); 17210 resource[0] = new TestResource(two_byte_string);
15748 v8::Local<v8::String> string0 = 17211 v8::Local<v8::String> string0 =
15749 v8::String::NewExternal(env->GetIsolate(), resource[0]); 17212 v8::String::NewExternal(env->GetIsolate(), resource[0]);
15750 resource[1] = new TestResource(two_byte_string, NULL, false); 17213 resource[1] = new TestResource(two_byte_string, NULL, false);
15751 v8::Local<v8::String> string1 = 17214 v8::Local<v8::String> string1 =
15752 v8::String::NewExternal(env->GetIsolate(), resource[1]); 17215 v8::String::NewExternal(env->GetIsolate(), resource[1]);
15753 17216
15754 // Externalized symbol. 17217 // Externalized symbol.
15755 resource[2] = new TestResource(two_byte_string, NULL, false); 17218 resource[2] = new TestResource(two_byte_string, NULL, false);
15756 v8::Local<v8::String> string2 = v8::String::NewFromUtf8( 17219 v8::Local<v8::String> string2 =
15757 env->GetIsolate(), string, v8::String::kInternalizedString); 17220 v8::String::NewFromUtf8(env->GetIsolate(), string,
17221 v8::NewStringType::kInternalized)
17222 .ToLocalChecked();
15758 CHECK(string2->MakeExternal(resource[2])); 17223 CHECK(string2->MakeExternal(resource[2]));
15759 17224
15760 // Symbolized External. 17225 // Symbolized External.
15761 resource[3] = new TestResource(AsciiToTwoByteString("Some other string")); 17226 resource[3] = new TestResource(AsciiToTwoByteString("Some other string"));
15762 v8::Local<v8::String> string3 = 17227 v8::Local<v8::String> string3 =
15763 v8::String::NewExternal(env->GetIsolate(), resource[3]); 17228 v8::String::NewExternal(env->GetIsolate(), resource[3]);
15764 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string. 17229 CcTest::heap()->CollectAllAvailableGarbage(); // Tenure string.
15765 // Turn into a symbol. 17230 // Turn into a symbol.
15766 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3); 17231 i::Handle<i::String> string3_i = v8::Utils::OpenHandle(*string3);
15767 CHECK(!CcTest::i_isolate()->factory()->InternalizeString( 17232 CHECK(!CcTest::i_isolate()->factory()->InternalizeString(
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
15923 -infinity, 17388 -infinity,
15924 -qnan, 17389 -qnan,
15925 -snan 17390 -snan
15926 }; 17391 };
15927 int num_test_values = 20; 17392 int num_test_values = 20;
15928 17393
15929 for (int i = 0; i < num_test_values; i++) { 17394 for (int i = 0; i < num_test_values; i++) {
15930 double test_value = test_values[i]; 17395 double test_value = test_values[i];
15931 17396
15932 // Check that Number::New preserves non-NaNs and quiets SNaNs. 17397 // Check that Number::New preserves non-NaNs and quiets SNaNs.
15933 v8::Handle<v8::Value> number = v8::Number::New(isolate, test_value); 17398 v8::Local<v8::Value> number = v8::Number::New(isolate, test_value);
15934 double stored_number = number->NumberValue(); 17399 double stored_number = number->NumberValue();
15935 if (!std::isnan(test_value)) { 17400 if (!std::isnan(test_value)) {
15936 CHECK_EQ(test_value, stored_number); 17401 CHECK_EQ(test_value, stored_number);
15937 } else { 17402 } else {
15938 uint64_t stored_bits = DoubleToBits(stored_number); 17403 uint64_t stored_bits = DoubleToBits(stored_number);
15939 // Check if quiet nan (bits 51..62 all set). 17404 // Check if quiet nan (bits 51..62 all set).
15940 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ 17405 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \
15941 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ 17406 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \
15942 !defined(USE_SIMULATOR) 17407 !defined(USE_SIMULATOR)
15943 // Most significant fraction bit for quiet nan is set to 0 17408 // Most significant fraction bit for quiet nan is set to 0
15944 // on MIPS architecture. Allowed by IEEE-754. 17409 // on MIPS architecture. Allowed by IEEE-754.
15945 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 17410 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
15946 #else 17411 #else
15947 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 17412 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
15948 #endif 17413 #endif
15949 } 17414 }
15950 17415
15951 // Check that Date::New preserves non-NaNs in the date range and 17416 // Check that Date::New preserves non-NaNs in the date range and
15952 // quiets SNaNs. 17417 // quiets SNaNs.
15953 v8::Handle<v8::Value> date = 17418 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); 17419 double expected_stored_date = DoubleToDateTime(test_value);
15956 double stored_date = date->NumberValue(); 17420 double stored_date = date->NumberValue();
15957 if (!std::isnan(expected_stored_date)) { 17421 if (!std::isnan(expected_stored_date)) {
15958 CHECK_EQ(expected_stored_date, stored_date); 17422 CHECK_EQ(expected_stored_date, stored_date);
15959 } else { 17423 } else {
15960 uint64_t stored_bits = DoubleToBits(stored_date); 17424 uint64_t stored_bits = DoubleToBits(stored_date);
15961 // Check if quiet nan (bits 51..62 all set). 17425 // Check if quiet nan (bits 51..62 all set).
15962 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \ 17426 #if (defined(V8_TARGET_ARCH_MIPS) || defined(V8_TARGET_ARCH_MIPS64)) && \
15963 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \ 17427 !defined(_MIPS_ARCH_MIPS64R6) && !defined(_MIPS_ARCH_MIPS32R6) && \
15964 !defined(USE_SIMULATOR) 17428 !defined(USE_SIMULATOR)
15965 // Most significant fraction bit for quiet nan is set to 0 17429 // Most significant fraction bit for quiet nan is set to 0
15966 // on MIPS architecture. Allowed by IEEE-754. 17430 // on MIPS architecture. Allowed by IEEE-754.
15967 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff)); 17431 CHECK_EQ(0xffe, static_cast<int>((stored_bits >> 51) & 0xfff));
15968 #else 17432 #else
15969 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff)); 17433 CHECK_EQ(0xfff, static_cast<int>((stored_bits >> 51) & 0xfff));
15970 #endif 17434 #endif
15971 } 17435 }
15972 } 17436 }
15973 } 17437 }
15974 17438
15975 17439
15976 static void SpaghettiIncident( 17440 static void SpaghettiIncident(
15977 const v8::FunctionCallbackInfo<v8::Value>& args) { 17441 const v8::FunctionCallbackInfo<v8::Value>& args) {
15978 v8::HandleScope scope(args.GetIsolate()); 17442 v8::HandleScope scope(args.GetIsolate());
15979 v8::TryCatch tc(args.GetIsolate()); 17443 v8::TryCatch tc(args.GetIsolate());
15980 v8::Handle<v8::String> str(args[0]->ToString(args.GetIsolate())); 17444 v8::Local<v8::String> str(args[0]->ToString(args.GetIsolate()));
15981 USE(str); 17445 USE(str);
15982 if (tc.HasCaught()) 17446 if (tc.HasCaught())
15983 tc.ReThrow(); 17447 tc.ReThrow();
15984 } 17448 }
15985 17449
15986 17450
15987 // Test that an exception can be propagated down through a spaghetti 17451 // Test that an exception can be propagated down through a spaghetti
15988 // stack using ReThrow. 17452 // stack using ReThrow.
15989 THREADED_TEST(SpaghettiStackReThrow) { 17453 THREADED_TEST(SpaghettiStackReThrow) {
15990 v8::Isolate* isolate = CcTest::isolate(); 17454 v8::Isolate* isolate = CcTest::isolate();
15991 v8::HandleScope scope(isolate); 17455 v8::HandleScope scope(isolate);
15992 LocalContext context; 17456 LocalContext context;
15993 context->Global()->Set( 17457 context->Global()->Set(v8_str("s"),
15994 v8::String::NewFromUtf8(isolate, "s"), 17458 v8::FunctionTemplate::New(isolate, SpaghettiIncident)
15995 v8::FunctionTemplate::New(isolate, SpaghettiIncident)->GetFunction()); 17459 ->GetFunction(context.local())
17460 .ToLocalChecked());
15996 v8::TryCatch try_catch(isolate); 17461 v8::TryCatch try_catch(isolate);
15997 CompileRun( 17462 CompileRun(
15998 "var i = 0;" 17463 "var i = 0;"
15999 "var o = {" 17464 "var o = {"
16000 " toString: function () {" 17465 " toString: function () {"
16001 " if (i == 10) {" 17466 " if (i == 10) {"
16002 " throw 'Hey!';" 17467 " throw 'Hey!';"
16003 " } else {" 17468 " } else {"
16004 " i++;" 17469 " i++;"
16005 " return s(o);" 17470 " return s(o);"
(...skipping 20 matching lines...) Expand all
16026 other_context = Context::New(isolate); 17491 other_context = Context::New(isolate);
16027 17492
16028 // Context-dependent context data creates reference from the compilation 17493 // Context-dependent context data creates reference from the compilation
16029 // cache to the global object. 17494 // cache to the global object.
16030 const char* source_simple = "1"; 17495 const char* source_simple = "1";
16031 { 17496 {
16032 v8::HandleScope scope(isolate); 17497 v8::HandleScope scope(isolate);
16033 v8::Local<Context> context = Context::New(isolate); 17498 v8::Local<Context> context = Context::New(isolate);
16034 17499
16035 context->Enter(); 17500 context->Enter();
16036 Local<v8::String> obj = v8::String::NewFromUtf8(isolate, ""); 17501 Local<v8::String> obj = v8_str("");
16037 context->SetEmbedderData(0, obj); 17502 context->SetEmbedderData(0, obj);
16038 CompileRun(source_simple); 17503 CompileRun(source_simple);
16039 context->Exit(); 17504 context->Exit();
16040 } 17505 }
16041 isolate->ContextDisposedNotification(); 17506 isolate->ContextDisposedNotification();
16042 for (gc_count = 1; gc_count < 10; gc_count++) { 17507 for (gc_count = 1; gc_count < 10; gc_count++) {
16043 other_context->Enter(); 17508 other_context->Enter();
16044 CompileRun(source_simple); 17509 CompileRun(source_simple);
16045 other_context->Exit(); 17510 other_context->Exit();
16046 CcTest::heap()->CollectAllGarbage(); 17511 CcTest::heap()->CollectAllGarbage();
(...skipping 28 matching lines...) Expand all
16075 // compilation cache to the global object. 17540 // compilation cache to the global object.
16076 const char* source_exception = "function f(){throw 1;} f()"; 17541 const char* source_exception = "function f(){throw 1;} f()";
16077 { 17542 {
16078 v8::HandleScope scope(isolate); 17543 v8::HandleScope scope(isolate);
16079 v8::Local<Context> context = Context::New(isolate); 17544 v8::Local<Context> context = Context::New(isolate);
16080 17545
16081 context->Enter(); 17546 context->Enter();
16082 v8::TryCatch try_catch(isolate); 17547 v8::TryCatch try_catch(isolate);
16083 CompileRun(source_exception); 17548 CompileRun(source_exception);
16084 CHECK(try_catch.HasCaught()); 17549 CHECK(try_catch.HasCaught());
16085 v8::Handle<v8::Message> message = try_catch.Message(); 17550 v8::Local<v8::Message> message = try_catch.Message();
16086 CHECK(!message.IsEmpty()); 17551 CHECK(!message.IsEmpty());
16087 CHECK_EQ(1, message->GetLineNumber()); 17552 CHECK_EQ(1, message->GetLineNumber());
16088 context->Exit(); 17553 context->Exit();
16089 } 17554 }
16090 isolate->ContextDisposedNotification(); 17555 isolate->ContextDisposedNotification();
16091 for (gc_count = 1; gc_count < 10; gc_count++) { 17556 for (gc_count = 1; gc_count < 10; gc_count++) {
16092 other_context->Enter(); 17557 other_context->Enter();
16093 CompileRun(source_exception); 17558 CompileRun(source_exception);
16094 other_context->Exit(); 17559 other_context->Exit();
16095 CcTest::heap()->CollectAllGarbage(); 17560 CcTest::heap()->CollectAllGarbage();
16096 if (GetGlobalObjectsCount() == 1) break; 17561 if (GetGlobalObjectsCount() == 1) break;
16097 } 17562 }
16098 CHECK_GE(2, gc_count); 17563 CHECK_GE(2, gc_count);
16099 CHECK_EQ(1, GetGlobalObjectsCount()); 17564 CHECK_EQ(1, GetGlobalObjectsCount());
16100 17565
16101 isolate->ContextDisposedNotification(); 17566 isolate->ContextDisposedNotification();
16102 } 17567 }
16103 17568
16104 17569
16105 THREADED_TEST(ScriptOrigin) { 17570 THREADED_TEST(ScriptOrigin) {
16106 LocalContext env; 17571 LocalContext env;
16107 v8::HandleScope scope(env->GetIsolate()); 17572 v8::HandleScope scope(env->GetIsolate());
16108 v8::ScriptOrigin origin = v8::ScriptOrigin( 17573 v8::ScriptOrigin origin = v8::ScriptOrigin(
16109 v8::String::NewFromUtf8(env->GetIsolate(), "test"), 17574 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()), 17575 v8::Integer::New(env->GetIsolate(), 1), v8::True(env->GetIsolate()),
16112 v8::Handle<v8::Integer>(), v8::True(env->GetIsolate()), 17576 v8::Local<v8::Integer>(), v8::True(env->GetIsolate()),
16113 v8::String::NewFromUtf8(env->GetIsolate(), "http://sourceMapUrl"), 17577 v8_str("http://sourceMapUrl"), v8::True(env->GetIsolate()));
16114 v8::True(env->GetIsolate())); 17578 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(); 17579 v8::Script::Compile(script, &origin)->Run();
16118 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17580 v8::Local<v8::Function> f =
16119 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 17581 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f")));
16120 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17582 v8::Local<v8::Function> g =
16121 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); 17583 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g")));
16122 17584
16123 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); 17585 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin();
16124 CHECK_EQ(0, strcmp("test", 17586 CHECK_EQ(0, strcmp("test",
16125 *v8::String::Utf8Value(script_origin_f.ResourceName()))); 17587 *v8::String::Utf8Value(script_origin_f.ResourceName())));
16126 CHECK_EQ(1, script_origin_f.ResourceLineOffset()->Int32Value()); 17588 CHECK_EQ(
17589 1,
17590 script_origin_f.ResourceLineOffset()->Int32Value(env.local()).FromJust());
16127 CHECK(script_origin_f.Options().IsSharedCrossOrigin()); 17591 CHECK(script_origin_f.Options().IsSharedCrossOrigin());
16128 CHECK(script_origin_f.Options().IsEmbedderDebugScript()); 17592 CHECK(script_origin_f.Options().IsEmbedderDebugScript());
16129 CHECK(script_origin_f.Options().IsOpaque()); 17593 CHECK(script_origin_f.Options().IsOpaque());
16130 printf("is name = %d\n", script_origin_f.SourceMapUrl()->IsUndefined()); 17594 printf("is name = %d\n", script_origin_f.SourceMapUrl()->IsUndefined());
16131 17595
16132 CHECK_EQ(0, strcmp("http://sourceMapUrl", 17596 CHECK_EQ(0, strcmp("http://sourceMapUrl",
16133 *v8::String::Utf8Value(script_origin_f.SourceMapUrl()))); 17597 *v8::String::Utf8Value(script_origin_f.SourceMapUrl())));
16134 17598
16135 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); 17599 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin();
16136 CHECK_EQ(0, strcmp("test", 17600 CHECK_EQ(0, strcmp("test",
16137 *v8::String::Utf8Value(script_origin_g.ResourceName()))); 17601 *v8::String::Utf8Value(script_origin_g.ResourceName())));
16138 CHECK_EQ(1, script_origin_g.ResourceLineOffset()->Int32Value()); 17602 CHECK_EQ(
17603 1,
17604 script_origin_g.ResourceLineOffset()->Int32Value(env.local()).FromJust());
16139 CHECK(script_origin_g.Options().IsSharedCrossOrigin()); 17605 CHECK(script_origin_g.Options().IsSharedCrossOrigin());
16140 CHECK(script_origin_g.Options().IsEmbedderDebugScript()); 17606 CHECK(script_origin_g.Options().IsEmbedderDebugScript());
16141 CHECK(script_origin_g.Options().IsOpaque()); 17607 CHECK(script_origin_g.Options().IsOpaque());
16142 CHECK_EQ(0, strcmp("http://sourceMapUrl", 17608 CHECK_EQ(0, strcmp("http://sourceMapUrl",
16143 *v8::String::Utf8Value(script_origin_g.SourceMapUrl()))); 17609 *v8::String::Utf8Value(script_origin_g.SourceMapUrl())));
16144 } 17610 }
16145 17611
16146 17612
16147 THREADED_TEST(FunctionGetInferredName) { 17613 THREADED_TEST(FunctionGetInferredName) {
16148 LocalContext env; 17614 LocalContext env;
16149 v8::HandleScope scope(env->GetIsolate()); 17615 v8::HandleScope scope(env->GetIsolate());
16150 v8::ScriptOrigin origin = 17616 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test"));
16151 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); 17617 v8::Local<v8::String> script =
16152 v8::Handle<v8::String> script = v8::String::NewFromUtf8( 17618 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(); 17619 v8::Script::Compile(script, &origin)->Run();
16156 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17620 v8::Local<v8::Function> f =
16157 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 17621 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f")));
16158 CHECK_EQ(0, 17622 CHECK_EQ(0,
16159 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName()))); 17623 strcmp("foo.bar.baz", *v8::String::Utf8Value(f->GetInferredName())));
16160 } 17624 }
16161 17625
16162 17626
16163 THREADED_TEST(FunctionGetDebugName) { 17627 THREADED_TEST(FunctionGetDebugName) {
16164 LocalContext env; 17628 LocalContext env;
16165 v8::HandleScope scope(env->GetIsolate()); 17629 v8::HandleScope scope(env->GetIsolate());
16166 const char* code = 17630 const char* code =
16167 "var error = false;" 17631 "var error = false;"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
16261 " throw new Error();" 17725 " throw new Error();"
16262 "});" 17726 "});"
16263 "function f() {};" 17727 "function f() {};"
16264 "f.displayName = { 'foo': 6, toString: function() {" 17728 "f.displayName = { 'foo': 6, toString: function() {"
16265 " error = true;" 17729 " error = true;"
16266 " return 'wrong_display_name';" 17730 " return 'wrong_display_name';"
16267 "}};" 17731 "}};"
16268 "var g = function() {" 17732 "var g = function() {"
16269 " arguments.callee.displayName = 'set_in_runtime';" 17733 " arguments.callee.displayName = 'set_in_runtime';"
16270 "}; g();"; 17734 "}; g();";
16271 v8::ScriptOrigin origin = 17735 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test"));
16272 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); 17736 v8::Script::Compile(v8_str(code), &origin)->Run();
16273 v8::Script::Compile(v8::String::NewFromUtf8(env->GetIsolate(), code), &origin) 17737 v8::Local<v8::Value> error = env->Global()->Get(v8_str("error"));
16274 ->Run(); 17738 v8::Local<v8::Function> a =
16275 v8::Local<v8::Value> error = 17739 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("a")));
16276 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "error")); 17740 v8::Local<v8::Function> b =
16277 v8::Local<v8::Function> a = v8::Local<v8::Function>::Cast( 17741 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("b")));
16278 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "a"))); 17742 v8::Local<v8::Function> c =
16279 v8::Local<v8::Function> b = v8::Local<v8::Function>::Cast( 17743 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("c")));
16280 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "b"))); 17744 v8::Local<v8::Function> d =
16281 v8::Local<v8::Function> c = v8::Local<v8::Function>::Cast( 17745 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("d")));
16282 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "c"))); 17746 v8::Local<v8::Function> e =
16283 v8::Local<v8::Function> d = v8::Local<v8::Function>::Cast( 17747 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("e")));
16284 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "d"))); 17748 v8::Local<v8::Function> f =
16285 v8::Local<v8::Function> e = v8::Local<v8::Function>::Cast( 17749 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f")));
16286 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "e"))); 17750 v8::Local<v8::Function> g =
16287 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17751 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()); 17752 CHECK_EQ(false, error->BooleanValue());
16292 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName()))); 17753 CHECK_EQ(0, strcmp("display_a", *v8::String::Utf8Value(a->GetDisplayName())));
16293 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName()))); 17754 CHECK_EQ(0, strcmp("display_b", *v8::String::Utf8Value(b->GetDisplayName())));
16294 CHECK(c->GetDisplayName()->IsUndefined()); 17755 CHECK(c->GetDisplayName()->IsUndefined());
16295 CHECK(d->GetDisplayName()->IsUndefined()); 17756 CHECK(d->GetDisplayName()->IsUndefined());
16296 CHECK(e->GetDisplayName()->IsUndefined()); 17757 CHECK(e->GetDisplayName()->IsUndefined());
16297 CHECK(f->GetDisplayName()->IsUndefined()); 17758 CHECK(f->GetDisplayName()->IsUndefined());
16298 CHECK_EQ( 17759 CHECK_EQ(
16299 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName()))); 17760 0, strcmp("set_in_runtime", *v8::String::Utf8Value(g->GetDisplayName())));
16300 } 17761 }
16301 17762
16302 17763
16303 THREADED_TEST(ScriptLineNumber) { 17764 THREADED_TEST(ScriptLineNumber) {
16304 LocalContext env; 17765 LocalContext env;
16305 v8::HandleScope scope(env->GetIsolate()); 17766 v8::HandleScope scope(env->GetIsolate());
16306 v8::ScriptOrigin origin = 17767 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test"));
16307 v8::ScriptOrigin(v8::String::NewFromUtf8(env->GetIsolate(), "test")); 17768 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(); 17769 v8::Script::Compile(script, &origin)->Run();
16311 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17770 v8::Local<v8::Function> f =
16312 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 17771 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f")));
16313 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17772 v8::Local<v8::Function> g =
16314 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); 17773 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g")));
16315 CHECK_EQ(0, f->GetScriptLineNumber()); 17774 CHECK_EQ(0, f->GetScriptLineNumber());
16316 CHECK_EQ(2, g->GetScriptLineNumber()); 17775 CHECK_EQ(2, g->GetScriptLineNumber());
16317 } 17776 }
16318 17777
16319 17778
16320 THREADED_TEST(ScriptColumnNumber) { 17779 THREADED_TEST(ScriptColumnNumber) {
16321 LocalContext env; 17780 LocalContext env;
16322 v8::Isolate* isolate = env->GetIsolate(); 17781 v8::Isolate* isolate = env->GetIsolate();
16323 v8::HandleScope scope(isolate); 17782 v8::HandleScope scope(isolate);
16324 v8::ScriptOrigin origin = 17783 v8::ScriptOrigin origin =
16325 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), 17784 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3),
16326 v8::Integer::New(isolate, 3),
16327 v8::Integer::New(isolate, 2)); 17785 v8::Integer::New(isolate, 2));
16328 v8::Handle<v8::String> script = v8::String::NewFromUtf8( 17786 v8::Local<v8::String> script =
16329 isolate, "function foo() {}\n\n function bar() {}"); 17787 v8_str("function foo() {}\n\n function bar() {}");
16330 v8::Script::Compile(script, &origin)->Run(); 17788 v8::Script::Compile(script, &origin)->Run();
16331 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17789 v8::Local<v8::Function> foo =
16332 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); 17790 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo")));
16333 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17791 v8::Local<v8::Function> bar =
16334 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); 17792 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar")));
16335 CHECK_EQ(14, foo->GetScriptColumnNumber()); 17793 CHECK_EQ(14, foo->GetScriptColumnNumber());
16336 CHECK_EQ(17, bar->GetScriptColumnNumber()); 17794 CHECK_EQ(17, bar->GetScriptColumnNumber());
16337 } 17795 }
16338 17796
16339 17797
16340 THREADED_TEST(FunctionIsBuiltin) { 17798 THREADED_TEST(FunctionIsBuiltin) {
16341 LocalContext env; 17799 LocalContext env;
16342 v8::Isolate* isolate = env->GetIsolate(); 17800 v8::Isolate* isolate = env->GetIsolate();
16343 v8::HandleScope scope(isolate); 17801 v8::HandleScope scope(isolate);
16344 v8::Local<v8::Function> f; 17802 v8::Local<v8::Function> f;
16345 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor")); 17803 f = v8::Local<v8::Function>::Cast(CompileRun("Math.floor"));
16346 CHECK(f->IsBuiltin()); 17804 CHECK(f->IsBuiltin());
16347 f = v8::Local<v8::Function>::Cast(CompileRun("Object")); 17805 f = v8::Local<v8::Function>::Cast(CompileRun("Object"));
16348 CHECK(f->IsBuiltin()); 17806 CHECK(f->IsBuiltin());
16349 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__")); 17807 f = v8::Local<v8::Function>::Cast(CompileRun("Object.__defineSetter__"));
16350 CHECK(f->IsBuiltin()); 17808 CHECK(f->IsBuiltin());
16351 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString")); 17809 f = v8::Local<v8::Function>::Cast(CompileRun("Array.prototype.toString"));
16352 CHECK(f->IsBuiltin()); 17810 CHECK(f->IsBuiltin());
16353 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;")); 17811 f = v8::Local<v8::Function>::Cast(CompileRun("function a() {}; a;"));
16354 CHECK(!f->IsBuiltin()); 17812 CHECK(!f->IsBuiltin());
16355 } 17813 }
16356 17814
16357 17815
16358 THREADED_TEST(FunctionGetScriptId) { 17816 THREADED_TEST(FunctionGetScriptId) {
16359 LocalContext env; 17817 LocalContext env;
16360 v8::Isolate* isolate = env->GetIsolate(); 17818 v8::Isolate* isolate = env->GetIsolate();
16361 v8::HandleScope scope(isolate); 17819 v8::HandleScope scope(isolate);
16362 v8::ScriptOrigin origin = 17820 v8::ScriptOrigin origin =
16363 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"), 17821 v8::ScriptOrigin(v8_str("test"), v8::Integer::New(isolate, 3),
16364 v8::Integer::New(isolate, 3),
16365 v8::Integer::New(isolate, 2)); 17822 v8::Integer::New(isolate, 2));
16366 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 17823 v8::Local<v8::String> scriptSource =
16367 isolate, "function foo() {}\n\n function bar() {}"); 17824 v8_str("function foo() {}\n\n function bar() {}");
16368 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 17825 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
16369 script->Run(); 17826 script->Run();
16370 v8::Local<v8::Function> foo = v8::Local<v8::Function>::Cast( 17827 v8::Local<v8::Function> foo =
16371 env->Global()->Get(v8::String::NewFromUtf8(isolate, "foo"))); 17828 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("foo")));
16372 v8::Local<v8::Function> bar = v8::Local<v8::Function>::Cast( 17829 v8::Local<v8::Function> bar =
16373 env->Global()->Get(v8::String::NewFromUtf8(isolate, "bar"))); 17830 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("bar")));
16374 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId()); 17831 CHECK_EQ(script->GetUnboundScript()->GetId(), foo->ScriptId());
16375 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId()); 17832 CHECK_EQ(script->GetUnboundScript()->GetId(), bar->ScriptId());
16376 } 17833 }
16377 17834
16378 17835
16379 THREADED_TEST(FunctionGetBoundFunction) { 17836 THREADED_TEST(FunctionGetBoundFunction) {
16380 LocalContext env; 17837 LocalContext env;
16381 v8::HandleScope scope(env->GetIsolate()); 17838 v8::HandleScope scope(env->GetIsolate());
16382 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::NewFromUtf8( 17839 v8::ScriptOrigin origin = v8::ScriptOrigin(v8_str("test"));
16383 env->GetIsolate(), "test")); 17840 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" 17841 "var a = new Object();\n"
16387 "a.x = 1;\n" 17842 "a.x = 1;\n"
16388 "function f () { return this.x };\n" 17843 "function f () { return this.x };\n"
16389 "var g = f.bind(a);\n" 17844 "var g = f.bind(a);\n"
16390 "var b = g();"); 17845 "var b = g();");
16391 v8::Script::Compile(script, &origin)->Run(); 17846 v8::Script::Compile(script, &origin)->Run();
16392 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 17847 v8::Local<v8::Function> f =
16393 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "f"))); 17848 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("f")));
16394 v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast( 17849 v8::Local<v8::Function> g =
16395 env->Global()->Get(v8::String::NewFromUtf8(env->GetIsolate(), "g"))); 17850 v8::Local<v8::Function>::Cast(env->Global()->Get(v8_str("g")));
16396 CHECK(g->GetBoundFunction()->IsFunction()); 17851 CHECK(g->GetBoundFunction()->IsFunction());
16397 Local<v8::Function> original_function = Local<v8::Function>::Cast( 17852 Local<v8::Function> original_function = Local<v8::Function>::Cast(
16398 g->GetBoundFunction()); 17853 g->GetBoundFunction());
16399 CHECK(f->GetName()->Equals(original_function->GetName())); 17854 CHECK(f->GetName()->Equals(original_function->GetName()));
16400 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber()); 17855 CHECK_EQ(f->GetScriptLineNumber(), original_function->GetScriptLineNumber());
16401 CHECK_EQ(f->GetScriptColumnNumber(), 17856 CHECK_EQ(f->GetScriptColumnNumber(),
16402 original_function->GetScriptColumnNumber()); 17857 original_function->GetScriptColumnNumber());
16403 } 17858 }
16404 17859
16405 17860
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
16441 } 17896 }
16442 17897
16443 17898
16444 TEST(SetterOnConstructorPrototype) { 17899 TEST(SetterOnConstructorPrototype) {
16445 v8::Isolate* isolate = CcTest::isolate(); 17900 v8::Isolate* isolate = CcTest::isolate();
16446 v8::HandleScope scope(isolate); 17901 v8::HandleScope scope(isolate);
16447 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 17902 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
16448 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, 17903 templ->SetAccessor(v8_str("x"), GetterWhichReturns42,
16449 SetterWhichSetsYOnThisTo23); 17904 SetterWhichSetsYOnThisTo23);
16450 LocalContext context; 17905 LocalContext context;
16451 context->Global()->Set(v8_str("P"), templ->NewInstance()); 17906 CHECK(context->Global()
17907 ->Set(context.local(), v8_str("P"),
17908 templ->NewInstance(context.local()).ToLocalChecked())
17909 .FromJust());
16452 CompileRun("function C1() {" 17910 CompileRun("function C1() {"
16453 " this.x = 23;" 17911 " this.x = 23;"
16454 "};" 17912 "};"
16455 "C1.prototype = P;" 17913 "C1.prototype = P;"
16456 "function C2() {" 17914 "function C2() {"
16457 " this.x = 23" 17915 " this.x = 23"
16458 "};" 17916 "};"
16459 "C2.prototype = { };" 17917 "C2.prototype = { };"
16460 "C2.prototype.__proto__ = P;"); 17918 "C2.prototype.__proto__ = P;");
16461 17919
16462 v8::Local<v8::Script> script; 17920 v8::Local<v8::Script> script;
16463 script = v8_compile("new C1();"); 17921 script = v8_compile("new C1();");
16464 for (int i = 0; i < 10; i++) { 17922 for (int i = 0; i < 10; i++) {
16465 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 17923 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run());
16466 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 17924 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16467 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 17925 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16468 } 17926 }
16469 17927
16470 script = v8_compile("new C2();"); 17928 script = v8_compile("new C2();");
16471 for (int i = 0; i < 10; i++) { 17929 for (int i = 0; i < 10; i++) {
16472 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 17930 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run());
16473 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value()); 17931 CHECK_EQ(42, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16474 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value()); 17932 CHECK_EQ(23, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16475 } 17933 }
16476 } 17934 }
16477 17935
16478 17936
16479 static void NamedPropertyGetterWhichReturns42( 17937 static void NamedPropertyGetterWhichReturns42(
16480 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 17938 Local<Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
16481 info.GetReturnValue().Set(v8_num(42)); 17939 info.GetReturnValue().Set(v8_num(42));
16482 } 17940 }
16483 17941
16484 17942
16485 static void NamedPropertySetterWhichSetsYOnThisTo23( 17943 static void NamedPropertySetterWhichSetsYOnThisTo23(
16486 Local<Name> name, Local<Value> value, 17944 Local<Name> name, Local<Value> value,
16487 const v8::PropertyCallbackInfo<v8::Value>& info) { 17945 const v8::PropertyCallbackInfo<v8::Value>& info) {
16488 if (name->Equals(v8_str("x"))) { 17946 if (name->Equals(v8_str("x"))) {
16489 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23)); 17947 Local<Object>::Cast(info.This())->Set(v8_str("y"), v8_num(23));
16490 } 17948 }
16491 } 17949 }
16492 17950
16493 17951
16494 THREADED_TEST(InterceptorOnConstructorPrototype) { 17952 THREADED_TEST(InterceptorOnConstructorPrototype) {
16495 v8::Isolate* isolate = CcTest::isolate(); 17953 v8::Isolate* isolate = CcTest::isolate();
16496 v8::HandleScope scope(isolate); 17954 v8::HandleScope scope(isolate);
16497 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 17955 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
16498 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 17956 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
16499 NamedPropertyGetterWhichReturns42, 17957 NamedPropertyGetterWhichReturns42,
16500 NamedPropertySetterWhichSetsYOnThisTo23)); 17958 NamedPropertySetterWhichSetsYOnThisTo23));
16501 LocalContext context; 17959 LocalContext context;
16502 context->Global()->Set(v8_str("P"), templ->NewInstance()); 17960 CHECK(context->Global()
17961 ->Set(context.local(), v8_str("P"),
17962 templ->NewInstance(context.local()).ToLocalChecked())
17963 .FromJust());
16503 CompileRun("function C1() {" 17964 CompileRun("function C1() {"
16504 " this.x = 23;" 17965 " this.x = 23;"
16505 "};" 17966 "};"
16506 "C1.prototype = P;" 17967 "C1.prototype = P;"
16507 "function C2() {" 17968 "function C2() {"
16508 " this.x = 23" 17969 " this.x = 23"
16509 "};" 17970 "};"
16510 "C2.prototype = { };" 17971 "C2.prototype = { };"
16511 "C2.prototype.__proto__ = P;"); 17972 "C2.prototype.__proto__ = P;");
16512 17973
16513 v8::Local<v8::Script> script; 17974 v8::Local<v8::Script> script;
16514 script = v8_compile("new C1();"); 17975 script = v8_compile("new C1();");
16515 for (int i = 0; i < 10; i++) { 17976 for (int i = 0; i < 10; i++) {
16516 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 17977 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run());
16517 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); 17978 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16518 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 17979 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16519 } 17980 }
16520 17981
16521 script = v8_compile("new C2();"); 17982 script = v8_compile("new C2();");
16522 for (int i = 0; i < 10; i++) { 17983 for (int i = 0; i < 10; i++) {
16523 v8::Handle<v8::Object> c2 = v8::Handle<v8::Object>::Cast(script->Run()); 17984 v8::Local<v8::Object> c2 = v8::Local<v8::Object>::Cast(script->Run());
16524 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value()); 17985 CHECK_EQ(23, c2->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16525 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value()); 17986 CHECK_EQ(42, c2->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16526 } 17987 }
16527 } 17988 }
16528 17989
16529 17990
16530 TEST(Regress618) { 17991 TEST(Regress618) {
16531 const char* source = "function C1() {" 17992 const char* source = "function C1() {"
16532 " this.x = 23;" 17993 " this.x = 23;"
16533 "};" 17994 "};"
16534 "C1.prototype = P;"; 17995 "C1.prototype = P;";
16535 17996
16536 LocalContext context; 17997 LocalContext context;
16537 v8::Isolate* isolate = context->GetIsolate(); 17998 v8::Isolate* isolate = context->GetIsolate();
16538 v8::HandleScope scope(isolate); 17999 v8::HandleScope scope(isolate);
16539 v8::Local<v8::Script> script; 18000 v8::Local<v8::Script> script;
16540 18001
16541 // Use a simple object as prototype. 18002 // Use a simple object as prototype.
16542 v8::Local<v8::Object> prototype = v8::Object::New(isolate); 18003 v8::Local<v8::Object> prototype = v8::Object::New(isolate);
16543 prototype->Set(v8_str("y"), v8_num(42)); 18004 prototype->Set(v8_str("y"), v8_num(42));
16544 context->Global()->Set(v8_str("P"), prototype); 18005 CHECK(context->Global()
18006 ->Set(context.local(), v8_str("P"), prototype)
18007 .FromJust());
16545 18008
16546 // This compile will add the code to the compilation cache. 18009 // This compile will add the code to the compilation cache.
16547 CompileRun(source); 18010 CompileRun(source);
16548 18011
16549 script = v8_compile("new C1();"); 18012 script = v8_compile("new C1();");
16550 // Allow enough iterations for the inobject slack tracking logic 18013 // Allow enough iterations for the inobject slack tracking logic
16551 // to finalize instance size and install the fast construct stub. 18014 // to finalize instance size and install the fast construct stub.
16552 for (int i = 0; i < 256; i++) { 18015 for (int i = 0; i < 256; i++) {
16553 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18016 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run());
16554 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value()); 18017 CHECK_EQ(23, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16555 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value()); 18018 CHECK_EQ(42, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16556 } 18019 }
16557 18020
16558 // Use an API object with accessors as prototype. 18021 // Use an API object with accessors as prototype.
16559 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 18022 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
16560 templ->SetAccessor(v8_str("x"), GetterWhichReturns42, 18023 templ->SetAccessor(v8_str("x"), GetterWhichReturns42,
16561 SetterWhichSetsYOnThisTo23); 18024 SetterWhichSetsYOnThisTo23);
16562 context->Global()->Set(v8_str("P"), templ->NewInstance()); 18025 CHECK(context->Global()
18026 ->Set(context.local(), v8_str("P"),
18027 templ->NewInstance(context.local()).ToLocalChecked())
18028 .FromJust());
16563 18029
16564 // This compile will get the code from the compilation cache. 18030 // This compile will get the code from the compilation cache.
16565 CompileRun(source); 18031 CompileRun(source);
16566 18032
16567 script = v8_compile("new C1();"); 18033 script = v8_compile("new C1();");
16568 for (int i = 0; i < 10; i++) { 18034 for (int i = 0; i < 10; i++) {
16569 v8::Handle<v8::Object> c1 = v8::Handle<v8::Object>::Cast(script->Run()); 18035 v8::Local<v8::Object> c1 = v8::Local<v8::Object>::Cast(script->Run());
16570 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value()); 18036 CHECK_EQ(42, c1->Get(v8_str("x"))->Int32Value(context.local()).FromJust());
16571 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value()); 18037 CHECK_EQ(23, c1->Get(v8_str("y"))->Int32Value(context.local()).FromJust());
16572 } 18038 }
16573 } 18039 }
16574 18040
16575 v8::Isolate* gc_callbacks_isolate = NULL; 18041 v8::Isolate* gc_callbacks_isolate = NULL;
16576 int prologue_call_count = 0; 18042 int prologue_call_count = 0;
16577 int epilogue_call_count = 0; 18043 int epilogue_call_count = 0;
16578 int prologue_call_count_second = 0; 18044 int prologue_call_count_second = 0;
16579 int epilogue_call_count_second = 0; 18045 int epilogue_call_count_second = 0;
16580 int prologue_call_count_alloc = 0; 18046 int prologue_call_count_alloc = 0;
16581 int epilogue_call_count_alloc = 0; 18047 int epilogue_call_count_alloc = 0;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
16805 CHECK(string->IsOneByteRepresentation()); 18271 CHECK(string->IsOneByteRepresentation());
16806 i::ConsString* cons = i::ConsString::cast(*string); 18272 i::ConsString* cons = i::ConsString::cast(*string);
16807 CHECK_EQ(0, cons->second()->length()); 18273 CHECK_EQ(0, cons->second()->length());
16808 CHECK(cons->first()->IsTwoByteRepresentation()); 18274 CHECK(cons->first()->IsTwoByteRepresentation());
16809 } 18275 }
16810 18276
16811 // Check that some string operations work. 18277 // Check that some string operations work.
16812 18278
16813 // Atom RegExp. 18279 // Atom RegExp.
16814 Local<Value> reresult = CompileRun("str2.match(/abel/g).length;"); 18280 Local<Value> reresult = CompileRun("str2.match(/abel/g).length;");
16815 CHECK_EQ(6, reresult->Int32Value()); 18281 CHECK_EQ(6, reresult->Int32Value(context.local()).FromJust());
16816 18282
16817 // Nonatom RegExp. 18283 // Nonatom RegExp.
16818 reresult = CompileRun("str2.match(/abe./g).length;"); 18284 reresult = CompileRun("str2.match(/abe./g).length;");
16819 CHECK_EQ(6, reresult->Int32Value()); 18285 CHECK_EQ(6, reresult->Int32Value(context.local()).FromJust());
16820 18286
16821 reresult = CompileRun("str2.search(/bel/g);"); 18287 reresult = CompileRun("str2.search(/bel/g);");
16822 CHECK_EQ(1, reresult->Int32Value()); 18288 CHECK_EQ(1, reresult->Int32Value(context.local()).FromJust());
16823 18289
16824 reresult = CompileRun("str2.search(/be./g);"); 18290 reresult = CompileRun("str2.search(/be./g);");
16825 CHECK_EQ(1, reresult->Int32Value()); 18291 CHECK_EQ(1, reresult->Int32Value(context.local()).FromJust());
16826 18292
16827 ExpectTrue("/bel/g.test(str2);"); 18293 ExpectTrue("/bel/g.test(str2);");
16828 18294
16829 ExpectTrue("/be./g.test(str2);"); 18295 ExpectTrue("/be./g.test(str2);");
16830 18296
16831 reresult = CompileRun("/bel/g.exec(str2);"); 18297 reresult = CompileRun("/bel/g.exec(str2);");
16832 CHECK(!reresult->IsNull()); 18298 CHECK(!reresult->IsNull());
16833 18299
16834 reresult = CompileRun("/be./g.exec(str2);"); 18300 reresult = CompileRun("/be./g.exec(str2);");
16835 CHECK(!reresult->IsNull()); 18301 CHECK(!reresult->IsNull());
16836 18302
16837 ExpectString("str2.substring(2, 10);", "elspenda"); 18303 ExpectString("str2.substring(2, 10);", "elspenda");
16838 18304
16839 ExpectString("str2.substring(2, 20);", "elspendabelabelspe"); 18305 ExpectString("str2.substring(2, 20);", "elspendabelabelspe");
16840 18306
16841 ExpectString("str2.charAt(2);", "e"); 18307 ExpectString("str2.charAt(2);", "e");
16842 18308
16843 ExpectObject("str2.indexOf('els');", indexof); 18309 ExpectObject("str2.indexOf('els');", indexof);
16844 18310
16845 ExpectObject("str2.lastIndexOf('dab');", lastindexof); 18311 ExpectObject("str2.lastIndexOf('dab');", lastindexof);
16846 18312
16847 reresult = CompileRun("str2.charCodeAt(2);"); 18313 reresult = CompileRun("str2.charCodeAt(2);");
16848 CHECK_EQ(static_cast<int32_t>('e'), reresult->Int32Value()); 18314 CHECK_EQ(static_cast<int32_t>('e'),
18315 reresult->Int32Value(context.local()).FromJust());
16849 } 18316 }
16850 18317
16851 18318
16852 TEST(ContainsOnlyOneByte) { 18319 TEST(ContainsOnlyOneByte) {
16853 v8::V8::Initialize(); 18320 v8::V8::Initialize();
16854 v8::Isolate* isolate = CcTest::isolate(); 18321 v8::Isolate* isolate = CcTest::isolate();
16855 v8::HandleScope scope(isolate); 18322 v8::HandleScope scope(isolate);
16856 // Make a buffer long enough that it won't automatically be converted. 18323 // Make a buffer long enough that it won't automatically be converted.
16857 const int length = 512; 18324 const int length = 512;
16858 // Ensure word aligned assignment. 18325 // Ensure word aligned assignment.
16859 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t); 18326 const int aligned_length = length*sizeof(uintptr_t)/sizeof(uint16_t);
16860 v8::base::SmartArrayPointer<uintptr_t> aligned_contents( 18327 v8::base::SmartArrayPointer<uintptr_t> aligned_contents(
16861 new uintptr_t[aligned_length]); 18328 new uintptr_t[aligned_length]);
16862 uint16_t* string_contents = 18329 uint16_t* string_contents =
16863 reinterpret_cast<uint16_t*>(aligned_contents.get()); 18330 reinterpret_cast<uint16_t*>(aligned_contents.get());
16864 // Set to contain only one byte. 18331 // Set to contain only one byte.
16865 for (int i = 0; i < length-1; i++) { 18332 for (int i = 0; i < length-1; i++) {
16866 string_contents[i] = 0x41; 18333 string_contents[i] = 0x41;
16867 } 18334 }
16868 string_contents[length-1] = 0; 18335 string_contents[length-1] = 0;
16869 // Simple case. 18336 // Simple case.
16870 Handle<String> string = 18337 Local<String> string = String::NewExternal(
16871 String::NewExternal(isolate, 18338 isolate, new TestResource(string_contents, NULL, false));
16872 new TestResource(string_contents, NULL, false));
16873 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18339 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
16874 // Counter example. 18340 // Counter example.
16875 string = String::NewFromTwoByte(isolate, string_contents); 18341 string = String::NewFromTwoByte(isolate, string_contents);
16876 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); 18342 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
16877 // Test left right and balanced cons strings. 18343 // Test left right and balanced cons strings.
16878 Handle<String> base = String::NewFromUtf8(isolate, "a"); 18344 Local<String> base = v8_str("a");
16879 Handle<String> left = base; 18345 Local<String> left = base;
16880 Handle<String> right = base; 18346 Local<String> right = base;
16881 for (int i = 0; i < 1000; i++) { 18347 for (int i = 0; i < 1000; i++) {
16882 left = String::Concat(base, left); 18348 left = String::Concat(base, left);
16883 right = String::Concat(right, base); 18349 right = String::Concat(right, base);
16884 } 18350 }
16885 Handle<String> balanced = String::Concat(left, base); 18351 Local<String> balanced = String::Concat(left, base);
16886 balanced = String::Concat(balanced, right); 18352 balanced = String::Concat(balanced, right);
16887 Handle<String> cons_strings[] = {left, balanced, right}; 18353 Local<String> cons_strings[] = {left, balanced, right};
16888 Handle<String> two_byte = 18354 Local<String> two_byte = String::NewExternal(
16889 String::NewExternal(isolate, 18355 isolate, new TestResource(string_contents, NULL, false));
16890 new TestResource(string_contents, NULL, false));
16891 USE(two_byte); USE(cons_strings); 18356 USE(two_byte); USE(cons_strings);
16892 for (size_t i = 0; i < arraysize(cons_strings); i++) { 18357 for (size_t i = 0; i < arraysize(cons_strings); i++) {
16893 // Base assumptions. 18358 // Base assumptions.
16894 string = cons_strings[i]; 18359 string = cons_strings[i];
16895 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte()); 18360 CHECK(string->IsOneByte() && string->ContainsOnlyOneByte());
16896 // Test left and right concatentation. 18361 // Test left and right concatentation.
16897 string = String::Concat(two_byte, cons_strings[i]); 18362 string = String::Concat(two_byte, cons_strings[i]);
16898 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18363 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
16899 string = String::Concat(cons_strings[i], two_byte); 18364 string = String::Concat(cons_strings[i], two_byte);
16900 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte()); 18365 CHECK(!string->IsOneByte() && string->ContainsOnlyOneByte());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
16936 // invocation. Then force the callback to be called from va 18401 // invocation. Then force the callback to be called from va
16937 18402
16938 v8::V8::Initialize(); 18403 v8::V8::Initialize();
16939 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC); 18404 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckCallbackGC);
16940 18405
16941 v8::Isolate* isolate = CcTest::isolate(); 18406 v8::Isolate* isolate = CcTest::isolate();
16942 v8::HandleScope scope(isolate); 18407 v8::HandleScope scope(isolate);
16943 18408
16944 // Create an ObjectTemplate for global objects and install access 18409 // Create an ObjectTemplate for global objects and install access
16945 // check callbacks that will block access. 18410 // check callbacks that will block access.
16946 v8::Handle<v8::ObjectTemplate> global_template = 18411 v8::Local<v8::ObjectTemplate> global_template =
16947 v8::ObjectTemplate::New(isolate); 18412 v8::ObjectTemplate::New(isolate);
16948 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); 18413 global_template->SetAccessCheckCallback(AccessAlwaysBlocked);
16949 18414
16950 // Create a context and set an x property on it's global object. 18415 // Create a context and set an x property on it's global object.
16951 LocalContext context0(NULL, global_template); 18416 LocalContext context0(NULL, global_template);
16952 context0->Global()->Set(v8_str("x"), v8_num(42)); 18417 CHECK(context0->Global()
16953 v8::Handle<v8::Object> global0 = context0->Global(); 18418 ->Set(context0.local(), v8_str("x"), v8_num(42))
18419 .FromJust());
18420 v8::Local<v8::Object> global0 = context0->Global();
16954 18421
16955 // Create a context with a different security token so that the 18422 // Create a context with a different security token so that the
16956 // failed access check callback will be called on each access. 18423 // failed access check callback will be called on each access.
16957 LocalContext context1(NULL, global_template); 18424 LocalContext context1(NULL, global_template);
16958 context1->Global()->Set(v8_str("other"), global0); 18425 CHECK(context1->Global()
18426 ->Set(context1.local(), v8_str("other"), global0)
18427 .FromJust());
16959 18428
16960 v8::TryCatch try_catch(isolate); 18429 v8::TryCatch try_catch(isolate);
16961 18430
16962 // Get property with failed access check. 18431 // Get property with failed access check.
16963 CHECK(CompileRun("other.x").IsEmpty()); 18432 CHECK(CompileRun("other.x").IsEmpty());
16964 CHECK(try_catch.HasCaught()); 18433 CHECK(try_catch.HasCaught());
16965 try_catch.Reset(); 18434 try_catch.Reset();
16966 18435
16967 // Get element with failed access check. 18436 // Get element with failed access check.
16968 CHECK(CompileRun("other[0]").IsEmpty()); 18437 CHECK(CompileRun("other[0]").IsEmpty());
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
17541 public: 19010 public:
17542 explicit Visitor42(v8::Persistent<v8::Object>* object) 19011 explicit Visitor42(v8::Persistent<v8::Object>* object)
17543 : counter_(0), object_(object) { } 19012 : counter_(0), object_(object) { }
17544 19013
17545 virtual void VisitPersistentHandle(Persistent<Value>* value, 19014 virtual void VisitPersistentHandle(Persistent<Value>* value,
17546 uint16_t class_id) { 19015 uint16_t class_id) {
17547 if (class_id != 42) return; 19016 if (class_id != 42) return;
17548 CHECK_EQ(42, value->WrapperClassId()); 19017 CHECK_EQ(42, value->WrapperClassId());
17549 v8::Isolate* isolate = CcTest::isolate(); 19018 v8::Isolate* isolate = CcTest::isolate();
17550 v8::HandleScope handle_scope(isolate); 19019 v8::HandleScope handle_scope(isolate);
17551 v8::Handle<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value); 19020 v8::Local<v8::Value> handle = v8::Local<v8::Value>::New(isolate, *value);
17552 v8::Handle<v8::Value> object = 19021 v8::Local<v8::Value> object = v8::Local<v8::Object>::New(isolate, *object_);
17553 v8::Local<v8::Object>::New(isolate, *object_);
17554 CHECK(handle->IsObject()); 19022 CHECK(handle->IsObject());
17555 CHECK(Handle<Object>::Cast(handle)->Equals(object)); 19023 CHECK(Local<Object>::Cast(handle)->Equals(object));
17556 ++counter_; 19024 ++counter_;
17557 } 19025 }
17558 19026
17559 int counter_; 19027 int counter_;
17560 v8::Persistent<v8::Object>* object_; 19028 v8::Persistent<v8::Object>* object_;
17561 }; 19029 };
17562 19030
17563 19031
17564 TEST(PersistentHandleVisitor) { 19032 TEST(PersistentHandleVisitor) {
17565 LocalContext context; 19033 LocalContext context;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
17615 object2.Reset(); 19083 object2.Reset();
17616 } 19084 }
17617 19085
17618 19086
17619 TEST(RegExp) { 19087 TEST(RegExp) {
17620 i::FLAG_harmony_regexps = true; 19088 i::FLAG_harmony_regexps = true;
17621 i::FLAG_harmony_unicode_regexps = true; 19089 i::FLAG_harmony_unicode_regexps = true;
17622 LocalContext context; 19090 LocalContext context;
17623 v8::HandleScope scope(context->GetIsolate()); 19091 v8::HandleScope scope(context->GetIsolate());
17624 19092
17625 v8::Handle<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone); 19093 v8::Local<v8::RegExp> re = v8::RegExp::New(v8_str("foo"), v8::RegExp::kNone);
17626 CHECK(re->IsRegExp()); 19094 CHECK(re->IsRegExp());
17627 CHECK(re->GetSource()->Equals(v8_str("foo"))); 19095 CHECK(re->GetSource()->Equals(v8_str("foo")));
17628 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); 19096 CHECK_EQ(v8::RegExp::kNone, re->GetFlags());
17629 19097
17630 re = v8::RegExp::New(v8_str("bar"), 19098 re = v8::RegExp::New(v8_str("bar"),
17631 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | 19099 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
17632 v8::RegExp::kGlobal)); 19100 v8::RegExp::kGlobal));
17633 CHECK(re->IsRegExp()); 19101 CHECK(re->IsRegExp());
17634 CHECK(re->GetSource()->Equals(v8_str("bar"))); 19102 CHECK(re->GetSource()->Equals(v8_str("bar")));
17635 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal, 19103 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kGlobal,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
17672 CHECK_EQ(v8::RegExp::kNone, re->GetFlags()); 19140 CHECK_EQ(v8::RegExp::kNone, re->GetFlags());
17673 19141
17674 re = v8::RegExp::New(v8_str("foobarbaz"), 19142 re = v8::RegExp::New(v8_str("foobarbaz"),
17675 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | 19143 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
17676 v8::RegExp::kMultiline)); 19144 v8::RegExp::kMultiline));
17677 CHECK(re->IsRegExp()); 19145 CHECK(re->IsRegExp());
17678 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); 19146 CHECK(re->GetSource()->Equals(v8_str("foobarbaz")));
17679 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline, 19147 CHECK_EQ(v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline,
17680 static_cast<int>(re->GetFlags())); 19148 static_cast<int>(re->GetFlags()));
17681 19149
17682 context->Global()->Set(v8_str("re"), re); 19150 CHECK(context->Global()->Set(context.local(), v8_str("re"), re).FromJust());
17683 ExpectTrue("re.test('FoobarbaZ')"); 19151 ExpectTrue("re.test('FoobarbaZ')");
17684 19152
17685 // RegExps are objects on which you can set properties. 19153 // RegExps are objects on which you can set properties.
17686 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32)); 19154 re->Set(v8_str("property"), v8::Integer::New(context->GetIsolate(), 32));
17687 v8::Handle<v8::Value> value(CompileRun("re.property")); 19155 v8::Local<v8::Value> value(CompileRun("re.property"));
17688 CHECK_EQ(32, value->Int32Value()); 19156 CHECK_EQ(32, value->Int32Value(context.local()).FromJust());
17689 19157
17690 v8::TryCatch try_catch(context->GetIsolate()); 19158 v8::TryCatch try_catch(context->GetIsolate());
17691 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 19159 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
17692 CHECK(re.IsEmpty()); 19160 CHECK(re.IsEmpty());
17693 CHECK(try_catch.HasCaught()); 19161 CHECK(try_catch.HasCaught());
17694 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 19162 CHECK(context->Global()
19163 ->Set(context.local(), v8_str("ex"), try_catch.Exception())
19164 .FromJust());
17695 ExpectTrue("ex instanceof SyntaxError"); 19165 ExpectTrue("ex instanceof SyntaxError");
17696 } 19166 }
17697 19167
17698 19168
17699 THREADED_TEST(Equals) { 19169 THREADED_TEST(Equals) {
17700 LocalContext localContext; 19170 LocalContext localContext;
17701 v8::HandleScope handleScope(localContext->GetIsolate()); 19171 v8::HandleScope handleScope(localContext->GetIsolate());
17702 19172
17703 v8::Handle<v8::Object> globalProxy = localContext->Global(); 19173 v8::Local<v8::Object> globalProxy = localContext->Global();
17704 v8::Handle<Value> global = globalProxy->GetPrototype(); 19174 v8::Local<Value> global = globalProxy->GetPrototype();
17705 19175
17706 CHECK(global->StrictEquals(global)); 19176 CHECK(global->StrictEquals(global));
17707 CHECK(!global->StrictEquals(globalProxy)); 19177 CHECK(!global->StrictEquals(globalProxy));
17708 CHECK(!globalProxy->StrictEquals(global)); 19178 CHECK(!globalProxy->StrictEquals(global));
17709 CHECK(globalProxy->StrictEquals(globalProxy)); 19179 CHECK(globalProxy->StrictEquals(globalProxy));
17710 19180
17711 CHECK(global->Equals(global)); 19181 CHECK(global->Equals(global));
17712 CHECK(!global->Equals(globalProxy)); 19182 CHECK(!global->Equals(globalProxy));
17713 CHECK(!globalProxy->Equals(global)); 19183 CHECK(!globalProxy->Equals(global));
17714 CHECK(globalProxy->Equals(globalProxy)); 19184 CHECK(globalProxy->Equals(globalProxy));
17715 } 19185 }
17716 19186
17717 19187
17718 static void Getter(v8::Local<v8::Name> property, 19188 static void Getter(v8::Local<v8::Name> property,
17719 const v8::PropertyCallbackInfo<v8::Value>& info) { 19189 const v8::PropertyCallbackInfo<v8::Value>& info) {
17720 info.GetReturnValue().Set(v8_str("42!")); 19190 info.GetReturnValue().Set(v8_str("42!"));
17721 } 19191 }
17722 19192
17723 19193
17724 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) { 19194 static void Enumerator(const v8::PropertyCallbackInfo<v8::Array>& info) {
17725 v8::Handle<v8::Array> result = v8::Array::New(info.GetIsolate()); 19195 v8::Local<v8::Array> result = v8::Array::New(info.GetIsolate());
17726 result->Set(0, v8_str("universalAnswer")); 19196 result->Set(0, v8_str("universalAnswer"));
17727 info.GetReturnValue().Set(result); 19197 info.GetReturnValue().Set(result);
17728 } 19198 }
17729 19199
17730 19200
17731 TEST(NamedEnumeratorAndForIn) { 19201 TEST(NamedEnumeratorAndForIn) {
17732 LocalContext context; 19202 LocalContext context;
17733 v8::Isolate* isolate = context->GetIsolate(); 19203 v8::Isolate* isolate = context->GetIsolate();
17734 v8::HandleScope handle_scope(isolate); 19204 v8::HandleScope handle_scope(isolate);
17735 v8::Context::Scope context_scope(context.local()); 19205 v8::Context::Scope context_scope(context.local());
17736 19206
17737 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate); 19207 v8::Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate);
17738 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL, 19208 tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(Getter, NULL, NULL,
17739 NULL, Enumerator)); 19209 NULL, Enumerator));
17740 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 19210 CHECK(context->Global()
17741 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 19211 ->Set(context.local(), v8_str("o"),
17742 "var result = []; for (var k in o) result.push(k); result")); 19212 tmpl->NewInstance(context.local()).ToLocalChecked())
19213 .FromJust());
19214 v8::Local<v8::Array> result = v8::Local<v8::Array>::Cast(
19215 CompileRun("var result = []; for (var k in o) result.push(k); result"));
17743 CHECK_EQ(1u, result->Length()); 19216 CHECK_EQ(1u, result->Length());
17744 CHECK(v8_str("universalAnswer")->Equals(result->Get(0))); 19217 CHECK(v8_str("universalAnswer")->Equals(result->Get(0)));
17745 } 19218 }
17746 19219
17747 19220
17748 TEST(DefinePropertyPostDetach) { 19221 TEST(DefinePropertyPostDetach) {
17749 LocalContext context; 19222 LocalContext context;
17750 v8::HandleScope scope(context->GetIsolate()); 19223 v8::HandleScope scope(context->GetIsolate());
17751 v8::Handle<v8::Object> proxy = context->Global(); 19224 v8::Local<v8::Object> proxy = context->Global();
17752 v8::Handle<v8::Function> define_property = 19225 v8::Local<v8::Function> define_property =
17753 CompileRun("(function() {" 19226 CompileRun(
17754 " Object.defineProperty(" 19227 "(function() {"
17755 " this," 19228 " Object.defineProperty("
17756 " 1," 19229 " this,"
17757 " { configurable: true, enumerable: true, value: 3 });" 19230 " 1,"
17758 "})").As<Function>(); 19231 " { configurable: true, enumerable: true, value: 3 });"
19232 "})")
19233 .As<Function>();
17759 context->DetachGlobal(); 19234 context->DetachGlobal();
17760 define_property->Call(proxy, 0, NULL); 19235 define_property->Call(proxy, 0, NULL);
17761 } 19236 }
17762 19237
17763 19238
17764 static void InstallContextId(v8::Handle<Context> context, int id) { 19239 static void InstallContextId(v8::Local<Context> context, int id) {
17765 Context::Scope scope(context); 19240 Context::Scope scope(context);
17766 CompileRun("Object.prototype").As<Object>()-> 19241 CHECK(CompileRun("Object.prototype")
17767 Set(v8_str("context_id"), v8::Integer::New(context->GetIsolate(), id)); 19242 .As<Object>()
19243 ->Set(context, v8_str("context_id"),
19244 v8::Integer::New(context->GetIsolate(), id))
19245 .FromJust());
17768 } 19246 }
17769 19247
17770 19248
17771 static void CheckContextId(v8::Handle<Object> object, int expected) { 19249 static void CheckContextId(v8::Local<Object> object, int expected) {
17772 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 19250 CHECK_EQ(expected, object->Get(v8_str("context_id"))
19251 ->Int32Value(CcTest::isolate()->GetCurrentContext())
19252 .FromJust());
17773 } 19253 }
17774 19254
17775 19255
17776 THREADED_TEST(CreationContext) { 19256 THREADED_TEST(CreationContext) {
17777 v8::Isolate* isolate = CcTest::isolate(); 19257 v8::Isolate* isolate = CcTest::isolate();
17778 HandleScope handle_scope(isolate); 19258 HandleScope handle_scope(isolate);
17779 Handle<Context> context1 = Context::New(isolate); 19259 Local<Context> context1 = Context::New(isolate);
17780 InstallContextId(context1, 1); 19260 InstallContextId(context1, 1);
17781 Handle<Context> context2 = Context::New(isolate); 19261 Local<Context> context2 = Context::New(isolate);
17782 InstallContextId(context2, 2); 19262 InstallContextId(context2, 2);
17783 Handle<Context> context3 = Context::New(isolate); 19263 Local<Context> context3 = Context::New(isolate);
17784 InstallContextId(context3, 3); 19264 InstallContextId(context3, 3);
17785 19265
17786 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate); 19266 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate);
17787 19267
17788 Local<Object> object1; 19268 Local<Object> object1;
17789 Local<Function> func1; 19269 Local<Function> func1;
17790 { 19270 {
17791 Context::Scope scope(context1); 19271 Context::Scope scope(context1);
17792 object1 = Object::New(isolate); 19272 object1 = Object::New(isolate);
17793 func1 = tmpl->GetFunction(); 19273 func1 = tmpl->GetFunction(context1).ToLocalChecked();
17794 } 19274 }
17795 19275
17796 Local<Object> object2; 19276 Local<Object> object2;
17797 Local<Function> func2; 19277 Local<Function> func2;
17798 { 19278 {
17799 Context::Scope scope(context2); 19279 Context::Scope scope(context2);
17800 object2 = Object::New(isolate); 19280 object2 = Object::New(isolate);
17801 func2 = tmpl->GetFunction(); 19281 func2 = tmpl->GetFunction(context2).ToLocalChecked();
17802 } 19282 }
17803 19283
17804 Local<Object> instance1; 19284 Local<Object> instance1;
17805 Local<Object> instance2; 19285 Local<Object> instance2;
17806 19286
17807 { 19287 {
17808 Context::Scope scope(context3); 19288 Context::Scope scope(context3);
17809 instance1 = func1->NewInstance(); 19289 instance1 = func1->NewInstance(context3).ToLocalChecked();
17810 instance2 = func2->NewInstance(); 19290 instance2 = func2->NewInstance(context3).ToLocalChecked();
17811 } 19291 }
17812 19292
17813 { 19293 {
17814 Handle<Context> other_context = Context::New(isolate); 19294 Local<Context> other_context = Context::New(isolate);
17815 Context::Scope scope(other_context); 19295 Context::Scope scope(other_context);
17816 CHECK(object1->CreationContext() == context1); 19296 CHECK(object1->CreationContext() == context1);
17817 CheckContextId(object1, 1); 19297 CheckContextId(object1, 1);
17818 CHECK(func1->CreationContext() == context1); 19298 CHECK(func1->CreationContext() == context1);
17819 CheckContextId(func1, 1); 19299 CheckContextId(func1, 1);
17820 CHECK(instance1->CreationContext() == context1); 19300 CHECK(instance1->CreationContext() == context1);
17821 CheckContextId(instance1, 1); 19301 CheckContextId(instance1, 1);
17822 CHECK(object2->CreationContext() == context2); 19302 CHECK(object2->CreationContext() == context2);
17823 CheckContextId(object2, 2); 19303 CheckContextId(object2, 2);
17824 CHECK(func2->CreationContext() == context2); 19304 CHECK(func2->CreationContext() == context2);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
17856 CHECK(func2->CreationContext() == context2); 19336 CHECK(func2->CreationContext() == context2);
17857 CheckContextId(func2, 2); 19337 CheckContextId(func2, 2);
17858 CHECK(instance2->CreationContext() == context2); 19338 CHECK(instance2->CreationContext() == context2);
17859 CheckContextId(instance2, 2); 19339 CheckContextId(instance2, 2);
17860 } 19340 }
17861 } 19341 }
17862 19342
17863 19343
17864 THREADED_TEST(CreationContextOfJsFunction) { 19344 THREADED_TEST(CreationContextOfJsFunction) {
17865 HandleScope handle_scope(CcTest::isolate()); 19345 HandleScope handle_scope(CcTest::isolate());
17866 Handle<Context> context = Context::New(CcTest::isolate()); 19346 Local<Context> context = Context::New(CcTest::isolate());
17867 InstallContextId(context, 1); 19347 InstallContextId(context, 1);
17868 19348
17869 Local<Object> function; 19349 Local<Object> function;
17870 { 19350 {
17871 Context::Scope scope(context); 19351 Context::Scope scope(context);
17872 function = CompileRun("function foo() {}; foo").As<Object>(); 19352 function = CompileRun("function foo() {}; foo").As<Object>();
17873 } 19353 }
17874 19354
17875 Handle<Context> other_context = Context::New(CcTest::isolate()); 19355 Local<Context> other_context = Context::New(CcTest::isolate());
17876 Context::Scope scope(other_context); 19356 Context::Scope scope(other_context);
17877 CHECK(function->CreationContext() == context); 19357 CHECK(function->CreationContext() == context);
17878 CheckContextId(function, 1); 19358 CheckContextId(function, 1);
17879 } 19359 }
17880 19360
17881 19361
17882 void HasOwnPropertyIndexedPropertyGetter( 19362 void HasOwnPropertyIndexedPropertyGetter(
17883 uint32_t index, 19363 uint32_t index,
17884 const v8::PropertyCallbackInfo<v8::Value>& info) { 19364 const v8::PropertyCallbackInfo<v8::Value>& info) {
17885 if (index == 42) info.GetReturnValue().Set(v8_str("yes")); 19365 if (index == 42) info.GetReturnValue().Set(v8_str("yes"));
(...skipping 29 matching lines...) Expand all
17915 const v8::PropertyCallbackInfo<v8::Value>& info) { 19395 const v8::PropertyCallbackInfo<v8::Value>& info) {
17916 info.GetReturnValue().Set(v8_str("yes")); 19396 info.GetReturnValue().Set(v8_str("yes"));
17917 } 19397 }
17918 19398
17919 19399
17920 TEST(HasOwnProperty) { 19400 TEST(HasOwnProperty) {
17921 LocalContext env; 19401 LocalContext env;
17922 v8::Isolate* isolate = env->GetIsolate(); 19402 v8::Isolate* isolate = env->GetIsolate();
17923 v8::HandleScope scope(isolate); 19403 v8::HandleScope scope(isolate);
17924 { // Check normal properties and defined getters. 19404 { // Check normal properties and defined getters.
17925 Handle<Value> value = CompileRun( 19405 Local<Value> value = CompileRun(
17926 "function Foo() {" 19406 "function Foo() {"
17927 " this.foo = 11;" 19407 " this.foo = 11;"
17928 " this.__defineGetter__('baz', function() { return 1; });" 19408 " this.__defineGetter__('baz', function() { return 1; });"
17929 "};" 19409 "};"
17930 "function Bar() { " 19410 "function Bar() { "
17931 " this.bar = 13;" 19411 " this.bar = 13;"
17932 " this.__defineGetter__('bla', function() { return 2; });" 19412 " this.__defineGetter__('bla', function() { return 2; });"
17933 "};" 19413 "};"
17934 "Bar.prototype = new Foo();" 19414 "Bar.prototype = new Foo();"
17935 "new Bar();"); 19415 "new Bar();");
17936 CHECK(value->IsObject()); 19416 CHECK(value->IsObject());
17937 Handle<Object> object = value->ToObject(isolate); 19417 Local<Object> object = value->ToObject(isolate);
17938 CHECK(object->Has(v8_str("foo"))); 19418 CHECK(object->Has(v8_str("foo")));
17939 CHECK(!object->HasOwnProperty(v8_str("foo"))); 19419 CHECK(!object->HasOwnProperty(v8_str("foo")));
17940 CHECK(object->HasOwnProperty(v8_str("bar"))); 19420 CHECK(object->HasOwnProperty(v8_str("bar")));
17941 CHECK(object->Has(v8_str("baz"))); 19421 CHECK(object->Has(v8_str("baz")));
17942 CHECK(!object->HasOwnProperty(v8_str("baz"))); 19422 CHECK(!object->HasOwnProperty(v8_str("baz")));
17943 CHECK(object->HasOwnProperty(v8_str("bla"))); 19423 CHECK(object->HasOwnProperty(v8_str("bla")));
17944 } 19424 }
17945 { // Check named getter interceptors. 19425 { // Check named getter interceptors.
17946 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19426 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17947 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 19427 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
17948 HasOwnPropertyNamedPropertyGetter)); 19428 HasOwnPropertyNamedPropertyGetter));
17949 Handle<Object> instance = templ->NewInstance(); 19429 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17950 CHECK(!instance->HasOwnProperty(v8_str("42"))); 19430 CHECK(!instance->HasOwnProperty(v8_str("42")));
17951 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19431 CHECK(instance->HasOwnProperty(v8_str("foo")));
17952 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19432 CHECK(!instance->HasOwnProperty(v8_str("bar")));
17953 } 19433 }
17954 { // Check indexed getter interceptors. 19434 { // Check indexed getter interceptors.
17955 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19435 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17956 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( 19436 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration(
17957 HasOwnPropertyIndexedPropertyGetter)); 19437 HasOwnPropertyIndexedPropertyGetter));
17958 Handle<Object> instance = templ->NewInstance(); 19438 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17959 CHECK(instance->HasOwnProperty(v8_str("42"))); 19439 CHECK(instance->HasOwnProperty(v8_str("42")));
17960 CHECK(!instance->HasOwnProperty(v8_str("43"))); 19440 CHECK(!instance->HasOwnProperty(v8_str("43")));
17961 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 19441 CHECK(!instance->HasOwnProperty(v8_str("foo")));
17962 } 19442 }
17963 { // Check named query interceptors. 19443 { // Check named query interceptors.
17964 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19444 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17965 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 19445 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
17966 0, 0, HasOwnPropertyNamedPropertyQuery)); 19446 0, 0, HasOwnPropertyNamedPropertyQuery));
17967 Handle<Object> instance = templ->NewInstance(); 19447 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17968 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19448 CHECK(instance->HasOwnProperty(v8_str("foo")));
17969 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19449 CHECK(!instance->HasOwnProperty(v8_str("bar")));
17970 } 19450 }
17971 { // Check indexed query interceptors. 19451 { // Check indexed query interceptors.
17972 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19452 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17973 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( 19453 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration(
17974 0, 0, HasOwnPropertyIndexedPropertyQuery)); 19454 0, 0, HasOwnPropertyIndexedPropertyQuery));
17975 Handle<Object> instance = templ->NewInstance(); 19455 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17976 CHECK(instance->HasOwnProperty(v8_str("42"))); 19456 CHECK(instance->HasOwnProperty(v8_str("42")));
17977 CHECK(!instance->HasOwnProperty(v8_str("41"))); 19457 CHECK(!instance->HasOwnProperty(v8_str("41")));
17978 } 19458 }
17979 { // Check callbacks. 19459 { // Check callbacks.
17980 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19460 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17981 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter); 19461 templ->SetAccessor(v8_str("foo"), HasOwnPropertyAccessorGetter);
17982 Handle<Object> instance = templ->NewInstance(); 19462 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17983 CHECK(instance->HasOwnProperty(v8_str("foo"))); 19463 CHECK(instance->HasOwnProperty(v8_str("foo")));
17984 CHECK(!instance->HasOwnProperty(v8_str("bar"))); 19464 CHECK(!instance->HasOwnProperty(v8_str("bar")));
17985 } 19465 }
17986 { // Check that query wins on disagreement. 19466 { // Check that query wins on disagreement.
17987 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19467 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
17988 templ->SetHandler(v8::NamedPropertyHandlerConfiguration( 19468 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(
17989 HasOwnPropertyNamedPropertyGetter, 0, 19469 HasOwnPropertyNamedPropertyGetter, 0,
17990 HasOwnPropertyNamedPropertyQuery2)); 19470 HasOwnPropertyNamedPropertyQuery2));
17991 Handle<Object> instance = templ->NewInstance(); 19471 Local<Object> instance = templ->NewInstance(env.local()).ToLocalChecked();
17992 CHECK(!instance->HasOwnProperty(v8_str("foo"))); 19472 CHECK(!instance->HasOwnProperty(v8_str("foo")));
17993 CHECK(instance->HasOwnProperty(v8_str("bar"))); 19473 CHECK(instance->HasOwnProperty(v8_str("bar")));
17994 } 19474 }
17995 } 19475 }
17996 19476
17997 19477
17998 TEST(IndexedInterceptorWithStringProto) { 19478 TEST(IndexedInterceptorWithStringProto) {
17999 v8::Isolate* isolate = CcTest::isolate(); 19479 v8::Isolate* isolate = CcTest::isolate();
18000 v8::HandleScope scope(isolate); 19480 v8::HandleScope scope(isolate);
18001 Handle<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19481 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18002 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration( 19482 templ->SetHandler(v8::IndexedPropertyHandlerConfiguration(
18003 NULL, NULL, HasOwnPropertyIndexedPropertyQuery)); 19483 NULL, NULL, HasOwnPropertyIndexedPropertyQuery));
18004 LocalContext context; 19484 LocalContext context;
18005 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 19485 CHECK(context->Global()
19486 ->Set(context.local(), v8_str("obj"),
19487 templ->NewInstance(context.local()).ToLocalChecked())
19488 .FromJust());
18006 CompileRun("var s = new String('foobar'); obj.__proto__ = s;"); 19489 CompileRun("var s = new String('foobar'); obj.__proto__ = s;");
18007 // These should be intercepted. 19490 // These should be intercepted.
18008 CHECK(CompileRun("42 in obj")->BooleanValue()); 19491 CHECK(CompileRun("42 in obj")->BooleanValue());
18009 CHECK(CompileRun("'42' in obj")->BooleanValue()); 19492 CHECK(CompileRun("'42' in obj")->BooleanValue());
18010 // These should fall through to the String prototype. 19493 // These should fall through to the String prototype.
18011 CHECK(CompileRun("0 in obj")->BooleanValue()); 19494 CHECK(CompileRun("0 in obj")->BooleanValue());
18012 CHECK(CompileRun("'0' in obj")->BooleanValue()); 19495 CHECK(CompileRun("'0' in obj")->BooleanValue());
18013 // And these should both fail. 19496 // And these should both fail.
18014 CHECK(!CompileRun("32 in obj")->BooleanValue()); 19497 CHECK(!CompileRun("32 in obj")->BooleanValue());
18015 CHECK(!CompileRun("'32' in obj")->BooleanValue()); 19498 CHECK(!CompileRun("'32' in obj")->BooleanValue());
18016 } 19499 }
18017 19500
18018 19501
18019 void CheckCodeGenerationAllowed() { 19502 void CheckCodeGenerationAllowed() {
18020 Handle<Value> result = CompileRun("eval('42')"); 19503 Local<v8::Context> context = CcTest::isolate()->GetCurrentContext();
18021 CHECK_EQ(42, result->Int32Value()); 19504 Local<Value> result = CompileRun("eval('42')");
19505 CHECK_EQ(42, result->Int32Value(context).FromJust());
18022 result = CompileRun("(function(e) { return e('42'); })(eval)"); 19506 result = CompileRun("(function(e) { return e('42'); })(eval)");
18023 CHECK_EQ(42, result->Int32Value()); 19507 CHECK_EQ(42, result->Int32Value(context).FromJust());
18024 result = CompileRun("var f = new Function('return 42'); f()"); 19508 result = CompileRun("var f = new Function('return 42'); f()");
18025 CHECK_EQ(42, result->Int32Value()); 19509 CHECK_EQ(42, result->Int32Value(context).FromJust());
18026 } 19510 }
18027 19511
18028 19512
18029 void CheckCodeGenerationDisallowed() { 19513 void CheckCodeGenerationDisallowed() {
18030 TryCatch try_catch(CcTest::isolate()); 19514 TryCatch try_catch(CcTest::isolate());
18031 19515
18032 Handle<Value> result = CompileRun("eval('42')"); 19516 Local<Value> result = CompileRun("eval('42')");
18033 CHECK(result.IsEmpty()); 19517 CHECK(result.IsEmpty());
18034 CHECK(try_catch.HasCaught()); 19518 CHECK(try_catch.HasCaught());
18035 try_catch.Reset(); 19519 try_catch.Reset();
18036 19520
18037 result = CompileRun("(function(e) { return e('42'); })(eval)"); 19521 result = CompileRun("(function(e) { return e('42'); })(eval)");
18038 CHECK(result.IsEmpty()); 19522 CHECK(result.IsEmpty());
18039 CHECK(try_catch.HasCaught()); 19523 CHECK(try_catch.HasCaught());
18040 try_catch.Reset(); 19524 try_catch.Reset();
18041 19525
18042 result = CompileRun("var f = new Function('return 42'); f()"); 19526 result = CompileRun("var f = new Function('return 42'); f()");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
18085 CHECK(!context->IsCodeGenerationFromStringsAllowed()); 19569 CHECK(!context->IsCodeGenerationFromStringsAllowed());
18086 CheckCodeGenerationDisallowed(); 19570 CheckCodeGenerationDisallowed();
18087 } 19571 }
18088 19572
18089 19573
18090 TEST(SetErrorMessageForCodeGenFromStrings) { 19574 TEST(SetErrorMessageForCodeGenFromStrings) {
18091 LocalContext context; 19575 LocalContext context;
18092 v8::HandleScope scope(context->GetIsolate()); 19576 v8::HandleScope scope(context->GetIsolate());
18093 TryCatch try_catch(context->GetIsolate()); 19577 TryCatch try_catch(context->GetIsolate());
18094 19578
18095 Handle<String> message = v8_str("Message"); 19579 Local<String> message = v8_str("Message");
18096 Handle<String> expected_message = v8_str("Uncaught EvalError: Message"); 19580 Local<String> expected_message = v8_str("Uncaught EvalError: Message");
18097 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 19581 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
18098 context->AllowCodeGenerationFromStrings(false); 19582 context->AllowCodeGenerationFromStrings(false);
18099 context->SetErrorMessageForCodeGenerationFromStrings(message); 19583 context->SetErrorMessageForCodeGenerationFromStrings(message);
18100 Handle<Value> result = CompileRun("eval('42')"); 19584 Local<Value> result = CompileRun("eval('42')");
18101 CHECK(result.IsEmpty()); 19585 CHECK(result.IsEmpty());
18102 CHECK(try_catch.HasCaught()); 19586 CHECK(try_catch.HasCaught());
18103 Handle<String> actual_message = try_catch.Message()->Get(); 19587 Local<String> actual_message = try_catch.Message()->Get();
18104 CHECK(expected_message->Equals(actual_message)); 19588 CHECK(expected_message->Equals(actual_message));
18105 } 19589 }
18106 19590
18107 19591
18108 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { 19592 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
18109 } 19593 }
18110 19594
18111 19595
18112 THREADED_TEST(CallAPIFunctionOnNonObject) { 19596 THREADED_TEST(CallAPIFunctionOnNonObject) {
18113 LocalContext context; 19597 LocalContext context;
18114 v8::Isolate* isolate = context->GetIsolate(); 19598 v8::Isolate* isolate = context->GetIsolate();
18115 v8::HandleScope scope(isolate); 19599 v8::HandleScope scope(isolate);
18116 Handle<FunctionTemplate> templ = 19600 Local<FunctionTemplate> templ =
18117 v8::FunctionTemplate::New(isolate, NonObjectThis); 19601 v8::FunctionTemplate::New(isolate, NonObjectThis);
18118 Handle<Function> function = templ->GetFunction(); 19602 Local<Function> function =
18119 context->Global()->Set(v8_str("f"), function); 19603 templ->GetFunction(context.local()).ToLocalChecked();
19604 CHECK(context->Global()
19605 ->Set(context.local(), v8_str("f"), function)
19606 .FromJust());
18120 TryCatch try_catch(isolate); 19607 TryCatch try_catch(isolate);
18121 CompileRun("f.call(2)"); 19608 CompileRun("f.call(2)");
18122 } 19609 }
18123 19610
18124 19611
18125 // Regression test for issue 1470. 19612 // Regression test for issue 1470.
18126 THREADED_TEST(ReadOnlyIndexedProperties) { 19613 THREADED_TEST(ReadOnlyIndexedProperties) {
18127 v8::Isolate* isolate = CcTest::isolate(); 19614 v8::Isolate* isolate = CcTest::isolate();
18128 v8::HandleScope scope(isolate); 19615 v8::HandleScope scope(isolate);
18129 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19616 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
18130 19617
18131 LocalContext context; 19618 LocalContext context;
18132 Local<v8::Object> obj = templ->NewInstance(); 19619 Local<v8::Object> obj = templ->NewInstance(context.local()).ToLocalChecked();
18133 context->Global()->Set(v8_str("obj"), obj); 19620 CHECK(context->Global()->Set(context.local(), v8_str("obj"), obj).FromJust());
18134 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly); 19621 obj->ForceSet(v8_str("1"), v8_str("DONT_CHANGE"), v8::ReadOnly);
18135 obj->Set(v8_str("1"), v8_str("foobar")); 19622 obj->Set(v8_str("1"), v8_str("foobar"));
18136 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("1")))); 19623 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_str("1"))));
18137 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly); 19624 obj->ForceSet(v8_num(2), v8_str("DONT_CHANGE"), v8::ReadOnly);
18138 obj->Set(v8_num(2), v8_str("foobar")); 19625 obj->Set(v8_num(2), v8_str("foobar"));
18139 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_num(2)))); 19626 CHECK(v8_str("DONT_CHANGE")->Equals(obj->Get(v8_num(2))));
18140 19627
18141 // Test non-smi case. 19628 // Test non-smi case.
18142 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly); 19629 obj->ForceSet(v8_str("2000000000"), v8_str("DONT_CHANGE"), v8::ReadOnly);
18143 obj->Set(v8_str("2000000000"), v8_str("foobar")); 19630 obj->Set(v8_str("2000000000"), v8_str("foobar"));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
18202 protected_hidden_proto_template->SetHiddenPrototype(true); 19689 protected_hidden_proto_template->SetHiddenPrototype(true);
18203 19690
18204 // Context for "foreign" objects used in test. 19691 // Context for "foreign" objects used in test.
18205 Local<Context> context = v8::Context::New(isolate); 19692 Local<Context> context = v8::Context::New(isolate);
18206 context->Enter(); 19693 context->Enter();
18207 19694
18208 // Plain object, no security check. 19695 // Plain object, no security check.
18209 Local<Object> simple_object = Object::New(isolate); 19696 Local<Object> simple_object = Object::New(isolate);
18210 19697
18211 // Object with explicit security check. 19698 // Object with explicit security check.
18212 Local<Object> protected_object = no_proto_template->NewInstance(); 19699 Local<Object> protected_object =
19700 no_proto_template->NewInstance(context).ToLocalChecked();
18213 19701
18214 // JSGlobalProxy object, always have security check. 19702 // JSGlobalProxy object, always have security check.
18215 Local<Object> proxy_object = context->Global(); 19703 Local<Object> proxy_object = context->Global();
18216 19704
18217 // Global object, the prototype of proxy_object. No security checks. 19705 // Global object, the prototype of proxy_object. No security checks.
18218 Local<Object> global_object = proxy_object->GetPrototype()->ToObject(isolate); 19706 Local<Object> global_object = proxy_object->GetPrototype()->ToObject(isolate);
18219 19707
18220 // Hidden prototype without security check. 19708 // Hidden prototype without security check.
18221 Local<Object> hidden_prototype = 19709 Local<Object> hidden_prototype = hidden_proto_template->GetFunction(context)
18222 hidden_proto_template->GetFunction()->NewInstance(); 19710 .ToLocalChecked()
19711 ->NewInstance(context)
19712 .ToLocalChecked();
18223 Local<Object> object_with_hidden = 19713 Local<Object> object_with_hidden =
18224 Object::New(isolate); 19714 Object::New(isolate);
18225 object_with_hidden->SetPrototype(hidden_prototype); 19715 object_with_hidden->SetPrototype(hidden_prototype);
18226 19716
18227 context->Exit(); 19717 context->Exit();
18228 19718
18229 // Template for object for second context. Values to test are put on it as 19719 // Template for object for second context. Values to test are put on it as
18230 // properties. 19720 // properties.
18231 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate); 19721 Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate);
18232 global_template->Set(v8_str("simple"), simple_object); 19722 global_template->Set(v8_str("simple"), simple_object);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
18303 19793
18304 CompileRun("function ownfunc() { return { 0: this.id, " 19794 CompileRun("function ownfunc() { return { 0: this.id, "
18305 " 1: this, " 19795 " 1: this, "
18306 " toString: function() { " 19796 " toString: function() { "
18307 " return this[0];" 19797 " return this[0];"
18308 " }" 19798 " }"
18309 " };" 19799 " };"
18310 "}" 19800 "}"
18311 "var id = 'o';" 19801 "var id = 'o';"
18312 "ownfunc"); 19802 "ownfunc");
18313 context->Global()->Set(v8_str("func"), foreign_function); 19803 CHECK(context->Global()
19804 ->Set(context.local(), v8_str("func"), foreign_function)
19805 .FromJust());
18314 19806
18315 // Sanity check the contexts. 19807 // Sanity check the contexts.
18316 CHECK(i->Equals(foreign_context->Global()->Get(id))); 19808 CHECK(i->Equals(foreign_context->Global()->Get(id)));
18317 CHECK(o->Equals(context->Global()->Get(id))); 19809 CHECK(o->Equals(context->Global()->Get(id)));
18318 19810
18319 // Checking local function's receiver. 19811 // Checking local function's receiver.
18320 // Calling function using its call/apply methods. 19812 // Calling function using its call/apply methods.
18321 TestReceiver(o, context->Global(), "ownfunc.call()"); 19813 TestReceiver(o, context->Global(), "ownfunc.call()");
18322 TestReceiver(o, context->Global(), "ownfunc.apply()"); 19814 TestReceiver(o, context->Global(), "ownfunc.apply()");
18323 // Making calls through built-in functions. 19815 // Making calls through built-in functions.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
18366 } 19858 }
18367 19859
18368 19860
18369 void CallCompletedCallback2() { 19861 void CallCompletedCallback2() {
18370 v8::base::OS::Print("Firing callback 2.\n"); 19862 v8::base::OS::Print("Firing callback 2.\n");
18371 callback_fired ^= 2; // Toggle second bit. 19863 callback_fired ^= 2; // Toggle second bit.
18372 } 19864 }
18373 19865
18374 19866
18375 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) { 19867 void RecursiveCall(const v8::FunctionCallbackInfo<v8::Value>& args) {
18376 int32_t level = args[0]->Int32Value(); 19868 int32_t level =
19869 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust();
18377 if (level < 3) { 19870 if (level < 3) {
18378 level++; 19871 level++;
18379 v8::base::OS::Print("Entering recursion level %d.\n", level); 19872 v8::base::OS::Print("Entering recursion level %d.\n", level);
18380 char script[64]; 19873 char script[64];
18381 i::Vector<char> script_vector(script, sizeof(script)); 19874 i::Vector<char> script_vector(script, sizeof(script));
18382 i::SNPrintF(script_vector, "recursion(%d)", level); 19875 i::SNPrintF(script_vector, "recursion(%d)", level);
18383 CompileRun(script_vector.start()); 19876 CompileRun(script_vector.start());
18384 v8::base::OS::Print("Leaving recursion level %d.\n", level); 19877 v8::base::OS::Print("Leaving recursion level %d.\n", level);
18385 CHECK_EQ(0, callback_fired); 19878 CHECK_EQ(0, callback_fired);
18386 } else { 19879 } else {
18387 v8::base::OS::Print("Recursion ends.\n"); 19880 v8::base::OS::Print("Recursion ends.\n");
18388 CHECK_EQ(0, callback_fired); 19881 CHECK_EQ(0, callback_fired);
18389 } 19882 }
18390 } 19883 }
18391 19884
18392 19885
18393 TEST(CallCompletedCallback) { 19886 TEST(CallCompletedCallback) {
18394 LocalContext env; 19887 LocalContext env;
18395 v8::HandleScope scope(env->GetIsolate()); 19888 v8::HandleScope scope(env->GetIsolate());
18396 v8::Handle<v8::FunctionTemplate> recursive_runtime = 19889 v8::Local<v8::FunctionTemplate> recursive_runtime =
18397 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall); 19890 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall);
18398 env->Global()->Set(v8_str("recursion"), 19891 env->Global()->Set(
18399 recursive_runtime->GetFunction()); 19892 v8_str("recursion"),
19893 recursive_runtime->GetFunction(env.local()).ToLocalChecked());
18400 // Adding the same callback a second time has no effect. 19894 // Adding the same callback a second time has no effect.
18401 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); 19895 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
18402 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1); 19896 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback1);
18403 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2); 19897 env->GetIsolate()->AddCallCompletedCallback(CallCompletedCallback2);
18404 v8::base::OS::Print("--- Script (1) ---\n"); 19898 v8::base::OS::Print("--- Script (1) ---\n");
18405 Local<Script> script = v8::Script::Compile( 19899 Local<Script> script = v8::Script::Compile(v8_str("recursion(0)"));
18406 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
18407 script->Run(); 19900 script->Run();
18408 CHECK_EQ(3, callback_fired); 19901 CHECK_EQ(3, callback_fired);
18409 19902
18410 v8::base::OS::Print("\n--- Script (2) ---\n"); 19903 v8::base::OS::Print("\n--- Script (2) ---\n");
18411 callback_fired = 0; 19904 callback_fired = 0;
18412 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1); 19905 env->GetIsolate()->RemoveCallCompletedCallback(CallCompletedCallback1);
18413 script->Run(); 19906 script->Run();
18414 CHECK_EQ(2, callback_fired); 19907 CHECK_EQ(2, callback_fired);
18415 19908
18416 v8::base::OS::Print("\n--- Function ---\n"); 19909 v8::base::OS::Print("\n--- Function ---\n");
18417 callback_fired = 0; 19910 callback_fired = 0;
18418 Local<Function> recursive_function = 19911 Local<Function> recursive_function =
18419 Local<Function>::Cast(env->Global()->Get(v8_str("recursion"))); 19912 Local<Function>::Cast(env->Global()->Get(v8_str("recursion")));
18420 v8::Handle<Value> args[] = { v8_num(0) }; 19913 v8::Local<Value> args[] = {v8_num(0)};
18421 recursive_function->Call(env->Global(), 1, args); 19914 recursive_function->Call(env->Global(), 1, args);
18422 CHECK_EQ(2, callback_fired); 19915 CHECK_EQ(2, callback_fired);
18423 } 19916 }
18424 19917
18425 19918
18426 void CallCompletedCallbackNoException() { 19919 void CallCompletedCallbackNoException() {
18427 v8::HandleScope scope(CcTest::isolate()); 19920 v8::HandleScope scope(CcTest::isolate());
18428 CompileRun("1+1;"); 19921 CompileRun("1+1;");
18429 } 19922 }
18430 19923
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
18471 } 19964 }
18472 19965
18473 19966
18474 TEST(EnqueueMicrotask) { 19967 TEST(EnqueueMicrotask) {
18475 LocalContext env; 19968 LocalContext env;
18476 v8::HandleScope scope(env->GetIsolate()); 19969 v8::HandleScope scope(env->GetIsolate());
18477 CompileRun( 19970 CompileRun(
18478 "var ext1Calls = 0;" 19971 "var ext1Calls = 0;"
18479 "var ext2Calls = 0;"); 19972 "var ext2Calls = 0;");
18480 CompileRun("1+1;"); 19973 CompileRun("1+1;");
18481 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); 19974 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18482 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 19975 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18483 19976
18484 env->GetIsolate()->EnqueueMicrotask( 19977 env->GetIsolate()->EnqueueMicrotask(
18485 Function::New(env->GetIsolate(), MicrotaskOne)); 19978 Function::New(env->GetIsolate(), MicrotaskOne));
18486 CompileRun("1+1;"); 19979 CompileRun("1+1;");
18487 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 19980 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18488 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 19981 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18489 19982
18490 env->GetIsolate()->EnqueueMicrotask( 19983 env->GetIsolate()->EnqueueMicrotask(
18491 Function::New(env->GetIsolate(), MicrotaskOne)); 19984 Function::New(env->GetIsolate(), MicrotaskOne));
18492 env->GetIsolate()->EnqueueMicrotask( 19985 env->GetIsolate()->EnqueueMicrotask(
18493 Function::New(env->GetIsolate(), MicrotaskTwo)); 19986 Function::New(env->GetIsolate(), MicrotaskTwo));
18494 CompileRun("1+1;"); 19987 CompileRun("1+1;");
18495 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 19988 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18496 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 19989 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18497 19990
18498 env->GetIsolate()->EnqueueMicrotask( 19991 env->GetIsolate()->EnqueueMicrotask(
18499 Function::New(env->GetIsolate(), MicrotaskTwo)); 19992 Function::New(env->GetIsolate(), MicrotaskTwo));
18500 CompileRun("1+1;"); 19993 CompileRun("1+1;");
18501 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 19994 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18502 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 19995 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18503 19996
18504 CompileRun("1+1;"); 19997 CompileRun("1+1;");
18505 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 19998 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18506 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 19999 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18507 20000
18508 g_passed_to_three = NULL; 20001 g_passed_to_three = NULL;
18509 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree); 20002 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree);
18510 CompileRun("1+1;"); 20003 CompileRun("1+1;");
18511 CHECK(!g_passed_to_three); 20004 CHECK(!g_passed_to_three);
18512 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20005 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18513 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 20006 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18514 20007
18515 int dummy; 20008 int dummy;
18516 env->GetIsolate()->EnqueueMicrotask( 20009 env->GetIsolate()->EnqueueMicrotask(
18517 Function::New(env->GetIsolate(), MicrotaskOne)); 20010 Function::New(env->GetIsolate(), MicrotaskOne));
18518 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy); 20011 env->GetIsolate()->EnqueueMicrotask(MicrotaskThree, &dummy);
18519 env->GetIsolate()->EnqueueMicrotask( 20012 env->GetIsolate()->EnqueueMicrotask(
18520 Function::New(env->GetIsolate(), MicrotaskTwo)); 20013 Function::New(env->GetIsolate(), MicrotaskTwo));
18521 CompileRun("1+1;"); 20014 CompileRun("1+1;");
18522 CHECK_EQ(&dummy, g_passed_to_three); 20015 CHECK_EQ(&dummy, g_passed_to_three);
18523 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value()); 20016 CHECK_EQ(3, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18524 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 20017 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18525 g_passed_to_three = NULL; 20018 g_passed_to_three = NULL;
18526 } 20019 }
18527 20020
18528 20021
18529 static void MicrotaskExceptionOne( 20022 static void MicrotaskExceptionOne(
18530 const v8::FunctionCallbackInfo<Value>& info) { 20023 const v8::FunctionCallbackInfo<Value>& info) {
18531 v8::HandleScope scope(info.GetIsolate()); 20024 v8::HandleScope scope(info.GetIsolate());
18532 CompileRun("exception1Calls++;"); 20025 CompileRun("exception1Calls++;");
18533 info.GetIsolate()->ThrowException( 20026 info.GetIsolate()->ThrowException(
18534 v8::Exception::Error(v8_str("first"))); 20027 v8::Exception::Error(v8_str("first")));
(...skipping 16 matching lines...) Expand all
18551 CompileRun( 20044 CompileRun(
18552 "var exception1Calls = 0;" 20045 "var exception1Calls = 0;"
18553 "var exception2Calls = 0;"); 20046 "var exception2Calls = 0;");
18554 isolate->EnqueueMicrotask( 20047 isolate->EnqueueMicrotask(
18555 Function::New(isolate, MicrotaskExceptionOne)); 20048 Function::New(isolate, MicrotaskExceptionOne));
18556 isolate->EnqueueMicrotask( 20049 isolate->EnqueueMicrotask(
18557 Function::New(isolate, MicrotaskExceptionTwo)); 20050 Function::New(isolate, MicrotaskExceptionTwo));
18558 TryCatch try_catch(isolate); 20051 TryCatch try_catch(isolate);
18559 CompileRun("1+1;"); 20052 CompileRun("1+1;");
18560 CHECK(!try_catch.HasCaught()); 20053 CHECK(!try_catch.HasCaught());
18561 CHECK_EQ(1, CompileRun("exception1Calls")->Int32Value()); 20054 CHECK_EQ(1,
18562 CHECK_EQ(1, CompileRun("exception2Calls")->Int32Value()); 20055 CompileRun("exception1Calls")->Int32Value(env.local()).FromJust());
20056 CHECK_EQ(1,
20057 CompileRun("exception2Calls")->Int32Value(env.local()).FromJust());
18563 } 20058 }
18564 20059
18565 20060
18566 TEST(SetAutorunMicrotasks) { 20061 TEST(SetAutorunMicrotasks) {
18567 LocalContext env; 20062 LocalContext env;
18568 v8::HandleScope scope(env->GetIsolate()); 20063 v8::HandleScope scope(env->GetIsolate());
18569 CompileRun( 20064 CompileRun(
18570 "var ext1Calls = 0;" 20065 "var ext1Calls = 0;"
18571 "var ext2Calls = 0;"); 20066 "var ext2Calls = 0;");
18572 CompileRun("1+1;"); 20067 CompileRun("1+1;");
18573 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value()); 20068 CHECK_EQ(0, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18574 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 20069 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18575 20070
18576 env->GetIsolate()->EnqueueMicrotask( 20071 env->GetIsolate()->EnqueueMicrotask(
18577 Function::New(env->GetIsolate(), MicrotaskOne)); 20072 Function::New(env->GetIsolate(), MicrotaskOne));
18578 CompileRun("1+1;"); 20073 CompileRun("1+1;");
18579 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 20074 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18580 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 20075 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18581 20076
18582 env->GetIsolate()->SetAutorunMicrotasks(false); 20077 env->GetIsolate()->SetAutorunMicrotasks(false);
18583 env->GetIsolate()->EnqueueMicrotask( 20078 env->GetIsolate()->EnqueueMicrotask(
18584 Function::New(env->GetIsolate(), MicrotaskOne)); 20079 Function::New(env->GetIsolate(), MicrotaskOne));
18585 env->GetIsolate()->EnqueueMicrotask( 20080 env->GetIsolate()->EnqueueMicrotask(
18586 Function::New(env->GetIsolate(), MicrotaskTwo)); 20081 Function::New(env->GetIsolate(), MicrotaskTwo));
18587 CompileRun("1+1;"); 20082 CompileRun("1+1;");
18588 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 20083 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18589 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value()); 20084 CHECK_EQ(0, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18590 20085
18591 env->GetIsolate()->RunMicrotasks(); 20086 env->GetIsolate()->RunMicrotasks();
18592 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20087 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18593 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 20088 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18594 20089
18595 env->GetIsolate()->EnqueueMicrotask( 20090 env->GetIsolate()->EnqueueMicrotask(
18596 Function::New(env->GetIsolate(), MicrotaskTwo)); 20091 Function::New(env->GetIsolate(), MicrotaskTwo));
18597 CompileRun("1+1;"); 20092 CompileRun("1+1;");
18598 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20093 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18599 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value()); 20094 CHECK_EQ(1, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18600 20095
18601 env->GetIsolate()->RunMicrotasks(); 20096 env->GetIsolate()->RunMicrotasks();
18602 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20097 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18603 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value()); 20098 CHECK_EQ(2, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18604 20099
18605 env->GetIsolate()->SetAutorunMicrotasks(true); 20100 env->GetIsolate()->SetAutorunMicrotasks(true);
18606 env->GetIsolate()->EnqueueMicrotask( 20101 env->GetIsolate()->EnqueueMicrotask(
18607 Function::New(env->GetIsolate(), MicrotaskTwo)); 20102 Function::New(env->GetIsolate(), MicrotaskTwo));
18608 CompileRun("1+1;"); 20103 CompileRun("1+1;");
18609 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20104 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18610 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 20105 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18611 20106
18612 env->GetIsolate()->EnqueueMicrotask( 20107 env->GetIsolate()->EnqueueMicrotask(
18613 Function::New(env->GetIsolate(), MicrotaskTwo)); 20108 Function::New(env->GetIsolate(), MicrotaskTwo));
18614 { 20109 {
18615 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate()); 20110 v8::Isolate::SuppressMicrotaskExecutionScope scope(env->GetIsolate());
18616 CompileRun("1+1;"); 20111 CompileRun("1+1;");
18617 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20112 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18618 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value()); 20113 CHECK_EQ(3, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18619 } 20114 }
18620 20115
18621 CompileRun("1+1;"); 20116 CompileRun("1+1;");
18622 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value()); 20117 CHECK_EQ(2, CompileRun("ext1Calls")->Int32Value(env.local()).FromJust());
18623 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value()); 20118 CHECK_EQ(4, CompileRun("ext2Calls")->Int32Value(env.local()).FromJust());
18624 } 20119 }
18625 20120
18626 20121
18627 TEST(RunMicrotasksWithoutEnteringContext) { 20122 TEST(RunMicrotasksWithoutEnteringContext) {
18628 v8::Isolate* isolate = CcTest::isolate(); 20123 v8::Isolate* isolate = CcTest::isolate();
18629 HandleScope handle_scope(isolate); 20124 HandleScope handle_scope(isolate);
18630 isolate->SetAutorunMicrotasks(false); 20125 isolate->SetAutorunMicrotasks(false);
18631 Handle<Context> context = Context::New(isolate); 20126 Local<Context> context = Context::New(isolate);
18632 { 20127 {
18633 Context::Scope context_scope(context); 20128 Context::Scope context_scope(context);
18634 CompileRun("var ext1Calls = 0;"); 20129 CompileRun("var ext1Calls = 0;");
18635 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne)); 20130 isolate->EnqueueMicrotask(Function::New(isolate, MicrotaskOne));
18636 } 20131 }
18637 isolate->RunMicrotasks(); 20132 isolate->RunMicrotasks();
18638 { 20133 {
18639 Context::Scope context_scope(context); 20134 Context::Scope context_scope(context);
18640 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value()); 20135 CHECK_EQ(1, CompileRun("ext1Calls")->Int32Value(context).FromJust());
18641 } 20136 }
18642 isolate->SetAutorunMicrotasks(true); 20137 isolate->SetAutorunMicrotasks(true);
18643 } 20138 }
18644 20139
18645 20140
18646 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) { 20141 static void DebugEventInObserver(const v8::Debug::EventDetails& event_details) {
18647 v8::DebugEvent event = event_details.GetEvent(); 20142 v8::DebugEvent event = event_details.GetEvent();
18648 if (event != v8::Break) return; 20143 if (event != v8::Break) return;
18649 Handle<Object> exec_state = event_details.GetExecutionState(); 20144 Local<Object> exec_state = event_details.GetExecutionState();
18650 Handle<Value> break_id = exec_state->Get(v8_str("break_id")); 20145 Local<Value> break_id = exec_state->Get(v8_str("break_id"));
18651 CompileRun("function f(id) { new FrameDetails(id, 0); }"); 20146 CompileRun("function f(id) { new FrameDetails(id, 0); }");
18652 Handle<Function> fun = 20147 Local<Function> fun =
18653 Handle<Function>::Cast(CcTest::global()->Get(v8_str("f"))); 20148 Local<Function>::Cast(CcTest::global()->Get(v8_str("f")));
18654 fun->Call(CcTest::global(), 1, &break_id); 20149 fun->Call(CcTest::global(), 1, &break_id);
18655 } 20150 }
18656 20151
18657 20152
18658 TEST(Regress385349) { 20153 TEST(Regress385349) {
18659 i::FLAG_allow_natives_syntax = true; 20154 i::FLAG_allow_natives_syntax = true;
18660 v8::Isolate* isolate = CcTest::isolate(); 20155 v8::Isolate* isolate = CcTest::isolate();
18661 HandleScope handle_scope(isolate); 20156 HandleScope handle_scope(isolate);
18662 isolate->SetAutorunMicrotasks(false); 20157 isolate->SetAutorunMicrotasks(false);
18663 Handle<Context> context = Context::New(isolate); 20158 Local<Context> context = Context::New(isolate);
18664 v8::Debug::SetDebugEventListener(DebugEventInObserver); 20159 v8::Debug::SetDebugEventListener(DebugEventInObserver);
18665 { 20160 {
18666 Context::Scope context_scope(context); 20161 Context::Scope context_scope(context);
18667 CompileRun("var obj = {};" 20162 CompileRun("var obj = {};"
18668 "Object.observe(obj, function(changes) { debugger; });" 20163 "Object.observe(obj, function(changes) { debugger; });"
18669 "obj.a = 0;"); 20164 "obj.a = 0;");
18670 } 20165 }
18671 isolate->RunMicrotasks(); 20166 isolate->RunMicrotasks();
18672 isolate->SetAutorunMicrotasks(true); 20167 isolate->SetAutorunMicrotasks(true);
18673 v8::Debug::SetDebugEventListener(NULL); 20168 v8::Debug::SetDebugEventListener(NULL);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
18916 } 20411 }
18917 20412
18918 20413
18919 THREADED_TEST(InstanceCheckOnInstanceAccessor) { 20414 THREADED_TEST(InstanceCheckOnInstanceAccessor) {
18920 v8::internal::FLAG_allow_natives_syntax = true; 20415 v8::internal::FLAG_allow_natives_syntax = true;
18921 LocalContext context; 20416 LocalContext context;
18922 v8::HandleScope scope(context->GetIsolate()); 20417 v8::HandleScope scope(context->GetIsolate());
18923 20418
18924 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 20419 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
18925 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20420 Local<ObjectTemplate> inst = templ->InstanceTemplate();
18926 inst->SetAccessor(v8_str("foo"), 20421 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter,
18927 InstanceCheckedGetter, InstanceCheckedSetter, 20422 Local<Value>(), v8::DEFAULT, v8::None,
18928 Handle<Value>(),
18929 v8::DEFAULT,
18930 v8::None,
18931 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20423 v8::AccessorSignature::New(context->GetIsolate(), templ));
18932 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20424 CHECK(context->Global()
20425 ->Set(context.local(), v8_str("f"),
20426 templ->GetFunction(context.local()).ToLocalChecked())
20427 .FromJust());
18933 20428
18934 printf("Testing positive ...\n"); 20429 printf("Testing positive ...\n");
18935 CompileRun("var obj = new f();"); 20430 CompileRun("var obj = new f();");
18936 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20431 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18937 CheckInstanceCheckedAccessors(true); 20432 CheckInstanceCheckedAccessors(true);
18938 20433
18939 printf("Testing negative ...\n"); 20434 printf("Testing negative ...\n");
18940 CompileRun("var obj = {};" 20435 CompileRun("var obj = {};"
18941 "obj.__proto__ = new f();"); 20436 "obj.__proto__ = new f();");
18942 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20437 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
(...skipping 12 matching lines...) Expand all
18955 20450
18956 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { 20451 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
18957 v8::internal::FLAG_allow_natives_syntax = true; 20452 v8::internal::FLAG_allow_natives_syntax = true;
18958 LocalContext context; 20453 LocalContext context;
18959 v8::HandleScope scope(context->GetIsolate()); 20454 v8::HandleScope scope(context->GetIsolate());
18960 20455
18961 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 20456 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
18962 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20457 Local<ObjectTemplate> inst = templ->InstanceTemplate();
18963 templ->InstanceTemplate()->SetNamedPropertyHandler(EmptyInterceptorGetter, 20458 templ->InstanceTemplate()->SetNamedPropertyHandler(EmptyInterceptorGetter,
18964 EmptyInterceptorSetter); 20459 EmptyInterceptorSetter);
18965 inst->SetAccessor(v8_str("foo"), 20460 inst->SetAccessor(v8_str("foo"), InstanceCheckedGetter, InstanceCheckedSetter,
18966 InstanceCheckedGetter, InstanceCheckedSetter, 20461 Local<Value>(), v8::DEFAULT, v8::None,
18967 Handle<Value>(),
18968 v8::DEFAULT,
18969 v8::None,
18970 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20462 v8::AccessorSignature::New(context->GetIsolate(), templ));
18971 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20463 CHECK(context->Global()
20464 ->Set(context.local(), v8_str("f"),
20465 templ->GetFunction(context.local()).ToLocalChecked())
20466 .FromJust());
18972 20467
18973 printf("Testing positive ...\n"); 20468 printf("Testing positive ...\n");
18974 CompileRun("var obj = new f();"); 20469 CompileRun("var obj = new f();");
18975 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20470 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18976 CheckInstanceCheckedAccessors(true); 20471 CheckInstanceCheckedAccessors(true);
18977 20472
18978 printf("Testing negative ...\n"); 20473 printf("Testing negative ...\n");
18979 CompileRun("var obj = {};" 20474 CompileRun("var obj = {};"
18980 "obj.__proto__ = new f();"); 20475 "obj.__proto__ = new f();");
18981 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20476 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
18982 CheckInstanceCheckedAccessors(false); 20477 CheckInstanceCheckedAccessors(false);
18983 } 20478 }
18984 20479
18985 20480
18986 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { 20481 THREADED_TEST(InstanceCheckOnPrototypeAccessor) {
18987 v8::internal::FLAG_allow_natives_syntax = true; 20482 v8::internal::FLAG_allow_natives_syntax = true;
18988 LocalContext context; 20483 LocalContext context;
18989 v8::HandleScope scope(context->GetIsolate()); 20484 v8::HandleScope scope(context->GetIsolate());
18990 20485
18991 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate()); 20486 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
18992 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); 20487 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
18993 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter, 20488 proto->SetAccessor(v8_str("foo"), InstanceCheckedGetter,
18994 InstanceCheckedSetter, Handle<Value>(), v8::DEFAULT, 20489 InstanceCheckedSetter, Local<Value>(), v8::DEFAULT,
18995 v8::None, 20490 v8::None,
18996 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20491 v8::AccessorSignature::New(context->GetIsolate(), templ));
18997 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20492 CHECK(context->Global()
20493 ->Set(context.local(), v8_str("f"),
20494 templ->GetFunction(context.local()).ToLocalChecked())
20495 .FromJust());
18998 20496
18999 printf("Testing positive ...\n"); 20497 printf("Testing positive ...\n");
19000 CompileRun("var obj = new f();"); 20498 CompileRun("var obj = new f();");
19001 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20499 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
19002 CheckInstanceCheckedAccessors(true); 20500 CheckInstanceCheckedAccessors(true);
19003 20501
19004 printf("Testing negative ...\n"); 20502 printf("Testing negative ...\n");
19005 CompileRun("var obj = {};" 20503 CompileRun("var obj = {};"
19006 "obj.__proto__ = new f();"); 20504 "obj.__proto__ = new f();");
19007 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20505 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
19067 LocalContext context; 20565 LocalContext context;
19068 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate()); 20566 Local<ObjectTemplate> templ = ObjectTemplate::New(context->GetIsolate());
19069 if (interceptor) { 20567 if (interceptor) {
19070 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor, 20568 templ->SetHandler(v8::NamedPropertyHandlerConfiguration(FooGetInterceptor,
19071 FooSetInterceptor)); 20569 FooSetInterceptor));
19072 } else { 20570 } else {
19073 templ->SetAccessor(v8_str("foo"), 20571 templ->SetAccessor(v8_str("foo"),
19074 GetterWhichReturns42, 20572 GetterWhichReturns42,
19075 SetterWhichSetsYOnThisTo23); 20573 SetterWhichSetsYOnThisTo23);
19076 } 20574 }
19077 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20575 CHECK(context->Global()
20576 ->Set(context.local(), v8_str("obj"),
20577 templ->NewInstance(context.local()).ToLocalChecked())
20578 .FromJust());
19078 20579
19079 // Turn monomorphic on slow object with native accessor, then turn 20580 // Turn monomorphic on slow object with native accessor, then turn
19080 // polymorphic, finally optimize to create negative lookup and fail. 20581 // polymorphic, finally optimize to create negative lookup and fail.
19081 CompileRun(do_store ? 20582 CompileRun(do_store ?
19082 "function f(x) { x.foo = void 0; }" : 20583 "function f(x) { x.foo = void 0; }" :
19083 "function f(x) { return x.foo; }"); 20584 "function f(x) { return x.foo; }");
19084 CompileRun("obj.y = void 0;"); 20585 CompileRun("obj.y = void 0;");
19085 if (!interceptor) { 20586 if (!interceptor) {
19086 CompileRun("%OptimizeObjectForAddingMultipleProperties(obj, 1);"); 20587 CompileRun("%OptimizeObjectForAddingMultipleProperties(obj, 1);");
19087 } 20588 }
19088 CompileRun("obj.__proto__ = null;" 20589 CompileRun("obj.__proto__ = null;"
19089 "f(obj); f(obj); f(obj);"); 20590 "f(obj); f(obj); f(obj);");
19090 if (polymorphic) { 20591 if (polymorphic) {
19091 CompileRun("f({});"); 20592 CompileRun("f({});");
19092 } 20593 }
19093 CompileRun("obj.y = void 0;" 20594 CompileRun("obj.y = void 0;"
19094 "%OptimizeFunctionOnNextCall(f);"); 20595 "%OptimizeFunctionOnNextCall(f);");
19095 if (remove_accessor) { 20596 if (remove_accessor) {
19096 CompileRun("delete obj.foo;"); 20597 CompileRun("delete obj.foo;");
19097 } 20598 }
19098 CompileRun("var result = f(obj);"); 20599 CompileRun("var result = f(obj);");
19099 if (do_store) { 20600 if (do_store) {
19100 CompileRun("result = obj.y;"); 20601 CompileRun("result = obj.y;");
19101 } 20602 }
19102 if (remove_accessor && !interceptor) { 20603 if (remove_accessor && !interceptor) {
19103 CHECK(context->Global()->Get(v8_str("result"))->IsUndefined()); 20604 CHECK(context->Global()->Get(v8_str("result"))->IsUndefined());
19104 } else { 20605 } else {
19105 CHECK_EQ(do_store ? 23 : 42, 20606 CHECK_EQ(do_store ? 23 : 42, context->Global()
19106 context->Global()->Get(v8_str("result"))->Int32Value()); 20607 ->Get(v8_str("result"))
20608 ->Int32Value(context.local())
20609 .FromJust());
19107 } 20610 }
19108 } 20611 }
19109 20612
19110 20613
19111 THREADED_TEST(Regress137002a) { 20614 THREADED_TEST(Regress137002a) {
19112 i::FLAG_allow_natives_syntax = true; 20615 i::FLAG_allow_natives_syntax = true;
19113 i::FLAG_compilation_cache = false; 20616 i::FLAG_compilation_cache = false;
19114 v8::HandleScope scope(CcTest::isolate()); 20617 v8::HandleScope scope(CcTest::isolate());
19115 for (int i = 0; i < 16; i++) { 20618 for (int i = 0; i < 16; i++) {
19116 Helper137002(i & 8, i & 4, i & 2, i & 1); 20619 Helper137002(i & 8, i & 4, i & 2, i & 1);
19117 } 20620 }
19118 } 20621 }
19119 20622
19120 20623
19121 THREADED_TEST(Regress137002b) { 20624 THREADED_TEST(Regress137002b) {
19122 i::FLAG_allow_natives_syntax = true; 20625 i::FLAG_allow_natives_syntax = true;
19123 LocalContext context; 20626 LocalContext context;
19124 v8::Isolate* isolate = context->GetIsolate(); 20627 v8::Isolate* isolate = context->GetIsolate();
19125 v8::HandleScope scope(isolate); 20628 v8::HandleScope scope(isolate);
19126 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 20629 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19127 templ->SetAccessor(v8_str("foo"), 20630 templ->SetAccessor(v8_str("foo"),
19128 GetterWhichReturns42, 20631 GetterWhichReturns42,
19129 SetterWhichSetsYOnThisTo23); 20632 SetterWhichSetsYOnThisTo23);
19130 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20633 CHECK(context->Global()
20634 ->Set(context.local(), v8_str("obj"),
20635 templ->NewInstance(context.local()).ToLocalChecked())
20636 .FromJust());
19131 20637
19132 // Turn monomorphic on slow object with native accessor, then just 20638 // Turn monomorphic on slow object with native accessor, then just
19133 // delete the property and fail. 20639 // delete the property and fail.
19134 CompileRun("function load(x) { return x.foo; }" 20640 CompileRun("function load(x) { return x.foo; }"
19135 "function store(x) { x.foo = void 0; }" 20641 "function store(x) { x.foo = void 0; }"
19136 "function keyed_load(x, key) { return x[key]; }" 20642 "function keyed_load(x, key) { return x[key]; }"
19137 // Second version of function has a different source (add void 0) 20643 // Second version of function has a different source (add void 0)
19138 // so that it does not share code with the first version. This 20644 // so that it does not share code with the first version. This
19139 // ensures that the ICs are monomorphic. 20645 // ensures that the ICs are monomorphic.
19140 "function load2(x) { void 0; return x.foo; }" 20646 "function load2(x) { void 0; return x.foo; }"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
19189 20695
19190 THREADED_TEST(Regress142088) { 20696 THREADED_TEST(Regress142088) {
19191 i::FLAG_allow_natives_syntax = true; 20697 i::FLAG_allow_natives_syntax = true;
19192 LocalContext context; 20698 LocalContext context;
19193 v8::Isolate* isolate = context->GetIsolate(); 20699 v8::Isolate* isolate = context->GetIsolate();
19194 v8::HandleScope scope(isolate); 20700 v8::HandleScope scope(isolate);
19195 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 20701 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19196 templ->SetAccessor(v8_str("foo"), 20702 templ->SetAccessor(v8_str("foo"),
19197 GetterWhichReturns42, 20703 GetterWhichReturns42,
19198 SetterWhichSetsYOnThisTo23); 20704 SetterWhichSetsYOnThisTo23);
19199 context->Global()->Set(v8_str("obj"), templ->NewInstance()); 20705 CHECK(context->Global()
20706 ->Set(context.local(), v8_str("obj"),
20707 templ->NewInstance(context.local()).ToLocalChecked())
20708 .FromJust());
19200 20709
19201 CompileRun("function load(x) { return x.foo; }" 20710 CompileRun("function load(x) { return x.foo; }"
19202 "var o = Object.create(obj);" 20711 "var o = Object.create(obj);"
19203 "%OptimizeObjectForAddingMultipleProperties(obj, 1);" 20712 "%OptimizeObjectForAddingMultipleProperties(obj, 1);"
19204 "load(o); load(o); load(o); load(o);"); 20713 "load(o); load(o); load(o); load(o);");
19205 } 20714 }
19206 20715
19207 20716
19208 THREADED_TEST(Regress137496) { 20717 THREADED_TEST(Regress137496) {
19209 i::FLAG_expose_gc = true; 20718 i::FLAG_expose_gc = true;
19210 LocalContext context; 20719 LocalContext context;
19211 v8::HandleScope scope(context->GetIsolate()); 20720 v8::HandleScope scope(context->GetIsolate());
19212 20721
19213 // Compile a try-finally clause where the finally block causes a GC 20722 // Compile a try-finally clause where the finally block causes a GC
19214 // while there still is a message pending for external reporting. 20723 // while there still is a message pending for external reporting.
19215 TryCatch try_catch(context->GetIsolate()); 20724 TryCatch try_catch(context->GetIsolate());
19216 try_catch.SetVerbose(true); 20725 try_catch.SetVerbose(true);
19217 CompileRun("try { throw new Error(); } finally { gc(); }"); 20726 CompileRun("try { throw new Error(); } finally { gc(); }");
19218 CHECK(try_catch.HasCaught()); 20727 CHECK(try_catch.HasCaught());
19219 } 20728 }
19220 20729
19221 20730
19222 THREADED_TEST(Regress157124) { 20731 THREADED_TEST(Regress157124) {
19223 LocalContext context; 20732 LocalContext context;
19224 v8::Isolate* isolate = context->GetIsolate(); 20733 v8::Isolate* isolate = context->GetIsolate();
19225 v8::HandleScope scope(isolate); 20734 v8::HandleScope scope(isolate);
19226 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 20735 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19227 Local<Object> obj = templ->NewInstance(); 20736 Local<Object> obj = templ->NewInstance(context.local()).ToLocalChecked();
19228 obj->GetIdentityHash(); 20737 obj->GetIdentityHash();
19229 obj->DeletePrivate(context.local(), 20738 obj->DeletePrivate(context.local(),
19230 v8::Private::ForApi(isolate, v8_str("Bug"))) 20739 v8::Private::ForApi(isolate, v8_str("Bug")))
19231 .FromJust(); 20740 .FromJust();
19232 } 20741 }
19233 20742
19234 20743
19235 THREADED_TEST(Regress2535) { 20744 THREADED_TEST(Regress2535) {
19236 LocalContext context; 20745 LocalContext context;
19237 v8::HandleScope scope(context->GetIsolate()); 20746 v8::HandleScope scope(context->GetIsolate());
(...skipping 20 matching lines...) Expand all
19258 } 20767 }
19259 20768
19260 20769
19261 THREADED_TEST(Regress260106) { 20770 THREADED_TEST(Regress260106) {
19262 LocalContext context; 20771 LocalContext context;
19263 v8::Isolate* isolate = context->GetIsolate(); 20772 v8::Isolate* isolate = context->GetIsolate();
19264 v8::HandleScope scope(isolate); 20773 v8::HandleScope scope(isolate);
19265 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, 20774 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate,
19266 DummyCallHandler); 20775 DummyCallHandler);
19267 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); 20776 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;");
19268 Local<Function> function = templ->GetFunction(); 20777 Local<Function> function =
20778 templ->GetFunction(context.local()).ToLocalChecked();
19269 CHECK(!function.IsEmpty()); 20779 CHECK(!function.IsEmpty());
19270 CHECK(function->IsFunction()); 20780 CHECK(function->IsFunction());
19271 } 20781 }
19272 20782
19273 20783
19274 THREADED_TEST(JSONParseObject) { 20784 THREADED_TEST(JSONParseObject) {
19275 LocalContext context; 20785 LocalContext context;
19276 HandleScope scope(context->GetIsolate()); 20786 HandleScope scope(context->GetIsolate());
19277 Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}")); 20787 Local<Value> obj = v8::JSON::Parse(v8_str("{\"x\":42}"));
19278 Handle<Object> global = context->Global(); 20788 Local<Object> global = context->Global();
19279 global->Set(v8_str("obj"), obj); 20789 global->Set(v8_str("obj"), obj);
19280 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); 20790 ExpectString("JSON.stringify(obj)", "{\"x\":42}");
19281 } 20791 }
19282 20792
19283 20793
19284 THREADED_TEST(JSONParseNumber) { 20794 THREADED_TEST(JSONParseNumber) {
19285 LocalContext context; 20795 LocalContext context;
19286 HandleScope scope(context->GetIsolate()); 20796 HandleScope scope(context->GetIsolate());
19287 Local<Value> obj = v8::JSON::Parse(v8_str("42")); 20797 Local<Value> obj = v8::JSON::Parse(v8_str("42"));
19288 Handle<Object> global = context->Global(); 20798 Local<Object> global = context->Global();
19289 global->Set(v8_str("obj"), obj); 20799 global->Set(v8_str("obj"), obj);
19290 ExpectString("JSON.stringify(obj)", "42"); 20800 ExpectString("JSON.stringify(obj)", "42");
19291 } 20801 }
19292 20802
19293 20803
19294 #if V8_OS_POSIX && !V8_OS_NACL 20804 #if V8_OS_POSIX && !V8_OS_NACL
19295 class ThreadInterruptTest { 20805 class ThreadInterruptTest {
19296 public: 20806 public:
19297 ThreadInterruptTest() : sem_(0), sem_value_(0) { } 20807 ThreadInterruptTest() : sem_(0), sem_value_(0) { }
19298 ~ThreadInterruptTest() {} 20808 ~ThreadInterruptTest() {}
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
19360 } 20870 }
19361 20871
19362 20872
19363 TEST(JSONStringifyAccessCheck) { 20873 TEST(JSONStringifyAccessCheck) {
19364 v8::V8::Initialize(); 20874 v8::V8::Initialize();
19365 v8::Isolate* isolate = CcTest::isolate(); 20875 v8::Isolate* isolate = CcTest::isolate();
19366 v8::HandleScope scope(isolate); 20876 v8::HandleScope scope(isolate);
19367 20877
19368 // Create an ObjectTemplate for global objects and install access 20878 // Create an ObjectTemplate for global objects and install access
19369 // check callbacks that will block access. 20879 // check callbacks that will block access.
19370 v8::Handle<v8::ObjectTemplate> global_template = 20880 v8::Local<v8::ObjectTemplate> global_template =
19371 v8::ObjectTemplate::New(isolate); 20881 v8::ObjectTemplate::New(isolate);
19372 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); 20882 global_template->SetAccessCheckCallback(AccessAlwaysBlocked);
19373 20883
19374 // Create a context and set an x property on it's global object. 20884 // Create a context and set an x property on it's global object.
19375 LocalContext context0(NULL, global_template); 20885 LocalContext context0(NULL, global_template);
19376 v8::Handle<v8::Object> global0 = context0->Global(); 20886 v8::Local<v8::Object> global0 = context0->Global();
19377 global0->Set(v8_str("x"), v8_num(42)); 20887 global0->Set(v8_str("x"), v8_num(42));
19378 ExpectString("JSON.stringify(this)", "{\"x\":42}"); 20888 ExpectString("JSON.stringify(this)", "{\"x\":42}");
19379 20889
19380 for (int i = 0; i < 2; i++) { 20890 for (int i = 0; i < 2; i++) {
19381 if (i == 1) { 20891 if (i == 1) {
19382 // Install a toJSON function on the second run. 20892 // Install a toJSON function on the second run.
19383 v8::Handle<v8::FunctionTemplate> toJSON = 20893 v8::Local<v8::FunctionTemplate> toJSON =
19384 v8::FunctionTemplate::New(isolate, UnreachableCallback); 20894 v8::FunctionTemplate::New(isolate, UnreachableCallback);
19385 20895
19386 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); 20896 global0->Set(v8_str("toJSON"),
20897 toJSON->GetFunction(context0.local()).ToLocalChecked());
19387 } 20898 }
19388 // Create a context with a different security token so that the 20899 // Create a context with a different security token so that the
19389 // failed access check callback will be called on each access. 20900 // failed access check callback will be called on each access.
19390 LocalContext context1(NULL, global_template); 20901 LocalContext context1(NULL, global_template);
19391 context1->Global()->Set(v8_str("other"), global0); 20902 CHECK(context1->Global()
20903 ->Set(context1.local(), v8_str("other"), global0)
20904 .FromJust());
19392 20905
19393 CHECK(CompileRun("JSON.stringify(other)").IsEmpty()); 20906 CHECK(CompileRun("JSON.stringify(other)").IsEmpty());
19394 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty()); 20907 CHECK(CompileRun("JSON.stringify({ 'a' : other, 'b' : ['c'] })").IsEmpty());
19395 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty()); 20908 CHECK(CompileRun("JSON.stringify([other, 'b', 'c'])").IsEmpty());
19396 } 20909 }
19397 } 20910 }
19398 20911
19399 20912
19400 bool access_check_fail_thrown = false; 20913 bool access_check_fail_thrown = false;
19401 bool catch_callback_called = false; 20914 bool catch_callback_called = false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
19448 20961
19449 TEST(AccessCheckThrows) { 20962 TEST(AccessCheckThrows) {
19450 i::FLAG_allow_natives_syntax = true; 20963 i::FLAG_allow_natives_syntax = true;
19451 v8::V8::Initialize(); 20964 v8::V8::Initialize();
19452 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows); 20965 v8::V8::SetFailedAccessCheckCallbackFunction(&FailedAccessCheckThrows);
19453 v8::Isolate* isolate = CcTest::isolate(); 20966 v8::Isolate* isolate = CcTest::isolate();
19454 v8::HandleScope scope(isolate); 20967 v8::HandleScope scope(isolate);
19455 20968
19456 // Create an ObjectTemplate for global objects and install access 20969 // Create an ObjectTemplate for global objects and install access
19457 // check callbacks that will block access. 20970 // check callbacks that will block access.
19458 v8::Handle<v8::ObjectTemplate> global_template = 20971 v8::Local<v8::ObjectTemplate> global_template =
19459 v8::ObjectTemplate::New(isolate); 20972 v8::ObjectTemplate::New(isolate);
19460 global_template->SetAccessCheckCallback(AccessAlwaysBlocked); 20973 global_template->SetAccessCheckCallback(AccessAlwaysBlocked);
19461 20974
19462 // Create a context and set an x property on it's global object. 20975 // Create a context and set an x property on it's global object.
19463 LocalContext context0(NULL, global_template); 20976 LocalContext context0(NULL, global_template);
19464 v8::Handle<v8::Object> global0 = context0->Global(); 20977 v8::Local<v8::Object> global0 = context0->Global();
19465 20978
19466 // Create a context with a different security token so that the 20979 // Create a context with a different security token so that the
19467 // failed access check callback will be called on each access. 20980 // failed access check callback will be called on each access.
19468 LocalContext context1(NULL, global_template); 20981 LocalContext context1(NULL, global_template);
19469 context1->Global()->Set(v8_str("other"), global0); 20982 CHECK(context1->Global()
20983 ->Set(context1.local(), v8_str("other"), global0)
20984 .FromJust());
19470 20985
19471 v8::Handle<v8::FunctionTemplate> catcher_fun = 20986 v8::Local<v8::FunctionTemplate> catcher_fun =
19472 v8::FunctionTemplate::New(isolate, CatcherCallback); 20987 v8::FunctionTemplate::New(isolate, CatcherCallback);
19473 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); 20988 CHECK(context1->Global()
20989 ->Set(context1.local(), v8_str("catcher"),
20990 catcher_fun->GetFunction(context1.local()).ToLocalChecked())
20991 .FromJust());
19474 20992
19475 v8::Handle<v8::FunctionTemplate> has_own_property_fun = 20993 v8::Local<v8::FunctionTemplate> has_own_property_fun =
19476 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback); 20994 v8::FunctionTemplate::New(isolate, HasOwnPropertyCallback);
19477 context1->Global()->Set(v8_str("has_own_property"), 20995 CHECK(context1->Global()
19478 has_own_property_fun->GetFunction()); 20996 ->Set(context1.local(), v8_str("has_own_property"),
20997 has_own_property_fun->GetFunction(context1.local())
20998 .ToLocalChecked())
20999 .FromJust());
19479 21000
19480 { 21001 {
19481 v8::TryCatch try_catch(isolate); 21002 v8::TryCatch try_catch(isolate);
19482 access_check_fail_thrown = false; 21003 access_check_fail_thrown = false;
19483 CompileRun("other.x;"); 21004 CompileRun("other.x;");
19484 CHECK(access_check_fail_thrown); 21005 CHECK(access_check_fail_thrown);
19485 CHECK(try_catch.HasCaught()); 21006 CHECK(try_catch.HasCaught());
19486 } 21007 }
19487 21008
19488 CheckCorrectThrow("other.x"); 21009 CheckCorrectThrow("other.x");
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
19601 InterruptThread i_thread; 21122 InterruptThread i_thread;
19602 }; 21123 };
19603 21124
19604 21125
19605 class RequestInterruptTestWithFunctionCall 21126 class RequestInterruptTestWithFunctionCall
19606 : public RequestInterruptTestBaseWithSimpleInterrupt { 21127 : public RequestInterruptTestBaseWithSimpleInterrupt {
19607 public: 21128 public:
19608 virtual void TestBody() { 21129 virtual void TestBody() {
19609 Local<Function> func = Function::New( 21130 Local<Function> func = Function::New(
19610 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); 21131 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
19611 env_->Global()->Set(v8_str("ShouldContinue"), func); 21132 CHECK(env_->Global()
21133 ->Set(env_.local(), v8_str("ShouldContinue"), func)
21134 .FromJust());
19612 21135
19613 CompileRun("while (ShouldContinue()) { }"); 21136 CompileRun("while (ShouldContinue()) { }");
19614 } 21137 }
19615 }; 21138 };
19616 21139
19617 21140
19618 class RequestInterruptTestWithMethodCall 21141 class RequestInterruptTestWithMethodCall
19619 : public RequestInterruptTestBaseWithSimpleInterrupt { 21142 : public RequestInterruptTestBaseWithSimpleInterrupt {
19620 public: 21143 public:
19621 virtual void TestBody() { 21144 virtual void TestBody() {
19622 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21145 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
19623 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 21146 v8::Local<v8::Template> proto = t->PrototypeTemplate();
19624 proto->Set(v8_str("shouldContinue"), Function::New( 21147 proto->Set(v8_str("shouldContinue"), Function::New(
19625 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); 21148 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)));
19626 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); 21149 CHECK(env_->Global()
21150 ->Set(env_.local(), v8_str("Klass"),
21151 t->GetFunction(env_.local()).ToLocalChecked())
21152 .FromJust());
19627 21153
19628 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 21154 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
19629 } 21155 }
19630 }; 21156 };
19631 21157
19632 21158
19633 class RequestInterruptTestWithAccessor 21159 class RequestInterruptTestWithAccessor
19634 : public RequestInterruptTestBaseWithSimpleInterrupt { 21160 : public RequestInterruptTestBaseWithSimpleInterrupt {
19635 public: 21161 public:
19636 virtual void TestBody() { 21162 virtual void TestBody() {
19637 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21163 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
19638 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 21164 v8::Local<v8::Template> proto = t->PrototypeTemplate();
19639 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New( 21165 proto->SetAccessorProperty(v8_str("shouldContinue"), FunctionTemplate::New(
19640 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); 21166 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)));
19641 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); 21167 CHECK(env_->Global()
21168 ->Set(env_.local(), v8_str("Klass"),
21169 t->GetFunction(env_.local()).ToLocalChecked())
21170 .FromJust());
19642 21171
19643 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); 21172 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }");
19644 } 21173 }
19645 }; 21174 };
19646 21175
19647 21176
19648 class RequestInterruptTestWithNativeAccessor 21177 class RequestInterruptTestWithNativeAccessor
19649 : public RequestInterruptTestBaseWithSimpleInterrupt { 21178 : public RequestInterruptTestBaseWithSimpleInterrupt {
19650 public: 21179 public:
19651 virtual void TestBody() { 21180 virtual void TestBody() {
19652 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21181 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
19653 t->InstanceTemplate()->SetNativeDataProperty( 21182 t->InstanceTemplate()->SetNativeDataProperty(
19654 v8_str("shouldContinue"), 21183 v8_str("shouldContinue"),
19655 &ShouldContinueNativeGetter, 21184 &ShouldContinueNativeGetter,
19656 NULL, 21185 NULL,
19657 v8::External::New(isolate_, this)); 21186 v8::External::New(isolate_, this));
19658 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); 21187 CHECK(env_->Global()
21188 ->Set(env_.local(), v8_str("Klass"),
21189 t->GetFunction(env_.local()).ToLocalChecked())
21190 .FromJust());
19659 21191
19660 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }"); 21192 CompileRun("var obj = new Klass; while (obj.shouldContinue) { }");
19661 } 21193 }
19662 21194
19663 private: 21195 private:
19664 static void ShouldContinueNativeGetter( 21196 static void ShouldContinueNativeGetter(
19665 Local<String> property, 21197 Local<String> property,
19666 const v8::PropertyCallbackInfo<v8::Value>& info) { 21198 const v8::PropertyCallbackInfo<v8::Value>& info) {
19667 RequestInterruptTestBase* test = 21199 RequestInterruptTestBase* test =
19668 reinterpret_cast<RequestInterruptTestBase*>( 21200 reinterpret_cast<RequestInterruptTestBase*>(
19669 info.Data().As<v8::External>()->Value()); 21201 info.Data().As<v8::External>()->Value());
19670 info.GetReturnValue().Set(test->ShouldContinue()); 21202 info.GetReturnValue().Set(test->ShouldContinue());
19671 } 21203 }
19672 }; 21204 };
19673 21205
19674 21206
19675 class RequestInterruptTestWithMethodCallAndInterceptor 21207 class RequestInterruptTestWithMethodCallAndInterceptor
19676 : public RequestInterruptTestBaseWithSimpleInterrupt { 21208 : public RequestInterruptTestBaseWithSimpleInterrupt {
19677 public: 21209 public:
19678 virtual void TestBody() { 21210 virtual void TestBody() {
19679 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_); 21211 v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate_);
19680 v8::Local<v8::Template> proto = t->PrototypeTemplate(); 21212 v8::Local<v8::Template> proto = t->PrototypeTemplate();
19681 proto->Set(v8_str("shouldContinue"), Function::New( 21213 proto->Set(v8_str("shouldContinue"), Function::New(
19682 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this))); 21214 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)));
19683 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate(); 21215 v8::Local<v8::ObjectTemplate> instance_template = t->InstanceTemplate();
19684 instance_template->SetHandler( 21216 instance_template->SetHandler(
19685 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor)); 21217 v8::NamedPropertyHandlerConfiguration(EmptyInterceptor));
19686 21218
19687 env_->Global()->Set(v8_str("Klass"), t->GetFunction()); 21219 CHECK(env_->Global()
21220 ->Set(env_.local(), v8_str("Klass"),
21221 t->GetFunction(env_.local()).ToLocalChecked())
21222 .FromJust());
19688 21223
19689 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }"); 21224 CompileRun("var obj = new Klass; while (obj.shouldContinue()) { }");
19690 } 21225 }
19691 21226
19692 private: 21227 private:
19693 static void EmptyInterceptor( 21228 static void EmptyInterceptor(
19694 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {} 21229 Local<Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {}
19695 }; 21230 };
19696 21231
19697 21232
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
19784 public: 21319 public:
19785 RequestMultipleInterrupts() : i_thread(this), counter_(0) {} 21320 RequestMultipleInterrupts() : i_thread(this), counter_(0) {}
19786 21321
19787 virtual void StartInterruptThread() { 21322 virtual void StartInterruptThread() {
19788 i_thread.Start(); 21323 i_thread.Start();
19789 } 21324 }
19790 21325
19791 virtual void TestBody() { 21326 virtual void TestBody() {
19792 Local<Function> func = Function::New( 21327 Local<Function> func = Function::New(
19793 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this)); 21328 isolate_, ShouldContinueCallback, v8::External::New(isolate_, this));
19794 env_->Global()->Set(v8_str("ShouldContinue"), func); 21329 CHECK(env_->Global()
21330 ->Set(env_.local(), v8_str("ShouldContinue"), func)
21331 .FromJust());
19795 21332
19796 CompileRun("while (ShouldContinue()) { }"); 21333 CompileRun("while (ShouldContinue()) { }");
19797 } 21334 }
19798 21335
19799 private: 21336 private:
19800 class InterruptThread : public v8::base::Thread { 21337 class InterruptThread : public v8::base::Thread {
19801 public: 21338 public:
19802 enum { NUM_INTERRUPTS = 10 }; 21339 enum { NUM_INTERRUPTS = 10 };
19803 explicit InterruptThread(RequestMultipleInterrupts* test) 21340 explicit InterruptThread(RequestMultipleInterrupts* test)
19804 : Thread(Options("RequestInterruptTest")), test_(test) {} 21341 : Thread(Options("RequestInterruptTest")), test_(test) {}
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
19855 } 21392 }
19856 21393
19857 21394
19858 THREADED_TEST(FunctionNew) { 21395 THREADED_TEST(FunctionNew) {
19859 LocalContext env; 21396 LocalContext env;
19860 v8::Isolate* isolate = env->GetIsolate(); 21397 v8::Isolate* isolate = env->GetIsolate();
19861 v8::HandleScope scope(isolate); 21398 v8::HandleScope scope(isolate);
19862 Local<Object> data = v8::Object::New(isolate); 21399 Local<Object> data = v8::Object::New(isolate);
19863 function_new_expected_env = data; 21400 function_new_expected_env = data;
19864 Local<Function> func = Function::New(isolate, FunctionNewCallback, data); 21401 Local<Function> func = Function::New(isolate, FunctionNewCallback, data);
19865 env->Global()->Set(v8_str("func"), func); 21402 CHECK(env->Global()->Set(env.local(), v8_str("func"), func).FromJust());
19866 Local<Value> result = CompileRun("func();"); 21403 Local<Value> result = CompileRun("func();");
19867 CHECK(v8::Integer::New(isolate, 17)->Equals(result)); 21404 CHECK(v8::Integer::New(isolate, 17)->Equals(result));
19868 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 21405 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
19869 // Verify function not cached 21406 // Verify function not cached
19870 auto serial_number = handle( 21407 auto serial_number = handle(
19871 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func)) 21408 i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
19872 ->shared() 21409 ->shared()
19873 ->get_api_func_data() 21410 ->get_api_func_data()
19874 ->serial_number()), 21411 ->serial_number()),
19875 i_isolate); 21412 i_isolate);
19876 auto cache = i_isolate->function_cache(); 21413 auto cache = i_isolate->function_cache();
19877 CHECK(cache->Lookup(serial_number)->IsTheHole()); 21414 CHECK(cache->Lookup(serial_number)->IsTheHole());
19878 // Verify that each Function::New creates a new function instance 21415 // Verify that each Function::New creates a new function instance
19879 Local<Object> data2 = v8::Object::New(isolate); 21416 Local<Object> data2 = v8::Object::New(isolate);
19880 function_new_expected_env = data2; 21417 function_new_expected_env = data2;
19881 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2); 21418 Local<Function> func2 = Function::New(isolate, FunctionNewCallback, data2);
19882 CHECK(!func2->IsNull()); 21419 CHECK(!func2->IsNull());
19883 CHECK(!func->Equals(func2)); 21420 CHECK(!func->Equals(func2));
19884 env->Global()->Set(v8_str("func2"), func2); 21421 CHECK(env->Global()->Set(env.local(), v8_str("func2"), func2).FromJust());
19885 Local<Value> result2 = CompileRun("func2();"); 21422 Local<Value> result2 = CompileRun("func2();");
19886 CHECK(v8::Integer::New(isolate, 17)->Equals(result2)); 21423 CHECK(v8::Integer::New(isolate, 17)->Equals(result2));
19887 } 21424 }
19888 21425
19889 21426
19890 TEST(EscapeableHandleScope) { 21427 TEST(EscapeableHandleScope) {
19891 HandleScope outer_scope(CcTest::isolate()); 21428 HandleScope outer_scope(CcTest::isolate());
19892 LocalContext context; 21429 LocalContext context;
19893 const int runs = 10; 21430 const int runs = 10;
19894 Local<String> values[runs]; 21431 Local<String> values[runs];
(...skipping 19 matching lines...) Expand all
19914 CHECK(info.Holder() != info.This()); 21451 CHECK(info.Holder() != info.This());
19915 } 21452 }
19916 21453
19917 21454
19918 TEST(Regress239669) { 21455 TEST(Regress239669) {
19919 LocalContext context; 21456 LocalContext context;
19920 v8::Isolate* isolate = context->GetIsolate(); 21457 v8::Isolate* isolate = context->GetIsolate();
19921 v8::HandleScope scope(isolate); 21458 v8::HandleScope scope(isolate);
19922 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 21459 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19923 templ->SetAccessor(v8_str("x"), 0, SetterWhichExpectsThisAndHolderToDiffer); 21460 templ->SetAccessor(v8_str("x"), 0, SetterWhichExpectsThisAndHolderToDiffer);
19924 context->Global()->Set(v8_str("P"), templ->NewInstance()); 21461 CHECK(context->Global()
21462 ->Set(context.local(), v8_str("P"),
21463 templ->NewInstance(context.local()).ToLocalChecked())
21464 .FromJust());
19925 CompileRun( 21465 CompileRun(
19926 "function C1() {" 21466 "function C1() {"
19927 " this.x = 23;" 21467 " this.x = 23;"
19928 "};" 21468 "};"
19929 "C1.prototype = P;" 21469 "C1.prototype = P;"
19930 "for (var i = 0; i < 4; i++ ) {" 21470 "for (var i = 0; i < 4; i++ ) {"
19931 " new C1();" 21471 " new C1();"
19932 "}"); 21472 "}");
19933 } 21473 }
19934 21474
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
19998 signature = v8::Signature::New(isolate, parent_template); 21538 signature = v8::Signature::New(isolate, parent_template);
19999 break; 21539 break;
20000 } 21540 }
20001 signature_template = function_template->InstanceTemplate(); 21541 signature_template = function_template->InstanceTemplate();
20002 } 21542 }
20003 // Global object must pass checks. 21543 // Global object must pass checks.
20004 Local<v8::Context> context = 21544 Local<v8::Context> context =
20005 v8::Context::New(isolate, NULL, signature_template); 21545 v8::Context::New(isolate, NULL, signature_template);
20006 v8::Context::Scope context_scope(context); 21546 v8::Context::Scope context_scope(context);
20007 // Install regular object that can pass signature checks. 21547 // Install regular object that can pass signature checks.
20008 Local<Object> function_receiver = signature_template->NewInstance(); 21548 Local<Object> function_receiver =
20009 context->Global()->Set(v8_str("function_receiver"), function_receiver); 21549 signature_template->NewInstance(context).ToLocalChecked();
21550 CHECK(context->Global()
21551 ->Set(context, v8_str("function_receiver"), function_receiver)
21552 .FromJust());
20010 // Get the holder objects. 21553 // Get the holder objects.
20011 Local<Object> inner_global = 21554 Local<Object> inner_global =
20012 Local<Object>::Cast(context->Global()->GetPrototype()); 21555 Local<Object>::Cast(context->Global()->GetPrototype());
20013 // Install functions on hidden prototype object if there is one. 21556 // Install functions on hidden prototype object if there is one.
20014 data = Object::New(isolate); 21557 data = Object::New(isolate);
20015 Local<FunctionTemplate> function_template = FunctionTemplate::New( 21558 Local<FunctionTemplate> function_template = FunctionTemplate::New(
20016 isolate, OptimizationCallback, data, signature); 21559 isolate, OptimizationCallback, data, signature);
20017 Local<Function> function = function_template->GetFunction(); 21560 Local<Function> function =
21561 function_template->GetFunction(context).ToLocalChecked();
20018 Local<Object> global_holder = inner_global; 21562 Local<Object> global_holder = inner_global;
20019 Local<Object> function_holder = function_receiver; 21563 Local<Object> function_holder = function_receiver;
20020 if (signature_type == kSignatureOnPrototype) { 21564 if (signature_type == kSignatureOnPrototype) {
20021 function_holder = Local<Object>::Cast(function_holder->GetPrototype()); 21565 function_holder = Local<Object>::Cast(function_holder->GetPrototype());
20022 global_holder = Local<Object>::Cast(global_holder->GetPrototype()); 21566 global_holder = Local<Object>::Cast(global_holder->GetPrototype());
20023 } 21567 }
20024 global_holder->Set(v8_str("g_f"), function); 21568 global_holder->Set(v8_str("g_f"), function);
20025 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function); 21569 global_holder->SetAccessorProperty(v8_str("g_acc"), function, function);
20026 function_holder->Set(v8_str("f"), function); 21570 function_holder->Set(v8_str("f"), function);
20027 function_holder->SetAccessorProperty(v8_str("acc"), function, function); 21571 function_holder->SetAccessorProperty(v8_str("acc"), function, function);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
20115 ApiCallOptimizationChecker checker; 21659 ApiCallOptimizationChecker checker;
20116 checker.RunAll(); 21660 checker.RunAll();
20117 } 21661 }
20118 21662
20119 21663
20120 TEST(FunctionCallOptimizationMultipleArgs) { 21664 TEST(FunctionCallOptimizationMultipleArgs) {
20121 i::FLAG_allow_natives_syntax = true; 21665 i::FLAG_allow_natives_syntax = true;
20122 LocalContext context; 21666 LocalContext context;
20123 v8::Isolate* isolate = context->GetIsolate(); 21667 v8::Isolate* isolate = context->GetIsolate();
20124 v8::HandleScope scope(isolate); 21668 v8::HandleScope scope(isolate);
20125 Handle<Object> global = context->Global(); 21669 Local<Object> global = context->Global();
20126 Local<v8::Function> function = Function::New(isolate, Returns42); 21670 Local<v8::Function> function = Function::New(isolate, Returns42);
20127 global->Set(v8_str("x"), function); 21671 global->Set(v8_str("x"), function);
20128 CompileRun( 21672 CompileRun(
20129 "function x_wrap() {\n" 21673 "function x_wrap() {\n"
20130 " for (var i = 0; i < 5; i++) {\n" 21674 " for (var i = 0; i < 5; i++) {\n"
20131 " x(1,2,3);\n" 21675 " x(1,2,3);\n"
20132 " }\n" 21676 " }\n"
20133 "}\n" 21677 "}\n"
20134 "x_wrap();\n" 21678 "x_wrap();\n"
20135 "%OptimizeFunctionOnNextCall(x_wrap);" 21679 "%OptimizeFunctionOnNextCall(x_wrap);"
20136 "x_wrap();\n"); 21680 "x_wrap();\n");
20137 } 21681 }
20138 21682
20139 21683
20140 static void ReturnsSymbolCallback( 21684 static void ReturnsSymbolCallback(
20141 const v8::FunctionCallbackInfo<v8::Value>& info) { 21685 const v8::FunctionCallbackInfo<v8::Value>& info) {
20142 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate())); 21686 info.GetReturnValue().Set(v8::Symbol::New(info.GetIsolate()));
20143 } 21687 }
20144 21688
20145 21689
20146 TEST(ApiCallbackCanReturnSymbols) { 21690 TEST(ApiCallbackCanReturnSymbols) {
20147 i::FLAG_allow_natives_syntax = true; 21691 i::FLAG_allow_natives_syntax = true;
20148 LocalContext context; 21692 LocalContext context;
20149 v8::Isolate* isolate = context->GetIsolate(); 21693 v8::Isolate* isolate = context->GetIsolate();
20150 v8::HandleScope scope(isolate); 21694 v8::HandleScope scope(isolate);
20151 Handle<Object> global = context->Global(); 21695 Local<Object> global = context->Global();
20152 Local<v8::Function> function = Function::New(isolate, ReturnsSymbolCallback); 21696 Local<v8::Function> function = Function::New(isolate, ReturnsSymbolCallback);
20153 global->Set(v8_str("x"), function); 21697 global->Set(v8_str("x"), function);
20154 CompileRun( 21698 CompileRun(
20155 "function x_wrap() {\n" 21699 "function x_wrap() {\n"
20156 " for (var i = 0; i < 5; i++) {\n" 21700 " for (var i = 0; i < 5; i++) {\n"
20157 " x();\n" 21701 " x();\n"
20158 " }\n" 21702 " }\n"
20159 "}\n" 21703 "}\n"
20160 "x_wrap();\n" 21704 "x_wrap();\n"
20161 "%OptimizeFunctionOnNextCall(x_wrap);" 21705 "%OptimizeFunctionOnNextCall(x_wrap);"
20162 "x_wrap();\n"); 21706 "x_wrap();\n");
20163 } 21707 }
20164 21708
20165 21709
20166 TEST(EmptyApiCallback) { 21710 TEST(EmptyApiCallback) {
20167 LocalContext context; 21711 LocalContext context;
20168 auto isolate = context->GetIsolate(); 21712 auto isolate = context->GetIsolate();
20169 v8::HandleScope scope(isolate); 21713 v8::HandleScope scope(isolate);
20170 auto global = context->Global(); 21714 auto global = context->Global();
20171 auto function = FunctionTemplate::New(isolate)->GetFunction(); 21715 auto function = FunctionTemplate::New(isolate)
21716 ->GetFunction(context.local())
21717 .ToLocalChecked();
20172 global->Set(v8_str("x"), function); 21718 global->Set(v8_str("x"), function);
20173 21719
20174 auto result = CompileRun("x()"); 21720 auto result = CompileRun("x()");
20175 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); 21721 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy());
20176 21722
20177 result = CompileRun("x(1,2,3)"); 21723 result = CompileRun("x(1,2,3)");
20178 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); 21724 CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy());
20179 21725
20180 result = CompileRun("7 + x.call(3) + 11"); 21726 result = CompileRun("7 + x.call(3) + 11");
20181 CHECK(result->IsInt32()); 21727 CHECK(result->IsInt32());
20182 CHECK_EQ(21, result->Int32Value()); 21728 CHECK_EQ(21, result->Int32Value(context.local()).FromJust());
20183 21729
20184 result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11"); 21730 result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11");
20185 CHECK(result->IsInt32()); 21731 CHECK(result->IsInt32());
20186 CHECK_EQ(21, result->Int32Value()); 21732 CHECK_EQ(21, result->Int32Value(context.local()).FromJust());
20187 21733
20188 result = CompileRun("var y = []; x.call(y)"); 21734 result = CompileRun("var y = []; x.call(y)");
20189 CHECK(result->IsArray()); 21735 CHECK(result->IsArray());
20190 21736
20191 result = CompileRun("x.call(y, 1, 2, 3, 4)"); 21737 result = CompileRun("x.call(y, 1, 2, 3, 4)");
20192 CHECK(result->IsArray()); 21738 CHECK(result->IsArray());
20193 } 21739 }
20194 21740
20195 21741
20196 TEST(SimpleSignatureCheck) { 21742 TEST(SimpleSignatureCheck) {
20197 LocalContext context; 21743 LocalContext context;
20198 auto isolate = context->GetIsolate(); 21744 auto isolate = context->GetIsolate();
20199 v8::HandleScope scope(isolate); 21745 v8::HandleScope scope(isolate);
20200 auto global = context->Global(); 21746 auto global = context->Global();
20201 auto sig_obj = FunctionTemplate::New(isolate); 21747 auto sig_obj = FunctionTemplate::New(isolate);
20202 auto sig = v8::Signature::New(isolate, sig_obj); 21748 auto sig = v8::Signature::New(isolate, sig_obj);
20203 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); 21749 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig);
20204 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); 21750 global->Set(v8_str("sig_obj"),
20205 global->Set(v8_str("x"), x->GetFunction()); 21751 sig_obj->GetFunction(context.local()).ToLocalChecked());
21752 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked());
20206 CompileRun("var s = new sig_obj();"); 21753 CompileRun("var s = new sig_obj();");
20207 { 21754 {
20208 TryCatch try_catch(isolate); 21755 TryCatch try_catch(isolate);
20209 CompileRun("x()"); 21756 CompileRun("x()");
20210 CHECK(try_catch.HasCaught()); 21757 CHECK(try_catch.HasCaught());
20211 } 21758 }
20212 { 21759 {
20213 TryCatch try_catch(isolate); 21760 TryCatch try_catch(isolate);
20214 CompileRun("x.call(1)"); 21761 CompileRun("x.call(1)");
20215 CHECK(try_catch.HasCaught()); 21762 CHECK(try_catch.HasCaught());
20216 } 21763 }
20217 { 21764 {
20218 TryCatch try_catch(isolate); 21765 TryCatch try_catch(isolate);
20219 auto result = CompileRun("s.x = x; s.x()"); 21766 auto result = CompileRun("s.x = x; s.x()");
20220 CHECK(!try_catch.HasCaught()); 21767 CHECK(!try_catch.HasCaught());
20221 CHECK_EQ(42, result->Int32Value()); 21768 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20222 } 21769 }
20223 { 21770 {
20224 TryCatch try_catch(isolate); 21771 TryCatch try_catch(isolate);
20225 auto result = CompileRun("x.call(s)"); 21772 auto result = CompileRun("x.call(s)");
20226 CHECK(!try_catch.HasCaught()); 21773 CHECK(!try_catch.HasCaught());
20227 CHECK_EQ(42, result->Int32Value()); 21774 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20228 } 21775 }
20229 } 21776 }
20230 21777
20231 21778
20232 TEST(ChainSignatureCheck) { 21779 TEST(ChainSignatureCheck) {
20233 LocalContext context; 21780 LocalContext context;
20234 auto isolate = context->GetIsolate(); 21781 auto isolate = context->GetIsolate();
20235 v8::HandleScope scope(isolate); 21782 v8::HandleScope scope(isolate);
20236 auto global = context->Global(); 21783 auto global = context->Global();
20237 auto sig_obj = FunctionTemplate::New(isolate); 21784 auto sig_obj = FunctionTemplate::New(isolate);
20238 auto sig = v8::Signature::New(isolate, sig_obj); 21785 auto sig = v8::Signature::New(isolate, sig_obj);
20239 for (int i = 0; i < 4; ++i) { 21786 for (int i = 0; i < 4; ++i) {
20240 auto temp = FunctionTemplate::New(isolate); 21787 auto temp = FunctionTemplate::New(isolate);
20241 temp->Inherit(sig_obj); 21788 temp->Inherit(sig_obj);
20242 sig_obj = temp; 21789 sig_obj = temp;
20243 } 21790 }
20244 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); 21791 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig);
20245 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); 21792 global->Set(v8_str("sig_obj"),
20246 global->Set(v8_str("x"), x->GetFunction()); 21793 sig_obj->GetFunction(context.local()).ToLocalChecked());
21794 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked());
20247 CompileRun("var s = new sig_obj();"); 21795 CompileRun("var s = new sig_obj();");
20248 { 21796 {
20249 TryCatch try_catch(isolate); 21797 TryCatch try_catch(isolate);
20250 CompileRun("x()"); 21798 CompileRun("x()");
20251 CHECK(try_catch.HasCaught()); 21799 CHECK(try_catch.HasCaught());
20252 } 21800 }
20253 { 21801 {
20254 TryCatch try_catch(isolate); 21802 TryCatch try_catch(isolate);
20255 CompileRun("x.call(1)"); 21803 CompileRun("x.call(1)");
20256 CHECK(try_catch.HasCaught()); 21804 CHECK(try_catch.HasCaught());
20257 } 21805 }
20258 { 21806 {
20259 TryCatch try_catch(isolate); 21807 TryCatch try_catch(isolate);
20260 auto result = CompileRun("s.x = x; s.x()"); 21808 auto result = CompileRun("s.x = x; s.x()");
20261 CHECK(!try_catch.HasCaught()); 21809 CHECK(!try_catch.HasCaught());
20262 CHECK_EQ(42, result->Int32Value()); 21810 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20263 } 21811 }
20264 { 21812 {
20265 TryCatch try_catch(isolate); 21813 TryCatch try_catch(isolate);
20266 auto result = CompileRun("x.call(s)"); 21814 auto result = CompileRun("x.call(s)");
20267 CHECK(!try_catch.HasCaught()); 21815 CHECK(!try_catch.HasCaught());
20268 CHECK_EQ(42, result->Int32Value()); 21816 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20269 } 21817 }
20270 } 21818 }
20271 21819
20272 21820
20273 TEST(PrototypeSignatureCheck) { 21821 TEST(PrototypeSignatureCheck) {
20274 LocalContext context; 21822 LocalContext context;
20275 auto isolate = context->GetIsolate(); 21823 auto isolate = context->GetIsolate();
20276 v8::HandleScope scope(isolate); 21824 v8::HandleScope scope(isolate);
20277 auto global = context->Global(); 21825 auto global = context->Global();
20278 auto sig_obj = FunctionTemplate::New(isolate); 21826 auto sig_obj = FunctionTemplate::New(isolate);
20279 sig_obj->SetHiddenPrototype(true); 21827 sig_obj->SetHiddenPrototype(true);
20280 auto sig = v8::Signature::New(isolate, sig_obj); 21828 auto sig = v8::Signature::New(isolate, sig_obj);
20281 auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); 21829 auto x = FunctionTemplate::New(isolate, Returns42, Local<Value>(), sig);
20282 global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); 21830 global->Set(v8_str("sig_obj"),
20283 global->Set(v8_str("x"), x->GetFunction()); 21831 sig_obj->GetFunction(context.local()).ToLocalChecked());
21832 global->Set(v8_str("x"), x->GetFunction(context.local()).ToLocalChecked());
20284 CompileRun("s = {}; s.__proto__ = new sig_obj();"); 21833 CompileRun("s = {}; s.__proto__ = new sig_obj();");
20285 { 21834 {
20286 TryCatch try_catch(isolate); 21835 TryCatch try_catch(isolate);
20287 CompileRun("x()"); 21836 CompileRun("x()");
20288 CHECK(try_catch.HasCaught()); 21837 CHECK(try_catch.HasCaught());
20289 } 21838 }
20290 { 21839 {
20291 TryCatch try_catch(isolate); 21840 TryCatch try_catch(isolate);
20292 CompileRun("x.call(1)"); 21841 CompileRun("x.call(1)");
20293 CHECK(try_catch.HasCaught()); 21842 CHECK(try_catch.HasCaught());
20294 } 21843 }
20295 { 21844 {
20296 TryCatch try_catch(isolate); 21845 TryCatch try_catch(isolate);
20297 auto result = CompileRun("s.x = x; s.x()"); 21846 auto result = CompileRun("s.x = x; s.x()");
20298 CHECK(!try_catch.HasCaught()); 21847 CHECK(!try_catch.HasCaught());
20299 CHECK_EQ(42, result->Int32Value()); 21848 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20300 } 21849 }
20301 { 21850 {
20302 TryCatch try_catch(isolate); 21851 TryCatch try_catch(isolate);
20303 auto result = CompileRun("x.call(s)"); 21852 auto result = CompileRun("x.call(s)");
20304 CHECK(!try_catch.HasCaught()); 21853 CHECK(!try_catch.HasCaught());
20305 CHECK_EQ(42, result->Int32Value()); 21854 CHECK_EQ(42, result->Int32Value(context.local()).FromJust());
20306 } 21855 }
20307 } 21856 }
20308 21857
20309 21858
20310 static const char* last_event_message; 21859 static const char* last_event_message;
20311 static int last_event_status; 21860 static int last_event_status;
20312 void StoringEventLoggerCallback(const char* message, int status) { 21861 void StoringEventLoggerCallback(const char* message, int status) {
20313 last_event_message = message; 21862 last_event_message = message;
20314 last_event_status = status; 21863 last_event_status = status;
20315 } 21864 }
(...skipping 11 matching lines...) Expand all
20327 histogramTimer.Stop(); 21876 histogramTimer.Stop();
20328 CHECK_EQ(0, strcmp("V8.Test", last_event_message)); 21877 CHECK_EQ(0, strcmp("V8.Test", last_event_message));
20329 CHECK_EQ(1, last_event_status); 21878 CHECK_EQ(1, last_event_status);
20330 } 21879 }
20331 21880
20332 21881
20333 TEST(Promises) { 21882 TEST(Promises) {
20334 LocalContext context; 21883 LocalContext context;
20335 v8::Isolate* isolate = context->GetIsolate(); 21884 v8::Isolate* isolate = context->GetIsolate();
20336 v8::HandleScope scope(isolate); 21885 v8::HandleScope scope(isolate);
20337 Handle<Object> global = context->Global(); 21886 Local<Object> global = context->Global();
20338 21887
20339 // Creation. 21888 // Creation.
20340 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); 21889 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate);
20341 Handle<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate); 21890 Local<v8::Promise::Resolver> rr = v8::Promise::Resolver::New(isolate);
20342 Handle<v8::Promise> p = pr->GetPromise(); 21891 Local<v8::Promise> p = pr->GetPromise();
20343 Handle<v8::Promise> r = rr->GetPromise(); 21892 Local<v8::Promise> r = rr->GetPromise();
20344 CHECK_EQ(isolate, p->GetIsolate()); 21893 CHECK_EQ(isolate, p->GetIsolate());
20345 21894
20346 // IsPromise predicate. 21895 // IsPromise predicate.
20347 CHECK(p->IsPromise()); 21896 CHECK(p->IsPromise());
20348 CHECK(r->IsPromise()); 21897 CHECK(r->IsPromise());
20349 Handle<Value> o = v8::Object::New(isolate); 21898 Local<Value> o = v8::Object::New(isolate);
20350 CHECK(!o->IsPromise()); 21899 CHECK(!o->IsPromise());
20351 21900
20352 // Resolution and rejection. 21901 // Resolution and rejection.
20353 pr->Resolve(v8::Integer::New(isolate, 1)); 21902 pr->Resolve(v8::Integer::New(isolate, 1));
20354 CHECK(p->IsPromise()); 21903 CHECK(p->IsPromise());
20355 rr->Reject(v8::Integer::New(isolate, 2)); 21904 rr->Reject(v8::Integer::New(isolate, 2));
20356 CHECK(r->IsPromise()); 21905 CHECK(r->IsPromise());
20357 21906
20358 // Chaining non-pending promises. 21907 // Chaining non-pending promises.
20359 CompileRun( 21908 CompileRun(
20360 "var x1 = 0;\n" 21909 "var x1 = 0;\n"
20361 "var x2 = 0;\n" 21910 "var x2 = 0;\n"
20362 "function f1(x) { x1 = x; return x+1 };\n" 21911 "function f1(x) { x1 = x; return x+1 };\n"
20363 "function f2(x) { x2 = x; return x+1 };\n"); 21912 "function f2(x) { x2 = x; return x+1 };\n");
20364 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); 21913 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1")));
20365 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); 21914 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2")));
20366 21915
20367 p->Chain(f1); 21916 p->Chain(f1);
20368 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 21917 CHECK_EQ(0,
21918 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
20369 isolate->RunMicrotasks(); 21919 isolate->RunMicrotasks();
20370 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 21920 CHECK_EQ(1,
21921 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
20371 21922
20372 p->Catch(f2); 21923 p->Catch(f2);
20373 isolate->RunMicrotasks(); 21924 isolate->RunMicrotasks();
20374 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21925 CHECK_EQ(0,
21926 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20375 21927
20376 r->Catch(f2); 21928 r->Catch(f2);
20377 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21929 CHECK_EQ(0,
21930 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20378 isolate->RunMicrotasks(); 21931 isolate->RunMicrotasks();
20379 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); 21932 CHECK_EQ(2,
21933 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20380 21934
20381 r->Chain(f1); 21935 r->Chain(f1);
20382 isolate->RunMicrotasks(); 21936 isolate->RunMicrotasks();
20383 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 21937 CHECK_EQ(1,
21938 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
20384 21939
20385 // Chaining pending promises. 21940 // Chaining pending promises.
20386 CompileRun("x1 = x2 = 0;"); 21941 CompileRun("x1 = x2 = 0;");
20387 pr = v8::Promise::Resolver::New(isolate); 21942 pr = v8::Promise::Resolver::New(isolate);
20388 rr = v8::Promise::Resolver::New(isolate); 21943 rr = v8::Promise::Resolver::New(isolate);
20389 21944
20390 pr->GetPromise()->Chain(f1); 21945 pr->GetPromise()->Chain(f1);
20391 rr->GetPromise()->Catch(f2); 21946 rr->GetPromise()->Catch(f2);
20392 isolate->RunMicrotasks(); 21947 isolate->RunMicrotasks();
20393 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 21948 CHECK_EQ(0,
20394 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21949 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21950 CHECK_EQ(0,
21951 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20395 21952
20396 pr->Resolve(v8::Integer::New(isolate, 1)); 21953 pr->Resolve(v8::Integer::New(isolate, 1));
20397 rr->Reject(v8::Integer::New(isolate, 2)); 21954 rr->Reject(v8::Integer::New(isolate, 2));
20398 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 21955 CHECK_EQ(0,
20399 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21956 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21957 CHECK_EQ(0,
21958 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20400 21959
20401 isolate->RunMicrotasks(); 21960 isolate->RunMicrotasks();
20402 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 21961 CHECK_EQ(1,
20403 CHECK_EQ(2, global->Get(v8_str("x2"))->Int32Value()); 21962 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21963 CHECK_EQ(2,
21964 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20404 21965
20405 // Multi-chaining. 21966 // Multi-chaining.
20406 CompileRun("x1 = x2 = 0;"); 21967 CompileRun("x1 = x2 = 0;");
20407 pr = v8::Promise::Resolver::New(isolate); 21968 pr = v8::Promise::Resolver::New(isolate);
20408 pr->GetPromise()->Chain(f1)->Chain(f2); 21969 pr->GetPromise()->Chain(f1)->Chain(f2);
20409 pr->Resolve(v8::Integer::New(isolate, 3)); 21970 pr->Resolve(v8::Integer::New(isolate, 3));
20410 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 21971 CHECK_EQ(0,
20411 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21972 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21973 CHECK_EQ(0,
21974 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20412 isolate->RunMicrotasks(); 21975 isolate->RunMicrotasks();
20413 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 21976 CHECK_EQ(3,
20414 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 21977 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21978 CHECK_EQ(4,
21979 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20415 21980
20416 CompileRun("x1 = x2 = 0;"); 21981 CompileRun("x1 = x2 = 0;");
20417 rr = v8::Promise::Resolver::New(isolate); 21982 rr = v8::Promise::Resolver::New(isolate);
20418 rr->GetPromise()->Catch(f1)->Chain(f2); 21983 rr->GetPromise()->Catch(f1)->Chain(f2);
20419 rr->Reject(v8::Integer::New(isolate, 3)); 21984 rr->Reject(v8::Integer::New(isolate, 3));
20420 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 21985 CHECK_EQ(0,
20421 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 21986 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21987 CHECK_EQ(0,
21988 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20422 isolate->RunMicrotasks(); 21989 isolate->RunMicrotasks();
20423 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 21990 CHECK_EQ(3,
20424 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 21991 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
21992 CHECK_EQ(4,
21993 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20425 } 21994 }
20426 21995
20427 21996
20428 TEST(PromiseThen) { 21997 TEST(PromiseThen) {
20429 LocalContext context; 21998 LocalContext context;
20430 v8::Isolate* isolate = context->GetIsolate(); 21999 v8::Isolate* isolate = context->GetIsolate();
20431 v8::HandleScope scope(isolate); 22000 v8::HandleScope scope(isolate);
20432 Handle<Object> global = context->Global(); 22001 Local<Object> global = context->Global();
20433 22002
20434 // Creation. 22003 // Creation.
20435 Handle<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate); 22004 Local<v8::Promise::Resolver> pr = v8::Promise::Resolver::New(isolate);
20436 Handle<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate); 22005 Local<v8::Promise::Resolver> qr = v8::Promise::Resolver::New(isolate);
20437 Handle<v8::Promise> p = pr->GetPromise(); 22006 Local<v8::Promise> p = pr->GetPromise();
20438 Handle<v8::Promise> q = qr->GetPromise(); 22007 Local<v8::Promise> q = qr->GetPromise();
20439 22008
20440 CHECK(p->IsPromise()); 22009 CHECK(p->IsPromise());
20441 CHECK(q->IsPromise()); 22010 CHECK(q->IsPromise());
20442 22011
20443 pr->Resolve(v8::Integer::New(isolate, 1)); 22012 pr->Resolve(v8::Integer::New(isolate, 1));
20444 qr->Resolve(p); 22013 qr->Resolve(p);
20445 22014
20446 // Chaining non-pending promises. 22015 // Chaining non-pending promises.
20447 CompileRun( 22016 CompileRun(
20448 "var x1 = 0;\n" 22017 "var x1 = 0;\n"
20449 "var x2 = 0;\n" 22018 "var x2 = 0;\n"
20450 "function f1(x) { x1 = x; return x+1 };\n" 22019 "function f1(x) { x1 = x; return x+1 };\n"
20451 "function f2(x) { x2 = x; return x+1 };\n"); 22020 "function f2(x) { x2 = x; return x+1 };\n");
20452 Handle<Function> f1 = Handle<Function>::Cast(global->Get(v8_str("f1"))); 22021 Local<Function> f1 = Local<Function>::Cast(global->Get(v8_str("f1")));
20453 Handle<Function> f2 = Handle<Function>::Cast(global->Get(v8_str("f2"))); 22022 Local<Function> f2 = Local<Function>::Cast(global->Get(v8_str("f2")));
20454 22023
20455 // TODO(caitp): remove tests once PromiseChain is removed, per bug 3237 22024 // TODO(caitp): remove tests once PromiseChain is removed, per bug 3237
20456 /* q->Chain(f1); 22025 /* q->Chain(f1);
20457 CHECK(global->Get(v8_str2("x1"))->IsNumber()); 22026 CHECK(global->Get(v8_str2("x1"))->IsNumber());
20458 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22027 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value());
20459 isolate->RunMicrotasks(); 22028 isolate->RunMicrotasks();
20460 CHECK(!global->Get(v8_str("x1"))->IsNumber()); 22029 CHECK(!global->Get(v8_str("x1"))->IsNumber());
20461 CHECK(p->Equals(global->Get(v8_str("x1")))); */ 22030 CHECK(p->Equals(global->Get(v8_str("x1")))); */
20462 22031
20463 // Then 22032 // Then
20464 CompileRun("x1 = x2 = 0;"); 22033 CompileRun("x1 = x2 = 0;");
20465 q->Then(f1); 22034 q->Then(f1);
20466 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22035 CHECK_EQ(0,
22036 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
20467 isolate->RunMicrotasks(); 22037 isolate->RunMicrotasks();
20468 CHECK_EQ(1, global->Get(v8_str("x1"))->Int32Value()); 22038 CHECK_EQ(1,
22039 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
20469 22040
20470 // Then 22041 // Then
20471 CompileRun("x1 = x2 = 0;"); 22042 CompileRun("x1 = x2 = 0;");
20472 pr = v8::Promise::Resolver::New(isolate); 22043 pr = v8::Promise::Resolver::New(isolate);
20473 qr = v8::Promise::Resolver::New(isolate); 22044 qr = v8::Promise::Resolver::New(isolate);
20474 22045
20475 qr->Resolve(pr); 22046 qr->Resolve(pr);
20476 qr->GetPromise()->Then(f1)->Then(f2); 22047 qr->GetPromise()->Then(f1)->Then(f2);
20477 22048
20478 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22049 CHECK_EQ(0,
20479 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22050 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
22051 CHECK_EQ(0,
22052 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20480 isolate->RunMicrotasks(); 22053 isolate->RunMicrotasks();
20481 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22054 CHECK_EQ(0,
20482 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22055 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
22056 CHECK_EQ(0,
22057 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20483 22058
20484 pr->Resolve(v8::Integer::New(isolate, 3)); 22059 pr->Resolve(v8::Integer::New(isolate, 3));
20485 22060
20486 CHECK_EQ(0, global->Get(v8_str("x1"))->Int32Value()); 22061 CHECK_EQ(0,
20487 CHECK_EQ(0, global->Get(v8_str("x2"))->Int32Value()); 22062 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
22063 CHECK_EQ(0,
22064 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20488 isolate->RunMicrotasks(); 22065 isolate->RunMicrotasks();
20489 CHECK_EQ(3, global->Get(v8_str("x1"))->Int32Value()); 22066 CHECK_EQ(3,
20490 CHECK_EQ(4, global->Get(v8_str("x2"))->Int32Value()); 22067 global->Get(v8_str("x1"))->Int32Value(context.local()).FromJust());
22068 CHECK_EQ(4,
22069 global->Get(v8_str("x2"))->Int32Value(context.local()).FromJust());
20491 } 22070 }
20492 22071
20493 22072
20494 TEST(DisallowJavascriptExecutionScope) { 22073 TEST(DisallowJavascriptExecutionScope) {
20495 LocalContext context; 22074 LocalContext context;
20496 v8::Isolate* isolate = context->GetIsolate(); 22075 v8::Isolate* isolate = context->GetIsolate();
20497 v8::HandleScope scope(isolate); 22076 v8::HandleScope scope(isolate);
20498 v8::Isolate::DisallowJavascriptExecutionScope no_js( 22077 v8::Isolate::DisallowJavascriptExecutionScope no_js(
20499 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE); 22078 isolate, v8::Isolate::DisallowJavascriptExecutionScope::CRASH_ON_FAILURE);
20500 CompileRun("2+2"); 22079 CompileRun("2+2");
(...skipping 24 matching lines...) Expand all
20525 CompileRun("1+1"); 22104 CompileRun("1+1");
20526 CHECK(try_catch.HasCaught()); 22105 CHECK(try_catch.HasCaught());
20527 } 22106 }
20528 22107
20529 22108
20530 TEST(Regress354123) { 22109 TEST(Regress354123) {
20531 LocalContext current; 22110 LocalContext current;
20532 v8::Isolate* isolate = current->GetIsolate(); 22111 v8::Isolate* isolate = current->GetIsolate();
20533 v8::HandleScope scope(isolate); 22112 v8::HandleScope scope(isolate);
20534 22113
20535 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); 22114 v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
20536 templ->SetAccessCheckCallback(AccessCounter); 22115 templ->SetAccessCheckCallback(AccessCounter);
20537 current->Global()->Set(v8_str("friend"), templ->NewInstance()); 22116 CHECK(current->Global()
22117 ->Set(current.local(), v8_str("friend"),
22118 templ->NewInstance(current.local()).ToLocalChecked())
22119 .FromJust());
20538 22120
20539 // Test access using __proto__ from the prototype chain. 22121 // Test access using __proto__ from the prototype chain.
20540 access_count = 0; 22122 access_count = 0;
20541 CompileRun("friend.__proto__ = {};"); 22123 CompileRun("friend.__proto__ = {};");
20542 CHECK_EQ(2, access_count); 22124 CHECK_EQ(2, access_count);
20543 CompileRun("friend.__proto__;"); 22125 CompileRun("friend.__proto__;");
20544 CHECK_EQ(4, access_count); 22126 CHECK_EQ(4, access_count);
20545 22127
20546 // Test access using __proto__ as a hijacked function (A). 22128 // Test access using __proto__ as a hijacked function (A).
20547 access_count = 0; 22129 access_count = 0;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
20596 isolate, &script_source); 22178 isolate, &script_source);
20597 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); 22179 Local<Value> script_name = script->GetUnboundScript()->GetScriptName();
20598 CHECK(!script_name.IsEmpty()); 22180 CHECK(!script_name.IsEmpty());
20599 CHECK(script_name->IsString()); 22181 CHECK(script_name->IsString());
20600 String::Utf8Value utf8_name(script_name); 22182 String::Utf8Value utf8_name(script_name);
20601 CHECK_EQ(0, strcmp(url, *utf8_name)); 22183 CHECK_EQ(0, strcmp(url, *utf8_name));
20602 int line_number = script->GetUnboundScript()->GetLineNumber(0); 22184 int line_number = script->GetUnboundScript()->GetLineNumber(0);
20603 CHECK_EQ(13, line_number); 22185 CHECK_EQ(13, line_number);
20604 } 22186 }
20605 22187
20606 void CheckMagicComments(Handle<Script> script, const char* expected_source_url, 22188 void CheckMagicComments(Local<Script> script, const char* expected_source_url,
20607 const char* expected_source_mapping_url) { 22189 const char* expected_source_mapping_url) {
20608 if (expected_source_url != NULL) { 22190 if (expected_source_url != NULL) {
20609 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); 22191 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL());
20610 CHECK_EQ(0, strcmp(expected_source_url, *url)); 22192 CHECK_EQ(0, strcmp(expected_source_url, *url));
20611 } else { 22193 } else {
20612 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); 22194 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined());
20613 } 22195 }
20614 if (expected_source_mapping_url != NULL) { 22196 if (expected_source_mapping_url != NULL) {
20615 v8::String::Utf8Value url( 22197 v8::String::Utf8Value url(
20616 script->GetUnboundScript()->GetSourceMappingURL()); 22198 script->GetUnboundScript()->GetSourceMappingURL());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
20705 Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop")); 22287 Local<Value> desc = x->GetOwnPropertyDescriptor(v8_str("no_prop"));
20706 CHECK(desc->IsUndefined()); 22288 CHECK(desc->IsUndefined());
20707 desc = x->GetOwnPropertyDescriptor(v8_str("p0")); 22289 desc = x->GetOwnPropertyDescriptor(v8_str("p0"));
20708 CHECK(v8_num(12)->Equals(Local<Object>::Cast(desc)->Get(v8_str("value")))); 22290 CHECK(v8_num(12)->Equals(Local<Object>::Cast(desc)->Get(v8_str("value"))));
20709 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22291 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
20710 Local<Function> set = 22292 Local<Function> set =
20711 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22293 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
20712 Local<Function> get = 22294 Local<Function> get =
20713 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22295 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
20714 CHECK(v8_num(13)->Equals(get->Call(x, 0, NULL))); 22296 CHECK(v8_num(13)->Equals(get->Call(x, 0, NULL)));
20715 Handle<Value> args[] = { v8_num(14) }; 22297 Local<Value> args[] = {v8_num(14)};
20716 set->Call(x, 1, args); 22298 set->Call(x, 1, args);
20717 CHECK(v8_num(14)->Equals(get->Call(x, 0, NULL))); 22299 CHECK(v8_num(14)->Equals(get->Call(x, 0, NULL)));
20718 } 22300 }
20719 22301
20720 22302
20721 TEST(Regress411877) { 22303 TEST(Regress411877) {
20722 v8::Isolate* isolate = CcTest::isolate(); 22304 v8::Isolate* isolate = CcTest::isolate();
20723 v8::HandleScope handle_scope(isolate); 22305 v8::HandleScope handle_scope(isolate);
20724 v8::Handle<v8::ObjectTemplate> object_template = 22306 v8::Local<v8::ObjectTemplate> object_template =
20725 v8::ObjectTemplate::New(isolate); 22307 v8::ObjectTemplate::New(isolate);
20726 object_template->SetAccessCheckCallback(AccessCounter); 22308 object_template->SetAccessCheckCallback(AccessCounter);
20727 22309
20728 v8::Handle<Context> context = Context::New(isolate); 22310 v8::Local<Context> context = Context::New(isolate);
20729 v8::Context::Scope context_scope(context); 22311 v8::Context::Scope context_scope(context);
20730 22312
20731 context->Global()->Set(v8_str("o"), object_template->NewInstance()); 22313 CHECK(context->Global()
22314 ->Set(context, v8_str("o"),
22315 object_template->NewInstance(context).ToLocalChecked())
22316 .FromJust());
20732 CompileRun("Object.getOwnPropertyNames(o)"); 22317 CompileRun("Object.getOwnPropertyNames(o)");
20733 } 22318 }
20734 22319
20735 22320
20736 TEST(GetHiddenPropertyTableAfterAccessCheck) { 22321 TEST(GetHiddenPropertyTableAfterAccessCheck) {
20737 v8::Isolate* isolate = CcTest::isolate(); 22322 v8::Isolate* isolate = CcTest::isolate();
20738 v8::HandleScope handle_scope(isolate); 22323 v8::HandleScope handle_scope(isolate);
20739 v8::Handle<v8::ObjectTemplate> object_template = 22324 v8::Local<v8::ObjectTemplate> object_template =
20740 v8::ObjectTemplate::New(isolate); 22325 v8::ObjectTemplate::New(isolate);
20741 object_template->SetAccessCheckCallback(AccessCounter); 22326 object_template->SetAccessCheckCallback(AccessCounter);
20742 22327
20743 v8::Handle<Context> context = Context::New(isolate); 22328 v8::Local<Context> context = Context::New(isolate);
20744 v8::Context::Scope context_scope(context); 22329 v8::Context::Scope context_scope(context);
20745 22330
20746 v8::Handle<v8::Object> obj = object_template->NewInstance(); 22331 v8::Local<v8::Object> obj =
22332 object_template->NewInstance(context).ToLocalChecked();
20747 obj->Set(v8_str("key"), v8_str("value")); 22333 obj->Set(v8_str("key"), v8_str("value"));
20748 obj->Delete(v8_str("key")); 22334 obj->Delete(v8_str("key"));
20749 22335
20750 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")), 22336 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")),
20751 v8_str("hidden value 2")) 22337 v8_str("hidden value 2"))
20752 .FromJust(); 22338 .FromJust();
20753 } 22339 }
20754 22340
20755 22341
20756 TEST(Regress411793) { 22342 TEST(Regress411793) {
20757 v8::Isolate* isolate = CcTest::isolate(); 22343 v8::Isolate* isolate = CcTest::isolate();
20758 v8::HandleScope handle_scope(isolate); 22344 v8::HandleScope handle_scope(isolate);
20759 v8::Handle<v8::ObjectTemplate> object_template = 22345 v8::Local<v8::ObjectTemplate> object_template =
20760 v8::ObjectTemplate::New(isolate); 22346 v8::ObjectTemplate::New(isolate);
20761 object_template->SetAccessCheckCallback(AccessCounter); 22347 object_template->SetAccessCheckCallback(AccessCounter);
20762 22348
20763 v8::Handle<Context> context = Context::New(isolate); 22349 v8::Local<Context> context = Context::New(isolate);
20764 v8::Context::Scope context_scope(context); 22350 v8::Context::Scope context_scope(context);
20765 22351
20766 context->Global()->Set(v8_str("o"), object_template->NewInstance()); 22352 CHECK(context->Global()
22353 ->Set(context, v8_str("o"),
22354 object_template->NewInstance(context).ToLocalChecked())
22355 .FromJust());
20767 CompileRun( 22356 CompileRun(
20768 "Object.defineProperty(o, 'key', " 22357 "Object.defineProperty(o, 'key', "
20769 " { get: function() {}, set: function() {} });"); 22358 " { get: function() {}, set: function() {} });");
20770 } 22359 }
20771 22360
20772 class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream { 22361 class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream {
20773 public: 22362 public:
20774 explicit TestSourceStream(const char** chunks) : chunks_(chunks), index_(0) {} 22363 explicit TestSourceStream(const char** chunks) : chunks_(chunks), index_(0) {}
20775 22364
20776 virtual size_t GetMoreData(const uint8_t** src) { 22365 virtual size_t GetMoreData(const uint8_t** src) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
20832 // TestSourceStream::GetMoreData won't block, so it's OK to just run the 22421 // TestSourceStream::GetMoreData won't block, so it's OK to just run the
20833 // task here in the main thread. 22422 // task here in the main thread.
20834 task->Run(); 22423 task->Run();
20835 delete task; 22424 delete task;
20836 22425
20837 // Possible errors are only produced while compiling. 22426 // Possible errors are only produced while compiling.
20838 CHECK_EQ(false, try_catch.HasCaught()); 22427 CHECK_EQ(false, try_catch.HasCaught());
20839 22428
20840 v8::ScriptOrigin origin(v8_str("http://foo.com")); 22429 v8::ScriptOrigin origin(v8_str("http://foo.com"));
20841 char* full_source = TestSourceStream::FullSourceString(chunks); 22430 char* full_source = TestSourceStream::FullSourceString(chunks);
20842 v8::Handle<Script> script = v8::ScriptCompiler::Compile( 22431 v8::Local<Script> script = v8::ScriptCompiler::Compile(
20843 isolate, &source, v8_str(full_source), origin); 22432 isolate, &source, v8_str(full_source), origin);
20844 if (expected_success) { 22433 if (expected_success) {
20845 CHECK(!script.IsEmpty()); 22434 CHECK(!script.IsEmpty());
20846 v8::Handle<Value> result(script->Run()); 22435 v8::Local<Value> result(script->Run());
20847 // All scripts are supposed to return the fixed value 13 when ran. 22436 // All scripts are supposed to return the fixed value 13 when ran.
20848 CHECK_EQ(13, result->Int32Value()); 22437 CHECK_EQ(13, result->Int32Value(env.local()).FromJust());
20849 CheckMagicComments(script, expected_source_url, 22438 CheckMagicComments(script, expected_source_url,
20850 expected_source_mapping_url); 22439 expected_source_mapping_url);
20851 } else { 22440 } else {
20852 CHECK(script.IsEmpty()); 22441 CHECK(script.IsEmpty());
20853 CHECK(try_catch.HasCaught()); 22442 CHECK(try_catch.HasCaught());
20854 } 22443 }
20855 delete[] full_source; 22444 delete[] full_source;
20856 } 22445 }
20857 22446
20858 22447
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
21107 task->Run(); 22696 task->Run();
21108 delete task; 22697 delete task;
21109 22698
21110 CHECK(!try_catch.HasCaught()); 22699 CHECK(!try_catch.HasCaught());
21111 22700
21112 v8::ScriptOrigin origin(v8_str("http://foo.com")); 22701 v8::ScriptOrigin origin(v8_str("http://foo.com"));
21113 char* full_source = TestSourceStream::FullSourceString(chunks); 22702 char* full_source = TestSourceStream::FullSourceString(chunks);
21114 22703
21115 EnableDebugger(); 22704 EnableDebugger();
21116 22705
21117 v8::Handle<Script> script = v8::ScriptCompiler::Compile( 22706 v8::Local<Script> script = v8::ScriptCompiler::Compile(
21118 isolate, &source, v8_str(full_source), origin); 22707 isolate, &source, v8_str(full_source), origin);
21119 22708
21120 Maybe<uint32_t> result = 22709 Maybe<uint32_t> result =
21121 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); 22710 script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local());
21122 CHECK_EQ(3U, result.FromMaybe(0)); 22711 CHECK_EQ(3U, result.FromMaybe(0));
21123 22712
21124 delete[] full_source; 22713 delete[] full_source;
21125 22714
21126 DisableDebugger(); 22715 DisableDebugger();
21127 } 22716 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
21211 v8::ScriptCompiler::StartStreamingScript(isolate, &source); 22800 v8::ScriptCompiler::StartStreamingScript(isolate, &source);
21212 task->Run(); 22801 task->Run();
21213 delete task; 22802 delete task;
21214 22803
21215 // Parsing should succeed (the script will be parsed and compiled in a context 22804 // Parsing should succeed (the script will be parsed and compiled in a context
21216 // independent way, so the error is not detected). 22805 // independent way, so the error is not detected).
21217 CHECK_EQ(false, try_catch.HasCaught()); 22806 CHECK_EQ(false, try_catch.HasCaught());
21218 22807
21219 v8::ScriptOrigin origin(v8_str("http://foo.com")); 22808 v8::ScriptOrigin origin(v8_str("http://foo.com"));
21220 char* full_source = TestSourceStream::FullSourceString(chunks); 22809 char* full_source = TestSourceStream::FullSourceString(chunks);
21221 v8::Handle<Script> script = v8::ScriptCompiler::Compile( 22810 v8::Local<Script> script = v8::ScriptCompiler::Compile(
21222 isolate, &source, v8_str(full_source), origin); 22811 isolate, &source, v8_str(full_source), origin);
21223 CHECK(!script.IsEmpty()); 22812 CHECK(!script.IsEmpty());
21224 CHECK_EQ(false, try_catch.HasCaught()); 22813 CHECK_EQ(false, try_catch.HasCaught());
21225 22814
21226 // Running the script exposes the error. 22815 // Running the script exposes the error.
21227 v8::Handle<Value> result(script->Run()); 22816 v8::Local<Value> result(script->Run());
21228 CHECK(result.IsEmpty()); 22817 CHECK(result.IsEmpty());
21229 CHECK(try_catch.HasCaught()); 22818 CHECK(try_catch.HasCaught());
21230 delete[] full_source; 22819 delete[] full_source;
21231 } 22820 }
21232 22821
21233 22822
21234 TEST(CodeCache) { 22823 TEST(CodeCache) {
21235 v8::Isolate::CreateParams create_params; 22824 v8::Isolate::CreateParams create_params;
21236 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); 22825 create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
21237 22826
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
21270 v8::ScriptCompiler::Source source(source_string, script_origin, cache); 22859 v8::ScriptCompiler::Source source(source_string, script_origin, cache);
21271 v8::ScriptCompiler::CompileOptions option = 22860 v8::ScriptCompiler::CompileOptions option =
21272 v8::ScriptCompiler::kConsumeCodeCache; 22861 v8::ScriptCompiler::kConsumeCodeCache;
21273 v8::Local<v8::Script> script; 22862 v8::Local<v8::Script> script;
21274 { 22863 {
21275 i::DisallowCompilation no_compile( 22864 i::DisallowCompilation no_compile(
21276 reinterpret_cast<i::Isolate*>(isolate2)); 22865 reinterpret_cast<i::Isolate*>(isolate2));
21277 script = v8::ScriptCompiler::Compile(context, &source, option) 22866 script = v8::ScriptCompiler::Compile(context, &source, option)
21278 .ToLocalChecked(); 22867 .ToLocalChecked();
21279 } 22868 }
21280 CHECK_EQ(2, script->Run()->ToInt32(isolate2)->Int32Value()); 22869 CHECK_EQ(2,
22870 script->Run()->ToInt32(isolate2)->Int32Value(context).FromJust());
21281 } 22871 }
21282 isolate2->Dispose(); 22872 isolate2->Dispose();
21283 } 22873 }
21284 22874
21285 22875
21286 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { 22876 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) {
21287 const char* garbage = "garbage garbage garbage garbage garbage garbage"; 22877 const char* garbage = "garbage garbage garbage garbage garbage garbage";
21288 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); 22878 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage);
21289 int length = 16; 22879 int length = 16;
21290 v8::ScriptCompiler::CachedData* cached_data = 22880 v8::ScriptCompiler::CachedData* cached_data =
21291 new v8::ScriptCompiler::CachedData(data, length); 22881 new v8::ScriptCompiler::CachedData(data, length);
21292 DCHECK(!cached_data->rejected); 22882 DCHECK(!cached_data->rejected);
21293 v8::ScriptOrigin origin(v8_str("origin")); 22883 v8::ScriptOrigin origin(v8_str("origin"));
21294 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); 22884 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data);
21295 v8::Handle<v8::Script> script = 22885 v8::Local<v8::Script> script =
21296 v8::ScriptCompiler::Compile(CcTest::isolate(), &source, option); 22886 v8::ScriptCompiler::Compile(CcTest::isolate(), &source, option);
21297 CHECK(cached_data->rejected); 22887 CHECK(cached_data->rejected);
21298 CHECK_EQ(42, script->Run()->Int32Value()); 22888 CHECK_EQ(42, script->Run()
22889 ->Int32Value(CcTest::isolate()->GetCurrentContext())
22890 .FromJust());
21299 } 22891 }
21300 22892
21301 22893
21302 TEST(InvalidCacheData) { 22894 TEST(InvalidCacheData) {
21303 v8::V8::Initialize(); 22895 v8::V8::Initialize();
21304 v8::HandleScope scope(CcTest::isolate()); 22896 v8::HandleScope scope(CcTest::isolate());
21305 LocalContext context; 22897 LocalContext context;
21306 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); 22898 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache);
21307 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); 22899 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache);
21308 } 22900 }
21309 22901
21310 22902
21311 TEST(ParserCacheRejectedGracefully) { 22903 TEST(ParserCacheRejectedGracefully) {
21312 i::FLAG_min_preparse_length = 0; 22904 i::FLAG_min_preparse_length = 0;
21313 v8::V8::Initialize(); 22905 v8::V8::Initialize();
21314 v8::HandleScope scope(CcTest::isolate()); 22906 v8::HandleScope scope(CcTest::isolate());
21315 LocalContext context; 22907 LocalContext context;
21316 // Produce valid cached data. 22908 // Produce valid cached data.
21317 v8::ScriptOrigin origin(v8_str("origin")); 22909 v8::ScriptOrigin origin(v8_str("origin"));
21318 v8::Local<v8::String> source_str = v8_str("function foo() {}"); 22910 v8::Local<v8::String> source_str = v8_str("function foo() {}");
21319 v8::ScriptCompiler::Source source(source_str, origin); 22911 v8::ScriptCompiler::Source source(source_str, origin);
21320 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile( 22912 v8::Local<v8::Script> script = v8::ScriptCompiler::Compile(
21321 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache); 22913 CcTest::isolate(), &source, v8::ScriptCompiler::kProduceParserCache);
21322 CHECK(!script.IsEmpty()); 22914 CHECK(!script.IsEmpty());
21323 const v8::ScriptCompiler::CachedData* original_cached_data = 22915 const v8::ScriptCompiler::CachedData* original_cached_data =
21324 source.GetCachedData(); 22916 source.GetCachedData();
21325 CHECK(original_cached_data != NULL); 22917 CHECK(original_cached_data != NULL);
21326 CHECK(original_cached_data->data != NULL); 22918 CHECK(original_cached_data->data != NULL);
21327 CHECK(!original_cached_data->rejected); 22919 CHECK(!original_cached_data->rejected);
21328 CHECK_GT(original_cached_data->length, 0); 22920 CHECK_GT(original_cached_data->length, 0);
21329 // Recompiling the same script with it won't reject the data. 22921 // Recompiling the same script with it won't reject the data.
21330 { 22922 {
21331 v8::ScriptCompiler::Source source_with_cached_data( 22923 v8::ScriptCompiler::Source source_with_cached_data(
21332 source_str, origin, 22924 source_str, origin,
21333 new v8::ScriptCompiler::CachedData(original_cached_data->data, 22925 new v8::ScriptCompiler::CachedData(original_cached_data->data,
21334 original_cached_data->length)); 22926 original_cached_data->length));
21335 v8::Handle<v8::Script> script = 22927 v8::Local<v8::Script> script =
21336 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, 22928 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data,
21337 v8::ScriptCompiler::kConsumeParserCache); 22929 v8::ScriptCompiler::kConsumeParserCache);
21338 CHECK(!script.IsEmpty()); 22930 CHECK(!script.IsEmpty());
21339 const v8::ScriptCompiler::CachedData* new_cached_data = 22931 const v8::ScriptCompiler::CachedData* new_cached_data =
21340 source_with_cached_data.GetCachedData(); 22932 source_with_cached_data.GetCachedData();
21341 CHECK(new_cached_data != NULL); 22933 CHECK(new_cached_data != NULL);
21342 CHECK(!new_cached_data->rejected); 22934 CHECK(!new_cached_data->rejected);
21343 } 22935 }
21344 // Compile an incompatible script with the cached data. The new script doesn't 22936 // 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 22937 // 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. 22938 // cached data will be incompatible with it and will be rejected.
21347 { 22939 {
21348 v8::Local<v8::String> incompatible_source_str = 22940 v8::Local<v8::String> incompatible_source_str =
21349 v8_str(" function foo() {}"); 22941 v8_str(" function foo() {}");
21350 v8::ScriptCompiler::Source source_with_cached_data( 22942 v8::ScriptCompiler::Source source_with_cached_data(
21351 incompatible_source_str, origin, 22943 incompatible_source_str, origin,
21352 new v8::ScriptCompiler::CachedData(original_cached_data->data, 22944 new v8::ScriptCompiler::CachedData(original_cached_data->data,
21353 original_cached_data->length)); 22945 original_cached_data->length));
21354 v8::Handle<v8::Script> script = 22946 v8::Local<v8::Script> script =
21355 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data, 22947 v8::ScriptCompiler::Compile(CcTest::isolate(), &source_with_cached_data,
21356 v8::ScriptCompiler::kConsumeParserCache); 22948 v8::ScriptCompiler::kConsumeParserCache);
21357 CHECK(!script.IsEmpty()); 22949 CHECK(!script.IsEmpty());
21358 const v8::ScriptCompiler::CachedData* new_cached_data = 22950 const v8::ScriptCompiler::CachedData* new_cached_data =
21359 source_with_cached_data.GetCachedData(); 22951 source_with_cached_data.GetCachedData();
21360 CHECK(new_cached_data != NULL); 22952 CHECK(new_cached_data != NULL);
21361 CHECK(new_cached_data->rejected); 22953 CHECK(new_cached_data->rejected);
21362 } 22954 }
21363 } 22955 }
21364 22956
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
21413 CHECK_EQ(should_be_neuterable, result->IsNeuterable()); 23005 CHECK_EQ(should_be_neuterable, result->IsNeuterable());
21414 } 23006 }
21415 23007
21416 23008
21417 TEST(GetPrototypeAccessControl) { 23009 TEST(GetPrototypeAccessControl) {
21418 i::FLAG_allow_natives_syntax = true; 23010 i::FLAG_allow_natives_syntax = true;
21419 v8::Isolate* isolate = CcTest::isolate(); 23011 v8::Isolate* isolate = CcTest::isolate();
21420 v8::HandleScope handle_scope(isolate); 23012 v8::HandleScope handle_scope(isolate);
21421 LocalContext env; 23013 LocalContext env;
21422 23014
21423 v8::Handle<v8::ObjectTemplate> obj_template = 23015 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
21424 v8::ObjectTemplate::New(isolate);
21425 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked); 23016 obj_template->SetAccessCheckCallback(AccessAlwaysBlocked);
21426 23017
21427 env->Global()->Set(v8_str("prohibited"), obj_template->NewInstance()); 23018 CHECK(env->Global()
23019 ->Set(env.local(), v8_str("prohibited"),
23020 obj_template->NewInstance(env.local()).ToLocalChecked())
23021 .FromJust());
21428 23022
21429 CHECK(CompileRun( 23023 CHECK(CompileRun(
21430 "function f() { return %_GetPrototype(prohibited); }" 23024 "function f() { return %_GetPrototype(prohibited); }"
21431 "%OptimizeFunctionOnNextCall(f);" 23025 "%OptimizeFunctionOnNextCall(f);"
21432 "f();")->IsNull()); 23026 "f();")->IsNull());
21433 } 23027 }
21434 23028
21435 23029
21436 TEST(GetPrototypeHidden) { 23030 TEST(GetPrototypeHidden) {
21437 i::FLAG_allow_natives_syntax = true; 23031 i::FLAG_allow_natives_syntax = true;
21438 v8::Isolate* isolate = CcTest::isolate(); 23032 v8::Isolate* isolate = CcTest::isolate();
21439 v8::HandleScope handle_scope(isolate); 23033 v8::HandleScope handle_scope(isolate);
21440 LocalContext env; 23034 LocalContext env;
21441 23035
21442 Handle<FunctionTemplate> t = FunctionTemplate::New(isolate); 23036 Local<FunctionTemplate> t = FunctionTemplate::New(isolate);
21443 t->SetHiddenPrototype(true); 23037 t->SetHiddenPrototype(true);
21444 Handle<Object> proto = t->GetFunction()->NewInstance(); 23038 Local<Object> proto = t->GetFunction(env.local())
21445 Handle<Object> object = Object::New(isolate); 23039 .ToLocalChecked()
21446 Handle<Object> proto2 = Object::New(isolate); 23040 ->NewInstance(env.local())
23041 .ToLocalChecked();
23042 Local<Object> object = Object::New(isolate);
23043 Local<Object> proto2 = Object::New(isolate);
21447 object->SetPrototype(proto); 23044 object->SetPrototype(proto);
21448 proto->SetPrototype(proto2); 23045 proto->SetPrototype(proto2);
21449 23046
21450 env->Global()->Set(v8_str("object"), object); 23047 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust());
21451 env->Global()->Set(v8_str("proto"), proto); 23048 CHECK(env->Global()->Set(env.local(), v8_str("proto"), proto).FromJust());
21452 env->Global()->Set(v8_str("proto2"), proto2); 23049 CHECK(env->Global()->Set(env.local(), v8_str("proto2"), proto2).FromJust());
21453 23050
21454 v8::Handle<v8::Value> result = CompileRun("%_GetPrototype(object)"); 23051 v8::Local<v8::Value> result = CompileRun("%_GetPrototype(object)");
21455 CHECK(result->Equals(proto2)); 23052 CHECK(result->Equals(proto2));
21456 23053
21457 result = CompileRun( 23054 result = CompileRun(
21458 "function f() { return %_GetPrototype(object); }" 23055 "function f() { return %_GetPrototype(object); }"
21459 "%OptimizeFunctionOnNextCall(f);" 23056 "%OptimizeFunctionOnNextCall(f);"
21460 "f()"); 23057 "f()");
21461 CHECK(result->Equals(proto2)); 23058 CHECK(result->Equals(proto2));
21462 } 23059 }
21463 23060
21464 23061
21465 TEST(ClassPrototypeCreationContext) { 23062 TEST(ClassPrototypeCreationContext) {
21466 v8::Isolate* isolate = CcTest::isolate(); 23063 v8::Isolate* isolate = CcTest::isolate();
21467 v8::HandleScope handle_scope(isolate); 23064 v8::HandleScope handle_scope(isolate);
21468 LocalContext env; 23065 LocalContext env;
21469 23066
21470 Handle<Object> result = Handle<Object>::Cast( 23067 Local<Object> result = Local<Object>::Cast(
21471 CompileRun("'use strict'; class Example { }; Example.prototype")); 23068 CompileRun("'use strict'; class Example { }; Example.prototype"));
21472 CHECK(env.local() == result->CreationContext()); 23069 CHECK(env.local() == result->CreationContext());
21473 } 23070 }
21474 23071
21475 23072
21476 TEST(SimpleStreamingScriptWithSourceURL) { 23073 TEST(SimpleStreamingScriptWithSourceURL) {
21477 const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n", 23074 const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n",
21478 "//# sourceURL=bar2.js\n", NULL}; 23075 "//# sourceURL=bar2.js\n", NULL};
21479 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, 23076 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true,
21480 "bar2.js"); 23077 "bar2.js");
(...skipping 20 matching lines...) Expand all
21501 v8::Isolate* isolate = CcTest::isolate(); 23098 v8::Isolate* isolate = CcTest::isolate();
21502 v8::HandleScope handle_scope(isolate); 23099 v8::HandleScope handle_scope(isolate);
21503 const int length = i::String::kMaxLength + 1; 23100 const int length = i::String::kMaxLength + 1;
21504 const int buffer_size = length * sizeof(uint16_t); 23101 const int buffer_size = length * sizeof(uint16_t);
21505 void* buffer = malloc(buffer_size); 23102 void* buffer = malloc(buffer_size);
21506 if (buffer == NULL) return; 23103 if (buffer == NULL) return;
21507 memset(buffer, 'A', buffer_size); 23104 memset(buffer, 'A', buffer_size);
21508 { 23105 {
21509 v8::TryCatch try_catch(isolate); 23106 v8::TryCatch try_catch(isolate);
21510 char* data = reinterpret_cast<char*>(buffer); 23107 char* data = reinterpret_cast<char*>(buffer);
21511 CHECK(v8::String::NewFromUtf8(isolate, data, v8::String::kNormalString, 23108 CHECK(v8::String::NewFromUtf8(isolate, data, v8::NewStringType::kNormal,
21512 length).IsEmpty()); 23109 length)
23110 .IsEmpty());
21513 CHECK(!try_catch.HasCaught()); 23111 CHECK(!try_catch.HasCaught());
21514 } 23112 }
21515 { 23113 {
21516 v8::TryCatch try_catch(isolate); 23114 v8::TryCatch try_catch(isolate);
21517 uint8_t* data = reinterpret_cast<uint8_t*>(buffer); 23115 uint8_t* data = reinterpret_cast<uint8_t*>(buffer);
21518 CHECK(v8::String::NewFromOneByte(isolate, data, v8::String::kNormalString, 23116 CHECK(v8::String::NewFromOneByte(isolate, data, v8::NewStringType::kNormal,
21519 length).IsEmpty()); 23117 length)
23118 .IsEmpty());
21520 CHECK(!try_catch.HasCaught()); 23119 CHECK(!try_catch.HasCaught());
21521 } 23120 }
21522 { 23121 {
21523 v8::TryCatch try_catch(isolate); 23122 v8::TryCatch try_catch(isolate);
21524 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); 23123 uint16_t* data = reinterpret_cast<uint16_t*>(buffer);
21525 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, 23124 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::NewStringType::kNormal,
21526 length).IsEmpty()); 23125 length)
23126 .IsEmpty());
21527 CHECK(!try_catch.HasCaught()); 23127 CHECK(!try_catch.HasCaught());
21528 } 23128 }
21529 free(buffer); 23129 free(buffer);
21530 } 23130 }
21531 23131
21532 23132
21533 TEST(SealHandleScope) { 23133 TEST(SealHandleScope) {
21534 v8::Isolate* isolate = CcTest::isolate(); 23134 v8::Isolate* isolate = CcTest::isolate();
21535 v8::HandleScope handle_scope(isolate); 23135 v8::HandleScope handle_scope(isolate);
21536 LocalContext env; 23136 LocalContext env;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
21576 Local<v8::Object> accessed_object) { 23176 Local<v8::Object> accessed_object) {
21577 access_was_called = true; 23177 access_was_called = true;
21578 return false; 23178 return false;
21579 } 23179 }
21580 23180
21581 23181
21582 TEST(StrongModeAccessCheckAllowed) { 23182 TEST(StrongModeAccessCheckAllowed) {
21583 i::FLAG_strong_mode = true; 23183 i::FLAG_strong_mode = true;
21584 v8::Isolate* isolate = CcTest::isolate(); 23184 v8::Isolate* isolate = CcTest::isolate();
21585 v8::HandleScope handle_scope(isolate); 23185 v8::HandleScope handle_scope(isolate);
21586 v8::Handle<Value> value; 23186 v8::Local<Value> value;
21587 access_was_called = false; 23187 access_was_called = false;
21588 23188
21589 v8::Handle<v8::ObjectTemplate> obj_template = 23189 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
21590 v8::ObjectTemplate::New(isolate);
21591 23190
21592 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 23191 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21593 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag); 23192 obj_template->SetAccessCheckCallback(AccessAlwaysAllowedWithFlag);
21594 23193
21595 // Create an environment 23194 // Create an environment
21596 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 23195 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21597 context0->Enter(); 23196 context0->Enter();
21598 v8::Handle<v8::Object> global0 = context0->Global(); 23197 v8::Local<v8::Object> global0 = context0->Global();
21599 global0->Set(v8_str("object"), obj_template->NewInstance()); 23198 global0->Set(v8_str("object"),
23199 obj_template->NewInstance(context0).ToLocalChecked());
21600 { 23200 {
21601 v8::TryCatch try_catch(isolate); 23201 v8::TryCatch try_catch(isolate);
21602 value = CompileRun("'use strong'; object.x"); 23202 value = CompileRun("'use strong'; object.x");
21603 CHECK(!try_catch.HasCaught()); 23203 CHECK(!try_catch.HasCaught());
21604 CHECK(!access_was_called); 23204 CHECK(!access_was_called);
21605 CHECK_EQ(42, value->Int32Value()); 23205 CHECK_EQ(42, value->Int32Value(context0).FromJust());
21606 } 23206 }
21607 { 23207 {
21608 v8::TryCatch try_catch(isolate); 23208 v8::TryCatch try_catch(isolate);
21609 value = CompileRun("'use strong'; object.foo"); 23209 value = CompileRun("'use strong'; object.foo");
21610 CHECK(try_catch.HasCaught()); 23210 CHECK(try_catch.HasCaught());
21611 CHECK(!access_was_called); 23211 CHECK(!access_was_called);
21612 } 23212 }
21613 { 23213 {
21614 v8::TryCatch try_catch(isolate); 23214 v8::TryCatch try_catch(isolate);
21615 value = CompileRun("'use strong'; object[10]"); 23215 value = CompileRun("'use strong'; object[10]");
21616 CHECK(try_catch.HasCaught()); 23216 CHECK(try_catch.HasCaught());
21617 CHECK(!access_was_called); 23217 CHECK(!access_was_called);
21618 } 23218 }
21619 23219
21620 // Create an environment 23220 // Create an environment
21621 v8::Local<Context> context1 = Context::New(isolate); 23221 v8::Local<Context> context1 = Context::New(isolate);
21622 context1->Enter(); 23222 context1->Enter();
21623 v8::Handle<v8::Object> global1 = context1->Global(); 23223 v8::Local<v8::Object> global1 = context1->Global();
21624 global1->Set(v8_str("object"), obj_template->NewInstance()); 23224 global1->Set(v8_str("object"),
23225 obj_template->NewInstance(context1).ToLocalChecked());
21625 { 23226 {
21626 v8::TryCatch try_catch(isolate); 23227 v8::TryCatch try_catch(isolate);
21627 value = CompileRun("'use strong'; object.x"); 23228 value = CompileRun("'use strong'; object.x");
21628 CHECK(!try_catch.HasCaught()); 23229 CHECK(!try_catch.HasCaught());
21629 CHECK(access_was_called); 23230 CHECK(access_was_called);
21630 CHECK_EQ(42, value->Int32Value()); 23231 CHECK_EQ(42, value->Int32Value(context1).FromJust());
21631 } 23232 }
21632 access_was_called = false; 23233 access_was_called = false;
21633 { 23234 {
21634 v8::TryCatch try_catch(isolate); 23235 v8::TryCatch try_catch(isolate);
21635 value = CompileRun("'use strong'; object.foo"); 23236 value = CompileRun("'use strong'; object.foo");
21636 CHECK(try_catch.HasCaught()); 23237 CHECK(try_catch.HasCaught());
21637 CHECK(access_was_called); 23238 CHECK(access_was_called);
21638 } 23239 }
21639 access_was_called = false; 23240 access_was_called = false;
21640 { 23241 {
21641 v8::TryCatch try_catch(isolate); 23242 v8::TryCatch try_catch(isolate);
21642 value = CompileRun("'use strong'; object[10]"); 23243 value = CompileRun("'use strong'; object[10]");
21643 CHECK(try_catch.HasCaught()); 23244 CHECK(try_catch.HasCaught());
21644 CHECK(access_was_called); 23245 CHECK(access_was_called);
21645 } 23246 }
21646 23247
21647 context1->Exit(); 23248 context1->Exit();
21648 context0->Exit(); 23249 context0->Exit();
21649 } 23250 }
21650 23251
21651 23252
21652 TEST(StrongModeAccessCheckBlocked) { 23253 TEST(StrongModeAccessCheckBlocked) {
21653 i::FLAG_strong_mode = true; 23254 i::FLAG_strong_mode = true;
21654 v8::Isolate* isolate = CcTest::isolate(); 23255 v8::Isolate* isolate = CcTest::isolate();
21655 v8::HandleScope handle_scope(isolate); 23256 v8::HandleScope handle_scope(isolate);
21656 v8::Handle<Value> value; 23257 v8::Local<Value> value;
21657 access_was_called = false; 23258 access_was_called = false;
21658 23259
21659 v8::Handle<v8::ObjectTemplate> obj_template = 23260 v8::Local<v8::ObjectTemplate> obj_template = v8::ObjectTemplate::New(isolate);
21660 v8::ObjectTemplate::New(isolate);
21661 23261
21662 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42)); 23262 obj_template->Set(v8_str("x"), v8::Integer::New(isolate, 42));
21663 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag); 23263 obj_template->SetAccessCheckCallback(AccessAlwaysBlockedWithFlag);
21664 23264
21665 // Create an environment 23265 // Create an environment
21666 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template); 23266 v8::Local<Context> context0 = Context::New(isolate, NULL, obj_template);
21667 context0->Enter(); 23267 context0->Enter();
21668 v8::Handle<v8::Object> global0 = context0->Global(); 23268 v8::Local<v8::Object> global0 = context0->Global();
21669 global0->Set(v8_str("object"), obj_template->NewInstance()); 23269 global0->Set(v8_str("object"),
23270 obj_template->NewInstance(context0).ToLocalChecked());
21670 { 23271 {
21671 v8::TryCatch try_catch(isolate); 23272 v8::TryCatch try_catch(isolate);
21672 value = CompileRun("'use strong'; object.x"); 23273 value = CompileRun("'use strong'; object.x");
21673 CHECK(!try_catch.HasCaught()); 23274 CHECK(!try_catch.HasCaught());
21674 CHECK(!access_was_called); 23275 CHECK(!access_was_called);
21675 CHECK_EQ(42, value->Int32Value()); 23276 CHECK_EQ(42, value->Int32Value(context0).FromJust());
21676 } 23277 }
21677 { 23278 {
21678 v8::TryCatch try_catch(isolate); 23279 v8::TryCatch try_catch(isolate);
21679 value = CompileRun("'use strong'; object.foo"); 23280 value = CompileRun("'use strong'; object.foo");
21680 CHECK(try_catch.HasCaught()); 23281 CHECK(try_catch.HasCaught());
21681 CHECK(!access_was_called); 23282 CHECK(!access_was_called);
21682 } 23283 }
21683 { 23284 {
21684 v8::TryCatch try_catch(isolate); 23285 v8::TryCatch try_catch(isolate);
21685 value = CompileRun("'use strong'; object[10]"); 23286 value = CompileRun("'use strong'; object[10]");
21686 CHECK(try_catch.HasCaught()); 23287 CHECK(try_catch.HasCaught());
21687 CHECK(!access_was_called); 23288 CHECK(!access_was_called);
21688 } 23289 }
21689 23290
21690 // Create an environment 23291 // Create an environment
21691 v8::Local<Context> context1 = Context::New(isolate); 23292 v8::Local<Context> context1 = Context::New(isolate);
21692 context1->Enter(); 23293 context1->Enter();
21693 v8::Handle<v8::Object> global1 = context1->Global(); 23294 v8::Local<v8::Object> global1 = context1->Global();
21694 global1->Set(v8_str("object"), obj_template->NewInstance()); 23295 global1->Set(v8_str("object"),
23296 obj_template->NewInstance(context1).ToLocalChecked());
21695 { 23297 {
21696 v8::TryCatch try_catch(isolate); 23298 v8::TryCatch try_catch(isolate);
21697 value = CompileRun("'use strong'; object.x"); 23299 value = CompileRun("'use strong'; object.x");
21698 CHECK(try_catch.HasCaught()); 23300 CHECK(try_catch.HasCaught());
21699 CHECK(access_was_called); 23301 CHECK(access_was_called);
21700 } 23302 }
21701 access_was_called = false; 23303 access_was_called = false;
21702 { 23304 {
21703 v8::TryCatch try_catch(isolate); 23305 v8::TryCatch try_catch(isolate);
21704 value = CompileRun("'use strong'; object.foo"); 23306 value = CompileRun("'use strong'; object.foo");
(...skipping 29 matching lines...) Expand all
21734 } 23336 }
21735 23337
21736 { 23338 {
21737 v8::TryCatch try_catch(isolate); 23339 v8::TryCatch try_catch(isolate);
21738 fun->Call(v8::Undefined(isolate), 0, nullptr); 23340 fun->Call(v8::Undefined(isolate), 0, nullptr);
21739 CHECK(try_catch.HasCaught()); 23341 CHECK(try_catch.HasCaught());
21740 } 23342 }
21741 23343
21742 { 23344 {
21743 v8::TryCatch try_catch(isolate); 23345 v8::TryCatch try_catch(isolate);
21744 v8::Handle<Value> args[] = {v8_num(42)}; 23346 v8::Local<Value> args[] = {v8_num(42)};
21745 fun->Call(v8::Undefined(isolate), arraysize(args), args); 23347 fun->Call(v8::Undefined(isolate), arraysize(args), args);
21746 CHECK(!try_catch.HasCaught()); 23348 CHECK(!try_catch.HasCaught());
21747 } 23349 }
21748 23350
21749 { 23351 {
21750 v8::TryCatch try_catch(isolate); 23352 v8::TryCatch try_catch(isolate);
21751 v8::Handle<Value> args[] = {v8_num(42), v8_num(555)}; 23353 v8::Local<Value> args[] = {v8_num(42), v8_num(555)};
21752 fun->Call(v8::Undefined(isolate), arraysize(args), args); 23354 fun->Call(v8::Undefined(isolate), arraysize(args), args);
21753 CHECK(!try_catch.HasCaught()); 23355 CHECK(!try_catch.HasCaught());
21754 } 23356 }
21755 } 23357 }
21756 23358
21757 23359
21758 TEST(StrongModeArityCallFromApi2) { 23360 TEST(StrongModeArityCallFromApi2) {
21759 i::FLAG_strong_mode = true; 23361 i::FLAG_strong_mode = true;
21760 LocalContext env; 23362 LocalContext env;
21761 v8::Isolate* isolate = env->GetIsolate(); 23363 v8::Isolate* isolate = env->GetIsolate();
(...skipping 10 matching lines...) Expand all
21772 } 23374 }
21773 23375
21774 { 23376 {
21775 v8::TryCatch try_catch(isolate); 23377 v8::TryCatch try_catch(isolate);
21776 fun->Call(v8::Undefined(isolate), 0, nullptr); 23378 fun->Call(v8::Undefined(isolate), 0, nullptr);
21777 CHECK(try_catch.HasCaught()); 23379 CHECK(try_catch.HasCaught());
21778 } 23380 }
21779 23381
21780 { 23382 {
21781 v8::TryCatch try_catch(isolate); 23383 v8::TryCatch try_catch(isolate);
21782 v8::Handle<Value> args[] = {v8_num(42)}; 23384 v8::Local<Value> args[] = {v8_num(42)};
21783 fun->Call(v8::Undefined(isolate), arraysize(args), args); 23385 fun->Call(v8::Undefined(isolate), arraysize(args), args);
21784 CHECK(!try_catch.HasCaught()); 23386 CHECK(!try_catch.HasCaught());
21785 } 23387 }
21786 23388
21787 { 23389 {
21788 v8::TryCatch try_catch(isolate); 23390 v8::TryCatch try_catch(isolate);
21789 v8::Handle<Value> args[] = {v8_num(42), v8_num(555)}; 23391 v8::Local<Value> args[] = {v8_num(42), v8_num(555)};
21790 fun->Call(v8::Undefined(isolate), arraysize(args), args); 23392 fun->Call(v8::Undefined(isolate), arraysize(args), args);
21791 CHECK(!try_catch.HasCaught()); 23393 CHECK(!try_catch.HasCaught());
21792 } 23394 }
21793 } 23395 }
21794 23396
21795 23397
21796 TEST(StrongObjectDelete) { 23398 TEST(StrongObjectDelete) {
21797 i::FLAG_strong_mode = true; 23399 i::FLAG_strong_mode = true;
21798 LocalContext env; 23400 LocalContext env;
21799 v8::Isolate* isolate = env->GetIsolate(); 23401 v8::Isolate* isolate = env->GetIsolate();
(...skipping 10 matching lines...) Expand all
21810 obj->ForceSet(v8_str("2"), v8_num(1), v8::None); 23412 obj->ForceSet(v8_str("2"), v8_num(1), v8::None);
21811 CHECK(obj->HasOwnProperty(v8_str("foo"))); 23413 CHECK(obj->HasOwnProperty(v8_str("foo")));
21812 CHECK(obj->HasOwnProperty(v8_str("2"))); 23414 CHECK(obj->HasOwnProperty(v8_str("2")));
21813 CHECK(!obj->Delete(v8_str("foo"))); 23415 CHECK(!obj->Delete(v8_str("foo")));
21814 CHECK(!obj->Delete(2)); 23416 CHECK(!obj->Delete(2));
21815 } 23417 }
21816 23418
21817 23419
21818 static void ExtrasBindingTestRuntimeFunction( 23420 static void ExtrasBindingTestRuntimeFunction(
21819 const v8::FunctionCallbackInfo<v8::Value>& args) { 23421 const v8::FunctionCallbackInfo<v8::Value>& args) {
21820 CHECK_EQ(3, args[0]->Int32Value()); 23422 CHECK_EQ(
23423 3,
23424 args[0]->Int32Value(args.GetIsolate()->GetCurrentContext()).FromJust());
21821 args.GetReturnValue().Set(v8_num(7)); 23425 args.GetReturnValue().Set(v8_num(7));
21822 } 23426 }
21823 23427
21824 23428
21825 TEST(ExtrasBindingObject) { 23429 TEST(ExtrasBindingObject) {
21826 v8::Isolate* isolate = CcTest::isolate(); 23430 v8::Isolate* isolate = CcTest::isolate();
21827 v8::HandleScope handle_scope(isolate); 23431 v8::HandleScope handle_scope(isolate);
21828 LocalContext env; 23432 LocalContext env;
21829 23433
21830 // standalone.gypi ensures we include the test-extra.js file, which should 23434 // standalone.gypi ensures we include the test-extra.js file, which should
21831 // export the tested functions. 23435 // export the tested functions.
21832 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); 23436 v8::Local<v8::Object> binding = env->GetExtrasBindingObject();
21833 23437
21834 auto func = 23438 auto func =
21835 binding->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>(); 23439 binding->Get(v8_str("testExtraShouldReturnFive")).As<v8::Function>();
21836 auto undefined = v8::Undefined(isolate); 23440 auto undefined = v8::Undefined(isolate);
21837 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); 23441 auto result = func->Call(undefined, 0, {}).As<v8::Number>();
21838 CHECK_EQ(5, result->Int32Value()); 23442 CHECK_EQ(5, result->Int32Value(env.local()).FromJust());
21839 23443
21840 v8::Handle<v8::FunctionTemplate> runtimeFunction = 23444 v8::Local<v8::FunctionTemplate> runtimeFunction =
21841 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); 23445 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction);
21842 binding->Set(v8_str("runtime"), runtimeFunction->GetFunction()); 23446 binding->Set(v8_str("runtime"),
23447 runtimeFunction->GetFunction(env.local()).ToLocalChecked());
21843 func = 23448 func =
21844 binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>(); 23449 binding->Get(v8_str("testExtraShouldCallToRuntime")).As<v8::Function>();
21845 result = func->Call(undefined, 0, {}).As<v8::Number>(); 23450 result = func->Call(undefined, 0, {}).As<v8::Number>();
21846 CHECK_EQ(7, result->Int32Value()); 23451 CHECK_EQ(7, result->Int32Value(env.local()).FromJust());
21847 } 23452 }
21848 23453
21849 23454
21850 TEST(ExperimentalExtras) { 23455 TEST(ExperimentalExtras) {
21851 i::FLAG_experimental_extras = true; 23456 i::FLAG_experimental_extras = true;
21852 23457
21853 v8::Isolate* isolate = CcTest::isolate(); 23458 v8::Isolate* isolate = CcTest::isolate();
21854 v8::HandleScope handle_scope(isolate); 23459 v8::HandleScope handle_scope(isolate);
21855 LocalContext env; 23460 LocalContext env;
21856 23461
21857 // standalone.gypi ensures we include the test-experimental-extra.js file, 23462 // standalone.gypi ensures we include the test-experimental-extra.js file,
21858 // which should export the tested functions. 23463 // which should export the tested functions.
21859 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); 23464 v8::Local<v8::Object> binding = env->GetExtrasBindingObject();
21860 23465
21861 auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen")) 23466 auto func = binding->Get(v8_str("testExperimentalExtraShouldReturnTen"))
21862 .As<v8::Function>(); 23467 .As<v8::Function>();
21863 auto undefined = v8::Undefined(isolate); 23468 auto undefined = v8::Undefined(isolate);
21864 auto result = func->Call(undefined, 0, {}).As<v8::Number>(); 23469 auto result = func->Call(undefined, 0, {}).As<v8::Number>();
21865 CHECK_EQ(10, result->Int32Value()); 23470 CHECK_EQ(10, result->Int32Value(env.local()).FromJust());
21866 23471
21867 v8::Handle<v8::FunctionTemplate> runtimeFunction = 23472 v8::Local<v8::FunctionTemplate> runtimeFunction =
21868 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction); 23473 v8::FunctionTemplate::New(isolate, ExtrasBindingTestRuntimeFunction);
21869 binding->Set(v8_str("runtime"), runtimeFunction->GetFunction()); 23474 binding->Set(v8_str("runtime"),
23475 runtimeFunction->GetFunction(env.local()).ToLocalChecked());
21870 func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime")) 23476 func = binding->Get(v8_str("testExperimentalExtraShouldCallToRuntime"))
21871 .As<v8::Function>(); 23477 .As<v8::Function>();
21872 result = func->Call(undefined, 0, {}).As<v8::Number>(); 23478 result = func->Call(undefined, 0, {}).As<v8::Number>();
21873 CHECK_EQ(7, result->Int32Value()); 23479 CHECK_EQ(7, result->Int32Value(env.local()).FromJust());
21874 } 23480 }
21875 23481
21876 23482
21877 TEST(ExtrasUtilsObject) { 23483 TEST(ExtrasUtilsObject) {
21878 LocalContext context; 23484 LocalContext context;
21879 v8::Isolate* isolate = context->GetIsolate(); 23485 v8::Isolate* isolate = context->GetIsolate();
21880 v8::HandleScope handle_scope(isolate); 23486 v8::HandleScope handle_scope(isolate);
21881 23487
21882 LocalContext env; 23488 LocalContext env;
21883 v8::Local<v8::Object> binding = env->GetExtrasBindingObject(); 23489 v8::Local<v8::Object> binding = env->GetExtrasBindingObject();
21884 23490
21885 auto func = binding->Get(v8_str("testExtraCanUseUtils")).As<v8::Function>(); 23491 auto func = binding->Get(v8_str("testExtraCanUseUtils")).As<v8::Function>();
21886 auto undefined = v8::Undefined(isolate); 23492 auto undefined = v8::Undefined(isolate);
21887 auto result = func->Call(undefined, 0, {}).As<v8::Object>(); 23493 auto result = func->Call(undefined, 0, {}).As<v8::Object>();
21888 23494
21889 auto private_symbol = result->Get(v8_str("privateSymbol")).As<v8::Symbol>(); 23495 auto private_symbol = result->Get(v8_str("privateSymbol")).As<v8::Symbol>();
21890 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol); 23496 i::Handle<i::Symbol> ips = v8::Utils::OpenHandle(*private_symbol);
21891 CHECK_EQ(true, ips->IsPrivate()); 23497 CHECK_EQ(true, ips->IsPrivate());
21892 23498
21893 CompileRun("var result = 0; function store(x) { result = x; }"); 23499 CompileRun("var result = 0; function store(x) { result = x; }");
21894 auto store = CompileRun("store").As<v8::Function>(); 23500 auto store = CompileRun("store").As<v8::Function>();
21895 23501
21896 auto fulfilled_promise = 23502 auto fulfilled_promise =
21897 result->Get(v8_str("fulfilledPromise")).As<v8::Promise>(); 23503 result->Get(v8_str("fulfilledPromise")).As<v8::Promise>();
21898 fulfilled_promise->Then(store); 23504 fulfilled_promise->Then(store);
21899 isolate->RunMicrotasks(); 23505 isolate->RunMicrotasks();
21900 CHECK_EQ(1, CompileRun("result")->Int32Value()); 23506 CHECK_EQ(1, CompileRun("result")->Int32Value(env.local()).FromJust());
21901 23507
21902 auto fulfilled_promise_2 = 23508 auto fulfilled_promise_2 =
21903 result->Get(v8_str("fulfilledPromise2")).As<v8::Promise>(); 23509 result->Get(v8_str("fulfilledPromise2")).As<v8::Promise>();
21904 fulfilled_promise_2->Then(store); 23510 fulfilled_promise_2->Then(store);
21905 isolate->RunMicrotasks(); 23511 isolate->RunMicrotasks();
21906 CHECK_EQ(2, CompileRun("result")->Int32Value()); 23512 CHECK_EQ(2, CompileRun("result")->Int32Value(env.local()).FromJust());
21907 23513
21908 auto rejected_promise = 23514 auto rejected_promise =
21909 result->Get(v8_str("rejectedPromise")).As<v8::Promise>(); 23515 result->Get(v8_str("rejectedPromise")).As<v8::Promise>();
21910 rejected_promise->Catch(store); 23516 rejected_promise->Catch(store);
21911 isolate->RunMicrotasks(); 23517 isolate->RunMicrotasks();
21912 CHECK_EQ(3, CompileRun("result")->Int32Value()); 23518 CHECK_EQ(3, CompileRun("result")->Int32Value(env.local()).FromJust());
21913 } 23519 }
21914 23520
21915 23521
21916 TEST(Map) { 23522 TEST(Map) {
21917 v8::Isolate* isolate = CcTest::isolate(); 23523 v8::Isolate* isolate = CcTest::isolate();
21918 v8::HandleScope handle_scope(isolate); 23524 v8::HandleScope handle_scope(isolate);
21919 LocalContext env; 23525 LocalContext env;
21920 23526
21921 v8::Local<v8::Map> map = v8::Map::New(isolate); 23527 v8::Local<v8::Map> map = v8::Map::New(isolate);
21922 CHECK(map->IsObject()); 23528 CHECK(map->IsObject());
(...skipping 16 matching lines...) Expand all
21939 CHECK_EQ(2U, map->Size()); 23545 CHECK_EQ(2U, map->Size());
21940 23546
21941 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust()); 23547 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 1)).FromJust());
21942 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust()); 23548 CHECK(map->Has(env.local(), v8::Integer::New(isolate, 3)).FromJust());
21943 23549
21944 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust()); 23550 CHECK(!map->Has(env.local(), v8::Integer::New(isolate, 2)).FromJust());
21945 CHECK(!map->Has(env.local(), map).FromJust()); 23551 CHECK(!map->Has(env.local(), map).FromJust());
21946 23552
21947 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1)) 23553 CHECK_EQ(2, map->Get(env.local(), v8::Integer::New(isolate, 1))
21948 .ToLocalChecked() 23554 .ToLocalChecked()
21949 ->Int32Value()); 23555 ->Int32Value(env.local())
23556 .FromJust());
21950 CHECK_EQ(4, map->Get(env.local(), v8::Integer::New(isolate, 3)) 23557 CHECK_EQ(4, map->Get(env.local(), v8::Integer::New(isolate, 3))
21951 .ToLocalChecked() 23558 .ToLocalChecked()
21952 ->Int32Value()); 23559 ->Int32Value(env.local())
23560 .FromJust());
21953 23561
21954 CHECK(map->Get(env.local(), v8::Integer::New(isolate, 42)) 23562 CHECK(map->Get(env.local(), v8::Integer::New(isolate, 42))
21955 .ToLocalChecked() 23563 .ToLocalChecked()
21956 ->IsUndefined()); 23564 ->IsUndefined());
21957 23565
21958 CHECK(!map->Set(env.local(), map, map).IsEmpty()); 23566 CHECK(!map->Set(env.local(), map, map).IsEmpty());
21959 CHECK_EQ(3U, map->Size()); 23567 CHECK_EQ(3U, map->Size());
21960 CHECK(map->Has(env.local(), map).FromJust()); 23568 CHECK(map->Has(env.local(), map).FromJust());
21961 23569
21962 CHECK(map->Delete(env.local(), map).FromJust()); 23570 CHECK(map->Delete(env.local(), map).FromJust());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
22016 v8::Isolate* isolate = CcTest::isolate(); 23624 v8::Isolate* isolate = CcTest::isolate();
22017 v8::HandleScope scope(isolate); 23625 v8::HandleScope scope(isolate);
22018 v8::Local<v8::FunctionTemplate> parent = FunctionTemplate::New(isolate); 23626 v8::Local<v8::FunctionTemplate> parent = FunctionTemplate::New(isolate);
22019 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, parent); 23627 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, parent);
22020 auto returns_42 = 23628 auto returns_42 =
22021 v8::FunctionTemplate::New(isolate, Returns42, Local<Value>(), signature); 23629 v8::FunctionTemplate::New(isolate, Returns42, Local<Value>(), signature);
22022 parent->PrototypeTemplate()->SetAccessorProperty(v8_str("age"), returns_42); 23630 parent->PrototypeTemplate()->SetAccessorProperty(v8_str("age"), returns_42);
22023 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate); 23631 v8::Local<v8::FunctionTemplate> child = v8::FunctionTemplate::New(isolate);
22024 child->Inherit(parent); 23632 child->Inherit(parent);
22025 LocalContext env; 23633 LocalContext env;
22026 env->Global()->Set(v8_str("Child"), child->GetFunction()); 23634 CHECK(env->Global()
23635 ->Set(env.local(), v8_str("Child"),
23636 child->GetFunction(env.local()).ToLocalChecked())
23637 .FromJust());
22027 23638
22028 // Make sure there's a compiled stub for "Child.prototype.age" in the cache. 23639 // Make sure there's a compiled stub for "Child.prototype.age" in the cache.
22029 CompileRun( 23640 CompileRun(
22030 "var real = new Child();\n" 23641 "var real = new Child();\n"
22031 "for (var i = 0; i < 3; ++i) {\n" 23642 "for (var i = 0; i < 3; ++i) {\n"
22032 " real.age;\n" 23643 " real.age;\n"
22033 "}\n"); 23644 "}\n");
22034 23645
22035 // Check that the cached stub is never used. 23646 // Check that the cached stub is never used.
22036 ExpectInt32( 23647 ExpectInt32(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
22099 23710
22100 bool NoAbortOnUncaughtException(v8::Isolate* isolate) { 23711 bool NoAbortOnUncaughtException(v8::Isolate* isolate) {
22101 ++nb_uncaught_exception_callback_calls; 23712 ++nb_uncaught_exception_callback_calls;
22102 return false; 23713 return false;
22103 } 23714 }
22104 23715
22105 23716
22106 TEST(AbortOnUncaughtExceptionNoAbort) { 23717 TEST(AbortOnUncaughtExceptionNoAbort) {
22107 v8::Isolate* isolate = CcTest::isolate(); 23718 v8::Isolate* isolate = CcTest::isolate();
22108 v8::HandleScope handle_scope(isolate); 23719 v8::HandleScope handle_scope(isolate);
22109 v8::Handle<v8::ObjectTemplate> global_template = 23720 v8::Local<v8::ObjectTemplate> global_template =
22110 v8::ObjectTemplate::New(isolate); 23721 v8::ObjectTemplate::New(isolate);
22111 LocalContext env(NULL, global_template); 23722 LocalContext env(NULL, global_template);
22112 23723
22113 i::FLAG_abort_on_uncaught_exception = true; 23724 i::FLAG_abort_on_uncaught_exception = true;
22114 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException); 23725 isolate->SetAbortOnUncaughtExceptionCallback(NoAbortOnUncaughtException);
22115 23726
22116 CompileRun("function boom() { throw new Error(\"boom\") }"); 23727 CompileRun("function boom() { throw new Error(\"boom\") }");
22117 23728
22118 v8::Local<v8::Object> global_object = env->Global(); 23729 v8::Local<v8::Object> global_object = env->Global();
22119 v8::Local<v8::Function> foo = 23730 v8::Local<v8::Function> foo =
22120 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("boom"))); 23731 v8::Local<v8::Function>::Cast(global_object->Get(v8_str("boom")));
22121 23732
22122 foo->Call(global_object, 0, NULL); 23733 foo->Call(global_object, 0, NULL);
22123 23734
22124 CHECK_EQ(1, nb_uncaught_exception_callback_calls); 23735 CHECK_EQ(1, nb_uncaught_exception_callback_calls);
22125 } 23736 }
22126 23737
22127 23738
22128 TEST(AccessCheckedIsConcatSpreadable) { 23739 TEST(AccessCheckedIsConcatSpreadable) {
22129 i::FLAG_harmony_concat_spreadable = true; 23740 i::FLAG_harmony_concat_spreadable = true;
22130 v8::Isolate* isolate = CcTest::isolate(); 23741 v8::Isolate* isolate = CcTest::isolate();
22131 HandleScope scope(isolate); 23742 HandleScope scope(isolate);
22132 LocalContext env; 23743 LocalContext env;
22133 23744
22134 // Object with access check 23745 // Object with access check
22135 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate); 23746 Local<ObjectTemplate> spreadable_template = v8::ObjectTemplate::New(isolate);
22136 spreadable_template->SetAccessCheckCallback(AccessBlocker); 23747 spreadable_template->SetAccessCheckCallback(AccessBlocker);
22137 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate), 23748 spreadable_template->Set(v8::Symbol::GetIsConcatSpreadable(isolate),
22138 v8::Boolean::New(isolate, true)); 23749 v8::Boolean::New(isolate, true));
22139 Local<Object> object = spreadable_template->NewInstance(); 23750 Local<Object> object =
23751 spreadable_template->NewInstance(env.local()).ToLocalChecked();
22140 23752
22141 allowed_access = true; 23753 allowed_access = true;
22142 env->Global()->Set(v8_str("object"), object); 23754 CHECK(env->Global()->Set(env.local(), v8_str("object"), object).FromJust());
22143 object->Set(v8_str("length"), v8_num(2)); 23755 object->Set(v8_str("length"), v8_num(2));
22144 object->Set(0U, v8_str("a")); 23756 object->Set(0U, v8_str("a"));
22145 object->Set(1U, v8_str("b")); 23757 object->Set(1U, v8_str("b"));
22146 23758
22147 // Access check is allowed, and the object is spread 23759 // Access check is allowed, and the object is spread
22148 CompileRun("var result = [].concat(object)"); 23760 CompileRun("var result = [].concat(object)");
22149 ExpectTrue("Array.isArray(result)"); 23761 ExpectTrue("Array.isArray(result)");
22150 ExpectString("result[0]", "a"); 23762 ExpectString("result[0]", "a");
22151 ExpectString("result[1]", "b"); 23763 ExpectString("result[1]", "b");
22152 ExpectTrue("result.length === 2"); 23764 ExpectTrue("result.length === 2");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
22201 23813
22202 23814
22203 TEST(ObjectTemplateIntrinsics) { 23815 TEST(ObjectTemplateIntrinsics) {
22204 v8::Isolate* isolate = CcTest::isolate(); 23816 v8::Isolate* isolate = CcTest::isolate();
22205 v8::HandleScope scope(isolate); 23817 v8::HandleScope scope(isolate);
22206 LocalContext env; 23818 LocalContext env;
22207 23819
22208 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate); 23820 Local<ObjectTemplate> object_template = v8::ObjectTemplate::New(isolate);
22209 object_template->SetIntrinsicDataProperty(v8_str("values"), 23821 object_template->SetIntrinsicDataProperty(v8_str("values"),
22210 v8::kArrayProto_values); 23822 v8::kArrayProto_values);
22211 Local<Object> object = object_template->NewInstance(); 23823 Local<Object> object =
23824 object_template->NewInstance(env.local()).ToLocalChecked();
22212 23825
22213 env->Global()->Set(v8_str("obj1"), object); 23826 CHECK(env->Global()->Set(env.local(), v8_str("obj1"), object).FromJust());
22214 ExpectString("typeof obj1.values", "function"); 23827 ExpectString("typeof obj1.values", "function");
22215 23828
22216 auto values = Local<Function>::Cast(object->Get(v8_str("values"))); 23829 auto values = Local<Function>::Cast(object->Get(v8_str("values")));
22217 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values)); 23830 auto fn = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values));
22218 auto ctx = v8::Utils::OpenHandle(*env.local()); 23831 auto ctx = v8::Utils::OpenHandle(*env.local());
22219 CHECK_EQ(fn->GetCreationContext(), *ctx); 23832 CHECK_EQ(fn->GetCreationContext(), *ctx);
22220 23833
22221 { 23834 {
22222 LocalContext env2; 23835 LocalContext env2;
22223 Local<Object> object2 = object_template->NewInstance(); 23836 Local<Object> object2 =
22224 env2->Global()->Set(v8_str("obj2"), object2); 23837 object_template->NewInstance(env2.local()).ToLocalChecked();
23838 CHECK(
23839 env2->Global()->Set(env2.local(), v8_str("obj2"), object2).FromJust());
22225 ExpectString("typeof obj2.values", "function"); 23840 ExpectString("typeof obj2.values", "function");
22226 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 23841 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
22227 23842
22228 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 23843 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
22229 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 23844 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
22230 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 23845 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
22231 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 23846 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
22232 } 23847 }
22233 } 23848 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698