项目作者: vigneshshanmugam

项目描述 :
JS helper function to debug elements kinds in v8
高级语言: JavaScript
项目地址: git://github.com/vigneshshanmugam/elements-kinds.git
创建时间: 2018-03-21T23:31:48Z
项目社区:https://github.com/vigneshshanmugam/elements-kinds

开源协议:MIT License

下载


elements-kinds

JS helper function to debug elements kinds in v8

More details in this blogpost by Mathias Bynes

DISCLAMIER: This module is not 100% correct, Its just a reference implementation in JavaScript.

Any JS only implementation can only guess what the elements kind is. The proper way of finding out is to get the debug build of d8 and in the REPL use the special %DebugPrint(object) function.

  1. $ out.gn/x64.debug/d8 --allow-natives-syntax
  2. d8> const array = [1, 2, 3]; %DebugPrint(array);
  3. DebugPrint: 0x1fbbad30fd71: [JSArray]
  4. - map = 0x10a6f8a038b1 [FastProperties]
  5. - prototype = 0x1212bb687ec1
  6. - elements = 0x1fbbad30fd19 <FixedArray[3]> [PACKED_SMI_ELEMENTS (COW)]
  7. - length = 3
  8. - properties = 0x219eb0702241 <FixedArray[0]> {
  9. #length: 0x219eb0764ac9 <AccessorInfo> (const accessor descriptor)
  10. }
  11. - elements= 0x1fbbad30fd19 <FixedArray[3]> {
  12. 0: 1
  13. 1: 2
  14. 2: 3
  15. }

Installation

  1. yarn add elements-kinds
  2. // npm
  3. npm install elements-kinds

Usage

  1. const getElementsKinds = require("elements-kinds");
  2. console.log(getElementsKinds(new Array(12));
  3. // HOLEY_SMI_ELEMENTS
  4. console.log(getElementsKinds([1, 2, "1", "3", 1.21]));
  5. // PACKED_ELEMENTS