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

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

Issue 108063003: Removed internal uses of (almost) deprecated FunctionTemplate::New version. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-ia32.cc » ('j') | 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
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 CHECK_EQ(10, signature_callback_count); 245 CHECK_EQ(10, signature_callback_count);
246 } else { 246 } else {
247 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 247 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
248 try_catch.Exception()->ToString()); 248 try_catch.Exception()->ToString());
249 } 249 }
250 } 250 }
251 251
252 252
253 THREADED_TEST(ReceiverSignature) { 253 THREADED_TEST(ReceiverSignature) {
254 LocalContext env; 254 LocalContext env;
255 v8::HandleScope scope(env->GetIsolate()); 255 v8::Isolate* isolate = env->GetIsolate();
256 v8::HandleScope scope(isolate);
256 // Setup templates. 257 // Setup templates.
257 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 258 v8::Handle<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
258 v8::Handle<v8::Signature> sig = v8::Signature::New(env->GetIsolate(), fun); 259 v8::Handle<v8::Signature> sig = v8::Signature::New(isolate, fun);
259 v8::Handle<v8::FunctionTemplate> callback_sig = 260 v8::Handle<v8::FunctionTemplate> callback_sig =
260 v8::FunctionTemplate::New( 261 v8::FunctionTemplate::New(
261 IncrementingSignatureCallback, Local<Value>(), sig); 262 isolate, IncrementingSignatureCallback, Local<Value>(), sig);
262 v8::Handle<v8::FunctionTemplate> callback = 263 v8::Handle<v8::FunctionTemplate> callback =
263 v8::FunctionTemplate::New(IncrementingSignatureCallback); 264 v8::FunctionTemplate::New(isolate, IncrementingSignatureCallback);
264 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(); 265 v8::Handle<v8::FunctionTemplate> sub_fun = v8::FunctionTemplate::New(isolate);
265 sub_fun->Inherit(fun); 266 sub_fun->Inherit(fun);
266 v8::Handle<v8::FunctionTemplate> unrel_fun = v8::FunctionTemplate::New(); 267 v8::Handle<v8::FunctionTemplate> unrel_fun =
268 v8::FunctionTemplate::New(isolate);
267 // Install properties. 269 // Install properties.
268 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate(); 270 v8::Handle<v8::ObjectTemplate> fun_proto = fun->PrototypeTemplate();
269 fun_proto->Set(v8_str("prop_sig"), callback_sig); 271 fun_proto->Set(v8_str("prop_sig"), callback_sig);
270 fun_proto->Set(v8_str("prop"), callback); 272 fun_proto->Set(v8_str("prop"), callback);
271 fun_proto->SetAccessorProperty( 273 fun_proto->SetAccessorProperty(
272 v8_str("accessor_sig"), callback_sig, callback_sig); 274 v8_str("accessor_sig"), callback_sig, callback_sig);
273 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback); 275 fun_proto->SetAccessorProperty(v8_str("accessor"), callback, callback);
274 // Instantiate templates. 276 // Instantiate templates.
275 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance(); 277 Local<Value> fun_instance = fun->InstanceTemplate()->NewInstance();
276 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance(); 278 Local<Value> sub_fun_instance = sub_fun->InstanceTemplate()->NewInstance();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 TestSignature("test_object.accessor_sig;", test_object); 320 TestSignature("test_object.accessor_sig;", test_object);
319 TestSignature("test_object[accessor_sig_key];", test_object); 321 TestSignature("test_object[accessor_sig_key];", test_object);
320 TestSignature("test_object.accessor_sig = 1;", test_object); 322 TestSignature("test_object.accessor_sig = 1;", test_object);
321 TestSignature("test_object[accessor_sig_key] = 1;", test_object); 323 TestSignature("test_object[accessor_sig_key] = 1;", test_object);
322 } 324 }
323 } 325 }
324 326
325 327
326 THREADED_TEST(ArgumentSignature) { 328 THREADED_TEST(ArgumentSignature) {
327 LocalContext env; 329 LocalContext env;
328 v8::HandleScope scope(env->GetIsolate()); 330 v8::Isolate* isolate = env->GetIsolate();
329 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(); 331 v8::HandleScope scope(isolate);
332 v8::Handle<v8::FunctionTemplate> cons = v8::FunctionTemplate::New(isolate);
330 cons->SetClassName(v8_str("Cons")); 333 cons->SetClassName(v8_str("Cons"));
331 v8::Handle<v8::Signature> sig = v8::Signature::New( 334 v8::Handle<v8::Signature> sig = v8::Signature::New(
332 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 1, &cons); 335 isolate, v8::Handle<v8::FunctionTemplate>(), 1, &cons);
333 v8::Handle<v8::FunctionTemplate> fun = 336 v8::Handle<v8::FunctionTemplate> fun =
334 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), sig); 337 v8::FunctionTemplate::New(isolate,
338 SignatureCallback,
339 v8::Handle<Value>(),
340 sig);
335 env->Global()->Set(v8_str("Cons"), cons->GetFunction()); 341 env->Global()->Set(v8_str("Cons"), cons->GetFunction());
336 env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); 342 env->Global()->Set(v8_str("Fun1"), fun->GetFunction());
337 343
338 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';"); 344 v8::Handle<Value> value1 = CompileRun("Fun1(4) == '';");
339 CHECK(value1->IsTrue()); 345 CHECK(value1->IsTrue());
340 346
341 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';"); 347 v8::Handle<Value> value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';");
342 CHECK(value2->IsTrue()); 348 CHECK(value2->IsTrue());
343 349
344 v8::Handle<Value> value3 = CompileRun("Fun1() == '';"); 350 v8::Handle<Value> value3 = CompileRun("Fun1() == '';");
345 CHECK(value3->IsTrue()); 351 CHECK(value3->IsTrue());
346 352
347 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New(); 353 v8::Handle<v8::FunctionTemplate> cons1 = v8::FunctionTemplate::New(isolate);
348 cons1->SetClassName(v8_str("Cons1")); 354 cons1->SetClassName(v8_str("Cons1"));
349 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New(); 355 v8::Handle<v8::FunctionTemplate> cons2 = v8::FunctionTemplate::New(isolate);
350 cons2->SetClassName(v8_str("Cons2")); 356 cons2->SetClassName(v8_str("Cons2"));
351 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New(); 357 v8::Handle<v8::FunctionTemplate> cons3 = v8::FunctionTemplate::New(isolate);
352 cons3->SetClassName(v8_str("Cons3")); 358 cons3->SetClassName(v8_str("Cons3"));
353 359
354 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 }; 360 v8::Handle<v8::FunctionTemplate> args[3] = { cons1, cons2, cons3 };
355 v8::Handle<v8::Signature> wsig = v8::Signature::New( 361 v8::Handle<v8::Signature> wsig = v8::Signature::New(
356 env->GetIsolate(), v8::Handle<v8::FunctionTemplate>(), 3, args); 362 isolate, v8::Handle<v8::FunctionTemplate>(), 3, args);
357 v8::Handle<v8::FunctionTemplate> fun2 = 363 v8::Handle<v8::FunctionTemplate> fun2 =
358 v8::FunctionTemplate::New(SignatureCallback, v8::Handle<Value>(), wsig); 364 v8::FunctionTemplate::New(isolate,
365 SignatureCallback,
366 v8::Handle<Value>(),
367 wsig);
359 368
360 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction()); 369 env->Global()->Set(v8_str("Cons1"), cons1->GetFunction());
361 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction()); 370 env->Global()->Set(v8_str("Cons2"), cons2->GetFunction());
362 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction()); 371 env->Global()->Set(v8_str("Cons3"), cons3->GetFunction());
363 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction()); 372 env->Global()->Set(v8_str("Fun2"), fun2->GetFunction());
364 v8::Handle<Value> value4 = CompileRun( 373 v8::Handle<Value> value4 = CompileRun(
365 "Fun2(new Cons1(), new Cons2(), new Cons3()) ==" 374 "Fun2(new Cons1(), new Cons2(), new Cons3()) =="
366 "'[object Cons1],[object Cons2],[object Cons3]'"); 375 "'[object Cons1],[object Cons2],[object Cons3]'");
367 CHECK(value4->IsTrue()); 376 CHECK(value4->IsTrue());
368 377
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 info.GetReturnValue().Set(v8_num(239)); 1022 info.GetReturnValue().Set(v8_num(239));
1014 } 1023 }
1015 1024
1016 1025
1017 template<typename Handler> 1026 template<typename Handler>
1018 static void TestFunctionTemplateInitializer(Handler handler, 1027 static void TestFunctionTemplateInitializer(Handler handler,
1019 Handler handler_2) { 1028 Handler handler_2) {
1020 // Test constructor calls. 1029 // Test constructor calls.
1021 { 1030 {
1022 LocalContext env; 1031 LocalContext env;
1023 v8::HandleScope scope(env->GetIsolate()); 1032 v8::Isolate* isolate = env->GetIsolate();
1033 v8::HandleScope scope(isolate);
1024 1034
1025 Local<v8::FunctionTemplate> fun_templ = 1035 Local<v8::FunctionTemplate> fun_templ =
1026 v8::FunctionTemplate::New(handler); 1036 v8::FunctionTemplate::New(isolate, handler);
1027 Local<Function> fun = fun_templ->GetFunction(); 1037 Local<Function> fun = fun_templ->GetFunction();
1028 env->Global()->Set(v8_str("obj"), fun); 1038 env->Global()->Set(v8_str("obj"), fun);
1029 Local<Script> script = v8_compile("obj()"); 1039 Local<Script> script = v8_compile("obj()");
1030 for (int i = 0; i < 30; i++) { 1040 for (int i = 0; i < 30; i++) {
1031 CHECK_EQ(102, script->Run()->Int32Value()); 1041 CHECK_EQ(102, script->Run()->Int32Value());
1032 } 1042 }
1033 } 1043 }
1034 // Use SetCallHandler to initialize a function template, should work like 1044 // Use SetCallHandler to initialize a function template, should work like
1035 // the previous one. 1045 // the previous one.
1036 { 1046 {
1037 LocalContext env; 1047 LocalContext env;
1038 v8::HandleScope scope(env->GetIsolate()); 1048 v8::Isolate* isolate = env->GetIsolate();
1049 v8::HandleScope scope(isolate);
1039 1050
1040 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 1051 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
1041 fun_templ->SetCallHandler(handler_2); 1052 fun_templ->SetCallHandler(handler_2);
1042 Local<Function> fun = fun_templ->GetFunction(); 1053 Local<Function> fun = fun_templ->GetFunction();
1043 env->Global()->Set(v8_str("obj"), fun); 1054 env->Global()->Set(v8_str("obj"), fun);
1044 Local<Script> script = v8_compile("obj()"); 1055 Local<Script> script = v8_compile("obj()");
1045 for (int i = 0; i < 30; i++) { 1056 for (int i = 0; i < 30; i++) {
1046 CHECK_EQ(102, script->Run()->Int32Value()); 1057 CHECK_EQ(102, script->Run()->Int32Value());
1047 } 1058 }
1048 } 1059 }
1049 } 1060 }
1050 1061
1051 1062
1052 template<typename Constructor, typename Accessor> 1063 template<typename Constructor, typename Accessor>
1053 static void TestFunctionTemplateAccessor(Constructor constructor, 1064 static void TestFunctionTemplateAccessor(Constructor constructor,
1054 Accessor accessor) { 1065 Accessor accessor) {
1055 LocalContext env; 1066 LocalContext env;
1056 v8::HandleScope scope(env->GetIsolate()); 1067 v8::HandleScope scope(env->GetIsolate());
1057 1068
1058 Local<v8::FunctionTemplate> fun_templ = 1069 Local<v8::FunctionTemplate> fun_templ =
1059 v8::FunctionTemplate::New(constructor); 1070 v8::FunctionTemplate::New(env->GetIsolate(), constructor);
1060 fun_templ->SetClassName(v8_str("funky")); 1071 fun_templ->SetClassName(v8_str("funky"));
1061 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor); 1072 fun_templ->InstanceTemplate()->SetAccessor(v8_str("m"), accessor);
1062 Local<Function> fun = fun_templ->GetFunction(); 1073 Local<Function> fun = fun_templ->GetFunction();
1063 env->Global()->Set(v8_str("obj"), fun); 1074 env->Global()->Set(v8_str("obj"), fun);
1064 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); 1075 Local<Value> result = v8_compile("(new obj()).toString()")->Run();
1065 CHECK_EQ(v8_str("[object funky]"), result); 1076 CHECK_EQ(v8_str("[object funky]"), result);
1066 CompileRun("var obj_instance = new obj();"); 1077 CompileRun("var obj_instance = new obj();");
1067 Local<Script> script; 1078 Local<Script> script;
1068 script = v8_compile("obj_instance.x"); 1079 script = v8_compile("obj_instance.x");
1069 for (int i = 0; i < 30; i++) { 1080 for (int i = 0; i < 30; i++) {
(...skipping 19 matching lines...) Expand all
1089 } 1100 }
1090 1101
1091 1102
1092 template<typename Callback> 1103 template<typename Callback>
1093 static void TestSimpleCallback(Callback callback) { 1104 static void TestSimpleCallback(Callback callback) {
1094 LocalContext env; 1105 LocalContext env;
1095 v8::HandleScope scope(env->GetIsolate()); 1106 v8::HandleScope scope(env->GetIsolate());
1096 1107
1097 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1108 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1098 object_template->Set(env->GetIsolate(), "callback", 1109 object_template->Set(env->GetIsolate(), "callback",
1099 v8::FunctionTemplate::New(callback)); 1110 v8::FunctionTemplate::New(env->GetIsolate(), callback));
1100 v8::Local<v8::Object> object = object_template->NewInstance(); 1111 v8::Local<v8::Object> object = object_template->NewInstance();
1101 (*env)->Global()->Set(v8_str("callback_object"), object); 1112 (*env)->Global()->Set(v8_str("callback_object"), object);
1102 v8::Handle<v8::Script> script; 1113 v8::Handle<v8::Script> script;
1103 script = v8_compile("callback_object.callback(17)"); 1114 script = v8_compile("callback_object.callback(17)");
1104 for (int i = 0; i < 30; i++) { 1115 for (int i = 0; i < 30; i++) {
1105 CHECK_EQ(51424, script->Run()->Int32Value()); 1116 CHECK_EQ(51424, script->Run()->Int32Value());
1106 } 1117 }
1107 script = v8_compile("callback_object.callback(17, 24)"); 1118 script = v8_compile("callback_object.callback(17, 24)");
1108 for (int i = 0; i < 30; i++) { 1119 for (int i = 0; i < 30; i++) {
1109 CHECK_EQ(51425, script->Run()->Int32Value()); 1120 CHECK_EQ(51425, script->Run()->Int32Value());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 info.GetReturnValue().Set(object); 1203 info.GetReturnValue().Set(object);
1193 } 1204 }
1194 1205
1195 template<typename T> 1206 template<typename T>
1196 Handle<Value> TestFastReturnValues() { 1207 Handle<Value> TestFastReturnValues() {
1197 LocalContext env; 1208 LocalContext env;
1198 v8::EscapableHandleScope scope(env->GetIsolate()); 1209 v8::EscapableHandleScope scope(env->GetIsolate());
1199 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New(); 1210 v8::Handle<v8::ObjectTemplate> object_template = v8::ObjectTemplate::New();
1200 v8::FunctionCallback callback = &FastReturnValueCallback<T>; 1211 v8::FunctionCallback callback = &FastReturnValueCallback<T>;
1201 object_template->Set(env->GetIsolate(), "callback", 1212 object_template->Set(env->GetIsolate(), "callback",
1202 v8::FunctionTemplate::New(callback)); 1213 v8::FunctionTemplate::New(env->GetIsolate(), callback));
1203 v8::Local<v8::Object> object = object_template->NewInstance(); 1214 v8::Local<v8::Object> object = object_template->NewInstance();
1204 (*env)->Global()->Set(v8_str("callback_object"), object); 1215 (*env)->Global()->Set(v8_str("callback_object"), object);
1205 return scope.Escape(CompileRun("callback_object.callback()")); 1216 return scope.Escape(CompileRun("callback_object.callback()"));
1206 } 1217 }
1207 1218
1208 1219
1209 THREADED_PROFILED_TEST(FastReturnValues) { 1220 THREADED_PROFILED_TEST(FastReturnValues) {
1210 LocalContext env; 1221 LocalContext env;
1211 v8::HandleScope scope(CcTest::isolate()); 1222 v8::HandleScope scope(CcTest::isolate());
1212 v8::Handle<v8::Value> value; 1223 v8::Handle<v8::Value> value;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 value = TestFastReturnValues<Object>(); 1279 value = TestFastReturnValues<Object>();
1269 CHECK(value->IsObject()); 1280 CHECK(value->IsObject());
1270 fast_return_value_object_is_empty = true; 1281 fast_return_value_object_is_empty = true;
1271 value = TestFastReturnValues<Object>(); 1282 value = TestFastReturnValues<Object>();
1272 CHECK(value->IsUndefined()); 1283 CHECK(value->IsUndefined());
1273 } 1284 }
1274 1285
1275 1286
1276 THREADED_TEST(FunctionTemplateSetLength) { 1287 THREADED_TEST(FunctionTemplateSetLength) {
1277 LocalContext env; 1288 LocalContext env;
1278 v8::HandleScope scope(env->GetIsolate()); 1289 v8::Isolate* isolate = env->GetIsolate();
1290 v8::HandleScope scope(isolate);
1279 { 1291 {
1280 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New( 1292 Local<v8::FunctionTemplate> fun_templ =
1281 handle_callback, Handle<v8::Value>(), Handle<v8::Signature>(), 23); 1293 v8::FunctionTemplate::New(isolate,
1294 handle_callback,
1295 Handle<v8::Value>(),
1296 Handle<v8::Signature>(),
1297 23);
1282 Local<Function> fun = fun_templ->GetFunction(); 1298 Local<Function> fun = fun_templ->GetFunction();
1283 env->Global()->Set(v8_str("obj"), fun); 1299 env->Global()->Set(v8_str("obj"), fun);
1284 Local<Script> script = v8_compile("obj.length"); 1300 Local<Script> script = v8_compile("obj.length");
1285 CHECK_EQ(23, script->Run()->Int32Value()); 1301 CHECK_EQ(23, script->Run()->Int32Value());
1286 } 1302 }
1287 { 1303 {
1288 Local<v8::FunctionTemplate> fun_templ = 1304 Local<v8::FunctionTemplate> fun_templ =
1289 v8::FunctionTemplate::New(handle_callback); 1305 v8::FunctionTemplate::New(isolate, handle_callback);
1290 fun_templ->SetLength(22); 1306 fun_templ->SetLength(22);
1291 Local<Function> fun = fun_templ->GetFunction(); 1307 Local<Function> fun = fun_templ->GetFunction();
1292 env->Global()->Set(v8_str("obj"), fun); 1308 env->Global()->Set(v8_str("obj"), fun);
1293 Local<Script> script = v8_compile("obj.length"); 1309 Local<Script> script = v8_compile("obj.length");
1294 CHECK_EQ(22, script->Run()->Int32Value()); 1310 CHECK_EQ(22, script->Run()->Int32Value());
1295 } 1311 }
1296 { 1312 {
1297 // Without setting length it defaults to 0. 1313 // Without setting length it defaults to 0.
1298 Local<v8::FunctionTemplate> fun_templ = 1314 Local<v8::FunctionTemplate> fun_templ =
1299 v8::FunctionTemplate::New(handle_callback); 1315 v8::FunctionTemplate::New(isolate, handle_callback);
1300 Local<Function> fun = fun_templ->GetFunction(); 1316 Local<Function> fun = fun_templ->GetFunction();
1301 env->Global()->Set(v8_str("obj"), fun); 1317 env->Global()->Set(v8_str("obj"), fun);
1302 Local<Script> script = v8_compile("obj.length"); 1318 Local<Script> script = v8_compile("obj.length");
1303 CHECK_EQ(0, script->Run()->Int32Value()); 1319 CHECK_EQ(0, script->Run()->Int32Value());
1304 } 1320 }
1305 } 1321 }
1306 1322
1307 1323
1308 static void* expected_ptr; 1324 static void* expected_ptr;
1309 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) { 1325 static void callback(const v8::FunctionCallbackInfo<v8::Value>& args) {
1310 void* ptr = v8::External::Cast(*args.Data())->Value(); 1326 void* ptr = v8::External::Cast(*args.Data())->Value();
1311 CHECK_EQ(expected_ptr, ptr); 1327 CHECK_EQ(expected_ptr, ptr);
1312 args.GetReturnValue().Set(true); 1328 args.GetReturnValue().Set(true);
1313 } 1329 }
1314 1330
1315 1331
1316 static void TestExternalPointerWrapping() { 1332 static void TestExternalPointerWrapping() {
1317 LocalContext env; 1333 LocalContext env;
1318 v8::HandleScope scope(env->GetIsolate()); 1334 v8::Isolate* isolate = env->GetIsolate();
1335 v8::HandleScope scope(isolate);
1319 1336
1320 v8::Handle<v8::Value> data = 1337 v8::Handle<v8::Value> data =
1321 v8::External::New(env->GetIsolate(), expected_ptr); 1338 v8::External::New(isolate, expected_ptr);
1322 1339
1323 v8::Handle<v8::Object> obj = v8::Object::New(); 1340 v8::Handle<v8::Object> obj = v8::Object::New();
1324 obj->Set(v8_str("func"), 1341 obj->Set(v8_str("func"),
1325 v8::FunctionTemplate::New(callback, data)->GetFunction()); 1342 v8::FunctionTemplate::New(isolate, callback, data)->GetFunction());
1326 env->Global()->Set(v8_str("obj"), obj); 1343 env->Global()->Set(v8_str("obj"), obj);
1327 1344
1328 CHECK(CompileRun( 1345 CHECK(CompileRun(
1329 "function foo() {\n" 1346 "function foo() {\n"
1330 " for (var i = 0; i < 13; i++) obj.func();\n" 1347 " for (var i = 0; i < 13; i++) obj.func();\n"
1331 "}\n" 1348 "}\n"
1332 "foo(), true")->BooleanValue()); 1349 "foo(), true")->BooleanValue());
1333 } 1350 }
1334 1351
1335 1352
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 TestExternalPointerWrapping(); 1391 TestExternalPointerWrapping();
1375 1392
1376 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1); 1393 expected_ptr = reinterpret_cast<void*>(0xdeadbeefdeadbeef + 1);
1377 TestExternalPointerWrapping(); 1394 TestExternalPointerWrapping();
1378 #endif 1395 #endif
1379 } 1396 }
1380 1397
1381 1398
1382 THREADED_TEST(FindInstanceInPrototypeChain) { 1399 THREADED_TEST(FindInstanceInPrototypeChain) {
1383 LocalContext env; 1400 LocalContext env;
1384 v8::HandleScope scope(env->GetIsolate()); 1401 v8::Isolate* isolate = env->GetIsolate();
1402 v8::HandleScope scope(isolate);
1385 1403
1386 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); 1404 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(isolate);
1387 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); 1405 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(isolate);
1388 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); 1406 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(isolate);
1389 derived->Inherit(base); 1407 derived->Inherit(base);
1390 1408
1391 Local<v8::Function> base_function = base->GetFunction(); 1409 Local<v8::Function> base_function = base->GetFunction();
1392 Local<v8::Function> derived_function = derived->GetFunction(); 1410 Local<v8::Function> derived_function = derived->GetFunction();
1393 Local<v8::Function> other_function = other->GetFunction(); 1411 Local<v8::Function> other_function = other->GetFunction();
1394 1412
1395 Local<v8::Object> base_instance = base_function->NewInstance(); 1413 Local<v8::Object> base_instance = base_function->NewInstance();
1396 Local<v8::Object> derived_instance = derived_function->NewInstance(); 1414 Local<v8::Object> derived_instance = derived_function->NewInstance();
1397 Local<v8::Object> derived_instance2 = derived_function->NewInstance(); 1415 Local<v8::Object> derived_instance2 = derived_function->NewInstance();
1398 Local<v8::Object> other_instance = other_function->NewInstance(); 1416 Local<v8::Object> other_instance = other_function->NewInstance();
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1767
1750 1768
1751 static void GetM(Local<String> name, 1769 static void GetM(Local<String> name,
1752 const v8::PropertyCallbackInfo<v8::Value>& info) { 1770 const v8::PropertyCallbackInfo<v8::Value>& info) {
1753 ApiTestFuzzer::Fuzz(); 1771 ApiTestFuzzer::Fuzz();
1754 info.GetReturnValue().Set(v8_num(876)); 1772 info.GetReturnValue().Set(v8_num(876));
1755 } 1773 }
1756 1774
1757 1775
1758 THREADED_TEST(GlobalPrototype) { 1776 THREADED_TEST(GlobalPrototype) {
1759 v8::HandleScope scope(CcTest::isolate()); 1777 v8::Isolate* isolate = CcTest::isolate();
1760 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 1778 v8::HandleScope scope(isolate);
1779 v8::Handle<v8::FunctionTemplate> func_templ =
1780 v8::FunctionTemplate::New(isolate);
1761 func_templ->PrototypeTemplate()->Set( 1781 func_templ->PrototypeTemplate()->Set(
1762 CcTest::isolate(), "dummy", v8::FunctionTemplate::New(DummyCallHandler)); 1782 isolate, "dummy", v8::FunctionTemplate::New(isolate, DummyCallHandler));
1763 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate(); 1783 v8::Handle<ObjectTemplate> templ = func_templ->InstanceTemplate();
1764 templ->Set(CcTest::isolate(), "x", v8_num(200)); 1784 templ->Set(isolate, "x", v8_num(200));
1765 templ->SetAccessor(v8_str("m"), GetM); 1785 templ->SetAccessor(v8_str("m"), GetM);
1766 LocalContext env(0, templ); 1786 LocalContext env(0, templ);
1767 v8::Handle<Script> script(v8_compile("dummy()")); 1787 v8::Handle<Script> script(v8_compile("dummy()"));
1768 v8::Handle<Value> result(script->Run()); 1788 v8::Handle<Value> result(script->Run());
1769 CHECK_EQ(13.4, result->NumberValue()); 1789 CHECK_EQ(13.4, result->NumberValue());
1770 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value()); 1790 CHECK_EQ(200, v8_compile("x")->Run()->Int32Value());
1771 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value()); 1791 CHECK_EQ(876, v8_compile("m")->Run()->Int32Value());
1772 } 1792 }
1773 1793
1774 1794
1775 THREADED_TEST(ObjectTemplate) { 1795 THREADED_TEST(ObjectTemplate) {
1776 v8::HandleScope scope(CcTest::isolate()); 1796 v8::Isolate* isolate = CcTest::isolate();
1797 v8::HandleScope scope(isolate);
1777 Local<ObjectTemplate> templ1 = ObjectTemplate::New(); 1798 Local<ObjectTemplate> templ1 = ObjectTemplate::New();
1778 templ1->Set(CcTest::isolate(), "x", v8_num(10)); 1799 templ1->Set(isolate, "x", v8_num(10));
1779 templ1->Set(CcTest::isolate(), "y", v8_num(13)); 1800 templ1->Set(isolate, "y", v8_num(13));
1780 LocalContext env; 1801 LocalContext env;
1781 Local<v8::Object> instance1 = templ1->NewInstance(); 1802 Local<v8::Object> instance1 = templ1->NewInstance();
1782 env->Global()->Set(v8_str("p"), instance1); 1803 env->Global()->Set(v8_str("p"), instance1);
1783 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue()); 1804 CHECK(v8_compile("(p.x == 10)")->Run()->BooleanValue());
1784 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue()); 1805 CHECK(v8_compile("(p.y == 13)")->Run()->BooleanValue());
1785 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(); 1806 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(isolate);
1786 fun->PrototypeTemplate()->Set(CcTest::isolate(), "nirk", v8_num(123)); 1807 fun->PrototypeTemplate()->Set(isolate, "nirk", v8_num(123));
1787 Local<ObjectTemplate> templ2 = fun->InstanceTemplate(); 1808 Local<ObjectTemplate> templ2 = fun->InstanceTemplate();
1788 templ2->Set(CcTest::isolate(), "a", v8_num(12)); 1809 templ2->Set(isolate, "a", v8_num(12));
1789 templ2->Set(CcTest::isolate(), "b", templ1); 1810 templ2->Set(isolate, "b", templ1);
1790 Local<v8::Object> instance2 = templ2->NewInstance(); 1811 Local<v8::Object> instance2 = templ2->NewInstance();
1791 env->Global()->Set(v8_str("q"), instance2); 1812 env->Global()->Set(v8_str("q"), instance2);
1792 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue()); 1813 CHECK(v8_compile("(q.nirk == 123)")->Run()->BooleanValue());
1793 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue()); 1814 CHECK(v8_compile("(q.a == 12)")->Run()->BooleanValue());
1794 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue()); 1815 CHECK(v8_compile("(q.b.x == 10)")->Run()->BooleanValue());
1795 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue()); 1816 CHECK(v8_compile("(q.b.y == 13)")->Run()->BooleanValue());
1796 } 1817 }
1797 1818
1798 1819
1799 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) { 1820 static void GetFlabby(const v8::FunctionCallbackInfo<v8::Value>& args) {
1800 ApiTestFuzzer::Fuzz(); 1821 ApiTestFuzzer::Fuzz();
1801 args.GetReturnValue().Set(v8_num(17.2)); 1822 args.GetReturnValue().Set(v8_num(17.2));
1802 } 1823 }
1803 1824
1804 1825
1805 static void GetKnurd(Local<String> property, 1826 static void GetKnurd(Local<String> property,
1806 const v8::PropertyCallbackInfo<v8::Value>& info) { 1827 const v8::PropertyCallbackInfo<v8::Value>& info) {
1807 ApiTestFuzzer::Fuzz(); 1828 ApiTestFuzzer::Fuzz();
1808 info.GetReturnValue().Set(v8_num(15.2)); 1829 info.GetReturnValue().Set(v8_num(15.2));
1809 } 1830 }
1810 1831
1811 1832
1812 THREADED_TEST(DescriptorInheritance) { 1833 THREADED_TEST(DescriptorInheritance) {
1813 v8::HandleScope scope(CcTest::isolate()); 1834 v8::Isolate* isolate = CcTest::isolate();
1814 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(); 1835 v8::HandleScope scope(isolate);
1815 super->PrototypeTemplate()->Set(CcTest::isolate(), "flabby", 1836 v8::Handle<v8::FunctionTemplate> super = v8::FunctionTemplate::New(isolate);
1816 v8::FunctionTemplate::New(GetFlabby)); 1837 super->PrototypeTemplate()->Set(isolate, "flabby",
1817 super->PrototypeTemplate()->Set(CcTest::isolate(), "PI", v8_num(3.14)); 1838 v8::FunctionTemplate::New(isolate,
1839 GetFlabby));
1840 super->PrototypeTemplate()->Set(isolate, "PI", v8_num(3.14));
1818 1841
1819 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd); 1842 super->InstanceTemplate()->SetAccessor(v8_str("knurd"), GetKnurd);
1820 1843
1821 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(); 1844 v8::Handle<v8::FunctionTemplate> base1 = v8::FunctionTemplate::New(isolate);
1822 base1->Inherit(super); 1845 base1->Inherit(super);
1823 base1->PrototypeTemplate()->Set(CcTest::isolate(), "v1", v8_num(20.1)); 1846 base1->PrototypeTemplate()->Set(isolate, "v1", v8_num(20.1));
1824 1847
1825 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(); 1848 v8::Handle<v8::FunctionTemplate> base2 = v8::FunctionTemplate::New(isolate);
1826 base2->Inherit(super); 1849 base2->Inherit(super);
1827 base2->PrototypeTemplate()->Set(CcTest::isolate(), "v2", v8_num(10.1)); 1850 base2->PrototypeTemplate()->Set(isolate, "v2", v8_num(10.1));
1828 1851
1829 LocalContext env; 1852 LocalContext env;
1830 1853
1831 env->Global()->Set(v8_str("s"), super->GetFunction()); 1854 env->Global()->Set(v8_str("s"), super->GetFunction());
1832 env->Global()->Set(v8_str("base1"), base1->GetFunction()); 1855 env->Global()->Set(v8_str("base1"), base1->GetFunction());
1833 env->Global()->Set(v8_str("base2"), base2->GetFunction()); 1856 env->Global()->Set(v8_str("base2"), base2->GetFunction());
1834 1857
1835 // Checks right __proto__ chain. 1858 // Checks right __proto__ chain.
1836 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue()); 1859 CHECK(CompileRun("base1.prototype.__proto__ == s.prototype")->BooleanValue());
1837 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue()); 1860 CHECK(CompileRun("base2.prototype.__proto__ == s.prototype")->BooleanValue());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 1968
1946 void AddInterceptor(Handle<FunctionTemplate> templ, 1969 void AddInterceptor(Handle<FunctionTemplate> templ,
1947 v8::NamedPropertyGetterCallback getter, 1970 v8::NamedPropertyGetterCallback getter,
1948 v8::NamedPropertySetterCallback setter) { 1971 v8::NamedPropertySetterCallback setter) {
1949 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter); 1972 templ->InstanceTemplate()->SetNamedPropertyHandler(getter, setter);
1950 } 1973 }
1951 1974
1952 1975
1953 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) { 1976 THREADED_TEST(EmptyInterceptorDoesNotShadowAccessors) {
1954 v8::HandleScope scope(CcTest::isolate()); 1977 v8::HandleScope scope(CcTest::isolate());
1955 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1978 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
1956 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1979 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
1957 child->Inherit(parent); 1980 child->Inherit(parent);
1958 AddAccessor(parent, v8_str("age"), 1981 AddAccessor(parent, v8_str("age"),
1959 SimpleAccessorGetter, SimpleAccessorSetter); 1982 SimpleAccessorGetter, SimpleAccessorSetter);
1960 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 1983 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1961 LocalContext env; 1984 LocalContext env;
1962 env->Global()->Set(v8_str("Child"), child->GetFunction()); 1985 env->Global()->Set(v8_str("Child"), child->GetFunction());
1963 CompileRun("var child = new Child;" 1986 CompileRun("var child = new Child;"
1964 "child.age = 10;"); 1987 "child.age = 10;");
1965 ExpectBoolean("child.hasOwnProperty('age')", false); 1988 ExpectBoolean("child.hasOwnProperty('age')", false);
1966 ExpectInt32("child.age", 10); 1989 ExpectInt32("child.age", 10);
1967 ExpectInt32("child.accessor_age", 10); 1990 ExpectInt32("child.accessor_age", 10);
1968 } 1991 }
1969 1992
1970 1993
1971 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) { 1994 THREADED_TEST(EmptyInterceptorDoesNotShadowJSAccessors) {
1972 v8::HandleScope scope(CcTest::isolate()); 1995 v8::Isolate* isolate = CcTest::isolate();
1973 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 1996 v8::HandleScope scope(isolate);
1974 Handle<FunctionTemplate> child = FunctionTemplate::New(); 1997 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate);
1998 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate);
1975 child->Inherit(parent); 1999 child->Inherit(parent);
1976 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 2000 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1977 LocalContext env; 2001 LocalContext env;
1978 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2002 env->Global()->Set(v8_str("Child"), child->GetFunction());
1979 CompileRun("var child = new Child;" 2003 CompileRun("var child = new Child;"
1980 "var parent = child.__proto__;" 2004 "var parent = child.__proto__;"
1981 "Object.defineProperty(parent, 'age', " 2005 "Object.defineProperty(parent, 'age', "
1982 " {get: function(){ return this.accessor_age; }, " 2006 " {get: function(){ return this.accessor_age; }, "
1983 " set: function(v){ this.accessor_age = v; }, " 2007 " set: function(v){ this.accessor_age = v; }, "
1984 " enumerable: true, configurable: true});" 2008 " enumerable: true, configurable: true});"
1985 "child.age = 10;"); 2009 "child.age = 10;");
1986 ExpectBoolean("child.hasOwnProperty('age')", false); 2010 ExpectBoolean("child.hasOwnProperty('age')", false);
1987 ExpectInt32("child.age", 10); 2011 ExpectInt32("child.age", 10);
1988 ExpectInt32("child.accessor_age", 10); 2012 ExpectInt32("child.accessor_age", 10);
1989 } 2013 }
1990 2014
1991 2015
1992 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) { 2016 THREADED_TEST(EmptyInterceptorDoesNotAffectJSProperties) {
1993 v8::HandleScope scope(CcTest::isolate()); 2017 v8::Isolate* isolate = CcTest::isolate();
1994 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2018 v8::HandleScope scope(isolate);
1995 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2019 Handle<FunctionTemplate> parent = FunctionTemplate::New(isolate);
2020 Handle<FunctionTemplate> child = FunctionTemplate::New(isolate);
1996 child->Inherit(parent); 2021 child->Inherit(parent);
1997 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter); 2022 AddInterceptor(child, EmptyInterceptorGetter, EmptyInterceptorSetter);
1998 LocalContext env; 2023 LocalContext env;
1999 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2024 env->Global()->Set(v8_str("Child"), child->GetFunction());
2000 CompileRun("var child = new Child;" 2025 CompileRun("var child = new Child;"
2001 "var parent = child.__proto__;" 2026 "var parent = child.__proto__;"
2002 "parent.name = 'Alice';"); 2027 "parent.name = 'Alice';");
2003 ExpectBoolean("child.hasOwnProperty('name')", false); 2028 ExpectBoolean("child.hasOwnProperty('name')", false);
2004 ExpectString("child.name", "Alice"); 2029 ExpectString("child.name", "Alice");
2005 CompileRun("child.name = 'Bob';"); 2030 CompileRun("child.name = 'Bob';");
2006 ExpectString("child.name", "Bob"); 2031 ExpectString("child.name", "Bob");
2007 ExpectBoolean("child.hasOwnProperty('name')", true); 2032 ExpectBoolean("child.hasOwnProperty('name')", true);
2008 ExpectString("parent.name", "Alice"); 2033 ExpectString("parent.name", "Alice");
2009 } 2034 }
2010 2035
2011 2036
2012 THREADED_TEST(SwitchFromInterceptorToAccessor) { 2037 THREADED_TEST(SwitchFromInterceptorToAccessor) {
2013 v8::HandleScope scope(CcTest::isolate()); 2038 v8::HandleScope scope(CcTest::isolate());
2014 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2039 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2015 AddAccessor(templ, v8_str("age"), 2040 AddAccessor(templ, v8_str("age"),
2016 SimpleAccessorGetter, SimpleAccessorSetter); 2041 SimpleAccessorGetter, SimpleAccessorSetter);
2017 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2042 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2018 LocalContext env; 2043 LocalContext env;
2019 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2044 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2020 CompileRun("var obj = new Obj;" 2045 CompileRun("var obj = new Obj;"
2021 "function setAge(i){ obj.age = i; };" 2046 "function setAge(i){ obj.age = i; };"
2022 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2047 "for(var i = 0; i <= 10000; i++) setAge(i);");
2023 // All i < 10000 go to the interceptor. 2048 // All i < 10000 go to the interceptor.
2024 ExpectInt32("obj.interceptor_age", 9999); 2049 ExpectInt32("obj.interceptor_age", 9999);
2025 // The last i goes to the accessor. 2050 // The last i goes to the accessor.
2026 ExpectInt32("obj.accessor_age", 10000); 2051 ExpectInt32("obj.accessor_age", 10000);
2027 } 2052 }
2028 2053
2029 2054
2030 THREADED_TEST(SwitchFromAccessorToInterceptor) { 2055 THREADED_TEST(SwitchFromAccessorToInterceptor) {
2031 v8::HandleScope scope(CcTest::isolate()); 2056 v8::HandleScope scope(CcTest::isolate());
2032 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2057 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2033 AddAccessor(templ, v8_str("age"), 2058 AddAccessor(templ, v8_str("age"),
2034 SimpleAccessorGetter, SimpleAccessorSetter); 2059 SimpleAccessorGetter, SimpleAccessorSetter);
2035 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2060 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2036 LocalContext env; 2061 LocalContext env;
2037 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2062 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2038 CompileRun("var obj = new Obj;" 2063 CompileRun("var obj = new Obj;"
2039 "function setAge(i){ obj.age = i; };" 2064 "function setAge(i){ obj.age = i; };"
2040 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2065 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2041 // All i >= 10000 go to the accessor. 2066 // All i >= 10000 go to the accessor.
2042 ExpectInt32("obj.accessor_age", 10000); 2067 ExpectInt32("obj.accessor_age", 10000);
2043 // The last i goes to the interceptor. 2068 // The last i goes to the interceptor.
2044 ExpectInt32("obj.interceptor_age", 9999); 2069 ExpectInt32("obj.interceptor_age", 9999);
2045 } 2070 }
2046 2071
2047 2072
2048 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) { 2073 THREADED_TEST(SwitchFromInterceptorToAccessorWithInheritance) {
2049 v8::HandleScope scope(CcTest::isolate()); 2074 v8::HandleScope scope(CcTest::isolate());
2050 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2075 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
2051 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2076 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
2052 child->Inherit(parent); 2077 child->Inherit(parent);
2053 AddAccessor(parent, v8_str("age"), 2078 AddAccessor(parent, v8_str("age"),
2054 SimpleAccessorGetter, SimpleAccessorSetter); 2079 SimpleAccessorGetter, SimpleAccessorSetter);
2055 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2080 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2056 LocalContext env; 2081 LocalContext env;
2057 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2082 env->Global()->Set(v8_str("Child"), child->GetFunction());
2058 CompileRun("var child = new Child;" 2083 CompileRun("var child = new Child;"
2059 "function setAge(i){ child.age = i; };" 2084 "function setAge(i){ child.age = i; };"
2060 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2085 "for(var i = 0; i <= 10000; i++) setAge(i);");
2061 // All i < 10000 go to the interceptor. 2086 // All i < 10000 go to the interceptor.
2062 ExpectInt32("child.interceptor_age", 9999); 2087 ExpectInt32("child.interceptor_age", 9999);
2063 // The last i goes to the accessor. 2088 // The last i goes to the accessor.
2064 ExpectInt32("child.accessor_age", 10000); 2089 ExpectInt32("child.accessor_age", 10000);
2065 } 2090 }
2066 2091
2067 2092
2068 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) { 2093 THREADED_TEST(SwitchFromAccessorToInterceptorWithInheritance) {
2069 v8::HandleScope scope(CcTest::isolate()); 2094 v8::HandleScope scope(CcTest::isolate());
2070 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2095 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
2071 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2096 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
2072 child->Inherit(parent); 2097 child->Inherit(parent);
2073 AddAccessor(parent, v8_str("age"), 2098 AddAccessor(parent, v8_str("age"),
2074 SimpleAccessorGetter, SimpleAccessorSetter); 2099 SimpleAccessorGetter, SimpleAccessorSetter);
2075 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2100 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2076 LocalContext env; 2101 LocalContext env;
2077 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2102 env->Global()->Set(v8_str("Child"), child->GetFunction());
2078 CompileRun("var child = new Child;" 2103 CompileRun("var child = new Child;"
2079 "function setAge(i){ child.age = i; };" 2104 "function setAge(i){ child.age = i; };"
2080 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2105 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2081 // All i >= 10000 go to the accessor. 2106 // All i >= 10000 go to the accessor.
2082 ExpectInt32("child.accessor_age", 10000); 2107 ExpectInt32("child.accessor_age", 10000);
2083 // The last i goes to the interceptor. 2108 // The last i goes to the interceptor.
2084 ExpectInt32("child.interceptor_age", 9999); 2109 ExpectInt32("child.interceptor_age", 9999);
2085 } 2110 }
2086 2111
2087 2112
2088 THREADED_TEST(SwitchFromInterceptorToJSAccessor) { 2113 THREADED_TEST(SwitchFromInterceptorToJSAccessor) {
2089 v8::HandleScope scope(CcTest::isolate()); 2114 v8::HandleScope scope(CcTest::isolate());
2090 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2115 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2091 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2116 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2092 LocalContext env; 2117 LocalContext env;
2093 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2118 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2094 CompileRun("var obj = new Obj;" 2119 CompileRun("var obj = new Obj;"
2095 "function setter(i) { this.accessor_age = i; };" 2120 "function setter(i) { this.accessor_age = i; };"
2096 "function getter() { return this.accessor_age; };" 2121 "function getter() { return this.accessor_age; };"
2097 "function setAge(i) { obj.age = i; };" 2122 "function setAge(i) { obj.age = i; };"
2098 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2123 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2099 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2124 "for(var i = 0; i <= 10000; i++) setAge(i);");
2100 // All i < 10000 go to the interceptor. 2125 // All i < 10000 go to the interceptor.
2101 ExpectInt32("obj.interceptor_age", 9999); 2126 ExpectInt32("obj.interceptor_age", 9999);
2102 // The last i goes to the JavaScript accessor. 2127 // The last i goes to the JavaScript accessor.
2103 ExpectInt32("obj.accessor_age", 10000); 2128 ExpectInt32("obj.accessor_age", 10000);
2104 // The installed JavaScript getter is still intact. 2129 // The installed JavaScript getter is still intact.
2105 // This last part is a regression test for issue 1651 and relies on the fact 2130 // This last part is a regression test for issue 1651 and relies on the fact
2106 // that both interceptor and accessor are being installed on the same object. 2131 // that both interceptor and accessor are being installed on the same object.
2107 ExpectInt32("obj.age", 10000); 2132 ExpectInt32("obj.age", 10000);
2108 ExpectBoolean("obj.hasOwnProperty('age')", true); 2133 ExpectBoolean("obj.hasOwnProperty('age')", true);
2109 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2134 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2110 } 2135 }
2111 2136
2112 2137
2113 THREADED_TEST(SwitchFromJSAccessorToInterceptor) { 2138 THREADED_TEST(SwitchFromJSAccessorToInterceptor) {
2114 v8::HandleScope scope(CcTest::isolate()); 2139 v8::HandleScope scope(CcTest::isolate());
2115 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 2140 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
2116 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 2141 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
2117 LocalContext env; 2142 LocalContext env;
2118 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 2143 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
2119 CompileRun("var obj = new Obj;" 2144 CompileRun("var obj = new Obj;"
2120 "function setter(i) { this.accessor_age = i; };" 2145 "function setter(i) { this.accessor_age = i; };"
2121 "function getter() { return this.accessor_age; };" 2146 "function getter() { return this.accessor_age; };"
2122 "function setAge(i) { obj.age = i; };" 2147 "function setAge(i) { obj.age = i; };"
2123 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 2148 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
2124 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2149 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2125 // All i >= 10000 go to the accessor. 2150 // All i >= 10000 go to the accessor.
2126 ExpectInt32("obj.accessor_age", 10000); 2151 ExpectInt32("obj.accessor_age", 10000);
2127 // The last i goes to the interceptor. 2152 // The last i goes to the interceptor.
2128 ExpectInt32("obj.interceptor_age", 9999); 2153 ExpectInt32("obj.interceptor_age", 9999);
2129 // The installed JavaScript getter is still intact. 2154 // The installed JavaScript getter is still intact.
2130 // This last part is a regression test for issue 1651 and relies on the fact 2155 // This last part is a regression test for issue 1651 and relies on the fact
2131 // that both interceptor and accessor are being installed on the same object. 2156 // that both interceptor and accessor are being installed on the same object.
2132 ExpectInt32("obj.age", 10000); 2157 ExpectInt32("obj.age", 10000);
2133 ExpectBoolean("obj.hasOwnProperty('age')", true); 2158 ExpectBoolean("obj.hasOwnProperty('age')", true);
2134 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value"); 2159 ExpectUndefined("Object.getOwnPropertyDescriptor(obj, 'age').value");
2135 } 2160 }
2136 2161
2137 2162
2138 THREADED_TEST(SwitchFromInterceptorToProperty) { 2163 THREADED_TEST(SwitchFromInterceptorToProperty) {
2139 v8::HandleScope scope(CcTest::isolate()); 2164 v8::HandleScope scope(CcTest::isolate());
2140 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2165 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
2141 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2166 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
2142 child->Inherit(parent); 2167 child->Inherit(parent);
2143 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2168 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2144 LocalContext env; 2169 LocalContext env;
2145 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2170 env->Global()->Set(v8_str("Child"), child->GetFunction());
2146 CompileRun("var child = new Child;" 2171 CompileRun("var child = new Child;"
2147 "function setAge(i){ child.age = i; };" 2172 "function setAge(i){ child.age = i; };"
2148 "for(var i = 0; i <= 10000; i++) setAge(i);"); 2173 "for(var i = 0; i <= 10000; i++) setAge(i);");
2149 // All i < 10000 go to the interceptor. 2174 // All i < 10000 go to the interceptor.
2150 ExpectInt32("child.interceptor_age", 9999); 2175 ExpectInt32("child.interceptor_age", 9999);
2151 // The last i goes to child's own property. 2176 // The last i goes to child's own property.
2152 ExpectInt32("child.age", 10000); 2177 ExpectInt32("child.age", 10000);
2153 } 2178 }
2154 2179
2155 2180
2156 THREADED_TEST(SwitchFromPropertyToInterceptor) { 2181 THREADED_TEST(SwitchFromPropertyToInterceptor) {
2157 v8::HandleScope scope(CcTest::isolate()); 2182 v8::HandleScope scope(CcTest::isolate());
2158 Handle<FunctionTemplate> parent = FunctionTemplate::New(); 2183 Handle<FunctionTemplate> parent = FunctionTemplate::New(CcTest::isolate());
2159 Handle<FunctionTemplate> child = FunctionTemplate::New(); 2184 Handle<FunctionTemplate> child = FunctionTemplate::New(CcTest::isolate());
2160 child->Inherit(parent); 2185 child->Inherit(parent);
2161 AddInterceptor(child, InterceptorGetter, InterceptorSetter); 2186 AddInterceptor(child, InterceptorGetter, InterceptorSetter);
2162 LocalContext env; 2187 LocalContext env;
2163 env->Global()->Set(v8_str("Child"), child->GetFunction()); 2188 env->Global()->Set(v8_str("Child"), child->GetFunction());
2164 CompileRun("var child = new Child;" 2189 CompileRun("var child = new Child;"
2165 "function setAge(i){ child.age = i; };" 2190 "function setAge(i){ child.age = i; };"
2166 "for(var i = 20000; i >= 9999; i--) setAge(i);"); 2191 "for(var i = 20000; i >= 9999; i--) setAge(i);");
2167 // All i >= 10000 go to child's own property. 2192 // All i >= 10000 go to child's own property.
2168 ExpectInt32("child.age", 10000); 2193 ExpectInt32("child.age", 10000);
2169 // The last i goes to the interceptor. 2194 // The last i goes to the interceptor.
2170 ExpectInt32("child.interceptor_age", 9999); 2195 ExpectInt32("child.interceptor_age", 9999);
2171 } 2196 }
2172 2197
2173 2198
2174 THREADED_TEST(NamedPropertyHandlerGetter) { 2199 THREADED_TEST(NamedPropertyHandlerGetter) {
2175 echo_named_call_count = 0; 2200 echo_named_call_count = 0;
2176 v8::HandleScope scope(CcTest::isolate()); 2201 v8::HandleScope scope(CcTest::isolate());
2177 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2202 v8::Handle<v8::FunctionTemplate> templ =
2203 v8::FunctionTemplate::New(CcTest::isolate());
2178 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty, 2204 templ->InstanceTemplate()->SetNamedPropertyHandler(EchoNamedProperty,
2179 0, 0, 0, 0, 2205 0, 0, 0, 0,
2180 v8_str("data")); 2206 v8_str("data"));
2181 LocalContext env; 2207 LocalContext env;
2182 env->Global()->Set(v8_str("obj"), 2208 env->Global()->Set(v8_str("obj"),
2183 templ->GetFunction()->NewInstance()); 2209 templ->GetFunction()->NewInstance());
2184 CHECK_EQ(echo_named_call_count, 0); 2210 CHECK_EQ(echo_named_call_count, 0);
2185 v8_compile("obj.x")->Run(); 2211 v8_compile("obj.x")->Run();
2186 CHECK_EQ(echo_named_call_count, 1); 2212 CHECK_EQ(echo_named_call_count, 1);
2187 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;"; 2213 const char* code = "var str = 'oddle'; obj[str] + obj.poddle;";
(...skipping 14 matching lines...) Expand all
2202 uint32_t index, 2228 uint32_t index,
2203 const v8::PropertyCallbackInfo<v8::Value>& info) { 2229 const v8::PropertyCallbackInfo<v8::Value>& info) {
2204 ApiTestFuzzer::Fuzz(); 2230 ApiTestFuzzer::Fuzz();
2205 CHECK_EQ(v8_num(637), info.Data()); 2231 CHECK_EQ(v8_num(637), info.Data());
2206 echo_indexed_call_count++; 2232 echo_indexed_call_count++;
2207 info.GetReturnValue().Set(v8_num(index)); 2233 info.GetReturnValue().Set(v8_num(index));
2208 } 2234 }
2209 2235
2210 2236
2211 THREADED_TEST(IndexedPropertyHandlerGetter) { 2237 THREADED_TEST(IndexedPropertyHandlerGetter) {
2212 v8::HandleScope scope(CcTest::isolate()); 2238 v8::Isolate* isolate = CcTest::isolate();
2213 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2239 v8::HandleScope scope(isolate);
2240 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2214 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty, 2241 templ->InstanceTemplate()->SetIndexedPropertyHandler(EchoIndexedProperty,
2215 0, 0, 0, 0, 2242 0, 0, 0, 0,
2216 v8_num(637)); 2243 v8_num(637));
2217 LocalContext env; 2244 LocalContext env;
2218 env->Global()->Set(v8_str("obj"), 2245 env->Global()->Set(v8_str("obj"),
2219 templ->GetFunction()->NewInstance()); 2246 templ->GetFunction()->NewInstance());
2220 Local<Script> script = v8_compile("obj[900]"); 2247 Local<Script> script = v8_compile("obj[900]");
2221 CHECK_EQ(script->Run()->Int32Value(), 900); 2248 CHECK_EQ(script->Run()->Int32Value(), 900);
2222 } 2249 }
2223 2250
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 void CheckThisNamedPropertyEnumerator( 2333 void CheckThisNamedPropertyEnumerator(
2307 const v8::PropertyCallbackInfo<v8::Array>& info) { 2334 const v8::PropertyCallbackInfo<v8::Array>& info) {
2308 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator)); 2335 CheckReturnValue(info, FUNCTION_ADDR(CheckThisNamedPropertyEnumerator));
2309 ApiTestFuzzer::Fuzz(); 2336 ApiTestFuzzer::Fuzz();
2310 CHECK(info.This()->Equals(bottom)); 2337 CHECK(info.This()->Equals(bottom));
2311 } 2338 }
2312 2339
2313 2340
2314 THREADED_PROFILED_TEST(PropertyHandlerInPrototype) { 2341 THREADED_PROFILED_TEST(PropertyHandlerInPrototype) {
2315 LocalContext env; 2342 LocalContext env;
2316 v8::HandleScope scope(env->GetIsolate()); 2343 v8::Isolate* isolate = env->GetIsolate();
2344 v8::HandleScope scope(isolate);
2317 2345
2318 // Set up a prototype chain with three interceptors. 2346 // Set up a prototype chain with three interceptors.
2319 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2347 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2320 templ->InstanceTemplate()->SetIndexedPropertyHandler( 2348 templ->InstanceTemplate()->SetIndexedPropertyHandler(
2321 CheckThisIndexedPropertyHandler, 2349 CheckThisIndexedPropertyHandler,
2322 CheckThisIndexedPropertySetter, 2350 CheckThisIndexedPropertySetter,
2323 CheckThisIndexedPropertyQuery, 2351 CheckThisIndexedPropertyQuery,
2324 CheckThisIndexedPropertyDeleter, 2352 CheckThisIndexedPropertyDeleter,
2325 CheckThisIndexedPropertyEnumerator); 2353 CheckThisIndexedPropertyEnumerator);
2326 2354
2327 templ->InstanceTemplate()->SetNamedPropertyHandler( 2355 templ->InstanceTemplate()->SetNamedPropertyHandler(
2328 CheckThisNamedPropertyHandler, 2356 CheckThisNamedPropertyHandler,
2329 CheckThisNamedPropertySetter, 2357 CheckThisNamedPropertySetter,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 static void PrePropertyHandlerQuery( 2401 static void PrePropertyHandlerQuery(
2374 Local<String> key, 2402 Local<String> key,
2375 const v8::PropertyCallbackInfo<v8::Integer>& info) { 2403 const v8::PropertyCallbackInfo<v8::Integer>& info) {
2376 if (v8_str("pre")->Equals(key)) { 2404 if (v8_str("pre")->Equals(key)) {
2377 info.GetReturnValue().Set(static_cast<int32_t>(v8::None)); 2405 info.GetReturnValue().Set(static_cast<int32_t>(v8::None));
2378 } 2406 }
2379 } 2407 }
2380 2408
2381 2409
2382 THREADED_TEST(PrePropertyHandler) { 2410 THREADED_TEST(PrePropertyHandler) {
2383 v8::HandleScope scope(CcTest::isolate()); 2411 v8::Isolate* isolate = CcTest::isolate();
2384 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 2412 v8::HandleScope scope(isolate);
2413 v8::Handle<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
2385 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet, 2414 desc->InstanceTemplate()->SetNamedPropertyHandler(PrePropertyHandlerGet,
2386 0, 2415 0,
2387 PrePropertyHandlerQuery); 2416 PrePropertyHandlerQuery);
2388 LocalContext env(NULL, desc->InstanceTemplate()); 2417 LocalContext env(NULL, desc->InstanceTemplate());
2389 Script::Compile(v8_str( 2418 Script::Compile(v8_str(
2390 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run(); 2419 "var pre = 'Object: pre'; var on = 'Object: on';"))->Run();
2391 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run(); 2420 v8::Handle<Value> result_pre = Script::Compile(v8_str("pre"))->Run();
2392 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre); 2421 CHECK_EQ(v8_str("PrePropertyHandler: pre"), result_pre);
2393 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run(); 2422 v8::Handle<Value> result_on = Script::Compile(v8_str("on"))->Run();
2394 CHECK_EQ(v8_str("Object: on"), result_on); 2423 CHECK_EQ(v8_str("Object: on"), result_on);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 } 2459 }
2431 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1)); 2460 args.This()->Set(v8_str("depth"), v8::Integer::New(depth + 1));
2432 v8::Handle<Value> function = 2461 v8::Handle<Value> function =
2433 args.This()->Get(v8_str("callFunctionRecursively")); 2462 args.This()->Get(v8_str("callFunctionRecursively"));
2434 args.GetReturnValue().Set( 2463 args.GetReturnValue().Set(
2435 function.As<Function>()->Call(args.This(), 0, NULL)); 2464 function.As<Function>()->Call(args.This(), 0, NULL));
2436 } 2465 }
2437 2466
2438 2467
2439 THREADED_TEST(DeepCrossLanguageRecursion) { 2468 THREADED_TEST(DeepCrossLanguageRecursion) {
2440 v8::HandleScope scope(CcTest::isolate()); 2469 v8::Isolate* isolate = CcTest::isolate();
2470 v8::HandleScope scope(isolate);
2441 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 2471 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
2442 global->Set(v8_str("callScriptRecursively"), 2472 global->Set(v8_str("callScriptRecursively"),
2443 v8::FunctionTemplate::New(CallScriptRecursivelyCall)); 2473 v8::FunctionTemplate::New(isolate, CallScriptRecursivelyCall));
2444 global->Set(v8_str("callFunctionRecursively"), 2474 global->Set(v8_str("callFunctionRecursively"),
2445 v8::FunctionTemplate::New(CallFunctionRecursivelyCall)); 2475 v8::FunctionTemplate::New(isolate, CallFunctionRecursivelyCall));
2446 LocalContext env(NULL, global); 2476 LocalContext env(NULL, global);
2447 2477
2448 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2478 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2449 call_recursively_script = v8_compile("callScriptRecursively()"); 2479 call_recursively_script = v8_compile("callScriptRecursively()");
2450 call_recursively_script->Run(); 2480 call_recursively_script->Run();
2451 call_recursively_script = v8::Handle<Script>(); 2481 call_recursively_script = v8::Handle<Script>();
2452 2482
2453 env->Global()->Set(v8_str("depth"), v8::Integer::New(0)); 2483 env->Global()->Set(v8_str("depth"), v8::Integer::New(0));
2454 Script::Compile(v8_str("callFunctionRecursively()"))->Run(); 2484 Script::Compile(v8_str("callFunctionRecursively()"))->Run();
2455 } 2485 }
(...skipping 26 matching lines...) Expand all
2482 v8::Handle<Value> otto = Script::Compile(v8_str( 2512 v8::Handle<Value> otto = Script::Compile(v8_str(
2483 "try { with (obj) { otto; } } catch (e) { e; }"))->Run(); 2513 "try { with (obj) { otto; } } catch (e) { e; }"))->Run();
2484 CHECK_EQ(v8_str("otto"), otto); 2514 CHECK_EQ(v8_str("otto"), otto);
2485 v8::Handle<Value> netto = Script::Compile(v8_str( 2515 v8::Handle<Value> netto = Script::Compile(v8_str(
2486 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run(); 2516 "try { with (obj) { netto = 4; } } catch (e) { e; }"))->Run();
2487 CHECK_EQ(v8_str("netto"), netto); 2517 CHECK_EQ(v8_str("netto"), netto);
2488 } 2518 }
2489 2519
2490 2520
2491 THREADED_TEST(FunctionPrototype) { 2521 THREADED_TEST(FunctionPrototype) {
2492 v8::HandleScope scope(CcTest::isolate()); 2522 v8::Isolate* isolate = CcTest::isolate();
2493 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(); 2523 v8::HandleScope scope(isolate);
2524 Local<v8::FunctionTemplate> Foo = v8::FunctionTemplate::New(isolate);
2494 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321)); 2525 Foo->PrototypeTemplate()->Set(v8_str("plak"), v8_num(321));
2495 LocalContext env; 2526 LocalContext env;
2496 env->Global()->Set(v8_str("Foo"), Foo->GetFunction()); 2527 env->Global()->Set(v8_str("Foo"), Foo->GetFunction());
2497 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak")); 2528 Local<Script> script = Script::Compile(v8_str("Foo.prototype.plak"));
2498 CHECK_EQ(script->Run()->Int32Value(), 321); 2529 CHECK_EQ(script->Run()->Int32Value(), 321);
2499 } 2530 }
2500 2531
2501 2532
2502 THREADED_TEST(InternalFields) { 2533 THREADED_TEST(InternalFields) {
2503 LocalContext env; 2534 LocalContext env;
2504 v8::HandleScope scope(env->GetIsolate()); 2535 v8::Isolate* isolate = env->GetIsolate();
2536 v8::HandleScope scope(isolate);
2505 2537
2506 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2538 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2507 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2539 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2508 instance_templ->SetInternalFieldCount(1); 2540 instance_templ->SetInternalFieldCount(1);
2509 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2541 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2510 CHECK_EQ(1, obj->InternalFieldCount()); 2542 CHECK_EQ(1, obj->InternalFieldCount());
2511 CHECK(obj->GetInternalField(0)->IsUndefined()); 2543 CHECK(obj->GetInternalField(0)->IsUndefined());
2512 obj->SetInternalField(0, v8_num(17)); 2544 obj->SetInternalField(0, v8_num(17));
2513 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value()); 2545 CHECK_EQ(17, obj->GetInternalField(0)->Int32Value());
2514 } 2546 }
2515 2547
2516 2548
(...skipping 25 matching lines...) Expand all
2542 void* value) { 2574 void* value) {
2543 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1)); 2575 CHECK_EQ(0, static_cast<int>(reinterpret_cast<uintptr_t>(value) & 0x1));
2544 obj->SetAlignedPointerInInternalField(0, value); 2576 obj->SetAlignedPointerInInternalField(0, value);
2545 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 2577 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
2546 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0)); 2578 CHECK_EQ(value, obj->GetAlignedPointerFromInternalField(0));
2547 } 2579 }
2548 2580
2549 2581
2550 THREADED_TEST(InternalFieldsAlignedPointers) { 2582 THREADED_TEST(InternalFieldsAlignedPointers) {
2551 LocalContext env; 2583 LocalContext env;
2552 v8::HandleScope scope(env->GetIsolate()); 2584 v8::Isolate* isolate = env->GetIsolate();
2585 v8::HandleScope scope(isolate);
2553 2586
2554 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 2587 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
2555 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate(); 2588 Local<v8::ObjectTemplate> instance_templ = templ->InstanceTemplate();
2556 instance_templ->SetInternalFieldCount(1); 2589 instance_templ->SetInternalFieldCount(1);
2557 Local<v8::Object> obj = templ->GetFunction()->NewInstance(); 2590 Local<v8::Object> obj = templ->GetFunction()->NewInstance();
2558 CHECK_EQ(1, obj->InternalFieldCount()); 2591 CHECK_EQ(1, obj->InternalFieldCount());
2559 2592
2560 CheckAlignedPointerInInternalField(obj, NULL); 2593 CheckAlignedPointerInInternalField(obj, NULL);
2561 2594
2562 int* heap_allocated = new int[100]; 2595 int* heap_allocated = new int[100];
2563 CheckAlignedPointerInInternalField(obj, heap_allocated); 2596 CheckAlignedPointerInInternalField(obj, heap_allocated);
2564 delete[] heap_allocated; 2597 delete[] heap_allocated;
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 3206
3174 static bool interceptor_for_hidden_properties_called; 3207 static bool interceptor_for_hidden_properties_called;
3175 static void InterceptorForHiddenProperties( 3208 static void InterceptorForHiddenProperties(
3176 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 3209 Local<String> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
3177 interceptor_for_hidden_properties_called = true; 3210 interceptor_for_hidden_properties_called = true;
3178 } 3211 }
3179 3212
3180 3213
3181 THREADED_TEST(HiddenPropertiesWithInterceptors) { 3214 THREADED_TEST(HiddenPropertiesWithInterceptors) {
3182 LocalContext context; 3215 LocalContext context;
3183 v8::HandleScope scope(context->GetIsolate()); 3216 v8::Isolate* isolate = context->GetIsolate();
3217 v8::HandleScope scope(isolate);
3184 3218
3185 interceptor_for_hidden_properties_called = false; 3219 interceptor_for_hidden_properties_called = false;
3186 3220
3187 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3221 v8::Local<v8::String> key = v8_str("api-test::hidden-key");
3188 3222
3189 // Associate an interceptor with an object and start setting hidden values. 3223 // Associate an interceptor with an object and start setting hidden values.
3190 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 3224 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
3191 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 3225 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
3192 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties); 3226 instance_templ->SetNamedPropertyHandler(InterceptorForHiddenProperties);
3193 Local<v8::Function> function = fun_templ->GetFunction(); 3227 Local<v8::Function> function = fun_templ->GetFunction();
3194 Local<v8::Object> obj = function->NewInstance(); 3228 Local<v8::Object> obj = function->NewInstance();
3195 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302))); 3229 CHECK(obj->SetHiddenValue(key, v8::Integer::New(2302)));
3196 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value()); 3230 CHECK_EQ(2302, obj->GetHiddenValue(key)->Int32Value());
3197 CHECK(!interceptor_for_hidden_properties_called); 3231 CHECK(!interceptor_for_hidden_properties_called);
3198 } 3232 }
3199 3233
3200 3234
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
4191 v8::EscapableHandleScope scope(args.GetIsolate()); 4225 v8::EscapableHandleScope scope(args.GetIsolate());
4192 ApiTestFuzzer::Fuzz(); 4226 ApiTestFuzzer::Fuzz();
4193 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length()); 4227 Local<v8::Array> result = v8::Array::New(args.GetIsolate(), args.Length());
4194 for (int i = 0; i < args.Length(); i++) 4228 for (int i = 0; i < args.Length(); i++)
4195 result->Set(i, args[i]); 4229 result->Set(i, args[i]);
4196 args.GetReturnValue().Set(scope.Escape(result)); 4230 args.GetReturnValue().Set(scope.Escape(result));
4197 } 4231 }
4198 4232
4199 4233
4200 THREADED_TEST(Vector) { 4234 THREADED_TEST(Vector) {
4201 v8::HandleScope scope(CcTest::isolate()); 4235 v8::Isolate* isolate = CcTest::isolate();
4236 v8::HandleScope scope(isolate);
4202 Local<ObjectTemplate> global = ObjectTemplate::New(); 4237 Local<ObjectTemplate> global = ObjectTemplate::New();
4203 global->Set(v8_str("f"), v8::FunctionTemplate::New(HandleF)); 4238 global->Set(v8_str("f"), v8::FunctionTemplate::New(isolate, HandleF));
4204 LocalContext context(0, global); 4239 LocalContext context(0, global);
4205 4240
4206 const char* fun = "f()"; 4241 const char* fun = "f()";
4207 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>(); 4242 Local<v8::Array> a0 = CompileRun(fun).As<v8::Array>();
4208 CHECK_EQ(0, a0->Length()); 4243 CHECK_EQ(0, a0->Length());
4209 4244
4210 const char* fun2 = "f(11)"; 4245 const char* fun2 = "f(11)";
4211 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>(); 4246 Local<v8::Array> a1 = CompileRun(fun2).As<v8::Array>();
4212 CHECK_EQ(1, a1->Length()); 4247 CHECK_EQ(1, a1->Length());
4213 CHECK_EQ(11, a1->Get(0)->Int32Value()); 4248 CHECK_EQ(11, a1->Get(0)->Int32Value());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
4377 // Set heap limits. 4412 // Set heap limits.
4378 static const int K = 1024; 4413 static const int K = 1024;
4379 v8::ResourceConstraints constraints; 4414 v8::ResourceConstraints constraints;
4380 constraints.set_max_young_space_size(256 * K); 4415 constraints.set_max_young_space_size(256 * K);
4381 constraints.set_max_old_space_size(5 * K * K); 4416 constraints.set_max_old_space_size(5 * K * K);
4382 v8::SetResourceConstraints(CcTest::isolate(), &constraints); 4417 v8::SetResourceConstraints(CcTest::isolate(), &constraints);
4383 4418
4384 v8::HandleScope scope(CcTest::isolate()); 4419 v8::HandleScope scope(CcTest::isolate());
4385 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4420 Local<ObjectTemplate> templ = ObjectTemplate::New();
4386 templ->Set(v8_str("ProvokeOutOfMemory"), 4421 templ->Set(v8_str("ProvokeOutOfMemory"),
4387 v8::FunctionTemplate::New(ProvokeOutOfMemory)); 4422 v8::FunctionTemplate::New(CcTest::isolate(), ProvokeOutOfMemory));
4388 LocalContext context(0, templ); 4423 LocalContext context(0, templ);
4389 v8::V8::IgnoreOutOfMemoryException(); 4424 v8::V8::IgnoreOutOfMemoryException();
4390 Local<Value> result = CompileRun( 4425 Local<Value> result = CompileRun(
4391 "var thrown = false;" 4426 "var thrown = false;"
4392 "try {" 4427 "try {"
4393 " ProvokeOutOfMemory();" 4428 " ProvokeOutOfMemory();"
4394 "} catch (e) {" 4429 "} catch (e) {"
4395 " thrown = true;" 4430 " thrown = true;"
4396 "}"); 4431 "}");
4397 // Check for out of memory state. 4432 // Check for out of memory state.
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run(); 4692 Local<Value> result = v8::Script::Compile(args[0]->ToString())->Run();
4658 CHECK(!try_catch.HasCaught() || result.IsEmpty()); 4693 CHECK(!try_catch.HasCaught() || result.IsEmpty());
4659 args.GetReturnValue().Set(try_catch.HasCaught()); 4694 args.GetReturnValue().Set(try_catch.HasCaught());
4660 } 4695 }
4661 4696
4662 4697
4663 THREADED_TEST(APICatch) { 4698 THREADED_TEST(APICatch) {
4664 v8::HandleScope scope(CcTest::isolate()); 4699 v8::HandleScope scope(CcTest::isolate());
4665 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4700 Local<ObjectTemplate> templ = ObjectTemplate::New();
4666 templ->Set(v8_str("ThrowFromC"), 4701 templ->Set(v8_str("ThrowFromC"),
4667 v8::FunctionTemplate::New(ThrowFromC)); 4702 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC));
4668 LocalContext context(0, templ); 4703 LocalContext context(0, templ);
4669 CompileRun( 4704 CompileRun(
4670 "var thrown = false;" 4705 "var thrown = false;"
4671 "try {" 4706 "try {"
4672 " ThrowFromC();" 4707 " ThrowFromC();"
4673 "} catch (e) {" 4708 "} catch (e) {"
4674 " thrown = true;" 4709 " thrown = true;"
4675 "}"); 4710 "}");
4676 Local<Value> thrown = context->Global()->Get(v8_str("thrown")); 4711 Local<Value> thrown = context->Global()->Get(v8_str("thrown"));
4677 CHECK(thrown->BooleanValue()); 4712 CHECK(thrown->BooleanValue());
4678 } 4713 }
4679 4714
4680 4715
4681 THREADED_TEST(APIThrowTryCatch) { 4716 THREADED_TEST(APIThrowTryCatch) {
4682 v8::HandleScope scope(CcTest::isolate()); 4717 v8::HandleScope scope(CcTest::isolate());
4683 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4718 Local<ObjectTemplate> templ = ObjectTemplate::New();
4684 templ->Set(v8_str("ThrowFromC"), 4719 templ->Set(v8_str("ThrowFromC"),
4685 v8::FunctionTemplate::New(ThrowFromC)); 4720 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC));
4686 LocalContext context(0, templ); 4721 LocalContext context(0, templ);
4687 v8::TryCatch try_catch; 4722 v8::TryCatch try_catch;
4688 CompileRun("ThrowFromC();"); 4723 CompileRun("ThrowFromC();");
4689 CHECK(try_catch.HasCaught()); 4724 CHECK(try_catch.HasCaught());
4690 } 4725 }
4691 4726
4692 4727
4693 // Test that a try-finally block doesn't shadow a try-catch block 4728 // Test that a try-finally block doesn't shadow a try-catch block
4694 // when setting up an external handler. 4729 // when setting up an external handler.
4695 // 4730 //
4696 // BUG(271): Some of the exception propagation does not work on the 4731 // BUG(271): Some of the exception propagation does not work on the
4697 // ARM simulator because the simulator separates the C++ stack and the 4732 // ARM simulator because the simulator separates the C++ stack and the
4698 // JS stack. This test therefore fails on the simulator. The test is 4733 // JS stack. This test therefore fails on the simulator. The test is
4699 // not threaded to allow the threading tests to run on the simulator. 4734 // not threaded to allow the threading tests to run on the simulator.
4700 TEST(TryCatchInTryFinally) { 4735 TEST(TryCatchInTryFinally) {
4701 v8::HandleScope scope(CcTest::isolate()); 4736 v8::HandleScope scope(CcTest::isolate());
4702 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4737 Local<ObjectTemplate> templ = ObjectTemplate::New();
4703 templ->Set(v8_str("CCatcher"), 4738 templ->Set(v8_str("CCatcher"),
4704 v8::FunctionTemplate::New(CCatcher)); 4739 v8::FunctionTemplate::New(CcTest::isolate(), CCatcher));
4705 LocalContext context(0, templ); 4740 LocalContext context(0, templ);
4706 Local<Value> result = CompileRun("try {" 4741 Local<Value> result = CompileRun("try {"
4707 " try {" 4742 " try {"
4708 " CCatcher('throw 7;');" 4743 " CCatcher('throw 7;');"
4709 " } finally {" 4744 " } finally {"
4710 " }" 4745 " }"
4711 "} catch (e) {" 4746 "} catch (e) {"
4712 "}"); 4747 "}");
4713 CHECK(result->IsTrue()); 4748 CHECK(result->IsTrue());
4714 } 4749 }
(...skipping 10 matching lines...) Expand all
4725 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { 4760 static void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) {
4726 ApiTestFuzzer::Fuzz(); 4761 ApiTestFuzzer::Fuzz();
4727 CHECK(false); 4762 CHECK(false);
4728 } 4763 }
4729 4764
4730 4765
4731 // Test that overwritten methods are not invoked on uncaught exception 4766 // Test that overwritten methods are not invoked on uncaught exception
4732 // formatting. However, they are invoked when performing normal error 4767 // formatting. However, they are invoked when performing normal error
4733 // string conversions. 4768 // string conversions.
4734 TEST(APIThrowMessageOverwrittenToString) { 4769 TEST(APIThrowMessageOverwrittenToString) {
4735 v8::HandleScope scope(CcTest::isolate()); 4770 v8::Isolate* isolate = CcTest::isolate();
4771 v8::HandleScope scope(isolate);
4736 v8::V8::AddMessageListener(check_reference_error_message); 4772 v8::V8::AddMessageListener(check_reference_error_message);
4737 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4773 Local<ObjectTemplate> templ = ObjectTemplate::New();
4738 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail)); 4774 templ->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail));
4739 LocalContext context(NULL, templ); 4775 LocalContext context(NULL, templ);
4740 CompileRun("asdf;"); 4776 CompileRun("asdf;");
4741 CompileRun("var limit = {};" 4777 CompileRun("var limit = {};"
4742 "limit.valueOf = fail;" 4778 "limit.valueOf = fail;"
4743 "Error.stackTraceLimit = limit;"); 4779 "Error.stackTraceLimit = limit;");
4744 CompileRun("asdf"); 4780 CompileRun("asdf");
4745 CompileRun("Array.prototype.pop = fail;"); 4781 CompileRun("Array.prototype.pop = fail;");
4746 CompileRun("Object.prototype.hasOwnProperty = fail;"); 4782 CompileRun("Object.prototype.hasOwnProperty = fail;");
4747 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }"); 4783 CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
4748 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); 4784 CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
4853 message_received = true; 4889 message_received = true;
4854 } 4890 }
4855 4891
4856 4892
4857 TEST(APIThrowMessage) { 4893 TEST(APIThrowMessage) {
4858 message_received = false; 4894 message_received = false;
4859 v8::HandleScope scope(CcTest::isolate()); 4895 v8::HandleScope scope(CcTest::isolate());
4860 v8::V8::AddMessageListener(receive_message); 4896 v8::V8::AddMessageListener(receive_message);
4861 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4897 Local<ObjectTemplate> templ = ObjectTemplate::New();
4862 templ->Set(v8_str("ThrowFromC"), 4898 templ->Set(v8_str("ThrowFromC"),
4863 v8::FunctionTemplate::New(ThrowFromC)); 4899 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC));
4864 LocalContext context(0, templ); 4900 LocalContext context(0, templ);
4865 CompileRun("ThrowFromC();"); 4901 CompileRun("ThrowFromC();");
4866 CHECK(message_received); 4902 CHECK(message_received);
4867 v8::V8::RemoveMessageListeners(receive_message); 4903 v8::V8::RemoveMessageListeners(receive_message);
4868 } 4904 }
4869 4905
4870 4906
4871 TEST(APIThrowMessageAndVerboseTryCatch) { 4907 TEST(APIThrowMessageAndVerboseTryCatch) {
4872 message_received = false; 4908 message_received = false;
4873 v8::HandleScope scope(CcTest::isolate()); 4909 v8::HandleScope scope(CcTest::isolate());
4874 v8::V8::AddMessageListener(receive_message); 4910 v8::V8::AddMessageListener(receive_message);
4875 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4911 Local<ObjectTemplate> templ = ObjectTemplate::New();
4876 templ->Set(v8_str("ThrowFromC"), 4912 templ->Set(v8_str("ThrowFromC"),
4877 v8::FunctionTemplate::New(ThrowFromC)); 4913 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC));
4878 LocalContext context(0, templ); 4914 LocalContext context(0, templ);
4879 v8::TryCatch try_catch; 4915 v8::TryCatch try_catch;
4880 try_catch.SetVerbose(true); 4916 try_catch.SetVerbose(true);
4881 Local<Value> result = CompileRun("ThrowFromC();"); 4917 Local<Value> result = CompileRun("ThrowFromC();");
4882 CHECK(try_catch.HasCaught()); 4918 CHECK(try_catch.HasCaught());
4883 CHECK(result.IsEmpty()); 4919 CHECK(result.IsEmpty());
4884 CHECK(message_received); 4920 CHECK(message_received);
4885 v8::V8::RemoveMessageListeners(receive_message); 4921 v8::V8::RemoveMessageListeners(receive_message);
4886 } 4922 }
4887 4923
(...skipping 10 matching lines...) Expand all
4898 CHECK(result.IsEmpty()); 4934 CHECK(result.IsEmpty());
4899 CHECK(message_received); 4935 CHECK(message_received);
4900 v8::V8::RemoveMessageListeners(receive_message); 4936 v8::V8::RemoveMessageListeners(receive_message);
4901 } 4937 }
4902 4938
4903 4939
4904 THREADED_TEST(ExternalScriptException) { 4940 THREADED_TEST(ExternalScriptException) {
4905 v8::HandleScope scope(CcTest::isolate()); 4941 v8::HandleScope scope(CcTest::isolate());
4906 Local<ObjectTemplate> templ = ObjectTemplate::New(); 4942 Local<ObjectTemplate> templ = ObjectTemplate::New();
4907 templ->Set(v8_str("ThrowFromC"), 4943 templ->Set(v8_str("ThrowFromC"),
4908 v8::FunctionTemplate::New(ThrowFromC)); 4944 v8::FunctionTemplate::New(CcTest::isolate(), ThrowFromC));
4909 LocalContext context(0, templ); 4945 LocalContext context(0, templ);
4910 4946
4911 v8::TryCatch try_catch; 4947 v8::TryCatch try_catch;
4912 Local<Script> script 4948 Local<Script> script
4913 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';")); 4949 = Script::Compile(v8_str("ThrowFromC(); throw 'panama';"));
4914 Local<Value> result = script->Run(); 4950 Local<Value> result = script->Run();
4915 CHECK(result.IsEmpty()); 4951 CHECK(result.IsEmpty());
4916 CHECK(try_catch.HasCaught()); 4952 CHECK(try_catch.HasCaught());
4917 String::Utf8Value exception_value(try_catch.Exception()); 4953 String::Utf8Value exception_value(try_catch.Exception());
4918 CHECK_EQ("konto", *exception_value); 4954 CHECK_EQ("konto", *exception_value);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
5000 // 5036 //
5001 // Each entry is an activation, either JS or C. The index is the count at that 5037 // Each entry is an activation, either JS or C. The index is the count at that
5002 // level. Stars identify activations with exception handlers, the @ identifies 5038 // level. Stars identify activations with exception handlers, the @ identifies
5003 // the exception handler that should catch the exception. 5039 // the exception handler that should catch the exception.
5004 // 5040 //
5005 // BUG(271): Some of the exception propagation does not work on the 5041 // BUG(271): Some of the exception propagation does not work on the
5006 // ARM simulator because the simulator separates the C++ stack and the 5042 // ARM simulator because the simulator separates the C++ stack and the
5007 // JS stack. This test therefore fails on the simulator. The test is 5043 // JS stack. This test therefore fails on the simulator. The test is
5008 // not threaded to allow the threading tests to run on the simulator. 5044 // not threaded to allow the threading tests to run on the simulator.
5009 TEST(ExceptionOrder) { 5045 TEST(ExceptionOrder) {
5010 v8::HandleScope scope(CcTest::isolate()); 5046 v8::Isolate* isolate = CcTest::isolate();
5047 v8::HandleScope scope(isolate);
5011 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5048 Local<ObjectTemplate> templ = ObjectTemplate::New();
5012 templ->Set(v8_str("check"), v8::FunctionTemplate::New(JSCheck)); 5049 templ->Set(v8_str("check"), v8::FunctionTemplate::New(isolate, JSCheck));
5013 templ->Set(v8_str("CThrowCountDown"), 5050 templ->Set(v8_str("CThrowCountDown"),
5014 v8::FunctionTemplate::New(CThrowCountDown)); 5051 v8::FunctionTemplate::New(isolate, CThrowCountDown));
5015 LocalContext context(0, templ); 5052 LocalContext context(0, templ);
5016 CompileRun( 5053 CompileRun(
5017 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {" 5054 "function JSThrowCountDown(count, jsInterval, cInterval, expected) {"
5018 " if (count == 0) throw 'FromJS';" 5055 " if (count == 0) throw 'FromJS';"
5019 " if (count % jsInterval == 0) {" 5056 " if (count % jsInterval == 0) {"
5020 " try {" 5057 " try {"
5021 " var value = CThrowCountDown(count - 1," 5058 " var value = CThrowCountDown(count - 1,"
5022 " jsInterval," 5059 " jsInterval,"
5023 " cInterval," 5060 " cInterval,"
5024 " expected);" 5061 " expected);"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
5064 5101
5065 5102
5066 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) { 5103 void ThrowValue(const v8::FunctionCallbackInfo<v8::Value>& args) {
5067 ApiTestFuzzer::Fuzz(); 5104 ApiTestFuzzer::Fuzz();
5068 CHECK_EQ(1, args.Length()); 5105 CHECK_EQ(1, args.Length());
5069 args.GetIsolate()->ThrowException(args[0]); 5106 args.GetIsolate()->ThrowException(args[0]);
5070 } 5107 }
5071 5108
5072 5109
5073 THREADED_TEST(ThrowValues) { 5110 THREADED_TEST(ThrowValues) {
5074 v8::HandleScope scope(CcTest::isolate()); 5111 v8::Isolate* isolate = CcTest::isolate();
5112 v8::HandleScope scope(isolate);
5075 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5113 Local<ObjectTemplate> templ = ObjectTemplate::New();
5076 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(ThrowValue)); 5114 templ->Set(v8_str("Throw"), v8::FunctionTemplate::New(isolate, ThrowValue));
5077 LocalContext context(0, templ); 5115 LocalContext context(0, templ);
5078 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 5116 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
5079 "function Run(obj) {" 5117 "function Run(obj) {"
5080 " try {" 5118 " try {"
5081 " Throw(obj);" 5119 " Throw(obj);"
5082 " } catch (e) {" 5120 " } catch (e) {"
5083 " return e;" 5121 " return e;"
5084 " }" 5122 " }"
5085 " return 'no exception';" 5123 " return 'no exception';"
5086 "}" 5124 "}"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
5133 } 5171 }
5134 5172
5135 5173
5136 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) { 5174 void WithTryCatch(const v8::FunctionCallbackInfo<v8::Value>& args) {
5137 v8::TryCatch try_catch; 5175 v8::TryCatch try_catch;
5138 } 5176 }
5139 5177
5140 5178
5141 THREADED_TEST(TryCatchAndFinally) { 5179 THREADED_TEST(TryCatchAndFinally) {
5142 LocalContext context; 5180 LocalContext context;
5143 v8::HandleScope scope(context->GetIsolate()); 5181 v8::Isolate* isolate = context->GetIsolate();
5182 v8::HandleScope scope(isolate);
5144 context->Global()->Set( 5183 context->Global()->Set(
5145 v8_str("native_with_try_catch"), 5184 v8_str("native_with_try_catch"),
5146 v8::FunctionTemplate::New(WithTryCatch)->GetFunction()); 5185 v8::FunctionTemplate::New(isolate, WithTryCatch)->GetFunction());
5147 v8::TryCatch try_catch; 5186 v8::TryCatch try_catch;
5148 CHECK(!try_catch.HasCaught()); 5187 CHECK(!try_catch.HasCaught());
5149 CompileRun( 5188 CompileRun(
5150 "try {\n" 5189 "try {\n"
5151 " throw new Error('a');\n" 5190 " throw new Error('a');\n"
5152 "} finally {\n" 5191 "} finally {\n"
5153 " native_with_try_catch();\n" 5192 " native_with_try_catch();\n"
5154 "}\n"); 5193 "}\n");
5155 CHECK(try_catch.HasCaught()); 5194 CHECK(try_catch.HasCaught());
5156 } 5195 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5202 try_catch.ReThrow(); 5241 try_catch.ReThrow();
5203 } 5242 }
5204 5243
5205 5244
5206 // This test ensures that an outer TryCatch in the following situation: 5245 // This test ensures that an outer TryCatch in the following situation:
5207 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError 5246 // C++/TryCatch -> JS -> C++/TryCatch -> JS w/ SyntaxError
5208 // does not clobber the Message object generated for the inner TryCatch. 5247 // does not clobber the Message object generated for the inner TryCatch.
5209 // This exercises the ability of TryCatch.ReThrow() to restore the 5248 // This exercises the ability of TryCatch.ReThrow() to restore the
5210 // inner pending Message before throwing the exception again. 5249 // inner pending Message before throwing the exception again.
5211 TEST(TryCatchMixedNesting) { 5250 TEST(TryCatchMixedNesting) {
5212 v8::HandleScope scope(CcTest::isolate()); 5251 v8::Isolate* isolate = CcTest::isolate();
5252 v8::HandleScope scope(isolate);
5213 v8::V8::Initialize(); 5253 v8::V8::Initialize();
5214 v8::TryCatch try_catch; 5254 v8::TryCatch try_catch;
5215 Local<ObjectTemplate> templ = ObjectTemplate::New(); 5255 Local<ObjectTemplate> templ = ObjectTemplate::New();
5216 templ->Set(v8_str("TryCatchMixedNestingHelper"), 5256 templ->Set(v8_str("TryCatchMixedNestingHelper"),
5217 v8::FunctionTemplate::New(TryCatchMixedNestingHelper)); 5257 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper));
5218 LocalContext context(0, templ); 5258 LocalContext context(0, templ);
5219 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 5259 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
5220 TryCatchMixedNestingCheck(&try_catch); 5260 TryCatchMixedNestingCheck(&try_catch);
5221 } 5261 }
5222 5262
5223 5263
5224 THREADED_TEST(Equality) { 5264 THREADED_TEST(Equality) {
5225 LocalContext context; 5265 LocalContext context;
5226 v8::Isolate* isolate = context->GetIsolate(); 5266 v8::Isolate* isolate = context->GetIsolate();
5227 v8::HandleScope scope(context->GetIsolate()); 5267 v8::HandleScope scope(context->GetIsolate());
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
5710 const v8::PropertyCallbackInfo<v8::Value>& info) { 5750 const v8::PropertyCallbackInfo<v8::Value>& info) {
5711 // Set x on the prototype object and do not handle the get request. 5751 // Set x on the prototype object and do not handle the get request.
5712 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype(); 5752 v8::Handle<v8::Value> proto = info.Holder()->GetPrototype();
5713 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23)); 5753 proto.As<v8::Object>()->Set(v8_str("x"), v8::Integer::New(23));
5714 } 5754 }
5715 5755
5716 5756
5717 // This is a regression test for http://crbug.com/20104. Map 5757 // This is a regression test for http://crbug.com/20104. Map
5718 // transitions should not interfere with post interceptor lookup. 5758 // transitions should not interfere with post interceptor lookup.
5719 THREADED_TEST(NamedInterceptorMapTransitionRead) { 5759 THREADED_TEST(NamedInterceptorMapTransitionRead) {
5720 v8::HandleScope scope(CcTest::isolate()); 5760 v8::Isolate* isolate = CcTest::isolate();
5721 Local<v8::FunctionTemplate> function_template = v8::FunctionTemplate::New(); 5761 v8::HandleScope scope(isolate);
5762 Local<v8::FunctionTemplate> function_template =
5763 v8::FunctionTemplate::New(isolate);
5722 Local<v8::ObjectTemplate> instance_template 5764 Local<v8::ObjectTemplate> instance_template
5723 = function_template->InstanceTemplate(); 5765 = function_template->InstanceTemplate();
5724 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter); 5766 instance_template->SetNamedPropertyHandler(SetXOnPrototypeGetter);
5725 LocalContext context; 5767 LocalContext context;
5726 context->Global()->Set(v8_str("F"), function_template->GetFunction()); 5768 context->Global()->Set(v8_str("F"), function_template->GetFunction());
5727 // Create an instance of F and introduce a map transition for x. 5769 // Create an instance of F and introduce a map transition for x.
5728 CompileRun("var o = new F(); o.x = 23;"); 5770 CompileRun("var o = new F(); o.x = 23;");
5729 // Create an instance of F and invoke the getter. The result should be 23. 5771 // Create an instance of F and invoke the getter. The result should be 23.
5730 Local<Value> result = CompileRun("o = new F(); o.x"); 5772 Local<Value> result = CompileRun("o = new F(); o.x");
5731 CHECK_EQ(result->Int32Value(), 23); 5773 CHECK_EQ(result->Int32Value(), 23);
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
6167 " }" 6209 " }"
6168 " 'PASSED'" 6210 " 'PASSED'"
6169 "} catch(e) {" 6211 "} catch(e) {"
6170 " e" 6212 " e"
6171 "}"; 6213 "}";
6172 ExpectString(code, "PASSED"); 6214 ExpectString(code, "PASSED");
6173 } 6215 }
6174 6216
6175 6217
6176 THREADED_TEST(MultiContexts) { 6218 THREADED_TEST(MultiContexts) {
6177 v8::HandleScope scope(CcTest::isolate()); 6219 v8::Isolate* isolate = CcTest::isolate();
6220 v8::HandleScope scope(isolate);
6178 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New(); 6221 v8::Handle<ObjectTemplate> templ = ObjectTemplate::New();
6179 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(DummyCallHandler)); 6222 templ->Set(v8_str("dummy"), v8::FunctionTemplate::New(isolate,
6223 DummyCallHandler));
6180 6224
6181 Local<String> password = v8_str("Password"); 6225 Local<String> password = v8_str("Password");
6182 6226
6183 // Create an environment 6227 // Create an environment
6184 LocalContext context0(0, templ); 6228 LocalContext context0(0, templ);
6185 context0->SetSecurityToken(password); 6229 context0->SetSecurityToken(password);
6186 v8::Handle<v8::Object> global0 = context0->Global(); 6230 v8::Handle<v8::Object> global0 = context0->Global();
6187 global0->Set(v8_str("custom"), v8_num(1234)); 6231 global0->Set(v8_str("custom"), v8_num(1234));
6188 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value()); 6232 CHECK_EQ(1234, global0->Get(v8_str("custom"))->Int32Value());
6189 6233
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
6256 LocalContext env1; 6300 LocalContext env1;
6257 Local<Script> script1 = Script::Compile(source); 6301 Local<Script> script1 = Script::Compile(source);
6258 CHECK_EQ(8901.0, script1->Run()->NumberValue()); 6302 CHECK_EQ(8901.0, script1->Run()->NumberValue());
6259 } 6303 }
6260 6304
6261 6305
6262 THREADED_TEST(UndetectableObject) { 6306 THREADED_TEST(UndetectableObject) {
6263 LocalContext env; 6307 LocalContext env;
6264 v8::HandleScope scope(env->GetIsolate()); 6308 v8::HandleScope scope(env->GetIsolate());
6265 6309
6266 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 6310 Local<v8::FunctionTemplate> desc =
6311 v8::FunctionTemplate::New(env->GetIsolate());
6267 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6312 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6268 6313
6269 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6314 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6270 env->Global()->Set(v8_str("undetectable"), obj); 6315 env->Global()->Set(v8_str("undetectable"), obj);
6271 6316
6272 ExpectString("undetectable.toString()", "[object Object]"); 6317 ExpectString("undetectable.toString()", "[object Object]");
6273 ExpectString("typeof undetectable", "undefined"); 6318 ExpectString("typeof undetectable", "undefined");
6274 ExpectString("typeof(undetectable)", "undefined"); 6319 ExpectString("typeof(undetectable)", "undefined");
6275 ExpectBoolean("typeof undetectable == 'undefined'", true); 6320 ExpectBoolean("typeof undetectable == 'undefined'", true);
6276 ExpectBoolean("typeof undetectable == 'object'", false); 6321 ExpectBoolean("typeof undetectable == 'object'", false);
(...skipping 20 matching lines...) Expand all
6297 ExpectBoolean("undetectable===null", false); 6342 ExpectBoolean("undetectable===null", false);
6298 ExpectBoolean("null===undetectable", false); 6343 ExpectBoolean("null===undetectable", false);
6299 ExpectBoolean("undetectable===undefined", false); 6344 ExpectBoolean("undetectable===undefined", false);
6300 ExpectBoolean("undefined===undetectable", false); 6345 ExpectBoolean("undefined===undetectable", false);
6301 ExpectBoolean("undetectable===undetectable", true); 6346 ExpectBoolean("undetectable===undetectable", true);
6302 } 6347 }
6303 6348
6304 6349
6305 THREADED_TEST(VoidLiteral) { 6350 THREADED_TEST(VoidLiteral) {
6306 LocalContext env; 6351 LocalContext env;
6307 v8::HandleScope scope(env->GetIsolate()); 6352 v8::Isolate* isolate = env->GetIsolate();
6353 v8::HandleScope scope(isolate);
6308 6354
6309 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 6355 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
6310 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6356 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6311 6357
6312 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6358 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6313 env->Global()->Set(v8_str("undetectable"), obj); 6359 env->Global()->Set(v8_str("undetectable"), obj);
6314 6360
6315 ExpectBoolean("undefined == void 0", true); 6361 ExpectBoolean("undefined == void 0", true);
6316 ExpectBoolean("undetectable == void 0", true); 6362 ExpectBoolean("undetectable == void 0", true);
6317 ExpectBoolean("null == void 0", true); 6363 ExpectBoolean("null == void 0", true);
6318 ExpectBoolean("undefined === void 0", true); 6364 ExpectBoolean("undefined === void 0", true);
6319 ExpectBoolean("undetectable === void 0", false); 6365 ExpectBoolean("undetectable === void 0", false);
(...skipping 20 matching lines...) Expand all
6340 " } catch(e) {" 6386 " } catch(e) {"
6341 " return e.toString();" 6387 " return e.toString();"
6342 " }" 6388 " }"
6343 "})()", 6389 "})()",
6344 "ReferenceError: x is not defined"); 6390 "ReferenceError: x is not defined");
6345 } 6391 }
6346 6392
6347 6393
6348 THREADED_TEST(ExtensibleOnUndetectable) { 6394 THREADED_TEST(ExtensibleOnUndetectable) {
6349 LocalContext env; 6395 LocalContext env;
6350 v8::HandleScope scope(env->GetIsolate()); 6396 v8::Isolate* isolate = env->GetIsolate();
6397 v8::HandleScope scope(isolate);
6351 6398
6352 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(); 6399 Local<v8::FunctionTemplate> desc = v8::FunctionTemplate::New(isolate);
6353 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable 6400 desc->InstanceTemplate()->MarkAsUndetectable(); // undetectable
6354 6401
6355 Local<v8::Object> obj = desc->GetFunction()->NewInstance(); 6402 Local<v8::Object> obj = desc->GetFunction()->NewInstance();
6356 env->Global()->Set(v8_str("undetectable"), obj); 6403 env->Global()->Set(v8_str("undetectable"), obj);
6357 6404
6358 Local<String> source = v8_str("undetectable.x = 42;" 6405 Local<String> source = v8_str("undetectable.x = 42;"
6359 "undetectable.x"); 6406 "undetectable.x");
6360 6407
6361 Local<Script> script = Script::Compile(source); 6408 Local<Script> script = Script::Compile(source);
6362 6409
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
6476 const v8::FunctionCallbackInfo<v8::Value>& args) { 6523 const v8::FunctionCallbackInfo<v8::Value>& args) {
6477 ApiTestFuzzer::Fuzz(); 6524 ApiTestFuzzer::Fuzz();
6478 } 6525 }
6479 6526
6480 6527
6481 THREADED_TEST(GlobalObjectTemplate) { 6528 THREADED_TEST(GlobalObjectTemplate) {
6482 v8::Isolate* isolate = CcTest::isolate(); 6529 v8::Isolate* isolate = CcTest::isolate();
6483 v8::HandleScope handle_scope(isolate); 6530 v8::HandleScope handle_scope(isolate);
6484 Local<ObjectTemplate> global_template = ObjectTemplate::New(); 6531 Local<ObjectTemplate> global_template = ObjectTemplate::New();
6485 global_template->Set(v8_str("JSNI_Log"), 6532 global_template->Set(v8_str("JSNI_Log"),
6486 v8::FunctionTemplate::New(HandleLogDelegator)); 6533 v8::FunctionTemplate::New(isolate, HandleLogDelegator));
6487 v8::Local<Context> context = Context::New(isolate, 0, global_template); 6534 v8::Local<Context> context = Context::New(isolate, 0, global_template);
6488 Context::Scope context_scope(context); 6535 Context::Scope context_scope(context);
6489 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run(); 6536 Script::Compile(v8_str("JSNI_Log('LOG')"))->Run();
6490 } 6537 }
6491 6538
6492 6539
6493 static const char* kSimpleExtensionSource = 6540 static const char* kSimpleExtensionSource =
6494 "function Foo() {" 6541 "function Foo() {"
6495 " return 4;" 6542 " return 4;"
6496 "}"; 6543 "}";
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
6709 public: 6756 public:
6710 NativeFunctionExtension(const char* name, 6757 NativeFunctionExtension(const char* name,
6711 const char* source, 6758 const char* source,
6712 v8::FunctionCallback fun = &Echo) 6759 v8::FunctionCallback fun = &Echo)
6713 : Extension(name, source), 6760 : Extension(name, source),
6714 function_(fun) { } 6761 function_(fun) { }
6715 6762
6716 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( 6763 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
6717 v8::Isolate* isolate, 6764 v8::Isolate* isolate,
6718 v8::Handle<v8::String> name) { 6765 v8::Handle<v8::String> name) {
6719 return v8::FunctionTemplate::New(function_); 6766 return v8::FunctionTemplate::New(isolate, function_);
6720 } 6767 }
6721 6768
6722 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) { 6769 static void Echo(const v8::FunctionCallbackInfo<v8::Value>& args) {
6723 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]); 6770 if (args.Length() >= 1) args.GetReturnValue().Set(args[0]);
6724 } 6771 }
6725 private: 6772 private:
6726 v8::FunctionCallback function_; 6773 v8::FunctionCallback function_;
6727 }; 6774 };
6728 6775
6729 6776
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
6839 v8::Isolate* isolate, 6886 v8::Isolate* isolate,
6840 v8::Handle<String> name); 6887 v8::Handle<String> name);
6841 }; 6888 };
6842 6889
6843 6890
6844 static int lookup_count = 0; 6891 static int lookup_count = 0;
6845 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate( 6892 v8::Handle<v8::FunctionTemplate> FunctionExtension::GetNativeFunctionTemplate(
6846 v8::Isolate* isolate, v8::Handle<String> name) { 6893 v8::Isolate* isolate, v8::Handle<String> name) {
6847 lookup_count++; 6894 lookup_count++;
6848 if (name->Equals(v8_str("A"))) { 6895 if (name->Equals(v8_str("A"))) {
6849 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(8)); 6896 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(8));
6850 } else if (name->Equals(v8_str("B"))) { 6897 } else if (name->Equals(v8_str("B"))) {
6851 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(7)); 6898 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(7));
6852 } else if (name->Equals(v8_str("C"))) { 6899 } else if (name->Equals(v8_str("C"))) {
6853 return v8::FunctionTemplate::New(CallFun, v8::Integer::New(6)); 6900 return v8::FunctionTemplate::New(isolate, CallFun, v8::Integer::New(6));
6854 } else { 6901 } else {
6855 return v8::Handle<v8::FunctionTemplate>(); 6902 return v8::Handle<v8::FunctionTemplate>();
6856 } 6903 }
6857 } 6904 }
6858 6905
6859 6906
6860 THREADED_TEST(FunctionLookup) { 6907 THREADED_TEST(FunctionLookup) {
6861 v8::RegisterExtension(new FunctionExtension()); 6908 v8::RegisterExtension(new FunctionExtension());
6862 v8::HandleScope handle_scope(CcTest::isolate()); 6909 v8::HandleScope handle_scope(CcTest::isolate());
6863 static const char* exts[1] = { "functiontest" }; 6910 static const char* exts[1] = { "functiontest" };
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
7197 CHECK_EQ(v8::Integer::New(1, isolate), args[0]); 7244 CHECK_EQ(v8::Integer::New(1, isolate), args[0]);
7198 CHECK_EQ(v8::Integer::New(2, isolate), args[1]); 7245 CHECK_EQ(v8::Integer::New(2, isolate), args[1]);
7199 CHECK_EQ(v8::Integer::New(3, isolate), args[2]); 7246 CHECK_EQ(v8::Integer::New(3, isolate), args[2]);
7200 CHECK_EQ(v8::Undefined(isolate), args[3]); 7247 CHECK_EQ(v8::Undefined(isolate), args[3]);
7201 v8::HandleScope scope(args.GetIsolate()); 7248 v8::HandleScope scope(args.GetIsolate());
7202 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 7249 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
7203 } 7250 }
7204 7251
7205 7252
7206 THREADED_TEST(Arguments) { 7253 THREADED_TEST(Arguments) {
7207 v8::HandleScope scope(CcTest::isolate()); 7254 v8::Isolate* isolate = CcTest::isolate();
7255 v8::HandleScope scope(isolate);
7208 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New(); 7256 v8::Handle<v8::ObjectTemplate> global = ObjectTemplate::New();
7209 global->Set(v8_str("f"), v8::FunctionTemplate::New(ArgumentsTestCallback)); 7257 global->Set(v8_str("f"),
7258 v8::FunctionTemplate::New(isolate, ArgumentsTestCallback));
7210 LocalContext context(NULL, global); 7259 LocalContext context(NULL, global);
7211 args_fun = context->Global()->Get(v8_str("f")).As<Function>(); 7260 args_fun = context->Global()->Get(v8_str("f")).As<Function>();
7212 v8_compile("f(1, 2, 3)")->Run(); 7261 v8_compile("f(1, 2, 3)")->Run();
7213 } 7262 }
7214 7263
7215 7264
7216 static void NoBlockGetterX(Local<String> name, 7265 static void NoBlockGetterX(Local<String> name,
7217 const v8::PropertyCallbackInfo<v8::Value>&) { 7266 const v8::PropertyCallbackInfo<v8::Value>&) {
7218 } 7267 }
7219 7268
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
8055 LocalContext context; 8104 LocalContext context;
8056 v8::Handle<v8::Object> holder = obj->NewInstance(); 8105 v8::Handle<v8::Object> holder = obj->NewInstance();
8057 context->Global()->Set(v8_str("holder"), holder); 8106 context->Global()->Set(v8_str("holder"), holder);
8058 v8::Handle<Value> result = CompileRun( 8107 v8::Handle<Value> result = CompileRun(
8059 "holder.y = 11; holder.y = 12; holder.y"); 8108 "holder.y = 11; holder.y = 12; holder.y");
8060 CHECK_EQ(12, result->Uint32Value()); 8109 CHECK_EQ(12, result->Uint32Value());
8061 } 8110 }
8062 8111
8063 8112
8064 THREADED_TEST(TypeSwitch) { 8113 THREADED_TEST(TypeSwitch) {
8065 v8::HandleScope scope(CcTest::isolate()); 8114 v8::Isolate* isolate = CcTest::isolate();
8066 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(); 8115 v8::HandleScope scope(isolate);
8067 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(); 8116 v8::Handle<v8::FunctionTemplate> templ1 = v8::FunctionTemplate::New(isolate);
8068 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(); 8117 v8::Handle<v8::FunctionTemplate> templ2 = v8::FunctionTemplate::New(isolate);
8118 v8::Handle<v8::FunctionTemplate> templ3 = v8::FunctionTemplate::New(isolate);
8069 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 }; 8119 v8::Handle<v8::FunctionTemplate> templs[3] = { templ1, templ2, templ3 };
8070 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs); 8120 v8::Handle<v8::TypeSwitch> type_switch = v8::TypeSwitch::New(3, templs);
8071 LocalContext context; 8121 LocalContext context;
8072 v8::Handle<v8::Object> obj0 = v8::Object::New(); 8122 v8::Handle<v8::Object> obj0 = v8::Object::New();
8073 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance(); 8123 v8::Handle<v8::Object> obj1 = templ1->GetFunction()->NewInstance();
8074 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance(); 8124 v8::Handle<v8::Object> obj2 = templ2->GetFunction()->NewInstance();
8075 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance(); 8125 v8::Handle<v8::Object> obj3 = templ3->GetFunction()->NewInstance();
8076 for (int i = 0; i < 10; i++) { 8126 for (int i = 0; i < 10; i++) {
8077 CHECK_EQ(0, type_switch->match(obj0)); 8127 CHECK_EQ(0, type_switch->match(obj0));
8078 CHECK_EQ(1, type_switch->match(obj1)); 8128 CHECK_EQ(1, type_switch->match(obj1));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
8136 v8::Handle<Value>) { 8186 v8::Handle<Value>) {
8137 report_count++; 8187 report_count++;
8138 } 8188 }
8139 8189
8140 8190
8141 // Counts uncaught exceptions, but other tests running in parallel 8191 // Counts uncaught exceptions, but other tests running in parallel
8142 // also have uncaught exceptions. 8192 // also have uncaught exceptions.
8143 TEST(ApiUncaughtException) { 8193 TEST(ApiUncaughtException) {
8144 report_count = 0; 8194 report_count = 0;
8145 LocalContext env; 8195 LocalContext env;
8146 v8::HandleScope scope(env->GetIsolate()); 8196 v8::Isolate* isolate = env->GetIsolate();
8197 v8::HandleScope scope(isolate);
8147 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener); 8198 v8::V8::AddMessageListener(ApiUncaughtExceptionTestListener);
8148 8199
8149 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 8200 Local<v8::FunctionTemplate> fun =
8201 v8::FunctionTemplate::New(isolate, TroubleCallback);
8150 v8::Local<v8::Object> global = env->Global(); 8202 v8::Local<v8::Object> global = env->Global();
8151 global->Set(v8_str("trouble"), fun->GetFunction()); 8203 global->Set(v8_str("trouble"), fun->GetFunction());
8152 8204
8153 Script::Compile(v8_str("function trouble_callee() {" 8205 Script::Compile(v8_str("function trouble_callee() {"
8154 " var x = null;" 8206 " var x = null;"
8155 " return x.foo;" 8207 " return x.foo;"
8156 "};" 8208 "};"
8157 "function trouble_caller() {" 8209 "function trouble_caller() {"
8158 " trouble();" 8210 " trouble();"
8159 "};"))->Run(); 8211 "};"))->Run();
(...skipping 16 matching lines...) Expand all
8176 v8::String::Utf8Value name(message->GetScriptResourceName()); 8228 v8::String::Utf8Value name(message->GetScriptResourceName());
8177 CHECK_EQ(script_resource_name, *name); 8229 CHECK_EQ(script_resource_name, *name);
8178 CHECK_EQ(3, message->GetLineNumber()); 8230 CHECK_EQ(3, message->GetLineNumber());
8179 v8::String::Utf8Value source_line(message->GetSourceLine()); 8231 v8::String::Utf8Value source_line(message->GetSourceLine());
8180 CHECK_EQ(" new o.foo();", *source_line); 8232 CHECK_EQ(" new o.foo();", *source_line);
8181 } 8233 }
8182 8234
8183 8235
8184 TEST(ExceptionInNativeScript) { 8236 TEST(ExceptionInNativeScript) {
8185 LocalContext env; 8237 LocalContext env;
8186 v8::HandleScope scope(env->GetIsolate()); 8238 v8::Isolate* isolate = env->GetIsolate();
8239 v8::HandleScope scope(isolate);
8187 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); 8240 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener);
8188 8241
8189 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); 8242 Local<v8::FunctionTemplate> fun =
8243 v8::FunctionTemplate::New(isolate, TroubleCallback);
8190 v8::Local<v8::Object> global = env->Global(); 8244 v8::Local<v8::Object> global = env->Global();
8191 global->Set(v8_str("trouble"), fun->GetFunction()); 8245 global->Set(v8_str("trouble"), fun->GetFunction());
8192 8246
8193 Script::Compile( 8247 Script::Compile(
8194 v8_str( 8248 v8_str(
8195 "function trouble() {\n" 8249 "function trouble() {\n"
8196 " var o = {};\n" 8250 " var o = {};\n"
8197 " new o.foo();\n" 8251 " new o.foo();\n"
8198 "};"), 8252 "};"),
8199 v8::String::NewFromUtf8(env->GetIsolate(), script_resource_name))->Run(); 8253 v8::String::NewFromUtf8(isolate, script_resource_name))->Run();
8200 Local<Value> trouble = global->Get(v8_str("trouble")); 8254 Local<Value> trouble = global->Get(v8_str("trouble"));
8201 CHECK(trouble->IsFunction()); 8255 CHECK(trouble->IsFunction());
8202 Function::Cast(*trouble)->Call(global, 0, NULL); 8256 Function::Cast(*trouble)->Call(global, 0, NULL);
8203 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); 8257 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener);
8204 } 8258 }
8205 8259
8206 8260
8207 TEST(CompilationErrorUsingTryCatchHandler) { 8261 TEST(CompilationErrorUsingTryCatchHandler) {
8208 LocalContext env; 8262 LocalContext env;
8209 v8::HandleScope scope(env->GetIsolate()); 8263 v8::HandleScope scope(env->GetIsolate());
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
8762 // Add an accessor accessible by cross-domain JS code. 8816 // Add an accessor accessible by cross-domain JS code.
8763 global_template->SetAccessor( 8817 global_template->SetAccessor(
8764 v8_str("accessible_prop"), 8818 v8_str("accessible_prop"),
8765 EchoGetter, EchoSetter, 8819 EchoGetter, EchoSetter,
8766 v8::Handle<Value>(), 8820 v8::Handle<Value>(),
8767 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 8821 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8768 8822
8769 8823
8770 global_template->SetAccessorProperty( 8824 global_template->SetAccessorProperty(
8771 v8_str("accessible_js_prop"), 8825 v8_str("accessible_js_prop"),
8772 v8::FunctionTemplate::New(EchoGetter), 8826 v8::FunctionTemplate::New(isolate, EchoGetter),
8773 v8::FunctionTemplate::New(EchoSetter), 8827 v8::FunctionTemplate::New(isolate, EchoSetter),
8774 v8::None, 8828 v8::None,
8775 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE)); 8829 v8::AccessControl(v8::ALL_CAN_READ | v8::ALL_CAN_WRITE));
8776 8830
8777 // Add an accessor that is not accessible by cross-domain JS code. 8831 // Add an accessor that is not accessible by cross-domain JS code.
8778 global_template->SetAccessor(v8_str("blocked_prop"), 8832 global_template->SetAccessor(v8_str("blocked_prop"),
8779 UnreachableGetter, UnreachableSetter, 8833 UnreachableGetter, UnreachableSetter,
8780 v8::Handle<Value>(), 8834 v8::Handle<Value>(),
8781 v8::DEFAULT); 8835 v8::DEFAULT);
8782 8836
8783 global_template->SetAccessorProperty( 8837 global_template->SetAccessorProperty(
8784 v8_str("blocked_js_prop"), 8838 v8_str("blocked_js_prop"),
8785 v8::FunctionTemplate::New(UnreachableFunction), 8839 v8::FunctionTemplate::New(isolate, UnreachableFunction),
8786 v8::FunctionTemplate::New(UnreachableFunction), 8840 v8::FunctionTemplate::New(isolate, UnreachableFunction),
8787 v8::None, 8841 v8::None,
8788 v8::DEFAULT); 8842 v8::DEFAULT);
8789 8843
8790 // Create an environment 8844 // Create an environment
8791 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template); 8845 v8::Local<Context> context0 = Context::New(isolate, NULL, global_template);
8792 context0->Enter(); 8846 context0->Enter();
8793 8847
8794 v8::Handle<v8::Object> global0 = context0->Global(); 8848 v8::Handle<v8::Object> global0 = context0->Global();
8795 8849
8796 // Define a property with JS getter and setter. 8850 // Define a property with JS getter and setter.
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9209 static void ConstTenGetter(Local<String> name, 9263 static void ConstTenGetter(Local<String> name,
9210 const v8::PropertyCallbackInfo<v8::Value>& info) { 9264 const v8::PropertyCallbackInfo<v8::Value>& info) {
9211 info.GetReturnValue().Set(v8_num(10)); 9265 info.GetReturnValue().Set(v8_num(10));
9212 } 9266 }
9213 9267
9214 9268
9215 THREADED_TEST(CrossDomainAccessors) { 9269 THREADED_TEST(CrossDomainAccessors) {
9216 v8::Isolate* isolate = CcTest::isolate(); 9270 v8::Isolate* isolate = CcTest::isolate();
9217 v8::HandleScope handle_scope(isolate); 9271 v8::HandleScope handle_scope(isolate);
9218 9272
9219 v8::Handle<v8::FunctionTemplate> func_template = v8::FunctionTemplate::New(); 9273 v8::Handle<v8::FunctionTemplate> func_template =
9274 v8::FunctionTemplate::New(isolate);
9220 9275
9221 v8::Handle<v8::ObjectTemplate> global_template = 9276 v8::Handle<v8::ObjectTemplate> global_template =
9222 func_template->InstanceTemplate(); 9277 func_template->InstanceTemplate();
9223 9278
9224 v8::Handle<v8::ObjectTemplate> proto_template = 9279 v8::Handle<v8::ObjectTemplate> proto_template =
9225 func_template->PrototypeTemplate(); 9280 func_template->PrototypeTemplate();
9226 9281
9227 // Add an accessor to proto that's accessible by cross-domain JS code. 9282 // Add an accessor to proto that's accessible by cross-domain JS code.
9228 proto_template->SetAccessor(v8_str("accessible"), 9283 proto_template->SetAccessor(v8_str("accessible"),
9229 ConstTenGetter, 0, 9284 ConstTenGetter, 0,
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
9575 9630
9576 static void InstanceFunctionCallback( 9631 static void InstanceFunctionCallback(
9577 const v8::FunctionCallbackInfo<v8::Value>& args) { 9632 const v8::FunctionCallbackInfo<v8::Value>& args) {
9578 ApiTestFuzzer::Fuzz(); 9633 ApiTestFuzzer::Fuzz();
9579 args.GetReturnValue().Set(v8_num(12)); 9634 args.GetReturnValue().Set(v8_num(12));
9580 } 9635 }
9581 9636
9582 9637
9583 THREADED_TEST(InstanceProperties) { 9638 THREADED_TEST(InstanceProperties) {
9584 LocalContext context; 9639 LocalContext context;
9585 v8::HandleScope handle_scope(context->GetIsolate()); 9640 v8::Isolate* isolate = context->GetIsolate();
9641 v8::HandleScope handle_scope(isolate);
9586 9642
9587 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9643 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9588 Local<ObjectTemplate> instance = t->InstanceTemplate(); 9644 Local<ObjectTemplate> instance = t->InstanceTemplate();
9589 9645
9590 instance->Set(v8_str("x"), v8_num(42)); 9646 instance->Set(v8_str("x"), v8_num(42));
9591 instance->Set(v8_str("f"), 9647 instance->Set(v8_str("f"),
9592 v8::FunctionTemplate::New(InstanceFunctionCallback)); 9648 v8::FunctionTemplate::New(isolate, InstanceFunctionCallback));
9593 9649
9594 Local<Value> o = t->GetFunction()->NewInstance(); 9650 Local<Value> o = t->GetFunction()->NewInstance();
9595 9651
9596 context->Global()->Set(v8_str("i"), o); 9652 context->Global()->Set(v8_str("i"), o);
9597 Local<Value> value = Script::Compile(v8_str("i.x"))->Run(); 9653 Local<Value> value = Script::Compile(v8_str("i.x"))->Run();
9598 CHECK_EQ(42, value->Int32Value()); 9654 CHECK_EQ(42, value->Int32Value());
9599 9655
9600 value = Script::Compile(v8_str("i.f()"))->Run(); 9656 value = Script::Compile(v8_str("i.f()"))->Run();
9601 CHECK_EQ(12, value->Int32Value()); 9657 CHECK_EQ(12, value->Int32Value());
9602 } 9658 }
9603 9659
9604 9660
9605 static void GlobalObjectInstancePropertiesGet( 9661 static void GlobalObjectInstancePropertiesGet(
9606 Local<String> key, 9662 Local<String> key,
9607 const v8::PropertyCallbackInfo<v8::Value>&) { 9663 const v8::PropertyCallbackInfo<v8::Value>&) {
9608 ApiTestFuzzer::Fuzz(); 9664 ApiTestFuzzer::Fuzz();
9609 } 9665 }
9610 9666
9611 9667
9612 THREADED_TEST(GlobalObjectInstanceProperties) { 9668 THREADED_TEST(GlobalObjectInstanceProperties) {
9613 v8::HandleScope handle_scope(CcTest::isolate()); 9669 v8::Isolate* isolate = CcTest::isolate();
9670 v8::HandleScope handle_scope(isolate);
9614 9671
9615 Local<Value> global_object; 9672 Local<Value> global_object;
9616 9673
9617 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9674 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9618 t->InstanceTemplate()->SetNamedPropertyHandler( 9675 t->InstanceTemplate()->SetNamedPropertyHandler(
9619 GlobalObjectInstancePropertiesGet); 9676 GlobalObjectInstancePropertiesGet);
9620 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 9677 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9621 instance_template->Set(v8_str("x"), v8_num(42)); 9678 instance_template->Set(v8_str("x"), v8_num(42));
9622 instance_template->Set(v8_str("f"), 9679 instance_template->Set(v8_str("f"),
9623 v8::FunctionTemplate::New(InstanceFunctionCallback)); 9680 v8::FunctionTemplate::New(isolate,
9681 InstanceFunctionCallback));
9624 9682
9625 // The script to check how Crankshaft compiles missing global function 9683 // The script to check how Crankshaft compiles missing global function
9626 // invocations. function g is not defined and should throw on call. 9684 // invocations. function g is not defined and should throw on call.
9627 const char* script = 9685 const char* script =
9628 "function wrapper(call) {" 9686 "function wrapper(call) {"
9629 " var x = 0, y = 1;" 9687 " var x = 0, y = 1;"
9630 " for (var i = 0; i < 1000; i++) {" 9688 " for (var i = 0; i < 1000; i++) {"
9631 " x += i * 100;" 9689 " x += i * 100;"
9632 " y += i * 100;" 9690 " y += i * 100;"
9633 " }" 9691 " }"
(...skipping 25 matching lines...) Expand all
9659 CHECK_EQ(42, value->Int32Value()); 9717 CHECK_EQ(42, value->Int32Value());
9660 value = Script::Compile(v8_str("f()"))->Run(); 9718 value = Script::Compile(v8_str("f()"))->Run();
9661 CHECK_EQ(12, value->Int32Value()); 9719 CHECK_EQ(12, value->Int32Value());
9662 value = Script::Compile(v8_str(script))->Run(); 9720 value = Script::Compile(v8_str(script))->Run();
9663 CHECK_EQ(1, value->Int32Value()); 9721 CHECK_EQ(1, value->Int32Value());
9664 } 9722 }
9665 } 9723 }
9666 9724
9667 9725
9668 THREADED_TEST(CallKnownGlobalReceiver) { 9726 THREADED_TEST(CallKnownGlobalReceiver) {
9669 v8::HandleScope handle_scope(CcTest::isolate()); 9727 v8::Isolate* isolate = CcTest::isolate();
9728 v8::HandleScope handle_scope(isolate);
9670 9729
9671 Local<Value> global_object; 9730 Local<Value> global_object;
9672 9731
9673 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9732 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9674 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 9733 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
9675 9734
9676 // The script to check that we leave global object not 9735 // The script to check that we leave global object not
9677 // global object proxy on stack when we deoptimize from inside 9736 // global object proxy on stack when we deoptimize from inside
9678 // arguments evaluation. 9737 // arguments evaluation.
9679 // To provoke error we need to both force deoptimization 9738 // To provoke error we need to both force deoptimization
9680 // from arguments evaluation and to force CallIC to take 9739 // from arguments evaluation and to force CallIC to take
9681 // CallIC_Miss code path that can't cope with global proxy. 9740 // CallIC_Miss code path that can't cope with global proxy.
9682 const char* script = 9741 const char* script =
9683 "function bar(x, y) { try { } finally { } }" 9742 "function bar(x, y) { try { } finally { } }"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
9738 } 9797 }
9739 9798
9740 9799
9741 static void ShadowNamedGet(Local<String> key, 9800 static void ShadowNamedGet(Local<String> key,
9742 const v8::PropertyCallbackInfo<v8::Value>&) { 9801 const v8::PropertyCallbackInfo<v8::Value>&) {
9743 } 9802 }
9744 9803
9745 9804
9746 THREADED_TEST(ShadowObject) { 9805 THREADED_TEST(ShadowObject) {
9747 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0; 9806 shadow_y = shadow_y_setter_call_count = shadow_y_getter_call_count = 0;
9748 v8::HandleScope handle_scope(CcTest::isolate()); 9807 v8::Isolate* isolate = CcTest::isolate();
9808 v8::HandleScope handle_scope(isolate);
9749 9809
9750 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New(); 9810 Local<ObjectTemplate> global_template = v8::ObjectTemplate::New();
9751 LocalContext context(NULL, global_template); 9811 LocalContext context(NULL, global_template);
9752 9812
9753 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 9813 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
9754 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet); 9814 t->InstanceTemplate()->SetNamedPropertyHandler(ShadowNamedGet);
9755 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet); 9815 t->InstanceTemplate()->SetIndexedPropertyHandler(ShadowIndexedGet);
9756 Local<ObjectTemplate> proto = t->PrototypeTemplate(); 9816 Local<ObjectTemplate> proto = t->PrototypeTemplate();
9757 Local<ObjectTemplate> instance = t->InstanceTemplate(); 9817 Local<ObjectTemplate> instance = t->InstanceTemplate();
9758 9818
9759 proto->Set(v8_str("f"), 9819 proto->Set(v8_str("f"),
9760 v8::FunctionTemplate::New(ShadowFunctionCallback, Local<Value>())); 9820 v8::FunctionTemplate::New(isolate,
9821 ShadowFunctionCallback,
9822 Local<Value>()));
9761 proto->Set(v8_str("x"), v8_num(12)); 9823 proto->Set(v8_str("x"), v8_num(12));
9762 9824
9763 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter); 9825 instance->SetAccessor(v8_str("y"), ShadowYGetter, ShadowYSetter);
9764 9826
9765 Local<Value> o = t->GetFunction()->NewInstance(); 9827 Local<Value> o = t->GetFunction()->NewInstance();
9766 context->Global()->Set(v8_str("__proto__"), o); 9828 context->Global()->Set(v8_str("__proto__"), o);
9767 9829
9768 Local<Value> value = 9830 Local<Value> value =
9769 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run(); 9831 Script::Compile(v8_str("this.propertyIsEnumerable(0)"))->Run();
9770 CHECK(value->IsBoolean()); 9832 CHECK(value->IsBoolean());
9771 CHECK(!value->BooleanValue()); 9833 CHECK(!value->BooleanValue());
9772 9834
9773 value = Script::Compile(v8_str("x"))->Run(); 9835 value = Script::Compile(v8_str("x"))->Run();
9774 CHECK_EQ(12, value->Int32Value()); 9836 CHECK_EQ(12, value->Int32Value());
9775 9837
9776 value = Script::Compile(v8_str("f()"))->Run(); 9838 value = Script::Compile(v8_str("f()"))->Run();
9777 CHECK_EQ(42, value->Int32Value()); 9839 CHECK_EQ(42, value->Int32Value());
9778 9840
9779 Script::Compile(v8_str("y = 43"))->Run(); 9841 Script::Compile(v8_str("y = 43"))->Run();
9780 CHECK_EQ(1, shadow_y_setter_call_count); 9842 CHECK_EQ(1, shadow_y_setter_call_count);
9781 value = Script::Compile(v8_str("y"))->Run(); 9843 value = Script::Compile(v8_str("y"))->Run();
9782 CHECK_EQ(1, shadow_y_getter_call_count); 9844 CHECK_EQ(1, shadow_y_getter_call_count);
9783 CHECK_EQ(42, value->Int32Value()); 9845 CHECK_EQ(42, value->Int32Value());
9784 } 9846 }
9785 9847
9786 9848
9787 THREADED_TEST(HiddenPrototype) { 9849 THREADED_TEST(HiddenPrototype) {
9788 LocalContext context; 9850 LocalContext context;
9789 v8::HandleScope handle_scope(context->GetIsolate()); 9851 v8::Isolate* isolate = context->GetIsolate();
9852 v8::HandleScope handle_scope(isolate);
9790 9853
9791 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 9854 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
9792 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 9855 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9793 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 9856 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9794 t1->SetHiddenPrototype(true); 9857 t1->SetHiddenPrototype(true);
9795 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 9858 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
9796 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 9859 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9797 t2->SetHiddenPrototype(true); 9860 t2->SetHiddenPrototype(true);
9798 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 9861 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
9799 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 9862 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
9800 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); 9863 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3));
9801 9864
9802 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); 9865 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
9803 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 9866 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
9804 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 9867 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
9805 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 9868 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
9806 9869
9807 // Setting the prototype on an object skips hidden prototypes. 9870 // Setting the prototype on an object skips hidden prototypes.
9808 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 9871 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value());
9809 o0->Set(v8_str("__proto__"), o1); 9872 o0->Set(v8_str("__proto__"), o1);
(...skipping 13 matching lines...) Expand all
9823 // which is o3. Therefore, z should not be defined on the prototype 9886 // which is o3. Therefore, z should not be defined on the prototype
9824 // object. 9887 // object.
9825 Local<Value> proto = o0->Get(v8_str("__proto__")); 9888 Local<Value> proto = o0->Get(v8_str("__proto__"));
9826 CHECK(proto->IsObject()); 9889 CHECK(proto->IsObject());
9827 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined()); 9890 CHECK(proto.As<v8::Object>()->Get(v8_str("z"))->IsUndefined());
9828 } 9891 }
9829 9892
9830 9893
9831 THREADED_TEST(HiddenPrototypeSet) { 9894 THREADED_TEST(HiddenPrototypeSet) {
9832 LocalContext context; 9895 LocalContext context;
9833 v8::HandleScope handle_scope(context->GetIsolate()); 9896 v8::Isolate* isolate = context->GetIsolate();
9897 v8::HandleScope handle_scope(isolate);
9834 9898
9835 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(); 9899 Local<v8::FunctionTemplate> ot = v8::FunctionTemplate::New(isolate);
9836 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(); 9900 Local<v8::FunctionTemplate> ht = v8::FunctionTemplate::New(isolate);
9837 ht->SetHiddenPrototype(true); 9901 ht->SetHiddenPrototype(true);
9838 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(); 9902 Local<v8::FunctionTemplate> pt = v8::FunctionTemplate::New(isolate);
9839 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 9903 ht->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9840 9904
9841 Local<v8::Object> o = ot->GetFunction()->NewInstance(); 9905 Local<v8::Object> o = ot->GetFunction()->NewInstance();
9842 Local<v8::Object> h = ht->GetFunction()->NewInstance(); 9906 Local<v8::Object> h = ht->GetFunction()->NewInstance();
9843 Local<v8::Object> p = pt->GetFunction()->NewInstance(); 9907 Local<v8::Object> p = pt->GetFunction()->NewInstance();
9844 o->Set(v8_str("__proto__"), h); 9908 o->Set(v8_str("__proto__"), h);
9845 h->Set(v8_str("__proto__"), p); 9909 h->Set(v8_str("__proto__"), p);
9846 9910
9847 // Setting a property that exists on the hidden prototype goes there. 9911 // Setting a property that exists on the hidden prototype goes there.
9848 o->Set(v8_str("x"), v8_num(7)); 9912 o->Set(v8_str("x"), v8_num(7));
(...skipping 18 matching lines...) Expand all
9867 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value()); 9931 CHECK_EQ(8, h->Get(v8_str("z"))->Int32Value());
9868 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value()); 9932 CHECK_EQ(8, p->Get(v8_str("z"))->Int32Value());
9869 } 9933 }
9870 9934
9871 9935
9872 // Regression test for issue 2457. 9936 // Regression test for issue 2457.
9873 THREADED_TEST(HiddenPrototypeIdentityHash) { 9937 THREADED_TEST(HiddenPrototypeIdentityHash) {
9874 LocalContext context; 9938 LocalContext context;
9875 v8::HandleScope handle_scope(context->GetIsolate()); 9939 v8::HandleScope handle_scope(context->GetIsolate());
9876 9940
9877 Handle<FunctionTemplate> t = FunctionTemplate::New(); 9941 Handle<FunctionTemplate> t = FunctionTemplate::New(context->GetIsolate());
9878 t->SetHiddenPrototype(true); 9942 t->SetHiddenPrototype(true);
9879 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75)); 9943 t->InstanceTemplate()->Set(v8_str("foo"), v8_num(75));
9880 Handle<Object> p = t->GetFunction()->NewInstance(); 9944 Handle<Object> p = t->GetFunction()->NewInstance();
9881 Handle<Object> o = Object::New(); 9945 Handle<Object> o = Object::New();
9882 o->SetPrototype(p); 9946 o->SetPrototype(p);
9883 9947
9884 int hash = o->GetIdentityHash(); 9948 int hash = o->GetIdentityHash();
9885 USE(hash); 9949 USE(hash);
9886 o->Set(v8_str("foo"), v8_num(42)); 9950 o->Set(v8_str("foo"), v8_num(42));
9887 ASSERT_EQ(hash, o->GetIdentityHash()); 9951 ASSERT_EQ(hash, o->GetIdentityHash());
9888 } 9952 }
9889 9953
9890 9954
9891 THREADED_TEST(SetPrototype) { 9955 THREADED_TEST(SetPrototype) {
9892 LocalContext context; 9956 LocalContext context;
9893 v8::HandleScope handle_scope(context->GetIsolate()); 9957 v8::Isolate* isolate = context->GetIsolate();
9958 v8::HandleScope handle_scope(isolate);
9894 9959
9895 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(); 9960 Local<v8::FunctionTemplate> t0 = v8::FunctionTemplate::New(isolate);
9896 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0)); 9961 t0->InstanceTemplate()->Set(v8_str("x"), v8_num(0));
9897 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 9962 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9898 t1->SetHiddenPrototype(true); 9963 t1->SetHiddenPrototype(true);
9899 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1)); 9964 t1->InstanceTemplate()->Set(v8_str("y"), v8_num(1));
9900 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 9965 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9901 t2->SetHiddenPrototype(true); 9966 t2->SetHiddenPrototype(true);
9902 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2)); 9967 t2->InstanceTemplate()->Set(v8_str("z"), v8_num(2));
9903 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 9968 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
9904 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3)); 9969 t3->InstanceTemplate()->Set(v8_str("u"), v8_num(3));
9905 9970
9906 Local<v8::Object> o0 = t0->GetFunction()->NewInstance(); 9971 Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
9907 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 9972 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
9908 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 9973 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
9909 Local<v8::Object> o3 = t3->GetFunction()->NewInstance(); 9974 Local<v8::Object> o3 = t3->GetFunction()->NewInstance();
9910 9975
9911 // Setting the prototype on an object does not skip hidden prototypes. 9976 // Setting the prototype on an object does not skip hidden prototypes.
9912 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value()); 9977 CHECK_EQ(0, o0->Get(v8_str("x"))->Int32Value());
9913 CHECK(o0->SetPrototype(o1)); 9978 CHECK(o0->SetPrototype(o1));
(...skipping 30 matching lines...) Expand all
9944 CHECK_EQ(proto2.As<v8::Object>(), o3); 10009 CHECK_EQ(proto2.As<v8::Object>(), o3);
9945 } 10010 }
9946 10011
9947 10012
9948 // Getting property names of an object with a prototype chain that 10013 // Getting property names of an object with a prototype chain that
9949 // triggers dictionary elements in GetLocalPropertyNames() shouldn't 10014 // triggers dictionary elements in GetLocalPropertyNames() shouldn't
9950 // crash the runtime. 10015 // crash the runtime.
9951 THREADED_TEST(Regress91517) { 10016 THREADED_TEST(Regress91517) {
9952 i::FLAG_allow_natives_syntax = true; 10017 i::FLAG_allow_natives_syntax = true;
9953 LocalContext context; 10018 LocalContext context;
9954 v8::HandleScope handle_scope(context->GetIsolate()); 10019 v8::Isolate* isolate = context->GetIsolate();
10020 v8::HandleScope handle_scope(isolate);
9955 10021
9956 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 10022 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
9957 t1->SetHiddenPrototype(true); 10023 t1->SetHiddenPrototype(true);
9958 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1)); 10024 t1->InstanceTemplate()->Set(v8_str("foo"), v8_num(1));
9959 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 10025 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
9960 t2->SetHiddenPrototype(true); 10026 t2->SetHiddenPrototype(true);
9961 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2)); 10027 t2->InstanceTemplate()->Set(v8_str("fuz1"), v8_num(2));
9962 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New()); 10028 t2->InstanceTemplate()->Set(v8_str("objects"), v8::Object::New());
9963 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2)); 10029 t2->InstanceTemplate()->Set(v8_str("fuz2"), v8_num(2));
9964 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(); 10030 Local<v8::FunctionTemplate> t3 = v8::FunctionTemplate::New(isolate);
9965 t3->SetHiddenPrototype(true); 10031 t3->SetHiddenPrototype(true);
9966 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3)); 10032 t3->InstanceTemplate()->Set(v8_str("boo"), v8_num(3));
9967 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(); 10033 Local<v8::FunctionTemplate> t4 = v8::FunctionTemplate::New(isolate);
9968 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4)); 10034 t4->InstanceTemplate()->Set(v8_str("baz"), v8_num(4));
9969 10035
9970 // Force dictionary-based properties. 10036 // Force dictionary-based properties.
9971 i::ScopedVector<char> name_buf(1024); 10037 i::ScopedVector<char> name_buf(1024);
9972 for (int i = 1; i <= 1000; i++) { 10038 for (int i = 1; i <= 1000; i++) {
9973 i::OS::SNPrintF(name_buf, "sdf%d", i); 10039 i::OS::SNPrintF(name_buf, "sdf%d", i);
9974 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2)); 10040 t2->InstanceTemplate()->Set(v8_str(name_buf.start()), v8_num(2));
9975 } 10041 }
9976 10042
9977 Local<v8::Object> o1 = t1->GetFunction()->NewInstance(); 10043 Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
(...skipping 16 matching lines...) Expand all
9994 ExpectTrue("names.indexOf(\"boo\") >= 0"); 10060 ExpectTrue("names.indexOf(\"boo\") >= 0");
9995 ExpectTrue("names.indexOf(\"foo\") >= 0"); 10061 ExpectTrue("names.indexOf(\"foo\") >= 0");
9996 ExpectTrue("names.indexOf(\"fuz1\") >= 0"); 10062 ExpectTrue("names.indexOf(\"fuz1\") >= 0");
9997 ExpectTrue("names.indexOf(\"fuz2\") >= 0"); 10063 ExpectTrue("names.indexOf(\"fuz2\") >= 0");
9998 ExpectFalse("names[1005] == undefined"); 10064 ExpectFalse("names[1005] == undefined");
9999 } 10065 }
10000 10066
10001 10067
10002 THREADED_TEST(FunctionReadOnlyPrototype) { 10068 THREADED_TEST(FunctionReadOnlyPrototype) {
10003 LocalContext context; 10069 LocalContext context;
10004 v8::HandleScope handle_scope(context->GetIsolate()); 10070 v8::Isolate* isolate = context->GetIsolate();
10071 v8::HandleScope handle_scope(isolate);
10005 10072
10006 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 10073 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10007 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 10074 t1->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
10008 t1->ReadOnlyPrototype(); 10075 t1->ReadOnlyPrototype();
10009 context->Global()->Set(v8_str("func1"), t1->GetFunction()); 10076 context->Global()->Set(v8_str("func1"), t1->GetFunction());
10010 // Configured value of ReadOnly flag. 10077 // Configured value of ReadOnly flag.
10011 CHECK(CompileRun( 10078 CHECK(CompileRun(
10012 "(function() {" 10079 "(function() {"
10013 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');" 10080 " descriptor = Object.getOwnPropertyDescriptor(func1, 'prototype');"
10014 " return (descriptor['writable'] == false);" 10081 " return (descriptor['writable'] == false);"
10015 "})()")->BooleanValue()); 10082 "})()")->BooleanValue());
10016 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value()); 10083 CHECK_EQ(42, CompileRun("func1.prototype.x")->Int32Value());
10017 CHECK_EQ(42, 10084 CHECK_EQ(42,
10018 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value()); 10085 CompileRun("func1.prototype = {}; func1.prototype.x")->Int32Value());
10019 10086
10020 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(); 10087 Local<v8::FunctionTemplate> t2 = v8::FunctionTemplate::New(isolate);
10021 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42)); 10088 t2->PrototypeTemplate()->Set(v8_str("x"), v8::Integer::New(42));
10022 context->Global()->Set(v8_str("func2"), t2->GetFunction()); 10089 context->Global()->Set(v8_str("func2"), t2->GetFunction());
10023 // Default value of ReadOnly flag. 10090 // Default value of ReadOnly flag.
10024 CHECK(CompileRun( 10091 CHECK(CompileRun(
10025 "(function() {" 10092 "(function() {"
10026 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');" 10093 " descriptor = Object.getOwnPropertyDescriptor(func2, 'prototype');"
10027 " return (descriptor['writable'] == true);" 10094 " return (descriptor['writable'] == true);"
10028 "})()")->BooleanValue()); 10095 "})()")->BooleanValue());
10029 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value()); 10096 CHECK_EQ(42, CompileRun("func2.prototype.x")->Int32Value());
10030 } 10097 }
10031 10098
10032 10099
10033 THREADED_TEST(SetPrototypeThrows) { 10100 THREADED_TEST(SetPrototypeThrows) {
10034 LocalContext context; 10101 LocalContext context;
10035 v8::HandleScope handle_scope(context->GetIsolate()); 10102 v8::Isolate* isolate = context->GetIsolate();
10103 v8::HandleScope handle_scope(isolate);
10036 10104
10037 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 10105 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10038 10106
10039 Local<v8::Object> o0 = t->GetFunction()->NewInstance(); 10107 Local<v8::Object> o0 = t->GetFunction()->NewInstance();
10040 Local<v8::Object> o1 = t->GetFunction()->NewInstance(); 10108 Local<v8::Object> o1 = t->GetFunction()->NewInstance();
10041 10109
10042 CHECK(o0->SetPrototype(o1)); 10110 CHECK(o0->SetPrototype(o1));
10043 // If setting the prototype leads to the cycle, SetPrototype should 10111 // If setting the prototype leads to the cycle, SetPrototype should
10044 // return false and keep VM in sane state. 10112 // return false and keep VM in sane state.
10045 v8::TryCatch try_catch; 10113 v8::TryCatch try_catch;
10046 CHECK(!o1->SetPrototype(o0)); 10114 CHECK(!o1->SetPrototype(o0));
10047 CHECK(!try_catch.HasCaught()); 10115 CHECK(!try_catch.HasCaught());
10048 ASSERT(!CcTest::i_isolate()->has_pending_exception()); 10116 ASSERT(!CcTest::i_isolate()->has_pending_exception());
10049 10117
10050 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value()); 10118 CHECK_EQ(42, CompileRun("function f() { return 42; }; f()")->Int32Value());
10051 } 10119 }
10052 10120
10053 10121
10054 THREADED_TEST(FunctionRemovePrototype) { 10122 THREADED_TEST(FunctionRemovePrototype) {
10055 LocalContext context; 10123 LocalContext context;
10056 v8::HandleScope handle_scope(context->GetIsolate()); 10124 v8::Isolate* isolate = context->GetIsolate();
10125 v8::HandleScope handle_scope(isolate);
10057 10126
10058 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(); 10127 Local<v8::FunctionTemplate> t1 = v8::FunctionTemplate::New(isolate);
10059 t1->RemovePrototype(); 10128 t1->RemovePrototype();
10060 Local<v8::Function> fun = t1->GetFunction(); 10129 Local<v8::Function> fun = t1->GetFunction();
10061 context->Global()->Set(v8_str("fun"), fun); 10130 context->Global()->Set(v8_str("fun"), fun);
10062 CHECK(!CompileRun("'prototype' in fun")->BooleanValue()); 10131 CHECK(!CompileRun("'prototype' in fun")->BooleanValue());
10063 10132
10064 v8::TryCatch try_catch; 10133 v8::TryCatch try_catch;
10065 CompileRun("new fun()"); 10134 CompileRun("new fun()");
10066 CHECK(try_catch.HasCaught()); 10135 CHECK(try_catch.HasCaught());
10067 10136
10068 try_catch.Reset(); 10137 try_catch.Reset();
(...skipping 20 matching lines...) Expand all
10089 x->Get(v8_str("get")); 10158 x->Get(v8_str("get"));
10090 x->Set(v8_str("set"), v8::Integer::New(8)); 10159 x->Set(v8_str("set"), v8::Integer::New(8));
10091 x->Get(v8_str("get")); 10160 x->Get(v8_str("get"));
10092 x->Set(v8_str("set"), v8::Integer::New(8)); 10161 x->Set(v8_str("set"), v8::Integer::New(8));
10093 x->Get(v8_str("get")); 10162 x->Get(v8_str("get"));
10094 } 10163 }
10095 10164
10096 10165
10097 THREADED_TEST(Constructor) { 10166 THREADED_TEST(Constructor) {
10098 LocalContext context; 10167 LocalContext context;
10099 v8::HandleScope handle_scope(context->GetIsolate()); 10168 v8::Isolate* isolate = context->GetIsolate();
10100 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10169 v8::HandleScope handle_scope(isolate);
10170 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
10101 templ->SetClassName(v8_str("Fun")); 10171 templ->SetClassName(v8_str("Fun"));
10102 Local<Function> cons = templ->GetFunction(); 10172 Local<Function> cons = templ->GetFunction();
10103 context->Global()->Set(v8_str("Fun"), cons); 10173 context->Global()->Set(v8_str("Fun"), cons);
10104 Local<v8::Object> inst = cons->NewInstance(); 10174 Local<v8::Object> inst = cons->NewInstance();
10105 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst)); 10175 i::Handle<i::JSObject> obj(v8::Utils::OpenHandle(*inst));
10106 CHECK(obj->IsJSObject()); 10176 CHECK(obj->IsJSObject());
10107 Local<Value> value = CompileRun("(new Fun()).constructor === Fun"); 10177 Local<Value> value = CompileRun("(new Fun()).constructor === Fun");
10108 CHECK(value->BooleanValue()); 10178 CHECK(value->BooleanValue());
10109 } 10179 }
10110 10180
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
10257 Local<Value> args[] = { v8_num(23) }; 10327 Local<Value> args[] = { v8_num(23) };
10258 value = instance->CallAsConstructor(1, args); 10328 value = instance->CallAsConstructor(1, args);
10259 CHECK(try_catch.HasCaught()); 10329 CHECK(try_catch.HasCaught());
10260 String::Utf8Value exception_value2(try_catch.Exception()); 10330 String::Utf8Value exception_value2(try_catch.Exception());
10261 CHECK_EQ("23", *exception_value2); 10331 CHECK_EQ("23", *exception_value2);
10262 try_catch.Reset(); 10332 try_catch.Reset();
10263 } 10333 }
10264 10334
10265 // Check whether constructor returns with an object or non-object. 10335 // Check whether constructor returns with an object or non-object.
10266 { Local<FunctionTemplate> function_template = 10336 { Local<FunctionTemplate> function_template =
10267 FunctionTemplate::New(FakeConstructorCallback); 10337 FunctionTemplate::New(isolate, FakeConstructorCallback);
10268 Local<Function> function = function_template->GetFunction(); 10338 Local<Function> function = function_template->GetFunction();
10269 Local<Object> instance1 = function; 10339 Local<Object> instance1 = function;
10270 context->Global()->Set(v8_str("obj4"), instance1); 10340 context->Global()->Set(v8_str("obj4"), instance1);
10271 v8::TryCatch try_catch; 10341 v8::TryCatch try_catch;
10272 Local<Value> value; 10342 Local<Value> value;
10273 CHECK(!try_catch.HasCaught()); 10343 CHECK(!try_catch.HasCaught());
10274 10344
10275 CHECK(instance1->IsObject()); 10345 CHECK(instance1->IsObject());
10276 CHECK(instance1->IsFunction()); 10346 CHECK(instance1->IsFunction());
10277 10347
(...skipping 22 matching lines...) Expand all
10300 Local<Value> args2[] = { v8_num(28) }; 10370 Local<Value> args2[] = { v8_num(28) };
10301 value = instance2->CallAsConstructor(1, args2); 10371 value = instance2->CallAsConstructor(1, args2);
10302 CHECK(!try_catch.HasCaught()); 10372 CHECK(!try_catch.HasCaught());
10303 CHECK(!value->IsObject()); 10373 CHECK(!value->IsObject());
10304 } 10374 }
10305 } 10375 }
10306 10376
10307 10377
10308 THREADED_TEST(FunctionDescriptorException) { 10378 THREADED_TEST(FunctionDescriptorException) {
10309 LocalContext context; 10379 LocalContext context;
10310 v8::HandleScope handle_scope(context->GetIsolate()); 10380 v8::Isolate* isolate = context->GetIsolate();
10311 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 10381 v8::HandleScope handle_scope(isolate);
10382 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
10312 templ->SetClassName(v8_str("Fun")); 10383 templ->SetClassName(v8_str("Fun"));
10313 Local<Function> cons = templ->GetFunction(); 10384 Local<Function> cons = templ->GetFunction();
10314 context->Global()->Set(v8_str("Fun"), cons); 10385 context->Global()->Set(v8_str("Fun"), cons);
10315 Local<Value> value = CompileRun( 10386 Local<Value> value = CompileRun(
10316 "function test() {" 10387 "function test() {"
10317 " try {" 10388 " try {"
10318 " (new Fun()).blah()" 10389 " (new Fun()).blah()"
10319 " } catch (e) {" 10390 " } catch (e) {"
10320 " var str = String(e);" 10391 " var str = String(e);"
10321 " if (str.indexOf('TypeError') == -1) return 1;" 10392 " if (str.indexOf('TypeError') == -1) return 1;"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
10518 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) { 10589 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
10519 args.GetReturnValue().Set(args.This()); 10590 args.GetReturnValue().Set(args.This());
10520 } 10591 }
10521 10592
10522 10593
10523 // Test that a call handler can be set for objects which will allow 10594 // Test that a call handler can be set for objects which will allow
10524 // non-function objects created through the API to be called as 10595 // non-function objects created through the API to be called as
10525 // functions. 10596 // functions.
10526 THREADED_TEST(CallAsFunction) { 10597 THREADED_TEST(CallAsFunction) {
10527 LocalContext context; 10598 LocalContext context;
10528 v8::HandleScope scope(context->GetIsolate()); 10599 v8::Isolate* isolate = context->GetIsolate();
10600 v8::HandleScope scope(isolate);
10529 10601
10530 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 10602 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10531 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 10603 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10532 instance_template->SetCallAsFunctionHandler(call_as_function); 10604 instance_template->SetCallAsFunctionHandler(call_as_function);
10533 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 10605 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10534 context->Global()->Set(v8_str("obj"), instance); 10606 context->Global()->Set(v8_str("obj"), instance);
10535 v8::TryCatch try_catch; 10607 v8::TryCatch try_catch;
10536 Local<Value> value; 10608 Local<Value> value;
10537 CHECK(!try_catch.HasCaught()); 10609 CHECK(!try_catch.HasCaught());
10538 10610
10539 value = CompileRun("obj(42)"); 10611 value = CompileRun("obj(42)");
10540 CHECK(!try_catch.HasCaught()); 10612 CHECK(!try_catch.HasCaught());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
10573 CHECK_EQ(-43, value->Int32Value()); 10645 CHECK_EQ(-43, value->Int32Value());
10574 10646
10575 // Check that the call-as-function handler can be called through 10647 // Check that the call-as-function handler can be called through
10576 // the API. 10648 // the API.
10577 v8::Handle<Value> args[] = { v8_num(28) }; 10649 v8::Handle<Value> args[] = { v8_num(28) };
10578 value = instance->CallAsFunction(instance, 1, args); 10650 value = instance->CallAsFunction(instance, 1, args);
10579 CHECK(!try_catch.HasCaught()); 10651 CHECK(!try_catch.HasCaught());
10580 CHECK_EQ(28, value->Int32Value()); 10652 CHECK_EQ(28, value->Int32Value());
10581 } 10653 }
10582 10654
10583 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 10655 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10584 Local<ObjectTemplate> instance_template(t->InstanceTemplate()); 10656 Local<ObjectTemplate> instance_template(t->InstanceTemplate());
10585 USE(instance_template); 10657 USE(instance_template);
10586 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 10658 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10587 context->Global()->Set(v8_str("obj2"), instance); 10659 context->Global()->Set(v8_str("obj2"), instance);
10588 v8::TryCatch try_catch; 10660 v8::TryCatch try_catch;
10589 Local<Value> value; 10661 Local<Value> value;
10590 CHECK(!try_catch.HasCaught()); 10662 CHECK(!try_catch.HasCaught());
10591 10663
10592 // Call an object without call-as-function handler through the JS 10664 // Call an object without call-as-function handler through the JS
10593 value = CompileRun("obj2(28)"); 10665 value = CompileRun("obj2(28)");
10594 CHECK(value.IsEmpty()); 10666 CHECK(value.IsEmpty());
10595 CHECK(try_catch.HasCaught()); 10667 CHECK(try_catch.HasCaught());
10596 String::Utf8Value exception_value1(try_catch.Exception()); 10668 String::Utf8Value exception_value1(try_catch.Exception());
10597 CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function", 10669 CHECK_EQ("TypeError: Property 'obj2' of object #<Object> is not a function",
10598 *exception_value1); 10670 *exception_value1);
10599 try_catch.Reset(); 10671 try_catch.Reset();
10600 10672
10601 // Call an object without call-as-function handler through the API 10673 // Call an object without call-as-function handler through the API
10602 value = CompileRun("obj2(28)"); 10674 value = CompileRun("obj2(28)");
10603 v8::Handle<Value> args[] = { v8_num(28) }; 10675 v8::Handle<Value> args[] = { v8_num(28) };
10604 value = instance->CallAsFunction(instance, 1, args); 10676 value = instance->CallAsFunction(instance, 1, args);
10605 CHECK(value.IsEmpty()); 10677 CHECK(value.IsEmpty());
10606 CHECK(try_catch.HasCaught()); 10678 CHECK(try_catch.HasCaught());
10607 String::Utf8Value exception_value2(try_catch.Exception()); 10679 String::Utf8Value exception_value2(try_catch.Exception());
10608 CHECK_EQ("TypeError: [object Object] is not a function", *exception_value2); 10680 CHECK_EQ("TypeError: [object Object] is not a function", *exception_value2);
10609 try_catch.Reset(); 10681 try_catch.Reset();
10610 } 10682 }
10611 10683
10612 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 10684 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10613 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 10685 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10614 instance_template->SetCallAsFunctionHandler(ThrowValue); 10686 instance_template->SetCallAsFunctionHandler(ThrowValue);
10615 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 10687 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10616 context->Global()->Set(v8_str("obj3"), instance); 10688 context->Global()->Set(v8_str("obj3"), instance);
10617 v8::TryCatch try_catch; 10689 v8::TryCatch try_catch;
10618 Local<Value> value; 10690 Local<Value> value;
10619 CHECK(!try_catch.HasCaught()); 10691 CHECK(!try_catch.HasCaught());
10620 10692
10621 // Catch the exception which is thrown by call-as-function handler 10693 // Catch the exception which is thrown by call-as-function handler
10622 value = CompileRun("obj3(22)"); 10694 value = CompileRun("obj3(22)");
10623 CHECK(try_catch.HasCaught()); 10695 CHECK(try_catch.HasCaught());
10624 String::Utf8Value exception_value1(try_catch.Exception()); 10696 String::Utf8Value exception_value1(try_catch.Exception());
10625 CHECK_EQ("22", *exception_value1); 10697 CHECK_EQ("22", *exception_value1);
10626 try_catch.Reset(); 10698 try_catch.Reset();
10627 10699
10628 v8::Handle<Value> args[] = { v8_num(23) }; 10700 v8::Handle<Value> args[] = { v8_num(23) };
10629 value = instance->CallAsFunction(instance, 1, args); 10701 value = instance->CallAsFunction(instance, 1, args);
10630 CHECK(try_catch.HasCaught()); 10702 CHECK(try_catch.HasCaught());
10631 String::Utf8Value exception_value2(try_catch.Exception()); 10703 String::Utf8Value exception_value2(try_catch.Exception());
10632 CHECK_EQ("23", *exception_value2); 10704 CHECK_EQ("23", *exception_value2);
10633 try_catch.Reset(); 10705 try_catch.Reset();
10634 } 10706 }
10635 10707
10636 { v8::Isolate* isolate = context->GetIsolate(); 10708 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate);
10637 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
10638 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 10709 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10639 instance_template->SetCallAsFunctionHandler(ReturnThis); 10710 instance_template->SetCallAsFunctionHandler(ReturnThis);
10640 Local<v8::Object> instance = t->GetFunction()->NewInstance(); 10711 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10641 10712
10642 Local<v8::Value> a1 = 10713 Local<v8::Value> a1 =
10643 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL); 10714 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL);
10644 CHECK(a1->StrictEquals(instance)); 10715 CHECK(a1->StrictEquals(instance));
10645 Local<v8::Value> a2 = 10716 Local<v8::Value> a2 =
10646 instance->CallAsFunction(v8::Null(isolate), 0, NULL); 10717 instance->CallAsFunction(v8::Null(isolate), 0, NULL);
10647 CHECK(a2->StrictEquals(instance)); 10718 CHECK(a2->StrictEquals(instance));
10648 Local<v8::Value> a3 = 10719 Local<v8::Value> a3 =
10649 instance->CallAsFunction(v8_num(42), 0, NULL); 10720 instance->CallAsFunction(v8_num(42), 0, NULL);
10650 CHECK(a3->StrictEquals(instance)); 10721 CHECK(a3->StrictEquals(instance));
10651 Local<v8::Value> a4 = 10722 Local<v8::Value> a4 =
10652 instance->CallAsFunction(v8_str("hello"), 0, NULL); 10723 instance->CallAsFunction(v8_str("hello"), 0, NULL);
10653 CHECK(a4->StrictEquals(instance)); 10724 CHECK(a4->StrictEquals(instance));
10654 Local<v8::Value> a5 = 10725 Local<v8::Value> a5 =
10655 instance->CallAsFunction(v8::True(isolate), 0, NULL); 10726 instance->CallAsFunction(v8::True(isolate), 0, NULL);
10656 CHECK(a5->StrictEquals(instance)); 10727 CHECK(a5->StrictEquals(instance));
10657 } 10728 }
10658 10729
10659 { v8::Isolate* isolate = context->GetIsolate(); 10730 { CompileRun(
10660 CompileRun(
10661 "function ReturnThisSloppy() {" 10731 "function ReturnThisSloppy() {"
10662 " return this;" 10732 " return this;"
10663 "}" 10733 "}"
10664 "function ReturnThisStrict() {" 10734 "function ReturnThisStrict() {"
10665 " 'use strict';" 10735 " 'use strict';"
10666 " return this;" 10736 " return this;"
10667 "}"); 10737 "}");
10668 Local<Function> ReturnThisSloppy = 10738 Local<Function> ReturnThisSloppy =
10669 Local<Function>::Cast( 10739 Local<Function>::Cast(
10670 context->Global()->Get(v8_str("ReturnThisSloppy"))); 10740 context->Global()->Get(v8_str("ReturnThisSloppy")));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
10706 Local<v8::Value> a10 = 10776 Local<v8::Value> a10 =
10707 ReturnThisStrict->CallAsFunction(v8::True(isolate), 0, NULL); 10777 ReturnThisStrict->CallAsFunction(v8::True(isolate), 0, NULL);
10708 CHECK(a10->StrictEquals(v8::True(isolate))); 10778 CHECK(a10->StrictEquals(v8::True(isolate)));
10709 } 10779 }
10710 } 10780 }
10711 10781
10712 10782
10713 // Check whether a non-function object is callable. 10783 // Check whether a non-function object is callable.
10714 THREADED_TEST(CallableObject) { 10784 THREADED_TEST(CallableObject) {
10715 LocalContext context; 10785 LocalContext context;
10716 v8::HandleScope scope(context->GetIsolate()); 10786 v8::Isolate* isolate = context->GetIsolate();
10787 v8::HandleScope scope(isolate);
10717 10788
10718 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10789 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
10719 instance_template->SetCallAsFunctionHandler(call_as_function); 10790 instance_template->SetCallAsFunctionHandler(call_as_function);
10720 Local<Object> instance = instance_template->NewInstance(); 10791 Local<Object> instance = instance_template->NewInstance();
10721 v8::TryCatch try_catch; 10792 v8::TryCatch try_catch;
10722 10793
10723 CHECK(instance->IsCallable()); 10794 CHECK(instance->IsCallable());
10724 CHECK(!try_catch.HasCaught()); 10795 CHECK(!try_catch.HasCaught());
10725 } 10796 }
10726 10797
10727 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10798 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
10728 Local<Object> instance = instance_template->NewInstance(); 10799 Local<Object> instance = instance_template->NewInstance();
10729 v8::TryCatch try_catch; 10800 v8::TryCatch try_catch;
10730 10801
10731 CHECK(!instance->IsCallable()); 10802 CHECK(!instance->IsCallable());
10732 CHECK(!try_catch.HasCaught()); 10803 CHECK(!try_catch.HasCaught());
10733 } 10804 }
10734 10805
10735 { Local<FunctionTemplate> function_template = 10806 { Local<FunctionTemplate> function_template =
10736 FunctionTemplate::New(call_as_function); 10807 FunctionTemplate::New(isolate, call_as_function);
10737 Local<Function> function = function_template->GetFunction(); 10808 Local<Function> function = function_template->GetFunction();
10738 Local<Object> instance = function; 10809 Local<Object> instance = function;
10739 v8::TryCatch try_catch; 10810 v8::TryCatch try_catch;
10740 10811
10741 CHECK(instance->IsCallable()); 10812 CHECK(instance->IsCallable());
10742 CHECK(!try_catch.HasCaught()); 10813 CHECK(!try_catch.HasCaught());
10743 } 10814 }
10744 10815
10745 { Local<FunctionTemplate> function_template = FunctionTemplate::New(); 10816 { Local<FunctionTemplate> function_template = FunctionTemplate::New(isolate);
10746 Local<Function> function = function_template->GetFunction(); 10817 Local<Function> function = function_template->GetFunction();
10747 Local<Object> instance = function; 10818 Local<Object> instance = function;
10748 v8::TryCatch try_catch; 10819 v8::TryCatch try_catch;
10749 10820
10750 CHECK(instance->IsCallable()); 10821 CHECK(instance->IsCallable());
10751 CHECK(!try_catch.HasCaught()); 10822 CHECK(!try_catch.HasCaught());
10752 } 10823 }
10753 } 10824 }
10754 10825
10755 10826
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
10797 10868
10798 static void InterceptorHasOwnPropertyGetter( 10869 static void InterceptorHasOwnPropertyGetter(
10799 Local<String> name, 10870 Local<String> name,
10800 const v8::PropertyCallbackInfo<v8::Value>& info) { 10871 const v8::PropertyCallbackInfo<v8::Value>& info) {
10801 ApiTestFuzzer::Fuzz(); 10872 ApiTestFuzzer::Fuzz();
10802 } 10873 }
10803 10874
10804 10875
10805 THREADED_TEST(InterceptorHasOwnProperty) { 10876 THREADED_TEST(InterceptorHasOwnProperty) {
10806 LocalContext context; 10877 LocalContext context;
10807 v8::HandleScope scope(context->GetIsolate()); 10878 v8::Isolate* isolate = context->GetIsolate();
10808 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10879 v8::HandleScope scope(isolate);
10880 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
10809 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 10881 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
10810 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter); 10882 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetter);
10811 Local<Function> function = fun_templ->GetFunction(); 10883 Local<Function> function = fun_templ->GetFunction();
10812 context->Global()->Set(v8_str("constructor"), function); 10884 context->Global()->Set(v8_str("constructor"), function);
10813 v8::Handle<Value> value = CompileRun( 10885 v8::Handle<Value> value = CompileRun(
10814 "var o = new constructor();" 10886 "var o = new constructor();"
10815 "o.hasOwnProperty('ostehaps');"); 10887 "o.hasOwnProperty('ostehaps');");
10816 CHECK_EQ(false, value->BooleanValue()); 10888 CHECK_EQ(false, value->BooleanValue());
10817 value = CompileRun( 10889 value = CompileRun(
10818 "o.ostehaps = 42;" 10890 "o.ostehaps = 42;"
10819 "o.hasOwnProperty('ostehaps');"); 10891 "o.hasOwnProperty('ostehaps');");
10820 CHECK_EQ(true, value->BooleanValue()); 10892 CHECK_EQ(true, value->BooleanValue());
10821 value = CompileRun( 10893 value = CompileRun(
10822 "var p = new constructor();" 10894 "var p = new constructor();"
10823 "p.hasOwnProperty('ostehaps');"); 10895 "p.hasOwnProperty('ostehaps');");
10824 CHECK_EQ(false, value->BooleanValue()); 10896 CHECK_EQ(false, value->BooleanValue());
10825 } 10897 }
10826 10898
10827 10899
10828 static void InterceptorHasOwnPropertyGetterGC( 10900 static void InterceptorHasOwnPropertyGetterGC(
10829 Local<String> name, 10901 Local<String> name,
10830 const v8::PropertyCallbackInfo<v8::Value>& info) { 10902 const v8::PropertyCallbackInfo<v8::Value>& info) {
10831 ApiTestFuzzer::Fuzz(); 10903 ApiTestFuzzer::Fuzz();
10832 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 10904 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
10833 } 10905 }
10834 10906
10835 10907
10836 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) { 10908 THREADED_TEST(InterceptorHasOwnPropertyCausingGC) {
10837 LocalContext context; 10909 LocalContext context;
10838 v8::HandleScope scope(context->GetIsolate()); 10910 v8::Isolate* isolate = context->GetIsolate();
10839 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 10911 v8::HandleScope scope(isolate);
10912 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(isolate);
10840 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate(); 10913 Local<v8::ObjectTemplate> instance_templ = fun_templ->InstanceTemplate();
10841 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC); 10914 instance_templ->SetNamedPropertyHandler(InterceptorHasOwnPropertyGetterGC);
10842 Local<Function> function = fun_templ->GetFunction(); 10915 Local<Function> function = fun_templ->GetFunction();
10843 context->Global()->Set(v8_str("constructor"), function); 10916 context->Global()->Set(v8_str("constructor"), function);
10844 // Let's first make some stuff so we can be sure to get a good GC. 10917 // Let's first make some stuff so we can be sure to get a good GC.
10845 CompileRun( 10918 CompileRun(
10846 "function makestr(size) {" 10919 "function makestr(size) {"
10847 " switch (size) {" 10920 " switch (size) {"
10848 " case 1: return 'f';" 10921 " case 1: return 'f';"
10849 " case 2: return 'fo';" 10922 " case 2: return 'fo';"
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
11659 if (count++ % 3 == 0) { 11732 if (count++ % 3 == 0) {
11660 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask); 11733 CcTest::heap()->CollectAllGarbage(i::Heap::kAbortIncrementalMarkingMask);
11661 // This should move the stub 11734 // This should move the stub
11662 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed 11735 GenerateSomeGarbage(); // This should ensure the old stub memory is flushed
11663 } 11736 }
11664 } 11737 }
11665 11738
11666 11739
11667 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) { 11740 THREADED_TEST(CallICFastApi_DirectCall_GCMoveStub) {
11668 LocalContext context; 11741 LocalContext context;
11669 v8::HandleScope scope(context->GetIsolate()); 11742 v8::Isolate* isolate = context->GetIsolate();
11743 v8::HandleScope scope(isolate);
11670 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11744 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New();
11671 nativeobject_templ->Set(context->GetIsolate(), "callback", 11745 nativeobject_templ->Set(isolate, "callback",
11672 v8::FunctionTemplate::New(DirectApiCallback)); 11746 v8::FunctionTemplate::New(isolate,
11747 DirectApiCallback));
11673 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11748 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11674 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11749 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11675 // call the api function multiple times to ensure direct call stub creation. 11750 // call the api function multiple times to ensure direct call stub creation.
11676 CompileRun( 11751 CompileRun(
11677 "function f() {" 11752 "function f() {"
11678 " for (var i = 1; i <= 30; i++) {" 11753 " for (var i = 1; i <= 30; i++) {"
11679 " nativeobject.callback();" 11754 " nativeobject.callback();"
11680 " }" 11755 " }"
11681 "}" 11756 "}"
11682 "f();"); 11757 "f();");
11683 } 11758 }
11684 11759
11685 11760
11686 void ThrowingDirectApiCallback( 11761 void ThrowingDirectApiCallback(
11687 const v8::FunctionCallbackInfo<v8::Value>& args) { 11762 const v8::FunctionCallbackInfo<v8::Value>& args) {
11688 args.GetIsolate()->ThrowException(v8_str("g")); 11763 args.GetIsolate()->ThrowException(v8_str("g"));
11689 } 11764 }
11690 11765
11691 11766
11692 THREADED_TEST(CallICFastApi_DirectCall_Throw) { 11767 THREADED_TEST(CallICFastApi_DirectCall_Throw) {
11693 LocalContext context; 11768 LocalContext context;
11694 v8::HandleScope scope(context->GetIsolate()); 11769 v8::Isolate* isolate = context->GetIsolate();
11695 v8::Handle<v8::ObjectTemplate> nativeobject_templ = v8::ObjectTemplate::New(); 11770 v8::HandleScope scope(isolate);
11696 nativeobject_templ->Set(context->GetIsolate(), "callback", 11771 v8::Handle<v8::ObjectTemplate> nativeobject_templ =
11697 v8::FunctionTemplate::New(ThrowingDirectApiCallback)); 11772 v8::ObjectTemplate::New();
11773 nativeobject_templ->Set(isolate, "callback",
11774 v8::FunctionTemplate::New(isolate,
11775 ThrowingDirectApiCallback));
11698 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance(); 11776 v8::Local<v8::Object> nativeobject_obj = nativeobject_templ->NewInstance();
11699 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj); 11777 context->Global()->Set(v8_str("nativeobject"), nativeobject_obj);
11700 // call the api function multiple times to ensure direct call stub creation. 11778 // call the api function multiple times to ensure direct call stub creation.
11701 v8::Handle<Value> result = CompileRun( 11779 v8::Handle<Value> result = CompileRun(
11702 "var result = '';" 11780 "var result = '';"
11703 "function f() {" 11781 "function f() {"
11704 " for (var i = 1; i <= 5; i++) {" 11782 " for (var i = 1; i <= 5; i++) {"
11705 " try { nativeobject.callback(); } catch (e) { result += e; }" 11783 " try { nativeobject.callback(); } catch (e) { result += e; }"
11706 " }" 11784 " }"
11707 "}" 11785 "}"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
11768 "for (var i = 0; i < 5; i++) {" 11846 "for (var i = 0; i < 5; i++) {"
11769 " try { o1.p1; } catch (e) { result += e; }" 11847 " try { o1.p1; } catch (e) { result += e; }"
11770 "}" 11848 "}"
11771 "result;"); 11849 "result;");
11772 CHECK_EQ(v8_str("ggggg"), result); 11850 CHECK_EQ(v8_str("ggggg"), result);
11773 } 11851 }
11774 11852
11775 11853
11776 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) { 11854 THREADED_PROFILED_TEST(InterceptorCallICFastApi_TrivialSignature) {
11777 int interceptor_call_count = 0; 11855 int interceptor_call_count = 0;
11778 v8::HandleScope scope(CcTest::isolate()); 11856 v8::Isolate* isolate = CcTest::isolate();
11779 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11857 v8::HandleScope scope(isolate);
11858 v8::Handle<v8::FunctionTemplate> fun_templ =
11859 v8::FunctionTemplate::New(isolate);
11780 v8::Handle<v8::FunctionTemplate> method_templ = 11860 v8::Handle<v8::FunctionTemplate> method_templ =
11781 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 11861 v8::FunctionTemplate::New(isolate,
11862 FastApiCallback_TrivialSignature,
11782 v8_str("method_data"), 11863 v8_str("method_data"),
11783 v8::Handle<v8::Signature>()); 11864 v8::Handle<v8::Signature>());
11784 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11865 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11785 proto_templ->Set(v8_str("method"), method_templ); 11866 proto_templ->Set(v8_str("method"), method_templ);
11786 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11867 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11787 templ->SetNamedPropertyHandler( 11868 templ->SetNamedPropertyHandler(
11788 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11869 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11789 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11870 v8::External::New(isolate, &interceptor_call_count));
11790 LocalContext context; 11871 LocalContext context;
11791 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11872 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11792 GenerateSomeGarbage(); 11873 GenerateSomeGarbage();
11793 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11874 context->Global()->Set(v8_str("o"), fun->NewInstance());
11794 CompileRun( 11875 CompileRun(
11795 "var result = 0;" 11876 "var result = 0;"
11796 "for (var i = 0; i < 100; i++) {" 11877 "for (var i = 0; i < 100; i++) {"
11797 " result = o.method(41);" 11878 " result = o.method(41);"
11798 "}"); 11879 "}");
11799 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11880 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11800 CHECK_EQ(100, interceptor_call_count); 11881 CHECK_EQ(100, interceptor_call_count);
11801 } 11882 }
11802 11883
11803 11884
11804 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) { 11885 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature) {
11805 int interceptor_call_count = 0; 11886 int interceptor_call_count = 0;
11806 v8::HandleScope scope(CcTest::isolate()); 11887 v8::Isolate* isolate = CcTest::isolate();
11807 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11888 v8::HandleScope scope(isolate);
11889 v8::Handle<v8::FunctionTemplate> fun_templ =
11890 v8::FunctionTemplate::New(isolate);
11808 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 11891 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11809 FastApiCallback_SimpleSignature, v8_str("method_data"), 11892 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
11810 v8::Signature::New(CcTest::isolate(), fun_templ)); 11893 v8::Signature::New(isolate, fun_templ));
11811 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11894 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11812 proto_templ->Set(v8_str("method"), method_templ); 11895 proto_templ->Set(v8_str("method"), method_templ);
11813 fun_templ->SetHiddenPrototype(true); 11896 fun_templ->SetHiddenPrototype(true);
11814 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11897 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11815 templ->SetNamedPropertyHandler( 11898 templ->SetNamedPropertyHandler(
11816 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11899 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11817 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11900 v8::External::New(isolate, &interceptor_call_count));
11818 LocalContext context; 11901 LocalContext context;
11819 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11902 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11820 GenerateSomeGarbage(); 11903 GenerateSomeGarbage();
11821 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11904 context->Global()->Set(v8_str("o"), fun->NewInstance());
11822 CompileRun( 11905 CompileRun(
11823 "o.foo = 17;" 11906 "o.foo = 17;"
11824 "var receiver = {};" 11907 "var receiver = {};"
11825 "receiver.__proto__ = o;" 11908 "receiver.__proto__ = o;"
11826 "var result = 0;" 11909 "var result = 0;"
11827 "for (var i = 0; i < 100; i++) {" 11910 "for (var i = 0; i < 100; i++) {"
11828 " result = receiver.method(41);" 11911 " result = receiver.method(41);"
11829 "}"); 11912 "}");
11830 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 11913 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
11831 CHECK_EQ(100, interceptor_call_count); 11914 CHECK_EQ(100, interceptor_call_count);
11832 } 11915 }
11833 11916
11834 11917
11835 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) { 11918 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss1) {
11836 int interceptor_call_count = 0; 11919 int interceptor_call_count = 0;
11837 v8::HandleScope scope(CcTest::isolate()); 11920 v8::Isolate* isolate = CcTest::isolate();
11838 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11921 v8::HandleScope scope(isolate);
11922 v8::Handle<v8::FunctionTemplate> fun_templ =
11923 v8::FunctionTemplate::New(isolate);
11839 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 11924 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11840 FastApiCallback_SimpleSignature, v8_str("method_data"), 11925 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
11841 v8::Signature::New(CcTest::isolate(), fun_templ)); 11926 v8::Signature::New(isolate, fun_templ));
11842 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11927 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11843 proto_templ->Set(v8_str("method"), method_templ); 11928 proto_templ->Set(v8_str("method"), method_templ);
11844 fun_templ->SetHiddenPrototype(true); 11929 fun_templ->SetHiddenPrototype(true);
11845 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11930 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11846 templ->SetNamedPropertyHandler( 11931 templ->SetNamedPropertyHandler(
11847 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11932 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11848 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11933 v8::External::New(isolate, &interceptor_call_count));
11849 LocalContext context; 11934 LocalContext context;
11850 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11935 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11851 GenerateSomeGarbage(); 11936 GenerateSomeGarbage();
11852 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11937 context->Global()->Set(v8_str("o"), fun->NewInstance());
11853 CompileRun( 11938 CompileRun(
11854 "o.foo = 17;" 11939 "o.foo = 17;"
11855 "var receiver = {};" 11940 "var receiver = {};"
11856 "receiver.__proto__ = o;" 11941 "receiver.__proto__ = o;"
11857 "var result = 0;" 11942 "var result = 0;"
11858 "var saved_result = 0;" 11943 "var saved_result = 0;"
11859 "for (var i = 0; i < 100; i++) {" 11944 "for (var i = 0; i < 100; i++) {"
11860 " result = receiver.method(41);" 11945 " result = receiver.method(41);"
11861 " if (i == 50) {" 11946 " if (i == 50) {"
11862 " saved_result = result;" 11947 " saved_result = result;"
11863 " receiver = {method: function(x) { return x - 1 }};" 11948 " receiver = {method: function(x) { return x - 1 }};"
11864 " }" 11949 " }"
11865 "}"); 11950 "}");
11866 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11951 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11867 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11952 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11868 CHECK_GE(interceptor_call_count, 50); 11953 CHECK_GE(interceptor_call_count, 50);
11869 } 11954 }
11870 11955
11871 11956
11872 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) { 11957 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss2) {
11873 int interceptor_call_count = 0; 11958 int interceptor_call_count = 0;
11874 v8::HandleScope scope(CcTest::isolate()); 11959 v8::Isolate* isolate = CcTest::isolate();
11875 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11960 v8::HandleScope scope(isolate);
11961 v8::Handle<v8::FunctionTemplate> fun_templ =
11962 v8::FunctionTemplate::New(isolate);
11876 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 11963 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11877 FastApiCallback_SimpleSignature, v8_str("method_data"), 11964 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
11878 v8::Signature::New(CcTest::isolate(), fun_templ)); 11965 v8::Signature::New(isolate, fun_templ));
11879 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 11966 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11880 proto_templ->Set(v8_str("method"), method_templ); 11967 proto_templ->Set(v8_str("method"), method_templ);
11881 fun_templ->SetHiddenPrototype(true); 11968 fun_templ->SetHiddenPrototype(true);
11882 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 11969 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11883 templ->SetNamedPropertyHandler( 11970 templ->SetNamedPropertyHandler(
11884 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 11971 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11885 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 11972 v8::External::New(isolate, &interceptor_call_count));
11886 LocalContext context; 11973 LocalContext context;
11887 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 11974 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11888 GenerateSomeGarbage(); 11975 GenerateSomeGarbage();
11889 context->Global()->Set(v8_str("o"), fun->NewInstance()); 11976 context->Global()->Set(v8_str("o"), fun->NewInstance());
11890 CompileRun( 11977 CompileRun(
11891 "o.foo = 17;" 11978 "o.foo = 17;"
11892 "var receiver = {};" 11979 "var receiver = {};"
11893 "receiver.__proto__ = o;" 11980 "receiver.__proto__ = o;"
11894 "var result = 0;" 11981 "var result = 0;"
11895 "var saved_result = 0;" 11982 "var saved_result = 0;"
11896 "for (var i = 0; i < 100; i++) {" 11983 "for (var i = 0; i < 100; i++) {"
11897 " result = receiver.method(41);" 11984 " result = receiver.method(41);"
11898 " if (i == 50) {" 11985 " if (i == 50) {"
11899 " saved_result = result;" 11986 " saved_result = result;"
11900 " o.method = function(x) { return x - 1 };" 11987 " o.method = function(x) { return x - 1 };"
11901 " }" 11988 " }"
11902 "}"); 11989 "}");
11903 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 11990 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
11904 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 11991 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11905 CHECK_GE(interceptor_call_count, 50); 11992 CHECK_GE(interceptor_call_count, 50);
11906 } 11993 }
11907 11994
11908 11995
11909 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) { 11996 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_Miss3) {
11910 int interceptor_call_count = 0; 11997 int interceptor_call_count = 0;
11911 v8::HandleScope scope(CcTest::isolate()); 11998 v8::Isolate* isolate = CcTest::isolate();
11912 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 11999 v8::HandleScope scope(isolate);
12000 v8::Handle<v8::FunctionTemplate> fun_templ =
12001 v8::FunctionTemplate::New(isolate);
11913 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12002 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11914 FastApiCallback_SimpleSignature, v8_str("method_data"), 12003 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
11915 v8::Signature::New(CcTest::isolate(), fun_templ)); 12004 v8::Signature::New(isolate, fun_templ));
11916 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12005 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11917 proto_templ->Set(v8_str("method"), method_templ); 12006 proto_templ->Set(v8_str("method"), method_templ);
11918 fun_templ->SetHiddenPrototype(true); 12007 fun_templ->SetHiddenPrototype(true);
11919 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12008 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11920 templ->SetNamedPropertyHandler( 12009 templ->SetNamedPropertyHandler(
11921 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12010 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11922 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 12011 v8::External::New(isolate, &interceptor_call_count));
11923 LocalContext context; 12012 LocalContext context;
11924 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12013 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11925 GenerateSomeGarbage(); 12014 GenerateSomeGarbage();
11926 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12015 context->Global()->Set(v8_str("o"), fun->NewInstance());
11927 v8::TryCatch try_catch; 12016 v8::TryCatch try_catch;
11928 CompileRun( 12017 CompileRun(
11929 "o.foo = 17;" 12018 "o.foo = 17;"
11930 "var receiver = {};" 12019 "var receiver = {};"
11931 "receiver.__proto__ = o;" 12020 "receiver.__proto__ = o;"
11932 "var result = 0;" 12021 "var result = 0;"
11933 "var saved_result = 0;" 12022 "var saved_result = 0;"
11934 "for (var i = 0; i < 100; i++) {" 12023 "for (var i = 0; i < 100; i++) {"
11935 " result = receiver.method(41);" 12024 " result = receiver.method(41);"
11936 " if (i == 50) {" 12025 " if (i == 50) {"
11937 " saved_result = result;" 12026 " saved_result = result;"
11938 " receiver = 333;" 12027 " receiver = 333;"
11939 " }" 12028 " }"
11940 "}"); 12029 "}");
11941 CHECK(try_catch.HasCaught()); 12030 CHECK(try_catch.HasCaught());
11942 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 12031 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
11943 try_catch.Exception()->ToString()); 12032 try_catch.Exception()->ToString());
11944 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12033 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11945 CHECK_GE(interceptor_call_count, 50); 12034 CHECK_GE(interceptor_call_count, 50);
11946 } 12035 }
11947 12036
11948 12037
11949 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) { 12038 THREADED_PROFILED_TEST(InterceptorCallICFastApi_SimpleSignature_TypeError) {
11950 int interceptor_call_count = 0; 12039 int interceptor_call_count = 0;
11951 v8::HandleScope scope(CcTest::isolate()); 12040 v8::Isolate* isolate = CcTest::isolate();
11952 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12041 v8::HandleScope scope(isolate);
12042 v8::Handle<v8::FunctionTemplate> fun_templ =
12043 v8::FunctionTemplate::New(isolate);
11953 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12044 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
11954 FastApiCallback_SimpleSignature, v8_str("method_data"), 12045 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
11955 v8::Signature::New(CcTest::isolate(), fun_templ)); 12046 v8::Signature::New(isolate, fun_templ));
11956 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12047 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11957 proto_templ->Set(v8_str("method"), method_templ); 12048 proto_templ->Set(v8_str("method"), method_templ);
11958 fun_templ->SetHiddenPrototype(true); 12049 fun_templ->SetHiddenPrototype(true);
11959 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate(); 12050 v8::Handle<v8::ObjectTemplate> templ = fun_templ->InstanceTemplate();
11960 templ->SetNamedPropertyHandler( 12051 templ->SetNamedPropertyHandler(
11961 InterceptorCallICFastApi, NULL, NULL, NULL, NULL, 12052 InterceptorCallICFastApi, NULL, NULL, NULL, NULL,
11962 v8::External::New(CcTest::isolate(), &interceptor_call_count)); 12053 v8::External::New(isolate, &interceptor_call_count));
11963 LocalContext context; 12054 LocalContext context;
11964 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12055 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
11965 GenerateSomeGarbage(); 12056 GenerateSomeGarbage();
11966 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12057 context->Global()->Set(v8_str("o"), fun->NewInstance());
11967 v8::TryCatch try_catch; 12058 v8::TryCatch try_catch;
11968 CompileRun( 12059 CompileRun(
11969 "o.foo = 17;" 12060 "o.foo = 17;"
11970 "var receiver = {};" 12061 "var receiver = {};"
11971 "receiver.__proto__ = o;" 12062 "receiver.__proto__ = o;"
11972 "var result = 0;" 12063 "var result = 0;"
11973 "var saved_result = 0;" 12064 "var saved_result = 0;"
11974 "for (var i = 0; i < 100; i++) {" 12065 "for (var i = 0; i < 100; i++) {"
11975 " result = receiver.method(41);" 12066 " result = receiver.method(41);"
11976 " if (i == 50) {" 12067 " if (i == 50) {"
11977 " saved_result = result;" 12068 " saved_result = result;"
11978 " receiver = {method: receiver.method};" 12069 " receiver = {method: receiver.method};"
11979 " }" 12070 " }"
11980 "}"); 12071 "}");
11981 CHECK(try_catch.HasCaught()); 12072 CHECK(try_catch.HasCaught());
11982 CHECK_EQ(v8_str("TypeError: Illegal invocation"), 12073 CHECK_EQ(v8_str("TypeError: Illegal invocation"),
11983 try_catch.Exception()->ToString()); 12074 try_catch.Exception()->ToString());
11984 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12075 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
11985 CHECK_GE(interceptor_call_count, 50); 12076 CHECK_GE(interceptor_call_count, 50);
11986 } 12077 }
11987 12078
11988 12079
11989 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) { 12080 THREADED_PROFILED_TEST(CallICFastApi_TrivialSignature) {
11990 v8::HandleScope scope(CcTest::isolate()); 12081 v8::Isolate* isolate = CcTest::isolate();
11991 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12082 v8::HandleScope scope(isolate);
12083 v8::Handle<v8::FunctionTemplate> fun_templ =
12084 v8::FunctionTemplate::New(isolate);
11992 v8::Handle<v8::FunctionTemplate> method_templ = 12085 v8::Handle<v8::FunctionTemplate> method_templ =
11993 v8::FunctionTemplate::New(FastApiCallback_TrivialSignature, 12086 v8::FunctionTemplate::New(isolate,
12087 FastApiCallback_TrivialSignature,
11994 v8_str("method_data"), 12088 v8_str("method_data"),
11995 v8::Handle<v8::Signature>()); 12089 v8::Handle<v8::Signature>());
11996 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12090 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
11997 proto_templ->Set(v8_str("method"), method_templ); 12091 proto_templ->Set(v8_str("method"), method_templ);
11998 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12092 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
11999 USE(templ); 12093 USE(templ);
12000 LocalContext context; 12094 LocalContext context;
12001 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12095 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
12002 GenerateSomeGarbage(); 12096 GenerateSomeGarbage();
12003 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12097 context->Global()->Set(v8_str("o"), fun->NewInstance());
12004 CompileRun( 12098 CompileRun(
12005 "var result = 0;" 12099 "var result = 0;"
12006 "for (var i = 0; i < 100; i++) {" 12100 "for (var i = 0; i < 100; i++) {"
12007 " result = o.method(41);" 12101 " result = o.method(41);"
12008 "}"); 12102 "}");
12009 12103
12010 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 12104 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
12011 } 12105 }
12012 12106
12013 12107
12014 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) { 12108 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature) {
12015 v8::HandleScope scope(CcTest::isolate()); 12109 v8::Isolate* isolate = CcTest::isolate();
12016 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12110 v8::HandleScope scope(isolate);
12111 v8::Handle<v8::FunctionTemplate> fun_templ =
12112 v8::FunctionTemplate::New(isolate);
12017 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12113 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
12018 FastApiCallback_SimpleSignature, v8_str("method_data"), 12114 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
12019 v8::Signature::New(CcTest::isolate(), fun_templ)); 12115 v8::Signature::New(isolate, fun_templ));
12020 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12116 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
12021 proto_templ->Set(v8_str("method"), method_templ); 12117 proto_templ->Set(v8_str("method"), method_templ);
12022 fun_templ->SetHiddenPrototype(true); 12118 fun_templ->SetHiddenPrototype(true);
12023 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12119 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
12024 CHECK(!templ.IsEmpty()); 12120 CHECK(!templ.IsEmpty());
12025 LocalContext context; 12121 LocalContext context;
12026 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12122 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
12027 GenerateSomeGarbage(); 12123 GenerateSomeGarbage();
12028 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12124 context->Global()->Set(v8_str("o"), fun->NewInstance());
12029 CompileRun( 12125 CompileRun(
12030 "o.foo = 17;" 12126 "o.foo = 17;"
12031 "var receiver = {};" 12127 "var receiver = {};"
12032 "receiver.__proto__ = o;" 12128 "receiver.__proto__ = o;"
12033 "var result = 0;" 12129 "var result = 0;"
12034 "for (var i = 0; i < 100; i++) {" 12130 "for (var i = 0; i < 100; i++) {"
12035 " result = receiver.method(41);" 12131 " result = receiver.method(41);"
12036 "}"); 12132 "}");
12037 12133
12038 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value()); 12134 CHECK_EQ(42, context->Global()->Get(v8_str("result"))->Int32Value());
12039 } 12135 }
12040 12136
12041 12137
12042 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) { 12138 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss1) {
12043 v8::HandleScope scope(CcTest::isolate()); 12139 v8::Isolate* isolate = CcTest::isolate();
12044 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12140 v8::HandleScope scope(isolate);
12141 v8::Handle<v8::FunctionTemplate> fun_templ =
12142 v8::FunctionTemplate::New(isolate);
12045 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12143 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
12046 FastApiCallback_SimpleSignature, v8_str("method_data"), 12144 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
12047 v8::Signature::New(CcTest::isolate(), fun_templ)); 12145 v8::Signature::New(isolate, fun_templ));
12048 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12146 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
12049 proto_templ->Set(v8_str("method"), method_templ); 12147 proto_templ->Set(v8_str("method"), method_templ);
12050 fun_templ->SetHiddenPrototype(true); 12148 fun_templ->SetHiddenPrototype(true);
12051 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12149 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
12052 CHECK(!templ.IsEmpty()); 12150 CHECK(!templ.IsEmpty());
12053 LocalContext context; 12151 LocalContext context;
12054 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12152 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
12055 GenerateSomeGarbage(); 12153 GenerateSomeGarbage();
12056 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12154 context->Global()->Set(v8_str("o"), fun->NewInstance());
12057 CompileRun( 12155 CompileRun(
12058 "o.foo = 17;" 12156 "o.foo = 17;"
12059 "var receiver = {};" 12157 "var receiver = {};"
12060 "receiver.__proto__ = o;" 12158 "receiver.__proto__ = o;"
12061 "var result = 0;" 12159 "var result = 0;"
12062 "var saved_result = 0;" 12160 "var saved_result = 0;"
12063 "for (var i = 0; i < 100; i++) {" 12161 "for (var i = 0; i < 100; i++) {"
12064 " result = receiver.method(41);" 12162 " result = receiver.method(41);"
12065 " if (i == 50) {" 12163 " if (i == 50) {"
12066 " saved_result = result;" 12164 " saved_result = result;"
12067 " receiver = {method: function(x) { return x - 1 }};" 12165 " receiver = {method: function(x) { return x - 1 }};"
12068 " }" 12166 " }"
12069 "}"); 12167 "}");
12070 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value()); 12168 CHECK_EQ(40, context->Global()->Get(v8_str("result"))->Int32Value());
12071 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12169 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
12072 } 12170 }
12073 12171
12074 12172
12075 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) { 12173 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_Miss2) {
12076 v8::HandleScope scope(CcTest::isolate()); 12174 v8::Isolate* isolate = CcTest::isolate();
12077 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12175 v8::HandleScope scope(isolate);
12176 v8::Handle<v8::FunctionTemplate> fun_templ =
12177 v8::FunctionTemplate::New(isolate);
12078 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12178 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
12079 FastApiCallback_SimpleSignature, v8_str("method_data"), 12179 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
12080 v8::Signature::New(CcTest::isolate(), fun_templ)); 12180 v8::Signature::New(isolate, fun_templ));
12081 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12181 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
12082 proto_templ->Set(v8_str("method"), method_templ); 12182 proto_templ->Set(v8_str("method"), method_templ);
12083 fun_templ->SetHiddenPrototype(true); 12183 fun_templ->SetHiddenPrototype(true);
12084 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12184 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
12085 CHECK(!templ.IsEmpty()); 12185 CHECK(!templ.IsEmpty());
12086 LocalContext context; 12186 LocalContext context;
12087 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12187 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
12088 GenerateSomeGarbage(); 12188 GenerateSomeGarbage();
12089 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12189 context->Global()->Set(v8_str("o"), fun->NewInstance());
12090 v8::TryCatch try_catch; 12190 v8::TryCatch try_catch;
(...skipping 11 matching lines...) Expand all
12102 " }" 12202 " }"
12103 "}"); 12203 "}");
12104 CHECK(try_catch.HasCaught()); 12204 CHECK(try_catch.HasCaught());
12105 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"), 12205 CHECK_EQ(v8_str("TypeError: Object 333 has no method 'method'"),
12106 try_catch.Exception()->ToString()); 12206 try_catch.Exception()->ToString());
12107 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value()); 12207 CHECK_EQ(42, context->Global()->Get(v8_str("saved_result"))->Int32Value());
12108 } 12208 }
12109 12209
12110 12210
12111 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) { 12211 THREADED_PROFILED_TEST(CallICFastApi_SimpleSignature_TypeError) {
12112 v8::HandleScope scope(CcTest::isolate()); 12212 v8::Isolate* isolate = CcTest::isolate();
12113 v8::Handle<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(); 12213 v8::HandleScope scope(isolate);
12214 v8::Handle<v8::FunctionTemplate> fun_templ =
12215 v8::FunctionTemplate::New(isolate);
12114 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New( 12216 v8::Handle<v8::FunctionTemplate> method_templ = v8::FunctionTemplate::New(
12115 FastApiCallback_SimpleSignature, v8_str("method_data"), 12217 isolate, FastApiCallback_SimpleSignature, v8_str("method_data"),
12116 v8::Signature::New(CcTest::isolate(), fun_templ)); 12218 v8::Signature::New(isolate, fun_templ));
12117 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate(); 12219 v8::Handle<v8::ObjectTemplate> proto_templ = fun_templ->PrototypeTemplate();
12118 proto_templ->Set(v8_str("method"), method_templ); 12220 proto_templ->Set(v8_str("method"), method_templ);
12119 fun_templ->SetHiddenPrototype(true); 12221 fun_templ->SetHiddenPrototype(true);
12120 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate()); 12222 v8::Handle<v8::ObjectTemplate> templ(fun_templ->InstanceTemplate());
12121 CHECK(!templ.IsEmpty()); 12223 CHECK(!templ.IsEmpty());
12122 LocalContext context; 12224 LocalContext context;
12123 v8::Handle<v8::Function> fun = fun_templ->GetFunction(); 12225 v8::Handle<v8::Function> fun = fun_templ->GetFunction();
12124 GenerateSomeGarbage(); 12226 GenerateSomeGarbage();
12125 context->Global()->Set(v8_str("o"), fun->NewInstance()); 12227 context->Global()->Set(v8_str("o"), fun->NewInstance());
12126 v8::TryCatch try_catch; 12228 v8::TryCatch try_catch;
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
12451 templ->Set(CcTest::isolate(), "42", v8_num(42)); 12553 templ->Set(CcTest::isolate(), "42", v8_num(42));
12452 v8::Handle<v8::Object> obj = templ->NewInstance(); 12554 v8::Handle<v8::Object> obj = templ->NewInstance();
12453 context->Global()->Set(v8_str("obj"), obj); 12555 context->Global()->Set(v8_str("obj"), obj);
12454 v8::Handle<Value> value = CompileRun("obj[42]"); 12556 v8::Handle<Value> value = CompileRun("obj[42]");
12455 CHECK(value->IsInt32()); 12557 CHECK(value->IsInt32());
12456 CHECK_EQ(42, value->Int32Value()); 12558 CHECK_EQ(42, value->Int32Value());
12457 } 12559 }
12458 12560
12459 12561
12460 THREADED_TEST(NamedPropertyHandlerGetterAttributes) { 12562 THREADED_TEST(NamedPropertyHandlerGetterAttributes) {
12461 v8::HandleScope scope(CcTest::isolate()); 12563 v8::Isolate* isolate = CcTest::isolate();
12462 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12564 v8::HandleScope scope(isolate);
12565 v8::Handle<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
12463 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter); 12566 templ->InstanceTemplate()->SetNamedPropertyHandler(InterceptorLoadXICGetter);
12464 LocalContext env; 12567 LocalContext env;
12465 env->Global()->Set(v8_str("obj"), 12568 env->Global()->Set(v8_str("obj"),
12466 templ->GetFunction()->NewInstance()); 12569 templ->GetFunction()->NewInstance());
12467 ExpectTrue("obj.x === 42"); 12570 ExpectTrue("obj.x === 42");
12468 ExpectTrue("!obj.propertyIsEnumerable('x')"); 12571 ExpectTrue("!obj.propertyIsEnumerable('x')");
12469 } 12572 }
12470 12573
12471 12574
12472 static void ThrowingGetter(Local<String> name, 12575 static void ThrowingGetter(Local<String> name,
12473 const v8::PropertyCallbackInfo<v8::Value>& info) { 12576 const v8::PropertyCallbackInfo<v8::Value>& info) {
12474 ApiTestFuzzer::Fuzz(); 12577 ApiTestFuzzer::Fuzz();
12475 info.GetIsolate()->ThrowException(Handle<Value>()); 12578 info.GetIsolate()->ThrowException(Handle<Value>());
12476 info.GetReturnValue().SetUndefined(); 12579 info.GetReturnValue().SetUndefined();
12477 } 12580 }
12478 12581
12479 12582
12480 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) { 12583 THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
12481 LocalContext context; 12584 LocalContext context;
12482 HandleScope scope(context->GetIsolate()); 12585 HandleScope scope(context->GetIsolate());
12483 12586
12484 Local<FunctionTemplate> templ = FunctionTemplate::New(); 12587 Local<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
12485 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate(); 12588 Local<ObjectTemplate> instance_templ = templ->InstanceTemplate();
12486 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter); 12589 instance_templ->SetAccessor(v8_str("f"), ThrowingGetter);
12487 12590
12488 Local<Object> instance = templ->GetFunction()->NewInstance(); 12591 Local<Object> instance = templ->GetFunction()->NewInstance();
12489 12592
12490 Local<Object> another = Object::New(); 12593 Local<Object> another = Object::New();
12491 another->SetPrototype(instance); 12594 another->SetPrototype(instance);
12492 12595
12493 Local<Object> with_js_getter = CompileRun( 12596 Local<Object> with_js_getter = CompileRun(
12494 "o = {};\n" 12597 "o = {};\n"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
12564 static void WebKitLike(Handle<Message> message, Handle<Value> data) { 12667 static void WebKitLike(Handle<Message> message, Handle<Value> data) {
12565 Handle<String> errorMessageString = message->Get(); 12668 Handle<String> errorMessageString = message->Get();
12566 CHECK(!errorMessageString.IsEmpty()); 12669 CHECK(!errorMessageString.IsEmpty());
12567 message->GetStackTrace(); 12670 message->GetStackTrace();
12568 message->GetScriptResourceName(); 12671 message->GetScriptResourceName();
12569 } 12672 }
12570 12673
12571 12674
12572 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) { 12675 THREADED_TEST(ExceptionsDoNotPropagatePastTryCatch) {
12573 LocalContext context; 12676 LocalContext context;
12574 HandleScope scope(context->GetIsolate()); 12677 v8::Isolate* isolate = context->GetIsolate();
12678 HandleScope scope(isolate);
12575 12679
12576 Local<Function> func = 12680 Local<Function> func =
12577 FunctionTemplate::New(ThrowingCallbackWithTryCatch)->GetFunction(); 12681 FunctionTemplate::New(isolate,
12682 ThrowingCallbackWithTryCatch)->GetFunction();
12578 context->Global()->Set(v8_str("func"), func); 12683 context->Global()->Set(v8_str("func"), func);
12579 12684
12580 MessageCallback callbacks[] = 12685 MessageCallback callbacks[] =
12581 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch }; 12686 { NULL, WebKitLike, ThrowViaApi, ThrowFromJS, WithTryCatch };
12582 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) { 12687 for (unsigned i = 0; i < sizeof(callbacks)/sizeof(callbacks[0]); i++) {
12583 MessageCallback callback = callbacks[i]; 12688 MessageCallback callback = callbacks[i];
12584 if (callback != NULL) { 12689 if (callback != NULL) {
12585 V8::AddMessageListener(callback); 12690 V8::AddMessageListener(callback);
12586 } 12691 }
12587 // Some small number to control number of times message handler should 12692 // Some small number to control number of times message handler should
(...skipping 20 matching lines...) Expand all
12608 static void ChildGetter(Local<String> name, 12713 static void ChildGetter(Local<String> name,
12609 const v8::PropertyCallbackInfo<v8::Value>& info) { 12714 const v8::PropertyCallbackInfo<v8::Value>& info) {
12610 ApiTestFuzzer::Fuzz(); 12715 ApiTestFuzzer::Fuzz();
12611 info.GetReturnValue().Set(v8_num(42)); 12716 info.GetReturnValue().Set(v8_num(42));
12612 } 12717 }
12613 12718
12614 12719
12615 THREADED_TEST(Overriding) { 12720 THREADED_TEST(Overriding) {
12616 i::FLAG_es5_readonly = true; 12721 i::FLAG_es5_readonly = true;
12617 LocalContext context; 12722 LocalContext context;
12618 v8::HandleScope scope(context->GetIsolate()); 12723 v8::Isolate* isolate = context->GetIsolate();
12724 v8::HandleScope scope(isolate);
12619 12725
12620 // Parent template. 12726 // Parent template.
12621 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(); 12727 Local<v8::FunctionTemplate> parent_templ = v8::FunctionTemplate::New(isolate);
12622 Local<ObjectTemplate> parent_instance_templ = 12728 Local<ObjectTemplate> parent_instance_templ =
12623 parent_templ->InstanceTemplate(); 12729 parent_templ->InstanceTemplate();
12624 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter); 12730 parent_instance_templ->SetAccessor(v8_str("f"), ParentGetter);
12625 12731
12626 // Template that inherits from the parent template. 12732 // Template that inherits from the parent template.
12627 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(); 12733 Local<v8::FunctionTemplate> child_templ = v8::FunctionTemplate::New(isolate);
12628 Local<ObjectTemplate> child_instance_templ = 12734 Local<ObjectTemplate> child_instance_templ =
12629 child_templ->InstanceTemplate(); 12735 child_templ->InstanceTemplate();
12630 child_templ->Inherit(parent_templ); 12736 child_templ->Inherit(parent_templ);
12631 // Override 'f'. The child version of 'f' should get called for child 12737 // Override 'f'. The child version of 'f' should get called for child
12632 // instances. 12738 // instances.
12633 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter); 12739 child_instance_templ->SetAccessor(v8_str("f"), ChildGetter);
12634 // Add 'g' twice. The 'g' added last should get called for instances. 12740 // Add 'g' twice. The 'g' added last should get called for instances.
12635 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter); 12741 child_instance_templ->SetAccessor(v8_str("g"), ParentGetter);
12636 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter); 12742 child_instance_templ->SetAccessor(v8_str("g"), ChildGetter);
12637 12743
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
12671 12777
12672 12778
12673 static void IsConstructHandler( 12779 static void IsConstructHandler(
12674 const v8::FunctionCallbackInfo<v8::Value>& args) { 12780 const v8::FunctionCallbackInfo<v8::Value>& args) {
12675 ApiTestFuzzer::Fuzz(); 12781 ApiTestFuzzer::Fuzz();
12676 args.GetReturnValue().Set(args.IsConstructCall()); 12782 args.GetReturnValue().Set(args.IsConstructCall());
12677 } 12783 }
12678 12784
12679 12785
12680 THREADED_TEST(IsConstructCall) { 12786 THREADED_TEST(IsConstructCall) {
12681 v8::HandleScope scope(CcTest::isolate()); 12787 v8::Isolate* isolate = CcTest::isolate();
12788 v8::HandleScope scope(isolate);
12682 12789
12683 // Function template with call handler. 12790 // Function template with call handler.
12684 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12791 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
12685 templ->SetCallHandler(IsConstructHandler); 12792 templ->SetCallHandler(IsConstructHandler);
12686 12793
12687 LocalContext context; 12794 LocalContext context;
12688 12795
12689 context->Global()->Set(v8_str("f"), templ->GetFunction()); 12796 context->Global()->Set(v8_str("f"), templ->GetFunction());
12690 Local<Value> value = v8_compile("f()")->Run(); 12797 Local<Value> value = v8_compile("f()")->Run();
12691 CHECK(!value->BooleanValue()); 12798 CHECK(!value->BooleanValue());
12692 value = v8_compile("new f()")->Run(); 12799 value = v8_compile("new f()")->Run();
12693 CHECK(value->BooleanValue()); 12800 CHECK(value->BooleanValue());
12694 } 12801 }
12695 12802
12696 12803
12697 THREADED_TEST(ObjectProtoToString) { 12804 THREADED_TEST(ObjectProtoToString) {
12698 v8::HandleScope scope(CcTest::isolate()); 12805 v8::Isolate* isolate = CcTest::isolate();
12699 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(); 12806 v8::HandleScope scope(isolate);
12807 Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
12700 templ->SetClassName(v8_str("MyClass")); 12808 templ->SetClassName(v8_str("MyClass"));
12701 12809
12702 LocalContext context; 12810 LocalContext context;
12703 12811
12704 Local<String> customized_tostring = v8_str("customized toString"); 12812 Local<String> customized_tostring = v8_str("customized toString");
12705 12813
12706 // Replace Object.prototype.toString 12814 // Replace Object.prototype.toString
12707 v8_compile("Object.prototype.toString = function() {" 12815 v8_compile("Object.prototype.toString = function() {"
12708 " return 'customized toString';" 12816 " return 'customized toString';"
12709 "}")->Run(); 12817 "}")->Run();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
12950 v8::Handle<Value> value = CompileRun(code); 13058 v8::Handle<Value> value = CompileRun(code);
12951 CHECK(value.IsEmpty()); 13059 CHECK(value.IsEmpty());
12952 args.GetReturnValue().Set(v8_str("foo")); 13060 args.GetReturnValue().Set(v8_str("foo"));
12953 } 13061 }
12954 } 13062 }
12955 13063
12956 13064
12957 // These are locking tests that don't need to be run again 13065 // These are locking tests that don't need to be run again
12958 // as part of the locking aggregation tests. 13066 // as part of the locking aggregation tests.
12959 TEST(NestedLockers) { 13067 TEST(NestedLockers) {
12960 v8::Locker locker(CcTest::isolate()); 13068 v8::Isolate* isolate = CcTest::isolate();
12961 CHECK(v8::Locker::IsLocked(CcTest::isolate())); 13069 v8::Locker locker(isolate);
13070 CHECK(v8::Locker::IsLocked(isolate));
12962 LocalContext env; 13071 LocalContext env;
12963 v8::HandleScope scope(env->GetIsolate()); 13072 v8::HandleScope scope(env->GetIsolate());
12964 Local<v8::FunctionTemplate> fun_templ = v8::FunctionTemplate::New(ThrowInJS); 13073 Local<v8::FunctionTemplate> fun_templ =
13074 v8::FunctionTemplate::New(isolate, ThrowInJS);
12965 Local<Function> fun = fun_templ->GetFunction(); 13075 Local<Function> fun = fun_templ->GetFunction();
12966 env->Global()->Set(v8_str("throw_in_js"), fun); 13076 env->Global()->Set(v8_str("throw_in_js"), fun);
12967 Local<Script> script = v8_compile("(function () {" 13077 Local<Script> script = v8_compile("(function () {"
12968 " try {" 13078 " try {"
12969 " throw_in_js();" 13079 " throw_in_js();"
12970 " return 42;" 13080 " return 42;"
12971 " } catch (e) {" 13081 " } catch (e) {"
12972 " return e * 13;" 13082 " return e * 13;"
12973 " }" 13083 " }"
12974 "})();"); 13084 "})();");
12975 CHECK_EQ(91, script->Run()->Int32Value()); 13085 CHECK_EQ(91, script->Run()->Int32Value());
12976 } 13086 }
12977 13087
12978 13088
12979 // These are locking tests that don't need to be run again 13089 // These are locking tests that don't need to be run again
12980 // as part of the locking aggregation tests. 13090 // as part of the locking aggregation tests.
12981 TEST(NestedLockersNoTryCatch) { 13091 TEST(NestedLockersNoTryCatch) {
12982 v8::Locker locker(CcTest::isolate()); 13092 v8::Locker locker(CcTest::isolate());
12983 LocalContext env; 13093 LocalContext env;
12984 v8::HandleScope scope(env->GetIsolate()); 13094 v8::HandleScope scope(env->GetIsolate());
12985 Local<v8::FunctionTemplate> fun_templ = 13095 Local<v8::FunctionTemplate> fun_templ =
12986 v8::FunctionTemplate::New(ThrowInJSNoCatch); 13096 v8::FunctionTemplate::New(env->GetIsolate(), ThrowInJSNoCatch);
12987 Local<Function> fun = fun_templ->GetFunction(); 13097 Local<Function> fun = fun_templ->GetFunction();
12988 env->Global()->Set(v8_str("throw_in_js"), fun); 13098 env->Global()->Set(v8_str("throw_in_js"), fun);
12989 Local<Script> script = v8_compile("(function () {" 13099 Local<Script> script = v8_compile("(function () {"
12990 " try {" 13100 " try {"
12991 " throw_in_js();" 13101 " throw_in_js();"
12992 " return 42;" 13102 " return 42;"
12993 " } catch (e) {" 13103 " } catch (e) {"
12994 " return e * 13;" 13104 " return e * 13;"
12995 " }" 13105 " }"
12996 "})();"); 13106 "})();");
(...skipping 15 matching lines...) Expand all
13012 v8::Unlocker unlocker(CcTest::isolate()); 13122 v8::Unlocker unlocker(CcTest::isolate());
13013 } 13123 }
13014 13124
13015 13125
13016 THREADED_TEST(LockUnlockLock) { 13126 THREADED_TEST(LockUnlockLock) {
13017 { 13127 {
13018 v8::Locker locker(CcTest::isolate()); 13128 v8::Locker locker(CcTest::isolate());
13019 v8::HandleScope scope(CcTest::isolate()); 13129 v8::HandleScope scope(CcTest::isolate());
13020 LocalContext env; 13130 LocalContext env;
13021 Local<v8::FunctionTemplate> fun_templ = 13131 Local<v8::FunctionTemplate> fun_templ =
13022 v8::FunctionTemplate::New(UnlockForAMoment); 13132 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment);
13023 Local<Function> fun = fun_templ->GetFunction(); 13133 Local<Function> fun = fun_templ->GetFunction();
13024 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 13134 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
13025 Local<Script> script = v8_compile("(function () {" 13135 Local<Script> script = v8_compile("(function () {"
13026 " unlock_for_a_moment();" 13136 " unlock_for_a_moment();"
13027 " return 42;" 13137 " return 42;"
13028 "})();"); 13138 "})();");
13029 CHECK_EQ(42, script->Run()->Int32Value()); 13139 CHECK_EQ(42, script->Run()->Int32Value());
13030 } 13140 }
13031 { 13141 {
13032 v8::Locker locker(CcTest::isolate()); 13142 v8::Locker locker(CcTest::isolate());
13033 v8::HandleScope scope(CcTest::isolate()); 13143 v8::HandleScope scope(CcTest::isolate());
13034 LocalContext env; 13144 LocalContext env;
13035 Local<v8::FunctionTemplate> fun_templ = 13145 Local<v8::FunctionTemplate> fun_templ =
13036 v8::FunctionTemplate::New(UnlockForAMoment); 13146 v8::FunctionTemplate::New(CcTest::isolate(), UnlockForAMoment);
13037 Local<Function> fun = fun_templ->GetFunction(); 13147 Local<Function> fun = fun_templ->GetFunction();
13038 env->Global()->Set(v8_str("unlock_for_a_moment"), fun); 13148 env->Global()->Set(v8_str("unlock_for_a_moment"), fun);
13039 Local<Script> script = v8_compile("(function () {" 13149 Local<Script> script = v8_compile("(function () {"
13040 " unlock_for_a_moment();" 13150 " unlock_for_a_moment();"
13041 " return 42;" 13151 " return 42;"
13042 "})();"); 13152 "})();");
13043 CHECK_EQ(42, script->Run()->Int32Value()); 13153 CHECK_EQ(42, script->Run()->Int32Value());
13044 } 13154 }
13045 } 13155 }
13046 13156
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
13533 return invocations; 13643 return invocations;
13534 } 13644 }
13535 13645
13536 13646
13537 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) { 13647 void SetFunctionEntryHookTest::RunLoopInNewEnv(v8::Isolate* isolate) {
13538 v8::HandleScope outer(isolate); 13648 v8::HandleScope outer(isolate);
13539 v8::Local<Context> env = Context::New(isolate); 13649 v8::Local<Context> env = Context::New(isolate);
13540 env->Enter(); 13650 env->Enter();
13541 13651
13542 Local<ObjectTemplate> t = ObjectTemplate::New(); 13652 Local<ObjectTemplate> t = ObjectTemplate::New();
13543 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(RuntimeCallback)); 13653 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(isolate, RuntimeCallback));
13544 env->Global()->Set(v8_str("obj"), t->NewInstance()); 13654 env->Global()->Set(v8_str("obj"), t->NewInstance());
13545 13655
13546 const char* script = 13656 const char* script =
13547 "function bar() {\n" 13657 "function bar() {\n"
13548 " var sum = 0;\n" 13658 " var sum = 0;\n"
13549 " for (i = 0; i < 100; ++i)\n" 13659 " for (i = 0; i < 100; ++i)\n"
13550 " sum = foo(i);\n" 13660 " sum = foo(i);\n"
13551 " return sum;\n" 13661 " return sum;\n"
13552 "}\n" 13662 "}\n"
13553 "function foo(i) { return i * i; }\n" 13663 "function foo(i) { return i * i; }\n"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
14021 14131
14022 static void FunctionNameCallback( 14132 static void FunctionNameCallback(
14023 const v8::FunctionCallbackInfo<v8::Value>& args) { 14133 const v8::FunctionCallbackInfo<v8::Value>& args) {
14024 ApiTestFuzzer::Fuzz(); 14134 ApiTestFuzzer::Fuzz();
14025 args.GetReturnValue().Set(v8_num(42)); 14135 args.GetReturnValue().Set(v8_num(42));
14026 } 14136 }
14027 14137
14028 14138
14029 THREADED_TEST(CallbackFunctionName) { 14139 THREADED_TEST(CallbackFunctionName) {
14030 LocalContext context; 14140 LocalContext context;
14031 v8::HandleScope scope(context->GetIsolate()); 14141 v8::Isolate* isolate = context->GetIsolate();
14142 v8::HandleScope scope(isolate);
14032 Local<ObjectTemplate> t = ObjectTemplate::New(); 14143 Local<ObjectTemplate> t = ObjectTemplate::New();
14033 t->Set(v8_str("asdf"), v8::FunctionTemplate::New(FunctionNameCallback)); 14144 t->Set(v8_str("asdf"),
14145 v8::FunctionTemplate::New(isolate, FunctionNameCallback));
14034 context->Global()->Set(v8_str("obj"), t->NewInstance()); 14146 context->Global()->Set(v8_str("obj"), t->NewInstance());
14035 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name"); 14147 v8::Handle<v8::Value> value = CompileRun("obj.asdf.name");
14036 CHECK(value->IsString()); 14148 CHECK(value->IsString());
14037 v8::String::Utf8Value name(value); 14149 v8::String::Utf8Value name(value);
14038 CHECK_EQ("asdf", *name); 14150 CHECK_EQ("asdf", *name);
14039 } 14151 }
14040 14152
14041 14153
14042 THREADED_TEST(DateAccess) { 14154 THREADED_TEST(DateAccess) {
14043 LocalContext context; 14155 LocalContext context;
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
15201 15313
15202 // Allow cross-domain access. 15314 // Allow cross-domain access.
15203 Local<String> token = v8_str("<security token>"); 15315 Local<String> token = v8_str("<security token>");
15204 calling_context0->SetSecurityToken(token); 15316 calling_context0->SetSecurityToken(token);
15205 calling_context1->SetSecurityToken(token); 15317 calling_context1->SetSecurityToken(token);
15206 calling_context2->SetSecurityToken(token); 15318 calling_context2->SetSecurityToken(token);
15207 15319
15208 // Create an object with a C++ callback in context0. 15320 // Create an object with a C++ callback in context0.
15209 calling_context0->Enter(); 15321 calling_context0->Enter();
15210 Local<v8::FunctionTemplate> callback_templ = 15322 Local<v8::FunctionTemplate> callback_templ =
15211 v8::FunctionTemplate::New(GetCallingContextCallback); 15323 v8::FunctionTemplate::New(isolate, GetCallingContextCallback);
15212 calling_context0->Global()->Set(v8_str("callback"), 15324 calling_context0->Global()->Set(v8_str("callback"),
15213 callback_templ->GetFunction()); 15325 callback_templ->GetFunction());
15214 calling_context0->Exit(); 15326 calling_context0->Exit();
15215 15327
15216 // Expose context0 in context1 and set up a function that calls the 15328 // Expose context0 in context1 and set up a function that calls the
15217 // callback function. 15329 // callback function.
15218 calling_context1->Enter(); 15330 calling_context1->Enter();
15219 calling_context1->Global()->Set(v8_str("context0"), 15331 calling_context1->Global()->Set(v8_str("context0"),
15220 calling_context0->Global()); 15332 calling_context0->Global());
15221 CompileRun("function f() { context0.callback() }"); 15333 CompileRun("function f() { context0.callback() }");
(...skipping 26 matching lines...) Expand all
15248 } 15360 }
15249 15361
15250 15362
15251 // Regression test for issue 398. 15363 // Regression test for issue 398.
15252 // If a function is added to an object, creating a constant function 15364 // If a function is added to an object, creating a constant function
15253 // field, and the result is cloned, replacing the constant function on the 15365 // field, and the result is cloned, replacing the constant function on the
15254 // original should not affect the clone. 15366 // original should not affect the clone.
15255 // See http://code.google.com/p/v8/issues/detail?id=398 15367 // See http://code.google.com/p/v8/issues/detail?id=398
15256 THREADED_TEST(ReplaceConstantFunction) { 15368 THREADED_TEST(ReplaceConstantFunction) {
15257 LocalContext context; 15369 LocalContext context;
15258 v8::HandleScope scope(context->GetIsolate()); 15370 v8::Isolate* isolate = context->GetIsolate();
15371 v8::HandleScope scope(isolate);
15259 v8::Handle<v8::Object> obj = v8::Object::New(); 15372 v8::Handle<v8::Object> obj = v8::Object::New();
15260 v8::Handle<v8::FunctionTemplate> func_templ = v8::FunctionTemplate::New(); 15373 v8::Handle<v8::FunctionTemplate> func_templ =
15374 v8::FunctionTemplate::New(isolate);
15261 v8::Handle<v8::String> foo_string = 15375 v8::Handle<v8::String> foo_string =
15262 v8::String::NewFromUtf8(context->GetIsolate(), "foo"); 15376 v8::String::NewFromUtf8(isolate, "foo");
15263 obj->Set(foo_string, func_templ->GetFunction()); 15377 obj->Set(foo_string, func_templ->GetFunction());
15264 v8::Handle<v8::Object> obj_clone = obj->Clone(); 15378 v8::Handle<v8::Object> obj_clone = obj->Clone();
15265 obj_clone->Set(foo_string, 15379 obj_clone->Set(foo_string,
15266 v8::String::NewFromUtf8(context->GetIsolate(), "Hello")); 15380 v8::String::NewFromUtf8(isolate, "Hello"));
15267 CHECK(!obj->Get(foo_string)->IsUndefined()); 15381 CHECK(!obj->Get(foo_string)->IsUndefined());
15268 } 15382 }
15269 15383
15270 15384
15271 static void CheckElementValue(i::Isolate* isolate, 15385 static void CheckElementValue(i::Isolate* isolate,
15272 int expected, 15386 int expected,
15273 i::Handle<i::Object> obj, 15387 i::Handle<i::Object> obj,
15274 int offset) { 15388 int offset) {
15275 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked(); 15389 i::Object* element = obj->GetElement(isolate, offset)->ToObjectChecked();
15276 CHECK_EQ(expected, i::Smi::cast(element)->value()); 15390 CHECK_EQ(expected, i::Smi::cast(element)->value());
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
16658 16772
16659 CHECK(stackTrace->AsArray()->IsArray()); 16773 CHECK(stackTrace->AsArray()->IsArray());
16660 } 16774 }
16661 } 16775 }
16662 16776
16663 16777
16664 // Tests the C++ StackTrace API. 16778 // Tests the C++ StackTrace API.
16665 // TODO(3074796): Reenable this as a THREADED_TEST once it passes. 16779 // TODO(3074796): Reenable this as a THREADED_TEST once it passes.
16666 // THREADED_TEST(CaptureStackTrace) { 16780 // THREADED_TEST(CaptureStackTrace) {
16667 TEST(CaptureStackTrace) { 16781 TEST(CaptureStackTrace) {
16668 v8::HandleScope scope(CcTest::isolate()); 16782 v8::Isolate* isolate = CcTest::isolate();
16783 v8::HandleScope scope(isolate);
16669 v8::Handle<v8::String> origin = 16784 v8::Handle<v8::String> origin =
16670 v8::String::NewFromUtf8(CcTest::isolate(), "capture-stack-trace-test"); 16785 v8::String::NewFromUtf8(isolate, "capture-stack-trace-test");
16671 Local<ObjectTemplate> templ = ObjectTemplate::New(); 16786 Local<ObjectTemplate> templ = ObjectTemplate::New();
16672 templ->Set(v8_str("AnalyzeStackInNativeCode"), 16787 templ->Set(v8_str("AnalyzeStackInNativeCode"),
16673 v8::FunctionTemplate::New(AnalyzeStackInNativeCode)); 16788 v8::FunctionTemplate::New(isolate, AnalyzeStackInNativeCode));
16674 LocalContext context(0, templ); 16789 LocalContext context(0, templ);
16675 16790
16676 // Test getting OVERVIEW information. Should ignore information that is not 16791 // Test getting OVERVIEW information. Should ignore information that is not
16677 // script name, function name, line number, and column offset. 16792 // script name, function name, line number, and column offset.
16678 const char *overview_source = 16793 const char *overview_source =
16679 "function bar() {\n" 16794 "function bar() {\n"
16680 " var y; AnalyzeStackInNativeCode(1);\n" 16795 " var y; AnalyzeStackInNativeCode(1);\n"
16681 "}\n" 16796 "}\n"
16682 "function foo() {\n" 16797 "function foo() {\n"
16683 "\n" 16798 "\n"
16684 " bar();\n" 16799 " bar();\n"
16685 "}\n" 16800 "}\n"
16686 "var x;eval('new foo();');"; 16801 "var x;eval('new foo();');";
16687 v8::Handle<v8::String> overview_src = 16802 v8::Handle<v8::String> overview_src =
16688 v8::String::NewFromUtf8(CcTest::isolate(), overview_source); 16803 v8::String::NewFromUtf8(isolate, overview_source);
16689 v8::Handle<Value> overview_result( 16804 v8::Handle<Value> overview_result(
16690 v8::Script::New(overview_src, origin)->Run()); 16805 v8::Script::New(overview_src, origin)->Run());
16691 CHECK(!overview_result.IsEmpty()); 16806 CHECK(!overview_result.IsEmpty());
16692 CHECK(overview_result->IsObject()); 16807 CHECK(overview_result->IsObject());
16693 16808
16694 // Test getting DETAILED information. 16809 // Test getting DETAILED information.
16695 const char *detailed_source = 16810 const char *detailed_source =
16696 "function bat() {AnalyzeStackInNativeCode(2);\n" 16811 "function bat() {AnalyzeStackInNativeCode(2);\n"
16697 "}\n" 16812 "}\n"
16698 "\n" 16813 "\n"
16699 "function baz() {\n" 16814 "function baz() {\n"
16700 " bat();\n" 16815 " bat();\n"
16701 "}\n" 16816 "}\n"
16702 "eval('new baz();');"; 16817 "eval('new baz();');";
16703 v8::Handle<v8::String> detailed_src = 16818 v8::Handle<v8::String> detailed_src =
16704 v8::String::NewFromUtf8(CcTest::isolate(), detailed_source); 16819 v8::String::NewFromUtf8(isolate, detailed_source);
16705 // Make the script using a non-zero line and column offset. 16820 // Make the script using a non-zero line and column offset.
16706 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3); 16821 v8::Handle<v8::Integer> line_offset = v8::Integer::New(3);
16707 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5); 16822 v8::Handle<v8::Integer> column_offset = v8::Integer::New(5);
16708 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset); 16823 v8::ScriptOrigin detailed_origin(origin, line_offset, column_offset);
16709 v8::Handle<v8::Script> detailed_script( 16824 v8::Handle<v8::Script> detailed_script(
16710 v8::Script::New(detailed_src, &detailed_origin)); 16825 v8::Script::New(detailed_src, &detailed_origin));
16711 v8::Handle<Value> detailed_result(detailed_script->Run()); 16826 v8::Handle<Value> detailed_result(detailed_script->Run());
16712 CHECK(!detailed_result.IsEmpty()); 16827 CHECK(!detailed_result.IsEmpty());
16713 CHECK(detailed_result->IsObject()); 16828 CHECK(detailed_result->IsObject());
16714 } 16829 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
16910 for (int i = 0; i < 3; i++) { 17025 for (int i = 0; i < 3; i++) {
16911 v8::Handle<v8::String> name = 17026 v8::Handle<v8::String> name =
16912 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL(); 17027 stackTrace->GetFrame(i)->GetScriptNameOrSourceURL();
16913 CHECK(!name.IsEmpty()); 17028 CHECK(!name.IsEmpty());
16914 CHECK_EQ(url, name); 17029 CHECK_EQ(url, name);
16915 } 17030 }
16916 } 17031 }
16917 17032
16918 17033
16919 TEST(SourceURLInStackTrace) { 17034 TEST(SourceURLInStackTrace) {
16920 v8::HandleScope scope(CcTest::isolate()); 17035 v8::Isolate* isolate = CcTest::isolate();
17036 v8::HandleScope scope(isolate);
16921 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17037 Local<ObjectTemplate> templ = ObjectTemplate::New();
16922 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"), 17038 templ->Set(v8_str("AnalyzeStackOfEvalWithSourceURL"),
16923 v8::FunctionTemplate::New(AnalyzeStackOfEvalWithSourceURL)); 17039 v8::FunctionTemplate::New(isolate,
17040 AnalyzeStackOfEvalWithSourceURL));
16924 LocalContext context(0, templ); 17041 LocalContext context(0, templ);
16925 17042
16926 const char *source = 17043 const char *source =
16927 "function outer() {\n" 17044 "function outer() {\n"
16928 "function bar() {\n" 17045 "function bar() {\n"
16929 " AnalyzeStackOfEvalWithSourceURL();\n" 17046 " AnalyzeStackOfEvalWithSourceURL();\n"
16930 "}\n" 17047 "}\n"
16931 "function foo() {\n" 17048 "function foo() {\n"
16932 "\n" 17049 "\n"
16933 " bar();\n" 17050 " bar();\n"
(...skipping 18 matching lines...) Expand all
16952 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace( 17069 v8::Handle<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
16953 args.GetIsolate(), 10, v8::StackTrace::kScriptId); 17070 args.GetIsolate(), 10, v8::StackTrace::kScriptId);
16954 CHECK_EQ(2, stackTrace->GetFrameCount()); 17071 CHECK_EQ(2, stackTrace->GetFrameCount());
16955 for (int i = 0; i < 2; i++) { 17072 for (int i = 0; i < 2; i++) {
16956 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId(); 17073 scriptIdInStack[i] = stackTrace->GetFrame(i)->GetScriptId();
16957 } 17074 }
16958 } 17075 }
16959 17076
16960 17077
16961 TEST(ScriptIdInStackTrace) { 17078 TEST(ScriptIdInStackTrace) {
16962 v8::HandleScope scope(CcTest::isolate()); 17079 v8::Isolate* isolate = CcTest::isolate();
17080 v8::HandleScope scope(isolate);
16963 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17081 Local<ObjectTemplate> templ = ObjectTemplate::New();
16964 templ->Set(v8_str("AnalyzeScriptIdInStack"), 17082 templ->Set(v8_str("AnalyzeScriptIdInStack"),
16965 v8::FunctionTemplate::New(AnalyzeScriptIdInStack)); 17083 v8::FunctionTemplate::New(isolate, AnalyzeScriptIdInStack));
16966 LocalContext context(0, templ); 17084 LocalContext context(0, templ);
16967 17085
16968 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8( 17086 v8::Handle<v8::String> scriptSource = v8::String::NewFromUtf8(
16969 CcTest::isolate(), 17087 isolate,
16970 "function foo() {\n" 17088 "function foo() {\n"
16971 " AnalyzeScriptIdInStack();" 17089 " AnalyzeScriptIdInStack();"
16972 "}\n" 17090 "}\n"
16973 "foo();\n"); 17091 "foo();\n");
16974 v8::ScriptOrigin origin = 17092 v8::ScriptOrigin origin =
16975 v8::ScriptOrigin(v8::String::NewFromUtf8(CcTest::isolate(), "test")); 17093 v8::ScriptOrigin(v8::String::NewFromUtf8(isolate, "test"));
16976 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin)); 17094 v8::Local<v8::Script> script(v8::Script::Compile(scriptSource, &origin));
16977 script->Run(); 17095 script->Run();
16978 for (int i = 0; i < 2; i++) { 17096 for (int i = 0; i < 2; i++) {
16979 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo); 17097 CHECK(scriptIdInStack[i] != v8::Message::kNoScriptIdInfo);
16980 CHECK_EQ(scriptIdInStack[i], script->GetId()); 17098 CHECK_EQ(scriptIdInStack[i], script->GetId());
16981 } 17099 }
16982 } 17100 }
16983 17101
16984 17102
16985 void AnalyzeStackOfInlineScriptWithSourceURL( 17103 void AnalyzeStackOfInlineScriptWithSourceURL(
(...skipping 10 matching lines...) Expand all
16996 CHECK_EQ(url, name); 17114 CHECK_EQ(url, name);
16997 } 17115 }
16998 } 17116 }
16999 17117
17000 17118
17001 TEST(InlineScriptWithSourceURLInStackTrace) { 17119 TEST(InlineScriptWithSourceURLInStackTrace) {
17002 v8::HandleScope scope(CcTest::isolate()); 17120 v8::HandleScope scope(CcTest::isolate());
17003 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17121 Local<ObjectTemplate> templ = ObjectTemplate::New();
17004 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"), 17122 templ->Set(v8_str("AnalyzeStackOfInlineScriptWithSourceURL"),
17005 v8::FunctionTemplate::New( 17123 v8::FunctionTemplate::New(
17006 AnalyzeStackOfInlineScriptWithSourceURL)); 17124 CcTest::isolate(), AnalyzeStackOfInlineScriptWithSourceURL));
17007 LocalContext context(0, templ); 17125 LocalContext context(0, templ);
17008 17126
17009 const char *source = 17127 const char *source =
17010 "function outer() {\n" 17128 "function outer() {\n"
17011 "function bar() {\n" 17129 "function bar() {\n"
17012 " AnalyzeStackOfInlineScriptWithSourceURL();\n" 17130 " AnalyzeStackOfInlineScriptWithSourceURL();\n"
17013 "}\n" 17131 "}\n"
17014 "function foo() {\n" 17132 "function foo() {\n"
17015 "\n" 17133 "\n"
17016 " bar();\n" 17134 " bar();\n"
(...skipping 24 matching lines...) Expand all
17041 CHECK_EQ(url, name); 17159 CHECK_EQ(url, name);
17042 } 17160 }
17043 } 17161 }
17044 17162
17045 17163
17046 TEST(DynamicWithSourceURLInStackTrace) { 17164 TEST(DynamicWithSourceURLInStackTrace) {
17047 v8::HandleScope scope(CcTest::isolate()); 17165 v8::HandleScope scope(CcTest::isolate());
17048 Local<ObjectTemplate> templ = ObjectTemplate::New(); 17166 Local<ObjectTemplate> templ = ObjectTemplate::New();
17049 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"), 17167 templ->Set(v8_str("AnalyzeStackOfDynamicScriptWithSourceURL"),
17050 v8::FunctionTemplate::New( 17168 v8::FunctionTemplate::New(
17051 AnalyzeStackOfDynamicScriptWithSourceURL)); 17169 CcTest::isolate(), AnalyzeStackOfDynamicScriptWithSourceURL));
17052 LocalContext context(0, templ); 17170 LocalContext context(0, templ);
17053 17171
17054 const char *source = 17172 const char *source =
17055 "function outer() {\n" 17173 "function outer() {\n"
17056 "function bar() {\n" 17174 "function bar() {\n"
17057 " AnalyzeStackOfDynamicScriptWithSourceURL();\n" 17175 " AnalyzeStackOfDynamicScriptWithSourceURL();\n"
17058 "}\n" 17176 "}\n"
17059 "function foo() {\n" 17177 "function foo() {\n"
17060 "\n" 17178 "\n"
17061 " bar();\n" 17179 " bar();\n"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
17215 17333
17216 // Set stack limit. 17334 // Set stack limit.
17217 v8::ResourceConstraints constraints; 17335 v8::ResourceConstraints constraints;
17218 constraints.set_stack_limit(set_limit); 17336 constraints.set_stack_limit(set_limit);
17219 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); 17337 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
17220 17338
17221 // Execute a script. 17339 // Execute a script.
17222 LocalContext env; 17340 LocalContext env;
17223 v8::HandleScope scope(env->GetIsolate()); 17341 v8::HandleScope scope(env->GetIsolate());
17224 Local<v8::FunctionTemplate> fun_templ = 17342 Local<v8::FunctionTemplate> fun_templ =
17225 v8::FunctionTemplate::New(GetStackLimitCallback); 17343 v8::FunctionTemplate::New(env->GetIsolate(), GetStackLimitCallback);
17226 Local<Function> fun = fun_templ->GetFunction(); 17344 Local<Function> fun = fun_templ->GetFunction();
17227 env->Global()->Set(v8_str("get_stack_limit"), fun); 17345 env->Global()->Set(v8_str("get_stack_limit"), fun);
17228 CompileRun("get_stack_limit();"); 17346 CompileRun("get_stack_limit();");
17229 17347
17230 CHECK(stack_limit == set_limit); 17348 CHECK(stack_limit == set_limit);
17231 } 17349 }
17232 17350
17233 17351
17234 TEST(SetResourceConstraintsInThread) { 17352 TEST(SetResourceConstraintsInThread) {
17235 uint32_t* set_limit; 17353 uint32_t* set_limit;
17236 { 17354 {
17237 v8::Locker locker(CcTest::isolate()); 17355 v8::Locker locker(CcTest::isolate());
17238 set_limit = ComputeStackLimit(stack_breathing_room); 17356 set_limit = ComputeStackLimit(stack_breathing_room);
17239 17357
17240 // Set stack limit. 17358 // Set stack limit.
17241 v8::ResourceConstraints constraints; 17359 v8::ResourceConstraints constraints;
17242 constraints.set_stack_limit(set_limit); 17360 constraints.set_stack_limit(set_limit);
17243 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints)); 17361 CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
17244 17362
17245 // Execute a script. 17363 // Execute a script.
17246 v8::HandleScope scope(CcTest::isolate()); 17364 v8::HandleScope scope(CcTest::isolate());
17247 LocalContext env; 17365 LocalContext env;
17248 Local<v8::FunctionTemplate> fun_templ = 17366 Local<v8::FunctionTemplate> fun_templ =
17249 v8::FunctionTemplate::New(GetStackLimitCallback); 17367 v8::FunctionTemplate::New(CcTest::isolate(), GetStackLimitCallback);
17250 Local<Function> fun = fun_templ->GetFunction(); 17368 Local<Function> fun = fun_templ->GetFunction();
17251 env->Global()->Set(v8_str("get_stack_limit"), fun); 17369 env->Global()->Set(v8_str("get_stack_limit"), fun);
17252 CompileRun("get_stack_limit();"); 17370 CompileRun("get_stack_limit();");
17253 17371
17254 CHECK(stack_limit == set_limit); 17372 CHECK(stack_limit == set_limit);
17255 } 17373 }
17256 { 17374 {
17257 v8::Locker locker(CcTest::isolate()); 17375 v8::Locker locker(CcTest::isolate());
17258 CHECK(stack_limit == set_limit); 17376 CHECK(stack_limit == set_limit);
17259 } 17377 }
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
17540 v8::Handle<v8::String> str(args[0]->ToString()); 17658 v8::Handle<v8::String> str(args[0]->ToString());
17541 USE(str); 17659 USE(str);
17542 if (tc.HasCaught()) 17660 if (tc.HasCaught())
17543 tc.ReThrow(); 17661 tc.ReThrow();
17544 } 17662 }
17545 17663
17546 17664
17547 // Test that an exception can be propagated down through a spaghetti 17665 // Test that an exception can be propagated down through a spaghetti
17548 // stack using ReThrow. 17666 // stack using ReThrow.
17549 THREADED_TEST(SpaghettiStackReThrow) { 17667 THREADED_TEST(SpaghettiStackReThrow) {
17550 v8::HandleScope scope(CcTest::isolate()); 17668 v8::Isolate* isolate = CcTest::isolate();
17669 v8::HandleScope scope(isolate);
17551 LocalContext context; 17670 LocalContext context;
17552 context->Global()->Set( 17671 context->Global()->Set(
17553 v8::String::NewFromUtf8(CcTest::isolate(), "s"), 17672 v8::String::NewFromUtf8(isolate, "s"),
17554 v8::FunctionTemplate::New(SpaghettiIncident)->GetFunction()); 17673 v8::FunctionTemplate::New(isolate, SpaghettiIncident)->GetFunction());
17555 v8::TryCatch try_catch; 17674 v8::TryCatch try_catch;
17556 CompileRun( 17675 CompileRun(
17557 "var i = 0;" 17676 "var i = 0;"
17558 "var o = {" 17677 "var o = {"
17559 " toString: function () {" 17678 " toString: function () {"
17560 " if (i == 10) {" 17679 " if (i == 10) {"
17561 " throw 'Hey!';" 17680 " throw 'Hey!';"
17562 " } else {" 17681 " } else {"
17563 " i++;" 17682 " i++;"
17564 " return s(o);" 17683 " return s(o);"
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
19225 Set(v8_str("context_id"), v8::Integer::New(id)); 19344 Set(v8_str("context_id"), v8::Integer::New(id));
19226 } 19345 }
19227 19346
19228 19347
19229 static void CheckContextId(v8::Handle<Object> object, int expected) { 19348 static void CheckContextId(v8::Handle<Object> object, int expected) {
19230 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value()); 19349 CHECK_EQ(expected, object->Get(v8_str("context_id"))->Int32Value());
19231 } 19350 }
19232 19351
19233 19352
19234 THREADED_TEST(CreationContext) { 19353 THREADED_TEST(CreationContext) {
19235 HandleScope handle_scope(CcTest::isolate()); 19354 v8::Isolate* isolate = CcTest::isolate();
19236 Handle<Context> context1 = Context::New(CcTest::isolate()); 19355 HandleScope handle_scope(isolate);
19356 Handle<Context> context1 = Context::New(isolate);
19237 InstallContextId(context1, 1); 19357 InstallContextId(context1, 1);
19238 Handle<Context> context2 = Context::New(CcTest::isolate()); 19358 Handle<Context> context2 = Context::New(isolate);
19239 InstallContextId(context2, 2); 19359 InstallContextId(context2, 2);
19240 Handle<Context> context3 = Context::New(CcTest::isolate()); 19360 Handle<Context> context3 = Context::New(isolate);
19241 InstallContextId(context3, 3); 19361 InstallContextId(context3, 3);
19242 19362
19243 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); 19363 Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(isolate);
19244 19364
19245 Local<Object> object1; 19365 Local<Object> object1;
19246 Local<Function> func1; 19366 Local<Function> func1;
19247 { 19367 {
19248 Context::Scope scope(context1); 19368 Context::Scope scope(context1);
19249 object1 = Object::New(); 19369 object1 = Object::New();
19250 func1 = tmpl->GetFunction(); 19370 func1 = tmpl->GetFunction();
19251 } 19371 }
19252 19372
19253 Local<Object> object2; 19373 Local<Object> object2;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
19553 CHECK(expected_message->Equals(actual_message)); 19673 CHECK(expected_message->Equals(actual_message));
19554 } 19674 }
19555 19675
19556 19676
19557 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) { 19677 static void NonObjectThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
19558 } 19678 }
19559 19679
19560 19680
19561 THREADED_TEST(CallAPIFunctionOnNonObject) { 19681 THREADED_TEST(CallAPIFunctionOnNonObject) {
19562 LocalContext context; 19682 LocalContext context;
19563 v8::HandleScope scope(context->GetIsolate()); 19683 v8::Isolate* isolate = context->GetIsolate();
19564 Handle<FunctionTemplate> templ = v8::FunctionTemplate::New(NonObjectThis); 19684 v8::HandleScope scope(isolate);
19685 Handle<FunctionTemplate> templ =
19686 v8::FunctionTemplate::New(isolate, NonObjectThis);
19565 Handle<Function> function = templ->GetFunction(); 19687 Handle<Function> function = templ->GetFunction();
19566 context->Global()->Set(v8_str("f"), function); 19688 context->Global()->Set(v8_str("f"), function);
19567 TryCatch try_catch; 19689 TryCatch try_catch;
19568 CompileRun("f.call(2)"); 19690 CompileRun("f.call(2)");
19569 } 19691 }
19570 19692
19571 19693
19572 // Regression test for issue 1470. 19694 // Regression test for issue 1470.
19573 THREADED_TEST(ReadOnlyIndexedProperties) { 19695 THREADED_TEST(ReadOnlyIndexedProperties) {
19574 v8::HandleScope scope(CcTest::isolate()); 19696 v8::HandleScope scope(CcTest::isolate());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
19640 HandleScope scope(isolate); 19762 HandleScope scope(isolate);
19641 19763
19642 // Template for object with security check. 19764 // Template for object with security check.
19643 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New(); 19765 Local<ObjectTemplate> no_proto_template = v8::ObjectTemplate::New();
19644 // We don't do indexing, so any callback can be used for that. 19766 // We don't do indexing, so any callback can be used for that.
19645 no_proto_template->SetAccessCheckCallbacks( 19767 no_proto_template->SetAccessCheckCallbacks(
19646 BlockProtoNamedSecurityTestCallback, 19768 BlockProtoNamedSecurityTestCallback,
19647 IndexedSecurityTestCallback); 19769 IndexedSecurityTestCallback);
19648 19770
19649 // Templates for objects with hidden prototypes and possibly security check. 19771 // Templates for objects with hidden prototypes and possibly security check.
19650 Local<FunctionTemplate> hidden_proto_template = v8::FunctionTemplate::New(); 19772 Local<FunctionTemplate> hidden_proto_template =
19773 v8::FunctionTemplate::New(isolate);
19651 hidden_proto_template->SetHiddenPrototype(true); 19774 hidden_proto_template->SetHiddenPrototype(true);
19652 19775
19653 Local<FunctionTemplate> protected_hidden_proto_template = 19776 Local<FunctionTemplate> protected_hidden_proto_template =
19654 v8::FunctionTemplate::New(); 19777 v8::FunctionTemplate::New(isolate);
19655 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks( 19778 protected_hidden_proto_template->InstanceTemplate()->SetAccessCheckCallbacks(
19656 BlockProtoNamedSecurityTestCallback, 19779 BlockProtoNamedSecurityTestCallback,
19657 IndexedSecurityTestCallback); 19780 IndexedSecurityTestCallback);
19658 protected_hidden_proto_template->SetHiddenPrototype(true); 19781 protected_hidden_proto_template->SetHiddenPrototype(true);
19659 19782
19660 // Context for "foreign" objects used in test. 19783 // Context for "foreign" objects used in test.
19661 Local<Context> context = v8::Context::New(isolate); 19784 Local<Context> context = v8::Context::New(isolate);
19662 context->Enter(); 19785 context->Enter();
19663 19786
19664 // Plain object, no security check. 19787 // Plain object, no security check.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
19720 CHECK(result5->Equals( 19843 CHECK(result5->Equals(
19721 object_with_hidden->GetPrototype()->ToObject()->GetPrototype())); 19844 object_with_hidden->GetPrototype()->ToObject()->GetPrototype()));
19722 19845
19723 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)"); 19846 Local<Value> result6 = CompileRun("Object.getPrototypeOf(phidden)");
19724 CHECK(result6->Equals(Undefined(isolate))); 19847 CHECK(result6->Equals(Undefined(isolate)));
19725 } 19848 }
19726 19849
19727 19850
19728 THREADED_TEST(Regress125988) { 19851 THREADED_TEST(Regress125988) {
19729 v8::HandleScope scope(CcTest::isolate()); 19852 v8::HandleScope scope(CcTest::isolate());
19730 Handle<FunctionTemplate> intercept = FunctionTemplate::New(); 19853 Handle<FunctionTemplate> intercept = FunctionTemplate::New(CcTest::isolate());
19731 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter); 19854 AddInterceptor(intercept, EmptyInterceptorGetter, EmptyInterceptorSetter);
19732 LocalContext env; 19855 LocalContext env;
19733 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction()); 19856 env->Global()->Set(v8_str("Intercept"), intercept->GetFunction());
19734 CompileRun("var a = new Object();" 19857 CompileRun("var a = new Object();"
19735 "var b = new Intercept();" 19858 "var b = new Intercept();"
19736 "var c = new Object();" 19859 "var c = new Object();"
19737 "c.__proto__ = b;" 19860 "c.__proto__ = b;"
19738 "b.__proto__ = a;" 19861 "b.__proto__ = a;"
19739 "a.x = 23;" 19862 "a.x = 23;"
19740 "for (var i = 0; i < 3; i++) c.x;"); 19863 "for (var i = 0; i < 3; i++) c.x;");
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
19882 i::OS::Print("Recursion ends.\n"); 20005 i::OS::Print("Recursion ends.\n");
19883 CHECK_EQ(0, callback_fired); 20006 CHECK_EQ(0, callback_fired);
19884 } 20007 }
19885 } 20008 }
19886 20009
19887 20010
19888 TEST(CallCompletedCallback) { 20011 TEST(CallCompletedCallback) {
19889 LocalContext env; 20012 LocalContext env;
19890 v8::HandleScope scope(env->GetIsolate()); 20013 v8::HandleScope scope(env->GetIsolate());
19891 v8::Handle<v8::FunctionTemplate> recursive_runtime = 20014 v8::Handle<v8::FunctionTemplate> recursive_runtime =
19892 v8::FunctionTemplate::New(RecursiveCall); 20015 v8::FunctionTemplate::New(env->GetIsolate(), RecursiveCall);
19893 env->Global()->Set(v8_str("recursion"), 20016 env->Global()->Set(v8_str("recursion"),
19894 recursive_runtime->GetFunction()); 20017 recursive_runtime->GetFunction());
19895 // Adding the same callback a second time has no effect. 20018 // Adding the same callback a second time has no effect.
19896 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 20019 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
19897 v8::V8::AddCallCompletedCallback(CallCompletedCallback1); 20020 v8::V8::AddCallCompletedCallback(CallCompletedCallback1);
19898 v8::V8::AddCallCompletedCallback(CallCompletedCallback2); 20021 v8::V8::AddCallCompletedCallback(CallCompletedCallback2);
19899 i::OS::Print("--- Script (1) ---\n"); 20022 i::OS::Print("--- Script (1) ---\n");
19900 Local<Script> script = v8::Script::Compile( 20023 Local<Script> script = v8::Script::Compile(
19901 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)")); 20024 v8::String::NewFromUtf8(env->GetIsolate(), "recursion(0)"));
19902 script->Run(); 20025 script->Run();
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
20179 "%DeoptimizeFunction(test_set);" 20302 "%DeoptimizeFunction(test_set);"
20180 "%ClearFunctionTypeFeedback(test_set);"); 20303 "%ClearFunctionTypeFeedback(test_set);");
20181 } 20304 }
20182 20305
20183 20306
20184 THREADED_TEST(InstanceCheckOnInstanceAccessor) { 20307 THREADED_TEST(InstanceCheckOnInstanceAccessor) {
20185 v8::internal::FLAG_allow_natives_syntax = true; 20308 v8::internal::FLAG_allow_natives_syntax = true;
20186 LocalContext context; 20309 LocalContext context;
20187 v8::HandleScope scope(context->GetIsolate()); 20310 v8::HandleScope scope(context->GetIsolate());
20188 20311
20189 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20312 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20190 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20313 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20191 inst->SetAccessor(v8_str("foo"), 20314 inst->SetAccessor(v8_str("foo"),
20192 InstanceCheckedGetter, InstanceCheckedSetter, 20315 InstanceCheckedGetter, InstanceCheckedSetter,
20193 Handle<Value>(), 20316 Handle<Value>(),
20194 v8::DEFAULT, 20317 v8::DEFAULT,
20195 v8::None, 20318 v8::None,
20196 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20319 v8::AccessorSignature::New(context->GetIsolate(), templ));
20197 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20320 context->Global()->Set(v8_str("f"), templ->GetFunction());
20198 20321
20199 printf("Testing positive ...\n"); 20322 printf("Testing positive ...\n");
20200 CompileRun("var obj = new f();"); 20323 CompileRun("var obj = new f();");
20201 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20324 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20202 CheckInstanceCheckedAccessors(true); 20325 CheckInstanceCheckedAccessors(true);
20203 20326
20204 printf("Testing negative ...\n"); 20327 printf("Testing negative ...\n");
20205 CompileRun("var obj = {};" 20328 CompileRun("var obj = {};"
20206 "obj.__proto__ = new f();"); 20329 "obj.__proto__ = new f();");
20207 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20330 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20208 CheckInstanceCheckedAccessors(false); 20331 CheckInstanceCheckedAccessors(false);
20209 } 20332 }
20210 20333
20211 20334
20212 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) { 20335 THREADED_TEST(InstanceCheckOnInstanceAccessorWithInterceptor) {
20213 v8::internal::FLAG_allow_natives_syntax = true; 20336 v8::internal::FLAG_allow_natives_syntax = true;
20214 LocalContext context; 20337 LocalContext context;
20215 v8::HandleScope scope(context->GetIsolate()); 20338 v8::HandleScope scope(context->GetIsolate());
20216 20339
20217 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20340 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20218 Local<ObjectTemplate> inst = templ->InstanceTemplate(); 20341 Local<ObjectTemplate> inst = templ->InstanceTemplate();
20219 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 20342 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
20220 inst->SetAccessor(v8_str("foo"), 20343 inst->SetAccessor(v8_str("foo"),
20221 InstanceCheckedGetter, InstanceCheckedSetter, 20344 InstanceCheckedGetter, InstanceCheckedSetter,
20222 Handle<Value>(), 20345 Handle<Value>(),
20223 v8::DEFAULT, 20346 v8::DEFAULT,
20224 v8::None, 20347 v8::None,
20225 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20348 v8::AccessorSignature::New(context->GetIsolate(), templ));
20226 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20349 context->Global()->Set(v8_str("f"), templ->GetFunction());
20227 20350
20228 printf("Testing positive ...\n"); 20351 printf("Testing positive ...\n");
20229 CompileRun("var obj = new f();"); 20352 CompileRun("var obj = new f();");
20230 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20353 CHECK(templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20231 CheckInstanceCheckedAccessors(true); 20354 CheckInstanceCheckedAccessors(true);
20232 20355
20233 printf("Testing negative ...\n"); 20356 printf("Testing negative ...\n");
20234 CompileRun("var obj = {};" 20357 CompileRun("var obj = {};"
20235 "obj.__proto__ = new f();"); 20358 "obj.__proto__ = new f();");
20236 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj")))); 20359 CHECK(!templ->HasInstance(context->Global()->Get(v8_str("obj"))));
20237 CheckInstanceCheckedAccessors(false); 20360 CheckInstanceCheckedAccessors(false);
20238 } 20361 }
20239 20362
20240 20363
20241 THREADED_TEST(InstanceCheckOnPrototypeAccessor) { 20364 THREADED_TEST(InstanceCheckOnPrototypeAccessor) {
20242 v8::internal::FLAG_allow_natives_syntax = true; 20365 v8::internal::FLAG_allow_natives_syntax = true;
20243 LocalContext context; 20366 LocalContext context;
20244 v8::HandleScope scope(context->GetIsolate()); 20367 v8::HandleScope scope(context->GetIsolate());
20245 20368
20246 Local<FunctionTemplate> templ = FunctionTemplate::New(); 20369 Local<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20247 Local<ObjectTemplate> proto = templ->PrototypeTemplate(); 20370 Local<ObjectTemplate> proto = templ->PrototypeTemplate();
20248 proto->SetAccessor(v8_str("foo"), 20371 proto->SetAccessor(v8_str("foo"),
20249 InstanceCheckedGetter, InstanceCheckedSetter, 20372 InstanceCheckedGetter, InstanceCheckedSetter,
20250 Handle<Value>(), 20373 Handle<Value>(),
20251 v8::DEFAULT, 20374 v8::DEFAULT,
20252 v8::None, 20375 v8::None,
20253 v8::AccessorSignature::New(context->GetIsolate(), templ)); 20376 v8::AccessorSignature::New(context->GetIsolate(), templ));
20254 context->Global()->Set(v8_str("f"), templ->GetFunction()); 20377 context->Global()->Set(v8_str("f"), templ->GetFunction());
20255 20378
20256 printf("Testing positive ...\n"); 20379 printf("Testing positive ...\n");
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
20469 TryCatch try_catch; 20592 TryCatch try_catch;
20470 try_catch.SetVerbose(true); 20593 try_catch.SetVerbose(true);
20471 CompileRun("try { throw new Error(); } finally { gc(); }"); 20594 CompileRun("try { throw new Error(); } finally { gc(); }");
20472 CHECK(try_catch.HasCaught()); 20595 CHECK(try_catch.HasCaught());
20473 } 20596 }
20474 20597
20475 20598
20476 THREADED_TEST(Regress149912) { 20599 THREADED_TEST(Regress149912) {
20477 LocalContext context; 20600 LocalContext context;
20478 v8::HandleScope scope(context->GetIsolate()); 20601 v8::HandleScope scope(context->GetIsolate());
20479 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20602 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20480 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 20603 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
20481 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); 20604 context->Global()->Set(v8_str("Bug"), templ->GetFunction());
20482 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();"); 20605 CompileRun("Number.prototype.__proto__ = new Bug; var x = 0; x.foo();");
20483 } 20606 }
20484 20607
20485 20608
20486 THREADED_TEST(Regress157124) { 20609 THREADED_TEST(Regress157124) {
20487 LocalContext context; 20610 LocalContext context;
20488 v8::HandleScope scope(context->GetIsolate()); 20611 v8::HandleScope scope(context->GetIsolate());
20489 Local<ObjectTemplate> templ = ObjectTemplate::New(); 20612 Local<ObjectTemplate> templ = ObjectTemplate::New();
(...skipping 24 matching lines...) Expand all
20514 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); 20637 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key");
20515 obj->SetHiddenValue(key, v8::Undefined(isolate)); 20638 obj->SetHiddenValue(key, v8::Undefined(isolate));
20516 Local<Value> value = obj->GetHiddenValue(key); 20639 Local<Value> value = obj->GetHiddenValue(key);
20517 CHECK(!value.IsEmpty()); 20640 CHECK(!value.IsEmpty());
20518 CHECK(value->IsUndefined()); 20641 CHECK(value->IsUndefined());
20519 } 20642 }
20520 20643
20521 20644
20522 THREADED_TEST(Regress260106) { 20645 THREADED_TEST(Regress260106) {
20523 LocalContext context; 20646 LocalContext context;
20524 v8::HandleScope scope(context->GetIsolate()); 20647 v8::Isolate* isolate = context->GetIsolate();
20525 Local<FunctionTemplate> templ = FunctionTemplate::New(DummyCallHandler); 20648 v8::HandleScope scope(isolate);
20649 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate,
20650 DummyCallHandler);
20526 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); 20651 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;");
20527 Local<Function> function = templ->GetFunction(); 20652 Local<Function> function = templ->GetFunction();
20528 CHECK(!function.IsEmpty()); 20653 CHECK(!function.IsEmpty());
20529 CHECK(function->IsFunction()); 20654 CHECK(function->IsFunction());
20530 } 20655 }
20531 20656
20532 20657
20533 THREADED_TEST(JSONParseObject) { 20658 THREADED_TEST(JSONParseObject) {
20534 LocalContext context; 20659 LocalContext context;
20535 HandleScope scope(context->GetIsolate()); 20660 HandleScope scope(context->GetIsolate());
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
20647 // Create a context and set an x property on it's global object. 20772 // Create a context and set an x property on it's global object.
20648 LocalContext context0(NULL, global_template); 20773 LocalContext context0(NULL, global_template);
20649 v8::Handle<v8::Object> global0 = context0->Global(); 20774 v8::Handle<v8::Object> global0 = context0->Global();
20650 global0->Set(v8_str("x"), v8_num(42)); 20775 global0->Set(v8_str("x"), v8_num(42));
20651 ExpectString("JSON.stringify(this)", "{\"x\":42}"); 20776 ExpectString("JSON.stringify(this)", "{\"x\":42}");
20652 20777
20653 for (int i = 0; i < 2; i++) { 20778 for (int i = 0; i < 2; i++) {
20654 if (i == 1) { 20779 if (i == 1) {
20655 // Install a toJSON function on the second run. 20780 // Install a toJSON function on the second run.
20656 v8::Handle<v8::FunctionTemplate> toJSON = 20781 v8::Handle<v8::FunctionTemplate> toJSON =
20657 v8::FunctionTemplate::New(UnreachableCallback); 20782 v8::FunctionTemplate::New(CcTest::isolate(), UnreachableCallback);
20658 20783
20659 global0->Set(v8_str("toJSON"), toJSON->GetFunction()); 20784 global0->Set(v8_str("toJSON"), toJSON->GetFunction());
20660 } 20785 }
20661 // Create a context with a different security token so that the 20786 // Create a context with a different security token so that the
20662 // failed access check callback will be called on each access. 20787 // failed access check callback will be called on each access.
20663 LocalContext context1(NULL, global_template); 20788 LocalContext context1(NULL, global_template);
20664 context1->Global()->Set(v8_str("other"), global0); 20789 context1->Global()->Set(v8_str("other"), global0);
20665 20790
20666 ExpectString("JSON.stringify(other)", "{}"); 20791 ExpectString("JSON.stringify(other)", "{}");
20667 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })", 20792 ExpectString("JSON.stringify({ 'a' : other, 'b' : ['c'] })",
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
20746 LocalContext context0(NULL, global_template); 20871 LocalContext context0(NULL, global_template);
20747 context0->Global()->Set(v8_str("x"), v8_num(42)); 20872 context0->Global()->Set(v8_str("x"), v8_num(42));
20748 v8::Handle<v8::Object> global0 = context0->Global(); 20873 v8::Handle<v8::Object> global0 = context0->Global();
20749 20874
20750 // Create a context with a different security token so that the 20875 // Create a context with a different security token so that the
20751 // failed access check callback will be called on each access. 20876 // failed access check callback will be called on each access.
20752 LocalContext context1(NULL, global_template); 20877 LocalContext context1(NULL, global_template);
20753 context1->Global()->Set(v8_str("other"), global0); 20878 context1->Global()->Set(v8_str("other"), global0);
20754 20879
20755 v8::Handle<v8::FunctionTemplate> catcher_fun = 20880 v8::Handle<v8::FunctionTemplate> catcher_fun =
20756 v8::FunctionTemplate::New(CatcherCallback); 20881 v8::FunctionTemplate::New(CcTest::isolate(), CatcherCallback);
20757 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction()); 20882 context1->Global()->Set(v8_str("catcher"), catcher_fun->GetFunction());
20758 20883
20759 v8::Handle<v8::FunctionTemplate> has_own_property_fun = 20884 v8::Handle<v8::FunctionTemplate> has_own_property_fun =
20760 v8::FunctionTemplate::New(HasOwnPropertyCallback); 20885 v8::FunctionTemplate::New(CcTest::isolate(), HasOwnPropertyCallback);
20761 context1->Global()->Set(v8_str("has_own_property"), 20886 context1->Global()->Set(v8_str("has_own_property"),
20762 has_own_property_fun->GetFunction()); 20887 has_own_property_fun->GetFunction());
20763 20888
20764 { v8::TryCatch try_catch; 20889 { v8::TryCatch try_catch;
20765 access_check_fail_thrown = false; 20890 access_check_fail_thrown = false;
20766 CompileRun("other.x;"); 20891 CompileRun("other.x;");
20767 CHECK(access_check_fail_thrown); 20892 CHECK(access_check_fail_thrown);
20768 CHECK(try_catch.HasCaught()); 20893 CHECK(try_catch.HasCaught());
20769 } 20894 }
20770 20895
(...skipping 18 matching lines...) Expand all
20789 // Reset the failed access check callback so it does not influence 20914 // Reset the failed access check callback so it does not influence
20790 // the other tests. 20915 // the other tests.
20791 v8::V8::SetFailedAccessCheckCallbackFunction(NULL); 20916 v8::V8::SetFailedAccessCheckCallbackFunction(NULL);
20792 } 20917 }
20793 20918
20794 20919
20795 THREADED_TEST(Regress256330) { 20920 THREADED_TEST(Regress256330) {
20796 i::FLAG_allow_natives_syntax = true; 20921 i::FLAG_allow_natives_syntax = true;
20797 LocalContext context; 20922 LocalContext context;
20798 v8::HandleScope scope(context->GetIsolate()); 20923 v8::HandleScope scope(context->GetIsolate());
20799 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20924 Handle<FunctionTemplate> templ = FunctionTemplate::New(context->GetIsolate());
20800 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter); 20925 AddInterceptor(templ, EmptyInterceptorGetter, EmptyInterceptorSetter);
20801 context->Global()->Set(v8_str("Bug"), templ->GetFunction()); 20926 context->Global()->Set(v8_str("Bug"), templ->GetFunction());
20802 CompileRun("\"use strict\"; var o = new Bug;" 20927 CompileRun("\"use strict\"; var o = new Bug;"
20803 "function f(o) { o.x = 10; };" 20928 "function f(o) { o.x = 10; };"
20804 "f(o); f(o); f(o);" 20929 "f(o); f(o); f(o);"
20805 "%OptimizeFunctionOnNextCall(f);" 20930 "%OptimizeFunctionOnNextCall(f);"
20806 "f(o);"); 20931 "f(o);");
20807 ExpectBoolean("%GetOptimizationStatus(f) != 2", true); 20932 ExpectBoolean("%GetOptimizationStatus(f) != 2", true);
20808 } 20933 }
20809 20934
20810 20935
20811 THREADED_TEST(CrankshaftInterceptorSetter) { 20936 THREADED_TEST(CrankshaftInterceptorSetter) {
20812 i::FLAG_allow_natives_syntax = true; 20937 i::FLAG_allow_natives_syntax = true;
20813 v8::HandleScope scope(CcTest::isolate()); 20938 v8::HandleScope scope(CcTest::isolate());
20814 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20939 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
20815 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20940 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20816 LocalContext env; 20941 LocalContext env;
20817 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20942 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20818 CompileRun("var obj = new Obj;" 20943 CompileRun("var obj = new Obj;"
20819 // Initialize fields to avoid transitions later. 20944 // Initialize fields to avoid transitions later.
20820 "obj.age = 0;" 20945 "obj.age = 0;"
20821 "obj.accessor_age = 42;" 20946 "obj.accessor_age = 42;"
20822 "function setter(i) { this.accessor_age = i; };" 20947 "function setter(i) { this.accessor_age = i; };"
20823 "function getter() { return this.accessor_age; };" 20948 "function getter() { return this.accessor_age; };"
20824 "function setAge(i) { obj.age = i; };" 20949 "function setAge(i) { obj.age = i; };"
20825 "Object.defineProperty(obj, 'age', { get:getter, set:setter });" 20950 "Object.defineProperty(obj, 'age', { get:getter, set:setter });"
20826 "setAge(1);" 20951 "setAge(1);"
20827 "setAge(2);" 20952 "setAge(2);"
20828 "setAge(3);" 20953 "setAge(3);"
20829 "%OptimizeFunctionOnNextCall(setAge);" 20954 "%OptimizeFunctionOnNextCall(setAge);"
20830 "setAge(4);"); 20955 "setAge(4);");
20831 // All stores went through the interceptor. 20956 // All stores went through the interceptor.
20832 ExpectInt32("obj.interceptor_age", 4); 20957 ExpectInt32("obj.interceptor_age", 4);
20833 ExpectInt32("obj.accessor_age", 42); 20958 ExpectInt32("obj.accessor_age", 42);
20834 } 20959 }
20835 20960
20836 20961
20837 THREADED_TEST(CrankshaftInterceptorGetter) { 20962 THREADED_TEST(CrankshaftInterceptorGetter) {
20838 i::FLAG_allow_natives_syntax = true; 20963 i::FLAG_allow_natives_syntax = true;
20839 v8::HandleScope scope(CcTest::isolate()); 20964 v8::HandleScope scope(CcTest::isolate());
20840 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20965 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
20841 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20966 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20842 LocalContext env; 20967 LocalContext env;
20843 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20968 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20844 CompileRun("var obj = new Obj;" 20969 CompileRun("var obj = new Obj;"
20845 // Initialize fields to avoid transitions later. 20970 // Initialize fields to avoid transitions later.
20846 "obj.age = 1;" 20971 "obj.age = 1;"
20847 "obj.accessor_age = 42;" 20972 "obj.accessor_age = 42;"
20848 "function getter() { return this.accessor_age; };" 20973 "function getter() { return this.accessor_age; };"
20849 "function getAge() { return obj.interceptor_age; };" 20974 "function getAge() { return obj.interceptor_age; };"
20850 "Object.defineProperty(obj, 'interceptor_age', { get:getter });" 20975 "Object.defineProperty(obj, 'interceptor_age', { get:getter });"
20851 "getAge();" 20976 "getAge();"
20852 "getAge();" 20977 "getAge();"
20853 "getAge();" 20978 "getAge();"
20854 "%OptimizeFunctionOnNextCall(getAge);"); 20979 "%OptimizeFunctionOnNextCall(getAge);");
20855 // Access through interceptor. 20980 // Access through interceptor.
20856 ExpectInt32("getAge()", 1); 20981 ExpectInt32("getAge()", 1);
20857 } 20982 }
20858 20983
20859 20984
20860 THREADED_TEST(CrankshaftInterceptorFieldRead) { 20985 THREADED_TEST(CrankshaftInterceptorFieldRead) {
20861 i::FLAG_allow_natives_syntax = true; 20986 i::FLAG_allow_natives_syntax = true;
20862 v8::HandleScope scope(CcTest::isolate()); 20987 v8::HandleScope scope(CcTest::isolate());
20863 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 20988 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
20864 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 20989 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20865 LocalContext env; 20990 LocalContext env;
20866 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 20991 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20867 CompileRun("var obj = new Obj;" 20992 CompileRun("var obj = new Obj;"
20868 "obj.__proto__.interceptor_age = 42;" 20993 "obj.__proto__.interceptor_age = 42;"
20869 "obj.age = 100;" 20994 "obj.age = 100;"
20870 "function getAge() { return obj.interceptor_age; };"); 20995 "function getAge() { return obj.interceptor_age; };");
20871 ExpectInt32("getAge();", 100); 20996 ExpectInt32("getAge();", 100);
20872 ExpectInt32("getAge();", 100); 20997 ExpectInt32("getAge();", 100);
20873 ExpectInt32("getAge();", 100); 20998 ExpectInt32("getAge();", 100);
20874 CompileRun("%OptimizeFunctionOnNextCall(getAge);"); 20999 CompileRun("%OptimizeFunctionOnNextCall(getAge);");
20875 // Access through interceptor. 21000 // Access through interceptor.
20876 ExpectInt32("getAge();", 100); 21001 ExpectInt32("getAge();", 100);
20877 } 21002 }
20878 21003
20879 21004
20880 THREADED_TEST(CrankshaftInterceptorFieldWrite) { 21005 THREADED_TEST(CrankshaftInterceptorFieldWrite) {
20881 i::FLAG_allow_natives_syntax = true; 21006 i::FLAG_allow_natives_syntax = true;
20882 v8::HandleScope scope(CcTest::isolate()); 21007 v8::HandleScope scope(CcTest::isolate());
20883 Handle<FunctionTemplate> templ = FunctionTemplate::New(); 21008 Handle<FunctionTemplate> templ = FunctionTemplate::New(CcTest::isolate());
20884 AddInterceptor(templ, InterceptorGetter, InterceptorSetter); 21009 AddInterceptor(templ, InterceptorGetter, InterceptorSetter);
20885 LocalContext env; 21010 LocalContext env;
20886 env->Global()->Set(v8_str("Obj"), templ->GetFunction()); 21011 env->Global()->Set(v8_str("Obj"), templ->GetFunction());
20887 CompileRun("var obj = new Obj;" 21012 CompileRun("var obj = new Obj;"
20888 "obj.age = 100000;" 21013 "obj.age = 100000;"
20889 "function setAge(i) { obj.age = i };" 21014 "function setAge(i) { obj.age = i };"
20890 "setAge(100);" 21015 "setAge(100);"
20891 "setAge(101);" 21016 "setAge(101);"
20892 "setAge(102);" 21017 "setAge(102);"
20893 "%OptimizeFunctionOnNextCall(setAge);" 21018 "%OptimizeFunctionOnNextCall(setAge);"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
20950 } 21075 }
20951 for (int i = 0; i < runs; i++) { 21076 for (int i = 0; i < runs; i++) {
20952 Local<String> expected; 21077 Local<String> expected;
20953 if (i != 0) { 21078 if (i != 0) {
20954 CHECK_EQ(v8_str("escape value"), values[i]); 21079 CHECK_EQ(v8_str("escape value"), values[i]);
20955 } else { 21080 } else {
20956 CHECK(values[i].IsEmpty()); 21081 CHECK(values[i].IsEmpty());
20957 } 21082 }
20958 } 21083 }
20959 } 21084 }
OLDNEW
« no previous file with comments | « test/cctest/test-accessors.cc ('k') | test/cctest/test-assembler-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698