1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

fix: replace single case type switches with if (#322)

Replace single case type switches with if statement.

Found using https://go-critic.github.io/overview.html#singleCaseSwitch-ref
This commit is contained in:
Iskander (Alex) Sharipov 2021-09-27 18:47:34 +03:00 committed by GitHub
parent 818f7465f8
commit ca9b4f9067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,11 +87,8 @@ func (value Value) IsNull() bool {
// ---
func (value Value) isCallable() bool {
switch value := value.value.(type) {
case *_object:
return value.isCall()
}
return false
v, ok := value.value.(*_object)
return ok && v.isCall()
}
// Call the value as a function with the given this value and argument list and
@ -118,8 +115,7 @@ func (value Value) Call(this Value, argumentList ...interface{}) (Value, error)
}
func (value Value) call(rt *_runtime, this Value, argumentList ...interface{}) Value {
switch function := value.value.(type) {
case *_object:
if function, ok := value.value.(*_object); ok {
return function.call(this, function.runtime.toValueArray(argumentList...), false, nativeFrame)
}
if rt == nil {
@ -137,8 +133,7 @@ func (value Value) constructSafe(rt *_runtime, this Value, argumentList ...inter
}
func (value Value) construct(rt *_runtime, this Value, argumentList ...interface{}) Value {
switch fn := value.value.(type) {
case *_object:
if fn, ok := value.value.(*_object); ok {
return fn.construct(fn.runtime.toValueArray(argumentList...))
}
if rt == nil {
@ -461,9 +456,8 @@ func (value Value) ToString() (string, error) {
}
func (value Value) _object() *_object {
switch value := value.value.(type) {
case *_object:
return value
if v, ok := value.value.(*_object); ok {
return v
}
return nil
}
@ -472,24 +466,21 @@ func (value Value) _object() *_object {
//
// This method will not do any implicit conversion. For example, calling this method on a string primitive value will not return a String object.
func (value Value) Object() *Object {
switch object := value.value.(type) {
case *_object:
if object, ok := value.value.(*_object); ok {
return _newObject(object, value)
}
return nil
}
func (value Value) reference() _reference {
switch value := value.value.(type) {
case _reference:
if value, ok := value.value.(_reference); ok {
return value
}
return nil
}
func (value Value) resolve() Value {
switch value := value.value.(type) {
case _reference:
if value, ok := value.value.(_reference); ok {
return value.getValue()
}
return value