-
Notifications
You must be signed in to change notification settings - Fork 43
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
feat(stdlib): Implement ifSGNodeField.hasField() #368
Conversation
returns: ValueKind.Boolean, | ||
}, | ||
impl: (interpreter: Interpreter, fieldname: BrsString) => { | ||
return this.fields.has(fieldname.value.toLowerCase()) |
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.
For future reference, this could be as simple as:
return this.fields.has(fieldname.value.toLowerCase()) | |
return BrsBoolean.from( | |
this.fields.has(fieldname.value.toLowerCase()) | |
) |
What you've got is of course fine though 😄
|
||
let hasField = node.getMethod("hasfield"); | ||
let result1 = hasField.call(interpreter, new BrsString("foo")); | ||
expect(result1).toEqual(new BrsBoolean(true)); |
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.
Also for future reference, this could be a tick simpler with expect(result1).toBe(BrsBoolean.True)
. Because there's only the two possible BrsBoolean
values, they're exposed as static members of BrsBoolean
for easy access!
@@ -35,6 +35,9 @@ sub main() | |||
print "field1 in node now is: " node1.getField("field1") ' => hello | |||
print "field3 in node now is: " node1.getField("field3") ' => false | |||
|
|||
print "field3 present? " node1.hasField("field3") | |||
print "fieldほ present? " node1.hasField("fieldほ") |
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.
Oh dang I've never thought about having non-ASCII characters in field names. I'm glad that works! 🎉
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.
Thanks a ton, @strattonbrazil! This looks great :)
Implements hasField() (resolves #367 ). The implementation is simpler than the existing getField method, which returns a value, while this simply returns a boolean if the field is present.
There is at least one bug in hasField in the official implementation that I'm aware of, where calling hasField() with specific strings will actually create the field, but this is a bug and I don't think we should match that for compatibility sake.