diff --git a/js/rhino/src/org/mozilla/javascript/Interpreter.java b/js/rhino/src/org/mozilla/javascript/Interpreter.java index 5a31667c380..1f35b54c785 100644 --- a/js/rhino/src/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/src/org/mozilla/javascript/Interpreter.java @@ -1542,22 +1542,8 @@ public class Interpreter { } } ScriptRuntime.initFunction(scope, fn); - String fnName = idata.itsName; - if (fnName.length() != 0) { - int type = idata.itsFunctionType; - if (type == FunctionNode.FUNCTION_STATEMENT) { - if (fromEvalCode) { - scope.put(fnName, scope, fn); - } else { - // ECMA specifies that functions defined in global and - // function scope should have DONTDELETE set. - ScriptableObject.defineProperty(scope, - fnName, fn, ScriptableObject.PERMANENT); - } - } else if (type == FunctionNode.FUNCTION_EXPRESSION_STATEMENT) { - scope.put(fnName, scope, fn); - } - } + ScriptRuntime.putFunction(scope, idata.itsName, fn, + idata.itsFunctionType, fromEvalCode); return fn; } diff --git a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java index ae0120a1d50..e5544d9137d 100644 --- a/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java +++ b/js/rhino/src/org/mozilla/javascript/ScriptRuntime.java @@ -1939,6 +1939,27 @@ public class ScriptRuntime { fn.setParentScope(scope); } + public static void putFunction(Scriptable scope, String name, + Function function, int type, + boolean fromEvalCode) + { + if (type == FunctionNode.FUNCTION_STATEMENT + || type == FunctionNode.FUNCTION_EXPRESSION_STATEMENT) + { + if (name != null && name.length() != 0) { + if (type == FunctionNode.FUNCTION_STATEMENT && !fromEvalCode) { + // ECMA specifies that functions defined in global and + // function scope outside eval should have DONTDELETE set. + ScriptableObject.defineProperty + (scope, name, function, ScriptableObject.PERMANENT); + } else { + scope.put(name, scope, function); + } + } + } + } + + static void checkDeprecated(Context cx, String name) { int version = cx.getLanguageVersion(); if (version >= Context.VERSION_1_4 || version == Context.VERSION_DEFAULT) {