Enable "strict" mode for NodeJS
Summary:
In particular, this changes the behavior of NodeJS in the following ways:
- Any attempt to get or modify the global object will result in an error.
- `null` values of `this` will no longer be evaluated to the global object and primitive values of this will not be converted to wrapper objects.
- Writing or deleting properties which have there writeable or configurable attributes set to false will now throw an error instead of failing silently.
- Adding a property to an object whose extensible attribute is false will also throw an error now.
- A functions arguments are not writeable so attempting to change them will now throw an error `arguments = [...]`.
- `with(){}` statements are gone.
- Use of `eval` is effectively banned.
- `eval` and `arguments` are not allowed as variable or function identifiers in any scope.
- The identifiers `implements`, `interface`, `let`, `package`, `private`, `protected`, `public`, `static` and `yield` are all now reserved for future use (roll on ES6).
Test Plan: Verified that Aphlict was still functional.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D11430
2015-01-19 21:41:46 +01:00
|
|
|
'use strict';
|
|
|
|
|
2015-01-19 20:46:14 +01:00
|
|
|
var JX = require('./javelin').JX;
|
2014-02-18 01:00:51 +01:00
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
JX.install('AphlictLog', {
|
Make the Aphlict server more resilient.
Summary:
Currently, the Aphlict server will crash if invalid JSON data is `POST`ed to it. I have fixed this to, instead, return a 400. Also made some minor formatting changes.
Ref T4324. Ref T5284. Also, modify the data structure that is passed around (i.e. `POST`ed to the Aphlict server and broadcast to the Aphlict clients) to include the subscribers. Initially, I figured that we shouldn't expose this information to the clients... however, it is necessary for T4324 that the `AphlictMaster` is able to route a notification to the appropriate clients.
Test Plan:
Making the following `curl` request: `curl --data "{" http://localhost:22281/`.
**Before**
```
sudo ./bin/aphlict debug
Starting Aphlict server in foreground...
Launching server:
$ 'nodejs' '/usr/src/phabricator/src/applications/aphlict/management/../../../../support/aphlict/server/aphlict_server.js' --port='22280' --admin='22281' --host='localhost' --user='aphlict'
[Wed Jun 11 2014 17:07:51 GMT+0000 (UTC)] Started Server (PID 2033)
[Wed Jun 11 2014 17:07:55 GMT+0000 (UTC)]
<<< UNCAUGHT EXCEPTION! >>>
SyntaxError: Unexpected end of input
>>> Server exited!
```
**After**
(No output... the bad JSON is caught and a 400 is returned)
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley, Korvin
Maniphest Tasks: T4324, T5284
Differential Revision: https://secure.phabricator.com/D9480
2014-06-11 19:16:31 +02:00
|
|
|
construct: function() {
|
2015-01-18 21:48:48 +01:00
|
|
|
this._consoles = [];
|
|
|
|
this._logs = [];
|
2014-02-18 01:00:51 +01:00
|
|
|
},
|
|
|
|
|
Make the Aphlict server more resilient.
Summary:
Currently, the Aphlict server will crash if invalid JSON data is `POST`ed to it. I have fixed this to, instead, return a 400. Also made some minor formatting changes.
Ref T4324. Ref T5284. Also, modify the data structure that is passed around (i.e. `POST`ed to the Aphlict server and broadcast to the Aphlict clients) to include the subscribers. Initially, I figured that we shouldn't expose this information to the clients... however, it is necessary for T4324 that the `AphlictMaster` is able to route a notification to the appropriate clients.
Test Plan:
Making the following `curl` request: `curl --data "{" http://localhost:22281/`.
**Before**
```
sudo ./bin/aphlict debug
Starting Aphlict server in foreground...
Launching server:
$ 'nodejs' '/usr/src/phabricator/src/applications/aphlict/management/../../../../support/aphlict/server/aphlict_server.js' --port='22280' --admin='22281' --host='localhost' --user='aphlict'
[Wed Jun 11 2014 17:07:51 GMT+0000 (UTC)] Started Server (PID 2033)
[Wed Jun 11 2014 17:07:55 GMT+0000 (UTC)]
<<< UNCAUGHT EXCEPTION! >>>
SyntaxError: Unexpected end of input
>>> Server exited!
```
**After**
(No output... the bad JSON is caught and a 400 is returned)
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: epriestley, Korvin
Maniphest Tasks: T4324, T5284
Differential Revision: https://secure.phabricator.com/D9480
2014-06-11 19:16:31 +02:00
|
|
|
members: {
|
2015-01-18 21:48:48 +01:00
|
|
|
_consoles: null,
|
|
|
|
_logs: null,
|
2020-04-14 22:17:41 +02:00
|
|
|
_trace: null,
|
|
|
|
|
|
|
|
setTrace: function(trace) {
|
|
|
|
this._trace = trace;
|
|
|
|
return this;
|
|
|
|
},
|
2014-02-18 01:00:51 +01:00
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
addConsole: function(console) {
|
|
|
|
this._consoles.push(console);
|
2014-02-18 01:00:51 +01:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
addLog: function(path) {
|
|
|
|
this._logs.push(fs.createWriteStream(path, {
|
|
|
|
flags: 'a',
|
|
|
|
encoding: 'utf8',
|
Enable "strict" mode for NodeJS
Summary:
In particular, this changes the behavior of NodeJS in the following ways:
- Any attempt to get or modify the global object will result in an error.
- `null` values of `this` will no longer be evaluated to the global object and primitive values of this will not be converted to wrapper objects.
- Writing or deleting properties which have there writeable or configurable attributes set to false will now throw an error instead of failing silently.
- Adding a property to an object whose extensible attribute is false will also throw an error now.
- A functions arguments are not writeable so attempting to change them will now throw an error `arguments = [...]`.
- `with(){}` statements are gone.
- Use of `eval` is effectively banned.
- `eval` and `arguments` are not allowed as variable or function identifiers in any scope.
- The identifiers `implements`, `interface`, `let`, `package`, `private`, `protected`, `public`, `static` and `yield` are all now reserved for future use (roll on ES6).
Test Plan: Verified that Aphlict was still functional.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D11430
2015-01-19 21:41:46 +01:00
|
|
|
mode: '0664',
|
2015-01-18 21:48:48 +01:00
|
|
|
}));
|
2014-02-18 01:00:51 +01:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2020-04-14 22:17:41 +02:00
|
|
|
trace: function() {
|
|
|
|
if (!this._trace) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.log.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
2014-06-30 22:00:12 +02:00
|
|
|
log: function() {
|
2014-02-18 01:00:51 +01:00
|
|
|
var str = util.format.apply(null, arguments);
|
|
|
|
var date = new Date().toLocaleString();
|
|
|
|
str = '[' + date + '] ' + str;
|
|
|
|
|
|
|
|
var ii;
|
2015-01-18 21:48:48 +01:00
|
|
|
for (ii = 0; ii < this._consoles.length; ii++) {
|
|
|
|
this._consoles[ii].log(str);
|
2014-02-18 01:00:51 +01:00
|
|
|
}
|
|
|
|
|
2015-01-18 21:48:48 +01:00
|
|
|
for (ii = 0; ii < this._logs.length; ii++) {
|
|
|
|
this._logs[ii].write(str + '\n');
|
2014-02-18 01:00:51 +01:00
|
|
|
}
|
2015-01-18 21:48:48 +01:00
|
|
|
},
|
|
|
|
},
|
2014-02-18 01:00:51 +01:00
|
|
|
});
|