Skip to content

Nhahan/function-location

Repository files navigation

function-location

locateV8() returns the absolute source file path for a function or class at runtime.

npm CI

Install

npm install function-location

Supports Node.js 16+.

Usage

import { locateV8 } from 'function-location';

class ExampleClass {}
function exampleFunction() {}

locateV8(ExampleClass);     // /path/to/file.ts
locateV8(exampleFunction);  // /path/to/file.ts

API

  • locateV8(input: Function): string | undefined
  • Throws Function argument expected when input is not a function/class constructor.
  • Returns undefined for anonymous/native/builtins where metadata is unavailable.

Performance sample

This library uses a synchronous native addon lookup instead of the inspector protocol.

Sample comparison against an inspector-protocol baseline:

Approach Median time / call Relative speed
locate 0.1197 µs 1878.60x faster
inspector protocol 224.8900 µs baseline

Locating performance (example run)

Results vary by environment; treat them as sample measurements only. Methodology and raw samples: docs/BENCHMARK.md

Links

About

Retrieve `[[FunctionLocation]]` from V8 engine.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors