Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Jun 25, 2019
1 parent 0f67f8d commit 6d2fc5c
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 76 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
members = [
"cli",
"core",
"test_plugin",
"tests/plugin",
]
14 changes: 7 additions & 7 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct DenoFlags {
pub allow_env: bool,
pub allow_run: bool,
pub allow_hrtime: bool,
pub allow_dlopen: bool,
pub allow_plugins: bool,
pub no_prompts: bool,
pub no_fetch: bool,
pub seed: Option<u64>,
Expand Down Expand Up @@ -79,8 +79,8 @@ fn add_run_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.long("allow-hrtime")
.help("Allow high resolution time measurement"),
).arg(
Arg::with_name("allow-dlopen")
.long("allow-dlopen")
Arg::with_name("allow-plugins")
.long("allow-plugins")
.help("Allow loading native plugins via dlopen"),
).arg(
Arg::with_name("allow-all")
Expand Down Expand Up @@ -494,8 +494,8 @@ fn parse_run_args(mut flags: DenoFlags, matches: &ArgMatches) -> DenoFlags {
if matches.is_present("allow-hrtime") {
flags.allow_hrtime = true;
}
if matches.is_present("allow-dlopen") {
flags.allow_dlopen = true;
if matches.is_present("allow-plugins") {
flags.allow_plugins = true;
}
if matches.is_present("allow-all") {
flags.allow_read = true;
Expand All @@ -504,7 +504,7 @@ fn parse_run_args(mut flags: DenoFlags, matches: &ArgMatches) -> DenoFlags {
flags.allow_net = true;
flags.allow_run = true;
flags.allow_hrtime = true;
flags.allow_dlopen = true;
flags.allow_plugins = true;
}
if matches.is_present("no-prompt") {
flags.no_prompts = true;
Expand Down Expand Up @@ -847,7 +847,7 @@ mod tests {
allow_read: true,
allow_write: true,
allow_hrtime: true,
allow_dlopen: true,
allow_plugins: true,
..DenoFlags::default()
}
);
Expand Down
2 changes: 1 addition & 1 deletion cli/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@ fn op_plugin_open(
let inner = base.inner_as_plugin_open().unwrap();
let (filename, filename_) = resolve_path(inner.filename().unwrap())?;

state.check_dlopen(&filename_)?;
state.check_plugins(&filename_)?;

let lib = resources::add_plugin(filename)?;

Expand Down
16 changes: 8 additions & 8 deletions cli/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub struct DenoPermissions {
pub allow_run: PermissionAccessor,
pub allow_hrtime: PermissionAccessor,
// TODO(afinch7) maybe add permissions whitelist for this?
pub allow_dlopen: PermissionAccessor,
pub allow_plugins: PermissionAccessor,
pub no_prompts: AtomicBool,
}

Expand All @@ -155,7 +155,7 @@ impl DenoPermissions {
allow_env: PermissionAccessor::from(flags.allow_env),
allow_run: PermissionAccessor::from(flags.allow_run),
allow_hrtime: PermissionAccessor::from(flags.allow_hrtime),
allow_dlopen: PermissionAccessor::from(flags.allow_dlopen),
allow_plugins: PermissionAccessor::from(flags.allow_plugins),
no_prompts: AtomicBool::new(flags.no_prompts),
}
}
Expand Down Expand Up @@ -319,15 +319,15 @@ impl DenoPermissions {
}
}

pub fn check_dlopen(&self, filename: &str) -> DenoResult<()> {
match self.allow_dlopen.get_state() {
pub fn check_plugins(&self, filename: &str) -> DenoResult<()> {
match self.allow_plugins.get_state() {
PermissionAccessorState::Allow => Ok(()),
PermissionAccessorState::Ask => match self.try_permissions_prompt(
&format!("to load native bindings from: {}", filename),
) {
Err(e) => Err(e),
Ok(v) => {
self.allow_dlopen.update_with_prompt_result(&v);
self.allow_plugins.update_with_prompt_result(&v);
v.check()?;
Ok(())
}
Expand Down Expand Up @@ -373,7 +373,7 @@ impl DenoPermissions {
}

pub fn allows_dlopen(&self) -> bool {
self.allow_dlopen.is_allow()
self.allow_plugins.is_allow()
}

pub fn revoke_run(&self) -> DenoResult<()> {
Expand Down Expand Up @@ -406,8 +406,8 @@ impl DenoPermissions {
Ok(())
}

pub fn revoke_dlopen(&self) -> DenoResult<()> {
self.allow_dlopen.revoke();
pub fn revoke_plugins(&self) -> DenoResult<()> {
self.allow_plugins.revoke();
Ok(())
}
}
Expand Down
4 changes: 2 additions & 2 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ impl ThreadSafeState {
}

#[inline]
pub fn check_dlopen(&self, filename: &str) -> DenoResult<()> {
self.permissions.check_dlopen(filename)
pub fn check_plugins(&self, filename: &str) -> DenoResult<()> {
self.permissions.check_plugins(filename)
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions js/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export { core } from "./core";
export {
PluginOp,
PluginImpl as Plugin,
dlopen,
dlname
openPlugin,
pluginFilename
} from "./native_plugins";

// TODO Don't expose Console nor stringifyArgs.
Expand Down
4 changes: 2 additions & 2 deletions js/native_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class PluginImpl implements Plugin {
}
}

export function dlopen(filename: string): Plugin {
export function openPlugin(filename: string): Plugin {
return new PluginImpl(filename);
}

Expand Down Expand Up @@ -178,6 +178,6 @@ const pluginFileExtension = ((): PluginFileExtension => {
}
})();

export function dlname(filenameBase: string): string {
export function pluginFilename(filenameBase: string): string {
return pluginFilePrefix + filenameBase + "." + pluginFileExtension;
}
39 changes: 0 additions & 39 deletions test_plugin/main.ts

This file was deleted.

2 changes: 0 additions & 2 deletions tests/033_native_plugins.test

This file was deleted.

2 changes: 2 additions & 0 deletions tests/034_native_plugins.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
args: run --reload --allow-plugins --allow-env tests/034_native_plugins.ts
output: tests/034_native_plugins.ts.out
14 changes: 8 additions & 6 deletions tests/033_native_plugins.ts → tests/034_native_plugins.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { dlname, dlopen, env } = Deno;
const { openPlugin, pluginFilename, env } = Deno;

const dLib = dlopen(env().DENO_BUILD_PATH + "/" + dlname("test_plugin"));
const testOpFn = dLib.loadOp("test_op");
const plugin = openPlugin(
env().DENO_BUILD_PATH + "/" + pluginFilename("test_plugin")
);
const testOp = plugin.loadOp("test_op");

interface TestOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -29,13 +31,13 @@ function decodeTestOp(data: Uint8Array): any {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const testOp = (args: TestOptions): any => {
const doTestOp = (args: TestOptions): any => {
return decodeTestOp(
testOpFn.dispatchSync(
testOp.dispatchSync(
encodeTestOp(args.data),
encodeTestOp(args.zeroCopyData)
)
);
};

console.log(testOp({ data: "test", zeroCopyData: { some: "data" } }));
console.log(doTestOp({ data: "test", zeroCopyData: { some: "data" } }));
File renamed without changes.
2 changes: 1 addition & 1 deletion test_plugin/Cargo.toml → tests/plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ path = "lib.rs"
crate-type = ["cdylib"]

[dependencies]
deno = { path = "../core" }
deno = { path = "../../core" }
File renamed without changes.
2 changes: 1 addition & 1 deletion tools/permission_prompt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RunPromptTest(DenoTestCase, BasePromptTest):


class DlopenPromptTest(DenoTestCase, BasePromptTest):
test_type = "dlopen"
test_type = "plugins"


def permission_prompt_tests():
Expand Down
8 changes: 4 additions & 4 deletions tools/permission_prompt_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
makeTempDirSync,
readFileSync,
run,
dlopen
openPlugin
} = Deno;

const firstCheckFailedMessage = "First check failed";
Expand Down Expand Up @@ -76,16 +76,16 @@ const test = {
]
});
},
needsDlopen: (): void => {
needsPlugins: (): void => {
try {
const dlib = dlopen("some/fake/path");
const plugin = openPlugin("some/fake/path");
} catch (e) {
if (e.kind === Deno.ErrorKind.PermissionDenied) {
console.log(firstCheckFailedMessage);
}
}
try {
const dlib = dlopen("some/fake/path");
const plugin = openPlugin("some/fake/path");
} catch (e) {
if (e.kind === Deno.ErrorKind.PermissionDenied) {
throw e;
Expand Down

0 comments on commit 6d2fc5c

Please sign in to comment.