CN107766119A - A kind of processing method of scripting language interface, device and equipment - Google Patents
A kind of processing method of scripting language interface, device and equipment Download PDFInfo
- Publication number
- CN107766119A CN107766119A CN201610693286.5A CN201610693286A CN107766119A CN 107766119 A CN107766119 A CN 107766119A CN 201610693286 A CN201610693286 A CN 201610693286A CN 107766119 A CN107766119 A CN 107766119A
- Authority
- CN
- China
- Prior art keywords
- function
- local
- program
- script language
- calling
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/455—Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
- G06F9/45504—Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
- G06F9/45529—Embedded in an application, e.g. JavaScript in a Web browser
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Devices For Executing Special Programs (AREA)
- Stored Programmes (AREA)
Abstract
The invention provides a kind of processing method of scripting language interface, device and equipment, wherein method includes:Nation method is registered, obtains nation method storehouse, the nation method storehouse includes nation method and registration function;Using the registration function, the nation method storehouse is loaded;Calling of the script-language program to nation method is realized by first function, the first function is the function for the calling nation method that scripting language interface provides to script-language program.The scripting language interface that the present invention realizes actually has taken out the interface mutually called between script-language program and local program, the variation of the abstract virtual machine and its version that cause local program to be concerned about script of this calling interface, the workload of developer is reduced, substantially increases the productivity of developer.
Description
[ technical field ] A method for producing a semiconductor device
The invention relates to the technical field of computer application, in particular to a processing method, a processing device and processing equipment of a scripting language interface.
[ background of the invention ]
When a developer develops an application, some functions cannot be developed completely by using the JavaScript language. For example, it is necessary to adapt to the platform-related base program capability, and it is desirable to utilize a local method library, and the developed functions are more demanding in performance. At this point, the developer needs to use a local method (e.g., C/C + + method) to perform these functions. A common way is to write JavaScript local methods using a JavaScript local call interface.
Currently, different JavaScript virtual machines provide different local method interfaces. These different local method interfaces force programmers to write, maintain, and publish multiple versions of local method libraries for a particular virtual machine. That is, when a developer develops a C/C + + module locally, the interface related to the virtual machine is used to interact with JavaScript. Therefore, Native development is bound to the virtual machine, and a developer must modify and compile the Native module again at any time due to the change of the virtual machine. This undoubtedly increases the developer's heavy workload, limiting the ability of Native development.
[ summary of the invention ]
In view of this, the present invention provides a method, an apparatus, and a device for processing a scripting language interface, so as to reduce the workload of a developer and improve the capability of Native development.
The specific technical scheme is as follows:
the invention provides a processing method of a scripting language interface, which comprises the following steps:
registering a local method to obtain a local method library, wherein the local method library comprises the local method and a registration function;
loading the local method library by using the registration function;
and calling the local method by the script language program through a first function, wherein the first function is a function which is provided by the script language interface to the script language program and calls the local method.
According to a preferred embodiment of the invention, the method further comprises:
and calling the script language method by the local program through a second function, wherein the second function is a function for calling the script language method provided by the script language interface to the local program.
According to a preferred embodiment of the present invention, the registering the local method to obtain the local method library includes:
acquiring a local method and the registration function;
and compiling the acquired local method and the registration function into a local method library.
According to a preferred embodiment of the present invention, loading the local method library using the registration function includes:
the script language interface is used for calling a loading function provided by a script language program;
and calling the registration function and making the local method in the local method library visible to the script language program.
According to a preferred embodiment of the present invention, before the calling the registration function, the method further includes:
judging whether the local method library exists or not according to the address of the local method library;
if yes, continuing to execute the calling of the registration function; otherwise, returning the prompt information that the local method library does not exist, and ending the current local method library loading process.
According to a preferred embodiment of the present invention, making the local methods in the local method library visible to the script language program comprises:
and transmitting the visible preset object of the script language program to the registration function, and setting the local method in the local method library into the preset object by the registration function so that the script language program can obtain the local method through the preset object.
According to a preferred embodiment of the present invention, the invoking of the local method by the first function implementing scripting language program includes:
acquiring an instruction for calling a local method from a script language program;
and calling a first function, wherein the first function is a function for calling the local method provided by the scripting language interface to the scripting language program, and the local method information to be called is transferred to the local program through the first function, so that the local program executes the corresponding local method according to the local method information to be called.
According to a preferred embodiment of the present invention, the calling of the script language method by the local program through the second function includes:
acquiring an instruction for calling a script language method from a local program;
and calling a second function, wherein the second function is a function for calling the script language method provided by the script language interface to the local program, and the information of the script language method to be called is transmitted to the script language program through the second function, so that the script language program executes the corresponding script language method according to the information of the script language method to be called.
According to a preferred embodiment of the invention, the method further comprises:
the called local method processes data transmitted to the local program by the script language program through a third function, wherein the third function is a function of operation data provided by the script language interface to the local program; and the number of the first and second groups,
and calling a fourth function, wherein the fourth function is a function which is provided by the scripting language interface to the local program and returns data to the scripting language program, and the processing result is returned to the scripting language program through the fourth function.
According to a preferred embodiment of the invention, the function of operational data comprises at least one of:
a function for judging the type of the image,
the function used for the conversion of the data,
and aiming at the operation function of the data type corresponding to the local program provided by the script language type.
According to a preferred embodiment of the present invention, when the script language program calls the local method, the on-stack address or the on-heap address of the local method stores the on-heap address of the script language object.
According to a preferred embodiment of the present invention, the scripting language object includes data passed by the scripting language program to a local program.
According to a preferred embodiment of the invention, the method further comprises:
a script language object declared as a global variable is referenced using a global index interface provided by the script language interface;
and if the memory release instruction aiming at the script language object declared as the global variable is obtained, canceling the reference mark of the global index interface to the script language object.
According to a preferred embodiment of the invention, the method further comprises:
and when the behavior execution of the local program application program is abnormal, calling a function which is provided by the scripting language interface for the local program and throws the abnormality to the scripting language program so as to throw the abnormality to the scripting language program.
The invention also provides an apparatus comprising
A memory including one or more programs;
one or more processors, coupled to the memory, that execute the one or more programs to implement:
registering a local method to obtain a local method library, wherein the local method library comprises the local method and a registration function;
loading the local method library by using the registration function;
and calling the local method by the script language program through a first function, wherein the first function is a function which is provided by the script language interface to the script language program and calls the local method.
The invention also provides a processing device of the script language interface, which comprises:
the registration unit is used for registering the local method to obtain a local method library, and the local method library comprises the local method and a registration function of the local method;
a loading unit for loading the local method library;
and the calling unit is used for providing a first function and a second function, the first function is a function which is provided for the script language program and calls the local method, and the second function is a function which is provided for the local program and calls the script language method.
An operating system comprises a scripting language interface, and the scripting language interface comprises the device.
A method for calling based on a scripting language interface, the method comprising:
the method comprises the steps that a script language program calls a local method through a first function, wherein the first function is a function which is provided by a script language interface for calling the local method; the script language interface registers a local method in advance and loads a local method library, wherein the local method library comprises the local method and a registration function.
A method for calling based on a scripting language interface, the method comprising:
the local program calls the script language method through a second function, wherein the second function is a function which is provided by the script language interface for calling the script language method to the local program; the script language interface registers a local method in advance and loads a local method library for realizing the calling of a script language program to the local method, wherein the local method library comprises the local method and a registration function.
A scripting language interface is used for realizing the calling of a scripting language program to a local method and realizing the calling of the local program to the scripting language method; wherein,
the script language interface registers a local method and loads a local method library, wherein the local method library comprises a local method and a registration function; and
the scripting language interface provides a first function for calling the local method to the scripting language program and provides a second function for calling the scripting language method to the local program.
According to the technical scheme, by applying the mode provided by the invention, the script language interface can utilize the calling function provided by the script language interface to call the local program after the local method library obtained by registering the local method is loaded. That is to say, the scripting language interface actually abstracts the interface called by the scripting language program to the local program, and the abstraction of the calling interface enables the local program not to adapt to the virtual machine of the scripting language and the change of the version of the virtual machine, so that even if the version of the virtual machine changes, the local program does not need to be modified and recompiled, the workload of a developer is reduced, and the productivity of the developer is greatly improved.
[ description of the drawings ]
Fig. 1 is a schematic diagram of an environment of a development system in which a JavaScript local interface provided in the embodiment of the present invention is located;
FIG. 2 is a flow chart of a method provided by an embodiment of the present invention;
fig. 3 is a registration flowchart of a Native method according to an embodiment of the present invention;
FIG. 4 is a flowchart of a method for loading Native libraries according to an embodiment of the present invention;
fig. 5 is an abstract diagram of a JavaScript object address provided in the embodiment of the present invention;
fig. 6 is a schematic diagram of functions provided by JSNI according to an embodiment of the present invention;
FIG. 7 is a block diagram of an apparatus according to an embodiment of the present invention;
fig. 8 is a block diagram of an apparatus according to an embodiment of the present invention.
[ detailed description ] embodiments
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the examples of the present invention and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be understood that the term "and/or" as used herein is merely one type of association that describes an associated object, meaning that three relationships may exist, e.g., a and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
The scripting language program related to the invention can be a JavaScript program, a VBScript program and other programs written by adopting a scripting language, the JavaScript program is taken as an example to describe in the embodiment of the invention, and the corresponding scripting language interface is taken as an example to describe the JavaScript local interface. The implementation for the VBScript program is similar. A Native program refers to a program written in a non-Java language (e.g., C language, C + + language).
In order to facilitate understanding of the present invention, a development system environment in which the JavaScript local interface provided by the present invention is located is first described. As shown in fig. 1, the JavaScript local interface (hereinafter abbreviated as JSNI) is located between the JavaScript program and the Native program, and interaction between the JavaScript program and the Native program is realized through the JSNI. The JSNI abstractly encapsulates the virtual machine interface so that developers do not need to be concerned about which virtual machine or which specific virtual machine version an application runs on.
Fig. 2 is a flowchart of a method provided in an embodiment of the present invention, and as shown in fig. 2, the method may include the following steps:
in 201, a Native method is registered to obtain a Native library.
When Native developers perform Native development, the Native methods to be used need to be registered, and the registration process is actually to compile the Native methods into the Native library and provide registration functions for subsequent loading of the Native library. The Native method can be regarded as an interface for calling non-Java code by Java, and the method is realized by non-Java language, such as C or C + +. "library" refers to a collection of compiled code and data that is available to other programs, and is typically loaded before or at the time of startup of an executable program. The Native library related in the embodiment of the invention is a Native method library which can be used by other programs, and in order to make the Native method visible to the JavaScript program when the Native library is loaded, a registration function is further included in the Native library.
The registration process of the Native method can be as shown in fig. 3, and the process can include the following steps:
in 301, Native methods written by a developer and registration functions (register _ methods) of the Native methods are obtained.
In the embodiment of the invention, the parameter type of the JSNI method can be predefined, so that a developer can write a Native method according to the parameter type of the JSNI method, and the corresponding function in the developed Native application is realized through the written Native method. That is, only one set of uniform parameter types needs to be provided, so that developers can write according to the parameter types without writing specific virtual machines.
In 302, the obtained Native method and the corresponding registration function thereof are compiled into a Native library for subsequent calls of the javascript program. Wherein the Native library may be stored at a specified address.
As an example, assuming that the developer needs to register N Native methods, named TestValue1, TestValue2, TestValue3, … …, TestValue en, the developer may first write methods TestValue1, TestValue2, TestValue3, … …, TestValue en according to the parameter type of the JSNI method defined in advance, and then designate the names of functions to be registered as "TestValue 1, TestValue2, TestValue3, … …, TestValue en" through register _ methods, respectively. Then, register functions register _ methods of the written methods TestValue1, TestValue2, TestValue3, … …, TestValue en and Native methods are compiled into Native libraries.
At 202, Native libraries are loaded.
In the embodiment of the present invention, the JSNI may provide a Load function (Load _ Native) to the JavaScript program. When the loading function is called by a JavaScript program, a Native library is loaded. The process of loading Native libraries can be as shown in fig. 4, and can include the following steps:
in 401, a load function is called.
In the process of developing the Native application, a developer needs to load a Native library, so that a Native method in the Native library can be visible to the JavaScript program, and can be called by the JavaScript program later. If a loading instruction is received from a developer, the JavaScript program calls a loading function provided by JNI.
At 402, judging whether the Native library exists according to the address of the Native library, if not, executing 403, returning to the prompting information that the Native library does not exist, and ending the Native loading flow. If so, then 404 is performed.
At 404, a register function (register _ methods) of the Native method is called to make the Native method visible to the JavaScript program and Native library loading is complete.
In this step, when the Native library is loaded by the JavaScript program, if the Native library exists, the Native method register function is automatically called, and an OBJECT visible to the JavaScript program, for example, OBJECT _ execute, is transferred to the register function. The registration function sets the Native method in the Native library into the OBJECT _ EXPORT OBJECT, and the JavaScript program can obtain the Native method through the OBJECT _ EXPORT OBJECT at the moment, so that the Native method is visible to the JavaScript program.
In 203, the Native method is called by the JavaScript program through the function for calling the Native method provided by the JSNI to the JavaScript program, and the JavaScript method is called by the Native program through the function for calling the JavaScript method provided by the JSNI to the Native program.
In the embodiment of the invention, the JSONI provides a function (call _ Native) for calling a Native method for the JavaScript program. The JSNI provides the Native program with a function (call _ methods) that calls JavaScript methods.
The method for calling the Native method by the JavaScript program through the JNI function for calling the Native method comprises the following steps:
firstly, an instruction for calling a certain Native method is obtained from a JavaScript program, a call _ Native function is called, and information of the Native method to be called is transferred to the Native program through the call _ Native function. The instruction for calling a certain Native method, which is obtained from the JavaScript program, may be obtained from a developer, or may be obtained from an application program, for example, the JavaScript application program needs to call a certain Native method during execution.
Then, the Native program executes the corresponding Native method according to the Native method information to be called.
Because some methods (for example, some methods including complex calculation) cannot be realized in the JavaScript program, developers need to realize the methods in the Native program, and then, the Native method can be called in the JavaScript program by the technical solution provided by the present application.
Through a function provided by the JSNI for calling the JavaScript method to the Native program, the implementation of calling the JavaScript method by the Native program may include the following steps:
firstly, an instruction for calling a JavaScript method is obtained from a Native program, a call _ method function is called, and information of the JavaScript method to be called is transmitted to the JavaScript program through the call _ method function. The instruction for calling a certain JavaScript method obtained from the Native program is usually obtained from the Native application program, and for example, the Native application program needs to call back a certain JavaScript method in the execution process. In this case, the JavaScript method that Native requires callback may be included in the Native method as a parameter in advance.
Then, the JavaScript program executes the corresponding JavaScript method according to the JavaScript method information to be called.
The method calling process may involve data transmission and processing, for example, when a JavaScript program calls a complicated calculation method of a Native program, it is necessary to transmit data required for calculation to the Native program at the same time.
In the embodiment of the invention, the data transmission from the JavaScript program to the Native program is realized in the process of calling the Native method. In the embodiment of the present invention, the function to be transferred is transferred as a parameter for calling a Native method, and is implemented as a JavaScript object. In order to enable a developer to design the bottom program implementation of the JavaScript virtual machine without concern during data transmission, in the embodiment of the invention, the JavaScript object address can be abstractly encapsulated, so that only the JavaScript object address needs to be transmitted in the parameter transmission process, and the data itself does not need to be transmitted.
Specifically, when the JavaScript program calls the Native method, as shown in fig. 5, the heap address 504 of the JavaScript object 506 is saved at the heap address 502 of the Native method, that is, the heap address 504 points to the JavaScript object 506. The Native program acquires the heap address 504 of the JavaScript object 506 according to the stack address 502 of the Native method, and further acquires the JavaScript object 506 pointed by the Native program, thereby acquiring data transmitted from the JavaScript program. The on-stack address 502 of the Native method may also be an on-heap address, and the difference is that the life cycle of the on-stack address of the Native method follows the creation and deletion of a local stack, while the on-heap address of the Native method needs to be explicitly set and allocated.
For data transfer from a Native program to a JavaScript program, JSNI provides the Native program with a function (return _ data) to return data to the JavaScript program. Data can be transferred from a Native program to a JavaScript program by calling the return _ data function, and the data to be transferred only needs to be used as a parameter of the return _ data function.
In addition, JSNI also provides Native programs with functions to manipulate data (operation _ data). The operation _ data function includes a series of data-related interfaces, which may include but are not limited to:
the Is interface, i.e. Is function (where Is a wildcard, the same applies hereinafter), for determining the type, for example, the IsObject Is used to determine whether the data Is of the object type, the IsNumber Is used to determine whether the data Is of the digital type, and so on.
To interfaces for data transformation, i.e. To generic functions, such as totint, etc.
In the embodiment of the invention, data type abstractions corresponding to Native programs can be provided for types of JavaScript languages, for example, JsValue, jsdnumber, jsbollean, jsbject, jsfusion, JsString, jstydatrary, and the like, and corresponding operation interfaces can be provided for the abstract data types.
JsValue provides a type definition interface of parameter types, so that all parameter types are inherited from JsValue. JsValue is the top-most program type, containing other data types.
JsNumbe is used to define the number type.
JsBoolean is used to define data types of yes (True) and no (False).
JsObject provides functional interfaces for judging and setting properties, setting and deleting prototypes, setting and acquiring objects, setting internal pointers and the like.
JsFunction provides an interface for building and calling JavaScript methods from Native methods.
JsString provides the method for acquiring a character String of a char type or a 16-bit type which can be identified by a Native program from a String type of a JavaScript program.
JsTypedArray provides an interface to get a data pointer from TypedArray type data of a JavaScript program. The pointer that the developer can get through this interface modifies the data in the array and returns to JavaScript.
The data types may be declared as local variables or may be declared as global variables. As for the JavaScript object, the system automatically adopts a garbage collection mechanism to carry out garbage collection on the JavaScript object. Garbage collection is an automatic memory management mechanism: when the JavaScript object is created, the system allocates a memory for the JavaScript object; when the JavaScript object is no longer referenced, its allocated memory is freed. In the embodiment of the invention, in order to ensure that the global variable is not garbage recycled, the JSNI provides a global index interface for marking that the JavaScript object declared as the global variable is always referred to so as to prevent garbage recycling. The JavaScript object declared as the global variable needs to be explicitly released, that is, released through a special instruction, and only if a memory release instruction for the JavaScript object declared as the global variable is obtained, the reference mark of the global index interface for the JavaScript object is cancelled, so that the memory occupied by the JavaScript object is released.
In addition, in the embodiment of the invention, the JSNI also provides a function (throw _ exception) for throwing exception to the JavaScript program to the Native program. When the behavior execution of the Native program application program is abnormal, such as a parameter type error, an array length error and the like of the incoming Native program, a throw _ exception function is called to throw the abnormality to the JavaScript program.
The method provided by the foregoing embodiment is implemented by the foregoing JSNI, and the execution subject may be a device disposed in the JSNI, and the device may be embodied as an application running in the terminal, or may also be embodied as a functional unit such as a plug-in or Software Development Kit (SDK) in the terminal application, which is not particularly limited in this embodiment of the present invention.
In summary, as shown in fig. 6, the function provided by JSNI to JavaScript program includes: a Load function (Load _ Native) and a function calling a Native method (call _ Native).
The functions provided by the JSNI to the Native program include: a register function (register _ methods) of a Native method, a function (call _ methods) of calling a JavaScript method, a function (operation _ data) of operating data, a function (return _ data) of returning data to a JavaScript program, and a function (throw _ exception) of throwing an exception to the JavaScript program.
Accordingly, based on the method, the Native method can be called in the JavaScript program based on the JavaScript local interface. Specifically, the JavaScript program calls the Native method through a function provided by the JavaScript local interface to the JavaScript program, which calls the Native method. The JavaScript local interface registers a Native method in advance and loads a Native library, wherein the Native library comprises a Native method and a registration function. The JavaScript local interface is implemented as described in the above embodiments.
Based on the method, the Native program can call the JavaScript method based on the JavaScript local interface. Specifically, the Native program calls the JavaScript method through a JavaScript local interface to a function for calling the JavaScript method provided by the Native program. The JavaScript local interface registers a Native method in advance and loads a Native library for realizing the calling of the JavaScript program to the Native method, wherein the Native library comprises the Native method and a registration function.
In the Native program, the called Native method can process the data transmitted to the Native program by the JavaScript program through a function of operation data provided by the JavaScript local interface to the Native program, and returns the processing result to the JavaScript program through a function of returning the data to the JavaScript program provided by the JavaScript local interface to the Native program.
The following simulates the developer's development process, to give a simple example:
the developer first writes a Native method and a Native method registration function (register _ methods), and the JSNI acquires the Native method and Native method registration function (register _ methods), and then compiles the Native method and Native method registration function into a Native library (Native.
The developer sends a loading instruction through the JavaScript program, and the running platform of the JavaScript program, namely the virtual machine, transmits the instruction to the JNI. The JSNI calls the Load function (Load _ Native). The Load _ Native calls register _ methods, passing OBJECT _ EXPORT to register _ methods. The register _ methods sets the Native methods in the Native library into the OBJECT _ EXPORT OBJECT, so that the JavaScript can call the Native methods through the OBJECT _ EXPORT OBJECT, that is, the Native methods are already visible to the JavaScript.
Then, the developer can send an instruction for calling a certain Native method to the JavaScript program, the JavaScript program transmits the instruction to the JSNI through the virtual machine, the JSNI calls a call _ Native function, the call _ Native function transmits information of the Native method to be called to the Native program, and the Native program executes the corresponding Native method.
If the Native method needs to transmit data, the data to be transmitted is used as a JavaScript object, and the on-stack address of the JavaScript object is stored in the on-stack address of the Native method. And the Native program acquires the on-heap address of the JavaScript object according to the on-stack address of the Native method, and further acquires the JavaScript object, namely the transmitted data.
After the corresponding Native method is executed to process the transmitted data, and the obtained processing result is transmitted to the JNI, the JNI can return to the JavaScript program through the virtual machine by calling a function (return _ data) of returning data.
If no JSONI exists, the Native program needs to be directly interacted with the JavaScript virtual machine, so that mutual calling between the Native program and the JavaScript program is realized, the application program in the Native program needs to be bound with the virtual machine, and a method interface, a data structure and the like used when the Native application program is written also need to be bound with the virtual machine. When the version of the virtual machine changes, the method interface and the data structure may also change, and the Native application program also needs to be modified and recompiled, which is time-consuming and labor-consuming. In the embodiment of the invention, the Native program and the JavaScript virtual machine are isolated by JSIN, and the interface for mutual calling between the Native program and the JavaScript program is abstracted, so that the Native program does not need to concern about the change of the virtual machine and the version thereof, the Native application program is unrelated to the virtual machine, the Native application program is not influenced even if the version of the virtual machine is changed, the Native application program does not need to be modified and recompiled, and the productivity of a developer is greatly improved.
The above is a description of the method provided by the present invention, and the following is a description of the apparatus provided by the present invention with reference to the examples.
Fig. 7 is a structural diagram of an apparatus for implementing JSNI involved in the above method according to an embodiment of the present invention. As an embodiment, the JSNI may be preset in an operating system, and is used for implementing mutual call between the JavaScript program and the Native program. As shown in fig. 7, the apparatus may include: the registering unit 01, the loading unit 02, and the calling unit 03 may further include (not shown in the figure): the device comprises a transfer unit, a marking unit and an exception handling unit. The main functions of each constituent unit are as follows:
the registration unit 01 is responsible for registering the Native methods to obtain Native libraries, which include registration functions of the Native methods and the Native methods. Specifically, the registration unit 01 may obtain a Native method written by a developer and a registration function of the Native method; and compiling the acquired Native method and the registration function to a Native library.
The loading unit 02 is responsible for loading Native libraries. Specifically, the loading unit 02 may call a registration function of a Native method, and make the Native method in the Native library visible to the JavaScript program, that is: and transmitting a preset OBJECT (such as an OBJECT _ EXPORT OBJECT) visible by the JavaScript program to the registration function, and setting a Native method in the Native library into the preset OBJECT by the registration function so that the JavaScript program can obtain the Native method through the preset OBJECT.
The calling unit 03 is responsible for providing a first function and a second function, the first function is a function provided for the JavaScript program to call the Native method, and the second function is a function provided for the Native program to call the JavaScript method. Calling the Native method by the JavaScript program through a first function; and realizing the calling of the Native program to the JavaScript method through the second function.
When the calling unit 03 calls the Native method by the JavaScript program, the following steps may be specifically executed: acquiring an instruction for calling a Native method from a JavaScript program; and calling a function for calling the Native method, which is provided by the JavaScript local interface to the JavaScript program, and transferring the information of the Native method to be called to the Native program through the function, so that the Native program executes the corresponding Native method according to the information of the Native method to be called.
When the calling unit 03 realizes the calling of the Native program to the JavaScript method, it may specifically execute: acquiring an instruction for calling a JavaScript method from a Native program; and calling a function for calling the JavaScript method provided by the JavaScript local interface to the Native program, and transferring the information of the JavaScript method to be called to the JavaScript program through the function, so that the JavaScript program executes the corresponding JavaScript method according to the information of the JavaScript method to be called.
The transfer unit is responsible for storing the on-heap address of the JavaScript object on the on-stack address or on-heap address of the Native method when the call unit 03 calls the Native method by the JavaScript program; and calling a function which is provided by the JavaScript local interface to the Native program and returns data to the JavaScript program, and returning a processing result to the JavaScript program through the function.
The marking unit is used for marking the JavaScript object declared as a global variable by using a global index interface provided by the JavaScript local interface to be always quoted so as to prevent the JavaScript object from being garbage recycled; and if a memory release instruction aiming at the JavaScript object declared as the global variable is obtained, canceling the reference mark of the global index interface to the JavaScript object, thereby releasing the memory occupied by the JavaScript object.
When the JavaScript program calls the Native method, the on-stack address or the on-heap address of the Native method is stored with the on-heap address of the JavaScript object.
When the behavior execution of the Native program application program is abnormal, the abnormality processing unit is responsible for calling a function which is provided by the JavaScript local interface to the Native program and throws the abnormality to the JavaScript program, so that the abnormality is thrown to the JavaScript program.
The JavaScript local interface provided by the embodiment of the invention is used for realizing the calling of a JavaScript program to a Native method and realizing the calling of the Native program to the JavaScript method; the JavaScript local interface registers a Native method and loads a Native library, wherein the Native library comprises the Native method and a registration function; and the JavaScript local interface provides a first function for calling the Native method for the JavaScript program and provides a second function for calling the JavaScript method for the Native program.
The above-described methods and apparatus provided by embodiments of the present invention may be embodied in a computer program that is configured and operable to be executed by a device. The apparatus may include one or more processors, and further include memory and one or more programs, as shown in fig. 8. Where the one or more programs are stored in memory and executed by the one or more processors to implement the method flows and/or device operations illustrated in the above-described embodiments of the invention. For example, the method flows executed by the one or more processors may include:
registering a Native method to obtain a Native library, wherein the Native library comprises a Native method and a registration function of the Native method;
loading the Native library;
the method comprises the steps that a function for calling the Native method is provided for a JavaScript program through a JavaScript local interface, and the JavaScript program is used for calling the Native method; and the function for calling the JavaScript method is provided for the Native program through the JavaScript local interface, so that the Native program calls the JavaScript method.
In the embodiments provided by the present invention, it should be understood that the disclosed apparatus, method and device may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, and for example, the division of the units is only one logical functional division, and other divisions may be realized in practice.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute some steps of the methods according to the embodiments of the present invention. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.
Claims (40)
1. A method for processing a scripting language interface, the method comprising:
registering a local method to obtain a local method library, wherein the local method library comprises the local method and a registration function;
loading the local method library by using the registration function;
and calling the local method by the script language program through a first function, wherein the first function is a function which is provided by the script language interface to the script language program and calls the local method.
2. The method of claim 1, further comprising:
and calling the script language method by the local program through a second function, wherein the second function is a function for calling the script language method provided by the script language interface to the local program.
3. The method of claim 1, wherein registering the local method to obtain the local method library comprises:
acquiring a local method and the registration function;
and compiling the acquired local method and the registration function into a local method library.
4. The method of claim 1, wherein loading the local method library using the registration function comprises:
the script language interface is used for calling a loading function provided by a script language program;
and calling the registration function and making the local method in the local method library visible to the script language program.
5. The method of claim 4, prior to invoking the registration function, further comprising:
judging whether the local method library exists or not according to the address of the local method library;
if yes, continuing to execute the calling of the registration function; otherwise, returning the prompt information that the local method library does not exist, and ending the current local method library loading process.
6. The method of claim 4, wherein making the local methods in the local method library visible to a script language program comprises:
and transmitting the visible preset object of the script language program to the registration function, and setting the local method in the local method library into the preset object by the registration function so that the script language program can obtain the local method through the preset object.
7. The method of claim 1, wherein implementing the call to the local method by the scripting language program through the first function comprises:
acquiring an instruction for calling a local method from a script language program;
and calling a first function, wherein the first function is a function for calling the local method provided by the scripting language interface to the scripting language program, and the local method information to be called is transferred to the local program through the first function, so that the local program executes the corresponding local method according to the local method information to be called.
8. The method of claim 2, wherein implementing the call by the local program to the script language method via the second function comprises:
acquiring an instruction for calling a script language method from a local program;
and calling a second function, wherein the second function is a function for calling the script language method provided by the script language interface to the local program, and the information of the script language method to be called is transmitted to the script language program through the second function, so that the script language program executes the corresponding script language method according to the information of the script language method to be called.
9. The method of claim 1, further comprising:
the called local method processes data transmitted to the local program by the script language program through a third function, wherein the third function is a function of operation data provided by the script language interface to the local program; and the number of the first and second groups,
and calling a fourth function, wherein the fourth function is a function which is provided by the scripting language interface to the local program and returns data to the scripting language program, and the processing result is returned to the scripting language program through the fourth function.
10. The method of claim 9, wherein the function of operational data comprises at least one of:
a function for judging the type of the image,
the function used for the conversion of the data,
and aiming at the operation function of the data type corresponding to the local program provided by the script language type.
11. The method according to claim 1, wherein when the call of the scripting language program to the local method is implemented, a heap address of the scripting language object is stored on a stack address or a heap address of the local method.
12. The method of claim 11, wherein the scripting language object comprises data passed by the scripting language program to a local program.
13. The method of claim 1, further comprising:
a script language object declared as a global variable is referenced using a global index interface provided by the script language interface;
and if the memory release instruction aiming at the script language object declared as the global variable is obtained, canceling the reference mark of the global index interface to the script language object.
14. The method of claim 1, further comprising:
and when the behavior execution of the local program application program is abnormal, calling a function which is provided by the scripting language interface for the local program and throws the abnormality to the scripting language program so as to throw the abnormality to the scripting language program.
15. An apparatus comprising
A memory including one or more programs;
one or more processors, coupled to the memory, that execute the one or more programs to implement:
registering a local method to obtain a local method library, wherein the local method library comprises the local method and a registration function;
loading the local method library by using the registration function;
and calling the local method by the script language program through a first function, wherein the first function is a function which is provided by the script language interface to the script language program and calls the local method.
16. The device of claim 15, wherein the one or more processors execute the one or more programs to further implement:
and calling the script language method by the local program through a second function, wherein the second function is a function for calling the script language method provided by the script language interface to the local program.
17. The apparatus of claim 15, wherein registering the local method to obtain the local method library comprises:
acquiring a local method and the registration function;
and compiling the acquired local method and the registration function into a local method library.
18. The apparatus of claim 15, wherein loading the local method library using the registration function comprises:
the script language interface is used for calling a loading function provided by a script language program;
and calling the registration function and making the local method in the local method library visible to the script language program.
19. The apparatus of claim 18, further comprising, prior to invoking the registration function:
judging whether the local method library exists or not according to the address of the local method library;
if yes, continuing to execute the calling of the registration function; otherwise, returning the prompt information that the local method library does not exist, and ending the current local method library loading process.
20. The apparatus of claim 18, wherein making the local methods in the local method library visible to a script language program comprises:
and transmitting the visible preset object of the script language program to the registration function, and setting the local method in the local method library into the preset object by the registration function so that the script language program can obtain the local method through the preset object.
21. The apparatus of claim 15, wherein the invoking of the local method by the first function implementing scripting language program comprises:
acquiring an instruction for calling a local method from a script language program;
and calling a first function, wherein the first function is a function for calling the local method provided by the scripting language interface to the scripting language program, and the local method information to be called is transferred to the local program through the first function, so that the local program executes the corresponding local method according to the local method information to be called.
22. The apparatus of claim 16, wherein the implementing of the call by the local program to the script language method via the second function comprises:
acquiring an instruction for calling a script language method from a local program;
and calling a second function, wherein the second function is a function for calling the script language method provided by the script language program to the local program, and the information of the script language method to be called is transmitted to the script language program through the second function, so that the script language program executes the corresponding script language method according to the information of the script language method to be called.
23. The device of claim 15, wherein the one or more processors execute the one or more programs to further implement:
the called local method processes data transmitted to the local program by the script language program through a third function, wherein the third function is a function of operation data provided by the script language interface to the local program; and the number of the first and second groups,
and calling a fourth function, wherein the fourth function is a function which is provided by the scripting language interface to the local program and returns data to the scripting language program, and the processing result is returned to the scripting language program through the fourth function.
24. The apparatus of claim 23, wherein the function of operational data comprises at least one of:
a function for judging the type of the image,
and the function for data conversion is an operation function of the data type corresponding to the local program provided by aiming at the script language type.
25. The apparatus according to claim 15, wherein when the call to the local method by the scripting language program is implemented, a heap address of the scripting language object is stored at a stack address or a heap address of the local method.
26. The apparatus of claim 25, wherein the scripting language object comprises data passed by the scripting language program to a local program.
27. The device of claim 15, wherein the one or more processors execute the one or more programs to further implement:
a script language object declared as a global variable is referenced using a global index interface provided by the script language interface;
and if the memory release instruction aiming at the script language object declared as the global variable is obtained, canceling the reference mark of the global index interface to the script language object.
28. The device of claim 15, wherein the one or more processors execute the one or more programs to further implement:
and when the behavior execution of the local program application program is abnormal, calling a function which is provided by the scripting language interface for the local program and throws the abnormality to the scripting language program so as to throw the abnormality to the scripting language program.
29. A processing apparatus of a scripting language interface, the apparatus comprising:
the registration unit is used for registering the local method to obtain a local method library, and the local method library comprises the local method and a registration function of the local method;
a loading unit for loading the local method library;
and the calling unit is used for providing a first function and a second function, the first function is a function which is provided for the script language program and calls the local method, and the second function is a function which is provided for the local program and calls the script language method.
30. The apparatus according to claim 29, wherein the calling unit is further configured to implement a call of a script language program to a local method through the first function; and calling the script language method by the local program through the second function.
31. The apparatus of claim 30, further comprising:
the transfer unit is used for saving the on-pile address of the script language object on the on-stack address or the on-pile address of the local method when the call unit calls the local method by the script language program; and calling a fourth function, wherein the fourth function is a function which is provided by the scripting language interface to the local program and returns data to the scripting language program, and the processing result is returned to the scripting language program through the fourth function.
32. The apparatus of claim 29, further comprising:
a marking unit for marking a script language object declared as a global variable with a global index interface provided by the script language interface to be referenced; and if the memory release instruction aiming at the script language object declared as the global variable is obtained, canceling the reference mark of the global index interface to the script language object.
33. The apparatus of claim 30, further comprising:
and the exception handling unit is used for calling a function which is provided by the scripting language interface for the local program and throws an exception to the scripting language program when the behavior execution of the local program application program is abnormal, so as to throw the exception to the scripting language program.
34. An operating system comprising a scripting language interface, said scripting language interface comprising apparatus as claimed in any one of claims 29 to 33.
35. A calling method based on a script language interface is characterized by comprising the following steps:
the method comprises the steps that a script language program calls a local method through a first function, wherein the first function is a function which is provided by a script language interface for calling the local method; the script language interface registers a local method in advance and loads a local method library, wherein the local method library comprises the local method and a registration function.
36. The method of claim 35, wherein when the scripting language program calls the local method through the first function, the on-stack address or the on-heap address of the local method stores the on-heap address of the scripting language object.
37. A method according to claim 36, wherein the scripting language object comprises data passed to a local program by the scripting language program.
38. A calling method based on a script language interface is characterized by comprising the following steps:
the local program calls the script language method through a second function, wherein the second function is a function which is provided by the script language interface for calling the script language method to the local program; the script language interface registers a local method in advance and loads a local method library for realizing the calling of a script language program to the local method, wherein the local method library comprises the local method and a registration function.
39. The method of claim 38, further comprising:
the called local method processes data transmitted to the local program by the script language program through a third function, wherein the third function is a function of operation data provided by the script language interface to the local program; and the number of the first and second groups,
and returning the processing result to the script language program through a fourth function, wherein the fourth function is a function which is provided by the script language interface to the local program and returns data to the script language program.
40. The scripting language interface is characterized in that the scripting language interface is used for realizing the calling of a scripting language program to a local method and realizing the calling of the local program to the scripting language method; wherein,
the script language interface registers a local method and loads a local method library, wherein the local method library comprises a local method and a registration function; and
the scripting language interface provides a first function for calling the local method to the scripting language program and provides a second function for calling the scripting language method to the local program.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610693286.5A CN107766119A (en) | 2016-08-19 | 2016-08-19 | A kind of processing method of scripting language interface, device and equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610693286.5A CN107766119A (en) | 2016-08-19 | 2016-08-19 | A kind of processing method of scripting language interface, device and equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN107766119A true CN107766119A (en) | 2018-03-06 |
Family
ID=61262044
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610693286.5A Pending CN107766119A (en) | 2016-08-19 | 2016-08-19 | A kind of processing method of scripting language interface, device and equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107766119A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108920218A (en) * | 2018-05-23 | 2018-11-30 | 北京五八信息技术有限公司 | A kind of reflection call method, device, terminal and computer readable storage medium |
CN109857478A (en) * | 2019-01-31 | 2019-06-07 | 北京小米移动软件有限公司 | Operation method, device and the readable storage medium storing program for executing of destination application |
CN113220380A (en) * | 2021-05-25 | 2021-08-06 | 北京小米移动软件有限公司 | Calling method and device of local native program, electronic equipment and storage medium |
CN116048668A (en) * | 2023-03-30 | 2023-05-02 | 麒麟软件有限公司 | Application plug-in communication system based on web operating system |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6066181A (en) * | 1997-12-08 | 2000-05-23 | Analysis & Technology, Inc. | Java native interface code generator |
CN104298493A (en) * | 2013-07-19 | 2015-01-21 | 深圳市同洲电子股份有限公司 | Local extension method and system for Javascript |
-
2016
- 2016-08-19 CN CN201610693286.5A patent/CN107766119A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6066181A (en) * | 1997-12-08 | 2000-05-23 | Analysis & Technology, Inc. | Java native interface code generator |
CN104298493A (en) * | 2013-07-19 | 2015-01-21 | 深圳市同洲电子股份有限公司 | Local extension method and system for Javascript |
Non-Patent Citations (3)
Title |
---|
IERUSALIMSCHY,R.: "《Lua程序设计:第二版》", 31 May 2008 * |
LANGLEY, NICK: "Javascript generator puts hand-rolled in the shade", 《COMPUTER WEEKLY》 * |
贺敏: "《C# 2.0程序设计初步》", 30 September 2007 * |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108920218A (en) * | 2018-05-23 | 2018-11-30 | 北京五八信息技术有限公司 | A kind of reflection call method, device, terminal and computer readable storage medium |
CN108920218B (en) * | 2018-05-23 | 2023-03-03 | 北京五八信息技术有限公司 | Reflection calling method, device, terminal and computer readable storage medium |
CN109857478A (en) * | 2019-01-31 | 2019-06-07 | 北京小米移动软件有限公司 | Operation method, device and the readable storage medium storing program for executing of destination application |
CN109857478B (en) * | 2019-01-31 | 2022-03-25 | 北京小米移动软件有限公司 | Target application program running method and device and readable storage medium |
CN113220380A (en) * | 2021-05-25 | 2021-08-06 | 北京小米移动软件有限公司 | Calling method and device of local native program, electronic equipment and storage medium |
CN116048668A (en) * | 2023-03-30 | 2023-05-02 | 麒麟软件有限公司 | Application plug-in communication system based on web operating system |
CN116048668B (en) * | 2023-03-30 | 2023-06-23 | 麒麟软件有限公司 | Application plug-in communication system based on web operating system |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10761860B2 (en) | Dynamically loaded plugin architecture | |
US9891900B2 (en) | Generation of specialized methods based on generic methods and type parameterizations | |
US20160232017A1 (en) | System and Method for Reloading Constructors | |
US6996590B2 (en) | Method and system for the garbage collection of shared data | |
US10684827B2 (en) | Generating dynamic modular proxies | |
US9417931B2 (en) | Unified metadata for external components | |
CN111176722B (en) | Method, device and storage medium for detecting file version of third party library | |
CN111679852B (en) | Detection method and device for conflict dependency library | |
US10466985B2 (en) | Hybrid deoptimization mechanism for class hierarchy analysis | |
US11537367B1 (en) | Source code conversion from application program interface to policy document | |
KR101059633B1 (en) | Heap configuration for multitasking virtual machines | |
EP4276610A1 (en) | Exception handling method and relevant apparatus | |
CN107766119A (en) | A kind of processing method of scripting language interface, device and equipment | |
US20090320007A1 (en) | Local metadata for external components | |
US11061695B2 (en) | Unikernel provisioning | |
CN111880804A (en) | Application program code processing method and device | |
US8694972B2 (en) | System and method for interoperating with foreign objects from a single language computing environment | |
US9841982B2 (en) | Locating import class files at alternate locations than specified in classpath information | |
US11157249B1 (en) | Method and system for identifying and extracting independent services from a computer program | |
CN111352631A (en) | Interface compatibility detection method and device | |
US9448782B1 (en) | Reducing a size of an application package | |
Lyu et al. | A procedure-based dynamic software update | |
CN112860279B (en) | Method, device, equipment and medium for generating application installation package | |
US20130042235A1 (en) | Dynamic bootstrap literal processing within a managed runtime environment | |
Chang et al. | Implementation of JVM tool interface on Dalvik virtual machine |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20201126 Address after: Room 603, 6 / F, Roche Plaza, 788 Cheung Sha Wan Road, Kowloon, China Applicant after: Zebra smart travel network (Hong Kong) Ltd. Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands Applicant before: Alibaba Group Holding Ltd. |
|
TA01 | Transfer of patent application right | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20180306 |
|
RJ01 | Rejection of invention patent application after publication |