Skip to content

Commit f33e2d3

Browse files
committed
Remove incognito from vm
1 parent 4aee595 commit f33e2d3

File tree

7 files changed

+15
-75
lines changed

7 files changed

+15
-75
lines changed

bytecode/src/bytecode.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ bitflags! {
5757
const NEW_LOCALS = 0x08;
5858
const IS_GENERATOR = 0x10;
5959
const IS_COROUTINE = 0x20;
60-
const INCOGNITO = 1 << 15;
6160
}
6261
}
6362

@@ -450,10 +449,6 @@ impl CodeObject {
450449
}
451450
Display(self)
452451
}
453-
454-
pub fn incognito(&self) -> bool {
455-
self.flags.contains(CodeFlags::INCOGNITO)
456-
}
457452
}
458453

459454
impl fmt::Display for CodeObject {

compiler/src/compile.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,10 @@ pub struct CompileOpts {
3939
/// How optimized the bytecode output should be; any optimize > 0 does
4040
/// not emit assert statements
4141
pub optimize: u8,
42-
/// Whether introspection on defined functions/other items should be allowed;
43-
/// e.g. when true, `func.__globals__` throws an error (where func is a function defined
44-
/// in an incognito context)
45-
pub incognito: bool,
4642
}
4743
impl Default for CompileOpts {
4844
fn default() -> Self {
49-
CompileOpts {
50-
optimize: 0,
51-
incognito: false,
52-
}
45+
CompileOpts { optimize: 0 }
5346
}
5447
}
5548

@@ -188,9 +181,7 @@ impl<O: OutputStream> Compiler<O> {
188181
}
189182
}
190183

191-
fn push_output(&mut self, mut code: CodeObject) {
192-
code.flags
193-
.set(bytecode::CodeFlags::INCOGNITO, self.opts.incognito);
184+
fn push_output(&mut self, code: CodeObject) {
194185
self.output_stack.push(code.into());
195186
}
196187

vm/src/obj/objframe.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,13 @@ impl FrameRef {
3030
}
3131

3232
#[pyproperty]
33-
fn f_globals(self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
34-
if self.code.incognito() {
35-
Err(vm.new_type_error("Can't get f_globals on an incognito frame".to_owned()))
36-
} else {
37-
Ok(self.scope.globals.clone())
38-
}
33+
fn f_globals(self) -> PyDictRef {
34+
self.scope.globals.clone()
3935
}
4036

4137
#[pyproperty]
42-
fn f_locals(self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
43-
if self.code.incognito() {
44-
Err(vm.new_type_error("Can't get f_locals on an incognito frame".to_owned()))
45-
} else {
46-
Ok(self.scope.get_locals())
47-
}
38+
fn f_locals(self) -> PyDictRef {
39+
self.scope.get_locals()
4840
}
4941

5042
#[pyproperty]

vm/src/obj/objfunction.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,8 @@ impl PyFunction {
280280
}
281281

282282
#[pyproperty(magic)]
283-
fn globals(&self, vm: &VirtualMachine) -> PyResult<PyDictRef> {
284-
if self.code.incognito() {
285-
Err(vm.new_type_error("Can't get __globals__ on an incognito function".to_owned()))
286-
} else {
287-
Ok(self.scope.globals.clone())
288-
}
283+
fn globals(&self) -> PyDictRef {
284+
self.scope.globals.clone()
289285
}
290286
}
291287

vm/src/vm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,6 @@ impl VirtualMachine {
10091009
pub fn compile_opts(&self) -> CompileOpts {
10101010
CompileOpts {
10111011
optimize: self.settings.optimize,
1012-
..Default::default()
10131012
}
10141013
}
10151014

wasm/lib/src/vm_class.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::convert::{self, PyResultExt};
1818
use crate::js_module;
1919
use crate::wasm_builtins;
2020
use rustpython_compiler::mode::Mode;
21-
use rustpython_vm::obj::objstr::PyStringRef;
2221

2322
pub(crate) struct StoredVirtualMachine {
2423
pub vm: VirtualMachine,
@@ -260,16 +259,10 @@ impl WASMVirtualMachine {
260259
name: String,
261260
source: &str,
262261
imports: Option<Object>,
263-
strict_private: Option<bool>,
264262
) -> Result<(), JsValue> {
265263
self.with(|StoredVirtualMachine { ref vm, .. }| {
266-
let strict_private = strict_private.unwrap_or(false);
267-
let opts = compile::CompileOpts {
268-
incognito: strict_private,
269-
..vm.compile_opts()
270-
};
271264
let code = vm
272-
.compile_with_opts(source, Mode::Exec, name.clone(), opts)
265+
.compile(source, Mode::Exec, name.clone())
273266
.map_err(convert::syntax_err)?;
274267
let attrs = vm.ctx.new_dict();
275268
attrs
@@ -279,37 +272,17 @@ impl WASMVirtualMachine {
279272
if let Some(imports) = imports {
280273
for entry in convert::object_entries(&imports) {
281274
let (key, value) = entry?;
282-
let key:String = Object::from(key).to_string().into();
283-
attrs.set_item(&key, convert::js_to_py(vm, value), vm).to_js(vm)?;
275+
let key: String = Object::from(key).to_string().into();
276+
attrs
277+
.set_item(&key, convert::js_to_py(vm, value), vm)
278+
.to_js(vm)?;
284279
}
285280
}
286281

287282
vm.run_code_obj(code, Scope::new(None, attrs.clone(), vm))
288283
.to_js(vm)?;
289284

290-
let module_attrs = if strict_private {
291-
let all = attrs
292-
.get_item_option("__all__", vm)
293-
.to_js(vm)?
294-
.ok_or_else(|| {
295-
TypeError::new(
296-
"you must define __all__ in your module if you pass strict_private: true",
297-
)
298-
})?;
299-
let all = vm.extract_elements::<PyStringRef>(&all).to_js(vm)?;
300-
301-
let actual_attrs = vm.ctx.new_dict();
302-
for member in all {
303-
actual_attrs
304-
.set_item(member.as_str(), attrs.get_item(member.as_str(), vm).to_js(vm)?, vm)
305-
.to_js(vm)?;
306-
}
307-
actual_attrs
308-
} else {
309-
attrs
310-
};
311-
312-
let module = vm.new_module(&name, module_attrs);
285+
let module = vm.new_module(&name, attrs);
313286

314287
let sys_modules = vm
315288
.get_attribute(vm.sys_module.clone(), "modules")

wasm/tests/test_inject_module.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def test_inject_private(wdriver):
1+
def test_inject_module_basic(wdriver):
22
wdriver.execute_script(
33
"""
44
const vm = rp.vmStore.init("vm")
@@ -15,12 +15,6 @@ def get_thing(): return __thing()
1515
`
1616
import mod
1717
assert mod.get_thing() == 1
18-
assert "__thing" not in dir(mod)
19-
try:
20-
globs = mod.get_thing.__globals__
21-
except TypeError: pass
22-
else:
23-
assert False, "incognito function.__globals__ didn't error"
2418
`
2519
);
2620
"""

0 commit comments

Comments
 (0)