Commit 0bd41314 authored by cbruni's avatar cbruni Committed by Commit bot

[runtime] Add Arguments.atOrUndefined()

atOrUndefined() will return undefined if the index is >= length()

BUG=

Review URL: https://codereview.chromium.org/1541413002

Cr-Commit-Position: refs/heads/master@{#33033}
parent f17c1d11
...@@ -47,6 +47,13 @@ class BuiltinArguments : public Arguments { ...@@ -47,6 +47,13 @@ class BuiltinArguments : public Arguments {
return Arguments::at<S>(index); return Arguments::at<S>(index);
} }
Handle<Object> atOrUndefined(Isolate* isolate, int index) {
if (index >= length()) {
return isolate->factory()->undefined_value();
}
return at<Object>(index);
}
Handle<Object> receiver() { Handle<Object> receiver() {
return Arguments::at<Object>(0); return Arguments::at<Object>(0);
} }
...@@ -1430,10 +1437,7 @@ BUILTIN(ArrayIsArray) { ...@@ -1430,10 +1437,7 @@ BUILTIN(ArrayIsArray) {
// ES6 19.1.2.1 Object.assign // ES6 19.1.2.1 Object.assign
BUILTIN(ObjectAssign) { BUILTIN(ObjectAssign) {
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Object> target = Handle<Object> target = args.atOrUndefined(isolate, 1);
args.length() > 1
? args.at<Object>(1)
: Handle<Object>::cast(isolate->factory()->undefined_value());
// 1. Let to be ? ToObject(target). // 1. Let to be ? ToObject(target).
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target,
...@@ -1613,9 +1617,8 @@ BUILTIN(ReflectDeleteProperty) { ...@@ -1613,9 +1617,8 @@ BUILTIN(ReflectDeleteProperty) {
// ES6 section 26.1.6 Reflect.get // ES6 section 26.1.6 Reflect.get
BUILTIN(ReflectGet) { BUILTIN(ReflectGet) {
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Object> undef = isolate->factory()->undefined_value(); Handle<Object> target = args.atOrUndefined(isolate, 1);
Handle<Object> target = args.length() > 1 ? args.at<Object>(1) : undef; Handle<Object> key = args.atOrUndefined(isolate, 2);
Handle<Object> key = args.length() > 2 ? args.at<Object>(2) : undef;
Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target; Handle<Object> receiver = args.length() > 3 ? args.at<Object>(3) : target;
if (!target->IsJSReceiver()) { if (!target->IsJSReceiver()) {
...@@ -1774,10 +1777,9 @@ BUILTIN(ReflectPreventExtensions) { ...@@ -1774,10 +1777,9 @@ BUILTIN(ReflectPreventExtensions) {
// ES6 section 26.1.13 Reflect.set // ES6 section 26.1.13 Reflect.set
BUILTIN(ReflectSet) { BUILTIN(ReflectSet) {
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<Object> undef = isolate->factory()->undefined_value(); Handle<Object> target = args.atOrUndefined(isolate, 1);
Handle<Object> target = args.length() > 1 ? args.at<Object>(1) : undef; Handle<Object> key = args.atOrUndefined(isolate, 2);
Handle<Object> key = args.length() > 2 ? args.at<Object>(2) : undef; Handle<Object> value = args.atOrUndefined(isolate, 3);
Handle<Object> value = args.length() > 3 ? args.at<Object>(3) : undef;
Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target; Handle<Object> receiver = args.length() > 4 ? args.at<Object>(4) : target;
if (!target->IsJSReceiver()) { if (!target->IsJSReceiver()) {
...@@ -2053,18 +2055,8 @@ BUILTIN(ProxyConstructor) { ...@@ -2053,18 +2055,8 @@ BUILTIN(ProxyConstructor) {
BUILTIN(ProxyConstructor_ConstructStub) { BUILTIN(ProxyConstructor_ConstructStub) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(isolate->proxy_function()->IsConstructor()); DCHECK(isolate->proxy_function()->IsConstructor());
Handle<Object> target; Handle<Object> target = args.atOrUndefined(isolate, 1);
if (args.length() < 2) { Handle<Object> handler = args.atOrUndefined(isolate, 2);
target = isolate->factory()->undefined_value();
} else {
target = args.at<Object>(1);
}
Handle<Object> handler;
if (args.length() < 3) {
handler = isolate->factory()->undefined_value();
} else {
handler = args.at<Object>(2);
}
// The ConstructStub is executed in the context of the caller, so we need // The ConstructStub is executed in the context of the caller, so we need
// to enter the callee context first before raising an exception. // to enter the callee context first before raising an exception.
isolate->set_context(args.target()->context()); isolate->set_context(args.target()->context());
......
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