CN106933651B - Method and device for replacing JS engine - Google Patents

Method and device for replacing JS engine Download PDF

Info

Publication number
CN106933651B
CN106933651B CN201710150699.3A CN201710150699A CN106933651B CN 106933651 B CN106933651 B CN 106933651B CN 201710150699 A CN201710150699 A CN 201710150699A CN 106933651 B CN106933651 B CN 106933651B
Authority
CN
China
Prior art keywords
engine
function
target
file
private object
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.)
Active
Application number
CN201710150699.3A
Other languages
Chinese (zh)
Other versions
CN106933651A (en
Inventor
徐佳宏
朱吕亮
梁达源
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Ipanel TV Inc
Original Assignee
Shenzhen Ipanel TV Inc
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Ipanel TV Inc filed Critical Shenzhen Ipanel TV Inc
Priority to CN201710150699.3A priority Critical patent/CN106933651B/en
Publication of CN106933651A publication Critical patent/CN106933651A/en
Application granted granted Critical
Publication of CN106933651B publication Critical patent/CN106933651B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45529Embedded in an application, e.g. JavaScript in a Web browser
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/958Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
    • G06F16/986Document structures and storage, e.g. HTML extensions

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

According to the method and the device for replacing the JS engine, after all the files on the outer layers of the private objects are realized and the bridge connection of the target JS engine to the webcore is completed, the transition of the middle layer of each private object is realized when the JS engine is replaced by defining the public interface function of each private object according to the structure of the target JS engine, and the target JS engine is operated by calling the public interface function. The public interface function of each private object is defined, the condition that an inner layer file containing a corresponding private object specific implementation function needs to be sequentially established for each private object in the prior art is avoided, namely, the condition that each private object implementation function is modified again is avoided, the development period of replacing the JS engine is shortened, and the development cost of replacing the JS engine is reduced.

Description

Method and device for replacing JS engine
Technical Field
The invention relates to the technical field of JS engines, in particular to a method and a device for replacing a JS engine.
Background
The browser kernel is mainly divided into two modules: one module is responsible for parsing the web of the HTML page, while the other module functions to parse JavaScript scripts, which we generally refer to as a JavaScript engine. The JavaScript engine is called JS engine for short, is a virtual machine specially processing JavaScript script, and at present mainly comprises jscore and V8 engines.
All things in the JavaScript, including character strings, numerical values, arrays, functions, and the like, are objects, and the objects are special data types with properties and methods. The JavaScript supports three objects, a built-in object, a browser private object, and a custom object. The object contains two elements: 1. a set of data, i.e. variables, used to describe the properties of an object is often referred to as an attribute. 2. Several actions, i.e. several functions, used to manipulate the properties of an object are commonly referred to as methods.
Since the browser is adapted to different environments, replacing the JS engine, for example from the jscore engine to the V8 engine, requires some modification to the browser module. For built-in objects, most of the mainstream JS engines are already implemented, and replacing the JS engines is not necessary. However, the browser private object is different, and the mainstream JS engine is not implemented, because the private object is designed according to requirements, the private object is generally implemented again after the JS engine is replaced.
The method for realizing the private object comprises the steps of firstly creating IDL files of all the private objects; then, running a Perl script according to the IDL file of the private object, and automatically generating an outer layer file JSMObject. cpp of the object, wherein when a program is run, a Binding module of the browser calls a function in the outer layer file; finally, MyObject.
Because the number of the private objects of the browser is large, if the private objects are realized again, the development period is long, and the cost for replacing the JS engine is high.
Disclosure of Invention
In view of this, the present invention provides a method and an apparatus for replacing a JS engine, where a public interface function in an intermediate layer is constructed, and the replaced JS engine is connected by calling the public interface function, so that the content of a private object does not need to be modified again, a development period for replacing the JS engine is shortened, and development cost is reduced.
The specific technical scheme is as follows:
a method of replacing a JS engine, the method comprising:
generating an outer layer file of each private object according with the syntax of the target JS engine;
when a Binding module of the browser calls each outer-layer file, bridging of the target JS engine to the webcore is achieved;
defining a public interface function of each private object according to the structure of the target JS engine, and writing the statement of the public interface function into a header file;
and calling the public interface function in the header file, and operating the target JS engine.
Preferably, the generating of the outer layer file of each private object conforming to the syntax of the target JS engine includes:
according to the grammar rule of the IDL file in the target JS engine, the grammar of the IDL file of each private object in the original JS engine is modified to obtain a plurality of modified IDL files;
respectively writing each modified IDL file into a Perl script;
and running each Perl script to generate an outer layer file of each private object.
Preferably, the common interface function includes: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
An apparatus to replace a JS engine, the apparatus comprising:
the generating unit is used for generating an outer layer file of each private object according with the syntax of the target JS engine;
the bridging unit is used for realizing bridging of the target JS engine on the webcore when the Binding module of the browser calls each outer-layer file;
the definition unit is used for defining a public interface function of each private object according to the structure of the target JS engine and writing the statement of the public interface function into a header file;
and the calling unit is used for calling the public interface function in the header file and operating the target JS engine.
Preferably, the generating unit includes:
the modifying subunit is used for modifying the syntax of the IDL file of each private object in the original JS engine according to the syntax rule of the IDL file in the target JS engine to obtain a plurality of modified IDL files;
a write-in subunit, configured to write each modified IDL file into a Perl script, respectively;
and the generating subunit is used for operating each Perl script and generating an outer layer file of each private object.
Preferably, the common interface function includes: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
Compared with the prior art, the invention has the following beneficial effects:
according to the method and the device for replacing the JS engine, after all the files on the outer layers of the private objects are realized and the bridge connection of the target JS engine to the webcore is completed, the transition of the middle layer of the private objects during the replacement of the JS engine is realized by defining the public interface function of each private object according to the structure of the target JS engine. The public interface function of each private object is defined, the condition that an inner layer file containing a corresponding private object specific implementation function needs to be sequentially established for each private object in the prior art is avoided, namely, the condition that each private object implementation function is modified again is avoided, the development period of replacing the JS engine is shortened, and the development cost of replacing the JS engine is reduced.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart of a method for replacing a JS engine according to an embodiment of the present invention;
FIG. 2 is a flowchart of a method for replacing a JS engine disclosed in an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a device for replacing a JS engine according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, the present embodiment discloses a method for replacing a JS engine, including the following steps:
s101: generating an outer layer file of each private object according with the syntax of the target JS engine;
it should be noted that, the original JS engine in this embodiment refers to a JS engine currently running in the browser, that is, a JS engine that needs to be replaced; the target engine refers to a new JS engine needed by the browser to adapt to different environments, namely the JS engine after browser replacement.
The existing commonly used JS engines comprise two engines, namely jscore and V8, and the grammars specified in different JS engines are different.
Specifically, referring to fig. 2, a preferred implementation method of S101 includes the following steps:
s201: according to the grammar rule of the IDL file in the target JS engine, the grammar of the IDL file of each private object in the original JS engine is modified to obtain a plurality of modified IDL files;
it should be noted that each private object corresponds to an IDL file, and the specific properties and methods of the corresponding private object are listed in the IDL file. It will be appreciated that the proprietary attributes and methods of each private object are different, that is, the content of the corresponding IDL file for each private object is different.
The special attribute and method of the private object in the modified IDL file are the same as those of the original IDL file, and the grammar of the modified IDL file conforms to the grammar rule of the target JS engine.
S202: respectively writing each modified IDL file into a Perl script;
s203: and running each Perl script to generate an outer layer file of each private object.
Specifically, after the Perl script is run, an outer layer file jsmyobject.
It can be seen that S101 completes the implementation of the outer layer file of each private object in the original JS engine in the target JS engine.
S102: when a Binding module of the browser calls each outer-layer file, bridging of the target JS engine to the webcore is achieved;
specifically, the Binding module is related to implementation information of the private object, and comprises code of a target JS engine bridging webcore.
S103: defining a public interface function of each private object according to the structure of the target JS engine, and writing the statement of the public interface function into a header file;
preferably, the common interface function includes: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
Creating and destroying an object class function, which is used for creating and destroying a class of a certain private object through an interface;
an attribute setting function for setting an affiliation between the private object and the private object, for example, the a private object is a parent of the B private object;
the code conversion function is used for converting the character string used by the private object into a code corresponding to the page;
executing a JS script function, inputting a JS script, running and outputting a result;
a basic data type conversion function for converting the data in the private object into the basic type of the JS script: string, number, boolean, Null, Undefined, etc.;
the array operation function is used for creating an array for the private object to use, setting and acquiring the value of a certain element in the array;
a protection and release function for protecting the private object through the interface, ensuring that the members of the private object cannot be changed externally, or releasing the protection of the private object;
and a memory recovery function, namely the private object can call the interface to recover the memory in the JS engine.
It should be noted that each function defined in the public interface function is a public function of each private object, and the definition of the public interface function avoids repeated development of the public function of each private object when specific contents of the private object are realized on the basis that the proprietary attributes and methods of the corresponding private object are listed in the IDL file.
That is to say, after defining the public interface functions of each private object, the purpose of connecting the replaced JS engine is achieved by calling the public interface functions, the content of the private object does not need to be modified again, and the proprietary attributes and methods of the corresponding private object in the IDL file are directly copied for use, so that the development period of replacing the JS engine is shortened, and the development cost of replacing the JS engine is reduced.
S104: and calling the public interface function in the header file, and operating the target JS engine.
Specifically, the public interface function is called by calling the header file through the declaration of the public interface function in the header file.
According to the method for replacing the JS engine, after all the outer files of the private objects are realized and the bridge connection of the target JS engine to the webcore is completed, the transition of the middle layer of each private object is realized when the JS engine is replaced by defining the public interface function of each private object according to the structure of the target JS engine, and the target JS engine is operated by calling the public interface function. The public interface function of each private object is defined, the condition that an inner layer file containing a corresponding private object specific implementation function needs to be sequentially established for each private object in the prior art is avoided, namely, the condition that each private object implementation function is modified again is avoided, the development period of replacing the JS engine is shortened, and the development cost of replacing the JS engine is reduced.
Referring to fig. 3, the method for replacing a JS engine disclosed in the above embodiment correspondingly discloses a device for replacing a JS engine, which specifically includes:
the generating unit 101 is used for generating an outer layer file of each private object according with the syntax of the target JS engine;
the bridging unit 102 is configured to implement bridging of the webcore by the target JS engine when the Binding module of the browser calls each skin file;
the defining unit 103 is configured to define a public interface function of each private object according to the structure of the target JS engine, and write a statement of the public interface function into a header file;
preferably, the common interface function includes: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
And the calling unit 104 is used for calling the public interface function in the header file and operating the target JS engine.
Preferably, the generating unit 101 includes:
the modifying subunit is used for modifying the syntax of the IDL file of each private object in the original JS engine according to the syntax rule of the IDL file in the target JS engine to obtain a plurality of modified IDL files;
a write-in subunit, configured to write each modified IDL file into a Perl script, respectively;
and the generating subunit is used for operating each Perl script and generating an outer layer file of each private object.
In the device for replacing the JS engine provided by the embodiment, after the generation unit 101 implements all the external files of the private objects, after the bridging unit 102 completes bridging of the target JS engine to the webcore, the definition unit 103 defines the public interface function of each private object according to the structure of the target JS engine, so that transition of the middle layer of the private object during replacing the JS engine is implemented, and the call unit 104 operates the target JS engine by calling the public interface function. The defining unit 103 defines the public interface function of each private object, and avoids the need to sequentially create an inner layer file containing a specific implementation function of a corresponding private object for each private object in the prior art, that is, the device for replacing the JS engine provided by this embodiment avoids re-modifying the implementation function of each private object, shortens the development period for replacing the JS engine, and reduces the development cost for replacing the JS engine.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (6)

1. A method for replacing a JS engine, the method comprising:
generating an outer layer file of each private object according with the syntax of the target JS engine;
when a Binding module of the browser calls each outer-layer file, bridging of the target JS engine to the webcore is achieved;
defining a public interface function of each private object according to the structure of the target JS engine, and writing the statement of the public interface function into a header file; and calling the public interface function in the header file, operating the target JS engine, wherein after the public interface function of each private object is defined, the public interface function is called to achieve the purpose of connecting the target JS engine after replacement so as to directly copy and use the proprietary attribute and method of the corresponding private object in the IDL file.
2. The method of claim 1, wherein generating the outer file that each private object conforms to the target JS engine syntax comprises:
according to the grammar rule of the IDL file in the target JS engine, the grammar of the IDL file of each private object in the original JS engine is modified to obtain a plurality of modified IDL files;
respectively writing each modified IDL file into a Perl script;
and running each Perl script to generate an outer layer file of each private object.
3. The method of claim 1, wherein the common interface function comprises: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
4. An apparatus for replacing a JS engine, the apparatus comprising:
the generating unit is used for generating an outer layer file of each private object according with the syntax of the target JS engine;
the bridging unit is used for realizing bridging of the target JS engine on the webcore when the Binding module of the browser calls each outer-layer file;
the definition unit is used for defining a public interface function of each private object according to the structure of the target JS engine and writing the statement of the public interface function into a header file;
and the calling unit is used for calling the public interface function in the header file to run the target JS engine, wherein after the public interface function of each private object is defined, the public interface function is called to achieve the purpose of connecting the target JS engine after replacement so as to directly copy and use the proprietary attribute and the method of the corresponding private object in the IDL file.
5. The apparatus of claim 4, wherein the generating unit comprises:
the modifying subunit is used for modifying the syntax of the IDL file of each private object in the original JS engine according to the syntax rule of the IDL file in the target JS engine to obtain a plurality of modified IDL files;
a write-in subunit, configured to write each modified IDL file into a Perl script, respectively;
and the generating subunit is used for operating each Perl script and generating an outer layer file of each private object.
6. The apparatus of claim 4, wherein the common interface function comprises: creating and destroying an object class function, an attribute setting function, a coding conversion function, executing a JS script function, a basic data type conversion function, an array operation function, a protection and protection release function and a memory recovery function.
CN201710150699.3A 2017-03-14 2017-03-14 Method and device for replacing JS engine Active CN106933651B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710150699.3A CN106933651B (en) 2017-03-14 2017-03-14 Method and device for replacing JS engine

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710150699.3A CN106933651B (en) 2017-03-14 2017-03-14 Method and device for replacing JS engine

Publications (2)

Publication Number Publication Date
CN106933651A CN106933651A (en) 2017-07-07
CN106933651B true CN106933651B (en) 2020-10-16

Family

ID=59432676

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710150699.3A Active CN106933651B (en) 2017-03-14 2017-03-14 Method and device for replacing JS engine

Country Status (1)

Country Link
CN (1) CN106933651B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050251809A1 (en) * 2001-05-30 2005-11-10 Bea Systems, Inc. System and method for software component plug-in framework
CN104424002A (en) * 2013-09-10 2015-03-18 中国科学院声学研究所 Dynamic component loading method and system based on plug-in mechanism
CN106354484A (en) * 2015-07-16 2017-01-25 中兴通讯股份有限公司 Browser compatibility method and browser

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20050251809A1 (en) * 2001-05-30 2005-11-10 Bea Systems, Inc. System and method for software component plug-in framework
CN104424002A (en) * 2013-09-10 2015-03-18 中国科学院声学研究所 Dynamic component loading method and system based on plug-in mechanism
CN106354484A (en) * 2015-07-16 2017-01-25 中兴通讯股份有限公司 Browser compatibility method and browser

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
支持异步调用的WebKit浏览器的JavaScript事件扩展方法;王硕等;《计算机应用与软件》;20160131;第33卷(第01期);第226-229页 *

Also Published As

Publication number Publication date
CN106933651A (en) 2017-07-07

Similar Documents

Publication Publication Date Title
CN106598579B (en) Method and apparatus for integrating dynamic type programming language on blockchain
WO2021088909A1 (en) Method and system for assisting operator development
CN103500087A (en) Code generation method and device based on maven plug-in and freemarker template
US10185546B2 (en) Service extraction and application composition
CN106648662B (en) Report generation device and method based on project cost calculation description language BCL
CN110187902B (en) Project transformation method, device, equipment and storage medium based on spring boot
CN106547681B (en) Method and device for testing data automatic loading and multiplexing simulation service
CN108762764A (en) Code automatic generation method, device, computer equipment and storage medium
CN100426750C (en) Method for generating two set of network administration systems
CN106445497A (en) Application program development method and system
CN108920496A (en) A kind of rendering method and device
CN102981941A (en) Alarm handling method and alarm handling device
CN110580174B (en) Application component generation method, server and terminal
CN101185116A (en) Using strong data types to express speech recognition grammars in software programs
CN105117215A (en) Development method and device of automobile function
US10496423B2 (en) Method for opening up data and functions of terminal application based on reconstruction technology
US10387124B2 (en) System and method for creating domain specific language
CN110704394A (en) Report configuration modification method and device
CN106933651B (en) Method and device for replacing JS engine
CN103246514A (en) Method for implementing exception framework on the basis of cloud computing
CN110659022B (en) Method for automatically calling Python script based on Java
CN103226475A (en) Method and device for realizing control replacement during transcoding
US10474443B2 (en) Code lineage tool
JP2010049439A (en) System construction method using software model and modeling device
CN107451167A (en) The click data acquisition methods and system of position are clicked in standing

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
GR01 Patent grant
GR01 Patent grant