OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 23404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23415 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); | 23415 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); |
23416 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 23416 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
23417 CHECK(!script_name.IsEmpty()); | 23417 CHECK(!script_name.IsEmpty()); |
23418 CHECK(script_name->IsString()); | 23418 CHECK(script_name->IsString()); |
23419 String::Utf8Value utf8_name(script_name); | 23419 String::Utf8Value utf8_name(script_name); |
23420 CHECK_EQ(0, strcmp(url, *utf8_name)); | 23420 CHECK_EQ(0, strcmp(url, *utf8_name)); |
23421 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 23421 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
23422 CHECK_EQ(13, line_number); | 23422 CHECK_EQ(13, line_number); |
23423 } | 23423 } |
23424 | 23424 |
| 23425 TEST(ScriptPositionInfo) { |
| 23426 LocalContext env; |
| 23427 v8::Isolate* isolate = env->GetIsolate(); |
| 23428 v8::HandleScope scope(isolate); |
| 23429 const char* url = "http://www.foo.com/foo.js"; |
| 23430 v8::ScriptOrigin origin(v8_str(url), v8::Integer::New(isolate, 13)); |
| 23431 v8::ScriptCompiler::Source script_source(v8_str("var foo;\n" |
| 23432 "var bar;\n" |
| 23433 "var fisk = foo + bar;\n"), |
| 23434 origin); |
| 23435 Local<Script> script = |
| 23436 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); |
| 23437 |
| 23438 i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo>::cast( |
| 23439 v8::Utils::OpenHandle(*script->GetUnboundScript())); |
| 23440 CHECK(obj->script()->IsScript()); |
| 23441 |
| 23442 i::Handle<i::Script> script1(i::Script::cast(obj->script())); |
| 23443 |
| 23444 v8::internal::Script::PositionInfo info; |
| 23445 |
| 23446 // With offset. |
| 23447 |
| 23448 // Behave as if 0 was passed if position is negative. |
| 23449 CHECK(script1->GetPositionInfo(-1, &info, script1->WITH_OFFSET)); |
| 23450 CHECK_EQ(13, info.line); |
| 23451 CHECK_EQ(0, info.column); |
| 23452 CHECK_EQ(0, info.line_start); |
| 23453 CHECK_EQ(8, info.line_end); |
| 23454 |
| 23455 CHECK(script1->GetPositionInfo(0, &info, script1->WITH_OFFSET)); |
| 23456 CHECK_EQ(13, info.line); |
| 23457 CHECK_EQ(0, info.column); |
| 23458 CHECK_EQ(0, info.line_start); |
| 23459 CHECK_EQ(8, info.line_end); |
| 23460 |
| 23461 CHECK(script1->GetPositionInfo(8, &info, script1->WITH_OFFSET)); |
| 23462 CHECK_EQ(13, info.line); |
| 23463 CHECK_EQ(8, info.column); |
| 23464 CHECK_EQ(0, info.line_start); |
| 23465 CHECK_EQ(8, info.line_end); |
| 23466 |
| 23467 CHECK(script1->GetPositionInfo(9, &info, script1->WITH_OFFSET)); |
| 23468 CHECK_EQ(14, info.line); |
| 23469 CHECK_EQ(0, info.column); |
| 23470 CHECK_EQ(9, info.line_start); |
| 23471 CHECK_EQ(17, info.line_end); |
| 23472 |
| 23473 // Fail when position is larger than script size. |
| 23474 CHECK(!script1->GetPositionInfo(220384, &info, script1->WITH_OFFSET)); |
| 23475 |
| 23476 // Without offset. |
| 23477 |
| 23478 // Behave as if 0 was passed if position is negative. |
| 23479 CHECK(script1->GetPositionInfo(-1, &info, script1->NO_OFFSET)); |
| 23480 CHECK_EQ(0, info.line); |
| 23481 CHECK_EQ(0, info.column); |
| 23482 CHECK_EQ(0, info.line_start); |
| 23483 CHECK_EQ(8, info.line_end); |
| 23484 |
| 23485 CHECK(script1->GetPositionInfo(0, &info, script1->NO_OFFSET)); |
| 23486 CHECK_EQ(0, info.line); |
| 23487 CHECK_EQ(0, info.column); |
| 23488 CHECK_EQ(0, info.line_start); |
| 23489 CHECK_EQ(8, info.line_end); |
| 23490 |
| 23491 CHECK(script1->GetPositionInfo(8, &info, script1->NO_OFFSET)); |
| 23492 CHECK_EQ(0, info.line); |
| 23493 CHECK_EQ(8, info.column); |
| 23494 CHECK_EQ(0, info.line_start); |
| 23495 CHECK_EQ(8, info.line_end); |
| 23496 |
| 23497 CHECK(script1->GetPositionInfo(9, &info, script1->NO_OFFSET)); |
| 23498 CHECK_EQ(1, info.line); |
| 23499 CHECK_EQ(0, info.column); |
| 23500 CHECK_EQ(9, info.line_start); |
| 23501 CHECK_EQ(17, info.line_end); |
| 23502 |
| 23503 // Fail when position is larger than script size. |
| 23504 CHECK(!script1->GetPositionInfo(220384, &info, script1->NO_OFFSET)); |
| 23505 } |
| 23506 |
23425 void CheckMagicComments(Local<Script> script, const char* expected_source_url, | 23507 void CheckMagicComments(Local<Script> script, const char* expected_source_url, |
23426 const char* expected_source_mapping_url) { | 23508 const char* expected_source_mapping_url) { |
23427 if (expected_source_url != NULL) { | 23509 if (expected_source_url != NULL) { |
23428 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); | 23510 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
23429 CHECK_EQ(0, strcmp(expected_source_url, *url)); | 23511 CHECK_EQ(0, strcmp(expected_source_url, *url)); |
23430 } else { | 23512 } else { |
23431 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); | 23513 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
23432 } | 23514 } |
23433 if (expected_source_mapping_url != NULL) { | 23515 if (expected_source_mapping_url != NULL) { |
23434 v8::String::Utf8Value url( | 23516 v8::String::Utf8Value url( |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25158 } | 25240 } |
25159 | 25241 |
25160 TEST(PrivateForApiIsNumber) { | 25242 TEST(PrivateForApiIsNumber) { |
25161 LocalContext context; | 25243 LocalContext context; |
25162 v8::Isolate* isolate = CcTest::isolate(); | 25244 v8::Isolate* isolate = CcTest::isolate(); |
25163 v8::HandleScope scope(isolate); | 25245 v8::HandleScope scope(isolate); |
25164 | 25246 |
25165 // Shouldn't crash. | 25247 // Shouldn't crash. |
25166 v8::Private::ForApi(isolate, v8_str("42")); | 25248 v8::Private::ForApi(isolate, v8_str("42")); |
25167 } | 25249 } |
OLD | NEW |