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 23390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23401 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); | 23401 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); |
23402 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 23402 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
23403 CHECK(!script_name.IsEmpty()); | 23403 CHECK(!script_name.IsEmpty()); |
23404 CHECK(script_name->IsString()); | 23404 CHECK(script_name->IsString()); |
23405 String::Utf8Value utf8_name(script_name); | 23405 String::Utf8Value utf8_name(script_name); |
23406 CHECK_EQ(0, strcmp(url, *utf8_name)); | 23406 CHECK_EQ(0, strcmp(url, *utf8_name)); |
23407 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 23407 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
23408 CHECK_EQ(13, line_number); | 23408 CHECK_EQ(13, line_number); |
23409 } | 23409 } |
23410 | 23410 |
| 23411 TEST(ScriptPositionInfo) { |
| 23412 LocalContext env; |
| 23413 v8::Isolate* isolate = env->GetIsolate(); |
| 23414 v8::HandleScope scope(isolate); |
| 23415 const char* url = "http://www.foo.com/foo.js"; |
| 23416 v8::ScriptOrigin origin(v8_str(url), v8::Integer::New(isolate, 13)); |
| 23417 v8::ScriptCompiler::Source script_source(v8_str("var foo;\n" |
| 23418 "var bar;\n" |
| 23419 "var fisk = foo + bar;\n"), |
| 23420 origin); |
| 23421 Local<Script> script = |
| 23422 v8::ScriptCompiler::Compile(env.local(), &script_source).ToLocalChecked(); |
| 23423 |
| 23424 i::Handle<i::SharedFunctionInfo> obj = i::Handle<i::SharedFunctionInfo>::cast( |
| 23425 v8::Utils::OpenHandle(*script->GetUnboundScript())); |
| 23426 CHECK(obj->script()->IsScript()); |
| 23427 |
| 23428 i::Handle<i::Script> script1(i::Script::cast(obj->script())); |
| 23429 |
| 23430 v8::internal::Script::PositionInfo info; |
| 23431 |
| 23432 // With offset. |
| 23433 |
| 23434 // Behave as if 0 was passed if position is negative. |
| 23435 CHECK(script1->GetPositionInfo(-1, &info, script1->kWithOffset)); |
| 23436 CHECK_EQ(13, info.line); |
| 23437 CHECK_EQ(0, info.column); |
| 23438 CHECK_EQ(0, info.line_start); |
| 23439 CHECK_EQ(8, info.line_end); |
| 23440 |
| 23441 CHECK(script1->GetPositionInfo(0, &info, script1->kWithOffset)); |
| 23442 CHECK_EQ(13, info.line); |
| 23443 CHECK_EQ(0, info.column); |
| 23444 CHECK_EQ(0, info.line_start); |
| 23445 CHECK_EQ(8, info.line_end); |
| 23446 |
| 23447 CHECK(script1->GetPositionInfo(8, &info, script1->kWithOffset)); |
| 23448 CHECK_EQ(13, info.line); |
| 23449 CHECK_EQ(8, info.column); |
| 23450 CHECK_EQ(0, info.line_start); |
| 23451 CHECK_EQ(8, info.line_end); |
| 23452 |
| 23453 CHECK(script1->GetPositionInfo(9, &info, script1->kWithOffset)); |
| 23454 CHECK_EQ(14, info.line); |
| 23455 CHECK_EQ(0, info.column); |
| 23456 CHECK_EQ(9, info.line_start); |
| 23457 CHECK_EQ(17, info.line_end); |
| 23458 |
| 23459 // Fail when position is larger than script size. |
| 23460 CHECK(!script1->GetPositionInfo(220384, &info, script1->kWithOffset)); |
| 23461 |
| 23462 // Without offset. |
| 23463 |
| 23464 // Behave as if 0 was passed if position is negative. |
| 23465 CHECK(script1->GetPositionInfo(-1, &info, script1->kNoOffset)); |
| 23466 CHECK_EQ(0, info.line); |
| 23467 CHECK_EQ(0, info.column); |
| 23468 CHECK_EQ(0, info.line_start); |
| 23469 CHECK_EQ(8, info.line_end); |
| 23470 |
| 23471 CHECK(script1->GetPositionInfo(0, &info, script1->kNoOffset)); |
| 23472 CHECK_EQ(0, info.line); |
| 23473 CHECK_EQ(0, info.column); |
| 23474 CHECK_EQ(0, info.line_start); |
| 23475 CHECK_EQ(8, info.line_end); |
| 23476 |
| 23477 CHECK(script1->GetPositionInfo(8, &info, script1->kNoOffset)); |
| 23478 CHECK_EQ(0, info.line); |
| 23479 CHECK_EQ(8, info.column); |
| 23480 CHECK_EQ(0, info.line_start); |
| 23481 CHECK_EQ(8, info.line_end); |
| 23482 |
| 23483 CHECK(script1->GetPositionInfo(9, &info, script1->kNoOffset)); |
| 23484 CHECK_EQ(1, info.line); |
| 23485 CHECK_EQ(0, info.column); |
| 23486 CHECK_EQ(9, info.line_start); |
| 23487 CHECK_EQ(17, info.line_end); |
| 23488 |
| 23489 // Fail when position is larger than script size. |
| 23490 CHECK(!script1->GetPositionInfo(220384, &info, script1->kNoOffset)); |
| 23491 } |
| 23492 |
23411 void CheckMagicComments(Local<Script> script, const char* expected_source_url, | 23493 void CheckMagicComments(Local<Script> script, const char* expected_source_url, |
23412 const char* expected_source_mapping_url) { | 23494 const char* expected_source_mapping_url) { |
23413 if (expected_source_url != NULL) { | 23495 if (expected_source_url != NULL) { |
23414 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); | 23496 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); |
23415 CHECK_EQ(0, strcmp(expected_source_url, *url)); | 23497 CHECK_EQ(0, strcmp(expected_source_url, *url)); |
23416 } else { | 23498 } else { |
23417 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); | 23499 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); |
23418 } | 23500 } |
23419 if (expected_source_mapping_url != NULL) { | 23501 if (expected_source_mapping_url != NULL) { |
23420 v8::String::Utf8Value url( | 23502 v8::String::Utf8Value url( |
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
25144 } | 25226 } |
25145 | 25227 |
25146 TEST(PrivateForApiIsNumber) { | 25228 TEST(PrivateForApiIsNumber) { |
25147 LocalContext context; | 25229 LocalContext context; |
25148 v8::Isolate* isolate = CcTest::isolate(); | 25230 v8::Isolate* isolate = CcTest::isolate(); |
25149 v8::HandleScope scope(isolate); | 25231 v8::HandleScope scope(isolate); |
25150 | 25232 |
25151 // Shouldn't crash. | 25233 // Shouldn't crash. |
25152 v8::Private::ForApi(isolate, v8_str("42")); | 25234 v8::Private::ForApi(isolate, v8_str("42")); |
25153 } | 25235 } |
OLD | NEW |