2022-05-24 07:51:09 +00:00
|
|
|
// Copyright 2022 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2022-08-06 07:56:26 +00:00
|
|
|
// Flags: --experimental-d8-web-snapshot-api --allow-natives-syntax --verify-heap
|
2022-05-24 07:51:09 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
|
|
|
|
|
|
|
|
(function TestBuiltin() {
|
|
|
|
function createObjects() {
|
|
|
|
globalThis.obj1 = {'a': Error};
|
|
|
|
globalThis.obj2 = {'b': Error.prototype};
|
|
|
|
}
|
|
|
|
const realm = Realm.create();
|
|
|
|
const {obj1, obj2} = takeAndUseWebSnapshot(
|
|
|
|
createObjects, ['obj1', 'obj2'], realm);
|
2022-09-07 11:13:42 +00:00
|
|
|
assertSame(Realm.eval(realm, 'Error'), obj1.a);
|
|
|
|
assertSame(Realm.eval(realm, 'Error.prototype'), obj2.b);
|
2022-05-24 07:51:09 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestInheritFromBuiltin() {
|
|
|
|
function createObjects() {
|
|
|
|
function inherit(subclass, superclass) {
|
|
|
|
function middle() {}
|
|
|
|
middle.prototype = superclass.prototype;
|
|
|
|
subclass.prototype = new middle();
|
|
|
|
subclass.prototype.constructor = subclass;
|
|
|
|
};
|
|
|
|
function MyError() {}
|
|
|
|
inherit(MyError, Error);
|
|
|
|
globalThis.MyError = MyError;
|
|
|
|
}
|
|
|
|
const realm = Realm.create();
|
|
|
|
const {MyError} = takeAndUseWebSnapshot(createObjects, ['MyError'], realm);
|
|
|
|
const obj = new MyError();
|
2022-09-07 11:13:42 +00:00
|
|
|
assertSame(Realm.eval(realm, 'Error.prototype'), obj.__proto__.__proto__);
|
2022-05-24 07:51:09 +00:00
|
|
|
})();
|