class JavaScriptCore::Context

Defined in:

lib/gi-crystal/src/auto/java_script_core-5.0/context.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class GObject::Object

bind_property(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags) : GObject::Binding bind_property, bind_property_full(source_property : String, target : GObject::Object, target_property : String, flags : GObject::BindingFlags, transform_to : GObject::Closure, transform_from : GObject::Closure) : GObject::Binding bind_property_full, data(key : String) : Pointer(Void)? data, finalize finalize, freeze_notify : Nil freeze_notify, getv(names : Enumerable(String), values : Enumerable(_)) : Nil getv, notify(property_name : String) : Nil notify, notify_by_pspec(pspec : GObject::ParamSpec) : Nil notify_by_pspec, notify_signal notify_signal, property(property_name : String, value : _) : Nil property, qdata(quark : UInt32) : Pointer(Void)? qdata, ref_count : UInt32 ref_count, run_dispose : Nil run_dispose, set_data(key : String, data : Pointer(Void)?) : Nil set_data, set_property(property_name : String, value : _) : Nil set_property, steal_data(key : String) : Pointer(Void)? steal_data, steal_qdata(quark : UInt32) : Pointer(Void)? steal_qdata, thaw_notify : Nil thaw_notify, to_unsafe : Pointer(Void) to_unsafe, watch_closure(closure : GObject::Closure) : Nil watch_closure

Constructor methods inherited from class GObject::Object

cast(obj : GObject::Object) : self cast, cast?(obj : GObject::Object) : self? cast?, new(pointer : Pointer(Void), transfer : GICrystal::Transfer)
new
new
, newv(object_type : UInt64, parameters : Enumerable(GObject::Parameter)) : self newv

Class methods inherited from class GObject::Object

compat_control(what : UInt64, data : Pointer(Void)?) : UInt64 compat_control, g_type : UInt64 g_type, interface_find_property(g_iface : GObject::TypeInterface, property_name : String) : GObject::ParamSpec interface_find_property, interface_list_properties(g_iface : GObject::TypeInterface) : Enumerable(GObject::ParamSpec) interface_list_properties

Constructor Detail

def self.new : self #

Create a new #JSCContext. The context is created in a new #JSCVirtualMachine. Use jsc_context_new_with_virtual_machine() to create a new #JSCContext in an existing #JSCVirtualMachine.


def self.new(*, virtual_machine : JavaScriptCore::VirtualMachine? = nil) #

def self.new_with_virtual_machine(vm : JavaScriptCore::VirtualMachine) : self #

Create a new #JSCContext in @virtual_machine.


Class Method Detail

def self.current : JavaScriptCore::Context? #

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


def self.g_type : UInt64 #

Returns the type id (GType) registered in GLib type system.


Instance Method Detail

def check_syntax(code : String, length : Int64, mode : JavaScriptCore::CheckSyntaxMode, uri : String, line_number : UInt32) : JavaScriptCore::CheckSyntaxResult #

Check the given @code in @context 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 %NULL to @exception to ignore the error details.


def clear_exception : Nil #

Clear the uncaught exception in @context if any.


def evaluate(code : String, length : Int64) : JavaScriptCore::Value #

Evaluate @code in @context.


def evaluate_in_object(code : String, length : Int64, object_instance : Pointer(Void)?, object_class : JavaScriptCore::Class?, uri : String, line_number : UInt32, object : JavaScriptCore::Value) : JavaScriptCore::Value #

Evaluate @code and create an new object where symbols defined in @code will be added as properties, instead of being added to @context global object. The new object is returned as @object parameter. Similar to how jsc_value_new_object() works, if @object_instance is not %NULL @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.


def evaluate_with_source_uri(code : String, length : Int64, uri : String, line_number : UInt32) : JavaScriptCore::Value #

Evaluate @code in @context 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.


def exception : JavaScriptCore::Exception? #

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


def global_object : JavaScriptCore::Value #

Get a #JSCValue referencing the @context global object


def pop_exception_handler : Nil #

Remove the last #JSCExceptionHandler previously pushed to @context with jsc_context_push_exception_handler().


def push_exception_handler(handler : JavaScriptCore::ExceptionHandler) : Nil #

Push an exception handler in @context. Whenever a JavaScript exception happens in the #JSCContext, the given @handler will be called. The default #JSCExceptionHandler simply calls jsc_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 jsc_context_throw_exception() in @handler like the default one does. The last exception handler pushed is the only one used by the #JSCContext, use jsc_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.


def register_class(name : String, parent_class : JavaScriptCore::Class?, vtable : JavaScriptCore::ClassVTable?, destroy_notify : GLib::DestroyNotify?) : JavaScriptCore::Class #

Register a custom class in @context using the given @name. If the new class inherits from another #JSCClass, the parent should be passed as @parent_class, otherwise %NULL 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 #JSCClass is cleared in the context, @destroy_notify is called with the instance as parameter.


def set_value(name : String, value : JavaScriptCore::Value) : Nil #

Set a property of @context global object with @name and @value.


def throw(error_message : String) : Nil #

Throw an exception to @context using the given error message. The created #JSCException can be retrieved with jsc_context_get_exception().


def throw_exception(exception : JavaScriptCore::Exception) : Nil #

Throw @exception to @context.


def throw_with_name(error_name : String, error_message : String) : Nil #

Throw an exception to @context using the given error name and message. The created #JSCException can be retrieved with jsc_context_get_exception().


def value(name : String) : JavaScriptCore::Value #

Get a property of @context global object with @name.


def virtual_machine : JavaScriptCore::VirtualMachine #

Get the #JSCVirtualMachine where @context was created.