Skip to content

Commit e4e418f

Browse files
bmeurerCommit bot
authored andcommitted
[runtime] Make %FunctionGetScript and %FunctionGetSourceCode robust.
R=jarin@chromium.org BUG=chromium:582703 LOG=n Review URL: https://codereview.chromium.org/1664483003 Cr-Commit-Position: refs/heads/master@{#33693}
1 parent 3c94fcb commit e4e418f

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/runtime/runtime-function.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,25 @@ RUNTIME_FUNCTION(Runtime_FunctionGetScript) {
5555
DCHECK_EQ(1, args.length());
5656
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
5757

58-
if (function->IsJSBoundFunction()) return isolate->heap()->undefined_value();
59-
Handle<Object> script(Handle<JSFunction>::cast(function)->shared()->script(),
60-
isolate);
61-
if (!script->IsScript()) return isolate->heap()->undefined_value();
62-
return *Script::GetWrapper(Handle<Script>::cast(script));
58+
if (function->IsJSFunction()) {
59+
Handle<Object> script(
60+
Handle<JSFunction>::cast(function)->shared()->script(), isolate);
61+
if (script->IsScript()) {
62+
return *Script::GetWrapper(Handle<Script>::cast(script));
63+
}
64+
}
65+
return isolate->heap()->undefined_value();
6366
}
6467

6568

6669
RUNTIME_FUNCTION(Runtime_FunctionGetSourceCode) {
6770
HandleScope scope(isolate);
6871
DCHECK_EQ(1, args.length());
6972
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0);
70-
if (function->IsJSBoundFunction()) return isolate->heap()->undefined_value();
71-
return *Handle<JSFunction>::cast(function)->shared()->GetSourceCode();
73+
if (function->IsJSFunction()) {
74+
return *Handle<JSFunction>::cast(function)->shared()->GetSourceCode();
75+
}
76+
return isolate->heap()->undefined_value();
7277
}
7378

7479

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2016 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
%FunctionGetScript({});
8+
%FunctionGetSourceCode({});

0 commit comments

Comments
 (0)