Commit 83d1db17 authored by Romain Courteaud's avatar Romain Courteaud

onLoop: call the callback function with the gadget as 'this'

parent a5273d87
...@@ -512,6 +512,7 @@ ...@@ -512,6 +512,7 @@
} }
this.__service_list.push(function () { this.__service_list.push(function () {
var queue_loop = new RSVP.Queue(), var queue_loop = new RSVP.Queue(),
context = this,
wait = function () { wait = function () {
queue_loop queue_loop
.push(function () { .push(function () {
...@@ -522,7 +523,7 @@ ...@@ -522,7 +523,7 @@
return promiseAnimationFrame(); return promiseAnimationFrame();
}) })
.push(function () { .push(function () {
return callback.apply(this, []); return callback.apply(context, []);
}) })
.push(function () { .push(function () {
wait(); wait();
......
...@@ -2807,6 +2807,7 @@ ...@@ -2807,6 +2807,7 @@
klass.onLoop(function (evt) { klass.onLoop(function (evt) {
service_status.start_count += 1; service_status.start_count += 1;
service_status.this = this;
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
service_status.status = "started"; service_status.status = "started";
...@@ -2823,6 +2824,7 @@ ...@@ -2823,6 +2824,7 @@
test('callback is triggered on timeout', function () { test('callback is triggered on timeout', function () {
var service1 = {}, var service1 = {},
gadget = new RenderJSGadget(), gadget = new RenderJSGadget(),
sub_gadget,
html_url = 'https://example.org/files/qunittest/test599.html'; html_url = 'https://example.org/files/qunittest/test599.html';
gadget.__sub_gadget_dict = {}; gadget.__sub_gadget_dict = {};
...@@ -2832,7 +2834,7 @@ ...@@ -2832,7 +2834,7 @@
document.getElementById('qunit-fixture').innerHTML = "<div></div>"; document.getElementById('qunit-fixture').innerHTML = "<div></div>";
stop(); stop();
expect(9); expect(11);
renderJS.declareGadgetKlass(html_url) renderJS.declareGadgetKlass(html_url)
.then(function (Klass) { .then(function (Klass) {
declareTimeoutToCheck(Klass, service1); declareTimeoutToCheck(Klass, service1);
...@@ -2843,12 +2845,14 @@ ...@@ -2843,12 +2845,14 @@
); );
}) })
.then(function (g) { .then(function (g) {
sub_gadget = g;
return RSVP.delay(50); return RSVP.delay(50);
}) })
.then(function () { .then(function () {
equal(service1.start_count, 1); equal(service1.start_count, 1);
equal(service1.stop_count, 0); equal(service1.stop_count, 0);
equal(service1.status, "started"); equal(service1.status, "started");
equal(service1.this, sub_gadget);
service1.defer.resolve(); service1.defer.resolve();
return RSVP.delay(50); return RSVP.delay(50);
}) })
...@@ -2856,6 +2860,7 @@ ...@@ -2856,6 +2860,7 @@
equal(service1.start_count, 2); equal(service1.start_count, 2);
equal(service1.stop_count, 1); equal(service1.stop_count, 1);
equal(service1.status, "started"); equal(service1.status, "started");
equal(service1.this, sub_gadget);
return RSVP.delay(50); return RSVP.delay(50);
}) })
.then(function () { .then(function () {
......
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