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

Unified Diff: src/objects.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/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 11114f9c04d007dc7c4309a23b43230135fbfedd..64a67ba134d2a541804a355f55d7498b7d14b45f 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -13361,6 +13361,10 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
return NativeCodeFunctionSourceString(shared_info);
}
+ if (FLAG_harmony_function_tostring) {
+ return Handle<String>::cast(shared_info->GetSourceCodeHarmony());
+ }
+
IncrementalStringBuilder builder(isolate);
FunctionKind kind = shared_info->kind();
if (!IsArrowFunction(kind)) {
@@ -13799,6 +13803,15 @@ Handle<Object> SharedFunctionInfo::GetSourceCode() {
source, start_position(), end_position());
}
+Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony() {
+ Isolate* isolate = GetIsolate();
+ if (!HasSourceCode()) return isolate->factory()->undefined_value();
+ Handle<String> script_source(String::cast(Script::cast(script())->source()));
+ int start_pos = function_token_position();
+ if (start_pos == kNoSourcePosition) start_pos = start_position();
+ return isolate->factory()->NewSubString(script_source, start_pos,
+ end_position());
+}
bool SharedFunctionInfo::IsInlineable() {
// Check that the function has a script associated with it.

Powered by Google App Engine
This is Rietveld 408576698