ScriptDef class final
A script. Its params are variables in its source; what it returns at
its top level (or what its main returns) is its result. It runs in a
sandbox with no network, files or timers, reaching the app only through
what its capabilities grant, and stops past timeoutMs of computing
or memoryLimitMb. A page script (pageId set) wins over a project
script of the same name. JSON (sparse):
{"id": "s1", "name": "payment", "params": [{"name": "principal"}],
"source": "return principal * 0.05;", "capabilities": ["variables.read"]}
- Annotations
-
- @immutable
Constructors
-
ScriptDef({required String id, required String name, String description = '', List<
ScriptParam> params = const [], String source = '', int version = 1, List<ScriptCapability> capabilities = const [], int timeoutMs = defaultTimeoutMs, int memoryLimitMb = defaultMemoryLimitMb, String? pageId, List<ScriptTest> tests = const []}) -
const
Properties
-
capabilities
→ List<
ScriptCapability> -
Capabilities this version doesn't know are dropped when read.
final
- description → String
-
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- id → String
-
final
- isProjectScope → bool
-
no setter
- memoryLimitMb → int
-
Enforced on devices; on the web only timeoutMs applies.
final
- name → String
-
A JavaScript identifier, unique in its scope: formulas and other
scripts call it as
script.<name>(...).final - pageId → String?
-
The editor page whose screens use it; null: every screen of the project.
final
-
paramNames
→ List<
String> -
no setter
-
params
→ List<
ScriptParam> -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- source → String
-
final
-
tests
→ List<
ScriptTest> -
final
- timeoutMs → int
-
final
- version → int
-
Goes up each time the script is saved.
final
Methods
-
allows(
ScriptCapability c) → bool -
copyWith(
{String? id, String? name, String? description, List< ScriptParam> ? params, String? source, int? version, List<ScriptCapability> ? capabilities, int? timeoutMs, int? memoryLimitMb, String? pageId, bool clearPageId = false, List<ScriptTest> ? tests}) → ScriptDef - A copy with the given fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Json -
toString(
) → String -
A string representation of this object.
override
-
validate(
) → List< String> - What's wrong with this script's name, params or limits; empty when nothing is. Doesn't check the source (the engine does).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Static Methods
-
fromJson(
Object? json) → ScriptDef? -
isValidName(
String name) → bool -
Whether
namecan name a script or a parameter: a JavaScript identifier, not a keyword or one of reservedNames. -
listFromJson(
Object? json) → List< ScriptDef>
Constants
- defaultMemoryLimitMb → const int
- defaultTimeoutMs → const int
- maxTimeoutMs → const int
- The longest timeoutMs a script may set.
-
reservedNames
→ const Set<
String> - Names a script or parameter can't have: they're the host APIs.