Method and device for calling code through intermediate script and electronic equipment

The method of calling code through intermediate scripts and running intermediate scripts using Node.js solves the problem that the Java execution engine cannot support JavaScript language features and low performance, and achieves more efficient JavaScript code execution and compatibility with higher versions.

CN119149161APending Publication Date: 2024-12-17SHANGHAI WEIWENJIA INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310670800.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-07
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

The existing Java execution engine cannot support all JavaScript language features when calling JavaScript code, and the execution performance is low, and the supported JavaScript versions are older, resulting in limited performance and functionality of JavaScript code.

Method used

The method of calling the code through an intermediate script is used to run the intermediate script, obtain the program parameters, transfer it to the intermediate script for execution, obtain the execution results, and output it on the Java platform, supporting higher versions of JavaScript, improving code compatibility and flexibility.

Benefits of technology

It effectively improves the execution efficiency of JavaScript code and the supported language features, improves the compatibility and user experience of the code, and avoids performance and security issues in Java virtual machines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149161A_ABST
    Figure CN119149161A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for calling a code through an intermediate script and electronic equipment, and the method for calling the code through the intermediate script comprises the steps: responding to a program execution request of a Java platform, and obtaining a program parameter; wherein the program parameters comprise a code file needing to be executed, a method needing to be executed and method parameters; transmitting the program parameters to an intermediate script, so that the intermediate script calls a code file on a code platform based on the program parameters to obtain an execution result; obtaining an execution result of the code file from the code platform; according to the JavaScript code implementation method and device, the middle script is operated through Node.js, the execution efficiency and supported language characteristics of the JavaScript code are effectively improved, meanwhile, the JavaScript of a higher version is supported, the compatibility and flexibility of the code are improved, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device and electronic device for calling a code through an intermediate script. Background Art

[0002] When Java (a computer programming language) execution engines provided by major companies call JavaScript (JS, a lightweight, interpreted or just-in-time compiled programming language with function priority) code, it is written based on the Java language and runs in the Java virtual machine. It cannot support all JavaScript language features, cannot use related JavaScript libraries, has low execution code performance, and supports older JavaScript versions. This situation leads to performance and functional limitations of JavaScript code. Summary of the invention

[0003] In view of this, the purpose of the present invention is to provide a method, device and electronic device for calling code through an intermediate script, running the intermediate script through Node.js, effectively improving the execution efficiency of JavaScript code and the supported language features, while supporting higher versions of JavaScript, improving the compatibility and flexibility of the code, and improving the user experience.

[0004] In a first aspect, an embodiment of the present invention provides a method for calling code through an intermediate script, and the method for calling code through an intermediate script includes: responding to a program execution request of a Java platform and obtaining program parameters; wherein the program parameters include: a code file to be executed, a method to be executed, and method parameters; transmitting the program parameters to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain an execution result; and obtaining the execution result of the code file from the code platform.

[0005] In some preferred embodiments of the present invention, after the step of obtaining program parameters in response to a program execution request of a Java platform, the method of calling the code through an intermediate script further includes: if the format of the method parameters in the program parameters is not in a string format, converting the format of the method parameters into a string format.

[0006] In some preferred embodiments of the present invention, the step of transmitting program parameters to the intermediate script includes: determining whether the operating environment of the intermediate script is a Windows environment; if so, transmitting the program parameters to the intermediate script based on a first program; if not, transmitting the program parameters to the intermediate script based on a second program; wherein the first program and the second program are both used to start the Node.js process, the first program runs in a Windows environment, and the second program runs in a MacOS or Linux environment.

[0007] In some preferred embodiments of the present invention, after the step of transmitting the program parameters to the intermediate script, the method further comprises: converting the format of the method parameters in the program parameters into an object format corresponding to the code platform.

[0008] In some preferred embodiments of the present invention, if the execution result is not empty, the method further includes: printing the execution result back to the Java platform, so that the Java platform outputs the execution result.

[0009] In some preferred embodiments of the present invention, if the execution result is not in a string format, the step of printing the execution result back to the Java platform and outputting it includes: printing the execution result back to the Java platform; converting the format of the execution result into an object format corresponding to the Java platform; and outputting the execution result in the converted format.

[0010] In some preferred embodiments of the present invention, if the execution result includes a first identifier; the step of printing the execution result back to the Java platform and outputting it includes: replacing the first identifier in the execution result with a second identifier; printing the execution result replaced with the second identifier back to the Java platform; replacing the second identifier in the execution result received by the Java platform with the first identifier; and outputting the execution result replaced with the first identifier.

[0011] In a second aspect, an embodiment of the present invention provides a device for calling code through an intermediate script, and the device for calling code through an intermediate script includes: a program parameter acquisition module, which is used to respond to a program execution request of a Java platform and obtain program parameters; wherein the program parameters include: a code file to be executed, a method to be executed, and method parameters; a program parameter transmission module, which is used to transmit the program parameters to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain an execution result; and a result acquisition module, which is used to obtain the execution result of the code file from the code platform.

[0012] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement any of the above-mentioned methods of calling code through an intermediate script.

[0013] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement any of the above-mentioned methods of calling code through an intermediate script.

[0014] The embodiments of the present invention bring the following beneficial effects:

[0015] The embodiment of the present invention provides a method, device and electronic device for calling code through an intermediate script. The method for calling code through an intermediate script includes: responding to a program execution request of a Java platform and obtaining program parameters; wherein the program parameters include: a code file to be executed, a method to be executed and method parameters; transmitting the program parameters to the intermediate script, so that the intermediate script calls the code file on a code platform based on the program parameters to obtain an execution result; obtaining the execution result of the code file from the code platform; running the intermediate script through Node.js, effectively improving the execution efficiency of JavaScript code and the supported language features, while supporting higher versions of JavaScript, improving the compatibility and flexibility of the code, and improving the user experience.

[0016] Other features and advantages disclosed in the present invention will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present invention.

[0017] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0019] Figure 1 A flowchart of a method for calling code through an intermediate script provided by an embodiment of the present invention;

[0020] Figure 2 A flowchart of another method for calling code through an intermediate script provided by an embodiment of the present invention;

[0021] Figure 3 A schematic diagram of the structure of a device for calling a code through an intermediate script provided by an embodiment of the present invention;

[0022] Figure 4 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

[0023] Icons: 310 - program parameter acquisition module; 320 - program parameter transmission module; 330 - result acquisition module; 400 - memory; 401 - processor; 402 - bus; 403 - communication interface. DETAILED DESCRIPTION

[0024] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0025] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0027] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, or the positions or positional relationships in which the product of the invention is usually placed when in use. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific position, be constructed and operated in a specific position, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.

[0028] In addition, the terms "horizontal", "vertical", "overhanging" and the like do not mean that the components are required to be absolutely horizontal or overhanging, but can be slightly tilted. For example, "horizontal" only means that its direction is more horizontal than "vertical", and does not mean that the structure must be completely horizontal, but can be slightly tilted.

[0029] In the description of the present invention, it is also necessary to explain that, unless otherwise clearly specified and limited, the terms "set", "install", "connect", and "connect" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0030] When the Java execution engines provided by major companies call JavaScript code, they are written based on the Java language and run in the Java virtual machine. They cannot support all JavaScript language features, cannot use related js libraries, have low execution code performance, and support older JavaScript versions. This situation leads to performance and functional limitations of JavaScript code, and a more efficient and complete solution is needed.

[0031] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.

[0032] Embodiment 1

[0033] The embodiment of the present invention provides a method for calling code through an intermediate script, see Figure 1 The flowchart of a method for calling code through an intermediate script provided by an embodiment of the present invention is shown, and the method includes:

[0034] Step S102, responding to the program execution request of the Java platform, obtaining program parameters; wherein the program parameters include: the code file to be executed, the method to be executed and the method parameters;

[0035] Specifically, in response to a command from a computer program or a user to call JavaScript code on a Java platform, the executed code file, the method to be executed, and the method parameters are obtained; wherein, the executed code file refers to the JavaScript code file to be executed, which may contain one or more JavaScript function definitions, or directly contain some JavaScript statements. In a Java program, we usually need to read the code file into memory, and compile and execute it through a JavaScript engine to obtain the corresponding result; the method to be executed refers to the JavaScript code to be executed, which may contain multiple function definitions. We need to specify one of the functions as the method to be executed so that it can be called in a Java program. The method is usually identified by a name, and the name of the method to be executed needs to be passed as a parameter when calling it; method parameters refer to some parameters that may need to be passed when calling a JavaScript method so that the method can be executed correctly. These parameters can be basic data types, objects, or even JavaScript data types such as functions. In a Java program, we can use the Object type to represent these parameters, and then pass them to the JavaScript engine to execute the corresponding method.

[0036] Step S104, transmitting the program parameters to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain an execution result;

[0037] Specifically, it is achieved through the following steps A1-A5:

[0038] Step A1, encapsulating the information such as the JavaScript code file to be executed, the name of the method to be executed and the method parameters obtained in the Java program into an object to facilitate subsequent transmission;

[0039] Exemplarily, it can be implemented by the following code:

[0040]

[0041] Among them, codeFile: the JavaScript code file to be executed, usually represented as a File object in a Java program; functionName: the name of the JavaScript function to be executed, represented as a string type in a Java program; parameters: the parameters required for the function to be executed, represented as an Object array type in a Java program.

[0042] Step A2, convert the object into JSON format and pass it to the intermediate script. You can use relevant JSON libraries to implement this step, such as jackson (a Java class library for processing JSON format data), gson (a Java class library for mapping between Java objects and JSON data), etc.

[0043] Exemplarily, it can be implemented by the following code:

[0044] ScriptExecutionRequest request=new ScriptExecutionRequest(codeFile,"add",new Object[]{2,3});

[0045] ObjectMapper mapper=new ObjectMapper();

[0046] String json=mapper.writeValueAsString(request);

[0047] First, we create a ScriptExecutionRequest object, which contains information such as the JavaScript code file to be executed, the function name to be executed, and the parameter list. Then, we use the ObjectMapper class provided by the Jackson library to convert the object into a string in JSON format. During the conversion process, Jackson will automatically serialize the member variables in the ScriptExecutionRequest object into corresponding JSON key-value pairs. Finally, we can pass the generated JSON string to the intermediate script through the network or other means for it to process. After receiving the JSON string, the intermediate script can deserialize the string and obtain the information in it, so as to call the corresponding JavaScript code file and execute the corresponding function on the code platform.

[0048] Step A3, read the JSON string in the intermediate script and convert it into a JavaScript object. You can use JavaScript's own JSON.parse() method or a third-party library to implement this step;

[0049] Exemplarily, it can be implemented by the following code:

[0050] var jsonString = '...'; / / JSON string read from the Java program

[0051] var request=JSON.parse(jsonString);

[0052] First, we create a string variable jsonString, which contains the JSON string to be parsed. Then, we use the built-in JSON.parse() method of JavaScript to parse the string into a JavaScript object and assign it to the variable request. During the parsing process, the JSON.parse() method automatically converts the JSON key-value pairs into corresponding JavaScript attributes and attribute values. Finally, we can use the attributes and attribute values ​​in the variable request for subsequent operations, such as calling functions or reading data in it. It should be noted that in actual applications, security verification and error handling may be required for JSON strings to ensure the stability and security of the system.

[0053] Step A4, obtaining the JavaScript code file to be executed in the intermediate script;

[0054] Exemplarily, it can be implemented by the following code:

[0055] var fs = require('fs');

[0056] var code=fs.readFileSync(request.codeFile,'utf8');

[0057] First, we use the built-in require() method to import the fs module in Node.js, which provides some methods for operating the file system. Then, we use the fs.readFileSync() method to read the JavaScript code file specified in the ScriptExecutionRequest object and return it to the variable code as a string. When reading a file, we need to pass two parameters: request.codeFile represents the file path to be read; 'utf8' represents the encoding format of the file, that is, converting binary data into a string type. When reading a file through the fs module, if the file does not exist or an error occurs when reading, an exception will be thrown, and the exception needs to be handled accordingly. Finally, we can perform subsequent operations based on the obtained code string, such as compiling and executing JavaScript code. It should be noted that in actual applications, security verification and error handling may be required for files to ensure the stability and security of the system.

[0058] Step A5, executing the JavaScript code file in the intermediate script;

[0059] Exemplarily, it can be implemented by the following code:

[0060] var vm = require('vm');

[0061] var sandbox = {};

[0062] vm.createContext(sandbox);

[0063] vm.runInContext(code,sandbox);

[0064] var func=sandbox[request.functionName];

[0065] First, we use the built-in require() method to import the vm module in Node.js, which provides some methods for creating a sandbox environment and running JavaScript code. Then, we create an empty object sandbox as a new context environment and call the vm.createContext() method to encapsulate it into an executable sandbox environment. Next, we call the vm.runInContext() method to compile and run the JavaScript code in the ScriptExecutionRequest object and execute it in the sandbox environment. During the execution process, all variables, functions, and objects will exist in the sandbox environment and remain isolated from the current environment. The final execution result will be stored inside the sandbox environment and can be obtained in the corresponding way. Finally, we get the reference of the function to be executed from the sandbox environment according to the function name specified in the ScriptExecutionRequest object for subsequent calls. When obtaining the function reference, we can use a method similar to sandbox[request.functionName] to directly access the property value in the sandbox environment to obtain the handle of the function to be executed.

[0066] Step S106, obtaining the execution result of the code file from the code platform;

[0067] Specifically, you can set a callback function or listener on the code platform so that after executing the specified JavaScript code, the corresponding execution result is returned. This callback function or listener is usually identified by a name, which needs to be passed to the code platform when executing the code and registered in the corresponding event handler. Wait for the code platform to return the execution result. After the execution is completed, the code platform will automatically trigger the callback function or listener and pass the execution result as a parameter to them.

[0068] An embodiment of the present invention provides a method for calling code through an intermediate script, and the method for calling code through an intermediate script includes: responding to a program execution request of a Java platform and obtaining program parameters; wherein the program parameters include: a code file to be executed, a method to be executed and method parameters; transmitting the program parameters to the intermediate script, so that the intermediate script calls the code file on a code platform based on the program parameters to obtain an execution result; obtaining the execution result of the code file from the code platform; and running the intermediate script through Node.js to effectively improve the execution efficiency of JavaScript code and the supported language features, while supporting higher versions of JavaScript, thereby improving the compatibility and flexibility of the code and improving the user experience.

[0069] Embodiment 2

[0070] Based on the above embodiment, the embodiment of the present invention provides a method for calling code through an intermediate script, which is implemented on the basis of the above invention embodiment, wherein first, a js execution code file to be called is prepared. The file example is as follows:

[0071]

[0072]

[0073] See also Figure 2 The flowchart of another method for calling code through an intermediate script provided by an embodiment of the present invention is shown, and the method includes the following steps:

[0074] Step S202, responding to the program execution request of the Java platform and obtaining program parameters;

[0075] Specifically, when the Java language is triggered to execute the logic of the JavaScript code file, the program parameters are obtained.

[0076] Step S204, converting the format of the method parameter into a string format;

[0077] Specifically, since js is called from Java across platforms, the object details of the two languages ​​are different. However, the text format of the string is universal, so the method parameters are converted from the Java object format to the JSON string format.

[0078] Step S206, determine whether the operating environment of the intermediate script is a Windows environment; if so, execute step S208, transfer the program parameters to the intermediate script based on the first program; if not, execute step S210, transfer the program parameters to the intermediate script based on the second program; wherein the first program and the second program are both used to start the Node.js process, the first program runs in a Windows environment, and the second program runs in a MacOS or Linux environment.

[0079] Specifically, 3. Differentiate the system environment, use the node command that executes the command line through Java, and execute node, intermediate scripts, js code files to be executed, methods to be executed, and method parameters.

[0080] Step S208, transmitting the program parameters to the intermediate script based on the first program;

[0081] In the Windows environment, the following code is used as an example:

[0082] Runtime.getRuntime().exec("node intermediate script to be executed js code file to be executed method parameter");

[0083] Specifically, this code is a Java program example, which is used to run the Node.js intermediate script locally and pass the JavaScript code file to be executed, the function name to be executed, and method parameters to it.

[0084] Further, first, we use the getRuntime() method of the Java built-in Runtime class to obtain the Runtime object. Then, we call the exec() method and pass the Shell command to be executed as a parameter to it in order to run the corresponding Node.js intermediate script locally. Specifically, this Shell command contains three parameters: node: represents the command to be executed, that is, the Node.js interpreter. Intermediate script: represents the path or file name of the Node.js intermediate script to be run. js code file to be executed, method to be executed, method parameters: represents the parameters to be passed to the intermediate script, that is, the JavaScript code file to be executed, the function name to be executed, and the method parameter list. In the intermediate script, the corresponding JavaScript code can be called according to these parameters and the execution result can be returned. It should be noted that when using the exec() method to execute external commands, special care should be taken with security issues.

[0085] Step S210, transmitting the program parameters to the intermediate script based on the second program;

[0086] In a Mac or Linux environment, for example, the following code is used to execute:

[0087] ProcessBuilder(" / bin / sh","-c"," / usr / local / bin / node intermediate script to be executed js code file to be executed method method parameter").start();

[0088] Specifically, this code is a Java program example, which is used to run the Node.js intermediate script locally and pass the JavaScript code file to be executed, the function name to be executed, and method parameters to it.

[0089] Further, first, we create a ProcessBuilder object and pass the Shell command to be executed as a parameter to it. Specifically, this Shell command contains four parameters: / bin / sh: indicates the Shell interpreter to be executed, usually / bin / sh or / bin / bash. -c: indicates that the subsequent commands are executed in command line mode. / usr / local / bin / node: indicates the command to be executed, that is, the path of the Node.js interpreter (here the default is / usr / local / bin / node). Intermediate script, js code file to be executed, method to be executed, method parameters: indicates the parameters to be passed to the intermediate script, that is, the JavaScript code file to be executed, the function name to be executed, and the method parameter list. In the intermediate script, the corresponding JavaScript code can be called according to these parameters and the execution result is returned. Then, we call the start() method to start a new process and execute the specified Shell command through the process. During the execution process, the Java program will block and wait for the process to return the execution result until the process ends or times out.

[0090] The node intermediate script to be executed in the above execution command, the js code file to be executed, the method to be executed, and the method parameters, use node to execute the content of the intermediate script; the execution naming passes three parameters to the intermediate script: the js code file to be executed, the method to be executed, and the method parameters.

[0091] Step S212, converting the format of the method parameters in the program parameters into an object format corresponding to the code platform;

[0092] Specifically, the third parameter (method parameter) is restored from the json string to the js object format (the object format is converted into a json string in step S204), which is used to pass the object parameter of the js language to the subsequent method to be executed.

[0093] Step S214, the code platform calls the code file to obtain the execution result;

[0094] Specifically, get the first parameter (js code file to be executed), load the js code file to be executed by require (js code file to be executed); get the second parameter (method to be executed), know the method to be executed; since the file to be executed is loaded, the method to be executed is known, and the parameters of the method to be executed are converted into the original object format. Then you can directly call the method and parameters to call the target js code file logic. When the called method is executed, get the execution result.

[0095] If the execution result is not empty, the method further includes: printing the execution result back to the Java platform so that the Java platform outputs the execution result. Since the execution result needs to be passed back to the Java code and the object cannot be passed, the object is converted into a json string for transmission.

[0096] Step S216, replacing the first identifier of the execution result with the second identifier;

[0097] Specifically, the first identifier is '\n', and the second identifier is '\\n'. In order to handle the compatibility issue of '\n' on different platforms during the transmission process, the '\n' in the json string in step S214 is replaced with '\\n';

[0098] Step S218, use console.log to return the print output;

[0099] Specifically, use console.log to add the json string of the final execution result to the output stream of the command line.

[0100] Step S220, replacing the second identifier in the execution result received by the Java platform with the first identifier;

[0101] Specifically, the output stream of the intermediate script execution is obtained. The execution result of the intermediate script in step S218 is read to obtain the json string result of the javascript execution. In order to handle the compatible processing of '\n' in step S216, the '\\n' in the execution result json string in step S218 is replaced with '\n'.

[0102] Step S222, converting the format of the execution result into an object format corresponding to the Java platform;

[0103] Specifically, the string processed with '\n' is converted into an object, which is the result of the JavaScript code execution.

[0104] Step S224, output the execution result.

[0105] The existing solution is run in the Java virtual machine, while the Node.js used in this solution is an independent runtime environment based on the V8 engine. This means that the performance, memory management, modular mechanism and other aspects of the two are different. Therefore, the method for calling code through an intermediate script provided by the embodiment of the present invention can effectively improve the execution efficiency of JavaScript code and the supported language characteristics, while supporting higher versions of JavaScript, improving the compatibility and flexibility of the code, and supporting the use of related js libraries. In addition, the method can also avoid some security vulnerabilities in the Java virtual machine and enhance the security of the code.

[0106] The method for calling code through an intermediate script provided in an embodiment of the present invention executes js scripts through Node.js, thereby achieving an execution effect that is better than that of Java language engines such as Oracle's Nashorn (a lightweight and high-performance JavaScript runtime environment based on JVM) and Mozilla's Rhino (a Java language engine), solving the performance and language characteristic problems existing in existing solutions, and also supporting unlimited JavaScript versions.

[0107] In particular, the execution of other scripting languages ​​such as Python can provide similar intermediate scripts to enable Java to execute the corresponding language code files.

[0108] Embodiment 3

[0109] Corresponding to the above method embodiment, the embodiment of the present invention provides a device for calling code through an intermediate script, see Figure 3 The schematic diagram of the structure of a device for calling a code through an intermediate script provided by an embodiment of the present invention is shown, and the device for calling a code through an intermediate script includes:

[0110] The program parameter acquisition module 310 is used to respond to the program execution request of the Java platform and acquire program parameters; wherein the program parameters include: the code file to be executed, the method to be executed and the method parameters.

[0111] The program parameter transmission module 320 is used to transmit the program parameters to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain the execution result.

[0112] The result acquisition module 330 is used to acquire the execution result of the code file from the code platform.

[0113] In some preferred embodiments of the present invention, the device for calling code through an intermediate script also includes: a first format conversion module, which is used to convert the format of the method parameter in the program parameter into a string format if the format of the method parameter in the program parameter is not a string format.

[0114] In some preferred embodiments of the present invention, the program parameter transmission module 320 is used to determine whether the operating environment of the intermediate script is a Windows environment; if so, the program parameters are transmitted to the intermediate script based on the first program; if not, the program parameters are transmitted to the intermediate script based on the second program; wherein the first program and the second program are both used to start the Node.js process, the first program runs in a Windows environment, and the second program runs in a MacOS or Linux environment.

[0115] In some preferred embodiments of the present invention, the second format conversion module is used to convert the format of the method parameters in the program parameters into an object format corresponding to the code platform.

[0116] In some preferred embodiments of the present invention, the device for calling code through an intermediate script also includes: a result returning module, which is used to print the execution result back to the Java platform if the execution result is not empty, so that the Java platform outputs the execution result.

[0117] In some preferred embodiments of the present invention, the format conversion module is used to convert the format of the execution result into an object format corresponding to the Java platform if the execution result is not in a string format.

[0118] In some preferred embodiments of the present invention, the device for calling code through an intermediate script also includes: a first identifier conversion module, used to replace the first identifier in the execution result with a second identifier; a second identifier conversion module, used to replace the second identifier in the execution result received by the Java platform with the first identifier.

[0119] The embodiment of the present invention provides a device for calling code through an intermediate script, which improves the problem that the Java execution engine cannot support all JavaScript language features, cannot use related js libraries, has low code execution performance, and supports older JavaScript versions when executing JavaScript language.

[0120] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device for calling code through an intermediate script described above can refer to the corresponding process in the aforementioned embodiment of the method for calling code through an intermediate script, and will not be repeated here.

[0121] Embodiment 4

[0122] The embodiment of the present invention also provides an electronic device for executing a method for calling a code through an intermediate script; see Figure 4 The structural diagram of an electronic device provided by an embodiment of the present invention is shown, and the electronic device includes a memory 400 and a processor 401, wherein the memory 400 is used to store one or more computer instructions, and the one or more computer instructions are executed by the processor 401 to implement the above-mentioned method of calling code through an intermediate script.

[0123] Further, Figure 4 The electronic device shown further includes a bus 402 and a communication interface 403 , and the processor 401 , the communication interface 403 and the memory 400 are connected via the bus 402 .

[0124] The memory 400 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 403 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 402 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0125] The processor 401 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 401. The above processor 401 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 400, and the processor 401 reads the information in the memory 400 and completes the steps of the method of the above embodiment in combination with its hardware.

[0126] An embodiment of the present invention further provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions prompt the processor to implement the above-mentioned business recommendation method. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0127] The computer program product of the method, device and electronic device for calling code through an intermediate script provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method in the previous method embodiment. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0128] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and / or device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0129] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0130] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0131] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for calling code through an intermediate script, characterized in that: The method of calling the code through the intermediate script includes: Responding to a program execution request of a Java platform, obtaining program parameters; wherein the program parameters include: a code file to be executed, a method to be executed, and method parameters; The program parameters are transmitted to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain an execution result; The execution result of the code file is obtained from the code platform.

2. The method for calling code through an intermediate script according to claim 1, characterized in that: After the step of responding to the program execution request of the Java platform and obtaining program parameters, the method of calling the code through the intermediate script further includes: If the format of the method parameter in the program parameter is not a string format, the format of the method parameter is converted to a string format.

3. The method for calling code through an intermediate script according to claim 1, characterized in that: The step of transferring the program parameters to the intermediate script comprises: Determine whether the operating environment of the intermediate script is a Windows environment; If yes, transferring the program parameters to the intermediate script based on the first program; If not, transmitting the program parameters to the intermediate script based on a second program; The first program and the second program are both used to start the Node.js process, the first program runs in a Windows environment, and the second program runs in a MacOS or Linux environment.

4. The method for calling code through an intermediate script according to claim 1, characterized in that: After the step of transmitting the program parameters to the intermediate script, the method further comprises: The format of the method parameters in the program parameters is converted into an object format corresponding to the code platform.

5. The method for calling code through an intermediate script according to claim 1, characterized in that: If the execution result is not empty, the method further includes: The execution result is printed and returned to the Java platform, so that the Java platform outputs the execution result.

6. The method for calling code through an intermediate script according to claim 5, characterized in that: If the execution result is not in a string format, the step of printing the execution result back to the Java platform and outputting it comprises: Printing the execution result back to the Java platform; Converting the format of the execution result into an object format corresponding to the Java platform; Output the execution result in a converted format.

7. The method for calling code through an intermediate script according to claim 5, characterized in that: If the execution result includes the first identifier, the step of printing the execution result back to the Java platform and outputting the result includes: Replacing the first identifier in the execution result with a second identifier; Printing the execution result replaced with the second identifier and returning it to the Java platform; replacing the second identifier in the execution result received by the Java platform with the first identifier; Output the execution result replaced by the first identifier.

8. A device for calling code through an intermediate script, characterized in that: The device for calling the code through the intermediate script includes: A program parameter acquisition module is used to respond to a program execution request of the Java platform and acquire program parameters; wherein the program parameters include: a code file to be executed, a method to be executed, and method parameters; A program parameter transmission module, used for transmitting the program parameters to the intermediate script, so that the intermediate script calls the code file on the code platform based on the program parameters to obtain an execution result; The result acquisition module is used to obtain the execution result of the code file from the code platform.

9. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores computer executable instructions that can be executed by the processor, and the processor executes the computer executable instructions to implement the method of calling a code through an intermediate script as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are called and executed by the processor, the computer-executable instructions prompt the processor to implement the method for calling code through an intermediate script as described in any one of claims 1 to 7.