| 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,
|
|
|