File.prototype.call()

Call a method on a file.

Syntax

file.call(method string) File file.call(method string, options Object) File

Parameters

method string

Name of the method to execute, for example Inline or custom.

options Object

Additional options to the call.

{
    context: File,
    request: File,
}
options.context File

Optional. Context file to use within the child transaction. Defaults to the current transaction’s context.

options.request File

Optional. Request file to use within the child transaction. Defaults to an empty file.

Description

Call a method on a file as defined on the filesystem. For example, calling f.call('Inline') will locate the closest .Inline file on the file’s type chain and execute it in a new transaction, in an isolated VM. The file on which .call() is executed will be available as file f within the child execution context.

For apps defined in user space, calling f.call(method) is identical to finding the source file first by source = f.chainSelect("." + method) and then executing it via source.exec(f).

Note that no post-processing is performed, thus the result of calling f.call("Inline", ...) will be slightly different from calling f.inline() which does apply some post-processing, for example it extracts the body of the generated result file, passes on Content-Security-Policy rules, head entries and updates the statusCode of the current transaction’s response file.

Examples

Execute the .Inline method of an app, returning hello world.

Execute a custom .hello method. Method names starting with a lower-case letter are considered user-space methods. (You can define any user-space method yourself.)

Increment a counter.

Request file defaults to a new, empty file.

Pass in custom request file.

Context file defaults to that of the current transaction.

Custom context file.

When the result contains an unhandled error, it will be thrown.

Here we catch it in a try-catch block.

Throws an error for unexpected options keys.

An error is thrown in a child execution context. Due to the unhandled error, the child transaction is rolled back.

The transaction is not rolled back merely by returning a non-success response, only if an unhandled error occurred.

Legacy: it is allowed to ommit the dot from method names. Do not use this format in new code.