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

Side by Side Diff: src/api.cc

Issue 2156303002: Implement new Function.prototype.toString and fix CreateDynamicFunction parsing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add DCHECK for the name anonymous Created 3 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
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | src/parsing/parser-base.h » ('J')
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 // 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 2256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2267 2267
2268 2268
2269 MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( 2269 MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
2270 Local<Context> v8_context, Source* source, size_t arguments_count, 2270 Local<Context> v8_context, Source* source, size_t arguments_count,
2271 Local<String> arguments[], size_t context_extension_count, 2271 Local<String> arguments[], size_t context_extension_count,
2272 Local<Object> context_extensions[]) { 2272 Local<Object> context_extensions[]) {
2273 PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext, 2273 PREPARE_FOR_EXECUTION(v8_context, ScriptCompiler, CompileFunctionInContext,
2274 Function); 2274 Function);
2275 TRACE_EVENT0("v8", "V8.ScriptCompiler"); 2275 TRACE_EVENT0("v8", "V8.ScriptCompiler");
2276 i::Handle<i::String> source_string; 2276 i::Handle<i::String> source_string;
2277 int parameters_end_pos = i::kNoSourcePosition;
2277 auto factory = isolate->factory(); 2278 auto factory = isolate->factory();
2278 if (arguments_count) { 2279 if (arguments_count) {
2279 source_string = factory->NewStringFromStaticChars("(function("); 2280 if (i::FLAG_harmony_function_tostring) {
2281 source_string = factory->NewStringFromStaticChars("(function anonymous(");
2282 } else {
2283 source_string = factory->NewStringFromStaticChars("(function(");
2284 }
2280 for (size_t i = 0; i < arguments_count; ++i) { 2285 for (size_t i = 0; i < arguments_count; ++i) {
2281 IsIdentifierHelper helper; 2286 IsIdentifierHelper helper;
2282 if (!helper.Check(*Utils::OpenHandle(*arguments[i]))) { 2287 if (!helper.Check(*Utils::OpenHandle(*arguments[i]))) {
2283 return Local<Function>(); 2288 return Local<Function>();
2284 } 2289 }
2285 has_pending_exception = 2290 has_pending_exception =
2286 !factory->NewConsString(source_string, 2291 !factory->NewConsString(source_string,
2287 Utils::OpenHandle(*arguments[i])) 2292 Utils::OpenHandle(*arguments[i]))
2288 .ToHandle(&source_string); 2293 .ToHandle(&source_string);
2289 RETURN_ON_FAILED_EXECUTION(Function); 2294 RETURN_ON_FAILED_EXECUTION(Function);
2290 if (i + 1 == arguments_count) continue; 2295 if (i + 1 == arguments_count) continue;
2291 has_pending_exception = 2296 has_pending_exception =
2292 !factory->NewConsString(source_string, 2297 !factory->NewConsString(source_string,
2293 factory->LookupSingleCharacterStringFromCode( 2298 factory->LookupSingleCharacterStringFromCode(
2294 ',')).ToHandle(&source_string); 2299 ',')).ToHandle(&source_string);
2295 RETURN_ON_FAILED_EXECUTION(Function); 2300 RETURN_ON_FAILED_EXECUTION(Function);
2296 } 2301 }
2297 auto brackets = factory->NewStringFromStaticChars("){"); 2302 i::Handle<i::String> brackets;
2303 if (i::FLAG_harmony_function_tostring) {
2304 brackets = factory->NewStringFromStaticChars("\n) {");
2305 parameters_end_pos = source_string->length() - 3;
2306 } else {
2307 brackets = factory->NewStringFromStaticChars("){");
2308 }
2298 has_pending_exception = !factory->NewConsString(source_string, brackets) 2309 has_pending_exception = !factory->NewConsString(source_string, brackets)
2299 .ToHandle(&source_string); 2310 .ToHandle(&source_string);
2300 RETURN_ON_FAILED_EXECUTION(Function); 2311 RETURN_ON_FAILED_EXECUTION(Function);
2301 } else { 2312 } else {
2302 source_string = factory->NewStringFromStaticChars("(function(){"); 2313 if (i::FLAG_harmony_function_tostring) {
2314 source_string =
2315 factory->NewStringFromStaticChars("(function anonymous(\n) {");
2316 parameters_end_pos = source_string->length() - 3;
2317 } else {
2318 source_string = factory->NewStringFromStaticChars("(function(){");
2319 }
2303 } 2320 }
2304 2321
2305 int scope_position = source_string->length(); 2322 int scope_position = source_string->length();
2306 has_pending_exception = 2323 has_pending_exception =
2307 !factory->NewConsString(source_string, 2324 !factory->NewConsString(source_string,
2308 Utils::OpenHandle(*source->source_string)) 2325 Utils::OpenHandle(*source->source_string))
2309 .ToHandle(&source_string); 2326 .ToHandle(&source_string);
2310 RETURN_ON_FAILED_EXECUTION(Function); 2327 RETURN_ON_FAILED_EXECUTION(Function);
2311 // Include \n in case the source contains a line end comment. 2328 // Include \n in case the source contains a line end comment.
2312 auto brackets = factory->NewStringFromStaticChars("\n})"); 2329 auto brackets = factory->NewStringFromStaticChars("\n})");
(...skipping 29 matching lines...) Expand all
2342 if (!source->resource_line_offset.IsEmpty()) { 2359 if (!source->resource_line_offset.IsEmpty()) {
2343 line_offset = static_cast<int>(source->resource_line_offset->Value()); 2360 line_offset = static_cast<int>(source->resource_line_offset->Value());
2344 } 2361 }
2345 if (!source->resource_column_offset.IsEmpty()) { 2362 if (!source->resource_column_offset.IsEmpty()) {
2346 column_offset = static_cast<int>(source->resource_column_offset->Value()); 2363 column_offset = static_cast<int>(source->resource_column_offset->Value());
2347 } 2364 }
2348 i::Handle<i::JSFunction> fun; 2365 i::Handle<i::JSFunction> fun;
2349 has_pending_exception = 2366 has_pending_exception =
2350 !i::Compiler::GetFunctionFromEval( 2367 !i::Compiler::GetFunctionFromEval(
2351 source_string, outer_info, context, i::SLOPPY, 2368 source_string, outer_info, context, i::SLOPPY,
2352 i::ONLY_SINGLE_FUNCTION_LITERAL, eval_scope_position, eval_position, 2369 i::ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos,
2353 line_offset, column_offset - scope_position, name_obj, 2370 eval_scope_position, eval_position, line_offset,
2354 source->resource_options) 2371 column_offset - scope_position, name_obj, source->resource_options)
2355 .ToHandle(&fun); 2372 .ToHandle(&fun);
2356 if (has_pending_exception) { 2373 if (has_pending_exception) {
2357 isolate->ReportPendingMessages(); 2374 isolate->ReportPendingMessages();
2358 } 2375 }
2359 RETURN_ON_FAILED_EXECUTION(Function); 2376 RETURN_ON_FAILED_EXECUTION(Function);
2360 2377
2361 i::Handle<i::Object> result; 2378 i::Handle<i::Object> result;
2362 has_pending_exception = 2379 has_pending_exception =
2363 !i::Execution::Call(isolate, fun, 2380 !i::Execution::Call(isolate, fun,
2364 Utils::OpenHandle(*v8_context->Global()), 0, 2381 Utils::OpenHandle(*v8_context->Global()), 0,
(...skipping 7798 matching lines...) Expand 10 before | Expand all | Expand 10 after
10163 Address callback_address = 10180 Address callback_address =
10164 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10181 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10165 VMState<EXTERNAL> state(isolate); 10182 VMState<EXTERNAL> state(isolate);
10166 ExternalCallbackScope call_scope(isolate, callback_address); 10183 ExternalCallbackScope call_scope(isolate, callback_address);
10167 callback(info); 10184 callback(info);
10168 } 10185 }
10169 10186
10170 10187
10171 } // namespace internal 10188 } // namespace internal
10172 } // namespace v8 10189 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/bootstrapper.cc » ('j') | src/parsing/parser-base.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698