Skip to content

Commit ae72a22

Browse files
committed
Code prepared for NODE_NEXT logic
1 parent 72ecc7f commit ae72a22

File tree

6 files changed

+186
-157
lines changed

6 files changed

+186
-157
lines changed

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
'variables': {
3-
'node_next': '<!(node -e "console.log(process.versions.modules > 45)")'
3+
'node_next': '<!(node -p -e "require(\'./tools/NODE_NEXT.js\')")'
44
},
55
'targets': [
66
{

test/binding.js

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -26,149 +26,4 @@ describe('binding', function() {
2626
});
2727
});
2828
});
29-
30-
describe('InjectedScriptHost', function() {
31-
var host = binding.InjectedScriptHost;
32-
33-
describe('function `subtype`', function() {
34-
checksTypeValid(new Array(), 'array');
35-
checksTypeValid(new Date(), 'date');
36-
checksTypeValid(new RegExp(), 'regexp');
37-
checksTypeValid(new Error(), 'error');
38-
checksTypeValid(new String(), undefined);
39-
40-
function checksTypeValid(value, type) {
41-
it('checks ' + type + ' subtype', function() {
42-
expect(host.subtype(value)).to.equal(type);
43-
});
44-
}
45-
46-
it('should throw on wrong arguments', function() {
47-
expect(host.subtype).to.throw();
48-
});
49-
});
50-
51-
describe('function `setNonEnumProperty`', function() {
52-
it('should set non enumerable property to object', function() {
53-
var object = {
54-
'visibleProp': '1'
55-
};
56-
host.setNonEnumProperty(object, 'hiddenProp', 'value');
57-
var keys = Object.keys(object);
58-
expect(keys).to.deep.equal(['visibleProp']);
59-
expect(object.hiddenProp).to.equal('value');
60-
});
61-
62-
throwsOnArgs([]);
63-
throwsOnArgs([{}, 'a']);
64-
throwsOnArgs([{}, null, 'b']);
65-
throwsOnArgs([null, {}, 'b']);
66-
67-
function throwsOnArgs(argvList) {
68-
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
69-
expect(host.setNonEnumProperty.bind.apply(
70-
host.setNonEnumProperty, [host].concat(argvList))).to.throw();
71-
});
72-
}
73-
74-
it('should not throw on valid arguments', function() {
75-
expect(host.setNonEnumProperty.bind(host, {}, 'a', null)).to.not.throw();
76-
expect(host.setNonEnumProperty.bind(host, {}, 'a', 'b')).to.not.throw();
77-
});
78-
});
79-
80-
describe('function `internalConstructorName`', function() {
81-
checksNameValid(new Number(), 'Number');
82-
checksNameValid(new Object(), 'Object');
83-
84-
function checksNameValid(value, name) {
85-
it('checks new ' + name + '() constructor name', function() {
86-
expect(host.internalConstructorName(value)).to.equal(name);
87-
});
88-
}
89-
90-
throwsOnArgs([]);
91-
throwsOnArgs([1]);
92-
throwsOnArgs([null]);
93-
94-
function throwsOnArgs(argvList) {
95-
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
96-
expect(host.internalConstructorName.bind.apply(
97-
host.internalConstructorName, [host].concat(argvList))).to.throw();
98-
});
99-
}
100-
});
101-
102-
describe('function `functionDetailsWithoutScopes`', function() {
103-
it('should return valid details', function() {
104-
function example() {}
105-
106-
var details = host.functionDetailsWithoutScopes(example);
107-
expect(details).to.include.keys(['location', 'functionName']);
108-
expect(details.location).to.include.keys(['lineNumber', 'columnNumber', 'scriptId']);
109-
});
110-
111-
throwsOnArgs([]);
112-
throwsOnArgs([null]);
113-
114-
function throwsOnArgs(argvList) {
115-
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
116-
expect(host.functionDetailsWithoutScopes.bind.apply(
117-
host.functionDetailsWithoutScopes, [host].concat(argvList))).to.throw();
118-
});
119-
}
120-
});
121-
122-
describe('function `eval`', function() {
123-
it('should evaluate expression', function() {
124-
expect(host.eval("[1]")).to.deep.equal([1]);
125-
});
126-
127-
it('should throw on wrong arguments', function() {
128-
expect(host.eval).to.throw();
129-
});
130-
131-
it('should throw on wrong expression', function() {
132-
expect(host.eval.bind(null, "[1")).to.throw(SyntaxError);
133-
});
134-
});
135-
136-
describe('function `evaluateWithExceptionDetails`', function() {
137-
it('should evaluate expression', function() {
138-
expect(host.evaluateWithExceptionDetails("[1]")).to.deep.equal({
139-
result: [1],
140-
exceptionDetails: undefined
141-
});
142-
});
143-
144-
it('should throw on wrong arguments', function() {
145-
expect(host.evaluateWithExceptionDetails).to.throw();
146-
});
147-
});
148-
149-
describe('function `callFunction`', function() {
150-
it('should call function without args', function(done) {
151-
host.callFunction(done, this);
152-
});
153-
154-
it('should call function with args', function(done) {
155-
host.callFunction(function(arg) {
156-
expect(arg).to.equal(1);
157-
done();
158-
}, this, [1]);
159-
});
160-
161-
it('should throw on wrong arguments', function() {
162-
expect(host.callFunction.bind(null, null, null, [1])).to.throw();
163-
expect(host.callFunction.bind(null, null, null, 1)).to.throw();
164-
});
165-
166-
it('should rethrow ReferenceError', function() {
167-
expect(host.callFunction.bind(null, function() {
168-
'use strict';
169-
if (error_here) return;
170-
}, this)).to.throw(ReferenceError);
171-
});
172-
});
173-
});
17429
});

test/injected-script.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
var expect = require('chai').expect;
2+
var binary = require('node-pre-gyp');
3+
var path = require('path');
4+
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
5+
var NODE_NEXT = require('../tools/NODE_NEXT.js');
6+
7+
if (!NODE_NEXT) return;
8+
9+
describe('binding', function() {
10+
var binding = require(binding_path);
11+
it('source was builded and can be accessed from script', function() {
12+
expect(binding.InjectedScriptHost).to.be.instanceof(Object);
13+
});
14+
15+
describe('InjectedScriptHost', function() {
16+
var host = binding.InjectedScriptHost;
17+
18+
describe('function `subtype`', function() {
19+
checksTypeValid(new Array(), 'array');
20+
checksTypeValid(new Date(), 'date');
21+
checksTypeValid(new RegExp(), 'regexp');
22+
checksTypeValid(new Error(), 'error');
23+
checksTypeValid(new String(), undefined);
24+
25+
function checksTypeValid(value, type) {
26+
it('checks ' + type + ' subtype', function() {
27+
expect(host.subtype(value)).to.equal(type);
28+
});
29+
}
30+
31+
it('should throw on wrong arguments', function() {
32+
expect(host.subtype).to.throw();
33+
});
34+
});
35+
36+
describe('function `setNonEnumProperty`', function() {
37+
it('should set non enumerable property to object', function() {
38+
var object = {
39+
'visibleProp': '1'
40+
};
41+
host.setNonEnumProperty(object, 'hiddenProp', 'value');
42+
var keys = Object.keys(object);
43+
expect(keys).to.deep.equal(['visibleProp']);
44+
expect(object.hiddenProp).to.equal('value');
45+
});
46+
47+
throwsOnArgs([]);
48+
throwsOnArgs([{}, 'a']);
49+
throwsOnArgs([{}, null, 'b']);
50+
throwsOnArgs([null, {}, 'b']);
51+
52+
function throwsOnArgs(argvList) {
53+
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
54+
expect(host.setNonEnumProperty.bind.apply(
55+
host.setNonEnumProperty, [host].concat(argvList))).to.throw();
56+
});
57+
}
58+
59+
it('should not throw on valid arguments', function() {
60+
expect(host.setNonEnumProperty.bind(host, {}, 'a', null)).to.not.throw();
61+
expect(host.setNonEnumProperty.bind(host, {}, 'a', 'b')).to.not.throw();
62+
});
63+
});
64+
65+
describe('function `internalConstructorName`', function() {
66+
checksNameValid(new Number(), 'Number');
67+
checksNameValid(new Object(), 'Object');
68+
69+
function checksNameValid(value, name) {
70+
it('checks new ' + name + '() constructor name', function() {
71+
expect(host.internalConstructorName(value)).to.equal(name);
72+
});
73+
}
74+
75+
throwsOnArgs([]);
76+
throwsOnArgs([1]);
77+
throwsOnArgs([null]);
78+
79+
function throwsOnArgs(argvList) {
80+
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
81+
expect(host.internalConstructorName.bind.apply(
82+
host.internalConstructorName, [host].concat(argvList))).to.throw();
83+
});
84+
}
85+
});
86+
87+
describe('function `functionDetailsWithoutScopes`', function() {
88+
it('should return valid details', function() {
89+
function example() {}
90+
91+
var details = host.functionDetailsWithoutScopes(example);
92+
expect(details).to.include.keys(['location', 'functionName']);
93+
expect(details.location).to.include.keys(['lineNumber', 'columnNumber', 'scriptId']);
94+
});
95+
96+
throwsOnArgs([]);
97+
throwsOnArgs([null]);
98+
99+
function throwsOnArgs(argvList) {
100+
it('should throw on wrong arguments ' + JSON.stringify(argvList), function() {
101+
expect(host.functionDetailsWithoutScopes.bind.apply(
102+
host.functionDetailsWithoutScopes, [host].concat(argvList))).to.throw();
103+
});
104+
}
105+
});
106+
107+
describe('function `eval`', function() {
108+
it('should evaluate expression', function() {
109+
expect(host.eval("[1]")).to.deep.equal([1]);
110+
});
111+
112+
it('should throw on wrong arguments', function() {
113+
expect(host.eval).to.throw();
114+
});
115+
116+
it('should throw on wrong expression', function() {
117+
expect(host.eval.bind(null, "[1")).to.throw(SyntaxError);
118+
});
119+
});
120+
121+
describe('function `evaluateWithExceptionDetails`', function() {
122+
it('should evaluate expression', function() {
123+
expect(host.evaluateWithExceptionDetails("[1]")).to.deep.equal({
124+
result: [1],
125+
exceptionDetails: undefined
126+
});
127+
});
128+
129+
it('should throw on wrong arguments', function() {
130+
expect(host.evaluateWithExceptionDetails).to.throw();
131+
});
132+
});
133+
134+
describe('function `callFunction`', function() {
135+
it('should call function without args', function(done) {
136+
host.callFunction(done, this);
137+
});
138+
139+
it('should call function with args', function(done) {
140+
host.callFunction(function(arg) {
141+
expect(arg).to.equal(1);
142+
done();
143+
}, this, [1]);
144+
});
145+
146+
it('should throw on wrong arguments', function() {
147+
expect(host.callFunction.bind(null, null, null, [1])).to.throw();
148+
expect(host.callFunction.bind(null, null, null, 1)).to.throw();
149+
});
150+
151+
it('should rethrow ReferenceError', function() {
152+
expect(host.callFunction.bind(null, function() {
153+
'use strict';
154+
if (error_here) return;
155+
}, this)).to.throw(ReferenceError);
156+
});
157+
});
158+
});
159+
});

test/v8-debug.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var expect = require('chai').expect,
22
v8debug = require('../');
33

4+
var NODE_NEXT = require('../tools/NODE_NEXT');
5+
46
var _debugger = require('child_process').spawn('node', ['./test/helpers/debugger.js']);
57

68
_debugger.stderr.on('data', function(data) {
@@ -32,17 +34,23 @@ describe('v8-debug', function() {
3234
expect(v8debug.registerAgentCommand.bind(v8debug, 'command', [], function() {})).to.throw();
3335
});
3436

35-
it('enableWebkitProtocol should enable Webkit protocol', function() {
36-
v8debug.enableWebkitProtocol();
37-
expect(v8debug.enableWebkitProtocol.bind(v8debug)).to.not.throw();
38-
});
39-
40-
it('if enabled registerAgentCommand should register command', function(done) {
41-
expect(v8debug.registerAgentCommand.bind(v8debug, 'command', [], function() {
42-
done();
43-
})).to.not.throw();
44-
v8debug.sendCommand('command');
45-
});
37+
if (NODE_NEXT) {
38+
it('enableWebkitProtocol should enable Webkit protocol', function() {
39+
v8debug.enableWebkitProtocol();
40+
expect(v8debug.enableWebkitProtocol.bind(v8debug)).to.not.throw();
41+
});
42+
43+
it('if enabled registerAgentCommand should register command', function(done) {
44+
expect(v8debug.registerAgentCommand.bind(v8debug, 'command', [], function() {
45+
done();
46+
})).to.not.throw();
47+
v8debug.sendCommand('command');
48+
});
49+
} else {
50+
it('enableWebkitProtocol should throw error', function() {
51+
expect(v8debug.enableWebkitProtocol).to.throw();
52+
});
53+
}
4654
});
4755

4856
describe('events.', function() {

tools/NODE_NEXT.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
return module.exports = process.versions.modules > 45;

v8-debug.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var EventEmitter = require('events').EventEmitter;
77
var inherits = require('util').inherits;
88
var extend = require('util')._extend;
99

10+
var NODE_NEXT = require('./tools/NODE_NEXT');
11+
1012
// Don't cache debugger module
1113
delete require.cache[module.id];
1214

@@ -214,6 +216,10 @@ V8Debug.prototype.getFromFrame = function(index, value) {
214216
};
215217

216218
V8Debug.prototype.enableWebkitProtocol = function() {
219+
if (!NODE_NEXT) {
220+
throw new Error('WebKit protocol is not supported on target node version (' + process.version + ')');
221+
}
222+
217223
if (this._webkitProtocolEnabled) return;
218224

219225
var DebuggerScriptSource,

0 commit comments

Comments
 (0)