Skip to content

Commit 6547330

Browse files
authored
guard against evaluation of active bindings (#1038)
- when inspecting environments - when composing data view of environments fixes #1030
1 parent b003a0e commit 6547330

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

R/session/vsc.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,21 @@ globalenv_cache <- new.env(parent = emptyenv())
135135
inspect_env <- function(env, cache) {
136136
all_names <- ls(env)
137137
rm(list = setdiff(names(globalenv_cache), all_names), envir = cache)
138-
is_promise <- rlang::env_binding_are_lazy(env, all_names)
138+
is_active <- vapply(all_names, bindingIsActive, logical(1), USE.NAMES = TRUE, env)
139+
is_promise <- rlang::env_binding_are_lazy(env, all_names[!is_active])
139140
show_object_size <- getOption("vsc.show_object_size", FALSE)
140141
object_length_limit <- getOption("vsc.object_length_limit", 2000)
141142
object_timeout <- getOption("vsc.object_timeout", 50) / 1000
142143
str_max_level <- getOption("vsc.str.max.level", 0)
143144
objs <- lapply(all_names, function(name) {
144-
if (is_promise[[name]]) {
145+
if (isTRUE(is_promise[name])) {
145146
info <- list(
146147
class = "promise",
147148
type = scalar("promise"),
148149
length = scalar(0L),
149150
str = scalar("(promise)")
150151
)
151-
} else if (bindingIsActive(name, env)) {
152+
} else if (isTRUE(is_active[name])) {
152153
info <- list(
153154
class = "active_binding",
154155
type = scalar("active_binding"),
@@ -407,9 +408,10 @@ if (show_view) {
407408
}
408409
if (is.environment(x)) {
409410
all_names <- ls(x)
410-
is_promise <- rlang::env_binding_are_lazy(x, all_names)
411+
is_active <- vapply(all_names, bindingIsActive, logical(1), USE.NAMES = TRUE, x)
412+
is_promise <- rlang::env_binding_are_lazy(x, all_names[!is_active])
411413
x <- lapply(all_names, function(name) {
412-
if (is_promise[[name]]) {
414+
if (isTRUE(is_promise[name])) {
413415
data.frame(
414416
class = "promise",
415417
type = "promise",
@@ -419,7 +421,7 @@ if (show_view) {
419421
stringsAsFactors = FALSE,
420422
check.names = FALSE
421423
)
422-
} else if (bindingIsActive(name, x)) {
424+
} else if (isTRUE(is_active[name])) {
423425
data.frame(
424426
class = "active_binding",
425427
type = "active_binding",

0 commit comments

Comments
 (0)