1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 package org.mozilla.javascript; 8 9 public final class NativeContinuation extends IdScriptableObject 10 implements Function 11 { 12 static final long serialVersionUID = 1794167133757605367L; 13 14 private static final Object FTAG = "Continuation"; 15 16 private Object implementation; 17 init(Context cx, Scriptable scope, boolean sealed)18 public static void init(Context cx, Scriptable scope, boolean sealed) 19 { 20 NativeContinuation obj = new NativeContinuation(); 21 obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); 22 } 23 getImplementation()24 public Object getImplementation() 25 { 26 return implementation; 27 } 28 initImplementation(Object implementation)29 public void initImplementation(Object implementation) 30 { 31 this.implementation = implementation; 32 } 33 34 @Override getClassName()35 public String getClassName() 36 { 37 return "Continuation"; 38 } 39 construct(Context cx, Scriptable scope, Object[] args)40 public Scriptable construct(Context cx, Scriptable scope, Object[] args) 41 { 42 throw Context.reportRuntimeError("Direct call is not supported"); 43 } 44 call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args)45 public Object call(Context cx, Scriptable scope, Scriptable thisObj, 46 Object[] args) 47 { 48 return Interpreter.restartContinuation(this, cx, scope, args); 49 } 50 isContinuationConstructor(IdFunctionObject f)51 public static boolean isContinuationConstructor(IdFunctionObject f) 52 { 53 if (f.hasTag(FTAG) && f.methodId() == Id_constructor) { 54 return true; 55 } 56 return false; 57 } 58 59 @Override initPrototypeId(int id)60 protected void initPrototypeId(int id) 61 { 62 String s; 63 int arity; 64 switch (id) { 65 case Id_constructor: arity=0; s="constructor"; break; 66 default: throw new IllegalArgumentException(String.valueOf(id)); 67 } 68 initPrototypeMethod(FTAG, id, s, arity); 69 } 70 71 @Override execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args)72 public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, 73 Scriptable thisObj, Object[] args) 74 { 75 if (!f.hasTag(FTAG)) { 76 return super.execIdCall(f, cx, scope, thisObj, args); 77 } 78 int id = f.methodId(); 79 switch (id) { 80 case Id_constructor: 81 throw Context.reportRuntimeError("Direct call is not supported"); 82 } 83 throw new IllegalArgumentException(String.valueOf(id)); 84 } 85 86 // #string_id_map# 87 88 @Override findPrototypeId(String s)89 protected int findPrototypeId(String s) 90 { 91 int id; 92 // #generated# Last update: 2007-05-09 08:16:40 EDT 93 L0: { id = 0; String X = null; 94 if (s.length()==11) { X="constructor";id=Id_constructor; } 95 if (X!=null && X!=s && !X.equals(s)) id = 0; 96 break L0; 97 } 98 // #/generated# 99 return id; 100 } 101 102 private static final int 103 Id_constructor = 1, 104 MAX_PROTOTYPE_ID = 1; 105 106 // #/string_id_map# 107 } 108