forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplification & refactor of (parts of) the runtime
* Proper lowercasing for internal stuff * *Environment => *_stash * ExecutionContext => _scope * Simpler & shallower call/construct mechanics * Remove unnecessary fields & methods * Better scoping (no more stack): []*_scope => _scope.outer * Some speed improvements In preparation for robertkrimen#66
- Loading branch information
1 parent
b7dd9df
commit 9cd045e
Showing
38 changed files
with
1,787 additions
and
1,744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,126 @@ | ||
package otto | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func builtinError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newError("", call.Argument(0))) | ||
} | ||
|
||
func builtinNewError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newError("", valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func builtinError_toString(call FunctionCall) Value { | ||
thisObject := call.thisObject() | ||
if thisObject == nil { | ||
panic(newTypeError()) | ||
} | ||
|
||
name := "Error" | ||
nameValue := thisObject.get("name") | ||
if nameValue.IsDefined() { | ||
name = toString(nameValue) | ||
} | ||
|
||
message := "" | ||
messageValue := thisObject.get("message") | ||
if messageValue.IsDefined() { | ||
message = toString(messageValue) | ||
} | ||
|
||
if len(name) == 0 { | ||
return toValue_string(message) | ||
} | ||
|
||
if len(message) == 0 { | ||
return toValue_string(name) | ||
} | ||
|
||
return toValue_string(fmt.Sprintf("%s: %s", name, message)) | ||
} | ||
|
||
func (runtime *_runtime) newEvalError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.EvalErrorPrototype | ||
self.prototype = runtime.global.EvalErrorPrototype | ||
return self | ||
} | ||
|
||
func builtinEvalError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newEvalError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewEvalError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewEvalError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newEvalError(valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func (runtime *_runtime) newTypeError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.TypeErrorPrototype | ||
self.prototype = runtime.global.TypeErrorPrototype | ||
return self | ||
} | ||
|
||
func builtinTypeError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newTypeError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewTypeError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewTypeError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newTypeError(valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func (runtime *_runtime) newRangeError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.RangeErrorPrototype | ||
self.prototype = runtime.global.RangeErrorPrototype | ||
return self | ||
} | ||
|
||
func builtinRangeError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newRangeError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewRangeError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewRangeError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newRangeError(valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func (runtime *_runtime) newURIError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.URIErrorPrototype | ||
self.prototype = runtime.global.URIErrorPrototype | ||
return self | ||
} | ||
|
||
func (runtime *_runtime) newReferenceError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.ReferenceErrorPrototype | ||
self.prototype = runtime.global.ReferenceErrorPrototype | ||
return self | ||
} | ||
|
||
func builtinReferenceError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newReferenceError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewReferenceError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewReferenceError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newReferenceError(valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func (runtime *_runtime) newSyntaxError(message Value) *_object { | ||
self := runtime.newErrorObject(message) | ||
self.prototype = runtime.Global.SyntaxErrorPrototype | ||
self.prototype = runtime.global.SyntaxErrorPrototype | ||
return self | ||
} | ||
|
||
func builtinSyntaxError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newSyntaxError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewSyntaxError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewSyntaxError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newSyntaxError(valueOfArrayIndex(argumentList, 0))) | ||
} | ||
|
||
func builtinURIError(call FunctionCall) Value { | ||
return toValue_object(call.runtime.newURIError(call.Argument(0))) | ||
} | ||
|
||
func builtinNewURIError(self *_object, _ Value, argumentList []Value) Value { | ||
func builtinNewURIError(self *_object, argumentList []Value) Value { | ||
return toValue_object(self.runtime.newURIError(valueOfArrayIndex(argumentList, 0))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.