Skip to content

Commit 3cc609a

Browse files
author
Robert Jackson
committed
Merge branch 'demonstrate-prototype-mutation-failures' into build-vm-context-per-visit
2 parents 79d57c0 + 43462e2 commit 3cc609a

File tree

9 files changed

+66347
-0
lines changed

9 files changed

+66347
-0
lines changed

test/fastboot-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,27 @@ describe('FastBoot', function() {
400400
expect(html).to.match(/Other Config {"default":"bar"}/);
401401
});
402402
});
403+
404+
it('in app prototype mutations do not leak across visits', async function() {
405+
this.timeout(3000);
406+
407+
var fastboot = new FastBoot({
408+
distPath: fixture('app-with-prototype-mutations'),
409+
});
410+
411+
let result = await fastboot.visit('/');
412+
let html = await result.html();
413+
414+
expect(html).to.match(/Items: 1/);
415+
416+
result = await fastboot.visit('/');
417+
html = await result.html();
418+
419+
expect(html).to.match(/Items: 1/);
420+
421+
result = await fastboot.visit('/');
422+
html = await result.html();
423+
424+
expect(html).to.match(/Items: 1/);
425+
});
403426
});
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
define('~fastboot/app-factory', ['app-with-mutable-prototype/app', 'app-with-mutable-prototype/config/environment'], function(App, config) {
2+
App = App['default'];
3+
config = config['default'];
4+
5+
return {
6+
'default': function() {
7+
return App.create(config.APP);
8+
}
9+
};
10+
});
11+
12+
define("app-with-mutable-prototype/initializers/ajax", ["exports"], function (_exports) {
13+
"use strict";
14+
15+
Object.defineProperty(_exports, "__esModule", {
16+
value: true
17+
});
18+
_exports.default = void 0;
19+
const {
20+
get
21+
} = Ember;
22+
23+
var nodeAjax = function (options) {
24+
let httpRegex = /^https?:\/\//;
25+
let protocolRelativeRegex = /^\/\//;
26+
let protocol = get(this, 'fastboot.request.protocol');
27+
28+
if (protocolRelativeRegex.test(options.url)) {
29+
options.url = protocol + options.url;
30+
} else if (!httpRegex.test(options.url)) {
31+
try {
32+
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
33+
} catch (fbError) {
34+
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
35+
}
36+
}
37+
38+
if (najax) {
39+
najax(options);
40+
} else {
41+
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
42+
}
43+
};
44+
45+
var _default = {
46+
name: 'ajax-service',
47+
initialize: function (application) {
48+
application.register('ajax:node', nodeAjax, {
49+
instantiate: false
50+
});
51+
application.inject('adapter', '_ajaxRequest', 'ajax:node');
52+
application.inject('adapter', 'fastboot', 'service:fastboot');
53+
}
54+
};
55+
_exports.default = _default;
56+
});
57+
define("app-with-mutable-prototype/initializers/error-handler", ["exports"], function (_exports) {
58+
"use strict";
59+
60+
Object.defineProperty(_exports, "__esModule", {
61+
value: true
62+
});
63+
_exports.default = void 0;
64+
65+
/**
66+
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
67+
* exceptions and other errors and prevents the node process from crashing.
68+
*
69+
*/
70+
var _default = {
71+
name: 'error-handler',
72+
initialize: function () {
73+
if (!Ember.onerror) {
74+
// if no onerror handler is defined, define one for fastboot environments
75+
Ember.onerror = function (err) {
76+
const errorMessage = "There was an error running your app in fastboot. More info about the error: \n ".concat(err.stack || err);
77+
console.error(errorMessage);
78+
};
79+
}
80+
}
81+
};
82+
_exports.default = _default;
83+
});//# sourceMappingURL=app-with-mutable-prototype-fastboot.map

test/fixtures/app-with-prototype-mutations/assets/app-with-mutable-prototype-fastboot.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/app-with-prototype-mutations/assets/app-with-mutable-prototype.js

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/app-with-prototype-mutations/assets/app-with-mutable-prototype.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)