|
@@ -191,29 +191,29 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
|
|
var methods = [], checker = Object.create(null);
|
|
var methods = [], checker = Object.create(null);
|
|
this.selectors = [];
|
|
this.selectors = [];
|
|
|
|
|
|
- this.get = function (string) {
|
|
|
|
- var index = this.selectors.indexOf(string);
|
|
|
|
|
|
+ this.get = function (stSelector) {
|
|
|
|
+ var index = this.selectors.indexOf(stSelector);
|
|
if(index !== -1) {
|
|
if(index !== -1) {
|
|
return methods[index];
|
|
return methods[index];
|
|
}
|
|
}
|
|
- this.selectors.push(string);
|
|
|
|
- var selector = st.selector(string);
|
|
|
|
- checker[selector] = true;
|
|
|
|
- var method = {jsSelector: selector, fn: createHandler(selector)};
|
|
|
|
|
|
+ this.selectors.push(stSelector);
|
|
|
|
+ var jsSelector = st.selector(stSelector);
|
|
|
|
+ checker[jsSelector] = true;
|
|
|
|
+ var method = {jsSelector: jsSelector, fn: createHandler(stSelector)};
|
|
methods.push(method);
|
|
methods.push(method);
|
|
manip.installMethod(method, rootAsClass);
|
|
manip.installMethod(method, rootAsClass);
|
|
return method;
|
|
return method;
|
|
};
|
|
};
|
|
|
|
|
|
- this.isSelector = function (selector) {
|
|
|
|
- return checker[selector];
|
|
|
|
|
|
+ this.isSelector = function (jsSelector) {
|
|
|
|
+ return checker[jsSelector];
|
|
};
|
|
};
|
|
|
|
|
|
/* Dnu handler method */
|
|
/* Dnu handler method */
|
|
|
|
|
|
- function createHandler(selector) {
|
|
|
|
|
|
+ function createHandler(stSelector) {
|
|
return function() {
|
|
return function() {
|
|
- return brikz.messageSend.messageNotUnderstood(this, selector, arguments);
|
|
|
|
|
|
+ return brikz.messageSend.messageNotUnderstood(this, stSelector, arguments);
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
@@ -987,43 +987,44 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
|
|
/* Handles unhandled errors during message sends */
|
|
/* Handles unhandled errors during message sends */
|
|
// simply send the message and handle #dnu:
|
|
// simply send the message and handle #dnu:
|
|
|
|
|
|
- st.send = function(receiver, selector, args, klass) {
|
|
|
|
|
|
+ st.send = function(receiver, jsSelector, args, klass) {
|
|
var method;
|
|
var method;
|
|
if(receiver === null) {
|
|
if(receiver === null) {
|
|
receiver = nil;
|
|
receiver = nil;
|
|
}
|
|
}
|
|
- method = klass ? klass.fn.prototype[selector] : receiver.klass && receiver[selector];
|
|
|
|
|
|
+ method = klass ? klass.fn.prototype[jsSelector] : receiver.klass && receiver[jsSelector];
|
|
if(method) {
|
|
if(method) {
|
|
return method.apply(receiver, args);
|
|
return method.apply(receiver, args);
|
|
} else {
|
|
} else {
|
|
- return messageNotUnderstood(receiver, selector, args);
|
|
|
|
|
|
+ return messageNotUnderstood(receiver, st.convertSelector(jsSelector), args);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- /* Handles #dnu: *and* JavaScript method calls.
|
|
|
|
- if the receiver has no klass, we consider it a JS object (outside of the
|
|
|
|
- Amber system). Else assume that the receiver understands #doesNotUnderstand: */
|
|
|
|
-
|
|
|
|
- function messageNotUnderstood(receiver, selector, args) {
|
|
|
|
- /* Handles JS method calls. */
|
|
|
|
- if(receiver.klass === undefined || receiver.allowJavaScriptCalls) {
|
|
|
|
- return callJavaScriptMethod(receiver, selector, args);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* Handles not understood messages. Also see the Amber counter-part
|
|
|
|
- Object>>doesNotUnderstand: */
|
|
|
|
-
|
|
|
|
|
|
+ function invokeDnuMethod(receiver, stSelector, args) {
|
|
return receiver._doesNotUnderstand_(
|
|
return receiver._doesNotUnderstand_(
|
|
globals.Message._new()
|
|
globals.Message._new()
|
|
- ._selector_(st.convertSelector(selector))
|
|
|
|
|
|
+ ._selector_(stSelector)
|
|
._arguments_([].slice.call(args))
|
|
._arguments_([].slice.call(args))
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
- /* Call a method of a JS object, or answer a property if it exists.
|
|
|
|
- Else try wrapping a JSObjectProxy around the receiver.
|
|
|
|
|
|
+ /* Handles #dnu: *and* JavaScript method calls.
|
|
|
|
+ if the receiver has no klass, we consider it a JS object (outside of the
|
|
|
|
+ Amber system). Else assume that the receiver understands #doesNotUnderstand: */
|
|
|
|
+ function messageNotUnderstood(receiver, stSelector, args) {
|
|
|
|
+ if (receiver.klass !== undefined && !receiver.allowJavaScriptCalls) {
|
|
|
|
+ return invokeDnuMethod(receiver, stSelector, args);
|
|
|
|
+ }
|
|
|
|
+ /* Call a method of a JS object, or answer a property if it exists.
|
|
|
|
+ Else try wrapping a JSObjectProxy around the receiver. */
|
|
|
|
+ var propertyName = st.st2prop(stSelector);
|
|
|
|
+ if (!(propertyName in receiver)) {
|
|
|
|
+ return invokeDnuMethod(globals.JSObjectProxy._on_(receiver), stSelector, args);
|
|
|
|
+ }
|
|
|
|
+ return accessJavaScript(receiver, propertyName, args);
|
|
|
|
+ }
|
|
|
|
|
|
- If the object property is a function, then call it, except if it starts with
|
|
|
|
|
|
+ /* If the object property is a function, then call it, except if it starts with
|
|
an uppercase character (we probably want to answer the function itself in this
|
|
an uppercase character (we probably want to answer the function itself in this
|
|
case and send it #new from Amber).
|
|
case and send it #new from Amber).
|
|
|
|
|
|
@@ -1032,24 +1033,19 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
|
|
|
|
|
|
Example:
|
|
Example:
|
|
"self do: aBlock with: anObject" -> "self.do(aBlock, anObject)" */
|
|
"self do: aBlock with: anObject" -> "self.do(aBlock, anObject)" */
|
|
-
|
|
|
|
- function callJavaScriptMethod(receiver, selector, args) {
|
|
|
|
- var jsSelector = st.st2prop(selector);
|
|
|
|
- if (jsSelector in receiver) {
|
|
|
|
- var jsProperty = receiver[jsSelector];
|
|
|
|
- if (typeof jsProperty === "function" && !/^[A-Z]/.test(jsSelector)) {
|
|
|
|
- return jsProperty.apply(receiver, args);
|
|
|
|
- } else if (args.length > 0) {
|
|
|
|
- receiver[jsSelector] = args[0];
|
|
|
|
- return nil;
|
|
|
|
- } else {
|
|
|
|
- return jsProperty;
|
|
|
|
- }
|
|
|
|
|
|
+ function accessJavaScript(receiver, propertyName, args) {
|
|
|
|
+ var propertyValue = receiver[propertyName];
|
|
|
|
+ if (typeof propertyValue === "function" && !/^[A-Z]/.test(propertyName)) {
|
|
|
|
+ return propertyValue.apply(receiver, args);
|
|
|
|
+ } else if (args.length > 0) {
|
|
|
|
+ receiver[propertyName] = args[0];
|
|
|
|
+ return nil;
|
|
|
|
+ } else {
|
|
|
|
+ return propertyValue;
|
|
}
|
|
}
|
|
-
|
|
|
|
- return st.send(globals.JSObjectProxy._on_(receiver), selector, args);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ st.accessJavaScript = accessJavaScript;
|
|
this.messageNotUnderstood = messageNotUnderstood;
|
|
this.messageNotUnderstood = messageNotUnderstood;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1110,7 +1106,6 @@ define("amber/boot", [ 'require', './browser-compatibility' ], function (require
|
|
}
|
|
}
|
|
|
|
|
|
st.st2prop = function (stSelector) {
|
|
st.st2prop = function (stSelector) {
|
|
- if (stSelector[0] === '_') return ''; // TODO revert when #1062 root cause fixed
|
|
|
|
var colonPosition = stSelector.indexOf(':');
|
|
var colonPosition = stSelector.indexOf(':');
|
|
return colonPosition === -1 ? stSelector : stSelector.slice(0, colonPosition);
|
|
return colonPosition === -1 ? stSelector : stSelector.slice(0, colonPosition);
|
|
};
|
|
};
|