Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the constants to both prototype and class itself #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions lib/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Url = require("url");
var spawn = require("child_process").spawn;
var fs = require("fs");

exports.XMLHttpRequest = function() {
function XMLHttpRequest() {
"use strict";

/**
Expand Down Expand Up @@ -86,16 +86,6 @@ exports.XMLHttpRequest = function() {
// Event listeners
var listeners = {};

/**
* Constants
*/

this.UNSENT = 0;
this.OPENED = 1;
this.HEADERS_RECEIVED = 2;
this.LOADING = 3;
this.DONE = 4;

/**
* Public vars
*/
Expand Down Expand Up @@ -618,3 +608,34 @@ exports.XMLHttpRequest = function() {
}
};
};

/**
* Constants
*/

[XMLHttpRequest, XMLHttpRequest.prototype].forEach(function(obj) {
Object.defineProperties(obj, {
UNSENT: {
value: 0
},

OPENED: {
value: 1
},

HEADERS_RECEIVED: {
value: 2
},

LOADING: {
value: 3
},

DONE: {
value: 4
}
});
});

exports.XMLHttpRequest = XMLHttpRequest;

9 changes: 8 additions & 1 deletion tests/test-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ var sys = require("util")
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
, xhr = new XMLHttpRequest();

// Test constant values
// Test constant values in class
assert.equal(0, XMLHttpRequest.UNSENT);
assert.equal(1, XMLHttpRequest.OPENED);
assert.equal(2, XMLHttpRequest.HEADERS_RECEIVED);
assert.equal(3, XMLHttpRequest.LOADING);
assert.equal(4, XMLHttpRequest.DONE);

// Test constant values in instance
assert.equal(0, xhr.UNSENT);
assert.equal(1, xhr.OPENED);
assert.equal(2, xhr.HEADERS_RECEIVED);
Expand Down