-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Match the spec properly #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,12 @@ var getRegexLiteral = function (stringRegex) { | |
} catch (e) {} | ||
}; | ||
|
||
flags.shim(); | ||
var descriptor = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags'); | ||
var testGenericFlags = function (object) { | ||
return descriptor.get.call(object); | ||
}; | ||
|
||
test('works as a function', function (t) { | ||
t.equal(flags(/a/g), 'g', 'flags(/a/g) !== "g"'); | ||
t.equal(flags(/a/gmi), 'gim', 'flags(/a/gmi) !== "gim"'); | ||
|
@@ -43,15 +49,13 @@ test('works as a function', function (t) { | |
var nonObjects = ['', false, true, 42, NaN, null, undefined]; | ||
st.plan(nonObjects.length); | ||
nonObjects.forEach(function (nonObject) { | ||
st.throws(function () { RegExp.prototype.flags.call(nonObject); }, TypeError); | ||
st.throws(function () { flags.call(nonObject); }, TypeError); | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('shims properly', function (t) { | ||
flags.shim(); | ||
|
||
t.equal((/a/g).flags, 'g', '(/a/g).flags !== "g"'); | ||
t.equal((/a/gmi).flags, 'gim', '(/a/gmi).flags !== "gim"'); | ||
t.equal(new RegExp('a', 'gmi').flags, 'gim', 'new RegExp("a", "gmi").flags !== "gim"'); | ||
|
@@ -79,12 +83,29 @@ test('shims properly', function (t) { | |
st.end(); | ||
}); | ||
|
||
t.test('has the correct descriptor', function (st) { | ||
st.equal(descriptor.configurable, true); | ||
st.equal(descriptor.enumerable, false); | ||
st.equal(typeof descriptor.get, 'function'); | ||
st.equal(descriptor.set, undefined); | ||
st.end(); | ||
}); | ||
|
||
t.test('throws properly', function (st) { | ||
var nonObjects = ['', false, true, 42, NaN, null, undefined]; | ||
st.plan(nonObjects.length); | ||
nonObjects.forEach(function (nonObject) { | ||
st.throws(function () { RegExp.prototype.flags.call(nonObject); }, TypeError); | ||
st.throws(function () { testGenericFlags(nonObject); }, TypeError); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't necessary; the original is functionally equivalent and imo reads more clearly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is necessary: paulmillr/es6-shim#310 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahhhh that makes sense. Thanks for clarifying. |
||
}); | ||
}); | ||
|
||
t.test('generic flags', function (st) { | ||
st.equal(testGenericFlags({}), ''); | ||
st.equal(testGenericFlags({ ignoreCase: true }), 'i'); | ||
st.equal(testGenericFlags({ global: 0, sticky: 1, unicode: 1 }), 'uy'); | ||
st.equal(testGenericFlags({ __proto__: { multiline: true } }), 'm'); | ||
st.end(); | ||
}); | ||
|
||
t.end(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this !== Object(this) {
is sufficient; no need to check for null or undefined.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it’s not necessary. Did you see the commit message of the commit that introduced this change?
I’m fine with removing it; just want to make sure we’re on the same page here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's true. Sure, why not keep it.