ES new features support methods, devices, equipment, and readable storage media

By detecting JavaScript engine anomalies in the browser and finding new feature code in the pre-built database, the problem of ES new feature anomalies caused by browser not being updated was solved, enabling rapid support for new ES features without updating the kernel version, and reducing development and maintenance costs.

CN115292080BActive Publication Date: 2026-05-26FIBERHOME TELECOMMUNICATION TECHNOLOGIES CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
FIBERHOME TELECOMMUNICATION TECHNOLOGIES CO LTD
Filing Date
2022-07-22
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

The lack of timely updates to existing browser versions has resulted in a lack of support for code written with new ES features, leading to page anomalies. Furthermore, updating the browser kernel version presents challenges such as high iteration difficulty, long development cycles, and high maintenance costs.

Method used

By detecting exceptions thrown by the JavaScript engine, obtaining the error object and type, searching for new feature code in a pre-built database, and compiling and running the new feature code in the context execution environment, the browser kernel version can be avoided.

Benefits of technology

It quickly resolves issues caused by browsers not supporting new ES features, simplifies deployment and maintenance, is compatible with most browsers, and reduces iteration costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115292080B_ABST
    Figure CN115292080B_ABST
Patent Text Reader

Abstract

This invention provides a method, apparatus, device, and readable storage medium for supporting new ES features. The method includes: when an exception is detected thrown by the JavaScript engine, obtaining the error object, error type, and execution context of the exception; searching for new feature code in a pre-built database based on the error object and the error type; and if found, compiling and running the new feature code in the execution context. This invention solves the problem of exceptions thrown by the JavaScript engine that cause it to not support code written using new ES features, and enables rapid support for new ES features without updating the browser's kernel version.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Internet front-end technology, and in particular to a method, apparatus, device and readable storage medium for supporting new features of Elasticsearch. Background Technology

[0002] ECMAScript (ES) is a scripting language specification defined by ECMA (European Computer Manufacturers Association) in the standard ECMA-262. JavaScript (JS) is an implementation and extension of the ECMA-262 standard. Currently, the JavaScript engines of mainstream browsers have implemented the ES specification. Since the release of ES6 in 2015, ES has added a small number of new features every year. It has now been updated to ES12, and browsers are constantly releasing new versions to quickly respond to and support these new ES features.

[0003] Due to the rapid development of front-end technologies on the Internet, it is common to encounter situations where the current browser version does not support code written using new ES features. This can lead to various abnormal issues, such as incomplete page loading, unresponsive page links, and missing functions. The usual solution is to update the browser kernel version to address the browser kernel's lack of support for new ES features. However, the source code of browser kernels is vast, especially for browsers that are being developed for secondary purposes. This presents challenges such as difficulty in iterating versions, long development cycles, and high maintenance costs. Summary of the Invention

[0004] The main objective of this invention is to provide a method, apparatus, device, and readable storage medium for supporting new features of Elasticsearch (ES). This invention aims to solve the technical problem that when ES releases new features, if the browser kernel version is not updated in time, it will not support the code written using the new ES features, thus causing abnormal page browsing.

[0005] In a first aspect, the present invention provides an ES new feature support method, the ES new feature support method comprising:

[0006] When an exception is detected thrown by the JavaScript engine, obtain the exception's error object, error type, and execution context.

[0007] Based on the error object and the error type, search for the new feature code in the prefab database;

[0008] If found, the new feature code is compiled and run in the execution context.

[0009] Optionally, the step of searching for new feature codes in the prefab database based on the error object and the error type includes:

[0010] Determine the data table corresponding to the erroneous object in the pre-built database;

[0011] Find the new feature code corresponding to the error type in the determined data table.

[0012] Optionally, compiling and running the new feature code in the execution context includes:

[0013] Compile the new feature code into bytecode;

[0014] The compiled bytecode is run in the execution context described above.

[0015] Optionally, the method for supporting new ES features also includes:

[0016] Get the new feature code;

[0017] During JavaScript engine initialization, the new feature code is loaded so that it can be transformed into a global object that the JavaScript engine can recognize.

[0018] Optionally, the code for obtaining new features includes:

[0019] Retrieve the missing new feature code from the browser kernel version in the pre-built database.

[0020] Secondly, the present invention also provides an ES new feature support device, the ES new feature support device comprising:

[0021] The detection module is used to obtain the error object, error type, and execution context of the exception when an exception is thrown by the JavaScript engine.

[0022] The lookup module is used to search for new feature codes in a pre-built database based on the error object and the error type;

[0023] A compilation module is used to compile and run the new feature code in the execution context if it is found.

[0024] Optionally, the search module is used for:

[0025] Determine the data table corresponding to the erroneous object in the pre-built database;

[0026] Find the new feature code corresponding to the error type in the determined data table.

[0027] Optionally, the compilation module is used for:

[0028] Compile the new feature code into bytecode;

[0029] The compiled bytecode is run in the execution context described above.

[0030] Thirdly, the present invention also provides an ES new feature support device, the ES new feature support device including a processor, a memory, and an ES new feature support program stored in the memory and executable by the processor, wherein when the ES new feature support program is executed by the processor, it implements the steps of the ES new feature support method as described above.

[0031] Fourthly, the present invention also provides a readable storage medium storing an ES new feature support program, wherein when the ES new feature support program is executed by a processor, it implements the steps of the ES new feature support method as described above.

[0032] In this invention, when an exception thrown by the JavaScript engine is detected, the error object, error type, and execution context of the exception are obtained. Based on the error object and error type, new feature code is searched in a pre-built database. If found, the new feature code is compiled and run in the execution context. This invention first detects and intercepts exceptions thrown by the JavaScript engine. After intercepting the exception, the error object, error type, and execution context of the intercepted exception are obtained. The latest ES new feature code is pre-stored in a pre-built database. Based on the error object and error type, the corresponding new feature code is searched in the pre-built database. If the corresponding new feature code is found, it is compiled and run in the execution context. This solves the problem of exceptions thrown by the JavaScript engine that are not supported by the JavaScript engine due to its lack of support for code written using new ES features. After returning to the previous state, the JavaScript engine continues to execute the subsequent code. After compilation and execution, the new feature code obtained from the pre-built database is converted into a global object recognizable by the JavaScript engine. This invention enables rapid support for new ES features without updating the browser's kernel version. Attached Figure Description

[0033] Figure 1 This is a schematic diagram of the hardware structure of an embodiment of the ES new feature support device of the present invention;

[0034] Figure 2 This is a flowchart illustrating an embodiment of the ES new feature support method of the present invention;

[0035] Figure 3 for Figure 2 A detailed flowchart of step S20;

[0036] Figure 4 This is a schematic diagram of a prefabricated database structure according to an embodiment of the ES new feature support method of the present invention;

[0037] Figure 5 for Figure 2 A detailed flowchart of step S30;

[0038] Figure 6 This is a schematic diagram of the functional modules of an embodiment of the ES new feature support device of the present invention.

[0039] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0040] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0041] In a first aspect, embodiments of the present invention provide an ES new feature support device.

[0042] Reference Figure 1 , Figure 1 This is a schematic diagram of the hardware structure of an embodiment of the ES (Elasticsearch) feature support device of the present invention. In this embodiment, the ES feature support device may include a processor 1001 (e.g., a Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to implement communication between these components; the user interface 1003 may include a display screen or an input unit such as a keyboard; the network interface 1004 may optionally include a standard wired interface or a wireless interface (e.g., Wireless Fidelity, Wi-Fi); the memory 1005 may be high-speed random access memory (RAM) or stable memory (non-volatile memory), such as a disk storage device. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001. Those skilled in the art will understand that… Figure 1 The hardware structure shown does not constitute a limitation of the invention and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0043] Continue to refer to Figure 1 , Figure 1The memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an ES (Elasticsearch) feature support program. The processor 1001 can call the ES feature support program stored in the memory 1005 and execute the ES feature support method provided in this embodiment of the invention.

[0044] Secondly, embodiments of the present invention provide a method for supporting new features of ES.

[0045] To more clearly demonstrate the ES new feature support method provided in the embodiments of this application, we will first introduce the application scenarios of the ES new feature support method provided in the embodiments of this application.

[0046] The ES new feature support method provided in this application is applicable to situations where, due to the rapid development of Internet front-end technology, the current browser version often does not support code written using ES new features. This can lead to various abnormal problems, such as incomplete page loading and display, unresponsive page links, and missing functions, resulting in a poor browsing experience for users. If such problems are solved by updating the browser kernel version, the browser kernel source code is huge, especially for secondary browsers, which will face problems such as difficulty in iterating versions, long development cycles, and high maintenance costs. Therefore, a method that can quickly solve the problem of browsers not supporting new feature code is needed.

[0047] In one embodiment, reference is made to Figure 2 , Figure 2 This is a flowchart illustrating an embodiment of the ES new feature support method of the present invention, as shown below. Figure 2 As shown, the methods for supporting new ES features include:

[0048] Step S10: When an exception is detected by the JavaScript engine, obtain the error object, error type, and execution context of the exception.

[0049] In this embodiment, exceptions thrown by the JavaScript engine are monitored and intercepted. The error object, error type, and execution context of the intercepted exception are obtained. The interception and capture of exceptions and the acquisition of exception information are based on the exception handling mechanism of the JavaScript language and the exception interface provided by the JavaScript engine. Since ES3, JavaScript has provided an exception handling mechanism to make the code written in JavaScript more robust. Even if an exception occurs during program execution, the program can still have a certain degree of exception recovery capability. When the JavaScript engine parses or runs the program code, once an error occurs, i.e., an exception, such as a code logic or syntax error that causes the program to be unable to continue execution, the JavaScript engine will throw an error object. JavaScript natively provides the Error constructor, and all thrown errors are instances of this constructor. When the JavaScript engine throws an exception, the program either stops executing or catches the exception using a try-catch statement. In some cases, exceptions can also be actively thrown using the throw keyword. A JavaScript engine is a virtual machine specifically designed to process JavaScript scripts. It is typically included with web browsers. The main functions of a JavaScript engine are compiling JavaScript scripts into bytecode, code execution, memory allocation, and garbage collection. It primarily consists of a compiler, interpreter, JIT (Just-in-Time) compilation tools, garbage collector, and analysis tools. For example, the JavaScript V8 engine provides the `Isolate::Throw` exception handling interface, while the JavaScriptCore engine provides the global static interface `throwError`. The JavaScript V8 engine is mainly used in browsers like Chrome and Edge, while the JavaScriptCore engine is primarily used in the Safari browser.

[0050] In this embodiment, the ES new feature support method of the present invention can be made into a browser extension or plugin through the development interface provided by the browser. After being installed by the browser manufacturer or user, the detection and interception of anomalies and subsequent functions of the present invention can be implemented and run. The browser plugin is a program written according to a certain application programming interface specification. In addition to the basic functions of the browser, it adds extended browser functions, such as web page translation, ad blocking, Flash plugin, etc.

[0051] Step S20: Based on the error object and the error type, search for new feature codes in the pre-built database.

[0052] In this embodiment, the prefabricated database is implemented using a virtual database or configuration file. The latest ES feature code is pre-stored in the prefabricated database according to error objects and error types. Based on the structured design of the prefabricated database, a data query language is used to search for the corresponding new feature code for each error object and error type. This new feature code is provided and released by the ES organization to help developers improve current functionality or expand new features. The latest version of ES feature code is publicly released and can be easily obtained directly. For example, on June 22, 2021, the 121st Ecma International conference was held remotely and officially adopted the ECMAScript 2021 standard. ES12 became the de facto standard in 2021. ES12 primarily released five new features: logical assignment operators, numeric separators, `Promise.any` and `AggregateError`, `String.prototype.replaceAll`, and `WeakRefs` and `FinalizationRegistry` objects. For example, in the new feature `replaceAll`, all matches of the pattern are replaced with a replacement. The pattern can be a string or a regular expression, and the replacement can be a string or a function executed for each match, returning a completely new string. An example of code written before this feature was available:

[0053] const str="student is real student";

[0054] constnewStr=str.replace( / student / g,"hahaha");

[0055] console.log(newStr);

[0056] Code examples after the new replaceAll feature is implemented:

[0057] const str="student is real student";

[0058] constnewStr=str.replaceAll('student',"hahaha");

[0059] console.log(newStr);

[0060] Both outputs are: hahaha is areal hahaha.

[0061] Step S30: If found, the new feature code is compiled and run in the execution context.

[0062] In this embodiment, if the corresponding new feature code is found, the new feature code is compiled and run in the context execution environment, thereby resolving the exception thrown by the JavaScript engine caused by the JavaScript engine's lack of support for code written using ES new features. After returning, the JavaScript engine continues to execute the following code. After compilation and execution, the new feature code obtained from the pre-built database will be converted into a global object that the JavaScript engine can recognize. If the compiled and run global object is used again in subsequent code, the JavaScript engine can directly recognize and access it without causing an exception. Another foreseeable scenario is that if the corresponding new feature code is not found in the pre-built database, the JavaScript engine will return and continue to throw an exception.

[0063] In this embodiment, exceptions thrown by the JavaScript engine are intercepted in the form of an extension or plugin. The corresponding new feature code is then searched in a pre-built database based on the exception's error object and type. This new feature code is then compiled and run in the execution context, thus resolving the exceptions thrown by the JavaScript engine due to its lack of support for code written using new ES features. By using a lightweight pre-built database and providing extensions, installation and updates are convenient. This allows for rapid support of new ES features without updating the browser's kernel version or modifying the JavaScript engine source code. It avoids the need to update the browser kernel version to address the browser's lack of support for new ES features. Since browser kernel source code is vast, especially for secondary development, it faces challenges such as difficult version iterations, long development cycles, and high maintenance costs. Therefore, this invention offers advantages such as simple deployment, ease of maintenance, and applicability to most browsers.

[0064] Furthermore, in one embodiment, reference is made to Figure 3 , Figure 3 for Figure 2 A detailed flowchart of step S20 is shown below. Figure 3 As shown, step S20 includes:

[0065] Step S201: Determine the data table corresponding to the erroneous object in the pre-built database;

[0066] Step S202: Search for the new feature code corresponding to the error type in the determined data table.

[0067] In this embodiment, refer to Figure 4 , Figure 4 This is a schematic diagram of a prefabricated database structure of an embodiment of the ES new feature support method of the present invention, as shown below. Figure 4 As shown, corresponding to the error object obtained from the exception, this embodiment uses tables such as JavaScript objects Promise (a method for handling asynchronous code defined in ES) and String (a string type defined in ES) in the prefabricated database. The Promise table implements the `finally` method (a new feature in ES9) and the `any` method (a new feature in ES12). The String table implements the `replaceAll` method (a new feature in ES12). The method name representing the error type (i.e., the property or method with the error) is stored as the key, and the corresponding new feature code (i.e., the specific implementation of the new feature code) is stored as the value. First, the prefabricated database determines the data table based on the error object. Then, the corresponding new feature code is searched in the determined data table based on the error type. For example, if the error object in the exception information is Promise, the Promise table is determined, and the error type is `finally`. The corresponding new feature code can be found in the Promise table.

[0068]

[0069] If the error object in the exception message is a String, identify the String table, and if the error type is replaceAll, the corresponding new feature code can be found in the String table.

[0070]

[0071] Furthermore, in one embodiment, reference is made to Figure 5 , Figure 5 for Figure 2 A detailed flowchart of step S30 is shown below. Figure 5 As shown, step S30 includes:

[0072] Step S301: Compile the new feature code into bytecode;

[0073] Step S302: Run the compiled bytecode in the execution context.

[0074] In this embodiment, the context execution environment is the context execution environment of the error exception thrown by the JavaScript engine. The compilation and execution of the new feature code is realized by encapsulating and calling the relevant interface methods of the JavaScript engine. First, the new feature code is compiled into bytecode, and then the compiled bytecode is put into the context execution environment for execution.

[0075] Furthermore, in one embodiment, the ES new feature support method includes:

[0076] Get the new feature code;

[0077] During JavaScript engine initialization, the new feature code is loaded so that it can be transformed into a global object that the JavaScript engine can recognize.

[0078] In this embodiment, during JavaScript engine initialization, new feature code is loaded and converted into a global object recognizable by the JavaScript engine. If subsequent code written using these new ES features is executed, exceptions due to lack of support for the new features will not be thrown. The global object is a predefined object that serves as a placeholder for global functions and properties in JavaScript. Using the global object, all other predefined objects, functions, and properties can be accessed. When JavaScript code is embedded in a specific environment, the global object typically has environment-specific properties. The ES standard does not specify the type of the global object; any JavaScript implementation or embedded JavaScript can use any type of object as the global object, as long as that object defines the basic properties and functions listed here.

[0079] Furthermore, in one embodiment, the step of obtaining the new feature code includes:

[0080] Retrieve the missing new feature code from the browser kernel version in the pre-built database.

[0081] In this embodiment, since different kernel versions of browsers support new ES features to varying degrees, the kernel version of the browser is obtained, and the missing part of the new feature code is retrieved from the pre-built database based on the browser kernel version. This part of the new feature code is then loaded during JavaScript engine initialization.

[0082] Thirdly, embodiments of the present invention also provide an ES new feature support device.

[0083] Reference Figure 6 , Figure 6 This is a schematic diagram of the functional modules of an embodiment of the ES new feature support device of the present invention.

[0084] In this embodiment, the ES new feature support device includes:

[0085] The detection module 10 is used to obtain the error object, error type and execution context of the exception when an exception is detected thrown by the JavaScript engine.

[0086] The lookup module 20 is used to search for new feature codes in a pre-built database based on the error object and the error type;

[0087] The compilation module 30 is used to compile and run the new feature code in the context execution environment if it is found.

[0088] Furthermore, in one embodiment, the lookup module 20 is used for:

[0089] Determine the data table corresponding to the erroneous object in the pre-built database;

[0090] Find the new feature code corresponding to the error type in the determined data table.

[0091] Furthermore, in one embodiment, the compilation module 30 is used for:

[0092] Compile the new feature code into bytecode;

[0093] The compiled bytecode is run in the execution context described above.

[0094] Furthermore, in one embodiment, the ES new feature support device includes:

[0095] The retrieval module is used to retrieve new feature code;

[0096] A loading module is used to load the new feature code during JavaScript engine initialization, so that the new feature code can be transformed into a global object that the JavaScript engine can recognize.

[0097] Furthermore, in one embodiment, the acquisition module is used for:

[0098] Retrieve the missing new feature code from the browser kernel version in the pre-built database.

[0099] The functions of each module in the above-mentioned ES new feature support device correspond to the steps in the above-mentioned ES new feature support method embodiment, and their functions and implementation processes will not be described in detail here.

[0100] Fourthly, embodiments of the present invention also provide a readable storage medium.

[0101] The present invention stores an ES new feature support program on a readable storage medium, wherein when the ES new feature support program is executed by a processor, the steps of the ES new feature support method described above are implemented.

[0102] The method implemented when the ES new feature support program is executed can be referred to in various embodiments of the ES new feature support method of the present invention, and will not be repeated here.

[0103] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0104] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0105] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of the present invention.

[0106] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. An ECMAScript new feature support method, characterized by, The methods for supporting new ECMAScript features include: When a browser plugin or extension detects an exception thrown by the JavaScript engine, it retrieves the exception's error object, error type, and execution context. Based on the error object and the error type, search for the new feature code in the prefab database; If found, the new feature code is compiled and run in the execution context. The step of searching for new feature codes in the pre-built database based on the error object and the error type includes: Determine the data table corresponding to the erroneous object in the pre-built database; Find the new feature code corresponding to the error type in the identified data table; The process of compiling and running the new feature code in the execution context includes: Compile the new feature code into bytecode; Run the compiled bytecode in the execution context described above; The ECMAScript new feature support methods also include: Get the new feature code; During JavaScript engine initialization, the new feature code is loaded so that it can be transformed into a global object that the JavaScript engine can recognize; The code for obtaining new features includes: Retrieve the missing new feature code from the browser kernel version in the pre-built database.

2. An ECMAScript new feature support device, characterized in that, The ECMAScript new feature support device includes: The detection module is used to obtain the error object, error type, and execution context of the exception when a browser plugin or extension detects an exception thrown by the JavaScript engine. The lookup module is used to search for new feature codes in a pre-built database based on the error object and the error type; A compilation module, used to compile and run the new feature code in the execution context if found; The search module is used for: Determine the data table corresponding to the erroneous object in the pre-built database; Find the new feature code corresponding to the error type in the identified data table; The compilation module is used for: Compile the new feature code into bytecode; Run the compiled bytecode in the execution context described above; The ECMAScript new feature support device also includes: The retrieval module is used to retrieve new feature code; During JavaScript engine initialization, the new feature code is loaded so that it can be transformed into a global object that the JavaScript engine can recognize; The acquisition module is also used for: Retrieve the missing new feature code from the browser kernel version in the pre-built database.

3. A device that supports new ECMAScript features, characterized in that, The ECMAScript feature support device includes a processor, a memory, and an ECMAScript feature support program stored in the memory and executable by the processor, wherein when the ECMAScript feature support program is executed by the processor, it implements the steps of the ECMAScript feature support method as described in claim 1.

4. A readable storage medium, characterized in that, The readable storage medium stores an ECMAScript new feature support program, wherein when the ECMAScript new feature support program is executed by a processor, it implements the steps of the ECMAScript new feature support method as described in claim 1.