| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
|
| 24 |
public Object getImplementation() |
| 25 |
{ |
| 26 |
return implementation; |
| 27 |
} |
| 28 |
|
| 29 |
public void initImplementation(Object implementation) |
| 30 |
{ |
| 31 |
this.implementation = implementation; |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
public String getClassName() |
| 36 |
{ |
| 37 |
return "Continuation"; |
| 38 |
} |
| 39 |
|
| 40 |
public Scriptable construct(Context cx, Scriptable scope, Object[] args) |
| 41 |
{ |
| 42 |
throw Context.reportRuntimeError("Direct call is not supported"); |
| 43 |
} |
| 44 |
|
| 45 |
public Object call(Context cx, Scriptable scope, Scriptable thisObj, |
| 46 |
Object[] args) |
| 47 |
{ |
| 48 |
return Interpreter.restartContinuation(this, cx, scope, args); |
| 49 |
} |
| 50 |
|
| 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 |
| 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 |
| 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 |
|
| 87 |
|
| 88 |
@Override |
| 89 |
protected int findPrototypeId(String s) |
| 90 |
{ |
| 91 |
int id; |
| 92 |
|
| 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 |
|
| 99 |
return id; |
| 100 |
} |
| 101 |
|
| 102 |
private static final int |
| 103 |
Id_constructor = 1, |
| 104 |
MAX_PROTOTYPE_ID = 1; |
| 105 |
|
| 106 |
|
| 107 |
} |