comparison src/luan/LuanClosure.java @ 1330:f41919741100

fix security
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 11 Feb 2019 01:38:55 -0700
parents src/luan/impl/Closure.java@3ef883468fd0
children 25746915a241
comparison
equal deleted inserted replaced
1329:5a39b006acd1 1330:f41919741100
1 package luan;
2
3 import luan.impl.Pointer;
4
5
6 public abstract class LuanClosure extends LuanFunction implements LuanCloneable, Cloneable {
7 public Pointer[] upValues;
8 public boolean javaOk;
9 public final String sourceName;
10 private LuanCloner cloner;
11
12 public LuanClosure(int nUpValues,boolean javaOk,String sourceName) throws LuanException {
13 this.upValues = new Pointer[nUpValues];
14 this.javaOk = javaOk;
15 this.sourceName = sourceName;
16 }
17
18 @Override public LuanClosure shallowClone() {
19 check();
20 try {
21 return (LuanClosure)clone();
22 } catch(CloneNotSupportedException e) {
23 throw new RuntimeException(e);
24 }
25 }
26
27 @Override public void deepenClone(LuanCloneable dc,LuanCloner cloner) {
28 LuanClosure clone = (LuanClosure)dc;
29 switch( cloner.type ) {
30 case COMPLETE:
31 clone.upValues = (Pointer[])cloner.clone(upValues);
32 return;
33 case INCREMENTAL:
34 clone.cloner = cloner;
35 clone.upValues = upValues;
36 return;
37 }
38 }
39
40 private void check() {
41 if( cloner != null ) {
42 upValues = (Pointer[])cloner.clone(upValues);
43 cloner = null;
44 }
45 }
46
47 @Override public final Object call(LuanState luan,Object[] args) throws LuanException {
48 if( luan.isLocked )
49 throw new RuntimeException("luan is locked");
50 check();
51 luan.push(this);
52 try {
53 return doCall(luan,args);
54 } catch(StackOverflowError e) {
55 throw new LuanException( "stack overflow" );
56 } finally {
57 luan.pop();
58 }
59 }
60
61 public abstract Object doCall(LuanState luan,Object[] args) throws LuanException;
62 }