Skip to content


Subversion checkout URL

You can clone with
Download ZIP
100644 549 lines (421 sloc) 23.2 KB
24935b6 @marijnh and finally, we have documentation
marijnh authored
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
2 <html>
3 <head>
4 <title>CL-JavaScript</title>
5 <style type="text/css">
b4edabd @marijnh make project page look a little less primitive
marijnh authored
6 body {margin: 0; padding: 0; max-width: 55em; background-color: #f5f5f5;}
7 #wrap {margin: 0 3em; padding: 3em 5em; border-left: 1px solid #400; border-right: 1px solid #400;
8 background-color: white;}
24935b6 @marijnh and finally, we have documentation
marijnh authored
9 h1, h2, h3 {font-family: tahoma, sans-serif;}
819e9f4 @marijnh release 0.10.11
marijnh authored
10 {padding-left: 2em; text-indent: -2em;}
24935b6 @marijnh and finally, we have documentation
marijnh authored
11 span {font-weight: bold;}
12 p.def {font-family: monospace; font-weight: bold;}
13 p.def span {color: #555; font-weight: normal}
14 .desc {padding-left: 1em;}
b4edabd @marijnh make project page look a little less primitive
marijnh authored
15 a {text-decoration: none; color: #600;}
24935b6 @marijnh and finally, we have documentation
marijnh authored
16 ul {padding: 0; margin: 0; margin-left: 1.5em;}
17 </style>
18 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
19 </head>
20 <body>
21 <div id="wrap">
22 <h1><a style="color: black" href="">CL-JavaScript</a></h1>
24 <p>JavaScript is the new BASIC—a universal scripting language.
25 CL-JavaScript allows you to add user scripting to your Common Lisp
26 application without requiring your poor users to learn Common Lisp.
27 It is a JavaScript to Common Lisp translator, runtime, and standard
b4edabd @marijnh make project page look a little less primitive
marijnh authored
28 library. We are <a href="">ECMAScript
29 3</a> compatible, with some of the ECMAScript 5 extensions.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
31 <p>By using the Lisp compiler to compile JavaScript (and by using
32 some clever tricks for the things that Lisp normally isn't good at),
33 this implementation manages to be faster than most of the 2009
34 generation of JavaScript engines. The new generation (V8,
819e9f4 @marijnh release 0.10.11
marijnh authored
35 Jägermonkey) beats it by, depending on the benchmark, a factor 4 or
24935b6 @marijnh and finally, we have documentation
marijnh authored
36 so.</p>
38 <h2>Contents</h2>
40 <ul>
41 <li><a href="#news">News</a></li>
42 <li><a href="#code">Code</a></li>
43 <li><a href="#dependencies">Dependencies</a></li>
44 <li><a href="#support">Support</a></li>
45 <li><a href="#quickstart">Quickstart</a></li>
46 <li><a href="#reference">Reference</a>
47 <ul>
48 <li><a href="#running">Running Code</a></li>
49 <li><a href="#values">JavaScript Values</a></li>
50 <li><a href="#exceptions">Exceptions</a></li>
51 <li><a href="#environment">The Environment</a></li>
52 <li><a href="#utilities">Utilities</a></li>
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
53 <li><a href="#deflib">Library Definition</a></li>
54 <li><a href="#provided">Provided Libraries</a></li>
24935b6 @marijnh and finally, we have documentation
marijnh authored
55 </ul>
56 </li>
57 </ul>
59 <h2 id="news">News</h2>
65df4ca @marijnh Mark release 0.12.03
marijnh authored
61 <p class="news"><span>14-03-2012</span>: <strong><a href="">Version
62 0.12.03</a></strong>: Fix CLISP incompatibility.</p>
0a351b0 @marijnh Mark release 0.12.01
marijnh authored
64 <p class="news"><span>09-01-2012</span>: <strong><a href="">Version
65 0.12.01</a></strong>: Follow changes
66 in <a href="">parse-js</a>,
67 add <code>Function.prototype.bind</code>, getter/setter support,
68 small fixes.</p>
9c2eced @marijnh mark release 0.10.12
marijnh authored
70 <p class="news"><span>08-12-2010</span>: <strong><a
71 href="">Version
72 0.10.12</a></strong>: Implements <a
73 href="">ECMA5-style</a>
74 array, string, and <code>Object</code> constructor methods, as well
75 as a <code>JSON</code> object. Rough <a
76 href="#requirelib">support</a> for <a
77 href="">CommonJS
78 modules</a>. Adds correct <code>length</code> (arity) properties to
79 function objects.</p>
819e9f4 @marijnh release 0.10.11
marijnh authored
81 <p class="news"><span>15-11-2010</span>: <strong><a
9d3e9ed @marijnh fix download links in project page
marijnh authored
82 href="">Version
819e9f4 @marijnh release 0.10.11
marijnh authored
83 0.10.11</a></strong>: The first release on the new project page. Our
84 API can be considered more or less stable now, and there are no
85 serious gaps left in our ECMAScript 3 support.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
87 <p class="news"><span>15-11-2010</span>: It seems I have finally
88 documented this library.</p>
90 <h2 id="code">Code</h2>
92 <p>CL-JavaScript was created by Alan Pavičić, Iva Jurišić, and
93 Marijn Haverbeke. It is released under a <a href="LICENSE">MIT-style
94 licence</a>.</p>
96 <p>Development takes place on <a
97 href="">github</a>. Any releases we make
819e9f4 @marijnh release 0.10.11
marijnh authored
98 are listed under <a href="#news">News</a>. The latest release is
99 always linked from <a
9d3e9ed @marijnh fix download links in project page
marijnh authored
100 href="">cl-javascript.tgz</a>.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
102 <h2 id="dependencies">Dependencies</h2>
104 <p>CL-JavaScript depends on <a
105 href="">parse-js</a>, <a
106 href="">CL-PPCRE</a>, and optionally <a
107 href="">local-time</a>
108 (you won't have a <code>Date</code> object if your ASDF can not find
109 local-time).</p>
111 <p>Because <em>emulating</em> IEEE 754 floating point special values
112 (NaN, Infinity) in software is painfully inefficient, CL-JavaScript
113 includes some non-portable code to directly use machine floats in
114 SBCL and Allegro Common Lisp. There is fallback code present for
115 other implementations, but since the developers don't develop on
116 those, that might not be very well tested. It is recommended, if you
117 really want to use the system on another implementation, to try and
118 add native float support for that implementation.</p>
120 <h2 id="support">Support</h2>
122 <p>When you have a problem, please either open an issue on <a
123 href="">github</a>, or send <a
124 href="">the maintainer</a> an e-mail.</p>
126 <h2 id="quickstart">Quickstart</h2>
128 <p>First, load the system:</p>
130 <pre>cl-user> (asdf:oos 'asdf:load-op :cl-js)
131 cl-user> (use-package :cl-js)</pre>
133 <p>We can start a JavaScript REPL to convince ourselves that yes, we
134 really do have JavaScript in our Common Lisp.</p>
136 <pre>cl-user> (js-repl)
137 JS repl (#q to quit)
138 > 1 + 1
139 2
140 > function fac(x) { return x <= 1 ? x : x * fac(x - 1); }
141 [object Object]
142 > fac(10)
143 3628800
144 > #q
145 cl-user></pre>
147 <p>Well, that seems to work. Next up: defining our own library.</p>
149 <pre>cl-user> (defparameter *mylib* (empty-lib))
150 cl-user> (add-to-lib *mylib*
151 (.func "plusOne" (x) (1+ (to-number x)))
152 (.object "numbers"
153 (.value "one" 1)
154 (.value "two" "2")))
155 cl-user> (with-js-env (*mylib*)
156 (run-js "plusOne(numbers.two)"))
157 3</pre>
159 <p>Note the <code>to-number</code> call. This will invoke
160 JavaScripts number-conversion. For a library like this, you are, of
161 course, better off just doing something like this:</p>
163 <pre>cl-user> (run-js "
164 function plusOne(x){return x + 1;}
165 var numbers = {one: 1, two: '2'};")</pre>
167 <p>But, in general, what you want to do is write <em>glue</em> code,
168 providing a JavaScript API for your application. For this, the
169 library does its best to provide a practical interface for defining
170 JavaScript environments.</p>
172 <h2 id="reference">Reference</h2>
174 <h3 id="running">Running Code</h3>
176 <p class="def" id="run-js"><span>function</span> run-js (code &amp;key (compile t) wrap-parse-errors optimize)</p>
178 <p class="desc">Runs the given code. <code>code</code> can be a
179 string or a stream. <code>compile</code> and <code>optimize</code>
180 determine whether the code should be compiled, and if, whether it
181 should be optimized, before it is run. When
182 <code>wrap-parse-errors</code> is given, parse errors are wrapped in
183 <a href="#js-condition"><code>js-condition</code></a> objects, and
184 can be caught by JavaScript <code>catch</code> forms.</p>
643399e @marijnh add external-format arg to run-js-file
marijnh authored
186 <p class="def" id="run-js-file"><span>function</span> run-js-file (file &amp;key (compile t) wrap-parse-errors optimize external-format)</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
188 <p class="desc">Runs the code from the given file. The keyword
189 arguments are passed through to <a
643399e @marijnh add external-format arg to run-js-file
marijnh authored
190 href="#run-js"><code>run-js</code></a>, except for
191 <code>external-format</code>, which is passed to
192 <code>open</code>.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
194 <p class="def" id="js-repl"><span>function</span> js-repl (&amp;key (handle-errors t))</p>
196 <p class="desc">Starts an interactive JavaScript REPL. If
197 <code>handle-errors</code> is <code>t</code>, all errors will be
198 caught and printed. If it is <code>nil</code>, all errors are let
199 through. If it has any other value, only errors of type <a
200 href="#js-condition"><code>js-condition</code></a> are handled and
201 printed.</p>
203 <h3 id="values">JavaScript Values</h3>
205 <p>Values in a JavaScript environment are represented as
206 follows:</p>
208 <p><code>null</code> and <code>undefined</code> are the Lisp
209 keywords <code>:null</code> and <code>:undefined</code>. The type
210 <code>js-null</code> is provided, which includes both these values.
211 <code>js-null</code> is also a predicate function (shortcut for
212 <code>(typep x 'js-null)</code>).</p>
214 <p>Booleans are Lisp booleans (<code>nil</code> and <code>t</code>).</p>
216 <p>Numbers are represented as Lisp numbers (integers and
217 double-floats). On implementations where no support for representing
218 NaN and Infinity as floats has been added, these are represented by
219 the values <code>:NaN</code>, <code>:Inf</code>, and
220 <code>:-Inf</code>. The <code>js-number</code> type helps abstract
221 this—matching only numbers on those implementations where no
222 keywords are needed, and both numbers and these three keywords on
223 others.</p>
225 <p>The macros <code>nan</code>, <code>infinity</code>, and
226 <code>-infinity</code> are provided to create special number values.
227 The predicate <code>is-nan</code> can be used to check whether a
228 value is NaN.</p>
230 <p>Strings are plain Lisp strings.</p>
232 <p>Objects are a custom struct type—<code>js-obj</code>. The
233 <code>js-func</code> and <code>js-array</code> types are subtypes of
234 this.</p>
236 <p class="def" id="js-obj"><span>function</span> js-obj (&amp;optional prototype type)</p>
238 <p class="desc">Creates a JavaScript object. Optionally, a prototype
754c2d8 @marijnh make it possible to directly pass a prototype to js-obj
marijnh authored
239 id (more about that <a href="#prototype">later</a>) or prototype
240 object, and a type (as
24935b6 @marijnh and finally, we have documentation
marijnh authored
241 in <a href="#define-js-obj"><code>define-js-obj</code></a>) can be
242 given.</p>
244 <p class="def" id="js-prop"><span>function</span> js-prop (obj propname)</p>
246 <p class="desc">Retrieves a property from an object. A
247 <code>setf</code> variant is provided for setting properties.</p>
249 <p class="def" id="js-array"><span>function</span> js-array (vector)</p>
251 <p class="desc">Creates a new JavaScript array. <code>vector</code>
252 must be an adjustable vector with a fill pointer.</p>
254 <p class="def" id="js-array-length"><span>function</span> js-array-length (array)</p>
256 <p class="desc">Retrieve the length of a JavaScript array.</p>
258 <p class="def" id="js-aref"><span>function</span> js-aref (array index)</p>
260 <p class="desc">Access an element in an array. There is a
261 <code>setf</code> variant as well.</p>
263 <p class="def" id="js-call"><span>macro</span> js-call (func this &amp;rest args)</p>
265 <p class="desc">Call a JavaScript function value.</p>
267 <p class="def" id="js-method"><span>macro</span> js-method (object name &amp;rest args)</p>
269 <p class="desc">Call a method in a JavaScript object.</p>
271 <p class="def" id="js-func"><span>macro</span> js-func (args &amp;body body)</p>
273 <p class="desc">Creates a JavaScript function object from a
274 <code>lambda</code>-like specification. Inside the body
275 <code>this</code> will be bound, in addition to the specified
276 arguments. The argument list is mangled to conform to JavaScript
277 calling conventions—each paramter will become optional, with an
278 implicit default of <code>:undefined</code>, unless you specify your
279 own default. A <code>&amp;rest</code> clause is allowed, but
280 <code>&amp;key</code> and <code>&amp;optional</code> can't be
281 used.</p>
283 <h3 id="exceptions">Exceptions</h3>
285 <p>JavaScript exceptions are raised as Lisp conditions of the
286 <code>js-condition</code> type. A JavaScript <code>catch</code>
287 block will catch these (and only these).</p>
289 <p class="def" id="js-condition-value"><span>method</span> js-condition-value (condition)</p>
291 <p class="desc">Returns the JavaScript value associated with the
292 given condition.</p>
294 <p class="def" id="js-error"><span>function</span> js-error (type message &amp;rest args)</p>
296 <p class="desc">Raises a JavaScript error (value of type
297 <code>Error</code>) . <code>type</code> must be prototype id
298 (<code>:error</code>, <code>:type-error</code>,
299 <code>:syntax-error</code>, <code>:range-error</code>,
300 <code>:uri-error</code>, and <code>:eval-error</code> are provided
301 by the standard lib). <code>message</code> can be a format string
302 into which <code>args</code> will be interpolated.</p>
304 <h3 id="environment">The Environment</h3>
306 <p class="def" id="env"><span>variable</span> *env*</p>
308 <p class="desc">The variable that holds the current environment.
309 Starts out unbound (though <a href="#run-js"><code>run-js</code></a>
310 and <a href="#js-repl"><code>js-repl</code></a> will give it a
311 default value automatically when they find it unbound).</p>
313 <p class="def" id="with-js-env"><span>macro</span> with-js-env ((&amp;rest libraries) &amp;body body)</p>
315 <p class="desc">Runs <code>body</code> with <a
316 href="#env"><code>*env*</code></a> bound to a fresh environment,
317 which was created by loading the standard library plus the given
318 libraries.</p>
320 <p class="def" id="create-env"><span>function</span> create-env (&amp;rest libraries)</p>
322 <p class="desc">Creates a new environment, loading the given libraries.</p>
324 <p class="def" id="add-to-env"><span>function</span> add-to-env (env &amp;rest libraries)</p>
326 <p class="desc">Extends <code>env</code> with the given libraries,
327 then returns it.</p>
329 <h3 id="utilities">Utilities</h3>
331 <p class="def" id="void"><span>macro</span> void (&amp;body body)</p>
333 <p class="desc">Executes the body, returns
334 <code>:undefined</code>.</p>
336 <p class="def" id="to-string">
337 <span>function</span> to-string (value)<br/>
338 <span>function</span> to-number (value)<br/>
339 <span>function</span> to-integer (value)<br/>
340 <span>function</span> to-boolean (value)</p>
342 <p class="desc">Invokes the standard JavaScript type conversion
343 algorithm on the given value.</p>
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
345 <h3 id="deflib">Library Definition</h3>
24935b6 @marijnh and finally, we have documentation
marijnh authored
347 <p>CL-JavaScript works with first-class libraries. These are
348 specifications of a set of variables, prototypes, and constructors
349 that can be instantiated into an environment to make their
350 definitions available there.</p>
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
352 <p class="def" id="empty-lib"><span>function</span> empty-lib (&amp;optional name)</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
354 <p class="desc">Returns a fresh, empty library specification object.
355 The name is only used for the printed representation of the object.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
357 <p class="def" id="add-to-lib"><span>macro</span> add-to-lib (lib &amp;body body)</p>
359 <p class="desc">Add the definitions found in <code>body</code> to
360 the given library.</p>
362 <p>Defining the content of a library is done with a family of macros
363 starting with a period. These all take a <code>&amp;body</code> in
364 which lists starting with a keyword can be used to set options. For
365 example:</p>
367 <pre>(.object "Math"
368 (:slot-default :noenum)
369 (.value "E" (exp 1)))</pre>
371 <p>Here, the <code>:slot-default</code> option is given, causing all
372 slots defined in the <code>Math</code> object to not be enumerable.</p>
374 <p>All defining forms that allow slots to be defined inside of them
375 accept the <code>:slot-default</code> option. All forms that define
376 slots accept the <code>:slot</code> option. Both of these expect a
377 list of keywords (<code>:enum</code>, <code>:noenum</code>,
378 <code>:ro</code>, <code>:rw</code>, <code>:del</code>,
379 <code>:nodel</code>) which specify slot properties (enumerabe,
380 read-only, and deletable). Properties that are not specified are
381 inherited from the context (as an under-the-covers special
382 variable). By default, properties are enumerable, read-write, and
383 deletable, except in prototypes, where they are not enumerable.</p>
385 <p class="def" id="prototype"><span>macro</span> .prototype (id &amp;body body)</p>
387 <p class="desc">Creates a new prototype and associates it with the
388 given ID. All non-option forms appearing in the body are evaluated,
389 and can add properties to the prototpe. A <code>:parent</code>
390 option (which should hold a prototype-id) can be used to make this
391 prototype inherit from another prototype.</p>
393 <p class="def" id="constructor"><span>macro</span> .constructor (name args &amp;body body)</p>
395 <p class="desc">Declares a constructor with the given argument list
396 (interpreted as in <a href="#js-func"><code>js-func</code></a>) and
397 body. A <code>:prototype</code> option may appear in the body, and
398 is used to determine what prototype objects created with this
399 constructor should get. If it holds a keyword, that is the ID of the
400 prototype to use, if it holds a list of slot definitions, a new prototype
401 object is created and given those slots.</p>
403 <p class="desc">If this constructor should not create regular
404 objects, you can give it a <code>:type</code> option containing the
405 name of a type defined with <a
406 href="#define-js-obj"><code>define-js-obj</code></a>. When the
407 constructor is invoked with <code>new</code>, you will then get an
408 object of that type as <code>this</code> variable, rather than a
409 plain object.</p>
411 <p class="desc">Finally, a <code>:properties</code> option can be
412 passed, within which properties for the constructor itself can be
413 defined (as in <code>String.fromCharCode</code>).</p>
415 <p class="def" id="value"><span>macro</span> .value (name &amp;body value)</p>
417 <p class="desc">Defines a simple value property. When this appears
418 at the top level, it defines a global variable. When it appears
419 inside another form, it adds a property to that definition.</p>
421 <p class="def" id="object"><span>macro</span> .object (name &amp;body body)</p>
423 <p class="desc">This defines an object property. The
424 <code>body</code> contains property definitons for this object, and
425 optionally a <code>:parent</code> option, as in <a
426 href="#prototype"><code>.prototype</code></a>, to give the object a
427 specific prototype.</p>
429 <p class="def" id="func"><span>macro</span> .func (name args &amp;body body)</p>
431 <p class="desc">Adds a function (top-level) or method.
432 <code>args</code> is an argument list as in <a
433 href="#js-func"><code>js-func</code></a>. The given body becomes the
434 body of the function. A <code>:properties</code> option can be used
435 to give the function object itself properties.</p>
437 <p class="def" id="active"><span>macro</span> .active (name &amp;body body)</p>
439 <p class="desc">This macro is used to add 'active' properties to
440 objects. Active properties are things that can be approached like
441 regular properties, but execute some function when read or written.
442 The <code>:read</code> and <code>:write</code> options can be used
443 to specify the bodies of the functions, like this:</p>
445 <pre class="desc">(.active "preciousProperty"
446 (:read () "my precious!")
447 (:write (value) (js-error :error "How dare you touch my precious!")))</pre>
449 <p class="desc">(The argument lists are compulsory, even though they are always
450 the same.)</p>
452 <p class="def" id="active-r"><span>macro</span> .active-r (name &amp;body body)</p>
454 <p class="desc">This is a shortcut for an <a
455 href="#active"><code>.active</code></a> property with only a
456 <code>:read</code> entry (meaning writes to the slot will be
457 ignored).</p>
459 <p>The following two macros should not be used inside library
460 definitions, but at the top level (they are global in their
461 effect).</p>
463 <p class="def" id="define-js-obj"><span>macro</span> define-js-obj (name &amp;body slots)</p>
465 <p class="desc">Defines a struct type fit for holding JavaScript
466 object values. The way to use this is to specify the type name you
467 use here as the <code>:type</code> option of a <a
468 href="#constructor"><code>.constructor</code></a> form, and then
469 fill in your custom slots in this constructor.</p>
471 <p class="def" id="integrate-type"><span>macro</span> integrate-type (specializer &amp;body options)</p>
473 <p class="desc">A type defined by <a
474 href="#define-js-obj"><code>define-js-obj</code></a> is a 'real'
475 JavaScript object, to which clients can add properties. Sometimes,
476 it is preferable to use Lisp objects 'as they are', because wrapping
477 is too expensive. This macro allows you to do that.</p>
479 <p class="desc">To be able to use a value as a JavaScript value, a
480 bunch of methods have to specialized on it, so that JavaScript
481 operations (<code>typeof</code>, <code>String(x)</code>) will know
482 what to do with it.</p>
484 <p class="desc"><code>specializer</code> should be a valid method
485 specializer that can be used to recognize the type you want to
486 integrate.</p>
488 <p class="desc">All options appearing under this macro can take
489 either the form of a single value, or an argument list (of a single
490 symbol) and then a body. The <code>:string</code> option determines
491 how the type is converted to string (default is <code>"[object
492 Object]"</code>). The <code>:number</code> option converts to
493 numbers (default <code>NaN</code>). The <code>:boolean</code> option
494 to booleans (default <code>true</code>). <code>typeof</code> is used
495 to determine the string returned by the <code>typeof</code> operator
496 (default <code>"foreign"</code>). When a <code>:proto-id</code> form
497 is given, it is used to locate a prototype in which properties for
498 these values are looked up.</p>
500 <p class="desc">An example:</p>
502 <pre class="desc">(integrate-type complex
503 (:number (val) (realpart val))
504 (:string (val) (format nil "~a+~ai" (realpart val) (imagpart val)))
505 (:typeof "complex")
506 (:proto-id :number)) ;; or add a custom prototype
508 /* ... and in your library ... */
509 (.func "complex" (real imag)
510 (complex (to-number real) (to-number imag)))</pre>
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
512 <h3 id="provided">Provided Libraries</h3>
514 <p class="def" id="printlib"><span>variable</span> *printlib*</p>
516 <p class="desc">A tiny library value containing only a
fa2b6f4 @marijnh make print take multiple arguments
marijnh authored
517 <code>print</code> function, which will write its arguments to
d5104e8 @marijnh Add minimal support for CommonJS modules (see requirelib)
marijnh authored
518 <code>*standard-output*</code>.</p>
520 <p class="def" id="requirelib"><span>function</span> requirelib (hook)</p>
522 <p class="desc">When called, returns a library object that
523 implements the CommonJS-style <code>require</code> operator.
524 <code>hook</code> should be a funcallable object which, given a
525 string, verifies that string as a module specifier, and returns a
526 pathname under which the module text can be found. Or, if you need
527 modules that aren't simply files, it can return two values—a
528 canonical module identifier (must be comparable with
529 <code>equal</code>) and a function that, given this identifier,
530 returns either a stream or a string containing the module's
531 text.</p>
533 <p class="desc">A trivial hook (without error-checking or safety)
534 could simply do <code>(merge-pathnames spec
535 "/my/script/dir/x.js")</code>. If you do want to do error-checking,
536 use <a href="#js-error"><code>js-error</code></a> to complain when a
537 specifier is not acceptable.</p>
539 <p class="desc">Note that CL-JavaScript's implementation of CommonJS
540 modules does not sandbox the modules in any serious way—it simply
541 wraps them in a function. This means that direct,
542 <code>var</code>-less assignments <em>will</em> create top-level
543 variables, and the module can mangle existing values (say,
544 <code>Object.prototype</code>) all it wants. For well-behaved
545 modules, this shouldn't be an issue.</p>
24935b6 @marijnh and finally, we have documentation
marijnh authored
547 </div>
548 </body></html>
Something went wrong with that request. Please try again.