Skip to content

guard against evaluation of active bindings#1038

Merged
renkun-ken merged 1 commit intoREditorSupport:masterfrom
MilesMcBain:master
Mar 10, 2022
Merged

guard against evaluation of active bindings#1038
renkun-ken merged 1 commit intoREditorSupport:masterfrom
MilesMcBain:master

Conversation

@MilesMcBain
Copy link
Collaborator

  • when inspecting environments
  • when composing data view of environments

fixes #1030

What problem did you solve?

Fixed evaluation of active bindings when collecting data for the data view and the workspace viewer.

It may be that the guard is only desired when looking in the global environment for the workspace view?

(If you do not have screenshot) How can I check this pull request?

Check the test code from #1030 and confirm "get" is no longer printed, except when the active binding is accessed:

> f <- local( {
+     x <- 1
+     function(v) {
+        if (missing(v))
+            cat("get\n")
+        else {
+            cat("set\n")
+            x <<- v
+        }
+        x
+     }
+ })
> makeActiveBinding("fred", f, .GlobalEnv)
> bindingIsActive("fred", .GlobalEnv)
[1] TRUE
> fred
get
[1] 1

- when inspecting environments
- when composing data view of environments

fixes REditorSupport#1030
@MilesMcBain MilesMcBain requested a review from renkun-ken March 10, 2022 12:14
@renkun-ken
Copy link
Member

Just curious, does bindingIsActive evaluate a promise in the first place?

@MilesMcBain
Copy link
Collaborator Author

HA. I'll have to check. That would be fun.

@renkun-ken
Copy link
Member

fun <- function(x) {
  bindingIsActive("x", environment())
}

fun(stop("early evaluation!"))

Looks like bindingIsActive is safe.

Copy link
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks!

@renkun-ken renkun-ken merged commit 6547330 into REditorSupport:master Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workspace Viewer is evaluating active bindings when populating its view

2 participants