| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public class ArrowFunction extends BaseFunction { |
| 14 |
|
| 15 |
static final long serialVersionUID = -7377989503697220633L; |
| 16 |
|
| 17 |
private final Callable targetFunction; |
| 18 |
private final Scriptable boundThis; |
| 19 |
|
| 20 |
public ArrowFunction(Context cx, Scriptable scope, Callable targetFunction, Scriptable boundThis) |
| 21 |
{ |
| 22 |
this.targetFunction = targetFunction; |
| 23 |
this.boundThis = boundThis; |
| 24 |
|
| 25 |
ScriptRuntime.setFunctionProtoAndParent(this, scope); |
| 26 |
|
| 27 |
Function thrower = ScriptRuntime.typeErrorThrower(); |
| 28 |
NativeObject throwing = new NativeObject(); |
| 29 |
throwing.put("get", throwing, thrower); |
| 30 |
throwing.put("set", throwing, thrower); |
| 31 |
throwing.put("enumerable", throwing, false); |
| 32 |
throwing.put("configurable", throwing, false); |
| 33 |
throwing.preventExtensions(); |
| 34 |
|
| 35 |
this.defineOwnProperty(cx, "caller", throwing, false); |
| 36 |
this.defineOwnProperty(cx, "arguments", throwing, false); |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) |
| 41 |
{ |
| 42 |
Scriptable callThis = boundThis != null ? boundThis : ScriptRuntime.getTopCallScope(cx); |
| 43 |
return targetFunction.call(cx, scope, callThis, args); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
public Scriptable construct(Context cx, Scriptable scope, Object[] args) { |
| 48 |
throw ScriptRuntime.typeError1("msg.not.ctor", decompile(0, 0)); |
| 49 |
} |
| 50 |
|
| 51 |
@Override |
| 52 |
public boolean hasInstance(Scriptable instance) { |
| 53 |
if (targetFunction instanceof Function) { |
| 54 |
return ((Function) targetFunction).hasInstance(instance); |
| 55 |
} |
| 56 |
throw ScriptRuntime.typeError0("msg.not.ctor"); |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public int getLength() { |
| 61 |
if (targetFunction instanceof BaseFunction) { |
| 62 |
return ((BaseFunction) targetFunction).getLength(); |
| 63 |
} |
| 64 |
return 0; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
String decompile(int indent, int flags) |
| 69 |
{ |
| 70 |
if (targetFunction instanceof BaseFunction) { |
| 71 |
return ((BaseFunction)targetFunction).decompile(indent, flags); |
| 72 |
} |
| 73 |
return super.decompile(indent, flags); |
| 74 |
} |
| 75 |
} |