JavaScriptCore.Context¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class JavaScriptCore.Context(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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
() orJavaScriptCore.Context.evaluate_with_source_uri
(). It’s also possible to register custom objects in the context withJavaScriptCore.Context.register_class
().- classmethod get_current()¶
- Returns:
the
JavaScriptCore.Context
that is currently executing.- Return type:
Get the
JavaScriptCore.Context
that is currently executing a function. This should only be called within a function or method callback, otherwiseNone
will be returned.
- classmethod new()¶
- Returns:
the newly created
JavaScriptCore.Context
.- Return type:
Create a new
JavaScriptCore.Context
. The context is created in a newJavaScriptCore.VirtualMachine
. UseJavaScriptCore.Context.new_with_virtual_machine
() to create a newJavaScriptCore.Context
in an existingJavaScriptCore.VirtualMachine
.
- classmethod new_with_virtual_machine(vm)¶
- Parameters:
vm (
JavaScriptCore.VirtualMachine
) – aJavaScriptCore.VirtualMachine
- Returns:
the newly created
JavaScriptCore.Context
.- Return type:
Create a new
JavaScriptCore.Context
in virtual_machine.
- check_syntax(code, length, mode, uri, line_number)¶
- Parameters:
code (
str
) – a JavaScript script to checklength (
int
) – length of code, or -1 if code is a nul-terminated stringmode (
JavaScriptCore.CheckSyntaxMode
) – aJavaScriptCore.CheckSyntaxMode
uri (
str
) – the source URIline_number (
int
) – the starting line number
- Returns:
a
JavaScriptCore.CheckSyntaxResult
- exception:
return location for a
JavaScriptCore.Exception
, orNone
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 passNone
to exception to ignore the error details.
- clear_exception()¶
Clear the uncaught exception in self if any.
- evaluate(code, length)¶
- Parameters:
- Returns:
a
JavaScriptCore.Value
representing the last value generated by the script.- Return type:
Evaluate code in self.
- evaluate_in_object(code, length, object_instance, object_class, uri, line_number)¶
- Parameters:
code (
str
) – a JavaScript script to evaluatelength (
int
) – length of code, or -1 if code is a nul-terminated stringobject_class (
JavaScriptCore.Class
orNone
) – aJavaScriptCore.Class
orNone
to use the defaulturi (
str
) – the source URIline_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 notNone
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:
- Returns:
a
JavaScriptCore.Value
representing the last value generated by the script.- Return type:
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
orNone
if there isn’t any unhandled exception in theJavaScriptCore.Context
.- Return type:
Get the last unhandled exception thrown in self by API functions calls.
- get_global_object()¶
- Returns:
- Return type:
Get a
JavaScriptCore.Value
referencing the self global object
- get_value(name)¶
- Parameters:
name (
str
) – the value name- Returns:
- Return type:
Get a property of self global object with name.
- get_virtual_machine()¶
- Returns:
the
JavaScriptCore.VirtualMachine
where theJavaScriptCore.Context
was created.- Return type:
Get the
JavaScriptCore.VirtualMachine
where self was created.
- pop_exception_handler()¶
Remove the last
JavaScriptCore.ExceptionHandler
previously pushed to self withJavaScriptCore.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 defaultJavaScriptCore.ExceptionHandler
simply callsJavaScriptCore.Context.throw_exception
() to throw the exception to theJavaScriptCore.Context
. If you don’t want to catch the exception, but only get notified about it, callJavaScriptCore.Context.throw_exception
() in handler like the default one does. The last exception handler pushed is the only one used by theJavaScriptCore.Context
, useJavaScriptCore.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:
name (
str
) – the class nameparent_class (
JavaScriptCore.Class
orNone
) – aJavaScriptCore.Class
orNone
vtable (
JavaScriptCore.ClassVTable
orNone
) – an optionalJavaScriptCore.ClassVTable
orNone
destroy_notify (
GLib.DestroyNotify
orNone
) – a destroy notifier for class instances
- Returns:
- Return type:
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, otherwiseNone
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 theJavaScriptCore.Class
is cleared in the context, destroy_notify is called with the instance as parameter.
- set_value(name, value)¶
- Parameters:
name (
str
) – the value namevalue (
JavaScriptCore.Value
) – aJavaScriptCore.Value
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 withJavaScriptCore.Context.get_exception
().
- throw_exception(exception)¶
- Parameters:
exception (
JavaScriptCore.Exception
) – aJavaScriptCore.Exception
Throw exception to self.
- throw_with_name(error_name, error_message)¶
-
Throw an exception to self using the given error name and message. The created
JavaScriptCore.Exception
can be retrieved withJavaScriptCore.Context.get_exception
().
Property Details¶
- JavaScriptCore.Context.props.virtual_machine¶
- Name:
virtual-machine
- Type:
- Default Value:
- Flags:
The
JavaScriptCore.VirtualMachine
in which the context was created.