Skip to content

Commit

Permalink
llv8: support JSApiObject/JSSpecialApiObject
Browse files Browse the repository at this point in the history
PR-URL: nodejs#51
Reviewed-By: Howard Hellyer <hhellyer@uk.ibm.com>
  • Loading branch information
indutny committed Nov 21, 2016
1 parent 6cb550f commit ad45a96
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ before_install:
node_js:
- "4"
- "5"
- "6"
- "7"
branches:
only:
- master
Expand Down
5 changes: 2 additions & 3 deletions src/llscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ bool FindReferencesCmd::DoExecute(SBDebugger d, char** cmd,
// We only need to handle the types that are in
// FindJSObjectsVisitor::IsAHistogramType
// as those are the only objects that end up in GetMapsToInstances
if (type == v8->types()->kJSObjectType ||
type == v8->types()->kJSArrayType) {
if (v8::JSObject::IsObjectType(v8, type)) {
// Objects can have elements and arrays can have named properties.
// Basically we need to access objects and arrays as both objects and
// arrays.
Expand Down Expand Up @@ -830,7 +829,7 @@ bool FindJSObjectsVisitor::IsAHistogramType(v8::Map& map, v8::Error& err) {
if (err.Fail()) return false;

v8::LLV8* v8 = map.v8();
if (type == v8->types()->kJSObjectType) return true;
if (v8::JSObject::IsObjectType(v8, type)) return true;
if (type == v8->types()->kJSArrayType) return true;
if (type == v8->types()->kJSTypedArrayType) return true;
if (type < v8->types()->kFirstNonstringType) return true;
Expand Down
34 changes: 31 additions & 3 deletions src/llv8-constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,34 @@ void Common::Load() {
kPointerSize = 1 << LoadConstant("PointerSizeLog2");
kVersionMajor = LoadRawConstant("v8::internal::Version::major_");
kVersionMinor = LoadRawConstant("v8::internal::Version::minor_");
kVersionPatch = LoadRawConstant("v8::internal::Version::patch_");
}


bool Common::CheckVersion(int64_t major, int64_t minor) {
bool Common::CheckHighestVersion(int64_t major, int64_t minor, int64_t patch) {
Load();

if (major > kVersionMajor) return false;
if (minor > kVersionMinor) return false;
if (kVersionMajor < major) return true;
if (kVersionMajor > major) return false;

if (kVersionMinor < minor) return true;
if (kVersionMinor > minor) return false;

if (kVersionPatch > patch) return false;
return true;
}


bool Common::CheckLowestVersion(int64_t major, int64_t minor, int64_t patch) {
Load();

if (kVersionMajor > major) return true;
if (kVersionMajor < major) return false;

if (kVersionMinor > minor) return true;
if (kVersionMinor < minor) return false;

if (kVersionPatch < patch) return false;
return true;
}

Expand Down Expand Up @@ -472,6 +491,8 @@ void Types::Load() {
LoadConstant("type_JSGlobalObject__JS_GLOBAL_OBJECT_TYPE");
kOddballType = LoadConstant("type_Oddball__ODDBALL_TYPE");
kJSObjectType = LoadConstant("type_JSObject__JS_OBJECT_TYPE");
kJSAPIObjectType = LoadConstant("APIObjectType");
kJSSpecialAPIObjectType = LoadConstant("APISpecialObjectType");
kJSArrayType = LoadConstant("type_JSArray__JS_ARRAY_TYPE");
kCodeType = LoadConstant("type_Code__CODE_TYPE");
kJSFunctionType = LoadConstant("type_JSFunction__JS_FUNCTION_TYPE");
Expand All @@ -483,6 +504,13 @@ void Types::Load() {
kSharedFunctionInfoType =
LoadConstant("type_SharedFunctionInfo__SHARED_FUNCTION_INFO_TYPE");
kScriptType = LoadConstant("type_Script__SCRIPT_TYPE");

if (kJSAPIObjectType == -1) {
common_->Load();

if (common_->CheckLowestVersion(5, 2, 12))
kJSAPIObjectType = kJSObjectType - 1;
}
}

} // namespace constants
Expand Down
6 changes: 5 additions & 1 deletion src/llv8-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class Common : public Module {
int64_t kPointerSize;
int64_t kVersionMajor;
int64_t kVersionMinor;
int64_t kVersionPatch;

bool CheckVersion(int64_t major, int64_t minor);
bool CheckLowestVersion(int64_t major, int64_t minor, int64_t patch);
bool CheckHighestVersion(int64_t major, int64_t minor, int64_t patch);

// Public, because other modules may use it
void Load();
Expand Down Expand Up @@ -434,6 +436,8 @@ class Types : public Module {
int64_t kGlobalObjectType;
int64_t kOddballType;
int64_t kJSObjectType;
int64_t kJSAPIObjectType;
int64_t kJSSpecialAPIObjectType;
int64_t kJSArrayType;
int64_t kCodeType;
int64_t kJSFunctionType;
Expand Down
6 changes: 6 additions & 0 deletions src/llv8-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ inline int64_t Map::InstanceSize(Error& err) {
ACCESSOR(JSObject, Properties, js_object()->kPropertiesOffset, HeapObject)
ACCESSOR(JSObject, Elements, js_object()->kElementsOffset, HeapObject)

inline bool JSObject::IsObjectType(LLV8* v8, int64_t type) {
return type == v8->types()->kJSObjectType ||
type == v8->types()->kJSAPIObjectType ||
type == v8->types()->kJSSpecialAPIObjectType;
}

ACCESSOR(HeapNumber, GetValue, heap_number()->kValueOffset, double)

ACCESSOR(JSArray, Length, js_array()->kLengthOffset, Smi)
Expand Down
4 changes: 2 additions & 2 deletions src/llv8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ std::string HeapObject::Inspect(InspectOptions* options, Error& err) {
return pre + m.Inspect(options, err);
}

if (type == v8()->types()->kJSObjectType) {
if (JSObject::IsObjectType(v8(), type)) {
JSObject o(this);
return pre + o.Inspect(options, err);
}
Expand Down Expand Up @@ -799,7 +799,7 @@ std::string HeapObject::GetTypeName(InspectOptions* options, Error& err) {
return "(Map)";
}

if (type == v8()->types()->kJSObjectType) {
if (JSObject::IsObjectType(v8(), type)) {
v8::HeapObject map_obj = GetMap(err);
if (err.Fail()) {
return std::string();
Expand Down
1 change: 1 addition & 0 deletions src/llv8.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class JSObject : public HeapObject {
int64_t GetArrayLength(Error& err);
Value GetArrayElement(int64_t pos, Error& err);

static inline bool IsObjectType(LLV8* v8, int64_t type);

protected:
template <class T>
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/inspect-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const common = require('../common');

const zlib = require('zlib');

let outerVar = 'outer variable';

function closure() {
Expand Down Expand Up @@ -30,9 +32,10 @@ function closure() {
c.hashmap[25] = (a,b)=>{a+b};

let scopedVar = 'scoped value';
let scopedAPI = zlib.createDeflate()._handle;

c.hashmap.scoped = function name() {
return scopedVar + outerVar;
return scopedVar + outerVar + scopedAPI;
};

c.method();
Expand Down
1 change: 1 addition & 0 deletions test/inspect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ tape('v8 inspect', (t) => {
// No Context debugging for older node.js
t.ok(/\(previous\)/.test(lines), 'method.previous');
t.ok(/scopedVar[^\n]+"scoped value"/.test(lines), 'method.scopedValue');
t.ok(/scopedAPI[^\n]+Zlib/.test(lines), 'method.scopedAPI');

let match = lines.match(
/\(closure\)=(0x[0-9a-f]+)[^\n]+function: closure/i);
Expand Down

0 comments on commit ad45a96

Please sign in to comment.