bare-buffer 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.c CHANGED
@@ -7,8 +7,6 @@
7
7
  #include <string.h>
8
8
  #include <utf.h>
9
9
 
10
- static js_type_tag_t bare_buffer__tag = {0xfea3e944b70b0812, 0xe53bb5c343c040b6};
11
-
12
10
  static inline int
13
11
  bare_buffer__memcmp(void *a, size_t a_len, void *b, size_t b_len) {
14
12
  int r = memcmp(a, b, a_len < b_len ? a_len : b_len);
@@ -663,47 +661,6 @@ bare_buffer_compare(js_env_t *env, js_callback_info_t *info) {
663
661
  return result;
664
662
  }
665
663
 
666
- static js_value_t *
667
- bare_buffer_tag(js_env_t *env, js_callback_info_t *info) {
668
- int err;
669
-
670
- size_t argc = 1;
671
- js_value_t *argv[1];
672
-
673
- err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
674
- assert(err == 0);
675
-
676
- assert(argc == 1);
677
-
678
- err = js_add_type_tag(env, argv[0], &bare_buffer__tag);
679
- assert(err == 0);
680
-
681
- return NULL;
682
- }
683
-
684
- static js_value_t *
685
- bare_buffer_is_tagged(js_env_t *env, js_callback_info_t *info) {
686
- int err;
687
-
688
- size_t argc = 1;
689
- js_value_t *argv[1];
690
-
691
- err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
692
- assert(err == 0);
693
-
694
- assert(argc == 1);
695
-
696
- bool is_tagged;
697
- err = js_check_type_tag(env, argv[0], &bare_buffer__tag, &is_tagged);
698
- assert(err == 0);
699
-
700
- js_value_t *result;
701
- err = js_get_boolean(env, is_tagged, &result);
702
- assert(err == 0);
703
-
704
- return result;
705
- }
706
-
707
664
  static js_value_t *
708
665
  bare_buffer_exports(js_env_t *env, js_value_t *exports) {
709
666
  int err;
@@ -850,10 +807,6 @@ bare_buffer_exports(js_env_t *env, js_value_t *exports) {
850
807
  }),
851
808
  bare_buffer_typed_compare
852
809
  );
853
-
854
- V("tag", bare_buffer_tag, NULL, NULL);
855
-
856
- V("isTagged", bare_buffer_is_tagged, NULL, NULL);
857
810
  #undef V
858
811
 
859
812
  return exports;
package/index.js CHANGED
@@ -7,11 +7,13 @@ const utf16le = require('./lib/utf16le')
7
7
  const latin1 = require('./lib/latin1')
8
8
  const binding = require('./binding')
9
9
 
10
+ const kind = Symbol.for('bare.buffer.kind')
11
+
10
12
  let poolSize = 0
11
13
 
12
14
  module.exports = exports = class Buffer extends Uint8Array {
13
- static {
14
- binding.tag(this)
15
+ static get [kind]() {
16
+ return 0 // Compatibility version
15
17
  }
16
18
 
17
19
  static get poolSize() {
@@ -60,8 +62,8 @@ module.exports = exports = class Buffer extends Uint8Array {
60
62
  super(arrayBuffer, offset, length)
61
63
  }
62
64
 
63
- [Symbol.species]() {
64
- return Buffer
65
+ get [kind]() {
66
+ return Buffer[kind]
65
67
  }
66
68
 
67
69
  copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
@@ -562,17 +564,10 @@ function viewOf(buffer) {
562
564
 
563
565
  exports.isBuffer = function isBuffer(value) {
564
566
  if (value instanceof Buffer) return true
565
- if (typeof value !== 'object' || value === null) return false
566
-
567
- let constructor = value.constructor
568
-
569
- while (typeof constructor === 'function') {
570
- if (binding.isTagged(constructor)) return true
571
567
 
572
- constructor = Reflect.getPrototypeOf(constructor)
573
- }
574
-
575
- return false
568
+ return (
569
+ typeof value === 'object' && value !== null && value[kind] === Buffer[kind]
570
+ )
576
571
  }
577
572
 
578
573
  exports.isEncoding = function isEncoding(encoding) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-buffer",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Native buffers for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",