| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 | 2268 |
| 2269 | 2269 |
| 2270 MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( | 2270 MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( |
| 2271 Local<Context> v8_context, Source* source, size_t arguments_count, | 2271 Local<Context> v8_context, Source* source, size_t arguments_count, |
| 2272 Local<String> arguments[], size_t context_extension_count, | 2272 Local<String> arguments[], size_t context_extension_count, |
| 2273 Local<Object> context_extensions[]) { | 2273 Local<Object> context_extensions[]) { |
| 2274 PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, | 2274 PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, |
| 2275 Function); | 2275 Function); |
| 2276 TRACE_EVENT0("v8", "V8.ScriptCompiler"); | 2276 TRACE_EVENT0("v8", "V8.ScriptCompiler"); |
| 2277 i::Handle<i::String> source_string; | 2277 i::Handle<i::String> source_string; |
| 2278 int parameters_end_pos = i::kNoSourcePosition; |
| 2278 auto factory = isolate->factory(); | 2279 auto factory = isolate->factory(); |
| 2279 if (arguments_count) { | 2280 if (arguments_count) { |
| 2280 source_string = factory->NewStringFromStaticChars("(function("); | 2281 if (i::FLAG_harmony_function_tostring) { |
| 2282 source_string = factory->NewStringFromStaticChars("(function anonymous("); |
| 2283 } else { |
| 2284 source_string = factory->NewStringFromStaticChars("(function("); |
| 2285 } |
| 2281 for (size_t i = 0; i < arguments_count; ++i) { | 2286 for (size_t i = 0; i < arguments_count; ++i) { |
| 2282 IsIdentifierHelper helper; | 2287 IsIdentifierHelper helper; |
| 2283 if (!helper.Check(*Utils::OpenHandle(*arguments[i]))) { | 2288 if (!helper.Check(*Utils::OpenHandle(*arguments[i]))) { |
| 2284 return Local<Function>(); | 2289 return Local<Function>(); |
| 2285 } | 2290 } |
| 2286 has_pending_exception = | 2291 has_pending_exception = |
| 2287 !factory->NewConsString(source_string, | 2292 !factory->NewConsString(source_string, |
| 2288 Utils::OpenHandle(*arguments[i])) | 2293 Utils::OpenHandle(*arguments[i])) |
| 2289 .ToHandle(&source_string); | 2294 .ToHandle(&source_string); |
| 2290 RETURN_ON_FAILED_EXECUTION(Function); | 2295 RETURN_ON_FAILED_EXECUTION(Function); |
| 2291 if (i + 1 == arguments_count) continue; | 2296 if (i + 1 == arguments_count) continue; |
| 2292 has_pending_exception = | 2297 has_pending_exception = |
| 2293 !factory->NewConsString(source_string, | 2298 !factory->NewConsString(source_string, |
| 2294 factory->LookupSingleCharacterStringFromCode( | 2299 factory->LookupSingleCharacterStringFromCode( |
| 2295 ',')).ToHandle(&source_string); | 2300 ',')).ToHandle(&source_string); |
| 2296 RETURN_ON_FAILED_EXECUTION(Function); | 2301 RETURN_ON_FAILED_EXECUTION(Function); |
| 2297 } | 2302 } |
| 2298 auto brackets = factory->NewStringFromStaticChars("){"); | 2303 i::Handle<i::String> brackets; |
| 2304 if (i::FLAG_harmony_function_tostring) { |
| 2305 brackets = factory->NewStringFromStaticChars("\n) {"); |
| 2306 parameters_end_pos = source_string->length() - 3; |
| 2307 } else { |
| 2308 brackets = factory->NewStringFromStaticChars("){"); |
| 2309 } |
| 2299 has_pending_exception = !factory->NewConsString(source_string, brackets) | 2310 has_pending_exception = !factory->NewConsString(source_string, brackets) |
| 2300 .ToHandle(&source_string); | 2311 .ToHandle(&source_string); |
| 2301 RETURN_ON_FAILED_EXECUTION(Function); | 2312 RETURN_ON_FAILED_EXECUTION(Function); |
| 2302 } else { | 2313 } else { |
| 2303 source_string = factory->NewStringFromStaticChars("(function(){"); | 2314 if (i::FLAG_harmony_function_tostring) { |
| 2315 source_string = |
| 2316 factory->NewStringFromStaticChars("(function anonymous(\n) {"); |
| 2317 parameters_end_pos = source_string->length() - 3; |
| 2318 } else { |
| 2319 source_string = factory->NewStringFromStaticChars("(function(){"); |
| 2320 } |
| 2304 } | 2321 } |
| 2305 | 2322 |
| 2306 int scope_position = source_string->length(); | 2323 int scope_position = source_string->length(); |
| 2307 has_pending_exception = | 2324 has_pending_exception = |
| 2308 !factory->NewConsString(source_string, | 2325 !factory->NewConsString(source_string, |
| 2309 Utils::OpenHandle(*source->source_string)) | 2326 Utils::OpenHandle(*source->source_string)) |
| 2310 .ToHandle(&source_string); | 2327 .ToHandle(&source_string); |
| 2311 RETURN_ON_FAILED_EXECUTION(Function); | 2328 RETURN_ON_FAILED_EXECUTION(Function); |
| 2312 // Include \n in case the source contains a line end comment. | 2329 // Include \n in case the source contains a line end comment. |
| 2313 auto brackets = factory->NewStringFromStaticChars("\n})"); | 2330 auto brackets = factory->NewStringFromStaticChars("\n})"); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2343 if (!source->resource_line_offset.IsEmpty()) { | 2360 if (!source->resource_line_offset.IsEmpty()) { |
| 2344 line_offset = static_cast<int>(source->resource_line_offset->Value()); | 2361 line_offset = static_cast<int>(source->resource_line_offset->Value()); |
| 2345 } | 2362 } |
| 2346 if (!source->resource_column_offset.IsEmpty()) { | 2363 if (!source->resource_column_offset.IsEmpty()) { |
| 2347 column_offset = static_cast<int>(source->resource_column_offset->Value()); | 2364 column_offset = static_cast<int>(source->resource_column_offset->Value()); |
| 2348 } | 2365 } |
| 2349 i::Handle<i::JSFunction> fun; | 2366 i::Handle<i::JSFunction> fun; |
| 2350 has_pending_exception = | 2367 has_pending_exception = |
| 2351 !i::Compiler::GetFunctionFromEval( | 2368 !i::Compiler::GetFunctionFromEval( |
| 2352 source_string, outer_info, context, i::SLOPPY, | 2369 source_string, outer_info, context, i::SLOPPY, |
| 2353 i::ONLY_SINGLE_FUNCTION_LITERAL, eval_scope_position, eval_position, | 2370 i::ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos, |
| 2354 line_offset, column_offset - scope_position, name_obj, | 2371 eval_scope_position, eval_position, line_offset, |
| 2355 source->resource_options) | 2372 column_offset - scope_position, name_obj, source->resource_options) |
| 2356 .ToHandle(&fun); | 2373 .ToHandle(&fun); |
| 2357 if (has_pending_exception) { | 2374 if (has_pending_exception) { |
| 2358 isolate->ReportPendingMessages(); | 2375 isolate->ReportPendingMessages(); |
| 2359 } | 2376 } |
| 2360 RETURN_ON_FAILED_EXECUTION(Function); | 2377 RETURN_ON_FAILED_EXECUTION(Function); |
| 2361 | 2378 |
| 2362 i::Handle<i::Object> result; | 2379 i::Handle<i::Object> result; |
| 2363 has_pending_exception = | 2380 has_pending_exception = |
| 2364 !i::Execution::Call(isolate, fun, | 2381 !i::Execution::Call(isolate, fun, |
| 2365 Utils::OpenHandle(*v8_context->Global()), 0, | 2382 Utils::OpenHandle(*v8_context->Global()), 0, |
| (...skipping 7850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10216 Address callback_address = | 10233 Address callback_address = |
| 10217 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10234 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10218 VMState<EXTERNAL> state(isolate); | 10235 VMState<EXTERNAL> state(isolate); |
| 10219 ExternalCallbackScope call_scope(isolate, callback_address); | 10236 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10220 callback(info); | 10237 callback(info); |
| 10221 } | 10238 } |
| 10222 | 10239 |
| 10223 | 10240 |
| 10224 } // namespace internal | 10241 } // namespace internal |
| 10225 } // namespace v8 | 10242 } // namespace v8 |
| OLD | NEW |