Skip to content

Commit

Permalink
core, feat:treat NaN as zero in argumets when require number (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot authored and xicilion committed Oct 4, 2017
1 parent 3a92d0e commit c0d4be1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
5 changes: 1 addition & 4 deletions fibjs/include/utils.h
Expand Up @@ -571,13 +571,10 @@ inline result_t GetArgumentValue(v8::Local<v8::Value> v, double& n, bool bStrict
return CALL_E_TYPEMISMATCH;

v = v->ToNumber();
if (v.IsEmpty())
return CALL_E_TYPEMISMATCH;
}

n = v->NumberValue();
if (isnan(n))
return CALL_E_TYPEMISMATCH;
if (isnan(n)) n = 0;

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions test/buffer_test.js
Expand Up @@ -818,15 +818,15 @@ describe('Buffer', () => {
assert.doesNotThrow(() => {
buf.resize("12")
});
assert.throws(() => {
assert.doesNotThrow(() => {
buf.resize("a12")
});

assert.throws(() => {
assert.doesNotThrow(() => {
buf.resize("12a")
});

assert.throws(() => {
assert.doesNotThrow(() => {
buf.resize("12.a")
});
});
Expand Down
18 changes: 13 additions & 5 deletions test/console_test.js
Expand Up @@ -42,11 +42,19 @@ describe("console", () => {
levels: [console.DEBUG, console.ERROR]
});

assert.throws(() => {
console.add({
type: "console",
levels: [console.DEBUG, "other"]
});
console.add({
type: "console",
levels: [console.DEBUG, {}]
});

console.add({
type: "console",
levels: [console.DEBUG, NaN]
});

console.add({
type: "console",
levels: [console.DEBUG, '1']
});

assert.throws(() => {
Expand Down
6 changes: 0 additions & 6 deletions test/int64_test.js
Expand Up @@ -17,12 +17,6 @@ describe('Int64', () => {
assert.equal(k.toString(16), '0xfedcba9876543210');
});

it('can not be constructed from object', () => {
assert.throws(() => {
var x = new Int64({});
});
});

it('can be compared', () => {
var a = new Int64(2),
b = new Int64(3);
Expand Down

0 comments on commit c0d4be1

Please sign in to comment.