Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9313090
wrap-error-constructor-with-cause.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
wrap-error-constructor-with-cause.js
View Options
'use strict'
;
var
getBuiltIn
=
require
(
'../internals/get-built-in'
);
var
hasOwn
=
require
(
'../internals/has-own-property'
);
var
createNonEnumerableProperty
=
require
(
'../internals/create-non-enumerable-property'
);
var
isPrototypeOf
=
require
(
'../internals/object-is-prototype-of'
);
var
setPrototypeOf
=
require
(
'../internals/object-set-prototype-of'
);
var
copyConstructorProperties
=
require
(
'../internals/copy-constructor-properties'
);
var
proxyAccessor
=
require
(
'../internals/proxy-accessor'
);
var
inheritIfRequired
=
require
(
'../internals/inherit-if-required'
);
var
normalizeStringArgument
=
require
(
'../internals/normalize-string-argument'
);
var
installErrorCause
=
require
(
'../internals/install-error-cause'
);
var
clearErrorStack
=
require
(
'../internals/clear-error-stack'
);
var
ERROR_STACK_INSTALLABLE
=
require
(
'../internals/error-stack-installable'
);
var
DESCRIPTORS
=
require
(
'../internals/descriptors'
);
var
IS_PURE
=
require
(
'../internals/is-pure'
);
module
.
exports
=
function
(
FULL_NAME
,
wrapper
,
FORCED
,
IS_AGGREGATE_ERROR
)
{
var
STACK_TRACE_LIMIT
=
'stackTraceLimit'
;
var
OPTIONS_POSITION
=
IS_AGGREGATE_ERROR
?
2
:
1
;
var
path
=
FULL_NAME
.
split
(
'.'
);
var
ERROR_NAME
=
path
[
path
.
length
-
1
];
var
OriginalError
=
getBuiltIn
.
apply
(
null
,
path
);
if
(
!
OriginalError
)
return
;
var
OriginalErrorPrototype
=
OriginalError
.
prototype
;
// V8 9.3- bug https://bugs.chromium.org/p/v8/issues/detail?id=12006
if
(
!
IS_PURE
&&
hasOwn
(
OriginalErrorPrototype
,
'cause'
))
delete
OriginalErrorPrototype
.
cause
;
if
(
!
FORCED
)
return
OriginalError
;
var
BaseError
=
getBuiltIn
(
'Error'
);
var
WrappedError
=
wrapper
(
function
(
a
,
b
)
{
var
message
=
normalizeStringArgument
(
IS_AGGREGATE_ERROR
?
b
:
a
,
undefined
);
var
result
=
IS_AGGREGATE_ERROR
?
new
OriginalError
(
a
)
:
new
OriginalError
();
if
(
message
!==
undefined
)
createNonEnumerableProperty
(
result
,
'message'
,
message
);
if
(
ERROR_STACK_INSTALLABLE
)
createNonEnumerableProperty
(
result
,
'stack'
,
clearErrorStack
(
result
.
stack
,
2
));
if
(
this
&&
isPrototypeOf
(
OriginalErrorPrototype
,
this
))
inheritIfRequired
(
result
,
this
,
WrappedError
);
if
(
arguments
.
length
>
OPTIONS_POSITION
)
installErrorCause
(
result
,
arguments
[
OPTIONS_POSITION
]);
return
result
;
});
WrappedError
.
prototype
=
OriginalErrorPrototype
;
if
(
ERROR_NAME
!==
'Error'
)
{
if
(
setPrototypeOf
)
setPrototypeOf
(
WrappedError
,
BaseError
);
else
copyConstructorProperties
(
WrappedError
,
BaseError
,
{
name
:
true
});
}
else
if
(
DESCRIPTORS
&&
STACK_TRACE_LIMIT
in
OriginalError
)
{
proxyAccessor
(
WrappedError
,
OriginalError
,
STACK_TRACE_LIMIT
);
proxyAccessor
(
WrappedError
,
OriginalError
,
'prepareStackTrace'
);
}
copyConstructorProperties
(
WrappedError
,
OriginalError
);
if
(
!
IS_PURE
)
try
{
// Safari 13- bug: WebAssembly errors does not have a proper `.name`
if
(
OriginalErrorPrototype
.
name
!==
ERROR_NAME
)
{
createNonEnumerableProperty
(
OriginalErrorPrototype
,
'name'
,
ERROR_NAME
);
}
OriginalErrorPrototype
.
constructor
=
WrappedError
;
}
catch
(
error
)
{
/* empty */
}
return
WrappedError
;
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 3, 11:23 AM (6 d, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3322539
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment