
Previously, sandbox creation used `gui?', which is the result of `gui-available?' at the time that `racket/sandbox' is instanited. This change makes sandbox behavior less sensitive tothe order in which modules `require'd into a program are intiantiated. The change depends on a new `sandbox-make-namespace' default function for `sandbox-namespace-specs'. The new function uses either `make-base-namespace' or `make-gui-namespace', depending on whether the GUI library is available at that point. A new `sandbox-gui-enabled' parameter can disable use of the GUI library even if it is available. The `gui?' binding is still exported for backward compatibility, but it shouldn't be used anymore. original commit: 5630a3a1cab8d7953bfbb290bd6ae63c84ead605
49 lines
1.3 KiB
Racket
49 lines
1.3 KiB
Racket
#lang racket
|
|
(require racket/sandbox
|
|
racket/gui/dynamic)
|
|
|
|
(define-syntax-rule (test expect expr)
|
|
(do-test 'expr expect expr))
|
|
|
|
(define (do-test which expect got)
|
|
(unless (equal? expect got)
|
|
(error 'test "failed: ~s expect: ~e got: ~e" which expect got)))
|
|
|
|
;; GUI is initialled allowed by sandbox, but not initially available:
|
|
|
|
(test #t (sandbox-gui-available))
|
|
(test #f (gui-available?))
|
|
|
|
;; Create a pre-GUI evaluator:
|
|
|
|
(define e (call-with-trusted-sandbox-configuration
|
|
(lambda ()
|
|
(make-evaluator 'racket))))
|
|
(test (void) (e '(require racket/gui/dynamic)))
|
|
(test #f (e '(gui-available?)))
|
|
|
|
;; Load GUI library
|
|
|
|
(test (void) (dynamic-require 'racket/gui #f))
|
|
|
|
;; Now the GUI is available:
|
|
|
|
(test #t (gui-available?))
|
|
|
|
;; Create a post-GUI evaluator:
|
|
|
|
(define ge (call-with-trusted-sandbox-configuration
|
|
(lambda ()
|
|
(make-evaluator 'racket))))
|
|
(test (void) (ge '(require racket/gui/dynamic)))
|
|
(test #t (ge '(gui-available?)))
|
|
|
|
;; A post-GUI evaluator, but with GUI disabled:
|
|
|
|
(define pe (parameterize ([sandbox-gui-available #f])
|
|
(call-with-trusted-sandbox-configuration
|
|
(lambda ()
|
|
(make-evaluator 'racket)))))
|
|
(test (void) (pe '(require racket/gui/dynamic)))
|
|
(test #f (pe '(gui-available?)))
|