1.2 <JSCContext>

Class: <JSCContext>

It derives from <GObject>.

JSCContext represents a JavaScript execution context, where all operations take place and where the values will be associated.

When a new context is created, a global object is allocated and the built-in JavaScript objects (Object, Function, String, Array) are populated. You can execute JavaScript in the context by using context:evaluate or context:evaluate-with-source-uri. It’s also possible to register custom objects in the context with jsc_context_register_class().

Properties

Property: context:virtual-machine self

The <JSCVirtualMachine> in which the context was created.

Its value is a <JSCVirtualMachine>, or #f.

It can only be set when the object is made, with #:virtual-machine.

Procedures

Method: context:check-syntax self code length mode uri line-number ⇒ %return exception
Method: check-syntax self code length mode uri line-number ⇒ %return exception

Check the given code in self for syntax errors. The line-number is the starting line number in uri; the value is one-based so the first line is 1. uri and line-number are only used to fill the exception. In case of errors exception will be set to a new <JSCException> with the details. You can pass #f to exception to ignore the error details.

self

Passed: a <JSCContext>.

a <JSCContext>

code

Passed: a string.

a JavaScript script to check

length

Passed: a 64-bit integer.

length of code, or -1 if code is a nul-terminated string

mode

Passed: a <%JSCCheckSyntaxMode>, or one of its symbols.

a <%JSCCheckSyntaxMode>

uri

Passed: a string.

the source URI

line-number

Passed: an unsigned 32-bit integer.

the starting line number

%return

Returned: a <%JSCCheckSyntaxResult>.

a <%JSCCheckSyntaxResult>

exception

Returned: a <JSCException>.

return location for a <JSCException>, or #f to ignore

Method: context:clear-exception self
Method: clear-exception self

Clear the uncaught exception in self if any.

self

Passed: a <JSCContext>.

a <JSCContext>

Method: context:evaluate self code length ⇒ %return
Method: evaluate self code length ⇒ %return

Evaluate code in self.

self

Passed: a <JSCContext>.

a <JSCContext>

code

Passed: a string.

a JavaScript script to evaluate

length

Passed: a 64-bit integer.

length of code, or -1 if code is a nul-terminated string

%return

Returned: a <JSCValue>.

a <JSCValue> representing the last value generated by the script.

Method: context:evaluate-in-object self code length object-instance object-class uri line-number ⇒ %return object
Method: evaluate-in-object self code length object-instance object-class uri line-number ⇒ %return object

Evaluate code and create an new object where symbols defined in code will be added as properties, instead of being added to self global object. The new object is returned as object parameter. Similar to how value:new-object works, if object-instance is not #f object-class must be provided too. The line-number is the starting line number in uri; the value is one-based so the first line is 1. uri and line-number will be shown in exceptions and they don’t affect the behavior of the script.

self

Passed: a <JSCContext>.

a <JSCContext>

code

Passed: a string.

a JavaScript script to evaluate

length

Passed: a 64-bit integer.

length of code, or -1 if code is a nul-terminated string

object-instance

Passed: a foreign pointer, or a bytevector, or #f.

an object instance

object-class

Passed: a <JSCClass>, or #f.

a <JSCClass> or #f to use the default

uri

Passed: a string.

the source URI

line-number

Passed: an unsigned 32-bit integer.

the starting line number

%return

Returned: a <JSCValue>.

a <JSCValue> representing the last value generated by the script.

object

Returned: a <JSCValue>.

return location for a <JSCValue>.

Method: context:evaluate-with-source-uri self code length uri line-number ⇒ %return
Method: evaluate-with-source-uri self code length uri line-number ⇒ %return

Evaluate code in self using uri as the source URI. The line-number is the starting line number in uri; the value is one-based so the first line is 1. uri and line-number will be shown in exceptions and they don’t affect the behavior of the script.

self

Passed: a <JSCContext>.

a <JSCContext>

code

Passed: a string.

a JavaScript script to evaluate

length

Passed: a 64-bit integer.

length of code, or -1 if code is a nul-terminated string

uri

Passed: a string.

the source URI

line-number

Passed: an unsigned 32-bit integer.

the starting line number

%return

Returned: a <JSCValue>.

a <JSCValue> representing the last value generated by the script.

Procedure: context:get-current ⇒ %return

Get the <JSCContext> that is currently executing a function. This should only be called within a function or method callback, otherwise #f will be returned.

%return

Returned: a <JSCContext>, or #f.

the <JSCContext> that is currently executing.

Method: context:get-exception self ⇒ %return
Method: get-exception self ⇒ %return

Get the last unhandled exception thrown in self by API functions calls.

self

Passed: a <JSCContext>.

a <JSCContext>

%return

Returned: a <JSCException>, or #f.

a <JSCException> or #f if there isn’t any unhandled exception in the <JSCContext>.

Method: context:get-global-object self ⇒ %return
Method: get-global-object self ⇒ %return

Get a <JSCValue> referencing the self global object

self

Passed: a <JSCContext>.

a <JSCContext>

%return

Returned: a <JSCValue>.

a <JSCValue>

Method: context:get-value self name ⇒ %return
Method: get-value self name ⇒ %return

Get a property of self global object with name.

self

Passed: a <JSCContext>.

a <JSCContext>

name

Passed: a string.

the value name

%return

Returned: a <JSCValue>.

a <JSCValue>

Method: context:get-virtual-machine self ⇒ %return
Method: get-virtual-machine self ⇒ %return

Get the <JSCVirtualMachine> where self was created.

self

Passed: a <JSCContext>.

a <JSCContext>

%return

Returned: a <JSCVirtualMachine>.

the <JSCVirtualMachine> where the <JSCContext> was created.

Procedure: context:new ⇒ %return

Create a new <JSCContext>. The context is created in a new <JSCVirtualMachine>. Use context:new-with-virtual-machine to create a new <JSCContext> in an existing <JSCVirtualMachine>.

%return

Returned: a <JSCContext>.

the newly created <JSCContext>.

Procedure: context:new-with-virtual-machine vm ⇒ %return

Create a new <JSCContext> in virtual-machine.

vm

Passed: a <JSCVirtualMachine>.

a <JSCVirtualMachine>

%return

Returned: a <JSCContext>.

the newly created <JSCContext>.

Method: context:pop-exception-handler self
Method: pop-exception-handler self

Remove the last JSCExceptionHandler previously pushed to self with context:push-exception-handler.

self

Passed: a <JSCContext>.

a <JSCContext>

Method: context:push-exception-handler self handler
Method: push-exception-handler self handler

Push an exception handler in self. Whenever a JavaScript exception happens in the <JSCContext>, the given handler will be called. The default JSCExceptionHandler simply calls context:throw-exception to throw the exception to the <JSCContext>. If you don’t want to catch the exception, but only get notified about it, call context:throw-exception in handler like the default one does. The last exception handler pushed is the only one used by the <JSCContext>, use context:pop-exception-handler to remove it and set the previous one. When handler is removed from the context, destroy-notify is called with user-data as parameter.

self

Passed: a <JSCContext>.

a <JSCContext>

handler

Passed: a procedure.

a JSCExceptionHandler

See JSCExceptionHandler for how it is called.

user-data

Not passed: guile-gi supplies it.

user data to pass to handler

destroy-notify

Not passed: guile-gi supplies it.

destroy notifier for user-data

See GDestroyNotify for how it is called.

Method: context:set-value self name value
Method: set-value self name value

Set a property of self global object with name and value.

self

Passed: a <JSCContext>.

a <JSCContext>

name

Passed: a string.

the value name

value

Passed: a <JSCValue>.

a <JSCValue>

Method: context:throw self error-message
Method: throw self error-message

Throw an exception to self using the given error message. The created <JSCException> can be retrieved with context:get-exception.

self

Passed: a <JSCContext>.

a <JSCContext>

error-message

Passed: a string.

an error message

Method: context:throw-exception self exception
Method: throw-exception self exception

Throw exception to self.

self

Passed: a <JSCContext>.

a <JSCContext>

exception

Passed: a <JSCException>.

a <JSCException>

Method: context:throw-with-name self error-name error-message
Method: throw-with-name self error-name error-message

Throw an exception to self using the given error name and message. The created <JSCException> can be retrieved with context:get-exception.

self

Passed: a <JSCContext>.

a <JSCContext>

error-name

Passed: a string.

the error name

error-message

Passed: a string.

an error message