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

feat(stdlib): Implement ifSGNodeField.hasField() #368

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

strattonbrazil
Copy link
Collaborator

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.

@strattonbrazil strattonbrazil added enhancement Any addition to this project's existing capabilities stdlib Affects the standard library included with this BrightScript implementation labels Jan 29, 2020
returns: ValueKind.Boolean,
},
impl: (interpreter: Interpreter, fieldname: BrsString) => {
return this.fields.has(fieldname.value.toLowerCase())
Copy link
Owner

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:

Suggested change
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));
Copy link
Owner

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ほ")
Copy link
Owner

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! 🎉

Copy link
Owner

@sjbarag sjbarag left a 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 :)

@sjbarag sjbarag added the scenegraph Affects this project's implementation of the SceneGraph framework label Jan 29, 2020
@sjbarag sjbarag changed the title implement ifSGNodeField.hasField() feat(stdlib): Implement ifSGNodeField.hasField() Jan 29, 2020
@sjbarag sjbarag merged commit ca54d7b into sjbarag:master Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any addition to this project's existing capabilities scenegraph Affects this project's implementation of the SceneGraph framework stdlib Affects the standard library included with this BrightScript implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(SceneGraph): Implement ifSGNode#hasField
2 participants