Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
10 changed files
with
353 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Code taken from Danne Lundqvist with custom modification | ||
* http://www.dotvoid.com/2005/06/aspect-oriented-programming-and-javascript/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var InvalidAspect = new Error("Missing a valid aspect. Aspect is not a function."); | ||
var InvalidObject = new Error("Missing valid object or an array of valid objects."); | ||
var InvalidMethod = new Error("Missing valid method to apply aspect on."); | ||
|
||
function doAround(func, aroundFunc){ | ||
return function(){ | ||
aroundFunc.prototype._innerFunc = func | ||
|
||
return aroundFunc.apply(this,arguments) | ||
}; | ||
} | ||
|
||
Aspects = function(){}; | ||
Aspects.prototype={ | ||
|
||
|
||
addIntroduction : function(aspect, objs){ | ||
function _addIntroduction(intro, obj){ | ||
for (var m in intro.prototype) { | ||
obj.prototype[m] = intro.prototype[m]; | ||
} | ||
} | ||
var oType = typeof(objs); | ||
|
||
if (typeof(aspect) != 'function') | ||
throw(InvalidAspect); | ||
|
||
if (oType == 'function'){ | ||
_addIntroduction(aspect, objs); | ||
} | ||
else if (oType == 'object'){ | ||
for (var n = 0; n < objs.length; n++){ | ||
_addIntroduction(aspect, objs[n]); | ||
} | ||
} | ||
else{ | ||
throw InvalidObject; | ||
} | ||
}, | ||
|
||
addAround : function(aspect, obj, funcs){ | ||
if (typeof(aspect) != 'function') | ||
throw InvalidAspect; | ||
|
||
if (typeof(funcs) != 'object') | ||
funcs = Array(funcs); | ||
|
||
for (var n = 0; n < funcs.length; n++) | ||
{ | ||
var fName = funcs[n]; | ||
var old; | ||
if(obj){ | ||
old = obj.prototype[fName]; | ||
} | ||
if (!old) | ||
throw InvalidMethod; | ||
|
||
var res = doAround(old,aspect); | ||
obj.prototype[fName] = res; | ||
} | ||
|
||
} | ||
|
||
} | ||
exports.addIntroduction = Aspects.prototype.addIntroduction | ||
exports.addAround = Aspects.prototype.addAround |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Code taken from Danne Lundqvist with custom modification | ||
* http://www.dotvoid.com/2005/06/aspect-oriented-programming-and-javascript/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var aop = require('../lib/engine/aop.js') | ||
module.exports = { | ||
'naive' : function(test){ | ||
function Document(){} | ||
Document.prototype = { | ||
_id: 0, | ||
_name: '', | ||
|
||
name: function() { | ||
return this._name; | ||
}, | ||
|
||
id: function() { | ||
return this._id; | ||
}, | ||
|
||
save: function() { | ||
return true; | ||
}, | ||
|
||
open: function(id) { | ||
this._id = id; | ||
this._name = 'Ajax on AOP steroids' | ||
return true; | ||
} | ||
} | ||
function openDocument(id) | ||
{ | ||
var doc = new Document(); | ||
try { | ||
doc.open(id); | ||
} | ||
catch(e) | ||
{ | ||
alert(e); | ||
return; | ||
} | ||
|
||
// Update icons and other user elements affected alert("Doc id: " + doc.id()); | ||
return doc; | ||
} | ||
function Lockable(){} | ||
Lockable.prototype = { | ||
_locked: false, | ||
|
||
locked: function() { | ||
return this._locked; | ||
} | ||
} | ||
function lockOnOpen() | ||
{ | ||
// Lock this object | ||
// If we didn't succeed | ||
//throw (new Error ("Failed locking " + this._name)); | ||
|
||
// The object is locked | ||
this._locked = true; | ||
var ret = arguments[0].apply(this, arguments) | ||
return ret; | ||
} | ||
try { | ||
aop.addIntroduction(Lockable, Document); | ||
aop.addAround(lockOnOpen, Document, "open"); | ||
test.done() | ||
} | ||
catch(e) | ||
{ | ||
console.log('epic fail') | ||
} | ||
} | ||
} |
Oops, something went wrong.