src: move JSDate "ToString" logic to JSDate class by Drieger · Pull Request #257 · nodejs/llnode · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/llv8.cc
1 change: 1 addition & 0 deletions src/llv8.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ class JSDate : public JSObject {
V8_VALUE_DEFAULT_METHODS(JSDate, JSObject);

inline Value GetValue(Error& err);
std::string ToString(Error& err);
};

class FixedArrayBase : public HeapObject {
Expand Down
33 changes: 5 additions & 28 deletions src/printer.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <cinttypes>
#include <sstream>
#include <iostream>

#include "deps/rang/include/rang.hpp"
#include "src/llv8-inl.h"
Expand Down Expand Up @@ -136,34 +137,10 @@ std::string Printer::Stringify(v8::JSFunction js_function, Error& err) {

template <>
std::string Printer::Stringify(v8::JSDate js_date, Error& err) {
std::string pre = "<JSDate: ";

v8::Value val = js_date.GetValue(err);

v8::Smi smi(val);
if (smi.Check()) {
std::string s = smi.ToString(err);
if (err.Fail()) {
return pre + ">";
}

return pre + s + ">";
}

v8::HeapNumber hn(val);
if (hn.Check()) {
std::string s = hn.ToString(true, err);
if (err.Fail()) {
return pre + ">";
}
return pre + s + ">";
}

double d = static_cast<double>(val.raw());

@Drieger Drieger Jan 16, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evanlucas do you remember why this last part, casting to double, was added? I couldn't find any test case where I could reach it. It was originally introduced in https://github.com/nodejs/llnode/pull/3/files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not off the top of my head, sorry!

char buf[128];
snprintf(buf, sizeof(buf), "%f", d);

return pre + ">";
std::stringstream ss;
ss << rang::fg::yellow << "<JSDate: " + js_date.ToString(err) + ">"
<< rang::fg::reset;
return ss.str();
}

template <>
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/inspect-scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ function closure() {
let scopedAPI = zlib.createDeflate()._handle;
let scopedArray = [ 0, scopedAPI ];

c.hashmap['date_1'] = new Date('2000-01-01');
c.hashmap['date_2'] = new Date(1);

exports.holder = scopedAPI;

c.hashmap.scoped = function name() {
Expand Down
11 changes: 11 additions & 0 deletions test/plugin/inspect-test.js