Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
add std::move to Call
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzilin committed Aug 5, 2024
1 parent d5488ee commit 7fc42a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
12 changes: 5 additions & 7 deletions es/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,6 @@ Handle<JSValue> EvalBinaryExpression(Handle<Error>& e, Token& op, AST* lhs, AST*
case Token::TK_ASSIGN: {
Handle<JSValue> lref = EvalLeftHandSideExpression(e, lhs);
if (unlikely(!e.val()->IsOk())) return Handle<JSValue>();
// TODO(zhuzilin) The compound assignment should do lval = GetValue(lref)
// here. Check if changing the order will have any influence.
Handle<JSValue> rval = EvalExpressionAndGetValue(e, rhs);
if (unlikely(!e.val()->IsOk())) return Handle<JSValue>();
return EvalSimpleAssignment(e, lref, rval);
Expand Down Expand Up @@ -1464,11 +1462,11 @@ Handle<JSValue> EvalLeftHandSideExpression(Handle<Error>& e, AST* ast) {
return Handle<JSValue>();
}
Handle<JSObject> constructor = static_cast<Handle<JSObject>>(base);
base = Construct(e, constructor, arg_list);
base = Construct(e, constructor, std::move(arg_list));
if (unlikely(!e.val()->IsOk())) return Handle<JSValue>();
new_count--;
} else {
base = EvalCallExpression(e, base, arg_list);
base = EvalCallExpression(e, base, std::move(arg_list));
if (unlikely(!e.val()->IsOk())) return Handle<JSValue>();
}
break;
Expand Down Expand Up @@ -1543,14 +1541,14 @@ Handle<JSValue> EvalCallExpression(Handle<Error>& e, Handle<JSValue> ref, std::v
this_value = ImplicitThisValue(env_rec);
}
// indirect
if (StringEqual(ref_name, String::eval())) {
if (unlikely(StringEqual(ref_name, String::eval()))) {
DirectEvalGuard guard;
return Call(e, obj, this_value, arg_list);
return Call(e, obj, this_value, std::move(arg_list));
}
} else {
this_value = Undefined::Instance();
}
return Call(e, obj, this_value, arg_list);
return Call(e, obj, this_value, std::move(arg_list));
}

// 11.2.1 Property Accessors
Expand Down
30 changes: 15 additions & 15 deletions es/impl/call-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ Handle<JSValue> Call(
if (O.val()->IsFunctionObject()) {
Handle<FunctionObject> F = static_cast<Handle<FunctionObject>>(O);
if (!F.val()->from_bind()) {
return Call__Function(e, F, this_arg, arguments);
return Call__Function(e, F, this_arg, std::move(arguments));
} else {
return Call__BindFunction(e, static_cast<Handle<BindFunctionObject>>(O), this_arg, arguments);
return Call__BindFunction(e, static_cast<Handle<BindFunctionObject>>(O), this_arg, std::move(arguments));
}
} else if (O.val()->IsConstructor()) {
switch (O.val()->type()) {
case Type::OBJ_BOOL_CONSTRUCTOR:
return Call__BoolConstructor(e, static_cast<Handle<BoolConstructor>>(O), this_arg, arguments);
return Call__BoolConstructor(e, static_cast<Handle<BoolConstructor>>(O), this_arg, std::move(arguments));
case Type::OBJ_NUMBER_CONSTRUCTOR:
return Call__NumberConstructor(e, static_cast<Handle<NumberConstructor>>(O), this_arg, arguments);
return Call__NumberConstructor(e, static_cast<Handle<NumberConstructor>>(O), this_arg, std::move(arguments));
case Type::OBJ_OBJECT_CONSTRUCTOR:
return Call__ObjectConstructor(e, static_cast<Handle<ObjectConstructor>>(O), this_arg, arguments);
return Call__ObjectConstructor(e, static_cast<Handle<ObjectConstructor>>(O), this_arg, std::move(arguments));
case Type::OBJ_REGEXP_CONSTRUCTOR:
return Call__RegExpConstructor(e, static_cast<Handle<RegExpConstructor>>(O), this_arg, arguments);
return Call__RegExpConstructor(e, static_cast<Handle<RegExpConstructor>>(O), this_arg, std::move(arguments));
case Type::OBJ_STRING_CONSTRUCTOR:
return Call__StringConstructor(e, static_cast<Handle<StringConstructor>>(O), this_arg, arguments);
return Call__StringConstructor(e, static_cast<Handle<StringConstructor>>(O), this_arg, std::move(arguments));
case Type::OBJ_FUNC_CONSTRUCTOR:
case Type::OBJ_ARRAY_CONSTRUCTOR:
case Type::OBJ_DATE_CONSTRUCTOR:
Expand All @@ -35,16 +35,16 @@ Handle<JSValue> Call(
// 15.5.1.1 Array ( [ value ] )
// 15.9.2.1 Date ( [ year [, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] ] ] )
// 15.11.1.1 Error (message)
return Call__Construct(e, O, this_arg, arguments);
return Call__Construct(e, O, this_arg, std::move(arguments));
default:
assert(false);
}
} else if (O.val()->IsFunctionProto()) {
return Call__FunctionProto(e, static_cast<Handle<FunctionProto>>(O), this_arg, arguments);
return Call__FunctionProto(e, static_cast<Handle<FunctionProto>>(O), this_arg, std::move(arguments));
} else if (O.val()->IsGetterSetter()) {
return Call__GetterSetter(e, static_cast<Handle<GetterSetter>>(O), this_arg, arguments);
return Call__GetterSetter(e, static_cast<Handle<GetterSetter>>(O), this_arg, std::move(arguments));
} else {
return Call__Base(e, O, this_arg, arguments);
return Call__Base(e, O, this_arg, std::move(arguments));
}
}

Expand All @@ -53,13 +53,13 @@ Handle<JSValue> Call__Base(
) {
inner_func callable = O.val()->callable();
ASSERT(O.val()->IsCallable() && callable != nullptr);
return callable(e, O, arguments);
return callable(e, O, std::move(arguments));
}

Handle<JSValue> Call__Construct(
Handle<Error>& e, Handle<JSObject> O, Handle<JSValue> this_arg, std::vector<Handle<JSValue>> arguments
) {
return Construct(e, O, arguments);
return Construct(e, O, std::move(arguments));
}

// 13.2.1 [[Call]]
Expand Down Expand Up @@ -169,7 +169,7 @@ Handle<JSValue> Call__ObjectConstructor(
Handle<Error>& e, Handle<ObjectConstructor> O, Handle<JSValue> this_arg, std::vector<Handle<JSValue>> arguments
) {
if (arguments.size() == 0 || arguments[0].val()->IsNull() || arguments[0].val()->IsUndefined())
return Construct(e, O, arguments);
return Construct(e, O, std::move(arguments));
return ToObject(e, arguments[0]);
}

Expand All @@ -184,7 +184,7 @@ Handle<JSValue> Call__RegExpConstructor(
if ((arguments.size() == 1 || arguments[1].val()->IsUndefined()) && arguments[0].val()->IsRegExpObject()) {
return arguments[0];
}
return Construct(e, O, arguments);
return Construct(e, O, std::move(arguments));
}

// 15.5.1.1 String ( [ value ] )
Expand Down
22 changes: 11 additions & 11 deletions es/impl/construct-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ Handle<JSObject> Construct(Handle<Error>& e, Handle<JSObject> O, std::vector<Han
if (O.val()->IsFunctionObject()) {
Handle<FunctionObject> F = static_cast<Handle<FunctionObject>>(O);
if (!F.val()->from_bind()) {
return Construct__Function(e, F, arguments);
return Construct__Function(e, F, std::move(arguments));
} else {
return Construct__BindFunction(e, static_cast<Handle<BindFunctionObject>>(O), arguments);
return Construct__BindFunction(e, static_cast<Handle<BindFunctionObject>>(O), std::move(arguments));
}
} else if (O.val()->IsConstructor()) {
switch (O.val()->type()) {
case Type::OBJ_BOOL_CONSTRUCTOR:
return Construct__BoolConstructor(e, static_cast<Handle<BoolConstructor>>(O), arguments);
return Construct__BoolConstructor(e, static_cast<Handle<BoolConstructor>>(O), std::move(arguments));
case Type::OBJ_NUMBER_CONSTRUCTOR:
return Construct__NumberConstructor(e, static_cast<Handle<NumberConstructor>>(O), arguments);
return Construct__NumberConstructor(e, static_cast<Handle<NumberConstructor>>(O), std::move(arguments));
case Type::OBJ_OBJECT_CONSTRUCTOR:
return Construct__ObjectConstructor(e, static_cast<Handle<ObjectConstructor>>(O), arguments);
return Construct__ObjectConstructor(e, static_cast<Handle<ObjectConstructor>>(O), std::move(arguments));
case Type::OBJ_REGEXP_CONSTRUCTOR:
return Construct__RegExpConstructor(e, static_cast<Handle<RegExpConstructor>>(O), arguments);
return Construct__RegExpConstructor(e, static_cast<Handle<RegExpConstructor>>(O), std::move(arguments));
case Type::OBJ_STRING_CONSTRUCTOR:
return Construct__StringConstructor(e, static_cast<Handle<StringConstructor>>(O), arguments);
return Construct__StringConstructor(e, static_cast<Handle<StringConstructor>>(O), std::move(arguments));
case Type::OBJ_FUNC_CONSTRUCTOR:
return Construct__FunctionConstructor(e, static_cast<Handle<FunctionConstructor>>(O), arguments);
return Construct__FunctionConstructor(e, static_cast<Handle<FunctionConstructor>>(O), std::move(arguments));
case Type::OBJ_ARRAY_CONSTRUCTOR:
return Construct__ArrayConstructor(e, static_cast<Handle<ArrayConstructor>>(O), arguments);
return Construct__ArrayConstructor(e, static_cast<Handle<ArrayConstructor>>(O), std::move(arguments));
case Type::OBJ_DATE_CONSTRUCTOR:
assert(false);
case Type::OBJ_ERROR_CONSTRUCTOR:
return Construct__ErrorConstructor(e, static_cast<Handle<ErrorConstructor>>(O), arguments);
return Construct__ErrorConstructor(e, static_cast<Handle<ErrorConstructor>>(O), std::move(arguments));
default:
assert(false);
}
Expand All @@ -58,7 +58,7 @@ Handle<JSObject> Construct__Function(
} else { // 7
obj.val()->SetPrototype(ObjectProto::Instance());
}
Handle<JSValue> result = Call(e, O, obj, arguments); // 8
Handle<JSValue> result = Call(e, O, obj, std::move(arguments)); // 8
// get more accurate num_decls from runtime.
func_ast->body()->SetNumThisProperties(obj.val()->named_properties()->hashmap().val()->occupancy());
if (unlikely(!e.val()->IsOk())) return Handle<JSValue>();
Expand Down

0 comments on commit 7fc42a9

Please sign in to comment.