| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 | 114 |
| 115 static Handle<JSFunction> Compile(const char* source) { | 115 static Handle<JSFunction> Compile(const char* source) { |
| 116 Handle<String> source_code(Factory::NewStringFromUtf8(CStrVector(source))); | 116 Handle<String> source_code(Factory::NewStringFromUtf8(CStrVector(source))); |
| 117 Handle<JSFunction> boilerplate = Compiler::Compile(source_code, | 117 Handle<JSFunction> boilerplate = Compiler::Compile(source_code, |
| 118 Handle<String>(), | 118 Handle<String>(), |
| 119 0, | 119 0, |
| 120 0, | 120 0, |
| 121 NULL, | 121 NULL, |
| 122 NULL, | 122 NULL, |
| 123 Handle<String>::null(), |
| 123 NOT_NATIVES_CODE); | 124 NOT_NATIVES_CODE); |
| 124 return Factory::NewFunctionFromBoilerplate(boilerplate, | 125 return Factory::NewFunctionFromBoilerplate(boilerplate, |
| 125 Top::global_context()); | 126 Top::global_context()); |
| 126 } | 127 } |
| 127 | 128 |
| 128 | 129 |
| 129 static double Inc(int x) { | 130 static double Inc(int x) { |
| 130 const char* source = "result = %d + 1;"; | 131 const char* source = "result = %d + 1;"; |
| 131 EmbeddedVector<char, 512> buffer; | 132 EmbeddedVector<char, 512> buffer; |
| 132 OS::SNPrintF(buffer, source, x); | 133 OS::SNPrintF(buffer, source, x); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 TEST(Regression236) { | 316 TEST(Regression236) { |
| 316 InitializeVM(); | 317 InitializeVM(); |
| 317 v8::HandleScope scope; | 318 v8::HandleScope scope; |
| 318 | 319 |
| 319 Handle<Script> script = Factory::NewScript(Factory::empty_string()); | 320 Handle<Script> script = Factory::NewScript(Factory::empty_string()); |
| 320 script->set_source(Heap::undefined_value()); | 321 script->set_source(Heap::undefined_value()); |
| 321 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); | 322 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); |
| 322 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); | 323 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); |
| 323 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); | 324 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); |
| 324 } | 325 } |
| 326 |
| 327 |
| 328 TEST(GetScriptLineNumber) { |
| 329 LocalContext env; |
| 330 v8::HandleScope scope; |
| 331 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
| 332 const char function_f[] = "function f() {}"; |
| 333 const int max_rows = 1000; |
| 334 const int buffer_size = max_rows + sizeof(function_f); |
| 335 ScopedVector<char> buffer(buffer_size); |
| 336 memset(buffer.start(), '\n', buffer_size - 1); |
| 337 buffer[buffer_size - 1] = '\0'; |
| 338 |
| 339 for (int i = 0; i < max_rows; ++i) { |
| 340 if (i > 0) |
| 341 buffer[i - 1] = '\n'; |
| 342 memcpy(&buffer[i], function_f, sizeof(function_f) - 1); |
| 343 v8::Handle<v8::String> script_body = v8::String::New(buffer.start()); |
| 344 v8::Script::Compile(script_body, &origin)->Run(); |
| 345 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 346 env->Global()->Get(v8::String::New("f"))); |
| 347 CHECK_EQ(i, f->GetScriptLineNumber()); |
| 348 } |
| 349 } |
| OLD | NEW |