Commit 766d3ea9 authored by yangguo's avatar yangguo Committed by Commit bot

[json] handle access checks in BasicJsonStringifier.

R=cbruni@chromium.org

Review-Url: https://codereview.chromium.org/1996333002
Cr-Commit-Position: refs/heads/master@{#36416}
parent ca266e74
...@@ -104,7 +104,6 @@ enum BindingFlags { ...@@ -104,7 +104,6 @@ enum BindingFlags {
V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \ V(EVAL_ERROR_FUNCTION_INDEX, JSFunction, eval_error_function) \
V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \ V(GET_STACK_TRACE_LINE_INDEX, JSFunction, get_stack_trace_line_fun) \
V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \ V(GLOBAL_EVAL_FUN_INDEX, JSFunction, global_eval_fun) \
V(JSON_SERIALIZE_ADAPTER_INDEX, JSFunction, json_serialize_adapter) \
V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \ V(MAKE_ERROR_FUNCTION_INDEX, JSFunction, make_error_function) \
V(MAP_DELETE_METHOD_INDEX, JSFunction, map_delete) \ V(MAP_DELETE_METHOD_INDEX, JSFunction, map_delete) \
V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \ V(MAP_GET_METHOD_INDEX, JSFunction, map_get) \
......
...@@ -280,19 +280,4 @@ utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [ ...@@ -280,19 +280,4 @@ utils.InstallFunctions(GlobalDate.prototype, DONT_ENUM, [
"toJSON", DateToJSON "toJSON", DateToJSON
]); ]);
// -------------------------------------------------------------------
// JSON Builtins
function JsonSerializeAdapter(key, object, indent, gap) {
var holder = {};
holder[key] = object;
// No need to pass the actual holder since there is no replacer function.
var current_indent = "";
for (var i = 0; i < indent; i++) current_indent += gap;
return JSONSerialize(
key, holder, UNDEFINED, new Stack(), current_indent, gap);
}
%InstallToContext(["json_serialize_adapter", JsonSerializeAdapter]);
}) })
...@@ -33,11 +33,6 @@ class BasicJsonStringifier BASE_EMBEDDED { ...@@ -33,11 +33,6 @@ class BasicJsonStringifier BASE_EMBEDDED {
Handle<Object> object, Handle<Object> object,
Handle<Object> key); Handle<Object> key);
Result SerializeGeneric(Handle<Object> object,
Handle<Object> key,
bool deferred_comma,
bool deferred_key);
// Entry point to serialize the object. // Entry point to serialize the object.
INLINE(Result SerializeObject(Handle<Object> obj)) { INLINE(Result SerializeObject(Handle<Object> obj)) {
return Serialize_<false>(obj, false, factory()->empty_string()); return Serialize_<false>(obj, false, factory()->empty_string());
...@@ -363,21 +358,23 @@ BasicJsonStringifier::Result BasicJsonStringifier::Serialize_( ...@@ -363,21 +358,23 @@ BasicJsonStringifier::Result BasicJsonStringifier::Serialize_(
return UNCHANGED; return UNCHANGED;
} }
case JS_ARRAY_TYPE: case JS_ARRAY_TYPE:
if (object->IsAccessCheckNeeded()) break;
if (deferred_string_key) SerializeDeferredKey(comma, key); if (deferred_string_key) SerializeDeferredKey(comma, key);
return SerializeJSArray(Handle<JSArray>::cast(object)); return SerializeJSArray(Handle<JSArray>::cast(object));
case JS_VALUE_TYPE: case JS_VALUE_TYPE:
if (deferred_string_key) SerializeDeferredKey(comma, key); if (deferred_string_key) SerializeDeferredKey(comma, key);
return SerializeJSValue(Handle<JSValue>::cast(object)); return SerializeJSValue(Handle<JSValue>::cast(object));
case SIMD128_VALUE_TYPE:
case SYMBOL_TYPE:
return UNCHANGED;
default: default:
if (object->IsString()) { if (object->IsString()) {
if (deferred_string_key) SerializeDeferredKey(comma, key); if (deferred_string_key) SerializeDeferredKey(comma, key);
SerializeString(Handle<String>::cast(object)); SerializeString(Handle<String>::cast(object));
return SUCCESS; return SUCCESS;
} else if (object->IsJSReceiver()) { } else {
DCHECK(object->IsJSReceiver());
if (object->IsCallable()) return UNCHANGED; if (object->IsCallable()) return UNCHANGED;
// Go to slow path for global proxy and objects requiring access checks. // Go to slow path for global proxy and objects requiring access checks.
if (object->IsAccessCheckNeeded() || object->IsJSGlobalProxy()) break;
if (deferred_string_key) SerializeDeferredKey(comma, key); if (deferred_string_key) SerializeDeferredKey(comma, key);
if (object->IsJSProxy()) { if (object->IsJSProxy()) {
return SerializeJSProxy(Handle<JSProxy>::cast(object)); return SerializeJSProxy(Handle<JSProxy>::cast(object));
...@@ -386,30 +383,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::Serialize_( ...@@ -386,30 +383,8 @@ BasicJsonStringifier::Result BasicJsonStringifier::Serialize_(
} }
} }
return SerializeGeneric(object, key, comma, deferred_string_key); UNREACHABLE();
} return UNCHANGED;
BasicJsonStringifier::Result BasicJsonStringifier::SerializeGeneric(
Handle<Object> object,
Handle<Object> key,
bool deferred_comma,
bool deferred_key) {
Handle<JSFunction> fun = isolate_->json_serialize_adapter();
Handle<Object> indent(Smi::FromInt(indent_), isolate_);
Handle<Object> argv[] = {key, object, indent, gap_string_};
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate_, result,
Execution::Call(isolate_, fun, object, arraysize(argv), argv), EXCEPTION);
if (result->IsUndefined()) return UNCHANGED;
if (deferred_key) {
if (key->IsSmi()) key = factory()->NumberToString(key);
SerializeDeferredKey(deferred_comma, key);
}
builder_.AppendString(Handle<String>::cast(result));
return SUCCESS;
} }
...@@ -433,8 +408,6 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue( ...@@ -433,8 +408,6 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSValue(
builder_.AppendCString(value->IsTrue() ? "true" : "false"); builder_.AppendCString(value->IsTrue() ? "true" : "false");
} else { } else {
// ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject. // ES6 24.3.2.1 step 10.c, serialize as an ordinary JSObject.
CHECK(!object->IsAccessCheckNeeded());
CHECK(!object->IsJSGlobalProxy());
return SerializeJSObject(object); return SerializeJSObject(object);
} }
return SUCCESS; return SUCCESS;
...@@ -471,6 +444,7 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray( ...@@ -471,6 +444,7 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSArray(
if (stack_push != SUCCESS) return stack_push; if (stack_push != SUCCESS) return stack_push;
uint32_t length = 0; uint32_t length = 0;
CHECK(object->length()->ToArrayLength(&length)); CHECK(object->length()->ToArrayLength(&length));
DCHECK(!object->IsAccessCheckNeeded());
builder_.AppendCharacter('['); builder_.AppendCharacter('[');
Indent(); Indent();
switch (object->GetElementsKind()) { switch (object->GetElementsKind()) {
...@@ -561,12 +535,12 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject( ...@@ -561,12 +535,12 @@ BasicJsonStringifier::Result BasicJsonStringifier::SerializeJSObject(
HandleScope handle_scope(isolate_); HandleScope handle_scope(isolate_);
Result stack_push = StackPush(object); Result stack_push = StackPush(object);
if (stack_push != SUCCESS) return stack_push; if (stack_push != SUCCESS) return stack_push;
DCHECK(!object->IsJSGlobalProxy() && !object->IsJSGlobalObject());
if (object->map()->instance_type() > LAST_CUSTOM_ELEMENTS_RECEIVER && if (object->map()->instance_type() > LAST_CUSTOM_ELEMENTS_RECEIVER &&
object->HasFastProperties() && object->HasFastProperties() &&
Handle<JSObject>::cast(object)->elements()->length() == 0) { Handle<JSObject>::cast(object)->elements()->length() == 0) {
DCHECK(object->IsJSObject()); DCHECK(object->IsJSObject());
DCHECK(!object->IsJSGlobalProxy());
Handle<JSObject> js_obj = Handle<JSObject>::cast(object); Handle<JSObject> js_obj = Handle<JSObject>::cast(object);
DCHECK(!js_obj->HasIndexedInterceptor()); DCHECK(!js_obj->HasIndexedInterceptor());
DCHECK(!js_obj->HasNamedInterceptor()); DCHECK(!js_obj->HasNamedInterceptor());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment