Skip to content

Commit

Permalink
fix(ses): Address charset error in integration
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal committed May 11, 2021
1 parent ede27df commit 20f303a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import test from 'tape-promise/tape';
import path from 'path';

const runBrowserTests = async (t, indexFile) => {
const browser = await puppeteer.launch();
const browser = await puppeteer.launch({
// debug:
// { headless: false }
});

let numTests;
let numPass;
Expand Down Expand Up @@ -62,7 +65,7 @@ const testBundler = (bundlerName, indexFile) => {
t.notEqual(numTests, undefined);
t.equal(numTests, numPass);
})
.catch(e => t.isNot(e, e, 'unexpected exception'))
.catch(e => t.fail(`Unexpected exception ${e}`))
.finally(() => t.end());
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>Test</title>
<meta charset="utf8">
</head>
<body>
<script src="../../../ses/dist/ses.umd.js"></script>
Expand Down
7 changes: 7 additions & 0 deletions packages/ses/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ User-visible changes in SES:
The constructor must perform the module analysis and transform the source,
and present this duck-type to the Compartment `importHook`.
This relieves SES of a dependency on Babel and simplifies its API.
- *BREAKING CHANGE* The UMD distribution of SES must have the UTF-8 charset.
The prior versions were accidentally ASCII, so SES would have worked
in any web page, regardless of the charset.
To remedy this, be sure to include `<head><meta charset="utf-8"></head>` in
the containing page (a general best-practice for web pages) or specifically
use `<script charset="utf-8" src="ses.umd.min.js">` to address the single
file.
- Relaxes the censorship of `import` and `eval` in programs evaluated
under SES to specifically allow the use of `something.import()` or
`something.eval()` methods.
Expand Down
7 changes: 7 additions & 0 deletions packages/ses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ npm install ses

## Usage

SES is a shim that can be run in most engines, either as an ESM module `ses` or
as a `<script>` tag.
For a script tag, the content encoding charset must be UTF-8, either by virtue
of `<head><meta charset="utf-8"></head>` (a general best practice for all HTML
files) or specifically `<script src="node_modules/ses/dist/ses.umd.min.js"
charset="utf-8">`.

### Lockdown

SES introduces the `lockdown()` function.
Expand Down
21 changes: 11 additions & 10 deletions packages/ses/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import '../index.js';
import fs from 'fs';
import { makeBundle } from '@agoric/compartment-mapper';
import prettier from 'prettier';
import terser from 'terser';

const resolve = (rel, abs) => new URL(rel, abs).toString();
Expand All @@ -18,19 +17,21 @@ const write = async (target, content) => {
read,
resolve('../index.js', import.meta.url),
);
const pretty = prettier.format(bundle);
const { code: terse } = terser.minify(bundle);
const { code: terse } = terser.minify(bundle, {
mangle: false,
keep_classnames: true,
});

console.log(`Bundle size: ${pretty.length} bytes`);
console.log(`Bundle size: ${bundle.length} bytes`);
console.log(`Minified bundle size: ${terse.length} bytes`);

await write('dist/ses.cjs', pretty);
await write('dist/ses.mjs', pretty);
await write('dist/ses.umd.js', pretty);
await write('dist/ses.cjs', bundle);
await write('dist/ses.mjs', bundle);
await write('dist/ses.umd.js', bundle);
await write('dist/ses.umd.min.js', terse);

await write('dist/lockdown.cjs', pretty);
await write('dist/lockdown.mjs', pretty);
await write('dist/lockdown.umd.js', pretty);
await write('dist/lockdown.cjs', bundle);
await write('dist/lockdown.mjs', bundle);
await write('dist/lockdown.umd.js', bundle);
await write('dist/lockdown.umd.min.js', terse);
})();

0 comments on commit 20f303a

Please sign in to comment.