Skip to content

[en]trashscript

devel01 edited this page Dec 6, 2024 · 2 revisions

TrashScript

The keywords var, let, and const are not implemented.

When you use these keywords in your code, they are treated as ordinary strings and ignored.

For example, in the statement var a = 123, the var keyword will be ignored, and only a = 123 will be executed.

The new keyword is not implemented and should be avoided. For instance, instead of using new RegExp(), you should simply use RegExp().


Global functions:

is_number

Identical to typeof(data) === "number"

is_string

Identical to typeof(data) === "string"

is_object

Identical to typeof(data) === "object"

is_array

Identical to data instanceof Array


Global objects:


Config

TrashScript.config = {
    max_exec_limit:10000000
}

bind

When binding existing JavaScript methods or classes, the bound properties will be read-only and cannot be modified from TrashScript.

TrashScript.bind(name,value);
TrashScript.bind({
    name: value,
    name2: value2
});

variables

Import global variables

var context = TrashScript("return global_var1",function(e)
{
    if(e.status === "complete"){
        //e.result is 123
    }else if(e.status === "error"){
        //e.error
    }
});
context.variables({global_var1:123}); //add global variables
context.exec();

terminate

context.terminate();

The terminate method is designed to stop code execution.

However, this process does not happen instantly.

If there are any ongoing asynchronous operations, such as HTTP requests or a sleep function, the termination will only occur once those operations are complete. When the termination is finished, the callback function will return a status of 'error', with the error type specified as 'terminated'.

exec

After creating an instance with TrashScript(source_code, callback), use the exec member function to execute the code.

context.exec(object = context)

**_The content parameter of the exec method serves as the default this object for the function.

If this parameter is not provided, the this object will default to an empty object {}.

It is not recommended to use window as this parameter, as it allows access to all window functions but may lead to modifications of properties within the window object. This means that the code executed in TrashScript would no longer be isolated._**

var context = TrashScript("return 123",function(e)
{
    /*
     * The callback function can be asynchronous, 
     * triggered after the execution of exec, or synchronous, 
     * triggered during the execution of exec, 
     * depending on whether your code calls any asynchronous functions. 
    */
    if(e.status === "complete"){
        //e.result is 123
    }else if(e.status === "error"){
        //e.error
    }
});
context.exec(); ///execute
Clone this wiki locally