CN105824665A - Weaving method and system for aspects in JavaScript program - Google Patents

Weaving method and system for aspects in JavaScript program Download PDF

Info

Publication number
CN105824665A
CN105824665A CN201610142721.5A CN201610142721A CN105824665A CN 105824665 A CN105824665 A CN 105824665A CN 201610142721 A CN201610142721 A CN 201610142721A CN 105824665 A CN105824665 A CN 105824665A
Authority
CN
China
Prior art keywords
junction point
target junction
described target
notification type
notification
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.)
Granted
Application number
CN201610142721.5A
Other languages
Chinese (zh)
Other versions
CN105824665B (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
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

Abstract

The invention discloses a weaving method and system for aspects in the JavaScript program. The method comprises the following steps: establishing a multi-thread execution environment; starting a thread, implementing an notification type method in an AOP object, and judging whether a pre-stated target connection point is loaded; if the pre-stated target connection point is loaded, starting another thread, storing the target connection point with a temporary variable, writing the temporary variable and a received notification method of the target connection point into the target connection point according to the notification type method, to complete aspect weaving; if the pre-stated target connection point is not loaded, continuously judging whether the target connection point is loaded. According to the weaving method, a multi-thread operation environment is simulated in a single-thread operation environment of JavaScript, and then an object monitoring thread is started in the multi-thread operation environment to monitor loading of the object; after the object is loaded, an aspect is inserted into the object immediately, to avoid the phenomenon that the aspect cannot be stated until the target connection point is loaded to the object in the prior art, so that the problem of failure of aspect weaving into the target connection point is solved.

Description

In a kind of JavaScript program, aspect inweaves method and system
Technical field
The present invention relates to field of computer technology, particularly relate to aspect in a kind of JavaScript program inweaves method and system.
Background technology
JavaScript is a kind of to aim at that webpage is mutual and the script that designs, is obtained for and is widely applied in almost all of Web applies.Growing along with Web application technology, the complexity of program is more and more higher, and this just makes the exploitation of JavaScript program therein and safeguards more and more difficult.As an important component part of Web, the importance of JavaScript is self-evident.People generally utilize OOP (ObjectOrientedProgramming, OOP) go to simplify exploitation and the maintenance process of JavaScript, but due to its limitation, the redundant code that a large amount of functions are identical too increases the development and maintenance cost of JavaScript.
Crosscutting concerns is encapsulated in aspect (Aspect) by AOP (AspectOrientedProgramming, towards tangent plane programming), it is achieved thereby that the unified management of crosscutting concerns and maintenance, and then reduce the complexity of system development.One aspect comprises point of penetration (Pointcut) and notice (Advice) two parts, wherein point of penetration definition is that some notifies that this one group of junction point (JointPoint) when performed, junction point then represent the foreseeable point of in a program process.After target junction point is inweaved aspect, when it performs, the notice in the aspect inweaved also can correspondingly be performed.Therefore, exploitation and maintenance that AOP is applied to JavaScript have highly important meaning.
At present, a lot of scholars achieve the JavaScript framework of the AOP of lightweight, and AspectJS is the most ripe and the most comprehensive one.AspectJS is a JavaScript assembly having the AOP controlling power completely to method call interception, it is according to the dynamic characteristic of JavaScript language, Application way calls interception (MCI) technology and performs other method before and after invocation target function, and the method that this aggregate function transparent to caller calls is exactly the ultimate principle that AspectJS realizes AOP.The method call that AspectJS is intercepted provides and controls completely and perfect management, makes the JavaScript programming of AOP become the simplest.But, this framework otherwise must can cause crochet to can not find target junction point because of JavaScript program execution sequence for the statement of aspect after the statement of junction point target, and causes the failure that aspect inweaves.
AOJS is the JavaScript framework of an AOP being different from AspectJS, uses XML file to go definition aspect with the AOJS that is not both of its maximum, then goes inweaving in terms of execution by a proxy server.The shortcoming of the JavaScript framework maximum of conventional AOP is exactly that aspect is not completely separated with source code, result of this is that when aspect inweaves source code, the problem that may cause some program reliabilities.And aspect and source code are kept completely separate by AOJS, operationally aspect is inweaved source code by proxy server, eliminate the definition aspect invasive to source code.But, the advantage having abandoned the characteristic of speech sounds of JavaScript itself due to AOJS completely, utilizing external program to go to revise the JavaScript program in Web application by predefined XML file, it is complicated that this just makes that Web project application AOP becomes difficulty, it is difficult to test.Meanwhile, the proxy server that AOJS needs too increases the cost of Web application.
AspectScript is a kind of to use high-order programming and dynamic designs the JavaScript framework of AOP of maturation of core for it.According to the dynamic characteristic of JavaScript language, the dynamic dispatching in terms of AspectScript support.Simultaneously as AspectScript takes full advantage of the advantage of high-order programming so that the definition for point of contact and aspect is more accurate, and combination domain policy, therefore AspectScript provides the accurate control for aspect.Finally, AspectScript not only supports implicit expression junction point, but also provides the possibility of accurate definition User Defined junction point, thus provides the probability of abundant extension for framework.AspectScript is for AspectJS, function more comprehensive and abundant, but it still has the deficiency the same with AspectJS, the i.e. statement of target junction point and aspect and has the sequencing of strict execution, thus target junction point can be caused in some cases to inweave aspect failure.
The JavaScript programming realization of three of the above AOP mainly goes to realize by static and dynamic two ways.Owing to JavaScript is interpreted languages, need not move through compiler to be compiled, therefore the static aspect that inweaves needs to go to revise source file according to the aspect file that predefined is good by external program, and AOJS is through the JavaScript programming of the AOP that this method realizes.Aspect is all defined in XML file by this framework, then uses other program to go to resolve these XML file, will be defined on aspect therein and be knitted in JavaScript program.But such mode abandons the feature of JavaScript language dynamic completely, it is achieved the most sufficiently complex, the most most realization is all to utilize the characteristic of speech sounds of JavaScript to go to be done dynamically inweaving of aspect.And be similar to the such reality of AspectJS and AspectScript and load now for junction point and sequentially considering of inweaving of aspect the most comprehensive, the realization programmed for the JavaScript of AOP is also comprehensive not, thus may result in target junction point and inweave the failure of aspect.
Summary of the invention
The embodiment of the present invention inweaves method and system by provide aspect in a kind of JavaScript program, solve the statement of target junction point and aspect in prior art and must have the technical problem of the sequencing of strict execution, it is achieved that avoid target junction point to inweave the technique effect that aspect is failed.
Embodiments provide aspect in a kind of JavaScript program inweaves method, including:
Create multithreading and perform environment;
Open a thread, perform the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
If loading, opening another thread, preserving described target junction point by temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect;
If not loading, continue to judge whether described target junction point loads.
Further, one thread of described unlatching, perform the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads, and specifically includes:
Create AOP object;
In at least 3 described notification type methods defined in described AOP object;
It is stored in described target junction point and Notification Method thereof in each described notification type method;
In each described notification type method, judge whether described target junction point loads respectively;
Load if described, open another thread, preserve described target junction point by temporary variable, specifically include:
If described target junction point loads in notification type method any one described, then open another thread, preserve described target junction point by described temporary variable.
Further, described judge whether described target junction point loads, specifically include:
Judge whether described target junction point is loaded into corresponding execution in environment;
The most then illustrate that described target junction point loads.
Further, described notification type method includes: preposition notice, rearmounted notice and encirclement notice.
The present invention provide JavaScript program in aspect inweave system, including:
Multithreading creation module, is used for creating multithreading and performs environment;
Judge module, for opening a thread, performs the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
Aspect inweaves module, if the judged result for described judge module is loading, open another thread, described target junction point is preserved by temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect.
Further, described judge module, specifically include:
AOP Object Creation unit, is used for creating AOP object;
Notification type creating unit, at least 3 described notification type methods defined in described AOP object;
Information receiving unit, for being stored in described target junction point and Notification Method thereof in each described notification type method;
Judge performance element, in each described notification type method, judge whether described target junction point loads respectively;
Described aspect inweaves module, if the judged result specifically for described judgement performance element is that described target junction point loads in notification type method any one described, then open another thread, described target junction point is preserved by described temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect.
Further, described judgement performance element, specifically in each described notification type method, judge whether described target junction point is loaded into corresponding execution in environment respectively;
The most then illustrate that described target junction point loads in this notification type.
Further, described notification type method includes: preposition notice, rearmounted notice and encirclement notice.
The one or more technical schemes provided in the embodiment of the present invention, at least have the following technical effect that or advantage:
First in single-threaded JavaScript running environment, simulate multithreading running environment, recycling is opened an object watcher thread in multi-thread environment and is carried out the loading of monitored object, after object loads, at once it is inweaved aspect, avoid in prior art must after target junction point is loaded into object could statement in terms of execution, thus solve target junction point and inweave the problem that aspect is failed.
Accompanying drawing explanation
The flow chart of the method that inweaves of aspect in the JavaScript program that Fig. 1 provides for the embodiment of the present invention one;
The module map of the system that inweaves of aspect in the JavaScript program that Fig. 2 provides for the embodiment of the present invention two.
Detailed description of the invention
The embodiment of the present invention inweaves method and system by provide aspect in a kind of JavaScript program, solve the statement of target junction point and aspect in prior art and must have the technical problem of the sequencing of strict execution, it is achieved that avoid target junction point to inweave the technique effect that aspect is failed.
Technical scheme in the embodiment of the present invention is for solving above-mentioned technical problem, and general thought is as follows:
First in single-threaded JavaScript running environment, simulate multithreading running environment, recycling is opened an object watcher thread in multi-thread environment and is carried out the loading of monitored object, after object loads, at once it is inweaved aspect, avoid in prior art must after target junction point is loaded into object could statement in terms of execution, thus solve target junction point and inweave the problem that aspect is failed.
In order to be more fully understood that technique scheme, below in conjunction with Figure of description and specific embodiment, technique scheme is described in detail.
Embodiment one
See Fig. 1, in the JavaScript program that the embodiment of the present invention provides aspect inweave method, including:
Step S110: create multithreading and perform environment;
This step is illustrated, is firstly introduced into Concurrent.Thread.js storehouse, and the notice being prepared as each AOP object calls one monitoring thread of establishment, and call incoming junction point and Notification Method to this notice.
Step S120: open a thread, performs the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
Step S130: if loading, open another thread, preserves target junction point by temporary variable, and type method is by the Notification Method write target junction point of temporary variable with the target junction point received as per advice, completes inweaving of aspect;
If not loading, continue to judge whether target junction point loads.
Specifically, step S120 is specifically described, including:
Create AOP object;
In the present embodiment, the Notification Method giving tacit consent to all junction points is the attribute of window, is accomplished by order to create the basic code of the AOP object of all kinds of notice
In at least 3 notification type methods defined in AOP object;
In the present embodiment, notification type method includes: preposition notice, rearmounted notice and encirclement notice, i.e. before, after and around.
It is stored in target junction point and Notification Method thereof in each notification type method;
In each notification type method, judge whether target junction point loads respectively;
In the present embodiment, it is judged that whether target junction point loads, and specifically includes:
Judge whether target junction point is loaded into corresponding execution in environment;
The most then explanation target junction point loads.
Specifically, after target junction point is loaded into above window object, call aspect crochet weaver.If also not loading, then in current thread, continue executing with monitoring.The code of one aspect of statement is as follows:
Junction point target is saved in a temp variable by weaver, then according to notification function is encapsulated in aspect method together with temp by the type of notice, finally aspect method is assigned to junction point target, completes inweaving of aspect.
The basic function of weaver method is accomplished by
In this case, if loading in step S130, open another thread, preserve target junction point by temporary variable, specifically include:
If target junction point loads in any one notification type method, then open another thread, preserve target junction point by temporary variable.
Embodiment two
See Fig. 2, in the JavaScript program that the embodiment of the present invention provides aspect inweave system, including:
Multithreading creation module 100, is used for creating multithreading and performs environment;
In the present embodiment, multithreading creation module 100, specifically for introducing Concurrent.Thread.js storehouse, and the notice being prepared as each AOP object calls one monitoring thread of establishment, and calls incoming junction point and Notification Method to this notice.
Judge module 200, for opening a thread, performs the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
Aspect inweaves module 300, if the judged result for judge module 200 is loading, opens another thread, preserve target junction point by temporary variable, type method is by the Notification Method write target junction point of temporary variable with the target junction point received as per advice, completes inweaving of aspect.
In the present embodiment, it is judged that module 200, specifically include:
AOP Object Creation unit, is used for creating AOP object;
Notification type creating unit, at least 3 notification type methods defined in AOP object;
In the present embodiment, notification type method includes: preposition notice, rearmounted notice and encirclement notice, i.e. before, after and around.
Information receiving unit, for being stored in target junction point and Notification Method thereof in each notification type method;
Judge performance element, in each notification type method, judge whether target junction point loads respectively;
In the present embodiment, it is judged that performance element, specifically in each notification type method, judge whether target junction point is loaded into corresponding execution in environment respectively;
The most then explanation target junction point loads in this notification type.
In this case, aspect inweaves module 300, if specifically for judging that the judged result of performance element is that target junction point loads in any one notification type method, then open another thread, target junction point is preserved by temporary variable, type method is by the Notification Method write target junction point of temporary variable with the target junction point received as per advice, completes inweaving of aspect.
[technique effect]
First in single-threaded JavaScript running environment, simulate multithreading running environment, recycling is opened an object watcher thread in multi-thread environment and is carried out the loading of monitored object, after object loads, at once it is inweaved aspect, avoid in prior art must after target junction point is loaded into object could statement in terms of execution, thus solve target junction point and inweave the problem that aspect is failed.
Those skilled in the art are it should be appreciated that embodiments of the invention can be provided as method, system or computer program.Therefore, the form of the embodiment in terms of the present invention can use complete hardware embodiment, complete software implementation or combine software and hardware.And, the present invention can use the form at one or more upper computer programs implemented of computer-usable storage medium (including but not limited to disk memory, CD-ROM, optical memory etc.) wherein including computer usable program code.
The present invention is to describe with reference to method, equipment (system) and the flow chart of computer program according to embodiments of the present invention and/or block diagram.It should be understood that can be by the flow process in each flow process in computer program instructions flowchart and/or block diagram and/or square frame and flow chart and/or block diagram and/or the combination of square frame.These computer program instructions can be provided to produce a machine to the processor of general purpose computer, special-purpose computer, Embedded Processor or other programmable data processing device so that the instruction performed by the processor of computer or other programmable data processing device is produced for realizing the device of function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions may be alternatively stored in and can guide in the computer-readable memory that computer or other programmable data processing device work in a specific way, the instruction making to be stored in this computer-readable memory produces the manufacture including command device, and this command device realizes the function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame.
These computer program instructions also can be loaded in computer or other programmable data processing device, make to perform sequence of operations step on computer or other programmable devices to produce computer implemented process, thus the instruction performed on computer or other programmable devices provides the step of the function specified in one flow process of flow chart or multiple flow process and/or one square frame of block diagram or multiple square frame for realization.
Although preferred embodiments of the present invention have been described, but those skilled in the art once know basic creative concept, then these embodiments can be made other change and amendment.So, claims are intended to be construed to include preferred embodiment and fall into all changes and the amendment of the scope of the invention.
Obviously, those skilled in the art can carry out various change and modification without departing from the spirit and scope of the present invention to the present invention.So, if these amendments of the present invention and modification belong within the scope of the claims in the present invention and equivalent technologies thereof, then the present invention is also intended to comprise these change and modification.

Claims (8)

1. in a JavaScript program aspect inweave method, it is characterised in that including:
Create multithreading and perform environment;
Open a thread, perform the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
If loading, opening another thread, preserving described target junction point by temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect;
If not loading, continue to judge whether described target junction point loads.
2. the method for claim 1, it is characterised in that one thread of described unlatching, performs the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads, and specifically includes:
Create AOP object;
In at least 3 described notification type methods defined in described AOP object;
It is stored in described target junction point and Notification Method thereof in each described notification type method;
In each described notification type method, judge whether described target junction point loads respectively;
Load if described, open another thread, preserve described target junction point by temporary variable, specifically include:
If described target junction point loads in notification type method any one described, then open another thread, preserve described target junction point by described temporary variable.
3. method as claimed in claim 2, it is characterised in that described judge whether described target junction point loads, specifically includes:
Judge whether described target junction point is loaded into corresponding execution in environment;
The most then illustrate that described target junction point loads.
4. method as claimed in claim 2 or claim 3, it is characterised in that described notification type method includes: preposition notice, rearmounted notice and encirclement notice.
5. in a JavaScript program aspect inweave system, it is characterised in that including:
Multithreading creation module, is used for creating multithreading and performs environment;
Judge module, for opening a thread, performs the notification type method in AOP object, it is judged that whether the target junction point stated in advance loads;
Aspect inweaves module, if the judged result for described judge module is loading, open another thread, described target junction point is preserved by temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect.
6. system as claimed in claim 5, it is characterised in that described judge module, specifically includes:
AOP Object Creation unit, is used for creating AOP object;
Notification type creating unit, at least 3 described notification type methods defined in described AOP object;
Information receiving unit, for being stored in described target junction point and Notification Method thereof in each described notification type method;
Judge performance element, in each described notification type method, judge whether described target junction point loads respectively;
Described aspect inweaves module, if the judged result specifically for described judgement performance element is that described target junction point loads in notification type method any one described, then open another thread, described target junction point is preserved by described temporary variable, the Notification Method of described temporary variable with the described target junction point received is write described target junction point by type method as per advice, completes inweaving of aspect.
7. system as claimed in claim 6, it is characterised in that described judgement performance element, specifically in each described notification type method, judges whether described target junction point is loaded into corresponding execution in environment respectively;
The most then illustrate that described target junction point loads in this notification type.
System the most as claimed in claims 6 or 7, it is characterised in that described notification type method includes: preposition notice, rearmounted notice and encirclement notice.
CN201610142721.5A 2016-03-14 2016-03-14 Method and system for weaving aspects in JavaScript program Active 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 program

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 program

Publications (2)

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

Family

ID=56987640

Family Applications (1)

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

Country Status (1)

Country Link
CN (1) CN105824665B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101957766A (en) * 2010-09-17 2011-01-26 山东中创软件工程股份有限公司 Method, device and system for weaving byte code
CN103714290A (en) * 2013-12-26 2014-04-09 北京工业大学 Software behavior obtaining, monitoring and verifying method
CN103823919A (en) * 2013-11-18 2014-05-28 芜湖大学科技园发展有限公司 Distributed fault-tolerance aspect description weaving method for universal power data platforms
US8806431B1 (en) * 2007-12-03 2014-08-12 Appecelerator, Inc. Aspect oriented programming

Patent Citations (4)

* 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
CN101957766A (en) * 2010-09-17 2011-01-26 山东中创软件工程股份有限公司 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
CN103714290A (en) * 2013-12-26 2014-04-09 北京工业大学 Software behavior obtaining, monitoring and verifying method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
GITHUB: "ifsantos/aop.js", 《HTTPS://GIST.GITHUB.COM/2430820》 *

Also Published As

Publication number Publication date
CN105824665B (en) 2019-12-17

Similar Documents

Publication Publication Date Title
US10936293B2 (en) Container image layer reordering
US7703089B2 (en) Compatibility framework using versioning class loaders
CN107092488B (en) Method and system for realizing non-invasive point burying of application
CN107463500B (en) Debugging method, medium, system and computing device of test script
CN105183457B (en) Method and device for monitoring interface life cycle callback
US8615750B1 (en) Optimizing application compiling
US10908943B1 (en) Browser credential management for terminal server sessions
US11797692B2 (en) Tool for generating security policies for containers
US20120266149A1 (en) Class isolation to minimize memory usage in a device
CN106919398A (en) A kind of software distribution method and device
CN108762956A (en) Obtain method, server, mobile terminal and the storage medium of Native local datas
CN105183547A (en) Task scheduling method and device of user interface
US9304762B2 (en) Automatically customizing a computer-executable application at runtime
KR102118236B1 (en) Operating system support for contracts
CN105630491A (en) Method and device for changing functions of program
US10218585B2 (en) Container host discovery
CN108829422A (en) A kind of dynamic deployment method and device
CN113779578B (en) Intelligent confusion method and system for mobile terminal application
Riganelli et al. Healing data loss problems in android apps
CN110018866B (en) User interface theme updating method, device and system, vehicle machine and vehicle
CN105824665A (en) Weaving method and system for aspects in JavaScript program
CN107622063B (en) Page switching method and device for avoiding white pages
US20160170739A1 (en) Alter application behaviour during runtime
US11537418B2 (en) Simulated change of immutable objects during execution runtime
CN108762753A (en) Page assembly amending method and equipment

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