MCPcopy Create free account
hub / github.com/WiseLibs/better-sqlite3 / IsPlainObject

Method IsPlainObject

src/util/binder.cpp:51–58  ·  view source on GitHub ↗

An object is "plain" if its prototype is null or a top-level prototype (i.e., some realm's Object.prototype). Rather than comparing against the current realm's Object.prototype -- which would reject plain objects from other contexts, such as the "vm" module -- we walk to the top of the prototype chain. A plain object's chain is exactly "obj -> proto -> null", so its immediate prototype must itself

Source from the content-addressed store, hash-verified

49 // so its immediate prototype must itself have a null prototype. This mirrors
50 // the cross-realm heuristic used by lodash's isPlainObject.
51 static bool IsPlainObject(Napi::Env env, Napi::Object obj) {
52 Napi::Value proto = GetPrototype(env, obj);
53 if (proto.IsEmpty()) return false;
54 if (proto.IsNull()) return true;
55 Napi::Value grandproto = GetPrototype(env, proto.As<Napi::Object>());
56 if (grandproto.IsEmpty()) return false;
57 return grandproto.IsNull();
58 }
59
60 void Fail(Napi::Value (*Throw)(Napi::Env, const char*), Napi::Env env, const char* message) {
61 assert(success == true);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected