Narcissus/Development: Difference between revisions

Jump to navigation Jump to search
interpreter info
(another host-lang req, more in the interpreter)
(interpreter info)
Line 62: Line 62:
=== Values ===
=== Values ===


* all values are roughly self-representing
User-JS primitive values are represented in host-JS directly as themselves.
* function proxies
 
User-JS objects are represented directly as host-JS objects; each user-property <code>foo</code> is directly represented as a host-property <code>foo</code>.
 
User-JS functions are represented as proxy functions that wrap a <code>FunctionObject</code>, which encapsulates the <code>Node</code> and <code>ExecutionContext</code> for the closure.


=== Control flow ===
=== Control flow ===


* <code>ExecutionContext</code>s
Code is always executed with a current <code>ExecutionContext</code>, which contains the current scope chain and <code>this</code> binding. Execution contexts also contain a <code>result</code> property, which is used for the completion value of the current statement or expression or the result of returning from a function or throwing an exception.
* <code>RETURN</code>, <code>THROW</code>, <code>BREAK</code>, <code>CONTINUE</code>
 
* <code>__call__</code>
Calling a user-JS function is represented by calling the host-JS <code>__call__</code> method. Narcissus patches the host-JS <code>Function.prototype</code> to add a default <code>__call__</code> method. Similarly, calling a user-JS function as a constructor (i.e., from <code>new</code>) is represented by calling the host-JS <code>__construct__</code> method. '''This is unnecessary now that functions are proxies; see [https://bugzilla.mozilla.org/show_bug.cgi?id=586095 bug 586095].'''
* function proxies
 
Returning from a function via <code>return</code> is represented by throwing the constant <code>RETURN</code>. The return value is stored in the <code>result</code> property of the current execution context.
 
Throwing a user-JS exception is represented by throwing the constant <code>THROW</code>. The exception value is stored in the <code>result</code> property of the current execution context.
 
Breaking or continuing a loop is represented by throwing the constant <code>BREAK</code> or <code>CONTINUE</code>, respectively.
34

edits

Navigation menu