update yjscompiler

This commit is contained in:
CaiHQ 2023-02-08 14:05:31 +08:00
parent 05e301d9e9
commit 7f81dba895
5 changed files with 24 additions and 22 deletions

View File

@ -1,6 +1,8 @@
{ {
"agentHttpAddr": "127.0.0.1:18000", "agentAddress": "127.0.0.1:18000",
"script": "/Users/huaqiancai/BDWare/datanet/datanet-gateway-bundle/datanet-gateway-backend/build/gateway.ypk", "ypkPath": "/Users/huaqiancai/BDWare/datanet/datanet-gateway-bundle/datanet-gateway-backend/build/gateway.ypk",
"pubKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd", "privateKey": "04d1924329f72ced148f6f333fb985ccbaa31b1e3aacf10be5f43d4a4ff5ad88899a005e79e37fc06993e1d66ada8cf8b711cb36f59538bb7d3e39e70fa9360ddd",
"privKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8" "publicKey": "589d94ee5688358a1c5c18430dd9c75097ddddebf769f139da36a807911d20f8",
"killBeforeStart":"ContractName",
"createParam":{}
} }

View File

@ -557,6 +557,9 @@ public class ContractProcess {
if (argSchemaHandler != null) { if (argSchemaHandler != null) {
fun.appendBeforeInvokeHandler(argSchemaHandler); fun.appendBeforeInvokeHandler(argSchemaHandler);
} }
if (fun.functionName.equals("onCreate")){
fun.appendAfterInvokeHandler(new ObjToJsonHandler());
}
if (fun.isExport()) { if (fun.isExport()) {
//if(fun.annotations...) //if(fun.annotations...)
AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class); AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class);

View File

@ -131,7 +131,8 @@ public class YJSCompiler {
if (czb.containsPath(str)) { if (czb.containsPath(str)) {
continue; continue;
} }
ZipEntry entry = zf.getEntry("/" + str);
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
if (null == entry) { if (null == entry) {
throw new IllegalStateException("missing import:" + str); throw new IllegalStateException("missing import:" + str);
} }

View File

@ -1,14 +1,15 @@
package org.bdware.sc.engine; package org.bdware.sc.engine;
import com.google.gson.*; import com.google.gson.*;
import jdk.nashorn.internal.runtime.Context;
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror; import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
import wrp.jdk.nashorn.internal.objects.NativeArray; import wrp.jdk.nashorn.internal.objects.NativeArray;
import wrp.jdk.nashorn.internal.runtime.PropertyMap; import wrp.jdk.nashorn.internal.runtime.PropertyMap;
import wrp.jdk.nashorn.internal.runtime.ScriptObject;
import wrp.jdk.nashorn.internal.scripts.JO; import wrp.jdk.nashorn.internal.scripts.JO;
import java.util.*; import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class JSONTool { public class JSONTool {
public static JsonElement convertMirrorToJson(Object ret2) { public static JsonElement convertMirrorToJson(Object ret2) {
@ -140,15 +141,15 @@ public class JSONTool {
return JsonNull.INSTANCE; return JsonNull.INSTANCE;
} else if (obj instanceof Number) { } else if (obj instanceof Number) {
return new JsonPrimitive((Number) obj); return new JsonPrimitive((Number) obj);
} else if (obj instanceof String) { } else if (obj instanceof String) {
return new JsonPrimitive((String) obj); return new JsonPrimitive((String) obj);
} else if (obj instanceof Character) { } else if (obj instanceof Character) {
return new JsonPrimitive((Character) obj); return new JsonPrimitive((Character) obj);
} } else if (obj instanceof Boolean) {
if (obj instanceof Boolean) {
return new JsonPrimitive((Boolean) obj); return new JsonPrimitive((Boolean) obj);
} else if (obj.getClass() == Boolean.TYPE) {
return new JsonPrimitive((boolean) obj);
} }
return JsonNull.INSTANCE; return JsonNull.INSTANCE;
} }

View File

@ -46,15 +46,13 @@ public class AccessHandler implements AnnotationHook {
} }
return argPacks; return argPacks;
} }
if (!argPacks.request.verifySignature()){
argPacks.request.setRequester(null);
}
if (acFunction == null) return argPacks; if (acFunction == null) return argPacks;
DesktopEngine de = (DesktopEngine) desktopEngine; DesktopEngine de = (DesktopEngine) desktopEngine;
Global oldGlobal = Context.getGlobal();
Global newGlobal = de.getDesktopGlobal();
boolean globalChanged = (oldGlobal != newGlobal);
try { try {
if (globalChanged) {
Context.setGlobal(newGlobal);
}
ContractRequest input = argPacks.request; ContractRequest input = argPacks.request;
JO jo = new JO(PropertyMap.newMap()); JO jo = new JO(PropertyMap.newMap());
jo.put("requester", input.getRequester(), false); jo.put("requester", input.getRequester(), false);
@ -69,9 +67,6 @@ public class AccessHandler implements AnnotationHook {
jo.addProperty("code", "401"); jo.addProperty("code", "401");
jo.addProperty("msg", "access check meets exception! " + e); jo.addProperty("msg", "access check meets exception! " + e);
throw new ScriptReturnException(jo); throw new ScriptReturnException(jo);
} finally {
if (globalChanged) Context.setGlobal(oldGlobal);
} }
} }