Narcissus/Development: Difference between revisions

no edit summary
(interpreter info)
No edit summary
 
Line 72: Line 72:
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 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.


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].'''
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 leaky and would be better implemented with private names; see [https://bugzilla.mozilla.org/show_bug.cgi?id=586095 bug 586095].)


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.
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.
34

edits