Commit f69c54b2 authored by Romain Courteaud's avatar Romain Courteaud

Acquired method get the child scope as parameter.

parent ddaeb274
......@@ -89,8 +89,18 @@
/////////////////////////////////////////////////////////////////
// RenderJSGadget.declareAcquiredMethod
/////////////////////////////////////////////////////////////////
function acquire(method_name, argument_list) {
var gadget = this;
function acquire(child_gadget, method_name, argument_list) {
var gadget = this,
key,
gadget_scope;
for (key in gadget.__sub_gadget_dict) {
if (gadget.__sub_gadget_dict.hasOwnProperty(key)) {
if (gadget.__sub_gadget_dict[key] === child_gadget) {
gadget_scope = key;
}
}
}
return new RSVP.Queue()
.push(function () {
// Do not specify default __acquired_method_dict on prototype
......@@ -98,7 +108,8 @@
// allowPublicAcquiredMethod for example)
var aq_dict = gadget.__acquired_method_dict || {};
if (aq_dict.hasOwnProperty(method_name)) {
return aq_dict[method_name].apply(gadget, [argument_list]);
return aq_dict[method_name].apply(gadget,
[argument_list, gadget_scope]);
}
throw new renderJS.AcquisitionError("aq_dynamic is not defined");
})
......@@ -365,7 +376,8 @@
var i;
// Define __aq_parent to reach parent gadget
gadget_instance.__aq_parent = function (method_name, argument_list) {
return acquire.apply(parent_gadget, [method_name, argument_list]);
return acquire.apply(parent_gadget, [gadget_instance, method_name,
argument_list]);
};
// Drop the current loading klass info used by selector
gadget_loading_klass = undefined;
......
......@@ -2184,12 +2184,13 @@
gadget.__acquired_method_dict = {};
gadget.__acquired_method_dict[original_method_name] =
function (argument_list) {
function (argument_list, child_scope) {
aq_dynamic_called = true;
equal(this, gadget, "Context should be kept");
deepEqual(argument_list, original_argument_list,
"Argument list should be kept"
);
equal(child_scope, undefined, "No child scope if unknown");
return "FOO";
};
......@@ -2217,6 +2218,48 @@
});
});
test('__aq_parent propagate child_scope to acquired_method', function () {
var gadget = new RenderJSGadget(),
aq_dynamic_called = false,
original_method_name = "foo",
original_argument_list = ["foobar", "barfoo"],
html_url = 'http://example.org/files/qunittest/test353.html';
gadget.__acquired_method_dict = {};
gadget.__sub_gadget_dict = {};
gadget.__acquired_method_dict[original_method_name] =
function (argument_list, child_scope) {
aq_dynamic_called = true;
equal(this, gadget, "Context should be kept");
deepEqual(argument_list, original_argument_list,
"Argument list should be kept"
);
equal(child_scope, "bar", "Child scope should be provided");
};
this.server.respondWith("GET", html_url, [200, {
"Content-Type": "text/html"
}, "<html><body></body></html>"]);
stop();
gadget.declareGadget(html_url, {scope: "bar"})
.then(function (new_gadget) {
return new_gadget.__aq_parent(
original_method_name,
original_argument_list
);
})
.then(function (result) {
equal(aq_dynamic_called, true);
})
.fail(function (e) {
ok(false, e);
})
.always(function () {
start();
});
});
test('__aq_parent fails if aquired_method throws an error', function () {
var gadget = new RenderJSGadget(),
original_error = new Error("Custom error for the test"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment