JavaScriptCore.Context

g GObject.Object GObject.Object JavaScriptCore.Context JavaScriptCore.Context GObject.Object->JavaScriptCore.Context

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

get_current ()

class

new ()

class

new_with_virtual_machine (vm)

check_syntax (code, length, mode, uri, line_number)

clear_exception ()

evaluate (code, length)

evaluate_in_object (code, length, object_instance, object_class, uri, line_number)

evaluate_with_source_uri (code, length, uri, line_number)

get_exception ()

get_global_object ()

get_value (name)

get_virtual_machine ()

pop_exception_handler ()

push_exception_handler (handler, *user_data)

register_class (name, parent_class, vtable, destroy_notify)

set_value (name, value)

throw (error_message)

throw_exception (exception)

throw_with_name (error_name, error_message)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

virtual-machine

JavaScriptCore.VirtualMachine

r/w/co

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class JavaScriptCore.Context(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

JavaScriptCore.ContextClass

JavaScriptCore.Context 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 JavaScriptCore.Context.evaluate() or JavaScriptCore.Context.evaluate_with_source_uri(). It’s also possible to register custom objects in the context with JavaScriptCore.Context.register_class().

classmethod get_current()
Returns:

the JavaScriptCore.Context that is currently executing.

Return type:

JavaScriptCore.Context or None

Get the JavaScriptCore.Context that is currently executing a function. This should only be called within a function or method callback, otherwise None will be returned.

classmethod new()
Returns:

the newly created JavaScriptCore.Context.

Return type:

JavaScriptCore.Context

Create a new JavaScriptCore.Context. The context is created in a new JavaScriptCore.VirtualMachine. Use JavaScriptCore.Context.new_with_virtual_machine() to create a new JavaScriptCore.Context in an existing JavaScriptCore.VirtualMachine.

classmethod new_with_virtual_machine(vm)
Parameters:

vm (JavaScriptCore.VirtualMachine) – a JavaScriptCore.VirtualMachine

Returns:

the newly created JavaScriptCore.Context.

Return type:

JavaScriptCore.Context

Create a new JavaScriptCore.Context in virtual_machine.

check_syntax(code, length, mode, uri, line_number)
Parameters:
Returns:

a JavaScriptCore.CheckSyntaxResult

exception:

return location for a JavaScriptCore.Exception, or None to ignore

Return type:

(JavaScriptCore.CheckSyntaxResult, exception: JavaScriptCore.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 JavaScriptCore.Exception with the details. You can pass None to exception to ignore the error details.

clear_exception()

Clear the uncaught exception in self if any.

evaluate(code, length)
Parameters:
  • code (str) – a JavaScript script to evaluate

  • length (int) – length of code, or -1 if code is a nul-terminated string

Returns:

a JavaScriptCore.Value representing the last value generated by the script.

Return type:

JavaScriptCore.Value

Evaluate code in self.

evaluate_in_object(code, length, object_instance, object_class, uri, line_number)
Parameters:
  • code (str) – a JavaScript script to evaluate

  • length (int) – length of code, or -1 if code is a nul-terminated string

  • object_instance (object or None) – an object instance

  • object_class (JavaScriptCore.Class or None) – a JavaScriptCore.Class or None to use the default

  • uri (str) – the source URI

  • line_number (int) – the starting line number

Returns:

a JavaScriptCore.Value representing the last value generated by the script.

object:

return location for a JavaScriptCore.Value.

Return type:

(JavaScriptCore.Value, object: JavaScriptCore.Value)

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 JavaScriptCore.Value.new_object() works, if object_instance is not None 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.

evaluate_with_source_uri(code, length, uri, line_number)
Parameters:
  • code (str) – a JavaScript script to evaluate

  • length (int) – length of code, or -1 if code is a nul-terminated string

  • uri (str) – the source URI

  • line_number (int) – the starting line number

Returns:

a JavaScriptCore.Value representing the last value generated by the script.

Return type:

JavaScriptCore.Value

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.

get_exception()
Returns:

a JavaScriptCore.Exception or None if there isn’t any unhandled exception in the JavaScriptCore.Context.

Return type:

JavaScriptCore.Exception or None

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

get_global_object()
Returns:

a JavaScriptCore.Value

Return type:

JavaScriptCore.Value

Get a JavaScriptCore.Value referencing the self global object

get_value(name)
Parameters:

name (str) – the value name

Returns:

a JavaScriptCore.Value

Return type:

JavaScriptCore.Value

Get a property of self global object with name.

get_virtual_machine()
Returns:

the JavaScriptCore.VirtualMachine where the JavaScriptCore.Context was created.

Return type:

JavaScriptCore.VirtualMachine

Get the JavaScriptCore.VirtualMachine where self was created.

pop_exception_handler()

Remove the last JavaScriptCore.ExceptionHandler previously pushed to self with JavaScriptCore.Context.push_exception_handler().

push_exception_handler(handler, *user_data)
Parameters:

Push an exception handler in self. Whenever a JavaScript exception happens in the JavaScriptCore.Context, the given handler will be called. The default JavaScriptCore.ExceptionHandler simply calls JavaScriptCore.Context.throw_exception() to throw the exception to the JavaScriptCore.Context. If you don’t want to catch the exception, but only get notified about it, call JavaScriptCore.Context.throw_exception() in handler like the default one does. The last exception handler pushed is the only one used by the JavaScriptCore.Context, use JavaScriptCore.Context.pop_exception_handler() to remove it and set the previous one. When handler is removed from the context, destroy_notify i called with user_data as parameter.

register_class(name, parent_class, vtable, destroy_notify)
Parameters:
Returns:

a JavaScriptCore.Class

Return type:

JavaScriptCore.Class

Register a custom class in self using the given name. If the new class inherits from another JavaScriptCore.Class, the parent should be passed as parent_class, otherwise None should be used. The optional vtable parameter allows to provide a custom implementation for handling the class, for example, to handle external properties not added to the prototype. When an instance of the JavaScriptCore.Class is cleared in the context, destroy_notify is called with the instance as parameter.

set_value(name, value)
Parameters:

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

throw(error_message)
Parameters:

error_message (str) – an error message

Throw an exception to self using the given error message. The created JavaScriptCore.Exception can be retrieved with JavaScriptCore.Context.get_exception().

throw_exception(exception)
Parameters:

exception (JavaScriptCore.Exception) – a JavaScriptCore.Exception

Throw exception to self.

throw_with_name(error_name, error_message)
Parameters:
  • error_name (str) – the error name

  • error_message (str) – an error message

Throw an exception to self using the given error name and message. The created JavaScriptCore.Exception can be retrieved with JavaScriptCore.Context.get_exception().

Property Details

JavaScriptCore.Context.props.virtual_machine
Name:

virtual-machine

Type:

JavaScriptCore.VirtualMachine

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The JavaScriptCore.VirtualMachine in which the context was created.