Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Deno/Deno.core not deletable/writable #2153

Merged
merged 2 commits into from
Apr 20, 2019

Conversation

kevinkassimo
Copy link
Contributor

before:

> Deno = 1
1
panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', ../../core/isolate.rs:468:7
Abort trap: 6

> delete window.Deno
true
panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', ../../core/isolate.rs:468:7
Abort trap: 6

> Deno.core.send = 1
1
panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', ../../core/isolate.rs:468:7
Abort trap: 6

> delete Deno.core.send
true
panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', ../../core/isolate.rs:468:7
Abort trap: 6

after:

> Deno = 1
1
> delete window.Deno
false
> Deno.core.send = 1
1
> delete Deno.core.send
false
> Deno
{ args, noColor, pid, env, exit, isTTY, execPath, chdir, cwd, File, open, openSync, stdin, stdout, stderr, read, readSync, write, writeSync, seek, seekSync, close, copy, toAsyncIterator, SeekMode, Buffer, readAll, readAllSync, mkdirSync, mkdir, makeTempDirSync, makeTempDir, chmodSync, chmod, removeSync, remove, renameSync, rename, readFileSync, readFile, readDirSync, readDir, copyFileSync, copyFile, readlinkSync, readlink, statSync, lstatSync, stat, lstat, linkSync, link, symlinkSync, symlink, writeFileSync, writeFile, ErrorKind, DenoError, permissions, revokePermission, truncateSync, truncate, connect, dial, listen, metrics, resources, run, Process, inspect, build, platform, version, core, Console, stringifyArgs, DomIterableMixin }
> Deno.core.send
[Function]
>

js/main.ts Outdated
@@ -19,6 +20,10 @@ import * as deno from "./deno";
import libDts from "gen/cli/lib/lib.deno_runtime.d.ts!string";

export default function denoMain(name?: string): void {
// Deno.core could ONLY be safely frozen here (not in globals.ts)
// since shared_queue.js will modify core properties.
Object.freeze(window.Deno.core);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe os.start() is a better place for this? I think this won't get called for workers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually denoMain() is still called in user-created workers:

deno/cli/ops.rs

Lines 1878 to 1881 in 0796a8f

let mut worker =
Worker::new(name, startup_data::deno_isolate_init(), child_state);
js_check(worker.execute("denoMain()"));
js_check(worker.execute("workerMain()"));

but yeah putting it in os.start() sound better since we also call core.setAsyncHandler(handleAsyncMsgFromRust); for core-related initialization.

delete Deno.core.print;
} catch {}
// @ts-ignore
assert(print === Deno.core.print);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry ry merged commit c8db224 into denoland:master Apr 20, 2019
@cybor0
Copy link

cybor0 commented Apr 20, 2019

Hi shuldn't this freeze be deeply
What with Deno.ErrorKind.IdnaError = "blabla" Deno.platform.arch="blabla"

@kevinkassimo
Copy link
Contributor Author

@cybor0 The major purposes of this PR is to avoid user messing up with the message passing mechanism of deno. We should probably also freeze these values, but it could be a separate PR and would be great if you want to work on this.

@cybor0
Copy link

cybor0 commented Apr 22, 2019

@kevinkassimo I understand your point of view. Maybe later in the future i will help.

@kevinkassimo kevinkassimo deleted the namespace/immutable branch December 27, 2019 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants