Pull request review commentdenoland/deno

Separate behavior for the compiler isolate

 // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. use crate::isolate_state::IsolateState;+use crate::isolate_state::{IsolateStateContainer, WorkerChannels}; use crate::msg;-use crate::permissions::{DenoPermissions, PermissionAccessor};+use crate::ops; use crate::resources; use crate::resources::Resource; use crate::resources::ResourceId; use crate::startup_data; use crate::workers;+use crate::workers::WorkerBehavior;+use deno_core::deno_buf;+use deno_core::deno_mod;+use deno_core::Behavior; use deno_core::Buf;+use deno_core::Op;+use deno_core::StartupData; use futures::Future; use serde_json; use std::str;+use std::sync::atomic::Ordering;+use std::sync::Arc; use std::sync::Mutex;  lazy_static! {   static ref C_RID: Mutex<Option<ResourceId>> = Mutex::new(None); } +pub struct CompilerBehavior {+  pub state: Arc<IsolateState>,+}++impl CompilerBehavior {+  pub fn new(state: Arc<IsolateState>) -> Self {

I did some more simplification, and removed the code duplication from resolve. My main reasons for the distinct Behaviors here are:

  1. I don't expect there to be many changes to Behavior, so this code shouldn't have any reason to change often.
  2. As you mentioned using a flag would be a extra compare operation.
  3. When we implement web workers we might want a separate Behavior for them(#1866), and this will serve as a good example for whoever takes that on in the future. It will also ensure that the the infrastructure I created for having separate Behaviors will be maintained.
afinch7

comment created time in 2 hours

push eventafinch7/deno

afinch7

commit sha 41c4b38b8bbab2f24a86bcfe7f70e1544fa2b36e

Simplified some more stuff

view details

push time in 3 hours

push eventafinch7/deno

afinch7

commit sha 2b323ee88df8444bebec3cb87426ff53ab4cdb27

Simplified the mess in ops and removed some old stuff from cli_behavior.rs

view details

push time in 4 hours

push eventafinch7/deno

afinch7

commit sha 2aacd032d3ff6231800f7d0534b5eb42a50b7810

Simplified the mess in ops and removed some old stuff from cli_behavior.rs

view details

push time in 4 hours

Pull request review commentdenoland/deno

Separate behavior for the compiler isolate

+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.+#![allow(unused_variables)]+#![allow(dead_code)]

from old branch will do

afinch7

comment created time in 4 hours

PR opened denoland/deno

Separate behavior for the compiler isolate

The primary goal was to create a separate Behavior implementation for the compiler isolate, so permissions could be moved back to IsolateState. It ended up turning into a ton of refactors and cleanups.

+510 -285

0 comment

9 changed files

pr created time in 4 hours

create barnchafinch7/deno

branch : seperate_behavior_for_compiler

created branch time in 4 hours

push eventafinch7/deno

andy finch

commit sha 14e41d0f193dfeec8e5f8ac89b148faab9a8c50a

Update isolate state

view details

andy finch

commit sha 1e2de5a39c974a239f78b5b6aed59dc4a00f63d7

Update other files

view details

push time in 7 hours

push eventafinch7/deno

andy finch

commit sha 96b0d8e47f3b3d2ff4fb5c36f74eba435eeb3430

Update isolate state

view details

push time in 8 hours

push eventafinch7/deno

andy

commit sha 192c0439c1b46201d2438af65b11e0259ad3f52c

Updated other files

view details

push time in 8 hours

push eventafinch7/deno

andy finch

commit sha 14e41d0f193dfeec8e5f8ac89b148faab9a8c50a

Update isolate state

view details

push time in 8 hours

PR opened denoland/deno

[WIP]: Remove old Buf definition in cli.rs

<!-- Before submitting a PR read https://deno.land/manual.html#contributing -->

+0 -5

0 comment

1 changed file

pr created time in 8 hours

push eventafinch7/deno

andy finch

commit sha 1e57458e29c4239c447f30adbd1ac9ebd2364fcf

Remove old Buf definition in cli.rs

view details

push time in 8 hours

pull request commentdenoland/deno

Use tokio::runtime::current_thread in CLI

Reduces tail latency in tests/http_bench.js by half.

Again?

ry

comment created time in a day

push eventafinch7/deno

afinch7

commit sha 55a140110da2776f45571080fc27916e236add0c

Ensure this will create build errors if we add more values to StartupData

view details

push time in a day

push eventafinch7/deno

afinch7

commit sha fdc4f8b89f1b65d01b6fdd241fd13fa2b631a334

requested changes

view details

push time in a day

Pull request review commentdenoland/deno

Re-implement init scripts in core

 impl Cli { }  impl Behavior for Cli {-  fn startup_snapshot(&mut self) -> Option<deno_buf> {-    self.init.snapshot.take()+  fn startup_data(&mut self) -> Option<StartupData> {

Is it ok if I put the documentation in the Behavior trait definition instead? I figure that is where this information belongs.

afinch7

comment created time in a day

push eventafinch7/deno

andy finch

commit sha c720e90655a59223b269040eb4a0072025a414f4

Re-enable permissions prompt tests

view details

push time in a day

push eventafinch7/deno

andy finch

commit sha 10c66dd78d4ef30694f91f6843f5c3ffeeb55432

Re-enable permissions prompt tests

view details

push time in a day

PR opened denoland/deno

Re-implement init scripts in core

Somewhere along the way script based isolate init got dropped. I've re-implemented it, and made some changes like replace IsolateInit with a enum StartupData.

+84 -116

0 comment

10 changed files

pr created time in a day

create barnchafinch7/deno

branch : fix_script_init

created branch time in a day

PR opened denoland/deno

Re-enable permissions prompt tests
+2 -3

0 comment

1 changed file

pr created time in a day

push eventafinch7/deno

andy finch

commit sha a3143154bca74b3e0d0b9e120d17a40ec03c2393

Re-enable permissions prompt tests

view details

push time in a day

PR opened denoland/deno

All CI jobs fail quicker on bad test_format or lint

We have 3 jobs that won't fail if lint.py or test_format.py does. Added:

- ./tools/lint.py
- ./tools/test_format.py

to the scripts of these other jobs, so they fail sooner and don't clog up CI.

+6 -0

0 comment

1 changed file

pr created time in a day

push eventafinch7/deno

andy finch

commit sha b37146485a30a6040f1161fe945ecbb72d4a8d13

All CI jobs fail quicker on bad test_format or lint We have 3 jobs that won't fail if `lint.py` or `test_format.py` does. Added: ``` - ./tools/lint.py - ./tools/test_format.py ``` to the scripts of these other jobs, so they fail sooner and don't clog up CI.

view details

push time in a day

push eventafinch7/deno

afinch7

commit sha d0e8c6a51f93b525e973d2a051c92a40c17c9691

fmt

view details

push time in a day

pull request commentdenoland/deno

More permissions prompt options

Not sure what happened to CI on that last one, but I made some changes based on @hayd's feedback. Hopefully it passes this time.

afinch7

comment created time in a day

push eventafinch7/deno

afinch7

commit sha ebb7732388355c27a36901a89ae2d8f077e6a26e

Merged arg and args and added some comments to wrap_test

view details

push time in a day

Pull request review commentdenoland/deno

More permissions prompt options

 import pty import select import subprocess+import sys+import time -from util import build_path, executable_suffix+from util import build_path, executable_suffix, green_ok, red_failed  PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts" +PROMPT_PATTERN = b'⚠️'+FIRST_CHECK_FAILED_PATTERN = b'First check failed'+PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'+  # This function is copied from: # https://gist.github.com/hayd/4f46a68fc697ba8888a7b517a414583e # https://stackoverflow.com/q/52954248/1240268-def tty_capture(cmd, bytes_input):+def tty_capture(cmd, bytes_input, timeout=5):     """Capture the output of cmd with bytes_input to stdin,     with stdin, stdout and stderr as TTYs."""     mo, so = pty.openpty()  # provide tty to enable line-buffering     me, se = pty.openpty()     mi, si = pty.openpty()     fdmap = {mo: 'stdout', me: 'stderr', mi: 'stdin'} +    timeout_exact = time.time() + timeout     p = subprocess.Popen(         cmd, bufsize=1, stdin=si, stdout=so, stderr=se, close_fds=True)     os.write(mi, bytes_input) -    timeout = .04  # seconds+    select_timeout = .04  #seconds     res = {'stdout': b'', 'stderr': b''}     while True:-        ready, _, _ = select.select([mo, me], [], [], timeout)+        ready, _, _ = select.select([mo, me], [], [], select_timeout)         if ready:             for fd in ready:                 data = os.read(fd, 512)                 if not data:                     break                 res[fdmap[fd]] += data-        elif p.poll() is not None:  # select timed-out+        elif p.poll() is not None or time.time(+        ) > timeout_exact:  # select timed-out             break  # p exited     for fd in [si, so, se, mi, mo, me]:         os.close(fd)  # can't do it sooner: it leads to errno.EIO error     p.wait()     return p.returncode, res['stdout'], res['stderr']  +def wrap_test(test_name, test_method, *argv):+    sys.stdout.write(test_name + " ... ")+    try:+        test_method(*argv)+        print green_ok()+    except AssertionError:+        print red_failed()+        raise++ class Prompt(object):-    def __init__(self, deno_exe):+    def __init__(self, deno_exe, test_types):         self.deno_exe = deno_exe+        self.test_types = test_types -    def run(self,-            arg,-            bytes_input,-            allow_read=False,-            allow_write=False,-            allow_net=False,-            allow_env=False,-            allow_run=False,-            no_prompt=False):+    def run(self, arg, bytes_input, args=None):         "Returns (return_code, stdout, stderr)."-        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]-        if allow_read:-            cmd.append("--allow-read")-        if allow_write:-            cmd.append("--allow-write")-        if allow_net:-            cmd.append("--allow-net")-        if allow_env:-            cmd.append("--allow-env")-        if allow_run:-            cmd.append("--allow-run")-        if no_prompt:-            cmd.append("--no-prompt")+        if args is None:+            args = []+        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg] + args         return tty_capture(cmd, bytes_input)      def warm_up(self):         # ignore the ts compiling message-        self.run('needsWrite', b'', allow_write=True)--    def test_read_yes(self):-        code, stdout, stderr = self.run('needsRead', b'y\n')+        self.run('needsWrite', b'', ["--allow-write"])++    def test(self):+        for test_type in self.test_types:+            test_name_base = "test_" + test_type+            wrap_test(test_name_base + "_allow_flag", self.test_allow_flag,

It might look cleaner, but I think from a debugging perspective it's not worth removing that much explicitness from a test. This would likely only save a few lines. I will add some comments to wrap_test.

afinch7

comment created time in a day

Pull request review commentdenoland/deno

More permissions prompt options

 import pty import select import subprocess+import sys+import time -from util import build_path, executable_suffix+from util import build_path, executable_suffix, green_ok, red_failed  PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts" +PROMPT_PATTERN = b'⚠️'+FIRST_CHECK_FAILED_PATTERN = b'First check failed'+PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'+  # This function is copied from: # https://gist.github.com/hayd/4f46a68fc697ba8888a7b517a414583e # https://stackoverflow.com/q/52954248/1240268-def tty_capture(cmd, bytes_input):+def tty_capture(cmd, bytes_input, timeout=5):     """Capture the output of cmd with bytes_input to stdin,     with stdin, stdout and stderr as TTYs."""     mo, so = pty.openpty()  # provide tty to enable line-buffering     me, se = pty.openpty()     mi, si = pty.openpty()     fdmap = {mo: 'stdout', me: 'stderr', mi: 'stdin'} +    timeout_exact = time.time() + timeout     p = subprocess.Popen(         cmd, bufsize=1, stdin=si, stdout=so, stderr=se, close_fds=True)     os.write(mi, bytes_input) -    timeout = .04  # seconds+    select_timeout = .04  #seconds     res = {'stdout': b'', 'stderr': b''}     while True:-        ready, _, _ = select.select([mo, me], [], [], timeout)+        ready, _, _ = select.select([mo, me], [], [], select_timeout)         if ready:             for fd in ready:                 data = os.read(fd, 512)                 if not data:                     break                 res[fdmap[fd]] += data-        elif p.poll() is not None:  # select timed-out+        elif p.poll() is not None or time.time(+        ) > timeout_exact:  # select timed-out             break  # p exited     for fd in [si, so, se, mi, mo, me]:         os.close(fd)  # can't do it sooner: it leads to errno.EIO error     p.wait()     return p.returncode, res['stdout'], res['stderr']  +def wrap_test(test_name, test_method, *argv):+    sys.stdout.write(test_name + " ... ")+    try:+        test_method(*argv)+        print green_ok()+    except AssertionError:+        print red_failed()+        raise++ class Prompt(object):-    def __init__(self, deno_exe):+    def __init__(self, deno_exe, test_types):         self.deno_exe = deno_exe+        self.test_types = test_types -    def run(self,-            arg,-            bytes_input,-            allow_read=False,-            allow_write=False,-            allow_net=False,-            allow_env=False,-            allow_run=False,-            no_prompt=False):+    def run(self, arg, bytes_input, args=None):         "Returns (return_code, stdout, stderr)."-        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]-        if allow_read:-            cmd.append("--allow-read")-        if allow_write:-            cmd.append("--allow-write")-        if allow_net:-            cmd.append("--allow-net")-        if allow_env:-            cmd.append("--allow-env")-        if allow_run:-            cmd.append("--allow-run")-        if no_prompt:-            cmd.append("--no-prompt")+        if args is None:+            args = []+        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg] + args         return tty_capture(cmd, bytes_input)      def warm_up(self):         # ignore the ts compiling message-        self.run('needsWrite', b'', allow_write=True)--    def test_read_yes(self):-        code, stdout, stderr = self.run('needsRead', b'y\n')+        self.run('needsWrite', b'', ["--allow-write"])++    def test(self):+        for test_type in self.test_types:+            test_name_base = "test_" + test_type+            wrap_test(test_name_base + "_allow_flag", self.test_allow_flag,+                      test_type)+            wrap_test(test_name_base + "_yes_yes", self.test_yes_yes,+                      test_type)+            wrap_test(test_name_base + "_yes_no", self.test_yes_no, test_type)+            wrap_test(test_name_base + "_no_no", self.test_no_no, test_type)+            wrap_test(test_name_base + "_no_yes", self.test_no_yes, test_type)+            wrap_test(test_name_base + "_allow", self.test_allow, test_type)+            wrap_test(test_name_base + "_deny", self.test_deny, test_type)+            wrap_test(test_name_base + "_unrecognized_option",+                      self.test_unrecognized_option, test_type)+            wrap_test(test_name_base + "_no_prompt", self.test_no_prompt,+                      test_type)+            wrap_test(test_name_base + "_no_prompt_allow",+                      self.test_no_prompt_allow, test_type)++    def test_allow_flag(self, test_type):+        code, stdout, stderr = self.run("needs" + test_type.capitalize(), b'',

That would be a little cleaner, but we might need to implement tests that don't follow this pattern in the future. I do think that I should combine arg and args now that I'm looking at it again.

afinch7

comment created time in a day

Pull request review commentdenoland/deno

More permissions prompt options

 import pty import select import subprocess+import sys+import time -from util import build_path, executable_suffix+from util import build_path, executable_suffix, green_ok, red_failed  PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts" +PROMPT_PATTERN = b'⚠️'+FIRST_CHECK_FAILED_PATTERN = b'First check failed'+PERMISSION_DENIED_PATTERN = b'PermissionDenied: permission denied'+  # This function is copied from: # https://gist.github.com/hayd/4f46a68fc697ba8888a7b517a414583e # https://stackoverflow.com/q/52954248/1240268-def tty_capture(cmd, bytes_input):+def tty_capture(cmd, bytes_input, timeout=5):     """Capture the output of cmd with bytes_input to stdin,     with stdin, stdout and stderr as TTYs."""     mo, so = pty.openpty()  # provide tty to enable line-buffering     me, se = pty.openpty()     mi, si = pty.openpty()     fdmap = {mo: 'stdout', me: 'stderr', mi: 'stdin'} +    timeout_exact = time.time() + timeout     p = subprocess.Popen(         cmd, bufsize=1, stdin=si, stdout=so, stderr=se, close_fds=True)     os.write(mi, bytes_input) -    timeout = .04  # seconds+    select_timeout = .04  #seconds     res = {'stdout': b'', 'stderr': b''}     while True:-        ready, _, _ = select.select([mo, me], [], [], timeout)+        ready, _, _ = select.select([mo, me], [], [], select_timeout)         if ready:             for fd in ready:                 data = os.read(fd, 512)                 if not data:                     break                 res[fdmap[fd]] += data-        elif p.poll() is not None:  # select timed-out+        elif p.poll() is not None or time.time(+        ) > timeout_exact:  # select timed-out             break  # p exited

I was a little worried there for a moment. I had to test this one to be sure. It does manage to terminate the sub process before it leaves the scope of tty_capture. I figure this:

for fd in [si, so, se, mi, mo, me]:
        os.close(fd)  # can't do it sooner: it leads to errno.EIO error

Causes the process to exit if it hasn't already.

afinch7

comment created time in a day

issue commentdenoland/deno

re-enable arm64 test

I have a working fix. It's dependent on #1938. I will create a PR as soon as you land it.

ry

comment created time in a day

Pull request review commentdenoland/deno

More permissions prompt options

 import pty import select import subprocess+import sys+import time -from util import build_path, executable_suffix+from util import build_path, executable_suffix, green_ok, red_failed  PERMISSIONS_PROMPT_TEST_TS = "tools/permission_prompt_test.ts"   # This function is copied from: # https://gist.github.com/hayd/4f46a68fc697ba8888a7b517a414583e # https://stackoverflow.com/q/52954248/1240268-def tty_capture(cmd, bytes_input):+def tty_capture(cmd, bytes_input, timeout=5):     """Capture the output of cmd with bytes_input to stdin,     with stdin, stdout and stderr as TTYs."""     mo, so = pty.openpty()  # provide tty to enable line-buffering     me, se = pty.openpty()     mi, si = pty.openpty()     fdmap = {mo: 'stdout', me: 'stderr', mi: 'stdin'} +    timeout_exact = time.time() + timeout     p = subprocess.Popen(         cmd, bufsize=1, stdin=si, stdout=so, stderr=se, close_fds=True)     os.write(mi, bytes_input) -    timeout = .04  # seconds+    select_timeout = .04  #seconds     res = {'stdout': b'', 'stderr': b''}     while True:-        ready, _, _ = select.select([mo, me], [], [], timeout)+        ready, _, _ = select.select([mo, me], [], [], select_timeout)         if ready:             for fd in ready:                 data = os.read(fd, 512)                 if not data:                     break                 res[fdmap[fd]] += data-        elif p.poll() is not None:  # select timed-out+        elif p.poll() is not None or time.time(+        ) > timeout_exact:  # select timed-out             break  # p exited     for fd in [si, so, se, mi, mo, me]:         os.close(fd)  # can't do it sooner: it leads to errno.EIO error     p.wait()     return p.returncode, res['stdout'], res['stderr']  +def wrap_test(test_name, test_method, *argv):+    sys.stdout.write(test_name + " ... ")+    try:+        test_method(*argv)+        print green_ok()+    except AssertionError:+        print red_failed()+        raise

Also added a timeout for tests since these tests are prone to getting forever stuck with little explanation.

afinch7

comment created time in a day

create barnchafinch7/deno

branch : fix_script_init_in_core_int

created branch time in a day

push eventafinch7/deno

afinch7

commit sha 80671797c56eea08f6e73cb22116278c9c821f6d

Constants for things and changed assertion pattern for prompts

view details

push time in a day

issue openeddenoland/deno

discussion: state and platform info shouldn't be required by js code

This one comes directly from Philosophy section of the manual.

It will always be distributed as a single executable - and that executable will be sufficient software to <b>any deno program</b>.

Many recent changes involve giving deno programs/scripts/libs access to platform(I.E. build) and state(I.E. permissions) info. While not a bad thing in itself, these sort of features often lead bad practices. From my experience with browser code it's simply better to build code that doesn't need this info to function correctly. In cases where a platform simply doesn't handle some interactions the same way, we should be designing abstractions that actually deal with the root problem instead of expecting deno programs/scripts/libs to implement these workarounds(and thus not be inherently compatible with deno executable on all platforms).

This doesn't necessarily mean reverting these changes. The info they provide may still be needed for debugging, some tests, and error reporting, but I think focusing on some of the key problems, terminal support and file systems(maybe a virtual file system #1836), would be a good goal for future releases. As a clear and simple goal: "The function of the utilities provided to programs and libraries should be the same on all platforms in respect to usability. " Essentially when designing a program or library the target platform(s) shouldn't need to be a factor in the way it is designed. I still don't think there is a good way to apply this to tests, but that shouldn't be affect end users running programs.

Thoughts?

created time in a day

pull request commentdenoland/deno

More permissions prompt options

This is ready for review.

afinch7

comment created time in a day

issue commentdenoland/deno

re-enable arm64 test

Looking at the core integration it looks like you dropped script init. The important information about this error is below:

<anonymous>:1:0
denoMain()
^
Uncaught ReferenceError: denoMain is not defined
    at <anonymous>:1:1

I can start working on a patch for #1938 to refactor init data to better fit with core.

ry

comment created time in a day

push eventafinch7/deno

afinch7

commit sha 617496aea56b5d9af36b68251c75544d48fafb56

Cleaned some stuff up and added a timeout

view details

push time in 2 days

Pull request review commentdenoland/deno

More permissions prompt options

 def wrap_test(test_method, test_name):   class Prompt(object):-    def __init__(self, deno_exe):+    def __init__(self, deno_exe, test_types):         self.deno_exe = deno_exe+        self.test_types = test_types -    def run(self,-            arg,-            bytes_input,-            allow_read=False,-            allow_write=False,-            allow_net=False,-            allow_env=False,-            allow_run=False,-            no_prompt=False):+    def run(self, arg, bytes_input, args=[]):         "Returns (return_code, stdout, stderr)."-        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg]-        if allow_read:-            cmd.append("--allow-read")-        if allow_write:-            cmd.append("--allow-write")-        if allow_net:-            cmd.append("--allow-net")-        if allow_env:-            cmd.append("--allow-env")-        if allow_run:-            cmd.append("--allow-run")-        if no_prompt:-            cmd.append("--no-prompt")+        cmd = [self.deno_exe, PERMISSIONS_PROMPT_TEST_TS, arg] + args         return tty_capture(cmd, bytes_input)      def warm_up(self):         # ignore the ts compiling message         self.run('needsWrite', b'', allow_write=True) -    def test_read_yes(self):-        sys.stdout.write("test_read_yes ...")-        code, stdout, stderr = self.run('needsRead', b'y\n')+    def test(self):+        for test_type in self.test_types:+            test_name_base = "test_" + test_type+            sys.stdout.write(test_name_base + "_allow_flag" + " ... ")+            self.test_allow_flag(test_type)+            print green_ok()+            sys.stdout.write(test_name_base + "_yes_yes" + " ... ")+            self.test_yes_yes(test_type)

No reason. Just didn't feel like it was needed. It does seem like that might be a little more confusing when debugging these tests.

afinch7

comment created time in 2 days

Pull request review commentdenoland/deno

More permissions prompt options

 use ansi_term::Style; use crate::errors::permission_denied; use crate::errors::DenoResult; use std::io;-use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};+use std::sync::Arc;++/// Tri-state value for storing permission state+pub enum PermissionAccessorState {+  Allow = 0,+  Ask = 1,+  Deny = 2,+}++impl From<usize> for PermissionAccessorState {+  fn from(val: usize) -> Self {+    match val {+      0 => PermissionAccessorState::Allow,+      1 => PermissionAccessorState::Ask,+      2 => PermissionAccessorState::Deny,+      _ => unreachable!(),+    }+  }+}++impl From<bool> for PermissionAccessorState {+  fn from(val: bool) -> Self {+    match val {+      true => PermissionAccessorState::Allow,+      false => PermissionAccessorState::Ask,+    }+  }+}++#[derive(Debug)]+pub struct PermissionAccessor {+  state: Arc<AtomicUsize>,+}++impl PermissionAccessor {+  pub fn new(state: PermissionAccessorState) -> Self {+    Self {+      state: Arc::new(AtomicUsize::new(state as usize)),+    }+  }++  pub fn is_allow(&self) -> bool {+    match self.get_state() {+      PermissionAccessorState::Allow => true,+      _ => false,+    }+  }++  /// If the state is "Allow" walk it back to the default "Ask"+  /// Don't do anything if state is "Deny"+  pub fn revoke(&self) {+    if self.is_allow() {+      self.ask();+    }+  }++  pub fn allow(&self) {+    self.set_state(PermissionAccessorState::Allow)+  }++  pub fn ask(&self) {+    self.set_state(PermissionAccessorState::Ask)+  }++  pub fn deny(&self) {+    self.set_state(PermissionAccessorState::Deny)+  }++  /// Update this accessors state based on a PromptResult value+  /// This will only update the state if the PromptResult value+  /// is one of the "Always" values+  pub fn update_with_prompt_result(&self, prompt_result: &PromptResult) {+    match prompt_result {+      PromptResult::AllowAlways => self.allow(),+      PromptResult::DenyAlways => self.deny(),+      _ => {}+    }+  }++  #[inline]+  pub fn get_state(&self) -> PermissionAccessorState {+    self.state.load(Ordering::SeqCst).into()+  }+  fn set_state(&self, state: PermissionAccessorState) {+    self.state.store(state as usize, Ordering::SeqCst)+  }+}++impl From<bool> for PermissionAccessor {+  fn from(val: bool) -> Self {+    Self::new(PermissionAccessorState::from(val))+  }+}++impl Default for PermissionAccessor {+  fn default() -> Self {+    Self {+      state: Arc::new(AtomicUsize::new(PermissionAccessorState::Ask as usize)),+    }+  }+}  #[cfg_attr(feature = "cargo-clippy", allow(stutter))] #[derive(Debug, Default)] pub struct DenoPermissions {   // Keep in sync with src/permissions.ts-  pub allow_read: AtomicBool,-  pub allow_write: AtomicBool,-  pub allow_net: AtomicBool,-  pub allow_env: AtomicBool,-  pub allow_run: AtomicBool,+  pub allow_read: PermissionAccessor,+  pub allow_write: PermissionAccessor,+  pub allow_net: PermissionAccessor,+  pub allow_env: PermissionAccessor,+  pub allow_run: PermissionAccessor,   pub no_prompts: AtomicBool, }  impl DenoPermissions {   pub fn from_flags(flags: &DenoFlags) -> Self {     Self {-      allow_read: AtomicBool::new(flags.allow_read),-      allow_write: AtomicBool::new(flags.allow_write),-      allow_env: AtomicBool::new(flags.allow_env),-      allow_net: AtomicBool::new(flags.allow_net),-      allow_run: AtomicBool::new(flags.allow_run),+      allow_read: PermissionAccessor::from(flags.allow_read),+      allow_write: PermissionAccessor::from(flags.allow_write),+      allow_env: PermissionAccessor::from(flags.allow_env),+      allow_net: PermissionAccessor::from(flags.allow_net),+      allow_run: PermissionAccessor::from(flags.allow_run),       no_prompts: AtomicBool::new(flags.no_prompts),     }   }    pub fn check_run(&self) -> DenoResult<()> {-    if self.allow_run.load(Ordering::SeqCst) {-      return Ok(());-    };-    // TODO get location (where access occurred)-    let r = self.try_permissions_prompt("access to run a subprocess");-    if r.is_ok() {-      self.allow_run.store(true, Ordering::SeqCst);+    match self.allow_run.get_state() {+      PermissionAccessorState::Allow => Ok(()),+      PermissionAccessorState::Ask => {+        match self.try_permissions_prompt("access to run a subprocess") {+          Err(e) => Err(e),+          Ok(v) => {+            self.allow_run.update_with_prompt_result(&v);+            v.check()?;+            Ok(())+          }+        }+      }+      PermissionAccessorState::Deny => Err(permission_denied()),     }-    r   }    pub fn check_read(&self, filename: &str) -> DenoResult<()> {-    if self.allow_read.load(Ordering::SeqCst) {-      return Ok(());-    };-    // TODO get location (where access occurred)-    let r =-      self.try_permissions_prompt(&format!("read access to \"{}\"", filename));;-    if r.is_ok() {-      self.allow_read.store(true, Ordering::SeqCst);+    match self.allow_read.get_state() {+      PermissionAccessorState::Allow => Ok(()),+      PermissionAccessorState::Ask => match self+        .try_permissions_prompt(&format!("read access to \"{}\"", filename))+      {+        Err(e) => Err(e),+        Ok(v) => {+          self.allow_run.update_with_prompt_result(&v);+          v.check()?;+          Ok(())+        }+      },+      PermissionAccessorState::Deny => Err(permission_denied()),     }-    r   }    pub fn check_write(&self, filename: &str) -> DenoResult<()> {-    if self.allow_write.load(Ordering::SeqCst) {-      return Ok(());-    };-    // TODO get location (where access occurred)-    let r =-      self.try_permissions_prompt(&format!("write access to \"{}\"", filename));;-    if r.is_ok() {-      self.allow_write.store(true, Ordering::SeqCst);+    match self.allow_write.get_state() {+      PermissionAccessorState::Allow => Ok(()),+      PermissionAccessorState::Ask => match self+        .try_permissions_prompt(&format!("write access to \"{}\"", filename))+      {+        Err(e) => Err(e),+        Ok(v) => {+          self.allow_run.update_with_prompt_result(&v);+          v.check()?;+          Ok(())+        }+      },+      PermissionAccessorState::Deny => Err(permission_denied()),     }-    r   }    pub fn check_net(&self, domain_name: &str) -> DenoResult<()> {-    if self.allow_net.load(Ordering::SeqCst) {-      return Ok(());-    };-    // TODO get location (where access occurred)-    let r = self.try_permissions_prompt(&format!(-      "network access to \"{}\"",-      domain_name-    ));-    if r.is_ok() {-      self.allow_net.store(true, Ordering::SeqCst);+    match self.allow_net.get_state() {+      PermissionAccessorState::Allow => Ok(()),+      PermissionAccessorState::Ask => match self.try_permissions_prompt(+        &format!("network access to \"{}\"", domain_name),+      ) {+        Err(e) => Err(e),+        Ok(v) => {+          self.allow_run.update_with_prompt_result(&v);+          v.check()?;+          Ok(())+        }+      },+      PermissionAccessorState::Deny => Err(permission_denied()),     }-    r   }    pub fn check_env(&self) -> DenoResult<()> {-    if self.allow_env.load(Ordering::SeqCst) {-      return Ok(());-    };-    // TODO get location (where access occurred)-    let r = self.try_permissions_prompt(&"access to environment variables");-    if r.is_ok() {-      self.allow_env.store(true, Ordering::SeqCst);+    match self.allow_env.get_state() {+      PermissionAccessorState::Allow => Ok(()),+      PermissionAccessorState::Ask => {+        match self.try_permissions_prompt("access to environment variables") {+          Err(e) => Err(e),+          Ok(v) => {+            self.allow_run.update_with_prompt_result(&v);+            v.check()?;+            Ok(())+          }+        }+      }+      PermissionAccessorState::Deny => Err(permission_denied()),     }-    r   }    /// Try to present the user with a permission prompt   /// will error with permission_denied if no_prompts is enabled-  fn try_permissions_prompt(&self, message: &str) -> DenoResult<()> {+  fn try_permissions_prompt(&self, message: &str) -> DenoResult<PromptResult> {     if self.no_prompts.load(Ordering::SeqCst) {       return Err(permission_denied());     }+    if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) {+      return Err(permission_denied());+    };     permission_prompt(message)   }    pub fn allows_run(&self) -> bool {-    return self.allow_run.load(Ordering::SeqCst);+    return self.allow_run.is_allow();   }    pub fn allows_read(&self) -> bool {-    return self.allow_read.load(Ordering::SeqCst);+    return self.allow_read.is_allow();   }    pub fn allows_write(&self) -> bool {-    return self.allow_write.load(Ordering::SeqCst);+    return self.allow_write.is_allow();   }    pub fn allows_net(&self) -> bool {-    return self.allow_net.load(Ordering::SeqCst);+    return self.allow_net.is_allow();   }    pub fn allows_env(&self) -> bool {-    return self.allow_env.load(Ordering::SeqCst);+    return self.allow_env.is_allow();   }    pub fn revoke_run(&self) -> DenoResult<()> {-    self.allow_run.store(false, Ordering::SeqCst);+    self.allow_run.revoke();     return Ok(());   }    pub fn revoke_read(&self) -> DenoResult<()> {-    self.allow_read.store(false, Ordering::SeqCst);+    self.allow_read.revoke();     return Ok(());   }    pub fn revoke_write(&self) -> DenoResult<()> {-    self.allow_write.store(false, Ordering::SeqCst);+    self.allow_write.revoke();     return Ok(());   }    pub fn revoke_net(&self) -> DenoResult<()> {-    self.allow_net.store(false, Ordering::SeqCst);+    self.allow_net.revoke();     return Ok(());   }    pub fn revoke_env(&self) -> DenoResult<()> {-    self.allow_env.store(false, Ordering::SeqCst);+    self.allow_env.revoke();     return Ok(());   }+} -  pub fn default() -> Self {-    Self {-      allow_read: AtomicBool::new(false),-      allow_write: AtomicBool::new(false),-      allow_env: AtomicBool::new(false),-      allow_net: AtomicBool::new(false),-      allow_run: AtomicBool::new(false),-      ..Default::default()+/// Quad-state value for representing user input on permission prompt+#[derive(Debug, Clone)]+pub enum PromptResult {+  AllowAlways = 0,+  AllowOnce = 1,+  DenyOnce = 2,+  DenyAlways = 3,+}++impl PromptResult {+  /// If value is any form of deny this will error with permission_denied+  pub fn check(&self) -> DenoResult<()> {+    match self {+      PromptResult::DenyOnce => Err(permission_denied()),+      PromptResult::DenyAlways => Err(permission_denied()),+      _ => Ok(()),     }   } } -fn permission_prompt(message: &str) -> DenoResult<()> {-  if !atty::is(atty::Stream::Stdin) || !atty::is(atty::Stream::Stderr) {-    return Err(permission_denied());-  };-  let msg = format!("⚠️  Deno requests {}. Grant? [yN] ", message);+fn permission_prompt(message: &str) -> DenoResult<PromptResult> {+  let msg = format!("⚠️  Deno requests {}. Grant? [a/y/n/d (a = allow always, y = allow once, n = deny once, d = deny always)] ", message);   // print to stderr so that if deno is > to a file this is still displayed.   eprint!("{}", Style::new().bold().paint(msg));-  let mut input = String::new();-  let stdin = io::stdin();-  let _nread = stdin.read_line(&mut input)?;-  let ch = input.chars().next().unwrap();-  let is_yes = ch == 'y' || ch == 'Y';-  if is_yes {-    Ok(())-  } else {-    Err(permission_denied())+  loop {+    let mut input = String::new();+    let stdin = io::stdin();+    let _nread = stdin.read_line(&mut input)?;+    let ch = input.chars().next().unwrap();+    match ch.to_ascii_lowercase() {+      'a' => return Ok(PromptResult::AllowAlways),+      'y' => return Ok(PromptResult::AllowOnce),+      'n' => return Ok(PromptResult::DenyOnce),+      'd' => return Ok(PromptResult::DenyAlways),+      _ => {+        // If we don't get a recognized option try again.+        let msg_again = format!("Unrecognized option '{}' [a/y/n/d (a = allow always, y = allow once, n = deny once, d = deny always)] ", ch);+        eprint!("{}", Style::new().bold().paint(msg_again));+      }

My solution at this point is to have two calls to the same operation, and one of them wrapped in a try-catch with a distinct console output First check failed.

try {
  readFileSync("package.json");
} catch (e) {
  console.log("First check failed");
}
readFileSync("package.json");

That way I can test combinations of allow once/deny once, and allow always/deny always.

afinch7

comment created time in 2 days

push eventafinch7/deno

afinch7

commit sha 332cda73a171e6c9d14ccc922b00dc2425807918

Fixed linter issues, removed async from test function, and added another test case no_prompt_allow

view details

push time in 2 days

pull request commentdenoland/deno

More permissions prompt options

Did a refactor of the permissions prompt tests. They are now semi-procedural I.E. test_yes_yes("read"). This should make them a little easier to maintain and update. I not completely sure if the run() call is synchronous, but it seems like it behaves just like the other calls in testing.

afinch7

comment created time in 2 days

push eventafinch7/deno

afinch7

commit sha 9f528bc4481617142925fae3fe680e0c0d55d4c2

Fixed a bug and implemeneted fmt::Display for PermissionAccessorState and Prompt result.

view details

afinch7

commit sha 463537809d1d59352aa3687f21cbe9bc6a8449c3

Redesigned permissions prompt testing and added in tests for most new conditions

view details

push time in 2 days

issue commentdenoland/deno

Add KV Storage Built In Module

I meant the KV Storage implementations not the browser itself.

kitsonk

comment created time in 6 days

issue commentdenoland/deno

Add KV Storage Built In Module

They way you put it the first time it sounded like it was just a implementation choice, but no it actually exists in the spec https://wicg.github.io/kv-storage/#storagearea-backingstore. That seems like a really questionable design choice if you ask me. We might have been at a point where IndexDB could be deprecated in favor of a promise based standard, but now one of the most questionable web APIs has another silly reason that it has to exist other than "for legacy applications". The point of an API is not to dictate implementation. This API is almost directly dependent on it's implementation. What happens when the way that x browser stores this information in IndexDB is not exactly the same as y browser? Is the idea to have a js module that works on all browsers? If that was the case why not just release it as a standalone js library? I like the idea of a more modern alternative to localStorage, but this seems like a really bad way to go about it.

kitsonk

comment created time in 6 days

Pull request review commentdenoland/deno

Integrate src/ with core/

 pub fn compile_sync(   send_future.wait().unwrap();    let recv_future = resources::worker_recv_message(compiler.rid);-  let res_msg = recv_future.wait().unwrap().unwrap();+  let result = recv_future.wait().unwrap();

The next error I run into in tests is pretty complicated. For some reason we end up with a thread panic in the middle of our file not found error print out:

Compiling file:///home/andy/Documents/projects/personal/deno/tests/error_004_missing_module.ts
thread 'Uncaught NotFound: Cannot resolve module "bad-module.ts" from "/home/andy/Documents/projects/personal/deno/tests/error_004_missing_module.ts"
    at DenoError (deno/js/errors.ts:22:5)
    at maybeError (deno/js/errors.ts:33:12)
    at maybeThrowError (deno/js/errors.ts:39:15)
    at sendSync (deno/js/dispatch.ts:87:5)
    at fetchModuleMetaData (deno/js/os.ts:81:19)
    at _resolveModule (deno/js/compiler.ts:249:38)
    at resolveModuleNames (deno/js/compiler.ts:479:35)
    at compilerHost.resolveModuleNames (deno/third_party/node_modules/typescript/lib/typescript.js:118650:138)
    at resolveModuleNamesWorker (deno/third_party/node_modules/typescript/lib/typescript.js:86767:127)
    at resolveModuleNamesReusingOldState (deno/third_party/node_modules/typescript/lib/typescript.js:87001:24)tokio-runtime-worker-0
' panicked at 'called `Result::unwrap()` on an `Err` value: DenoError { repr: Simple(BadResource, "bad resource id") }', src/libcore/result.rs:997:5

It's not really a problem for end users, but it just makes it very difficult to test expected failures. The best way to replicate this one is with target/release/deno tests/error_004_missing_module.ts --reload. It looks like the thread that compile_sync is running in manages to panic here before we finish our error print and exit in workers.rs. Maybe we should avoid the panic here by returning a Result error.

ry

comment created time in 6 days

PR opened denoland/deno

[WIP]: More permissions prompt options

Added some new permissions prompt options, and gave better names to existing options. The existing options when you receive a permission prompt are: y for allow always(I thought this meant yes once for some time) and n for no once(give the program a permission denied error this time). This change adds two new options and renames the existing allow always option the new set of options are:

  • a/A for allow always for this permission type
  • y/Y for allow once
  • n/N for deny once
  • d/D for deny always for this permission type

It might also make sense to remove the revoke commands, since this solves the same problems in a way that doesn't conflict with --no-prompt.

+281 -145

0 comment

4 changed files

pr created time in 6 days

create barnchafinch7/deno

branch : more_prompt_options

created branch time in 6 days

push eventafinch7/deno

afinch7

commit sha 82dea1dad5056c835f0f8ace19d9b7cfda159445

fmt

view details

push time in 6 days

push eventafinch7/deno

afinch7

commit sha 5395a33d4637ec7b574cf17d3e5e27429ee5b1d3

fmt

view details

push time in 7 days

push eventafinch7/deno

afinch7

commit sha 7625d117db513adc2899e5c477b1437cf92edab8

Wrap this comment

view details

push time in 7 days

issue commentdenoland/deno

Add KV Storage Built In Module

Doesn't mean that we have to implement it like that.

kitsonk

comment created time in 7 days

push eventafinch7/deno

afinch7

commit sha 0e4ee2db91613d4278a0ac501eeaa0197524e9f1

Added a comment to make ci run again

view details

push time in 7 days

push eventafinch7/deno

afinch7

commit sha 03665efb6463108e85a10b56607e27ddb0411eda

Forgot the most important part

view details

push time in 7 days

push eventafinch7/deno

afinch7

commit sha 4af28451e6e9854c7dd60340e862e182f16d48d5

Added some tests

view details

push time in 7 days

Pull request review commentdenoland/deno

Integrate src/ with core/

+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.+#![allow(unused_variables)]+#![allow(dead_code)]++use crate::errors::DenoResult;+use crate::isolate_init::IsolateInit;+use crate::isolate_state::IsolateState;+use crate::msg_ring;+use crate::ops;+use crate::permissions::DenoPermissions;+use deno_core::deno_buf;+use deno_core::deno_mod;+use deno_core::Behavior;+use deno_core::Op;+use std::cell::Cell;+use std::sync::atomic::Ordering;+use std::sync::Arc;+use std::time::Instant;++// Buf represents a byte array returned from a "Op". The message might be empty+// (which will be translated into a null object on the javascript side) or it is+// a heap allocated opaque sequence of bytes.  Usually a flatbuffer message.+pub type Buf = Box<[u8]>;++pub type CliOp = Op<Buf>;++/// Implements deno_core::Behavior for the main Deno command-line.+pub struct Cli {+  shared: Option<deno_buf>, // Pin?+  tx: msg_ring::Sender,+  rx: msg_ring::Receiver,+  init: IsolateInit,+  timeout_due: Cell<Option<Instant>>,+  pub state: Arc<IsolateState>,+  pub permissions: Arc<DenoPermissions>, // TODO(ry) move to IsolateState+}++impl Cli {+  pub fn new(+    init: IsolateInit,+    state: Arc<IsolateState>,+    permissions: DenoPermissions,+  ) -> Self {+    let buffer = msg_ring::Buffer::new(1024 * 1024);

It looks like this might become problematic. The record that failed in that test was smaller than 1048576 bytes, so it was likely caused by a chain of blocking operations. At what point are records removed from the buffer here(I assume that is what records_shift is for)? Could this garbage collection potentially be blocked by chain operations(I.E. lots of imports in a single file)?

ry

comment created time in 7 days

Pull request review commentdenoland/deno

Integrate src/ with core/

+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.+#![allow(unused_variables)]+#![allow(dead_code)]++use crate::errors::DenoResult;+use crate::isolate_init::IsolateInit;+use crate::isolate_state::IsolateState;+use crate::msg_ring;+use crate::ops;+use crate::permissions::DenoPermissions;+use deno_core::deno_buf;+use deno_core::deno_mod;+use deno_core::Behavior;+use deno_core::Op;+use std::cell::Cell;+use std::sync::atomic::Ordering;+use std::sync::Arc;+use std::time::Instant;++// Buf represents a byte array returned from a "Op". The message might be empty+// (which will be translated into a null object on the javascript side) or it is+// a heap allocated opaque sequence of bytes.  Usually a flatbuffer message.+pub type Buf = Box<[u8]>;++pub type CliOp = Op<Buf>;++/// Implements deno_core::Behavior for the main Deno command-line.+pub struct Cli {+  shared: Option<deno_buf>, // Pin?+  tx: msg_ring::Sender,+  rx: msg_ring::Receiver,+  init: IsolateInit,+  timeout_due: Cell<Option<Instant>>,+  pub state: Arc<IsolateState>,+  pub permissions: Arc<DenoPermissions>, // TODO(ry) move to IsolateState+}++impl Cli {+  pub fn new(+    init: IsolateInit,+    state: Arc<IsolateState>,+    permissions: DenoPermissions,+  ) -> Self {+    let buffer = msg_ring::Buffer::new(1024 * 1024);

This buffer is too small for some tests to complete. Might need a redesign. Changing it to 1024 * 8196 bytes(~8MB) get us past the current failure, but errors out on a later test with:

tests/error_004_missing_module.test ... FAILED
Expected output does not match actual.
Expected output: 
Compiling [WILDCARD]tests/error_004_missing_module.ts
Uncaught NotFound: Cannot resolve module "bad-module.ts" from "[WILDCARD]/tests/error_004_missing_module.ts"
    at DenoError ([WILDCARD]/js/errors.ts:[WILDCARD])
    at maybeError ([WILDCARD]/js/errors.ts:[WILDCARD])
    at maybeThrowError ([WILDCARD]/js/errors.ts:[WILDCARD])
    at sendSync ([WILDCARD]/js/dispatch.ts:[WILDCARD])
    at fetchModuleMetaData ([WILDCARD]/js/os.ts:[WILDCARD])
    at _resolveModule ([WILDCARD]/js/compiler.ts:[WILDCARD])
    at resolveModuleNames ([WILDCARD]/js/compiler.ts:[WILDCARD])
    at compilerHost.resolveModuleNames ([WILDCARD]typescript.js:[WILDCARD])
    at resolveModuleNamesWorker ([WILDCARD]typescript.js:[WILDCARD])
    at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])

Actual output:   
Compiling file:///home/andy/Documents/projects/personal/deno/tests/error_004_missing_module.ts
Uncaught NotFound: Cannot resolve module "bad-module.ts" from "/home/andy/Documents/projects/personal/deno/tests/error_004_missing_module.ts"
    at DenoError (deno/js/errors.ts:22:5)
    at maybeError (deno/js/errors.ts:33:12)
    at maybeThrowError (deno/js/errors.ts:39:15)
    at sendSync (deno/js/dispatch.ts:87:5)
    at fetchModuleMetaData (deno/js/os.ts:81:19)
    at _resolveModule (deno/js/compiler.ts:249:38)
    at resolveModuleNames (deno/js/compiler.ts:479:35)
    at compilerHost.resolveModuleNames (deno/third_party/node_modules/typescript/lib/typescript.js:118650:138)
    at resolveModuleNamesWorker (deno/third_party/node_modules/typescript/lib/typescript.js:86767:127)
    at resolveModuleNamesReusingOldState (deno/third_party/node_modules/typescript/lib/typescript.js:87001:24)thread '
tokio-runtime-worker-0' panicked at 'called `Result::unwrap()` on an `Err` value: DenoError { repr: Simple(BadResource, "bad resource id") }', src/libcore/result.rs:997:5
ry

comment created time in 7 days

Pull request review commentdenoland/deno

No prompts flag for non interactive environments.

 pub fn set_flags(   opts.optflag("", "allow-env", "Allow environment access");   opts.optflag("", "allow-run", "Allow running subprocesses");   opts.optflag("A", "allow-all", "Allow all permissions");+  opts.optflag("", "no-prompt", "Do not use prompts");

I guess for the time being it only affects permissions, but If we add any other prompts in the future it should be used to allow disabling those as well.

afinch7

comment created time in 8 days

push eventafinch7/deno

afinch7

commit sha 57c362f841f866c58247b4912363806bf07543f4

Not sure what I was thinking with that last commit

view details

push time in 8 days

Pull request review commentdenoland/deno

No prompts flag for non interactive environments.

 impl DenoPermissions {       return Ok(());     };     // TODO get location (where access occurred)-    let r = permission_prompt("access to run a subprocess");-    if r.is_ok() {-      self.allow_run.store(true, Ordering::SeqCst);+    if !self.no_prompts.load(Ordering::SeqCst) {+      let r = permission_prompt("access to run a subprocess");+      if r.is_ok() {+        self.allow_run.store(true, Ordering::SeqCst);+      }+      r+    } else {+      Err(permission_denied())     }-    r   }    pub fn check_read(&self, filename: &str) -> DenoResult<()> {     if self.allow_read.load(Ordering::SeqCst) {       return Ok(());     };     // TODO get location (where access occurred)-    let r = permission_prompt(&format!("read access to \"{}\"", filename));;-    if r.is_ok() {-      self.allow_read.store(true, Ordering::SeqCst);+    if !self.no_prompts.load(Ordering::SeqCst) {+      let r = permission_prompt(&format!("read access to \"{}\"", filename));;+      if r.is_ok() {+        self.allow_read.store(true, Ordering::SeqCst);+      }+      r+    } else {+      Err(permission_denied())     }-    r   }    pub fn check_write(&self, filename: &str) -> DenoResult<()> {     if self.allow_write.load(Ordering::SeqCst) {       return Ok(());     };     // TODO get location (where access occurred)-    let r = permission_prompt(&format!("write access to \"{}\"", filename));;-    if r.is_ok() {-      self.allow_write.store(true, Ordering::SeqCst);+    if !self.no_prompts.load(Ordering::SeqCst) {+      let r = permission_prompt(&format!("write access to \"{}\"", filename));;+      if r.is_ok() {+        self.allow_write.store(true, Ordering::SeqCst);+      }+      r+    } else {+      Err(permission_denied())     }-    r   }    pub fn check_net(&self, domain_name: &str) -> DenoResult<()> {     if self.allow_net.load(Ordering::SeqCst) {       return Ok(());     };     // TODO get location (where access occurred)-    let r =-      permission_prompt(&format!("network access to \"{}\"", domain_name));-    if r.is_ok() {-      self.allow_net.store(true, Ordering::SeqCst);+    if !self.no_prompts.load(Ordering::SeqCst) {+      let r =+        permission_prompt(&format!("network access to \"{}\"", domain_name));+      if r.is_ok() {+        self.allow_net.store(true, Ordering::SeqCst);+      }+      r+    } else {+      Err(permission_denied())

That should be much cleaner.

afinch7

comment created time in 8 days

push eventafinch7/deno

afinch7

commit sha ddd043d1f75b72d247bd662d3777a117ada5b5dc

Applied a little DRY to no prompts checks in permissions.

view details

push time in 8 days

Pull request review commentdenoland/deno

No prompts flag for non interactive environments.

 pub fn set_flags(   opts.optflag("", "allow-env", "Allow environment access");   opts.optflag("", "allow-run", "Allow running subprocesses");   opts.optflag("A", "allow-all", "Allow all permissions");+  opts.optflag("", "no-prompt", "Do not use prompts");

No prompt shouldn't be limited to permissions, so in that respect it's different than --deny. Either your there to answer for prompts or you aren't as a user.

afinch7

comment created time in 8 days

issue commentdenoland/deno

Colors capability detection

Not really a fan of "sniffing" either. One of the primary benefits of javascript is it can be abstracted from the host. This should really be abstracted out in rust or the deno js libs.

zekth

comment created time in 8 days

pull request commentdenoland/deno

No prompts flag for non interactive environments.

That only checks if stdio is a tty. Not really the same as the user simply wanting to disable all prompts regardless of tty.

afinch7

comment created time in 8 days

Pull request review commentdenoland/deno

Small cleanups for //core

 pub trait Behavior<R> {   fn records_shift(&mut self) -> Option<R>; } +/// A single excitation context of JavaScript. Corresponds roughly to the "Web

typo here

ry

comment created time in 8 days

PR opened denoland/deno

No prompts flag for non interactive environments.
+54 -21

0 comment

4 changed files

pr created time in 8 days

push eventafinch7/deno

afinch7

commit sha 9160e8de067fe19ab11f3f74eb795550c804e752

No prompts flag for non interactive environments.

view details

push time in 8 days

create barnchafinch7/deno

branch : no-prompt-flag

created branch time in 8 days

push eventafinch7/deno

afinch7

commit sha 5ac3ed4a8d5648281f52d8b2fbaec23d3b36fccd

Removed rename tests binary from .travis.yml

view details

push time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 fn main() {     env::var("PROFILE").unwrap()   }; +  // Equivalent to target arch != host arch+  let is_different_target_arch =+    env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() != env::var("HOST")+      .unwrap()+      .as_str()+      .split("-")+      .collect::<Vec<&str>>()[0];++  // If we are not using a standard target+  let is_nonstandard_target =

I added some more detailed comments Including how to check your default target: rustup target list

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha 844db3ad55872f24fc04ef198309c0d079047a97

Added some more detailed comments to build.rs

view details

push time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 fn main() {     env::var("PROFILE").unwrap()   }; +  // Equivalent to target arch != host arch+  let is_different_target_arch =+    env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() != env::var("HOST")+      .unwrap()+      .as_str()+      .split("-")+      .collect::<Vec<&str>>()[0];++  // If we are not using a standard target+  let is_nonstandard_target =

Actually I like is_default_target better.

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 fn main() {     env::var("PROFILE").unwrap()   }; +  // Equivalent to target arch != host arch+  let is_different_target_arch =+    env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() != env::var("HOST")+      .unwrap()+      .as_str()+      .split("-")+      .collect::<Vec<&str>>()[0];++  // If we are not using a standard target+  let is_nonstandard_target =

HOST, TARGET, and CARGO_CFG_TARGET_ARCH are standard variables provided by cargo and documented here https://doc.rust-lang.org/cargo/reference/environment-variables.html I might rename this is_not_default_target. The output of rustup target list will tell you what is default for your install of cargo/rustup.

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 jobs:           branch: master           repo: denoland/deno         skip-cleanup: true+    +    - name: "cargo release linux arm64"+      os: linux+      dist: xenial+      script:+      - rustup target add aarch64-unknown-linux-gnu+      - sudo apt update+      - |-+        sudo apt -yq --no-install-suggests --no-install-recommends install+        g++-5-aarch64-linux-gnu gcc-5-aarch64-linux-gnu g++-5-multilib+        libc6-arm64-cross+      - build/linux/sysroot_scripts/install-sysroot.py --arch=arm64+      - export DENO_BUILD_ARGS="target_cpu=\"arm64\" v8_target_cpu=\"arm64\""+      - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="/usr/bin/aarch64-linux-gnu-gcc-5"+      - export CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc-5"+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --locked+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --tests --locked+      - |-+        mv $(find $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release+        -maxdepth 1 -type f -executable -regextype sed -regex+        '.*/[a-z_]*-[0-9a-f]*') +        $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/test_rs

This one should make more sense now that the backslashes are in.

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 jobs:           branch: master           repo: denoland/deno         skip-cleanup: true+    +    - name: "cargo release linux arm64"+      os: linux+      dist: xenial+      script:+      - rustup target add aarch64-unknown-linux-gnu+      - sudo apt update+      - |-+        sudo apt -yq --no-install-suggests --no-install-recommends install+        g++-5-aarch64-linux-gnu gcc-5-aarch64-linux-gnu g++-5-multilib+        libc6-arm64-cross+      - build/linux/sysroot_scripts/install-sysroot.py --arch=arm64+      - export DENO_BUILD_ARGS="target_cpu=\"arm64\" v8_target_cpu=\"arm64\""+      - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="/usr/bin/aarch64-linux-gnu-gcc-5"+      - export CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc-5"+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --locked+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --tests --locked+      - |-+        mv $(find $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release+        -maxdepth 1 -type f -executable -regextype sed -regex+        '.*/[a-z_]*-[0-9a-f]*') 

It shouldn't require any changes. The binary it outputs is almost identical to the test_rs from gn builds(different process same result). I've already successfully used it with tools/test.py.

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha d97c1ff30680a7267c169ad735b0c68fc93b39b5

Fixed accidental changes to submodules

view details

push time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 jobs:           branch: master           repo: denoland/deno         skip-cleanup: true+    +    - name: "cargo release linux arm64"+      os: linux+      dist: xenial+      script:+      - rustup target add aarch64-unknown-linux-gnu+      - sudo apt update+      - |-+        sudo apt -yq --no-install-suggests --no-install-recommends install+        g++-5-aarch64-linux-gnu gcc-5-aarch64-linux-gnu g++-5-multilib+        libc6-arm64-cross+      - build/linux/sysroot_scripts/install-sysroot.py --arch=arm64+      - export DENO_BUILD_ARGS="target_cpu=\"arm64\" v8_target_cpu=\"arm64\""+      - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="/usr/bin/aarch64-linux-gnu-gcc-5"+      - export CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc-5"+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --locked+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --tests --locked+      - |-+        mv $(find $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release+        -maxdepth 1 -type f -executable -regextype sed -regex+        '.*/[a-z_]*-[0-9a-f]*') 

This might need a comment. cargo build --tests builds cargo test as a executable Unfortunately the name of the binary can't be specified. I think it's based on a hash or something. The solution is to find said executable and rename it to test_rs.

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha 420a0be76dcc4208721161f0660a55789ef426a6

Some backslashes for .travis.yml

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 136040ded4b4f1312de5d18cd4369699e3f350da

Format and renamed some variables in build.rs

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha c0afaabd82ac6e677539faf9c302c3318b86ebd5

fmt

view details

push time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 fn main() {     env::var("PROFILE").unwrap()   }; +  // Equivilent to target arch != host arch+  let is_cross_compile = env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str()

is_cross_compile might be a bad name for this one.

afinch7

comment created time in 12 days

push eventafinch7/deno

Ryan Dahl

commit sha c42a9d737081fb8ee768c7178dae0e1f19c0f343

Upgrade deno_std (#1892) A major API change was that asserts are imported from testing/asserts.ts now rather than testing/mod.ts and assertEqual as renamed to assertEquals to conform to what is most common in JavaScript.

view details

Ryan Dahl

commit sha 535037b519711d238dc0bfa2c4d2ffb4b17dec53

v0.3.2

view details

Kitson Kelly

commit sha 0473d832c138a7acc25372441cfa01848e6b9915

Cleanup node_modules, update packages (#1894) And fix new lint issues.

view details

Ryan Dahl

commit sha cd1992aeaab92c4446ac289bced3ec548050467d

Upgrade deno_std to 395392 (#1902)

view details

Kitson Kelly

commit sha 24d6bf6aeb2b9ac929808e2b8ae4cd5e844a9f8b

Remove 'deno' builtin module (#1895)

view details

afinch7

commit sha 7820d5f534014bfef7ae28c0cb029fb518894118

Merge remote-tracking branch 'upstream/master' into arm-builds-ci

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 46927e7fd0dec3d4c0c311d571a9af28d4f01362

Added some comments and added another variable in build.rs for nonstandard targets.

view details

push time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 fn main() {     env::var("PROFILE").unwrap()   }; +  // Equivilent to target arch != host arch+  let is_cross_compile = env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str()

This might not have the intended effect. Some targets might vary from host, but will still be compatible with the host. I.E. x86_64-unknown-linux-musl

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 import {   TypeGuards,   VariableStatement,   VariableDeclarationKind-} from "ts-simple-ast";+} from "ts-morph";

Yet again from master.

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 export function main({     compilerOptions: {       baseUrl: buildPath,       moduleResolution: ModuleResolutionKind.NodeJs,-      noLib: true,

ditto

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 export function main({       baseUrl: basePath,       declaration: true,       emitDeclarationOnly: true,-      lib: [],-      module: ModuleKind.AMD,+      module: ModuleKind.ESNext,       moduleResolution: ModuleResolutionKind.NodeJs,-      noLib: true,+      // noLib: true,

I made some changes to tools for testing, but ended up reverting them. Might need to do a rebase before merge.

afinch7

comment created time in 12 days

Pull request review commentdenoland/deno

Arm64 build process for ci

 jobs:           branch: master           repo: denoland/deno         skip-cleanup: true+    +    - name: "cargo release linux arm64"+      os: linux+      dist: xenial+      script:+      - rustup target add aarch64-unknown-linux-gnu+      - sudo apt update+      - sudo apt -yq --no-install-suggests --no-install-recommends install g++-5-aarch64-linux-gnu gcc-5-aarch64-linux-gnu g++-5-multilib libc6-arm64-cross+      - build/linux/sysroot_scripts/install-sysroot.py --arch=arm64+      - export DENO_BUILD_ARGS="target_cpu=\"arm64\" v8_target_cpu=\"arm64\""+      - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="/usr/bin/aarch64-linux-gnu-gcc-5"+      - export CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc-5"+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --locked+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --tests --locked+      - mv $(find $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release -maxdepth 1 -type f -executable -regextype sed -regex '.*/[a-z_]*-[0-9a-f]*') $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/test_rs+      - sudo apt -yq install qemu qemu-user binfmt-support qemu-user-binfmt+      - sudo ln -s /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1 /lib/ld-linux-aarch64.so.1+      - export QEMU_LD_PREFIX=/usr/aarch64-linux-gnu+      - $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/deno tests/002_hello.ts+      # - DENO_BUILD_MODE=release ./tools/test.py $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release TODO(afinch7): Get the tests working

I added it into deno_deps_cross group, but it's currently throwing a error that looks really familiar.

#
# Fatal error in , line 0
# unreachable code
#
#
#
#FailureMessage Object: 0x4001224930
==== C stack trace ===============================

    target/aarch64-unknown-linux-gnu/release/test_cc(+0x9da184) [0x40009da184]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x9d9750) [0x40009d9750]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x9d580c) [0x40009d580c]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x7f61bc) [0x40007f61bc]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x6c44dc) [0x40006c44dc]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x74b558) [0x400074b558]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x74b4a0) [0x400074b4a0]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x74a08c) [0x400074a08c]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x74b328) [0x400074b328]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x749588) [0x4000749588]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x21be90) [0x400021be90]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x754718) [0x4000754718]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x600548) [0x4000600548]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x75335c) [0x400075335c]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1dc7d4) [0x40001dc7d4]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1dc8bc) [0x40001dc8bc]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1c5e80) [0x40001c5e80]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1b6dc8) [0x40001b6dc8]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x983bac) [0x4000983bac]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x9844e0) [0x40009844e0]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x984944) [0x4000984944]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x990238) [0x4000990238]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x98fcec) [0x400098fcec]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1c53fc) [0x40001c53fc]
    /lib/libc.so.6(__libc_start_main+0xe0) [0x40013ab6e0]
    target/aarch64-unknown-linux-gnu/release/test_cc(+0x1b3034) [0x40001b3034]

Almost certain this is the same initial issue I was dealing with on arm builds. Once we have a fix for snapshot generation for cross compiled builds this should be fixed.

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha 4067deed0413c14ad43b62713bf23289770bdfd1

Removed whitespace here

view details

push time in 12 days

pull request commentdenoland/deno

[WIP]: Arm64 build process for ci

Ready for review. I will be unavailable this weekend, so I would recommend holding off merging until monday.

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha b5c0c4560d2601c9d31bdef4358ae0606e914719

Revert changes to tools.

view details

push time in 12 days

Pull request review commentdenoland/deno

[WIP]: Arm64 build process for ci

 jobs:           branch: master           repo: denoland/deno         skip-cleanup: true+    +    - name: "cargo release linux arm64"+      os: linux+      dist: xenial+      after_success:+        - gzip -c $CARGO_TARGET_DIR/aarch64-unknown-linux-gnu/release/deno > target/release/deno_${TRAVIS_OS_NAME}_arm64.gz+      script:+      - rustup target add aarch64-unknown-linux-gnu+      - sudo apt update+      - sudo apt -yq --no-install-suggests --no-install-recommends install g++-5-aarch64-linux-gnu gcc-5-aarch64-linux-gnu g++-5-multilib libc6-arm64-cross+      - build/linux/sysroot_scripts/install-sysroot.py --arch=arm64+      - export DENO_BUILD_ARGS="target_cpu=\"arm64\" v8_target_cpu=\"arm64\""+      - export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="/usr/bin/aarch64-linux-gnu-gcc-5"+      - export CC_aarch64_unknown_linux_gnu="/usr/bin/aarch64-linux-gnu-gcc-5"+      - ./tools/setup.py+      - cargo build -vv --target=aarch64-unknown-linux-gnu --release --locked -    - name: "cargo release linux"+    - name: "cargo release linux x86_64"       os: linux       script:       - cargo build -vv --release --locked-+      

No more cargo linux build?

afinch7

comment created time in 12 days

push eventafinch7/deno

afinch7

commit sha 7cd3a2f507b5a4a69cb3dfa606365dd455310dcf

qemu-user-binfmt

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 70c38b7d3769187e7774a790a1057c97cf0f998c

Fixed some other tests stuff commented out test for now. Will fix later

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 0e1a6e4913d174e98052b8821b1c97c7e4ee27ba

fmt

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha b4f0eb6c9338a3e7380bb3a7899fe1048de2a2b2

Fixed build path for cross compiled builds in build.rs and fixed some ci script stuff.

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 316eca07236b353211817a1c4039134b1b8fb6dc

Fixed error in mv command

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha 732004c93315f54a5887866c315a3d367f0eae9b

Simplified testing emulation

view details

push time in 12 days

push eventafinch7/deno

afinch7

commit sha cf7388a3d8829880061b6ef40b7fcce4e18253ea

Fixed typo

view details

push time in 12 days

more