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

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

Issue 145773008: A64: Synchronize with r17104. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 months 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/cctest.status ('k') | test/cctest/test-debug.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 using ::v8::Script; 70 using ::v8::Script;
71 using ::v8::StackTrace; 71 using ::v8::StackTrace;
72 using ::v8::String; 72 using ::v8::String;
73 using ::v8::TryCatch; 73 using ::v8::TryCatch;
74 using ::v8::Undefined; 74 using ::v8::Undefined;
75 using ::v8::UniqueId; 75 using ::v8::UniqueId;
76 using ::v8::V8; 76 using ::v8::V8;
77 using ::v8::Value; 77 using ::v8::Value;
78 78
79 79
80 // TODO(bmeurer): Don't run profiled tests when using the simulator.
81 // This is a temporary work-around, until the profiler is fixed.
82 #if USE_SIMULATOR
83 #define THREADED_PROFILED_TEST(Name) \
84 THREADED_TEST(Name)
85 #else
86 #define THREADED_PROFILED_TEST(Name) \ 80 #define THREADED_PROFILED_TEST(Name) \
87 static void Test##Name(); \ 81 static void Test##Name(); \
88 TEST(Name##WithProfiler) { \ 82 TEST(Name##WithProfiler) { \
89 RunWithProfiler(&Test##Name); \ 83 RunWithProfiler(&Test##Name); \
90 } \ 84 } \
91 THREADED_TEST(Name) 85 THREADED_TEST(Name)
92 #endif
93 86
94 87
95 void RunWithProfiler(void (*test)()) { 88 void RunWithProfiler(void (*test)()) {
96 LocalContext env; 89 LocalContext env;
97 v8::HandleScope scope(env->GetIsolate()); 90 v8::HandleScope scope(env->GetIsolate());
98 v8::Local<v8::String> profile_name = v8::String::New("my_profile1"); 91 v8::Local<v8::String> profile_name = v8::String::New("my_profile1");
99 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler(); 92 v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
100 93
101 cpu_profiler->StartCpuProfiling(profile_name); 94 cpu_profiler->StartCpuProfiling(profile_name);
102 (*test)(); 95 (*test)();
(...skipping 3901 matching lines...) Expand 10 before | Expand all | Expand 10 after
4004 CHECK_EQ(4, a4->Length()); 3997 CHECK_EQ(4, a4->Length());
4005 CHECK_EQ(17, a4->Get(0)->Int32Value()); 3998 CHECK_EQ(17, a4->Get(0)->Int32Value());
4006 CHECK_EQ(18, a4->Get(1)->Int32Value()); 3999 CHECK_EQ(18, a4->Get(1)->Int32Value());
4007 CHECK_EQ(19, a4->Get(2)->Int32Value()); 4000 CHECK_EQ(19, a4->Get(2)->Int32Value());
4008 CHECK_EQ(20, a4->Get(3)->Int32Value()); 4001 CHECK_EQ(20, a4->Get(3)->Int32Value());
4009 } 4002 }
4010 4003
4011 4004
4012 THREADED_TEST(FunctionCall) { 4005 THREADED_TEST(FunctionCall) {
4013 LocalContext context; 4006 LocalContext context;
4014 v8::HandleScope scope(context->GetIsolate()); 4007 v8::Isolate* isolate = context->GetIsolate();
4008 v8::HandleScope scope(isolate);
4015 CompileRun( 4009 CompileRun(
4016 "function Foo() {" 4010 "function Foo() {"
4017 " var result = [];" 4011 " var result = [];"
4018 " for (var i = 0; i < arguments.length; i++) {" 4012 " for (var i = 0; i < arguments.length; i++) {"
4019 " result.push(arguments[i]);" 4013 " result.push(arguments[i]);"
4020 " }" 4014 " }"
4021 " return result;" 4015 " return result;"
4016 "}"
4017 "function ReturnThisSloppy() {"
4018 " return this;"
4019 "}"
4020 "function ReturnThisStrict() {"
4021 " 'use strict';"
4022 " return this;"
4022 "}"); 4023 "}");
4023 Local<Function> Foo = 4024 Local<Function> Foo =
4024 Local<Function>::Cast(context->Global()->Get(v8_str("Foo"))); 4025 Local<Function>::Cast(context->Global()->Get(v8_str("Foo")));
4026 Local<Function> ReturnThisSloppy =
4027 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisSloppy")));
4028 Local<Function> ReturnThisStrict =
4029 Local<Function>::Cast(context->Global()->Get(v8_str("ReturnThisStrict")));
4025 4030
4026 v8::Handle<Value>* args0 = NULL; 4031 v8::Handle<Value>* args0 = NULL;
4027 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0)); 4032 Local<v8::Array> a0 = Local<v8::Array>::Cast(Foo->Call(Foo, 0, args0));
4028 CHECK_EQ(0, a0->Length()); 4033 CHECK_EQ(0, a0->Length());
4029 4034
4030 v8::Handle<Value> args1[] = { v8_num(1.1) }; 4035 v8::Handle<Value> args1[] = { v8_num(1.1) };
4031 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1)); 4036 Local<v8::Array> a1 = Local<v8::Array>::Cast(Foo->Call(Foo, 1, args1));
4032 CHECK_EQ(1, a1->Length()); 4037 CHECK_EQ(1, a1->Length());
4033 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue()); 4038 CHECK_EQ(1.1, a1->Get(v8::Integer::New(0))->NumberValue());
4034 4039
(...skipping 16 matching lines...) Expand all
4051 v8::Handle<Value> args4[] = { v8_num(7.7), 4056 v8::Handle<Value> args4[] = { v8_num(7.7),
4052 v8_num(8.8), 4057 v8_num(8.8),
4053 v8_num(9.9), 4058 v8_num(9.9),
4054 v8_num(10.11) }; 4059 v8_num(10.11) };
4055 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4)); 4060 Local<v8::Array> a4 = Local<v8::Array>::Cast(Foo->Call(Foo, 4, args4));
4056 CHECK_EQ(4, a4->Length()); 4061 CHECK_EQ(4, a4->Length());
4057 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue()); 4062 CHECK_EQ(7.7, a4->Get(v8::Integer::New(0))->NumberValue());
4058 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue()); 4063 CHECK_EQ(8.8, a4->Get(v8::Integer::New(1))->NumberValue());
4059 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue()); 4064 CHECK_EQ(9.9, a4->Get(v8::Integer::New(2))->NumberValue());
4060 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue()); 4065 CHECK_EQ(10.11, a4->Get(v8::Integer::New(3))->NumberValue());
4066
4067 Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL);
4068 CHECK(r1->StrictEquals(context->Global()));
4069 Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL);
4070 CHECK(r2->StrictEquals(context->Global()));
4071 Local<v8::Value> r3 = ReturnThisSloppy->Call(v8_num(42), 0, NULL);
4072 CHECK(r3->IsNumberObject());
4073 CHECK_EQ(42.0, r3.As<v8::NumberObject>()->ValueOf());
4074 Local<v8::Value> r4 = ReturnThisSloppy->Call(v8_str("hello"), 0, NULL);
4075 CHECK(r4->IsStringObject());
4076 CHECK(r4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello")));
4077 Local<v8::Value> r5 = ReturnThisSloppy->Call(v8::True(isolate), 0, NULL);
4078 CHECK(r5->IsBooleanObject());
4079 CHECK(r5.As<v8::BooleanObject>()->ValueOf());
4080
4081 Local<v8::Value> r6 = ReturnThisStrict->Call(v8::Undefined(isolate), 0, NULL);
4082 CHECK(r6->IsUndefined());
4083 Local<v8::Value> r7 = ReturnThisStrict->Call(v8::Null(isolate), 0, NULL);
4084 CHECK(r7->IsNull());
4085 Local<v8::Value> r8 = ReturnThisStrict->Call(v8_num(42), 0, NULL);
4086 CHECK(r8->StrictEquals(v8_num(42)));
4087 Local<v8::Value> r9 = ReturnThisStrict->Call(v8_str("hello"), 0, NULL);
4088 CHECK(r9->StrictEquals(v8_str("hello")));
4089 Local<v8::Value> r10 = ReturnThisStrict->Call(v8::True(isolate), 0, NULL);
4090 CHECK(r10->StrictEquals(v8::True(isolate)));
4061 } 4091 }
4062 4092
4063 4093
4064 static const char* js_code_causing_out_of_memory = 4094 static const char* js_code_causing_out_of_memory =
4065 "var a = new Array(); while(true) a.push(a);"; 4095 "var a = new Array(); while(true) a.push(a);";
4066 4096
4067 4097
4068 // These tests run for a long time and prevent us from running tests 4098 // These tests run for a long time and prevent us from running tests
4069 // that come after them so they cannot run in parallel. 4099 // that come after them so they cannot run in parallel.
4070 TEST(OutOfMemory) { 4100 TEST(OutOfMemory) {
(...skipping 6099 matching lines...) Expand 10 before | Expand all | Expand 10 after
10170 if (args[0]->IsInt32()) { 10200 if (args[0]->IsInt32()) {
10171 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value())); 10201 args.GetReturnValue().Set(v8_num(-args[0]->Int32Value()));
10172 return; 10202 return;
10173 } 10203 }
10174 } 10204 }
10175 10205
10176 args.GetReturnValue().Set(args[0]); 10206 args.GetReturnValue().Set(args[0]);
10177 } 10207 }
10178 10208
10179 10209
10210 static void ReturnThis(const v8::FunctionCallbackInfo<v8::Value>& args) {
10211 args.GetReturnValue().Set(args.This());
10212 }
10213
10214
10180 // Test that a call handler can be set for objects which will allow 10215 // Test that a call handler can be set for objects which will allow
10181 // non-function objects created through the API to be called as 10216 // non-function objects created through the API to be called as
10182 // functions. 10217 // functions.
10183 THREADED_TEST(CallAsFunction) { 10218 THREADED_TEST(CallAsFunction) {
10184 LocalContext context; 10219 LocalContext context;
10185 v8::HandleScope scope(context->GetIsolate()); 10220 v8::HandleScope scope(context->GetIsolate());
10186 10221
10187 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(); 10222 { Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
10188 Local<ObjectTemplate> instance_template = t->InstanceTemplate(); 10223 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10189 instance_template->SetCallAsFunctionHandler(call_as_function); 10224 instance_template->SetCallAsFunctionHandler(call_as_function);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
10282 CHECK_EQ("22", *exception_value1); 10317 CHECK_EQ("22", *exception_value1);
10283 try_catch.Reset(); 10318 try_catch.Reset();
10284 10319
10285 v8::Handle<Value> args[] = { v8_num(23) }; 10320 v8::Handle<Value> args[] = { v8_num(23) };
10286 value = instance->CallAsFunction(instance, 1, args); 10321 value = instance->CallAsFunction(instance, 1, args);
10287 CHECK(try_catch.HasCaught()); 10322 CHECK(try_catch.HasCaught());
10288 String::Utf8Value exception_value2(try_catch.Exception()); 10323 String::Utf8Value exception_value2(try_catch.Exception());
10289 CHECK_EQ("23", *exception_value2); 10324 CHECK_EQ("23", *exception_value2);
10290 try_catch.Reset(); 10325 try_catch.Reset();
10291 } 10326 }
10327
10328 { v8::Isolate* isolate = context->GetIsolate();
10329 Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New();
10330 Local<ObjectTemplate> instance_template = t->InstanceTemplate();
10331 instance_template->SetCallAsFunctionHandler(ReturnThis);
10332 Local<v8::Object> instance = t->GetFunction()->NewInstance();
10333
10334 Local<v8::Value> a1 =
10335 instance->CallAsFunction(v8::Undefined(isolate), 0, NULL);
10336 CHECK(a1->StrictEquals(instance));
10337 Local<v8::Value> a2 =
10338 instance->CallAsFunction(v8::Null(isolate), 0, NULL);
10339 CHECK(a2->StrictEquals(instance));
10340 Local<v8::Value> a3 =
10341 instance->CallAsFunction(v8_num(42), 0, NULL);
10342 CHECK(a3->StrictEquals(instance));
10343 Local<v8::Value> a4 =
10344 instance->CallAsFunction(v8_str("hello"), 0, NULL);
10345 CHECK(a4->StrictEquals(instance));
10346 Local<v8::Value> a5 =
10347 instance->CallAsFunction(v8::True(isolate), 0, NULL);
10348 CHECK(a5->StrictEquals(instance));
10349 }
10350
10351 { v8::Isolate* isolate = context->GetIsolate();
10352 CompileRun(
10353 "function ReturnThisSloppy() {"
10354 " return this;"
10355 "}"
10356 "function ReturnThisStrict() {"
10357 " 'use strict';"
10358 " return this;"
10359 "}");
10360 Local<Function> ReturnThisSloppy =
10361 Local<Function>::Cast(
10362 context->Global()->Get(v8_str("ReturnThisSloppy")));
10363 Local<Function> ReturnThisStrict =
10364 Local<Function>::Cast(
10365 context->Global()->Get(v8_str("ReturnThisStrict")));
10366
10367 Local<v8::Value> a1 =
10368 ReturnThisSloppy->CallAsFunction(v8::Undefined(isolate), 0, NULL);
10369 CHECK(a1->StrictEquals(context->Global()));
10370 Local<v8::Value> a2 =
10371 ReturnThisSloppy->CallAsFunction(v8::Null(isolate), 0, NULL);
10372 CHECK(a2->StrictEquals(context->Global()));
10373 Local<v8::Value> a3 =
10374 ReturnThisSloppy->CallAsFunction(v8_num(42), 0, NULL);
10375 CHECK(a3->IsNumberObject());
10376 CHECK_EQ(42.0, a3.As<v8::NumberObject>()->ValueOf());
10377 Local<v8::Value> a4 =
10378 ReturnThisSloppy->CallAsFunction(v8_str("hello"), 0, NULL);
10379 CHECK(a4->IsStringObject());
10380 CHECK(a4.As<v8::StringObject>()->ValueOf()->StrictEquals(v8_str("hello")));
10381 Local<v8::Value> a5 =
10382 ReturnThisSloppy->CallAsFunction(v8::True(isolate), 0, NULL);
10383 CHECK(a5->IsBooleanObject());
10384 CHECK(a5.As<v8::BooleanObject>()->ValueOf());
10385
10386 Local<v8::Value> a6 =
10387 ReturnThisStrict->CallAsFunction(v8::Undefined(isolate), 0, NULL);
10388 CHECK(a6->IsUndefined());
10389 Local<v8::Value> a7 =
10390 ReturnThisStrict->CallAsFunction(v8::Null(isolate), 0, NULL);
10391 CHECK(a7->IsNull());
10392 Local<v8::Value> a8 =
10393 ReturnThisStrict->CallAsFunction(v8_num(42), 0, NULL);
10394 CHECK(a8->StrictEquals(v8_num(42)));
10395 Local<v8::Value> a9 =
10396 ReturnThisStrict->CallAsFunction(v8_str("hello"), 0, NULL);
10397 CHECK(a9->StrictEquals(v8_str("hello")));
10398 Local<v8::Value> a10 =
10399 ReturnThisStrict->CallAsFunction(v8::True(isolate), 0, NULL);
10400 CHECK(a10->StrictEquals(v8::True(isolate)));
10401 }
10292 } 10402 }
10293 10403
10294 10404
10295 // Check whether a non-function object is callable. 10405 // Check whether a non-function object is callable.
10296 THREADED_TEST(CallableObject) { 10406 THREADED_TEST(CallableObject) {
10297 LocalContext context; 10407 LocalContext context;
10298 v8::HandleScope scope(context->GetIsolate()); 10408 v8::HandleScope scope(context->GetIsolate());
10299 10409
10300 { Local<ObjectTemplate> instance_template = ObjectTemplate::New(); 10410 { Local<ObjectTemplate> instance_template = ObjectTemplate::New();
10301 instance_template->SetCallAsFunctionHandler(call_as_function); 10411 instance_template->SetCallAsFunctionHandler(call_as_function);
(...skipping 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after
13996 } 14106 }
13997 14107
13998 14108
13999 // This test verifies that pre-compilation (aka preparsing) can be called 14109 // This test verifies that pre-compilation (aka preparsing) can be called
14000 // without initializing the whole VM. Thus we cannot run this test in a 14110 // without initializing the whole VM. Thus we cannot run this test in a
14001 // multi-threaded setup. 14111 // multi-threaded setup.
14002 TEST(PreCompile) { 14112 TEST(PreCompile) {
14003 // TODO(155): This test would break without the initialization of V8. This is 14113 // TODO(155): This test would break without the initialization of V8. This is
14004 // a workaround for now to make this test not fail. 14114 // a workaround for now to make this test not fail.
14005 v8::V8::Initialize(); 14115 v8::V8::Initialize();
14116 v8::Isolate* isolate = CcTest::isolate();
14006 const char* script = "function foo(a) { return a+1; }"; 14117 const char* script = "function foo(a) { return a+1; }";
14007 v8::ScriptData* sd = 14118 v8::ScriptData* sd =
14008 v8::ScriptData::PreCompile(script, i::StrLength(script)); 14119 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14009 CHECK_NE(sd->Length(), 0); 14120 CHECK_NE(sd->Length(), 0);
14010 CHECK_NE(sd->Data(), NULL); 14121 CHECK_NE(sd->Data(), NULL);
14011 CHECK(!sd->HasError()); 14122 CHECK(!sd->HasError());
14012 delete sd; 14123 delete sd;
14013 } 14124 }
14014 14125
14015 14126
14016 TEST(PreCompileWithError) { 14127 TEST(PreCompileWithError) {
14017 v8::V8::Initialize(); 14128 v8::V8::Initialize();
14129 v8::Isolate* isolate = CcTest::isolate();
14018 const char* script = "function foo(a) { return 1 * * 2; }"; 14130 const char* script = "function foo(a) { return 1 * * 2; }";
14019 v8::ScriptData* sd = 14131 v8::ScriptData* sd =
14020 v8::ScriptData::PreCompile(script, i::StrLength(script)); 14132 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14021 CHECK(sd->HasError()); 14133 CHECK(sd->HasError());
14022 delete sd; 14134 delete sd;
14023 } 14135 }
14024 14136
14025 14137
14026 TEST(Regress31661) { 14138 TEST(Regress31661) {
14027 v8::V8::Initialize(); 14139 v8::V8::Initialize();
14140 v8::Isolate* isolate = CcTest::isolate();
14028 const char* script = " The Definintive Guide"; 14141 const char* script = " The Definintive Guide";
14029 v8::ScriptData* sd = 14142 v8::ScriptData* sd =
14030 v8::ScriptData::PreCompile(script, i::StrLength(script)); 14143 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14031 CHECK(sd->HasError()); 14144 CHECK(sd->HasError());
14032 delete sd; 14145 delete sd;
14033 } 14146 }
14034 14147
14035 14148
14036 // Tests that ScriptData can be serialized and deserialized. 14149 // Tests that ScriptData can be serialized and deserialized.
14037 TEST(PreCompileSerialization) { 14150 TEST(PreCompileSerialization) {
14038 v8::V8::Initialize(); 14151 v8::V8::Initialize();
14152 v8::Isolate* isolate = CcTest::isolate();
14039 const char* script = "function foo(a) { return a+1; }"; 14153 const char* script = "function foo(a) { return a+1; }";
14040 v8::ScriptData* sd = 14154 v8::ScriptData* sd =
14041 v8::ScriptData::PreCompile(script, i::StrLength(script)); 14155 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14042 14156
14043 // Serialize. 14157 // Serialize.
14044 int serialized_data_length = sd->Length(); 14158 int serialized_data_length = sd->Length();
14045 char* serialized_data = i::NewArray<char>(serialized_data_length); 14159 char* serialized_data = i::NewArray<char>(serialized_data_length);
14046 i::OS::MemCopy(serialized_data, sd->Data(), serialized_data_length); 14160 i::OS::MemCopy(serialized_data, sd->Data(), serialized_data_length);
14047 14161
14048 // Deserialize. 14162 // Deserialize.
14049 v8::ScriptData* deserialized_sd = 14163 v8::ScriptData* deserialized_sd =
14050 v8::ScriptData::New(serialized_data, serialized_data_length); 14164 v8::ScriptData::New(serialized_data, serialized_data_length);
14051 14165
(...skipping 16 matching lines...) Expand all
14068 14182
14069 CHECK_EQ(0, sd->Length()); 14183 CHECK_EQ(0, sd->Length());
14070 14184
14071 delete sd; 14185 delete sd;
14072 } 14186 }
14073 14187
14074 14188
14075 // Attempts to deserialize bad data. 14189 // Attempts to deserialize bad data.
14076 TEST(PreCompileInvalidPreparseDataError) { 14190 TEST(PreCompileInvalidPreparseDataError) {
14077 v8::V8::Initialize(); 14191 v8::V8::Initialize();
14192 v8::Isolate* isolate = CcTest::isolate();
14078 LocalContext context; 14193 LocalContext context;
14079 v8::HandleScope scope(context->GetIsolate()); 14194 v8::HandleScope scope(context->GetIsolate());
14080 14195
14081 const char* script = "function foo(){ return 5;}\n" 14196 const char* script = "function foo(){ return 5;}\n"
14082 "function bar(){ return 6 + 7;} foo();"; 14197 "function bar(){ return 6 + 7;} foo();";
14083 v8::ScriptData* sd = 14198 v8::ScriptData* sd =
14084 v8::ScriptData::PreCompile(script, i::StrLength(script)); 14199 v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14085 CHECK(!sd->HasError()); 14200 CHECK(!sd->HasError());
14086 // ScriptDataImpl private implementation details 14201 // ScriptDataImpl private implementation details
14087 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize; 14202 const int kHeaderSize = i::PreparseDataConstants::kHeaderSize;
14088 const int kFunctionEntrySize = i::FunctionEntry::kSize; 14203 const int kFunctionEntrySize = i::FunctionEntry::kSize;
14089 const int kFunctionEntryStartOffset = 0; 14204 const int kFunctionEntryStartOffset = 0;
14090 const int kFunctionEntryEndOffset = 1; 14205 const int kFunctionEntryEndOffset = 1;
14091 unsigned* sd_data = 14206 unsigned* sd_data =
14092 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14207 reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14093 14208
14094 // Overwrite function bar's end position with 0. 14209 // Overwrite function bar's end position with 0.
14095 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0; 14210 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryEndOffset] = 0;
14096 v8::TryCatch try_catch; 14211 v8::TryCatch try_catch;
14097 14212
14098 Local<String> source = String::New(script); 14213 Local<String> source = String::New(script);
14099 Local<Script> compiled_script = Script::New(source, NULL, sd); 14214 Local<Script> compiled_script = Script::New(source, NULL, sd);
14100 CHECK(try_catch.HasCaught()); 14215 CHECK(try_catch.HasCaught());
14101 String::Utf8Value exception_value(try_catch.Message()->Get()); 14216 String::Utf8Value exception_value(try_catch.Message()->Get());
14102 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar", 14217 CHECK_EQ("Uncaught SyntaxError: Invalid preparser data for function bar",
14103 *exception_value); 14218 *exception_value);
14104 14219
14105 try_catch.Reset(); 14220 try_catch.Reset();
14106 14221
14107 // Overwrite function bar's start position with 200. The function entry 14222 // Overwrite function bar's start position with 200. The function entry
14108 // will not be found when searching for it by position and we should fall 14223 // will not be found when searching for it by position and we should fall
14109 // back on eager compilation. 14224 // back on eager compilation.
14110 sd = v8::ScriptData::PreCompile(script, i::StrLength(script)); 14225 sd = v8::ScriptData::PreCompile(isolate, script, i::StrLength(script));
14111 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data())); 14226 sd_data = reinterpret_cast<unsigned*>(const_cast<char*>(sd->Data()));
14112 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] = 14227 sd_data[kHeaderSize + 1 * kFunctionEntrySize + kFunctionEntryStartOffset] =
14113 200; 14228 200;
14114 compiled_script = Script::New(source, NULL, sd); 14229 compiled_script = Script::New(source, NULL, sd);
14115 CHECK(!try_catch.HasCaught()); 14230 CHECK(!try_catch.HasCaught());
14116 14231
14117 delete sd; 14232 delete sd;
14118 } 14233 }
14119 14234
14120 14235
14121 // Verifies that the Handle<String> and const char* versions of the API produce 14236 // Verifies that the Handle<String> and const char* versions of the API produce
14122 // the same results (at least for one trivial case). 14237 // the same results (at least for one trivial case).
14123 TEST(PreCompileAPIVariationsAreSame) { 14238 TEST(PreCompileAPIVariationsAreSame) {
14124 v8::V8::Initialize(); 14239 v8::V8::Initialize();
14125 v8::HandleScope scope(CcTest::isolate()); 14240 v8::Isolate* isolate = CcTest::isolate();
14241 v8::HandleScope scope(isolate);
14126 14242
14127 const char* cstring = "function foo(a) { return a+1; }"; 14243 const char* cstring = "function foo(a) { return a+1; }";
14128 14244
14129 v8::ScriptData* sd_from_cstring = 14245 v8::ScriptData* sd_from_cstring =
14130 v8::ScriptData::PreCompile(cstring, i::StrLength(cstring)); 14246 v8::ScriptData::PreCompile(isolate, cstring, i::StrLength(cstring));
14131 14247
14132 TestAsciiResource* resource = new TestAsciiResource(cstring); 14248 TestAsciiResource* resource = new TestAsciiResource(cstring);
14133 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile( 14249 v8::ScriptData* sd_from_external_string = v8::ScriptData::PreCompile(
14134 v8::String::NewExternal(resource)); 14250 v8::String::NewExternal(resource));
14135 14251
14136 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile( 14252 v8::ScriptData* sd_from_string = v8::ScriptData::PreCompile(
14137 v8::String::New(cstring)); 14253 v8::String::New(cstring));
14138 14254
14139 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length()); 14255 CHECK_EQ(sd_from_cstring->Length(), sd_from_external_string->Length());
14140 CHECK_EQ(0, memcmp(sd_from_cstring->Data(), 14256 CHECK_EQ(0, memcmp(sd_from_cstring->Data(),
(...skipping 6468 matching lines...) Expand 10 before | Expand all | Expand 10 after
20609 } 20725 }
20610 for (int i = 0; i < runs; i++) { 20726 for (int i = 0; i < runs; i++) {
20611 Local<String> expected; 20727 Local<String> expected;
20612 if (i != 0) { 20728 if (i != 0) {
20613 CHECK_EQ(v8_str("escape value"), values[i]); 20729 CHECK_EQ(v8_str("escape value"), values[i]);
20614 } else { 20730 } else {
20615 CHECK(values[i].IsEmpty()); 20731 CHECK(values[i].IsEmpty());
20616 } 20732 }
20617 } 20733 }
20618 } 20734 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698