From a34bbef3146902e5268ce899444cf011b501b300 Mon Sep 17 00:00:00 2001 From: domenic Date: Thu, 30 Apr 2015 02:29:33 -0700 Subject: [PATCH] Show function () { [native code] } for built-in classes The existing logic would show the full source for all classes, even built-in ones. R=arv@chromium.org,dslomov@chromium.org BUG= Review URL: https://codereview.chromium.org/1112113002 Cr-Commit-Position: refs/heads/master@{#28151} --- src/v8natives.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/v8natives.js b/src/v8natives.js index 1e42ac5..d163f5e 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -1738,6 +1738,16 @@ SetUpNumber(); // ---------------------------------------------------------------------------- // Function +function NativeCodeFunctionSourceString(func) { + var name = %FunctionGetName(func); + if (name) { + // Mimic what KJS does. + return 'function ' + name + '() { [native code] }'; + } + + return 'function () { [native code] }'; +} + function FunctionSourceString(func) { while (%IsJSFunctionProxy(func)) { func = %GetCallTrap(func); @@ -1747,20 +1757,18 @@ function FunctionSourceString(func) { throw MakeTypeError(kNotGeneric, 'Function.prototype.toString'); } + if (%FunctionIsBuiltin(func)) { + return NativeCodeFunctionSourceString(func); + } + var classSource = %ClassGetSourceCode(func); if (IS_STRING(classSource)) { return classSource; } var source = %FunctionGetSourceCode(func); - if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { - var name = %FunctionGetName(func); - if (name) { - // Mimic what KJS does. - return 'function ' + name + '() { [native code] }'; - } else { - return 'function () { [native code] }'; - } + if (!IS_STRING(source)) { + return NativeCodeFunctionSourceString(func); } if (%FunctionIsArrow(func)) { -- 2.7.4