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

Unified Diff: src/builtins/builtins-function.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: rebase 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/bootstrapper.cc ('k') | src/builtins/builtins-global.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-function.cc
diff --git a/src/builtins/builtins-function.cc b/src/builtins/builtins-function.cc
index f306ea2bc4b03e2632f49f1756b6b8172433af0e..1e9b7f7d525970ae11afa0323b2babafbf5003e2 100644
--- a/src/builtins/builtins-function.cc
+++ b/src/builtins/builtins-function.cc
@@ -32,11 +32,16 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
// Build the source string.
Handle<String> source;
+ int parameters_end_pos = kNoSourcePosition;
{
IncrementalStringBuilder builder(isolate);
builder.AppendCharacter('(');
builder.AppendCString(token);
- builder.AppendCharacter('(');
+ if (FLAG_harmony_function_tostring) {
+ builder.AppendCString(" anonymous(");
+ } else {
+ builder.AppendCharacter('(');
+ }
bool parenthesis_in_arg_string = false;
if (argc > 1) {
for (int i = 1; i < argc; ++i) {
@@ -46,22 +51,30 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
isolate, param, Object::ToString(isolate, args.at(i)), Object);
param = String::Flatten(param);
builder.AppendString(param);
- // If the formal parameters string include ) - an illegal
- // character - it may make the combined function expression
- // compile. We avoid this problem by checking for this early on.
- DisallowHeapAllocation no_gc; // Ensure vectors stay valid.
- String::FlatContent param_content = param->GetFlatContent();
- for (int i = 0, length = param->length(); i < length; ++i) {
- if (param_content.Get(i) == ')') {
- parenthesis_in_arg_string = true;
- break;
+ if (!FLAG_harmony_function_tostring) {
+ // If the formal parameters string include ) - an illegal
+ // character - it may make the combined function expression
+ // compile. We avoid this problem by checking for this early on.
+ DisallowHeapAllocation no_gc; // Ensure vectors stay valid.
+ String::FlatContent param_content = param->GetFlatContent();
+ for (int i = 0, length = param->length(); i < length; ++i) {
+ if (param_content.Get(i) == ')') {
+ parenthesis_in_arg_string = true;
+ break;
+ }
}
}
}
- // If the formal parameters include an unbalanced block comment, the
- // function must be rejected. Since JavaScript does not allow nested
- // comments we can include a trailing block comment to catch this.
- builder.AppendCString("\n/*``*/");
+ if (!FLAG_harmony_function_tostring) {
+ // If the formal parameters include an unbalanced block comment, the
+ // function must be rejected. Since JavaScript does not allow nested
+ // comments we can include a trailing block comment to catch this.
+ builder.AppendCString("\n/*``*/");
+ }
+ }
+ if (FLAG_harmony_function_tostring) {
+ builder.AppendCharacter('\n');
+ parameters_end_pos = builder.Length();
}
builder.AppendCString(") {\n");
if (argc > 0) {
@@ -86,11 +99,12 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
// come from here.
Handle<JSFunction> function;
{
- ASSIGN_RETURN_ON_EXCEPTION(isolate, function,
- Compiler::GetFunctionFromString(
- handle(target->native_context(), isolate),
- source, ONLY_SINGLE_FUNCTION_LITERAL),
- Object);
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, function,
+ Compiler::GetFunctionFromString(
+ handle(target->native_context(), isolate), source,
+ ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos),
+ Object);
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
« no previous file with comments | « src/bootstrapper.cc ('k') | src/builtins/builtins-global.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698