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) {
}
if (FLAG_harmony_function_tostring) {
return Handle<String>::cast(shared_info->GetSourceCodeHarmony());
return Handle<String>::cast(
SharedFunctionInfo::GetSourceCodeHarmony(shared_info));
}
IncrementalStringBuilder builder(isolate);
......@@ -13205,7 +13206,8 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
}
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()) {
builder.AppendCString("\n}");
}
......@@ -13687,27 +13689,32 @@ bool SharedFunctionInfo::HasSourceCode() const {
!reinterpret_cast<Script*>(script())->source()->IsUndefined(isolate);
}
Handle<Object> SharedFunctionInfo::GetSourceCode() {
if (!HasSourceCode()) return GetIsolate()->factory()->undefined_value();
Handle<String> source(String::cast(Script::cast(script())->source()));
return GetIsolate()->factory()->NewSubString(
source, start_position(), end_position());
// static
Handle<Object> SharedFunctionInfo::GetSourceCode(
Handle<SharedFunctionInfo> shared) {
Isolate* isolate = shared->GetIsolate();
if (!shared->HasSourceCode()) return isolate->factory()->undefined_value();
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() {
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();
// static
Handle<Object> SharedFunctionInfo::GetSourceCodeHarmony(
Handle<SharedFunctionInfo> shared) {
Isolate* isolate = shared->GetIsolate();
if (!shared->HasSourceCode()) return isolate->factory()->undefined_value();
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(
script_source, start_pos, end_position());
if (!is_wrapped()) return source;
script_source, start_pos, shared->end_position());
if (!shared->is_wrapped()) return source;
IncrementalStringBuilder builder(isolate);
builder.AppendCString("function (");
Handle<FixedArray> args(Script::cast(script())->wrapped_arguments());
Handle<FixedArray> args(Script::cast(shared->script())->wrapped_arguments());
int argc = args->length();
for (int i = 0; i < argc; i++) {
if (i > 0) builder.AppendCString(", ");
......
......@@ -339,8 +339,8 @@ class SharedFunctionInfo : public HeapObject {
// [source code]: Source code for the function.
bool HasSourceCode() const;
Handle<Object> GetSourceCode();
Handle<Object> GetSourceCodeHarmony();
static Handle<Object> GetSourceCode(Handle<SharedFunctionInfo> shared);
static Handle<Object> GetSourceCodeHarmony(Handle<SharedFunctionInfo> shared);
// Tells whether this function should be subject to debugging.
inline bool IsSubjectToDebugging();
......
......@@ -63,7 +63,9 @@ RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
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();
}
......
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