tame Error as a shim
that was the last non-shim taming function, so remove tame.js
MODIFY
src/bundle/createSES.js
src/bundle/createSES.js
import tameDate from './tame-date.js';
import tameMath from './tame-math.js';
import tameIntl from './tame-intl.js';
+import tameError from './tame-error.js';
export function createSESWithRealmConstructor(creatorStrings, Realm) {
function makeSESRootRealm(options) {
@@ -36,11 +37,14 @@ export function createSESWithRealmConstructor(creatorStrings, Realm) {
shims.push(`(${tameIntl})();`);
}
+ if (options.errorStackMode !== "allow") {
+ shims.push(`(${tameError})();`);
+ }
+
const r = Realm.makeRootRealm({shims: shims});
const b = r.evaluate(creatorStrings);
b.createSESInThisRealm(r.global, creatorStrings, r);
//b.removeProperties(r.global);
- b.tamePrimordials(r.global, options);
r.global.def = b.def;
r.global.Nat = b.Nat;

MODIFY
src/bundle/index.js
src/bundle/index.js
import { createSESWithRealmConstructor, createSESInThisRealm } from './createSES.js';
import { deepFreezePrimordials } from './deepFreeze.js';
import { removeProperties } from './removeProperties.js';
-import { tamePrimordials } from './tame.js';
import { getAnonIntrinsics } from './anonIntrinsics.js';
import { def } from './def.js';
import { Nat } from './nat.js';
export { createSESWithRealmConstructor, createSESInThisRealm,
- deepFreezePrimordials, removeProperties, tamePrimordials, getAnonIntrinsics,
+ deepFreezePrimordials, removeProperties, getAnonIntrinsics,
def, Nat
};

ADD
src/bundle/tame-error.js
+
+export default function tameError() {
+ if (!(Object.isExtensible(Error))) {
+ throw Error('huh Error is not extensible');
+ }
+ /* this worked back when we were running it on a global, but stopped
+ working when we turned it into a shim */
+ /*
+ Object.defineProperty(Error.prototype, "stack",
+ { get() { return 'stack suppressed'; } });
+ */
+ delete Error.captureStackTrace;
+ if ('captureStackTrace' in Error) {
+ throw Error('hey we could not remove Error.captureStackTrace');
+ }
+}

DELETE
src/bundle/tame.js
-// Copyright (C) 2018 Agoric
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-function tameError(global) {
- Object.defineProperty(global.Error.prototype, "stack",
- { get() { return 'stack suppressed'; } });
-}
-
-export function tamePrimordials(global, options) {
- tameError(global);
-}

ADD
test/test-error.js
+import test from 'tape';
+import SES from '../src/index.js';
+
+test('Error.captureStackTrace neutered by default', function(t) {
+ const s = SES.makeSESRootRealm();
+ t.equal(s.evaluate('Error.captureStackTrace'), undefined);
+ t.end();
+});
+
+test('Error.captureStackTrace neutered upon request', function(t) {
+ const s = SES.makeSESRootRealm({errorStackMode: false});
+ t.equal(s.evaluate('Error.captureStackTrace'), undefined);
+ t.end();
+});
+
+// Error.captureStackTrace is a v8 extension, and other engines may or may
+// not provide it
+
+test('Error.captureStackTrace can be left alone', function(t) {
+ const rootHasCaptureStackTrace = 'captureStackTrace' in Error;
+ const s = SES.makeSESRootRealm({errorStackMode: "allow"});
+ const realmHasCaptureStackTrace = s.evaluate('"captureStackTrace" in Error');
+ t.equal(rootHasCaptureStackTrace, realmHasCaptureStackTrace);
+ t.end();
+});

tame Error as a shim

that was the last non-shim taming function, so remove tame.js