Skip to content

Commit

Permalink
constructing an object returns the new object --'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiosantoscode committed Mar 28, 2014
1 parent c8b943e commit 7e3beab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/sjedon.js
Expand Up @@ -81,7 +81,7 @@ StackFrame.prototype.fetchVar = function (name, maybeNothing) {
if (name in this.sjedon.global) {
return this.sjedon.global[name];
}
if (maybeNothing) { return nothing_ }
if (maybeNothing) { return nothing }
throw new ReferenceError(name + ' is not defined')
}
StackFrame.prototype.assignVar = function (name, value, maybeNothing) {
Expand All @@ -94,7 +94,7 @@ StackFrame.prototype.assignVar = function (name, value, maybeNothing) {
if (name in this.sjedon.global) {
return this.sjedon.global[name] = value;
}
if (maybeNothing) { return nothing_ }
if (maybeNothing) { return nothing }
throw new ReferenceError(name + ' is not defined')
}
StackFrame.prototype.declareVar = function (name, value) {
Expand Down Expand Up @@ -425,7 +425,8 @@ Sjedon.prototype.evalExpression = function (expr) {
} else if (expr.type === 'NewExpression') {
var callee = this.evalExpression(expr.callee);
var newObj = inheritFrom(callee.prototype || {});
return callee.apply(newObj, expr['arguments'].map(this.evalExpression.bind(this)))
callee.apply(newObj, expr['arguments'].map(this.evalExpression.bind(this)))
return newObj;
} else if (expr.type === 'Literal') {
return expr.value;
} else if (expr.type === 'ArrayExpression') {
Expand Down
7 changes: 5 additions & 2 deletions test/sjedon_test.js
Expand Up @@ -366,22 +366,25 @@ describe('functions', function () {
}))
it('with the new keyword', function () {
var spy = sinon.spy()
var spy2 = sinon.spy()
aSjedon('(' + function () {
function SomeClass() {
spy(this, SomeClass);
}

SomeClass.prototype.b = 'b'

new SomeClass();
} + '())', { spy: spy }).run();
spy2(new SomeClass());
} + '())', { spy: spy, spy2: spy2 }).run();

ok(spy.calledOnce)
ok(spy.lastCall.args[0].b === 'b')
ok(!{}.hasOwnProperty.call(spy.lastCall.args[0], 'b'))

ok(spy.lastCall.args[1].prototype.b)
ok({}.hasOwnProperty.call(spy.lastCall.args[1].prototype, 'b'))

ok(spy2.lastCall.args[0] === spy.lastCall.args[0]);
});
it('new keyword (outside functions)', function () {
var spy = sinon.spy()
Expand Down

0 comments on commit 7e3beab

Please sign in to comment.