Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.

Use Object cast for safe property access #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions lib/api/dsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function alias(rule, value) {
content: normalize(rule)
};

switch (value.constructor) {
switch (Object(value).constructor) {
case String:
result.named = false;
result.value = value;
Expand Down Expand Up @@ -158,7 +158,7 @@ function normalize(value) {
if (typeof value == "undefined")
throw new Error("Undefined symbol");

switch (value.constructor) {
switch (Object(value).constructor) {
case String:
return string(value);
case RegExp:
Expand All @@ -170,12 +170,13 @@ function normalize(value) {
));
case ReferenceError:
throw value
default:
case Object:
if (typeof value.type === 'string') {
return value;
} else {
throw new TypeError("Invalid rule: " + value.toString());
}
// fall through
default:
throw new TypeError("Invalid rule: " + value.toString());
}
}

Expand Down