标题: [技术讨论] 关于jscript.net [打印本页]
作者: jyswjjgdwtdtj 时间: 2024-8-26 15:21 标题: 关于jscript.net
本帖最后由 jyswjjgdwtdtj 于 2024-8-26 15:23 编辑
jscript.net是c#,vb.net的同胞兄弟 然而c#没有历史包袱,如今愈发茁壮,vb.net尽管语法似乎不太适配如今的新东西,但依然有着大量的爱好者
jscript.net却被M$彻底遗弃,早早夭折,typescript这个同为js系的弟弟彻底为他添上坟头最后一捧土
说到底,jscript.net从未被当成一项正经的语言 它不支持直接使用win32api操作底层(哪怕对于这项语言的设计者来说在容易不过),甚至不像powershell可以简单的add-type加载c#Dll进assembly 它不支持泛型(哪怕它的标准es4中有)……
js.net的定位非M$声称的在asp.net里做vbs的后继者,因为他比起c#来说一无是处,而似乎更像powershell的脚本语言,然而js强调类型,函数,需要用编译器来”解释“,拔高了门槛。
如今js.net在2010年停止更新,在.net framework中保持静默发布
说来好笑 M$在es4(ie5时代,即jscript,vbs还可以在ie上运行的时候)上表示强烈反对,转头又做出了这么个缝合怪jscript.net——不完全支持es4,还夹带了些私货,把一门彻底的弱类型语言强行向CIL靠拢,实际上在一开始就给他判了死刑
注释的部分为es4支持但jscript.net不支持- import System;
- import System.Windows.Forms;
- import System.Drawing;
- import System.Collections.Generic;
- import System.Collections;
- //import * from System;
- package Jscript_Net_Test{
- class ES1ToES3{
- var a="Windows Script Host||IE-Jscript";
- function A(){
- var name="Jscript";
- var WshVersion=5.6;
- var IE=7;
- var __null__=null;
- var __undefined__=undefined;
- var string=new String('hello');
- WshVersion=parseFloat(WshVersion);
- IE=parseInt(IE);
- MessageBox.Show(('hello'===string).toString());
- MessageBox.Show(('hello'==string).toString());
- var obj={
- array:[
- "a",
- 1,
- new Array(1),
- new Function("return 1"),
- Math.tan,
- new Date(),
- function(){
- return true;
- }
- ]
- };
- var ifunc=(function(){
- var i=0
- return function(){
- return i++;
- }
- }())
- with(Math){
- var t=tan(1);
- }
- }
- }
- class JscripOnly{
- var enumobj=new Enumerator([]);
- }
- class ES4{
- const a="";
- internal const foo = 5;
- //const a=""" I'm "Jscript.Net" """;
- //var b:(Number,String);
- /*function LIKE(param1:like{x:int,y:int},param2:double):String{
- return "";
- }*/
- interface IMyInterface{
- function foo():double;
- }
- /*class Wrapper<T> {
- inner: T
- }*/
- //generic function addItem(x);
- function addItem(x: int) {
- }
- function addItem(x: Number) {
- }
- //const foo = <div class={a}>{"Hello" + a}</div>;
- public function b(){
-
- }
- private function c(){
-
- }
- }
- class Jscript_NetOnly{
- expando class MyExpandoClass {
- function dump() {
- for (var x : String in this)
- print(x + " = " + this[x]);
- }
- }
- }
- }
复制代码
作者: jyswjjgdwtdtj 时间: 2024-8-26 15:21
当把jscript.net翻译成c# 可以看出实际上是把js.net“解释”,再解释执行(但凡与js天生的灵活性相关的都用类似反射的方法来赋值)- using System;
- using System.Windows.Forms;
- using Microsoft.JScript;
- using Microsoft.JScript.Vsa;
-
- namespace Jscript_Net_Test;
-
- [Serializable]
- public class ES1ToES3 : INeedEngine
- {
- public object a;
-
- [NonSerialized]
- private VsaEngine vsa_0020Engine;
-
- static ES1ToES3()
- {
- }//Error decoding local variables: Signature type sequence must have at least one element.
-
-
- private void _002Einit()
- {
- //Error decoding local variables: Signature type sequence must have at least one element.
- a = "Windows Script Host||IE-Jscript";
- }
-
- public virtual void A()
- {
- //IL_0005: Unknown result type (might be due to invalid IL or missing references)
- //IL_000c: Expected O, but got Unknown
- //IL_0034: Unknown result type (might be due to invalid IL or missing references)
- //IL_003a: Expected O, but got Unknown
- //IL_0076: Unknown result type (might be due to invalid IL or missing references)
- //IL_007c: Expected O, but got Unknown
- //IL_0089: Unknown result type (might be due to invalid IL or missing references)
- //IL_008f: Expected O, but got Unknown
- //IL_0112: Unknown result type (might be due to invalid IL or missing references)
- //IL_0134: Unknown result type (might be due to invalid IL or missing references)
- //IL_01ca: Unknown result type (might be due to invalid IL or missing references)
- //IL_01d0: Expected O, but got Unknown
- //IL_01e7: Unknown result type (might be due to invalid IL or missing references)
- //IL_01f3: Unknown result type (might be due to invalid IL or missing references)
- //IL_020b: Expected O, but got Unknown
- LateBinding val = new LateBinding("tan");
- FunctionObject val2 = FunctionExpression.JScriptFunctionExpression(typeof(ES1ToES3).TypeHandle, "anonymous 0", "A.anonymous 0", new string[0], (JSLocalField[])(object)new JSLocalField[1]
- {
- new JSLocalField("return value", typeof(bool).TypeHandle, 0)
- }, false, false, "function(){\r\n\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t}", ((INeedEngine)this).GetEngine());
- FunctionObject val3 = FunctionExpression.JScriptFunctionExpression(typeof(ES1ToES3).TypeHandle, "anonymous 2", "A.anonymous 2", new string[0], (JSLocalField[])(object)new JSLocalField[2]
- {
- new JSLocalField("i", typeof(double).TypeHandle, 0),
- new JSLocalField("return value", typeof(ScriptFunction).TypeHandle, 1)
- }, true, false, "function(){\r\n\t\t\t\tvar i=0\r\n\t\t\t\treturn function(){\r\n\t\t\t\t\treturn i++;\r\n\t\t\t\t}\r\n\t\t\t}", ((INeedEngine)this).GetEngine());
- string text = "Jscript";
- double num = 5.6;
- double num2 = 7.0;
- object value = DBNull.Value;
- object obj = null;
- StringObject val4 = GlobalObject.String.CreateInstance(new object[1] { "hello" });
- num = GlobalObject.parseFloat((object)num);
- num2 = GlobalObject.parseInt((object)num2, (object)Missing.Value);
- MessageBox.Show(BooleanPrototype.toString((object)(StrictEquality.JScriptStrictEquals((object)"hello", (object)val4) ? true : false)));
- MessageBox.Show(BooleanPrototype.toString((object)(Equality.JScriptEquals((object)"hello", (object)val4) ? true : false)));
- JSObject obj2 = ((INeedEngine)this).GetEngine().GetOriginalObjectConstructor().ConstructObject();
- object[] obj3 = new object[7]
- {
- "a",
- 1,
- GlobalObject.Array.CreateInstance(new object[1] { 1 }),
- GlobalObject.Function.CreateInstance(new object[1] { "return 1" }),
- null,
- null,
- null
- };
- val.obj = GlobalObject.Math;
- obj3[4] = val.GetNonMissingValue();
- obj3[5] = GlobalObject.Date.CreateInstance(new object[0]);
- obj3[6] = (object)new Closure(val2);
- obj2.SetMemberValue2("array", (object)Globals.ConstructArrayLiteral(obj3));
- object obj4 = obj2;
- object obj5 = LateBinding.CallValue((object)((IActivationObject)((INeedEngine)this).GetEngine().ScriptObjectStackTop()).GetGlobalScope(), (object)new Closure(val3), new object[0], false, false, ((INeedEngine)this).GetEngine());
- With.JScriptWith((object)GlobalObject.Math, ((INeedEngine)this).GetEngine());
- try
- {
- double num3 = MathObject.tan(1.0);
- }
- finally
- {
- ((INeedEngine)this).GetEngine().PopScriptObject();
- }
- }
-
- [JSFunction(/*Could not decode attribute arguments.*/)]
- public static bool A_002Eanonymous_00200(object @this, VsaEngine vsa_0020Engine)
- {
- return true;
- }
-
- [JSFunction(/*Could not decode attribute arguments.*/)]
- public static ScriptFunction A_002Eanonymous_00202(object @this, VsaEngine vsa_0020Engine)
- {
- //IL_0028: Unknown result type (might be due to invalid IL or missing references)
- //IL_002e: Expected O, but got Unknown
- //IL_003b: Unknown result type (might be due to invalid IL or missing references)
- //IL_0041: Expected O, but got Unknown
- //IL_0053: Unknown result type (might be due to invalid IL or missing references)
- //IL_0059: Expected O, but got Unknown
- //IL_0064: Unknown result type (might be due to invalid IL or missing references)
- FunctionObject val = FunctionExpression.JScriptFunctionExpression(typeof(ES1ToES3).TypeHandle, "anonymous 1", "A.anonymous 2.anonymous 1", new string[0], (JSLocalField[])(object)new JSLocalField[2]
- {
- new JSLocalField("return value", typeof(double).TypeHandle, 0),
- new JSLocalField("i", typeof(double).TypeHandle, 1)
- }, false, false, "function(){\r\n\t\t\t\t\treturn i++;\r\n\t\t\t\t}", vsa_0020Engine);
- double num = 0.0;
- ScriptFunction val2 = (ScriptFunction)new Closure(val);
- object[] localVars = ((StackFrame)vsa_0020Engine.ScriptObjectStackTop()).localVars;
- localVars[0] = num;
- localVars[1] = val2;
- return val2;
- }
-
- [JSFunction(/*Could not decode attribute arguments.*/)]
- public static double A_002Eanonymous_00202_002Eanonymous_00201(object @this, VsaEngine vsa_0020Engine)
- {
- //IL_000c: Unknown result type (might be due to invalid IL or missing references)
- //IL_0045: Unknown result type (might be due to invalid IL or missing references)
- ScriptObject parent = vsa_0020Engine.ScriptObjectStackTop().GetParent();
- double num = Convert.ToNumber(((StackFrame)parent).localVars[0]);
- parent.GetParent().GetParent();
- double num2;
- num = (num2 = num) + 1.0;
- double result = num2;
- ScriptObject parent2 = vsa_0020Engine.ScriptObjectStackTop().GetParent();
- ((StackFrame)parent2).localVars[0] = num;
- parent2.GetParent().GetParent();
- return result;
- }
-
- public ES1ToES3()
- {
- //Error decoding local variables: Signature type sequence must have at least one element.
- _002Einit();
- }
-
- private override VsaEngine GetEngine()
- {
- //Error decoding local variables: Signature type sequence must have at least one element.
- if (vsa_0020Engine == null)
- {
- vsa_0020Engine = VsaEngine.CreateEngineWithType(typeof(ES1ToES3).TypeHandle);
- }
-
- return vsa_0020Engine;
- }
-
- private override void SetEngine(VsaEngine P_0)
- {
- //Error decoding local variables: Signature type sequence must have at least one element.
- vsa_0020Engine = P_0;
- }
- }
复制代码
作者: Five66 时间: 2024-8-26 23:15
对es4完整支持的估计也就actionscript,而且你都说了ms反对es4的,怎么可能会支持,再说了,es4根本就没有被采纳成为标准
jsn能用dotnet类库,用反射就能调winapi和C#dll,功能上,该有的其实都差不多有,只是没有对应的语法
作者: jyswjjgdwtdtj 时间: 2024-8-28 12:02
回复 3# Five66
如果你说的反射调用winapi是指把c#代码保存到字符串 再用csc.exe编译,再反射载入assembly,再反射调用的话,那也太麻烦了jsn本就可以直接原生调用c#dll
作者: Five66 时间: 2024-8-28 14:47
回复 4# jyswjjgdwtdtj
我所说的用反射调winapi并不是你说的这个,虽然你这个确实也是一种方法
我说是指是动态平台调用,是用反射相关的类对应的方法来创建程序集,然后设置各种东西后调用,这是一种通用的方案,不需要其他语言,只要支持dotnet类库的都能使用(powershell也能用,虽然确实很麻烦)
示例可以看下面的
http://cx20.main.jp/blog/hello/2013/03/07/hello-win32-api-jscript-net-world/
作者: jyswjjgdwtdtj 时间: 2024-8-28 17:11
回复 5# Five66
那就是用emit了 还没学到
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |