[go: up one dir, main page]

CN105824665B - Method and system for weaving aspects in JavaScript programs - Google Patents

Method and system for weaving aspects in JavaScript programs Download PDF

Info

Publication number
CN105824665B
CN105824665B CN201610142721.5A CN201610142721A CN105824665B CN 105824665 B CN105824665 B CN 105824665B CN 201610142721 A CN201610142721 A CN 201610142721A CN 105824665 B CN105824665 B CN 105824665B
Authority
CN
China
Prior art keywords
connection point
target connection
loaded
notification
notification type
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.)
Expired - Fee Related
Application number
CN201610142721.5A
Other languages
Chinese (zh)
Other versions
CN105824665A (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.)
Wuhan Institute of Technology
Original Assignee
Wuhan Institute of Technology
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 Wuhan Institute of Technology filed Critical Wuhan Institute of Technology
Priority to CN201610142721.5A priority Critical patent/CN105824665B/en
Publication of CN105824665A publication Critical patent/CN105824665A/en
Application granted granted Critical
Publication of CN105824665B publication Critical patent/CN105824665B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/445Program loading or initiating
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

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)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种JavaScript程序中方面的织入方法及系统。其中,该方法包括:创建多线程执行环境;开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;若加载,开启另一条线程,用临时变量保存目标连接点,按照通知类型方法将临时变量和接收到的目标连接点的通知方法写入目标连接点,完成方面的织入;若没有加载,继续判断目标连接点是否加载。本发明先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面,避免了现有技术中必须在目标连接点加载到对象之后才能执行方面的声明,从而解决了目标连接点织入方面失败的问题。

The invention discloses an aspect weaving method and system in a JavaScript program. Among them, the method includes: creating a multi-threaded execution environment; opening a thread, executing the notification type method in the AOP object, and judging whether the pre-declared target connection point is loaded; if loaded, opening another thread, and saving the target connection point with a temporary variable , write the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method, and complete the aspect weaving; if not loaded, continue to judge whether the target connection point is loaded. The present invention first simulates a multi-threaded running environment in a single-threaded JavaScript running environment, and then uses an object monitoring thread to monitor the loading of an object in the multi-threaded environment, and weaves the object immediately after it is loaded, avoiding the present In the prior art, the declaration of the aspect must be executed after the target connection point is loaded into the object, thus solving the problem of failure in weaving the aspect of the target connection point.

Description

一种JavaScript程序中方面的织入方法及系统Method and system for weaving aspects in JavaScript programs

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种JavaScript程序中方面的织入方法及系统。The invention relates to the field of computer technology, in particular to a method and system for weaving aspects in a JavaScript program.

背景技术Background technique

JavaScript是一种专为网页交互而设计的脚本语言,在几乎所有的Web 应用中都得到了广泛的应用。随着Web应用技术的日益增长,程序的复杂度越来越高,这便使得其中的JavaScript程序的开发和维护越来越困难。作为Web 的一个重要组成部分,JavaScript的重要性是不言而喻的。人们通常利用OOP (Object Oriented Programming,面向对象编程)去简化JavaScript的开发和维护过程,但是由于其局限性,大量功能相同的冗余代码也增加了 JavaScript的开发和维护成本。JavaScript is a scripting language specially designed for web page interaction, and is widely used in almost all web applications. With the increasing of Web application technology, the complexity of the program is getting higher and higher, which makes the development and maintenance of the JavaScript program in it more and more difficult. As an important part of the Web, the importance of JavaScript is self-evident. People usually use OOP (Object Oriented Programming, object-oriented programming) to simplify the development and maintenance process of JavaScript, but due to its limitations, a large number of redundant codes with the same functions also increase the development and maintenance costs of JavaScript.

AOP(Aspect Oriented Programming,面向切面编程)将横切关注点封装在方面(Aspect)中,从而实现了横切关注点的统一管理和维护,进而降低了系统开发的复杂度。一个方面包含切入点(Pointcut)和通知(Advice)两个部分,其中切入点定义的是某一个通知该何时执行的一组连接点(JointPoint),而连接点则表示一个程序执行过程中的一个可预见的点。对目标连接点织入方面之后,当其执行时,织入的方面中的通知也会相应地被执行。因此,将AOP应用到JavaScript的开发和维护有着十分重要的意义。AOP (Aspect Oriented Programming, Aspect-Oriented Programming) encapsulates cross-cutting concerns in aspects (Aspect), thereby realizing unified management and maintenance of cross-cutting concerns, thereby reducing the complexity of system development. An aspect includes two parts: Pointcut and Advice. The pointcut defines a set of connection points (JointPoint) when a certain advice should be executed, and the connection point represents a program during execution. a foreseeable point. After weaving an aspect to the target join point, when it executes, the advice in the weaving aspect will be executed accordingly. Therefore, it is of great significance to apply AOP to the development and maintenance of JavaScript.

目前,很多学者实现了轻量级的面向方面的JavaScript框架,而AspectJS 是其中较为成熟且较为全面的一个。AspectJS是一个对方法调用拦截有完全控制力的面向方面的JavaScript组件,其依据JavaScript语言的动态性特性,利用方法调用拦截(MCI)技术在调用目标函数前后执行其它方法,这种对调用者透明的聚合函数调用的方法就是AspectJS实现AOP的基本原理。AspectJS 为被拦截的方法调用提供了完全的控制和完善的管理,使面向方面的 JavaScript编程变得容易简单。但是,该框架对于方面的声明必须在连接点目标的声明之后,否则会因为JavaScript程序执行顺序造成编织器找不到目标连接点,而导致方面织入的失败。At present, many scholars have implemented lightweight aspect-oriented JavaScript frameworks, and AspectJS is one of the more mature and comprehensive ones. AspectJS is an aspect-oriented JavaScript component that has full control over method call interception. Based on the dynamic nature of the JavaScript language, it uses method call interception (MCI) technology to execute other methods before and after calling the target function, which is transparent to the caller. The method of aggregate function call is the basic principle of AspectJS to realize AOP. AspectJS provides full control and sophisticated management of intercepted method calls, making aspect-oriented JavaScript programming easy and simple. However, the framework's declaration of the aspect must be after the declaration of the join point target, otherwise the weaving machine will not be able to find the target join point due to the execution sequence of the JavaScript program, resulting in the failure of aspect weaving.

AOJS是一个不同于AspectJS的面向方面的JavaScript框架,与其最大的不同是AOJS采用XML文件去定义方面,然后通过一个代理服务器去执行方面的织入。以往的面向方面的JavaScript框架最大的缺点就是方面与源代码没有彻底分离,这样做的结果就是方面织入到源代码时,可能会引起一些程序可靠性的问题。而AOJS将方面与源代码完全分离,通过代理服务器在运行时将方面织入源代码,消除了定义方面对源代码的入侵性。但是,由于AOJS完全抛弃了JavaScript本身的语言特性的优点,利用外部程序按预先定义的XML 文件去修改Web应用中的JavaScript程序,这便使得对Web项目应用AOP变得困难复杂,难以测试。同时,AOJS需要的代理服务器也增加了Web应用的代价。AOJS is an aspect-oriented JavaScript framework different from AspectJS. The biggest difference is that AOJS uses XML files to define aspects, and then implements aspect weaving through a proxy server. The biggest disadvantage of the previous aspect-oriented JavaScript frameworks is that the aspects are not completely separated from the source code. The result of this is that when the aspects are woven into the source code, it may cause some program reliability problems. However, AOJS completely separates aspects from source code, and weaves aspects into source code at runtime through a proxy server, eliminating the intrusion of defining aspects to source code. However, because AOJS completely abandons the advantages of the language features of JavaScript itself, and uses external programs to modify JavaScript programs in Web applications according to predefined XML files, this makes it difficult to apply AOP to Web projects, and it is difficult to test. At the same time, the proxy server required by AOJS also increases the cost of Web applications.

AspectScript是一种采用高阶编程和动态性为其设计核心的成熟的面向方面的JavaScript框架。依据JavaScript语言的动态性特性,AspectScript 支持方面的动态调度。同时,由于AspectScript充分利用了高阶编程的优势,使得对于切点和方面的定义更加精确,而且结合作用域策略,因此 AspectScript提供了对于方面的精确控制。最后,AspectScript不仅仅支持隐式连接点,而且还提供了准确定义用户自定义连接点的可能,从而为框架提供了丰富的扩展的可能性。AspectScript相对于AspectJS来说,功能更加全面丰富,但是其仍然具有和AspectJS一样的不足,即目标连接点和方面的声明有严格的执行的先后顺序,从而在某些情况下会导致目标连接点织入方面失败。AspectScript is a mature aspect-oriented JavaScript framework with high-level programming and dynamism at its core. According to the dynamic nature of the JavaScript language, AspectScript supports dynamic scheduling of aspects. At the same time, because AspectScript makes full use of the advantages of high-level programming, it makes the definition of pointcuts and aspects more precise, and combined with scope strategies, AspectScript provides precise control over aspects. Finally, AspectScript not only supports implicit join points, but also provides the possibility to accurately define user-defined join points, thus providing rich extension possibilities for the framework. Compared with AspectJS, AspectScript is more comprehensive and rich in functions, but it still has the same disadvantages as AspectJS, that is, the target connection point and the declaration of the aspect have a strict execution sequence, which in some cases will cause the target connection point. Entry failed.

以上三种面向方面的JavaScript编程实现主要通过静态和动态两种方式去实现。由于JavaScript是解释型语言,不需要经过编译器进行编译,因此静态织入方面需要借助外部程序依据事先定义好的方面文件去修改源文件, AOJS就是通过这种方法实现的面向方面的JavaScript编程。该框架将方面都定义在XML文件中,然后使用另外的程序去解析这些XML文件,将定义在其中的方面编织入JavaScript程序中。但是这样的方式完全放弃了JavaScript语言动态性的特点,实现也十分复杂,因此大多数的实现都是利用JavaScript的语言特性去动态地完成方面的织入。而类似于AspectJS和AspectScript这样的实现在对于连接点加载和方面织入的顺序上考虑的不够全面,对于面向方面的JavaScript编程的实现也是不够全面的,因而可能会导致目标连接点织入方面的失败。The above three aspect-oriented JavaScript programming implementations are mainly implemented in two ways: static and dynamic. Since JavaScript is an interpreted language and does not need to be compiled by a compiler, static weaving requires an external program to modify the source file according to the pre-defined aspect file. AOJS is aspect-oriented JavaScript programming realized by this method. The framework defines aspects in XML files, and then uses other programs to parse these XML files, and weaves the aspects defined in them into JavaScript programs. However, this method completely abandons the dynamic characteristics of the JavaScript language, and the implementation is also very complicated. Therefore, most implementations use the language characteristics of JavaScript to dynamically complete aspect weaving. However, implementations like AspectJS and AspectScript do not fully consider the order of connection point loading and aspect weaving, and the implementation of aspect-oriented JavaScript programming is not comprehensive enough, which may cause the target connection point to weave aspects. fail.

发明内容Contents of the invention

本发明实施例通过提供一种JavaScript程序中方面的织入方法及系统,解决了现有技术中目标连接点和方面的声明必须有严格的执行的先后顺序的技术问题,实现了避免目标连接点织入方面失败的技术效果。The embodiment of the present invention provides a method and system for weaving aspects in a JavaScript program, which solves the technical problem in the prior art that target connection points and aspect declarations must have a strict order of execution, and realizes the avoidance of target connection points. The technical effect of failure in weaving.

本发明实施例提供了一种JavaScript程序中方面的织入方法,包括:The embodiment of the present invention provides a method for weaving aspects in a JavaScript program, including:

创建多线程执行环境;Create a multi-threaded execution environment;

开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;Open a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded;

若加载,开启另一条线程,用临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入;If loading, open another thread, save the target connection point with a temporary variable, write the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method, and complete the aspect Weave into;

若没有加载,继续判断所述目标连接点是否加载。If not loaded, continue to determine whether the target connection point is loaded.

进一步地,所述开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载,具体包括:Further, said opening a thread, executing the notification type method in the AOP object, and judging whether the pre-declared target connection point is loaded, specifically includes:

创建AOP对象;Create an AOP object;

在所述AOP对象中定义至少3个所述通知类型方法;defining at least 3 notification type methods in the AOP object;

在各所述通知类型方法中存入所述目标连接点及其通知方法;storing the target connection point and its notification method in each notification type method;

在各所述通知类型方法中,分别判断所述目标连接点是否加载;In each of the notification type methods, determine whether the target connection point is loaded;

所述若加载,开启另一条线程,用临时变量保存所述目标连接点,具体包括:If it is loaded, start another thread, and save the target connection point with a temporary variable, specifically including:

若所述目标连接点在任一个所述通知类型方法中加载,则开启另一条线程,用所述临时变量保存所述目标连接点。If the target connection point is loaded in any one of the notification type methods, start another thread, and use the temporary variable to save the target connection point.

进一步地,所述判断所述目标连接点是否加载,具体包括:Further, the judging whether the target connection point is loaded specifically includes:

判断所述目标连接点是否加载到相应的执行环境中;judging whether the target connection point is loaded into a corresponding execution environment;

若是,则说明所述目标连接点加载。If yes, it indicates that the target connection point is loaded.

进一步地,所述通知类型方法包括:前置通知、后置通知和包围通知。Further, the notification type method includes: pre-notification, post-notification and surrounding notification.

本发明提供的JavaScript程序中方面的织入系统,包括:The aspect weaving system in the JavaScript program provided by the present invention includes:

多线程创建模块,用于创建多线程执行环境;A multi-thread creation module for creating a multi-thread execution environment;

判断模块,用于开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;The judging module is used to start a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded;

方面织入模块,用于若所述判断模块的判断结果为加载,开启另一条线程,用临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入。An aspect weaving module is used to open another thread if the judgment result of the judging module is loading, save the target connection point with a temporary variable, and connect the temporary variable to the received target according to the notification type method The notification method of the point is written to the target connection point to complete the aspect weaving.

进一步地,所述判断模块,具体包括:Further, the judging module specifically includes:

AOP对象创建单元,用于创建AOP对象;AOP object creation unit, used to create AOP objects;

通知类型创建单元,用于在所述AOP对象中定义至少3个所述通知类型方法;a notification type creation unit, configured to define at least three methods of the notification type in the AOP object;

信息接收单元,用于在各所述通知类型方法中存入所述目标连接点及其通知方法;An information receiving unit, configured to store the target connection point and its notification method in each notification type method;

判断执行单元,用于在各所述通知类型方法中,分别判断所述目标连接点是否加载;A judging execution unit, configured to judge whether the target connection point is loaded in each notification type method;

所述方面织入模块,具体用于若所述判断执行单元的判断结果为所述目标连接点在任一个所述通知类型方法中加载,则开启另一条线程,用所述临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入。The aspect weaving module is specifically used to start another thread and use the temporary variable to save the target if the judgment result of the judgment execution unit is that the target connection point is loaded in any one of the notification type methods The connection point writes the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method to complete aspect weaving.

进一步地,所述判断执行单元,具体用于在各所述通知类型方法中,分别判断所述目标连接点是否加载到相应的执行环境中;Further, the judgment execution unit is specifically configured to respectively judge whether the target connection point is loaded into the corresponding execution environment in each of the notification type methods;

若是,则说明所述目标连接点在该通知类型中加载。If yes, it means that the target connection point is loaded in this notification type.

进一步地,所述通知类型方法包括:前置通知、后置通知和包围通知。Further, the notification type method includes: pre-notification, post-notification and surrounding notification.

本发明实施例中提供的一个或多个技术方案,至少具有如下技术效果或优点:One or more technical solutions provided in the embodiments of the present invention have at least the following technical effects or advantages:

先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面,避免了现有技术中必须在目标连接点加载到对象之后才能执行方面的声明,从而解决了目标连接点织入方面失败的问题。First simulate a multi-threaded running environment in a single-threaded JavaScript running environment, and then use an object monitoring thread to monitor the loading of the object in the multi-threaded environment, and weave the object immediately after it is loaded, avoiding the existing technology The declaration of the aspect must be executed after the target connection point is loaded into the object, thus solving the problem that the target connection point weaves the aspect failure.

附图说明Description of drawings

图1为本发明实施例一提供的JavaScript程序中方面的织入方法的流程图;FIG. 1 is a flowchart of an aspect weaving method in a JavaScript program provided by Embodiment 1 of the present invention;

图2为本发明实施例二提供的JavaScript程序中方面的织入系统的模块图。FIG. 2 is a block diagram of a system for weaving aspects in a JavaScript program provided by Embodiment 2 of the present invention.

具体实施方式Detailed ways

本发明实施例通过提供一种JavaScript程序中方面的织入方法及系统,解决了现有技术中目标连接点和方面的声明必须有严格的执行的先后顺序的技术问题,实现了避免目标连接点织入方面失败的技术效果。The embodiment of the present invention provides a method and system for weaving aspects in a JavaScript program, which solves the technical problem in the prior art that target connection points and aspect declarations must have a strict order of execution, and realizes the avoidance of target connection points. The technical effect of failure in weaving.

本发明实施例中的技术方案为解决上述技术问题,总体思路如下:The technical solution in the embodiment of the present invention is to solve the above-mentioned technical problems, and the general idea is as follows:

先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面,避免了现有技术中必须在目标连接点加载到对象之后才能执行方面的声明,从而解决了目标连接点织入方面失败的问题。First simulate a multi-threaded running environment in a single-threaded JavaScript running environment, and then use an object monitoring thread to monitor the loading of the object in the multi-threaded environment, and weave the object immediately after it is loaded, avoiding the existing technology The declaration of the aspect must be executed after the target connection point is loaded into the object, thus solving the problem that the target connection point weaves the aspect failure.

为了更好地理解上述技术方案,下面将结合说明书附图以及具体的实施方式对上述技术方案进行详细的说明。In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

实施例一Embodiment one

参见图1,本发明实施例提供的JavaScript程序中方面的织入方法,包括:Referring to Fig. 1, the method for weaving aspects in the JavaScript program provided by the embodiment of the present invention includes:

步骤S110:创建多线程执行环境;Step S110: creating a multi-thread execution environment;

对本步骤进行说明,首先引入Concurrent.Thread.js库,并准备为各AOP 对象的通知调用创建一个监控线程,并给该通知调用传入连接点和通知方法。To illustrate this step, first import the Concurrent.Thread.js library, and prepare to create a monitoring thread for the notification call of each AOP object, and pass in the connection point and notification method to the notification call.

步骤S120:开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;Step S120: start a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded;

步骤S130:若加载,开启另一条线程,用临时变量保存目标连接点,按照通知类型方法将临时变量和接收到的目标连接点的通知方法写入目标连接点,完成方面的织入;Step S130: If loaded, start another thread, save the target connection point with a temporary variable, write the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method, and complete the aspect weaving;

若没有加载,继续判断目标连接点是否加载。If not loaded, continue to judge whether the target connection point is loaded.

具体地,对步骤S120进行具体的说明,包括:Specifically, step S120 is specifically described, including:

创建AOP对象;Create an AOP object;

在本实施例中,默认所有连接点的通知方法均为window的属性,用以创建各类通知的AOP对象的基本代码实现如下:In this embodiment, the default notification methods of all connection points are properties of window, and the basic code for creating AOP objects of various notifications is implemented as follows:

在AOP对象中定义至少3个通知类型方法;Define at least 3 notification type methods in the AOP object;

在本实施例中,通知类型方法包括:前置通知、后置通知和包围通知,即before、after和around。In this embodiment, the notification type methods include: pre-notification, post-notification and surrounding notification, namely before, after and around.

在各通知类型方法中存入目标连接点及其通知方法;Store the target connection point and its notification method in each notification type method;

在各通知类型方法中,分别判断目标连接点是否加载;In each notification type method, determine whether the target connection point is loaded;

在本实施例中,判断目标连接点是否加载,具体包括:In this embodiment, judging whether the target connection point is loaded specifically includes:

判断目标连接点是否加载到相应的执行环境中;Determine whether the target join point is loaded into the corresponding execution environment;

若是,则说明目标连接点加载。If so, the target join point is loaded.

具体地,当目标连接点加载到window对象上面后,调用方面编织器 weaver。若还未加载,则在当前线程中继续执行监控。声明一个方面的代码如下:Specifically, when the target connection point is loaded on the window object, the aspect weaver weaver is called. If it has not been loaded, continue monitoring in the current thread. The code to declare an aspect is as follows:

weaver将连接点目标保存在一个temp变量中,然后按照通知的类型将通知函数与temp一起封装到aspect方法中,最后将aspect方法赋值给连接点目标,完成方面的织入。Weaver saves the connection point target in a temp variable, then encapsulates the notification function and temp into the aspect method according to the notification type, and finally assigns the aspect method to the connection point target to complete the aspect weaving.

weaver方法的基本功能实现如下:The basic functions of the weaver method are implemented as follows:

在这种情况下,步骤S130中的若加载,开启另一条线程,用临时变量保存目标连接点,具体包括:In this case, if loading in step S130, start another thread, and save the target connection point with a temporary variable, specifically including:

若目标连接点在任一个通知类型方法中加载,则开启另一条线程,用临时变量保存目标连接点。If the target connection point is loaded in any advice type method, start another thread and save the target connection point with a temporary variable.

实施例二Embodiment two

参见图2,本发明实施例提供的JavaScript程序中方面的织入系统,包括:Referring to Fig. 2, the aspect weaving system in the JavaScript program provided by the embodiment of the present invention includes:

多线程创建模块100,用于创建多线程执行环境;A multi-thread creation module 100, configured to create a multi-thread execution environment;

在本实施例中,多线程创建模块100,具体用于引入Concurrent.Thread.js 库,并准备为各AOP对象的通知调用创建一个监控线程,并给该通知调用传入连接点和通知方法。In this embodiment, the multi-thread creation module 100 is specifically used to introduce the Concurrent.Thread.js library, and prepare to create a monitoring thread for the notification call of each AOP object, and call the incoming connection point and notification method for the notification call.

判断模块200,用于开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;The judging module 200 is used to open a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded;

方面织入模块300,用于若判断模块200的判断结果为加载,开启另一条线程,用临时变量保存目标连接点,按照通知类型方法将临时变量和接收到的目标连接点的通知方法写入目标连接点,完成方面的织入。Aspect weaving module 300 is used to open another thread if the judgment result of judging module 200 is loading, save the target connection point with a temporary variable, write the temporary variable and the notification method of the received target connection point according to the notification type method Target join point to complete aspect weaving.

在本实施例中,判断模块200,具体包括:In this embodiment, the judging module 200 specifically includes:

AOP对象创建单元,用于创建AOP对象;AOP object creation unit, used to create AOP objects;

通知类型创建单元,用于在AOP对象中定义至少3个通知类型方法;A notification type creation unit is used to define at least 3 notification type methods in the AOP object;

在本实施例中,通知类型方法包括:前置通知、后置通知和包围通知,即 before、after和around。In this embodiment, the notification type methods include: pre-notification, post-notification and surrounding notification, namely before, after and around.

信息接收单元,用于在各通知类型方法中存入目标连接点及其通知方法;The information receiving unit is used to store the target connection point and its notification method in each notification type method;

判断执行单元,用于在各通知类型方法中,分别判断目标连接点是否加载;A judging execution unit is used to judge whether the target connection point is loaded in each notification type method;

在本实施例中,判断执行单元,具体用于在各通知类型方法中,分别判断目标连接点是否加载到相应的执行环境中;In this embodiment, the judging execution unit is specifically used to judge whether the target connection point is loaded into the corresponding execution environment in each notification type method;

若是,则说明目标连接点在该通知类型中加载。If so, the target join point is loaded in that advice type.

在这种情况下,方面织入模块300,具体用于若判断执行单元的判断结果为目标连接点在任一个通知类型方法中加载,则开启另一条线程,用临时变量保存目标连接点,按照通知类型方法将临时变量和接收到的目标连接点的通知方法写入目标连接点,完成方面的织入。In this case, the aspect weaving module 300 is specifically used to start another thread if the judging result of the execution unit is that the target connection point is loaded in any notification type method, save the target connection point with a temporary variable, and follow the notification The type method writes the temporary variable and the received notification method of the target connection point into the target connection point to complete aspect weaving.

【技术效果】【Technical effect】

先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面,避免了现有技术中必须在目标连接点加载到对象之后才能执行方面的声明,从而解决了目标连接点织入方面失败的问题。First simulate a multi-threaded running environment in a single-threaded JavaScript running environment, and then use an object monitoring thread to monitor the loading of the object in the multi-threaded environment, and weave the object immediately after it is loaded, avoiding the existing technology The declaration of the aspect must be executed after the target connection point is loaded into the object, thus solving the problem that the target connection point weaves the aspect failure.

本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present invention may be provided as methods, systems, or computer program products. Accordingly, the present invention can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.

本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和 /或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/ 或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each process and/or block in the flowchart and/or block diagram, and a combination of processes and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams.

尽管已描述了本发明的优选实施例,但本领域内的技术人员一旦得知了基本创造性概念,则可对这些实施例作出另外的变更和修改。所以,所附权利要求意欲解释为包括优选实施例以及落入本发明范围的所有变更和修改。While preferred embodiments of the invention have been described, additional changes and modifications to these embodiments can be made by those skilled in the art once the basic inventive concept is appreciated. Therefore, it is intended that the appended claims be construed to cover the preferred embodiment as well as all changes and modifications which fall within the scope of the invention.

显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalent technologies, the present invention also intends to include these modifications and variations.

Claims (6)

1.一种JavaScript程序中方面的织入方法,其特征在于,包括:1. A method for weaving aspects in a JavaScript program, comprising: 创建多线程执行环境;Create a multi-threaded execution environment; 开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;Open a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded; 若加载,开启另一条线程,用临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入;If loading, open another thread, save the target connection point with a temporary variable, write the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method, and complete the aspect Weave into; 若没有加载,继续判断所述目标连接点是否加载;If not loaded, continue to determine whether the target connection point is loaded; 先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面;First simulate a multi-threaded running environment in a single-threaded JavaScript running environment, and then use an object monitoring thread to monitor the loading of the object in the multi-threaded environment, and weave aspects into it immediately after the object is loaded; 所述开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载,具体包括:Said opening a thread, executing the notification type method in the AOP object, and judging whether the pre-declared target connection point is loaded, specifically includes: 创建AOP对象;Create an AOP object; 在所述AOP对象中定义至少3个所述通知类型方法;defining at least 3 notification type methods in the AOP object; 在各所述通知类型方法中存入所述目标连接点及其通知方法;storing the target connection point and its notification method in each notification type method; 在各所述通知类型方法中,分别判断所述目标连接点是否加载;In each of the notification type methods, determine whether the target connection point is loaded; 所述若加载,开启另一条线程,用临时变量保存所述目标连接点,具体包括:If it is loaded, start another thread, and save the target connection point with a temporary variable, specifically including: 若所述目标连接点在任一个所述通知类型方法中加载,则开启另一条线程,用所述临时变量保存所述目标连接点。If the target connection point is loaded in any one of the notification type methods, start another thread, and use the temporary variable to save the target connection point. 2.如权利要求1所述的方法,其特征在于,所述判断所述目标连接点是否加载,具体包括:2. The method according to claim 1, wherein the judging whether the target connection point is loaded specifically comprises: 判断所述目标连接点是否加载到相应的执行环境中;judging whether the target connection point is loaded into a corresponding execution environment; 若是,则说明所述目标连接点加载。If yes, it indicates that the target connection point is loaded. 3.如权利要求1或2所述的方法,其特征在于,所述通知类型方法包括:前置通知、后置通知和包围通知。3. The method according to claim 1 or 2, wherein the notification type methods include: pre-notification, post-notification and surrounding notification. 4.一种JavaScript程序中方面的织入系统,其特征在于,包括:4. An aspect weaving system in a JavaScript program, comprising: 多线程创建模块,用于创建多线程执行环境;A multi-thread creation module for creating a multi-thread execution environment; 判断模块,用于开启一条线程,执行AOP对象里的通知类型方法,判断预先声明的目标连接点是否加载;The judging module is used to start a thread, execute the notification type method in the AOP object, and judge whether the pre-declared target connection point is loaded; 方面织入模块,用于若所述判断模块的判断结果为加载,开启另一条线程,用临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入;An aspect weaving module is used to open another thread if the judgment result of the judging module is loading, save the target connection point with a temporary variable, and connect the temporary variable to the received target according to the notification type method The notification method of the point is written into the target connection point to complete the aspect weaving; 先在单线程的JavaScript运行环境中模拟出多线程运行环境,再利用在多线程环境中开启一个对象监听线程来监控对象的加载,在对象加载之后立刻对其织入方面;First simulate a multi-threaded running environment in a single-threaded JavaScript running environment, and then use an object monitoring thread to monitor the loading of the object in the multi-threaded environment, and weave aspects into it immediately after the object is loaded; 所述判断模块,具体包括:The judgment module specifically includes: AOP对象创建单元,用于创建AOP对象;AOP object creation unit, used to create AOP objects; 通知类型创建单元,用于在所述AOP对象中定义至少3个所述通知类型方法;a notification type creation unit, configured to define at least three methods of the notification type in the AOP object; 信息接收单元,用于在各所述通知类型方法中存入所述目标连接点及其通知方法;An information receiving unit, configured to store the target connection point and its notification method in each notification type method; 判断执行单元,用于在各所述通知类型方法中,分别判断所述目标连接点是否加载;A judging execution unit, configured to judge whether the target connection point is loaded in each notification type method; 所述方面织入模块,具体用于若所述判断执行单元的判断结果为所述目标连接点在任一个所述通知类型方法中加载,则开启另一条线程,用所述临时变量保存所述目标连接点,按照通知类型方法将所述临时变量和接收到的所述目标连接点的通知方法写入所述目标连接点,完成方面的织入。The aspect weaving module is specifically used to start another thread and use the temporary variable to save the target if the judgment result of the judgment execution unit is that the target connection point is loaded in any one of the notification type methods The connection point writes the temporary variable and the received notification method of the target connection point into the target connection point according to the notification type method to complete aspect weaving. 5.如权利要求4所述的系统,其特征在于,所述判断执行单元,具体用于在各所述通知类型方法中,分别判断所述目标连接点是否加载到相应的执行环境中;5. The system according to claim 4, wherein the judgment execution unit is specifically configured to respectively judge whether the target connection point is loaded into the corresponding execution environment in each of the notification type methods; 若是,则说明所述目标连接点在该通知类型中加载。If yes, it means that the target connection point is loaded in this notification type. 6.如权利要求4或5所述的系统,其特征在于,所述通知类型方法包括:前置通知、后置通知和包围通知。6. The system according to claim 4 or 5, wherein the notification type methods include: pre-notification, post-notification and surrounding notification.
CN201610142721.5A 2016-03-14 2016-03-14 Method and system for weaving aspects in JavaScript programs Expired - Fee Related CN105824665B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610142721.5A CN105824665B (en) 2016-03-14 2016-03-14 Method and system for weaving aspects in JavaScript programs

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610142721.5A CN105824665B (en) 2016-03-14 2016-03-14 Method and system for weaving aspects in JavaScript programs

Publications (2)

Publication Number Publication Date
CN105824665A CN105824665A (en) 2016-08-03
CN105824665B true CN105824665B (en) 2019-12-17

Family

ID=56987640

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610142721.5A Expired - Fee Related CN105824665B (en) 2016-03-14 2016-03-14 Method and system for weaving aspects in JavaScript programs

Country Status (1)

Country Link
CN (1) CN105824665B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8806431B1 (en) * 2007-12-03 2014-08-12 Appecelerator, Inc. Aspect oriented programming

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957766B (en) * 2010-09-17 2014-07-09 山东中创软件工程股份有限公司 Method, device and system for weaving byte code
CN103823919A (en) * 2013-11-18 2014-05-28 芜湖大学科技园发展有限公司 Distributed fault-tolerance aspect description weaving method for universal power data platforms
CN103714290B (en) * 2013-12-26 2016-08-17 北京工业大学 A kind of software action obtains, monitors and verification method

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8806431B1 (en) * 2007-12-03 2014-08-12 Appecelerator, Inc. Aspect oriented programming

Also Published As

Publication number Publication date
CN105824665A (en) 2016-08-03

Similar Documents

Publication Publication Date Title
US9092332B2 (en) Activity based sampling of diagnostics data
CN107092488B (en) Method and system for realizing non-invasive point burying of application
US11861394B2 (en) Automated semantic tagging
CN104375938B (en) Android application dynamic behavior monitoring method and system
US9552221B1 (en) Monitoring application execution using probe and profiling modules to collect timing and dependency information
US11586455B2 (en) Managing containers across multiple operating systems
WO2016112625A1 (en) System realizing script operation in preset embedded system
KR20150130298A (en) Operating system support for contracts
US20180121266A1 (en) Idempotent mode of executing commands triggered by complex event processing
US20190205242A1 (en) System and method for controlled data extraction in computer networks
CN114595462A (en) Data processing method and device
US9195550B2 (en) Method for guaranteeing program correctness using fine-grained hardware speculative execution
US20110191754A1 (en) System using a unique marker with each software code-block
CN110442404A (en) A kind of object method for releasing, device, equipment and storage medium
US8856763B2 (en) Compiler optimization based on collectivity analysis
US9489179B2 (en) Application programming interface tracing mechanism
TW202032395A (en) Data calculation method and engine
US20170091076A1 (en) Debugging remote vertex code on test machine
CN105824665B (en) Method and system for weaving aspects in JavaScript programs
US9395987B2 (en) Method and device for detecting a race condition
CN103019844B (en) A kind ofly support multithreading to call the method and apparatus of MPI function
US9250878B1 (en) Function attribute for dynamic stack allocation
CN112445683A (en) Multi-switch detection bypass method, storage medium, device and system
CN105487852A (en) Policy mode based multi-thread management method for signal generator
CN103365690B (en) In OSGi, application resource loads the intermodule resource loading method of appointing inversion mechanism

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20191217