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

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 4 years 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
Index: src/builtins/builtins-function.cc
diff --git a/src/builtins/builtins-function.cc b/src/builtins/builtins-function.cc
index 6cd1b283ec6f1e144bc1fe8cff3b5a5783da185c..ceec1a4bad959f2342c3730c4533fa016c9a4999 100644
--- a/src/builtins/builtins-function.cc
+++ b/src/builtins/builtins-function.cc
@@ -31,11 +31,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,24 +51,33 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
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) {
+ parameters_end_pos = builder.Length() + 1;
+ builder.AppendCString("\n) {");
+ } else {
+ builder.AppendCString(") {\n");
}
- builder.AppendCString(") {\n");
if (argc > 0) {
Handle<String> body;
ASSIGN_RETURN_ON_EXCEPTION(
@@ -87,11 +101,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,

Powered by Google App Engine
This is Rietveld 408576698