WebKit

Update of "Dealing with JavaScript Objects"
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

Artifact ID: 82b60ba480e1284ff54bc0c15c5576723fcdce8c
Page Name:Dealing with JavaScript Objects
Date: 2011-12-11 16:33:56
Original User: murphy
Parent: bd5cd2de4b40197b1ba1c916733154148144064c
Content

Dealing with JavaScript Objects

Value Conversions

JavaScript Value

Scheme Value
undefined (void)
null '()
a boolean satisfies boolean?
a number satisfies number?
a string satisfies string?
a wrapper object the wrapped value
anything satisfies jso?

Scheme Value

JavaScript Value
(void) undefined
'() null
satisfies boolean? a boolean
satisfies number? a number
satisfies string? a string
satisfies symbol? a string
satisfies jso? the wrapped object
anything a wrapper object

If any JavaScript operation invoked from Scheme throws an error, a Scheme condition is raised with an equivalent error message.

If any Scheme operation invoked from JavaScript raises a condition, a JavaScript error is thrown with an equivalent error message.

Wrapper Records in Scheme

Complex JavaScript objects are not converted to Scheme values but rather encapsulted in a wrapper that allows various natural forms of access from Scheme. If the JavaScript object is a function, the resulting wrapper is callable as a procedure in addition to being accessible using the procedures described below.

  (jso? VALUE) => BOOLEAN
Tests whether the VALUE is a wrapped JavaScript object.
  (jso-new JSO ARGUMENT ...) => VALUE
Converts or unwraps the ARGUMENTs to JavaScript values, calls the JSO as a constructor with those arguments and returns the newly instantiated object converted or wrapped into a Scheme value.
  (jso-apply JSO ARGUMENT ... REST) => VALUE
Converts or unwraps the ARGUMENTs (and the contents of REST) to JavaScript values, calls the JSO as a function with those arguments and returns the result converted or wrapped into a Scheme value.
  (jso-exists? JSO KEY) => BOOLEAN
Checks whether the JSO has a property with a name obtained by stringifying KEY.
  (jso-ref JSO KEY) => VALUE
Stringifies KEY, gets the property of JSO with the resulting name and returns the value converted or wrapped into a Scheme value.
  (set! (jso-ref JSO KEY) VALUE) => VOID
  (jso-set! JSO KEY VALUE) => VOID
Stringifies KEY, converts or unwraps VALUE to JavaScript and sets the property of JSO with the resulting name to the resulting value.
  (jso-delete! JSO KEY)
Stringifies KEY, tries to delete the property of JSO with the resulting name and returns whether the operation was successful.
  (:jso KEY JSO [(index INDEX)])
SRFI-42 generator syntax for the enumerable property names of a JavaScript object.
  (jso-keys JSO) => LIST
Retrieves the enumerable property names of a JavaScript object as a list of strings.

Wrapper Objects in JavaScript

Complex Scheme values are not converted to JavaScript but rather encapsulated in a wrapper that allows various natural forms of access from JavaScript. If the Scheme value is a procedure, the resulting wrapper is callable as a function in addition to supporting the generic properties described below.

  SCO.type => STRING
Returns a string describing the type of the wrapped Scheme value. Possible values are "hash-table", "vector", "pair", "procedure", the name of a SRFI-99 record type or the undefined value.
  SCO.length => INTEGER
Returns the size of a hash table or the length of a vector. For other Scheme values the result is the undefined value.
  SCO[STRING] => VALUE
  SCO[STRING] = VALUE
  delete SCO[STRING]
The string keys of a Scheme hash table are accessible as mutable, deletable properties.
  SCO.car => VALUE
  SCO.cdr => VALUE
  SCO.c[ad]{2,5}r => VALUE
These direct and indirect properties of a pair are accessible as immutable properties.
  SCO[NUMBER] => VALUE
The valid indices of a Scheme vector are accessible as mutable properties.
  SCO[SYMBOL] => VALUE
  SCO[SYMBOL] = VALUE
The fields of a transparent SRFI-99 record are accessible as (potentially mutable) properties.
  SCO(ARGUMENT, ...) => VALUE
Converts or unwraps the ARGUMENTs to Scheme, applies the Scheme procedure wrapped by SCO to the resulting values and returns the result converted or wrapped into a JavaScript value.
  String(SCO) => STRING
Stringifying a wrapper object produces the display representation of the Scheme value.

Utilities for DOM Objects

  (xexpr->jso XEXPR DOCUMENT) => JSO

Converts the X-expression XEXPR into a DOM object using factory functions of the given DOCUMENT instance.

  (jso->xexpr JSO [AT-ATTRIBUTES?]) => XEXPR

Converts the DOM object JSO into an X-expression. The optional argument determines whether element attribute lists should be prefixed with the symbol @.