class Medusa::ValueWrapper

Defined in:

medusa/value_wrapper.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(context : QuickJS::JSContext, value : QuickJS::JSValue) #

[View source]
def self.new(context : QuickJS::JSContext, value : Float64) #

[View source]
def self.new(context : QuickJS::JSContext, value : Int32) #

[View source]
def self.new(context : QuickJS::JSContext, value : Int64) #

[View source]
def self.new(context : QuickJS::JSContext, value : String) #

[View source]
def self.new(context : QuickJS::JSContext, value : Bool) #

[View source]
def self.new(context : QuickJS::JSContext, value : Hash(String, JSON::Any)) #

[View source]
def self.new(context : QuickJS::JSContext, values : Array(JSON::Any)) #

[View source]

Instance Method Detail

def ==(other : self) : Bool #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


[View source]
def [](index : Int32) : ValueWrapper #

[View source]
def [](key : String) : ValueWrapper #

[View source]
def []=(index : Int32, value : ValueWrapper) : ValueWrapper #

[View source]
def []=(key : String, value : ValueWrapper) : ValueWrapper #

[View source]
def []?(index : Int32) : ValueWrapper | Nil #

[View source]
def []?(key : String) : ValueWrapper | Nil #

[View source]
def array? : Bool #

[View source]
def as_a : Array(JSON::Any) #

[View source]
def as_big_int64 : Int64 #

[View source]
def as_bool : Bool #

[View source]
def as_f64 : Float64 #

[View source]
def as_h : Hash(String, JSON::Any) #

[View source]
def as_i : Int32 #

[View source]
def as_i64 : Int64 #

[View source]
def as_s : String #

[View source]
def bool? : Bool #

[View source]
def call(this_obj : ValueWrapper, args : Array(ValueWrapper) = [] of ValueWrapper) : ValueWrapper #

[View source]
def call_constructor(args : Array(ValueWrapper) = [] of ValueWrapper) : ValueWrapper #

[View source]
def constructor? : Bool #

[View source]
def define_property_value(atom : QuickJS::JSAtom, val : ValueWrapper, flags : Int32 = Constants::JS_PROP_C_W_E) : Nil #

[View source]
def delete_property(atom : QuickJS::JSAtom, flags : Int32 = 0) : Bool #

[View source]
def duplicate : QuickJS::JSValue #

[View source]
def error? : Bool #

[View source]
def exception? : Bool #

[View source]
def finalize #

GC finalizer. We intentionally do NOT call FreeValue here.

Boehm GC runs finalizers in non-deterministic order and can trigger them during allocation inside other callbacks. If this ValueWrapper belongs to a sandbox that has already been closed, the context pointer is dangling and FreeValue would segfault.

The trade-off: JSValues with refcounts leak until their Engine is closed, at which point FreeContextAndRuntime drops everything in bulk. During normal long-lived operation (like a GUI event loop), this is fine — QuickJS's own GC handles internal object collection. The Crystal-side wrappers only hold extra refs that prevent QuickJS from collecting; once the engine shuts down, everything is freed.


[View source]
def float64? : Bool #

[View source]
def free! : Nil #

[View source]
def from_json(value : JSON::Any) : ValueWrapper #

[View source]
def function? : Bool #

[View source]
def get_opaque(class_id : QuickJS::JSClassID) : Pointer(Void) #

[View source]
def get_opaque2(class_id : QuickJS::JSClassID) : Pointer(Void) #

[View source]
def get_property(atom : QuickJS::JSAtom) : ValueWrapper #

[View source]
def has_property?(atom : QuickJS::JSAtom) : Bool #

[View source]
def int? : Bool #

[View source]
def null? : Bool #

[View source]
def number? : Bool #

[View source]
def object? : Bool #

[View source]
def prototype : ValueWrapper #

[View source]
def prototype=(proto : ValueWrapper) : Nil #

[View source]
def same_value?(other : self) : Bool #

[View source]
def set_opaque(ptr : Pointer(Void)) : Nil #

[View source]
def short_big_int? : Bool #

[View source]
def string? : Bool #

[View source]
def to_json_any : JSON::Any #

[View source]
def to_s(io : IO) : Nil #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

[View source]
def to_unsafe : QuickJS::JSValue #

[View source]
def undefined? : Bool #

[View source]