Skip to content
Permalink
Browse files

core, bugfix: javascript getter throw in libs(assert, jsonformat, uti…

…l, sandbox) (#511)
  • Loading branch information...
Fiber-Man authored and xicilion committed Jun 24, 2019
1 parent c6fa2d7 commit 750f23e084ba1dd43160c283622676be2818bbdd
Showing with 524 additions and 14 deletions.
  1. +2 −1 fibjs/include/SandBox.h
  2. +6 −0 fibjs/include/utils.h
  3. +11 −1 fibjs/src/test/assert.cpp
  4. +52 −11 fibjs/src/util/util.cpp
  5. +9 −1 fibjs/src/util/util_format.cpp
  6. +443 −0 test/getter_throw.js
  7. +1 −0 test/main.js
@@ -62,7 +62,8 @@ class SandBox : public SandBox_base {

if (m.IsEmpty()) {
m = v8::Object::New(isolate->m_isolate);
m->Set(isolate->NewString("exports"), o);
if (!o.IsEmpty())
m->Set(isolate->NewString("exports"), o);
}

mods()->Set(isolate->NewString(fname), m);
@@ -556,6 +556,9 @@ inline result_t GetArgumentValue(v8::Local<v8::Value> v, exlib::string& n, bool
else
return CALL_E_TYPEMISMATCH;

if (str.IsEmpty())
return CALL_E_JAVASCRIPT;

int32_t bufUtf8Len = str->Utf8Length();
n.resize(bufUtf8Len);
int flags = v8::String::HINT_MANY_WRITES_EXPECTED | v8::String::NO_NULL_TERMINATION;
@@ -581,6 +584,9 @@ inline result_t GetArgumentValue(v8::Local<v8::Value> v, double& n, bool bStrict
v = v->ToNumber(Isolate::current()->m_isolate);
}

if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

n = v->NumberValue();
if (std::isnan(n))
n = 0;
@@ -256,7 +256,12 @@ bool objectEquals(QuickArray<v8::Local<v8::Object>>& acts,

for (i = 0; i < len; i++) {
v8::Local<v8::Value> ks = keys->Get(i);
if (!deepEquals(acts, exps, act->Get(ks), exp->Get(ks))) {
v8::Local<v8::Value> v1 = act->Get(ks);
v8::Local<v8::Value> v2 = exp->Get(ks);
if (v1.IsEmpty() || v2.IsEmpty())
return CALL_E_JAVASCRIPT;

if (!deepEquals(acts, exps, v1, v2)) {
acts.pop();
exps.pop();
return false;
@@ -786,6 +791,9 @@ result_t has_val(v8::Local<v8::Value> object, v8::Local<v8::Value> prop,

v8::Local<v8::Object> v = object->ToObject();
got = v->Get(prop);
if(got.IsEmpty())
return CALL_E_JAVASCRIPT;

retVal = value->Equals(got);

return 0;
@@ -850,6 +858,8 @@ result_t deep_has_val(v8::Local<v8::Value> object, v8::Local<v8::Value> prop,
}

got = v->Get(isolate->NewString(p));
if(got.IsEmpty())
return CALL_E_JAVASCRIPT;
retVal = value->Equals(got);

return 0;
@@ -86,7 +86,10 @@ result_t util_base::values(v8::Local<v8::Value> v, v8::Local<v8::Array>& retVal)

for (i = 0; i < len; i++) {
v8::Local<v8::Value> key = keys->Get(i);
arr->Set(n++, obj->Get(key));
v8::Local<v8::Value> value = obj->Get(key);
if (value.IsEmpty())
return CALL_E_JAVASCRIPT;
arr->Set(n++, value);
}

retVal = arr;
@@ -98,6 +101,9 @@ result_t util_base::values(v8::Local<v8::Value> v, v8::Local<v8::Array>& retVal)

result_t util_base::clone(v8::Local<v8::Value> v, v8::Local<v8::Value>& retVal)
{
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;

if (!v->IsProxy() && v->IsObject() && !object_base::getInstance(v)) {
Isolate* isolate = Isolate::current();
v8::Local<v8::Context> _context = isolate->context();
@@ -174,7 +180,10 @@ result_t util_base::extend(v8::Local<v8::Value> v, OptArgs objs,

for (j = 0; j < len; j++) {
v8::Local<v8::Value> key = keys->Get(j);
obj->Set(key, obj1->Get(key));
v8::Local<v8::Value> value = obj1->Get(key);
if (value.IsEmpty())
return CALL_E_JAVASCRIPT;
obj->Set(key, value);
}
}

@@ -215,14 +224,22 @@ result_t util_base::pick(v8::Local<v8::Value> v, OptArgs objs,
for (j = 0; j < len; j++) {
v8::Local<v8::Value> k = arr->Get(j);

if (obj->Has(k))
obj1->Set(k, obj->Get(k));
if (obj->Has(k)) {
v8::Local<v8::Value> v = obj->Get(k);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;
obj1->Set(k, v);
}
}
} else {
v8::Local<v8::Value> k = o;

if (obj->Has(k))
obj1->Set(k, obj->Get(k));
if (obj->Has(k)) {
v8::Local<v8::Value> v = obj->Get(k);
if (v.IsEmpty())
return CALL_E_JAVASCRIPT;
obj1->Set(k, v);
}
}
}

@@ -281,8 +298,12 @@ result_t util_base::omit(v8::Local<v8::Value> v, OptArgs keys,
for (i = 0; i < len; i++) {
v8::Local<v8::Value> key = keys1->Get(i);

if (_map.find(ToCString(v8::String::Utf8Value(key))) == _map.end())
obj1->Set(key, obj->Get(key));
if (_map.find(ToCString(v8::String::Utf8Value(key))) == _map.end()) {
v8::Local<v8::Value> value = obj->Get(key);
if (value.IsEmpty())
return CALL_E_JAVASCRIPT;
obj1->Set(key, value);
}
}

retVal = obj1;
@@ -669,12 +690,17 @@ result_t util_base::each(v8::Local<v8::Value> list, v8::Local<v8::Function> iter

if (IsEmpty(v)) {
v8::Local<v8::Array> keys = o->GetPropertyNames();
int32_t len = keys->Length();
int32_t len = 0;
if (!keys.IsEmpty())
len = keys->Length();

int32_t i;

for (i = 0; i < len; i++) {
args[1] = keys->Get(i);
args[0] = o->Get(args[1]);
if (args[0].IsEmpty() || args[1].IsEmpty())
return CALL_E_JAVASCRIPT;

v = iterator->Call(context, 3, args);
if (v.IsEmpty())
@@ -688,6 +714,8 @@ result_t util_base::each(v8::Local<v8::Value> list, v8::Local<v8::Function> iter
for (i = 0; i < len; i++) {
args[1] = v8::Int32::New(isolate->m_isolate, i);
args[0] = o->Get(args[1]);
if (args[0].IsEmpty() || args[1].IsEmpty())
return CALL_E_JAVASCRIPT;

v = iterator->Call(context, 3, args);
if (v.IsEmpty())
@@ -720,12 +748,16 @@ result_t util_base::map(v8::Local<v8::Value> list, v8::Local<v8::Function> itera

if (IsEmpty(v)) {
v8::Local<v8::Array> keys = o->GetPropertyNames();
int32_t len = keys->Length();
int32_t len = 0;
if (!keys.IsEmpty())
len = keys->Length();
int32_t i;

for (i = 0; i < len; i++) {
args[1] = keys->Get(i);
args[0] = o->Get(args[1]);
if (args[0].IsEmpty() || args[1].IsEmpty())
return CALL_E_JAVASCRIPT;

v = iterator->Call(context, 3, args);
if (v.IsEmpty())
@@ -741,6 +773,8 @@ result_t util_base::map(v8::Local<v8::Value> list, v8::Local<v8::Function> itera
for (i = 0; i < len; i++) {
args[1] = v8::Int32::New(isolate->m_isolate, i);
args[0] = o->Get(args[1]);
if (args[0].IsEmpty() || args[1].IsEmpty())
return CALL_E_JAVASCRIPT;

v = iterator->Call(context, 3, args);
if (v.IsEmpty())
@@ -773,12 +807,17 @@ result_t util_base::reduce(v8::Local<v8::Value> list, v8::Local<v8::Function> it

if (IsEmpty(v)) {
v8::Local<v8::Array> keys = o->GetPropertyNames();
int32_t len = keys->Length();
int32_t len = 0;
if (!keys.IsEmpty())
len = keys->Length();

int32_t i;

for (i = 0; i < len; i++) {
args[2] = keys->Get(i);
args[1] = o->Get(args[2]);
if (args[1].IsEmpty() || args[2].IsEmpty())
return CALL_E_JAVASCRIPT;

args[0] = memo;

@@ -794,6 +833,8 @@ result_t util_base::reduce(v8::Local<v8::Value> list, v8::Local<v8::Function> it
for (i = 0; i < len; i++) {
args[2] = v8::Int32::New(isolate->m_isolate, i);
args[1] = o->Get(args[2]);
if (args[1].IsEmpty() || args[2].IsEmpty())
return CALL_E_JAVASCRIPT;

args[0] = memo;

@@ -232,7 +232,15 @@ exlib::string json_format(v8::Local<v8::Value> obj)
if (len == 0)
strBuffer.append("{}");
else {
if (len == 1 && v->StrictEquals(obj->Get(keys->Get(0))))
v8::Local<v8::Value> k1 = keys->Get(0);
v8::Local<v8::Value> v1;
if (!k1.IsEmpty())
v1 = obj->Get(k1);

if (v1.IsEmpty())
v1 = v8::Undefined(isolate->m_isolate);

if (len == 1 && v->StrictEquals(v1))
strBuffer.append("[Circular]");
else {
stk.resize(sz + 1);

0 comments on commit 750f23e

Please sign in to comment.
You can’t perform that action at this time.