Commit ad126d46 authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

Make SharedFunctionInfo::GetSourceCodeHarmony GC-safe.

R=mlippautz@chromium.org

Bug: chromium:795856
Change-Id: I2a631a94e4bc0c000842923a962e812e0370b837
Reviewed-on: https://chromium-review.googlesource.com/832454
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50190}
parent 43577d65
...@@ -13163,7 +13163,8 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) { ...@@ -13163,7 +13163,8 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
} }
if (FLAG_harmony_function_tostring) { if (FLAG_harmony_function_tostring) {
return Handle<String>::cast(shared_info->GetSourceCodeHarmony()); return Handle<String>::cast(
SharedFunctionInfo::GetSourceCodeHarmony(shared_info));
} }
IncrementalStringBuilder builder(isolate); IncrementalStringBuilder builder(isolate);
...@@ -13205,7 +13206,8 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) { ...@@ -13205,7 +13206,8 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
} }
builder.AppendCString(") {\n"); builder.AppendCString(") {\n");
} }
builder.AppendString(Handle<String>::cast(shared_info->GetSourceCode())); builder.AppendString(
Handle<String>::cast(SharedFunctionInfo::GetSourceCode(shared_info)));
if (shared_info->is_wrapped()) { if (shared_info->is_wrapped()) {
builder.AppendCString("\n}"); builder.AppendCString("\n}");
} }
...@@ -13687,27 +13689,32 @@ bool SharedFunctionInfo::HasSourceCode() const { ...@@ -13687,27 +13689,32 @@ bool SharedFunctionInfo::HasSourceCode() const {
!reinterpret_cast<Script*>(script())->source()->IsUndefined(isolate); !reinterpret_cast<Script*>(script())->source()->IsUndefined(isolate);
} }
// static
Handle<Object> SharedFunctionInfo::GetSourceCode() { Handle<Object> SharedFunctionInfo::GetSourceCode(
if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value(); Handle<SharedFunctionInfo> shared) {
Handle<String> source(String::cast(Script::cast(script())->source())); Isolate* isolate = shared->GetIsolate();
return GetIsolate()->factory()->NewSubString( if (!shared->HasSourceCode()) return isolate->factory()->undefined_value();
source, start_position(), end_position()); Handle<String> source(String::cast(Script::cast(shared->script())->source()));
return isolate->factory()->NewSubString(source, shared->start_position(),
shared->end_position());
} }
Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony() { // static
Isolate* isolate = GetIsolate(); Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony(
if (!HasSourceCode()) return isolate->factory()->undefined_value(); Handle<SharedFunctionInfo> shared) {
Handle<String> script_source(String::cast(Script::cast(script())->source())); Isolate* isolate = shared->GetIsolate();
int start_pos = function_token_position(); if (!shared->HasSourceCode()) return isolate->factory()->undefined_value();
if (start_pos == kNoSourcePosition) start_pos = start_position(); Handle<String> script_source(
String::cast(Script::cast(shared->script())->source()));
int start_pos = shared->function_token_position();
if (start_pos == kNoSourcePosition) start_pos = shared->start_position();
Handle<String> source = isolate->factory()->NewSubString( Handle<String> source = isolate->factory()->NewSubString(
script_source, start_pos, end_position()); script_source, start_pos, shared->end_position());
if (!is_wrapped()) return source; if (!shared->is_wrapped()) return source;
IncrementalStringBuilder builder(isolate); IncrementalStringBuilder builder(isolate);
builder.AppendCString("function ("); builder.AppendCString("function (");
Handle<FixedArray> args(Script::cast(script())->wrapped_arguments()); Handle<FixedArray> args(Script::cast(shared->script())->wrapped_arguments());
int argc = args->length(); int argc = args->length();
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
if (i > 0) builder.AppendCString(", "); if (i > 0) builder.AppendCString(", ");
......
...@@ -339,8 +339,8 @@ class SharedFunctionInfo : public HeapObject { ...@@ -339,8 +339,8 @@ class SharedFunctionInfo : public HeapObject {
// [source code]: Source code for the function. // [source code]: Source code for the function.
bool HasSourceCode() const; bool HasSourceCode() const;
Handle<Object> GetSourceCode(); static Handle<Object> GetSourceCode(Handle<SharedFunctionInfo> shared);
Handle<Object> GetSourceCodeHarmony(); static Handle<Object> GetSourceCodeHarmony(Handle<SharedFunctionInfo> shared);
// Tells whether this function should be subject to debugging. // Tells whether this function should be subject to debugging.
inline bool IsSubjectToDebugging(); inline bool IsSubjectToDebugging();
......
...@@ -63,7 +63,9 @@ RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) { ...@@ -63,7 +63,9 @@ RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
if (function->IsJSFunction()) { if (function->IsJSFunction()) {
return *Handle<JSFunction>::cast(function)->shared()->GetSourceCode(); Handle<SharedFunctionInfo> shared(
Handle<JSFunction>::cast(function)->shared());
return *SharedFunctionInfo::GetSourceCode(shared);
} }
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment