New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.mozilla.javascript.EcmaError: ReferenceError for function #19

Open
lutzhorn opened this Issue Oct 30, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@lutzhorn
Contributor

lutzhorn commented Oct 30, 2017

Consider this code:

var lib = {
	foo: function(node) {
		logger.debug("" + node.name);
	}
};

var sql = "select 'workspace://SpacesStore/af9f95ac-dfdd-4787-b044-22e2026c4e74'"; // some existing NodeRef

var result = database.query("dataSource", sql);

var nodesToMigrate = [];

for each (var row in result) {
    var node = search.findNode(row[0]);
    if (!node || !node.exists()) {
        continue;
    }
    nodesToMigrate.push(node);
}

var process = function process(node) {
    logger.info("processing " + node.typeShort + " " + node.nodeRef);

    // calling function from `lib` fails!
    lib.foo(node);
};

var beforeProcessFunction = function beforeProcess() {
};

var afterProcessFunction = function afterProcess() {
};

batch.runForNodes('Process-', 2, 10, nodesToMigrate, process, true, beforeProcessFunction, afterProcessFunction);

Observed Behaviour

This will throw

Caused by: org.mozilla.javascript.EcmaError: ReferenceError: "lib" is not defined. (AlfrescoJS#4)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3687)
        at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3665)
        at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3750)
        at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1728)
        at org.mozilla.javascript.gen.AlfrescoJS_108._c_process_1(AlfrescoJS:4)
        at org.mozilla.javascript.gen.AlfrescoJS_108.call(AlfrescoJS)
        at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63)
        at org.mozilla.javascript.gen.AlfrescoJS_108._c_script_0(AlfrescoJS:7)
        at org.mozilla.javascript.gen.AlfrescoJS_108.call(AlfrescoJS)
        at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
        at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
        at org.mozilla.javascript.gen.AlfrescoJS_108.call(AlfrescoJS)
        at org.mozilla.javascript.gen.AlfrescoJS_108.exec(AlfrescoJS)
        at org.alfresco.repo.jscript.RhinoScriptProcessor.executeScriptImpl(RhinoScriptProcessor.java:502)
        ... 29 more

Expected Behaviour

The lib.foo function is executed.

@jgoldhammer

This comment has been minimized.

Show comment
Hide comment
@jgoldhammer

jgoldhammer Nov 27, 2017

Owner

I do not know if we can fix that?! Any ideas?

Owner

jgoldhammer commented Nov 27, 2017

I do not know if we can fix that?! Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment