File tree Expand file tree Collapse file tree 5 files changed +33
-5
lines changed Expand file tree Collapse file tree 5 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,19 @@ inline bool Value::IsPromise() const {
347
347
return result;
348
348
}
349
349
350
+ #if NAPI_DATA_VIEW_FEATURE
351
+ inline bool Value::IsDataView () const {
352
+ if (_value == nullptr ) {
353
+ return false ;
354
+ }
355
+
356
+ bool result;
357
+ napi_status status = napi_is_dataview (_env, _value, &result);
358
+ NAPI_THROW_IF_FAILED (_env, status, false );
359
+ return result;
360
+ }
361
+ #endif
362
+
350
363
inline bool Value::IsBuffer () const {
351
364
if (_value == nullptr ) {
352
365
return false ;
Original file line number Diff line number Diff line change @@ -177,6 +177,9 @@ namespace Napi {
177
177
bool IsObject () const ; // /< Tests if a value is a JavaScript object.
178
178
bool IsFunction () const ; // /< Tests if a value is a JavaScript function.
179
179
bool IsPromise () const ; // /< Tests if a value is a JavaScript promise.
180
+ #if NAPI_DATA_VIEW_FEATURE
181
+ bool IsDataView () const ; // /< Tests if a value is a JavaScript data view.
182
+ #endif
180
183
bool IsBuffer () const ; // /< Tests if a value is a Node buffer.
181
184
182
185
// / Casts to another type of `Napi::Value`, when the actual type is known or assumed.
Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ static Value IsPromise(const CallbackInfo& info) {
55
55
return Boolean::New (info.Env (), info[0 ].IsPromise ());
56
56
}
57
57
58
+ static Value IsDataView (const CallbackInfo& info) {
59
+ return Boolean::New (info.Env (), info[0 ].IsDataView ());
60
+ }
61
+
58
62
static Value ToBoolean (const CallbackInfo& info) {
59
63
return info[0 ].ToBoolean ();
60
64
}
@@ -87,6 +91,7 @@ Object InitBasicTypesValue(Env env) {
87
91
exports[" isObject" ] = Function::New (env, IsObject);
88
92
exports[" isFunction" ] = Function::New (env, IsFunction);
89
93
exports[" isPromise" ] = Function::New (env, IsPromise);
94
+ exports[" isDataView" ] = Function::New (env, IsDataView);
90
95
exports[" toBoolean" ] = Function::New (env, ToBoolean);
91
96
exports[" toNumber" ] = Function::New (env, ToNumber);
92
97
exports[" toString" ] = Function::New (env, ToString);
Original file line number Diff line number Diff line change @@ -24,8 +24,13 @@ function test(binding) {
24
24
if ( value instanceof ArrayBuffer )
25
25
return 'arraybuffer' ;
26
26
27
- if ( ArrayBuffer . isView ( value ) )
28
- return 'typedarray' ;
27
+ if ( ArrayBuffer . isView ( value ) ) {
28
+ if ( value instanceof DataView ) {
29
+ return 'dataview' ;
30
+ } else {
31
+ return 'typedarray' ;
32
+ }
33
+ }
29
34
30
35
if ( value instanceof Promise )
31
36
return 'promise' ;
@@ -46,7 +51,8 @@ function test(binding) {
46
51
new Int32Array ( new ArrayBuffer ( 12 ) ) ,
47
52
{ } ,
48
53
function ( ) { } ,
49
- new Promise ( ( resolve , reject ) => { } )
54
+ new Promise ( ( resolve , reject ) => { } ) ,
55
+ new DataView ( new ArrayBuffer ( 12 ) )
50
56
] ;
51
57
52
58
testValueList . forEach ( ( testValue ) => {
@@ -99,6 +105,7 @@ function test(binding) {
99
105
typeCheckerTest ( value . isObject , 'object' ) ;
100
106
typeCheckerTest ( value . isFunction , 'function' ) ;
101
107
typeCheckerTest ( value . isPromise , 'promise' ) ;
108
+ typeCheckerTest ( value . isDataView , 'dataview' ) ;
102
109
103
110
typeConverterTest ( value . toBoolean , Boolean ) ;
104
111
assert . strictEqual ( value . toBoolean ( undefined ) , false ) ;
Original file line number Diff line number Diff line change 27
27
'targets' : [
28
28
{
29
29
'target_name' : 'binding' ,
30
- 'defines' : [ 'NAPI_CPP_EXCEPTIONS' ],
30
+ 'defines' : [ 'NAPI_CPP_EXCEPTIONS' , 'NAPI_DATA_VIEW_FEATURE' ],
31
31
'cflags!' : [ '-fno-exceptions' ],
32
32
'cflags_cc!' : [ '-fno-exceptions' ],
33
33
'msvs_settings' : {
41
41
},
42
42
{
43
43
'target_name' : 'binding_noexcept' ,
44
- 'defines' : [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
44
+ 'defines' : [ 'NAPI_DISABLE_CPP_EXCEPTIONS' , 'NAPI_DATA_VIEW_FEATURE' ],
45
45
'cflags' : [ '-fno-exceptions' ],
46
46
'cflags_cc' : [ '-fno-exceptions' ],
47
47
'msvs_settings' : {
You can’t perform that action at this time.
0 commit comments