001: /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
002: *
003: * ***** BEGIN LICENSE BLOCK *****
004: * Version: MPL 1.1/GPL 2.0
005: *
006: * The contents of this file are subject to the Mozilla Public License Version
007: * 1.1 (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: * http://www.mozilla.org/MPL/
010: *
011: * Software distributed under the License is distributed on an "AS IS" basis,
012: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
013: * for the specific language governing rights and limitations under the
014: * License.
015: *
016: * The Original Code is Rhino code, released
017: * May 6, 1999.
018: *
019: * The Initial Developer of the Original Code is
020: * Netscape Communications Corporation.
021: * Portions created by the Initial Developer are Copyright (C) 1997-1999
022: * the Initial Developer. All Rights Reserved.
023: *
024: * Contributor(s):
025: * Igor Bukanov
026: *
027: * Alternatively, the contents of this file may be used under the terms of
028: * the GNU General Public License Version 2 or later (the "GPL"), in which
029: * case the provisions of the GPL are applicable instead of those above. If
030: * you wish to allow use of your version of this file only under the terms of
031: * the GPL and not to allow others to use your version of this file under the
032: * MPL, indicate your decision by deleting the provisions above and replacing
033: * them with the notice and other provisions required by the GPL. If you do
034: * not delete the provisions above, a recipient may use your version of this
035: * file under either the MPL or the GPL.
036: *
037: * ***** END LICENSE BLOCK ***** */
038:
039: package org.mozilla.javascript.continuations;
040:
041: import org.mozilla.javascript.*;
042:
043: public final class Continuation extends IdScriptableObject implements
044: Function {
045: static final long serialVersionUID = 1794167133757605367L;
046:
047: private static final Object FTAG = new Object();
048:
049: private Object implementation;
050:
051: public static void init(Context cx, Scriptable scope, boolean sealed) {
052: Continuation obj = new Continuation();
053: obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
054: }
055:
056: public Object getImplementation() {
057: return implementation;
058: }
059:
060: public void initImplementation(Object implementation) {
061: this .implementation = implementation;
062: }
063:
064: public String getClassName() {
065: return "Continuation";
066: }
067:
068: public Scriptable construct(Context cx, Scriptable scope,
069: Object[] args) {
070: throw Context
071: .reportRuntimeError("Direct call is not supported");
072: }
073:
074: public Object call(Context cx, Scriptable scope,
075: Scriptable this Obj, Object[] args) {
076: return Interpreter.restartContinuation(this , cx, scope, args);
077: }
078:
079: public static boolean isContinuationConstructor(IdFunctionObject f) {
080: if (f.hasTag(FTAG) && f.methodId() == Id_constructor) {
081: return true;
082: }
083: return false;
084: }
085:
086: protected void initPrototypeId(int id) {
087: String s;
088: int arity;
089: switch (id) {
090: case Id_constructor:
091: arity = 0;
092: s = "constructor";
093: break;
094: default:
095: throw new IllegalArgumentException(String.valueOf(id));
096: }
097: initPrototypeMethod(FTAG, id, s, arity);
098: }
099:
100: public Object execIdCall(IdFunctionObject f, Context cx,
101: Scriptable scope, Scriptable this Obj, Object[] args) {
102: if (!f.hasTag(FTAG)) {
103: return super .execIdCall(f, cx, scope, this Obj, args);
104: }
105: int id = f.methodId();
106: switch (id) {
107: case Id_constructor:
108: throw Context
109: .reportRuntimeError("Direct call is not supported");
110: }
111: throw new IllegalArgumentException(String.valueOf(id));
112: }
113:
114: // #string_id_map#
115:
116: protected int findPrototypeId(String s) {
117: int id;
118: // #generated# Last update: 2007-05-09 08:16:40 EDT
119: L0: {
120: id = 0;
121: String X = null;
122: if (s.length() == 11) {
123: X = "constructor";
124: id = Id_constructor;
125: }
126: if (X != null && X != s && !X.equals(s))
127: id = 0;
128: break L0;
129: }
130: // #/generated#
131: return id;
132: }
133:
134: private static final int Id_constructor = 1, MAX_PROTOTYPE_ID = 1;
135:
136: // #/string_id_map#
137: }
|