File tree 3 files changed +45
-4
lines changed
3 files changed +45
-4
lines changed Original file line number Diff line number Diff line change @@ -1049,10 +1049,31 @@ by `new Boolean()`.
1049
1049
``` js
1050
1050
util .types .isBooleanObject (false ); // Returns false
1051
1051
util .types .isBooleanObject (true ); // Returns false
1052
- util .types .isBooleanObject (new Boolean (false )); // Returns true
1053
- util .types .isBooleanObject (new Boolean (true )); // Returns true
1052
+ util .types .isBooleanObject (new Boolean (false )); // Returns true
1053
+ util .types .isBooleanObject (new Boolean (true )); // Returns true
1054
1054
util .types .isBooleanObject (Boolean (false )); // Returns false
1055
- util .types .isBooleanObject (Boolean (true )); // Returns false
1055
+ util .types .isBooleanObject (Boolean (true )); // Returns false
1056
+ ```
1057
+
1058
+ ### util.types.isBoxedPrimitive(value)
1059
+ <!-- YAML
1060
+ added: REPLACEME
1061
+ -->
1062
+
1063
+ * ` value ` {any}
1064
+ * Returns: {boolean}
1065
+
1066
+ Returns ` true ` if the value is any boxed primitive object, e.g. created
1067
+ by ` new Boolean() ` , ` new String() ` or ` Object(Symbol()) ` .
1068
+
1069
+ For example:
1070
+
1071
+ ``` js
1072
+ util .types .isBoxedPrimitive (false ); // Returns false
1073
+ util .types .isBoxedPrimitive (new Boolean (false )); // Returns true
1074
+ util .types .isBoxedPrimitive (Symbol (' foo' )); // Returns false
1075
+ util .types .isBoxedPrimitive (Object (Symbol (' foo' ))); // Returns true
1076
+ util .types .isBoxedPrimitive (Object (BigInt (5 ))); // Returns true
1056
1077
```
1057
1078
1058
1079
### util.types.isDataView(value)
Original file line number Diff line number Diff line change @@ -51,6 +51,15 @@ static void IsAnyArrayBuffer(const FunctionCallbackInfo<Value>& args) {
51
51
args[0 ]->IsArrayBuffer () || args[0 ]->IsSharedArrayBuffer ());
52
52
}
53
53
54
+ static void IsBoxedPrimitive (const FunctionCallbackInfo<Value>& args) {
55
+ args.GetReturnValue ().Set (
56
+ args[0 ]->IsNumberObject () ||
57
+ args[0 ]->IsStringObject () ||
58
+ args[0 ]->IsBooleanObject () ||
59
+ args[0 ]->IsBigIntObject () ||
60
+ args[0 ]->IsSymbolObject ());
61
+ }
62
+
54
63
void InitializeTypes (Local<Object> target,
55
64
Local<Value> unused,
56
65
Local<Context> context) {
@@ -63,6 +72,7 @@ void InitializeTypes(Local<Object> target,
63
72
#undef V
64
73
65
74
env->SetMethodNoSideEffect (target, " isAnyArrayBuffer" , IsAnyArrayBuffer);
75
+ env->SetMethodNoSideEffect (target, " isBoxedPrimitive" , IsBoxedPrimitive);
66
76
}
67
77
68
78
} // anonymous namespace
Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ for (const [ value, _method ] of [
57
57
58
58
for ( const key of Object . keys ( types ) ) {
59
59
if ( ( types . isArrayBufferView ( value ) ||
60
- types . isAnyArrayBuffer ( value ) ) && key . includes ( 'Array' ) ) {
60
+ types . isAnyArrayBuffer ( value ) ) && key . includes ( 'Array' ) ||
61
+ key === 'isBoxedPrimitive' ) {
61
62
continue ;
62
63
}
63
64
@@ -68,6 +69,15 @@ for (const [ value, _method ] of [
68
69
}
69
70
}
70
71
72
+ // Check boxed primitives.
73
+ [
74
+ new Boolean ( ) ,
75
+ new Number ( ) ,
76
+ new String ( ) ,
77
+ Object ( Symbol ( ) ) ,
78
+ Object ( BigInt ( 0 ) )
79
+ ] . forEach ( ( entry ) => assert ( types . isBoxedPrimitive ( entry ) ) ) ;
80
+
71
81
{
72
82
assert ( ! types . isUint8Array ( { [ Symbol . toStringTag ] : 'Uint8Array' } ) ) ;
73
83
assert ( types . isUint8Array ( vm . runInNewContext ( 'new Uint8Array' ) ) ) ;
You can’t perform that action at this time.
0 commit comments