| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent afbaf92 commit 6390f70
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -525,4 +525,16 @@ export default [ | |||
| 525 | 525 | ], | |
| 526 | 526 | }, | |
| 527 | 527 | }, | |
| 528 | + { | ||
| 529 | + files: [ | ||
| 530 | + 'lib/internal/per_context/domexception.js', | ||
| 531 | + ], | ||
| 532 | + languageOptions: { | ||
| 533 | + globals: { | ||
| 534 | + // Parameters passed to internal modules. | ||
| 535 | + privateSymbols: 'readonly', | ||
| 536 | + perIsolateSymbols: 'readonly', | ||
| 537 | + }, | ||
| 538 | + }, | ||
| 539 | + }, | ||
| 528 | 540 | ]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,18 @@ const { | |||
| 12 | 12 | SymbolToStringTag, | |
| 13 | 13 | TypeError, | |
| 14 | 14 | } = primordials; | |
| 15 | + const { | ||
| 16 | + transfer_mode_private_symbol, | ||
| 17 | + } = privateSymbols; | ||
| 18 | + const { | ||
| 19 | + messaging_clone_symbol, | ||
| 20 | + messaging_deserialize_symbol, | ||
| 21 | + } = perIsolateSymbols; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * Maps to BaseObject::TransferMode::kCloneable | ||
| 25 | + */ | ||
| 26 | + const kCloneable = 2; | ||
| 15 | 27 | ||
| 16 | 28 | function throwInvalidThisError(Base, type) { | |
| 17 | 29 | const err = new Base(); | |
@@ -50,6 +62,7 @@ const disusedNamesSet = new SafeSet() | |||
| 50 | 62 | ||
| 51 | 63 | class DOMException { | |
| 52 | 64 | constructor(message = '', options = 'Error') { | |
| 65 | + this[transfer_mode_private_symbol] = kCloneable; | ||
| 53 | 66 | ErrorCaptureStackTrace(this); | |
| 54 | 67 | ||
| 55 | 68 | if (options && typeof options === 'object') { | |
@@ -76,6 +89,28 @@ class DOMException { | |||
| 76 | 89 | } | |
| 77 | 90 | } | |
| 78 | 91 | ||
| 92 | + [messaging_clone_symbol]() { | ||
| 93 | + // See serialization steps in https://webidl.spec.whatwg.org/#dom-domexception-domexception | ||
| 94 | + const internals = internalsMap.get(this); | ||
| 95 | + return { | ||
| 96 | + data: { | ||
| 97 | + message: internals.message, | ||
| 98 | + name: internals.name, | ||
| 99 | + stack: this.stack, | ||
| 100 | + }, | ||
| 101 | + deserializeInfo: 'internal/worker/clone_dom_exception:DOMException', | ||
| 102 | + }; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + [messaging_deserialize_symbol](data) { | ||
| 106 | + // See deserialization steps in https://webidl.spec.whatwg.org/#dom-domexception-domexception | ||
| 107 | + internalsMap.set(this, { | ||
| 108 | + message: data.message, | ||
| 109 | + name: data.name, | ||
| 110 | + }); | ||
| 111 | + this.stack = data.stack; | ||
| 112 | + } | ||
| 113 | + | ||
| 79 | 114 | get name() { | |
| 80 | 115 | const internals = internalsMap.get(this); | |
| 81 | 116 | if (internals === undefined) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Delegate to the actual DOMException implementation. | ||
| 4 | + module.exports = { | ||
| 5 | + DOMException: internalBinding('messaging').DOMException, | ||
| 6 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -787,13 +787,13 @@ MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context, | |||
| 787 | 787 | Context::Scope context_scope(context); | |
| 788 | 788 | ||
| 789 | 789 | Local<ObjectTemplate> private_symbols = ObjectTemplate::New(isolate); | |
| 790 | - Local<Object> private_symbols_object; | ||
| 791 | 790 | #define V(PropertyName, _) \ | |
| 792 | 791 | private_symbols->Set(isolate, #PropertyName, isolate_data->PropertyName()); | |
| 793 | 792 | ||
| 794 | 793 | PER_ISOLATE_PRIVATE_SYMBOL_PROPERTIES(V) | |
| 795 | 794 | #undef V | |
| 796 | 795 | ||
| 796 | + Local<Object> private_symbols_object; | ||
| 797 | 797 | if (!private_symbols->NewInstance(context).ToLocal(&private_symbols_object) || | |
| 798 | 798 | private_symbols_object->SetPrototypeV2(context, Null(isolate)) | |
| 799 | 799 | .IsNothing()) { | |
@@ -803,6 +803,32 @@ MaybeLocal<Object> InitializePrivateSymbols(Local<Context> context, | |||
| 803 | 803 | return scope.Escape(private_symbols_object); | |
| 804 | 804 | } | |
| 805 | 805 | ||
| 806 | + MaybeLocal<Object> InitializePerIsolateSymbols(Local<Context> context, | ||
| 807 | + IsolateData* isolate_data) { | ||
| 808 | + CHECK(isolate_data); | ||
| 809 | + Isolate* isolate = context->GetIsolate(); | ||
| 810 | + EscapableHandleScope scope(isolate); | ||
| 811 | + Context::Scope context_scope(context); | ||
| 812 | + | ||
| 813 | + Local<ObjectTemplate> per_isolate_symbols = ObjectTemplate::New(isolate); | ||
| 814 | + #define V(PropertyName, _) \ | ||
| 815 | + per_isolate_symbols->Set( \ | ||
| 816 | + isolate, #PropertyName, isolate_data->PropertyName()); | ||
| 817 | + | ||
| 818 | + PER_ISOLATE_SYMBOL_PROPERTIES(V) | ||
| 819 | + #undef V | ||
| 820 | + | ||
| 821 | + Local<Object> per_isolate_symbols_object; | ||
| 822 | + if (!per_isolate_symbols->NewInstance(context).ToLocal( | ||
| 823 | + &per_isolate_symbols_object) || | ||
| 824 | + per_isolate_symbols_object->SetPrototypeV2(context, Null(isolate)) | ||
| 825 | + .IsNothing()) { | ||
| 826 | + return MaybeLocal<Object>(); | ||
| 827 | + } | ||
| 828 | + | ||
| 829 | + return scope.Escape(per_isolate_symbols_object); | ||
| 830 | + } | ||
| 831 | + | ||
| 806 | 832 | Maybe<void> InitializePrimordials(Local<Context> context, | |
| 807 | 833 | IsolateData* isolate_data) { | |
| 808 | 834 | // Run per-context JS files. | |
@@ -832,6 +858,12 @@ Maybe<void> InitializePrimordials(Local<Context> context, | |||
| 832 | 858 | return Nothing<void>(); | |
| 833 | 859 | } | |
| 834 | 860 | ||
| 861 | + Local<Object> per_isolate_symbols; | ||
| 862 | + if (!InitializePerIsolateSymbols(context, isolate_data) | ||
| 863 | + .ToLocal(&per_isolate_symbols)) { | ||
| 864 | + return Nothing<void>(); | ||
| 865 | + } | ||
| 866 | + | ||
| 835 | 867 | static const char* context_files[] = {"internal/per_context/primordials", | |
| 836 | 868 | "internal/per_context/domexception", | |
| 837 | 869 | "internal/per_context/messageport", | |
@@ -847,7 +879,8 @@ Maybe<void> InitializePrimordials(Local<Context> context, | |||
| 847 | 879 | builtin_loader.SetEagerCompile(); | |
| 848 | 880 | ||
| 849 | 881 | for (const char** module = context_files; *module != nullptr; module++) { | |
| 850 | - Local<Value> arguments[] = {exports, primordials, private_symbols}; | ||
| 882 | + Local<Value> arguments[] = { | ||
| 883 | + exports, primordials, private_symbols, per_isolate_symbols}; | ||
| 851 | 884 | ||
| 852 | 885 | if (builtin_loader | |
| 853 | 886 | .CompileAndCall( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -415,6 +415,7 @@ MaybeLocal<Function> BuiltinLoader::LookupAndCompile(Local<Context> context, | |||
| 415 | 415 | FIXED_ONE_BYTE_STRING(isolate, "exports"), | |
| 416 | 416 | FIXED_ONE_BYTE_STRING(isolate, "primordials"), | |
| 417 | 417 | FIXED_ONE_BYTE_STRING(isolate, "privateSymbols"), | |
| 418 | + FIXED_ONE_BYTE_STRING(isolate, "perIsolateSymbols"), | ||
| 418 | 419 | }; | |
| 419 | 420 | } else if (strncmp(id, "internal/main/", strlen("internal/main/")) == 0 || | |
| 420 | 421 | strncmp(id, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,48 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + function assertDOMException(actual, expected) { | ||
| 7 | + assert.strictEqual(actual instanceof DOMException, true); | ||
| 8 | + assert.strictEqual(actual.message, expected.message); | ||
| 9 | + assert.strictEqual(actual.name, expected.name); | ||
| 10 | + assert.strictEqual(actual.code, expected.code); | ||
| 11 | + assert.strictEqual(actual.stack, expected.stack); | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + { | ||
| 15 | + // Clone basic DOMException | ||
| 16 | + const e = new DOMException('test'); | ||
| 17 | + const clone = structuredClone(e); | ||
| 18 | + const clone2 = structuredClone(clone); | ||
| 19 | + assertDOMException(clone, e); | ||
| 20 | + assertDOMException(clone2, e); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + { | ||
| 24 | + // Clone a DOMException with a name | ||
| 25 | + const e = new DOMException('test', 'DataCloneError'); | ||
| 26 | + const clone = structuredClone(e); | ||
| 27 | + const clone2 = structuredClone(clone); | ||
| 28 | + assertDOMException(clone, e); | ||
| 29 | + assertDOMException(clone2, e); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + { | ||
| 33 | + // Clone an arbitrary object with a DOMException prototype | ||
| 34 | + const obj = {}; | ||
| 35 | + Object.setPrototypeOf(obj, DOMException.prototype); | ||
| 36 | + const clone = structuredClone(obj); | ||
| 37 | + assert.strictEqual(clone instanceof DOMException, false); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + { | ||
| 41 | + // Transfer a DOMException. DOMExceptions are not transferable. | ||
| 42 | + const e = new DOMException('test'); | ||
| 43 | + assert.throws(() => { | ||
| 44 | + structuredClone(e, { transfer: [e] }); | ||
| 45 | + }, { | ||
| 46 | + name: 'DataCloneError', | ||
| 47 | + }); | ||
| 48 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments