Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8390867
to-primitive.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
to-primitive.js
View Options
var
global
=
require
(
'../internals/global'
);
var
call
=
require
(
'../internals/function-call'
);
var
isObject
=
require
(
'../internals/is-object'
);
var
isSymbol
=
require
(
'../internals/is-symbol'
);
var
getMethod
=
require
(
'../internals/get-method'
);
var
ordinaryToPrimitive
=
require
(
'../internals/ordinary-to-primitive'
);
var
wellKnownSymbol
=
require
(
'../internals/well-known-symbol'
);
var
TypeError
=
global
.
TypeError
;
var
TO_PRIMITIVE
=
wellKnownSymbol
(
'toPrimitive'
);
// `ToPrimitive` abstract operation
// https://tc39.es/ecma262/#sec-toprimitive
module
.
exports
=
function
(
input
,
pref
)
{
if
(
!
isObject
(
input
)
||
isSymbol
(
input
))
return
input
;
var
exoticToPrim
=
getMethod
(
input
,
TO_PRIMITIVE
);
var
result
;
if
(
exoticToPrim
)
{
if
(
pref
===
undefined
)
pref
=
'default'
;
result
=
call
(
exoticToPrim
,
input
,
pref
);
if
(
!
isObject
(
result
)
||
isSymbol
(
result
))
return
result
;
throw
TypeError
(
"Can't convert object to primitive value"
);
}
if
(
pref
===
undefined
)
pref
=
'number'
;
return
ordinaryToPrimitive
(
input
,
pref
);
};
File Metadata
Details
Attached
Mime Type
text/x-Algol68
Expires
Jun 4 2025, 6:36 PM (14 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3368494
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment