Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: src/runtime.js

Issue 7623011: Implement function proxies (except for their use as constructors). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed second round of comments. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.cc ('k') | src/string.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.js
diff --git a/src/runtime.js b/src/runtime.js
index 4b600df7360b3431f9a3834937a022e35d1a4648..263384775abe95bd755f255e18e5c745f732ddd9 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -365,7 +365,7 @@ function IN(x) {
// an expensive ToBoolean conversion in the generated code.
function INSTANCE_OF(F) {
var V = this;
- if (!IS_FUNCTION(F)) {
+ if (!IS_SPEC_FUNCTION(F)) {
throw %MakeTypeError('instanceof_function_expected', [V]);
}
@@ -404,22 +404,41 @@ function FILTER_KEY(key) {
function CALL_NON_FUNCTION() {
var delegate = %GetFunctionDelegate(this);
- if (!IS_FUNCTION(delegate)) {
- throw %MakeTypeError('called_non_callable', [typeof this]);
- }
return delegate.apply(this, arguments);
}
function CALL_NON_FUNCTION_AS_CONSTRUCTOR() {
var delegate = %GetConstructorDelegate(this);
- if (!IS_FUNCTION(delegate)) {
- throw %MakeTypeError('called_non_callable', [typeof this]);
- }
return delegate.apply(this, arguments);
}
+function CALL_FUNCTION_PROXY() {
+ var arity = %_ArgumentsLength() - 1;
+ var proxy = %_Arguments(arity); // The proxy comes in as an additional arg.
+ var trap = %GetCallTrap(proxy);
+ return %Apply(trap, this, arguments, 0, arity);
+}
+
+
+function CALL_FUNCTION_PROXY_AS_CONSTRUCTOR(proxy) {
+ var arity = %_ArgumentsLength() - 1;
+ var trap = %GetConstructTrap(proxy);
+ var receiver = void 0;
+ if (!IS_UNDEFINED(trap)) {
+ trap = %GetCallTrap(proxy);
+ var proto = proxy.prototype;
+ if (!IS_SPEC_OBJECT(proto) && proto !== null) {
+ throw MakeTypeError("proto_object_or_null", [proto]);
+ }
+ receiver = new global.Object();
+ receiver.__proto__ = proto;
+ }
+ return %Apply(trap, this, arguments, 1, arity);
+}
+
+
function APPLY_PREPARE(args) {
var length;
// First check whether length is a positive Smi and args is an
@@ -427,7 +446,8 @@ function APPLY_PREPARE(args) {
// that takes care of more eventualities.
if (IS_ARRAY(args)) {
length = args.length;
- if (%_IsSmi(length) && length >= 0 && length < 0x800000 && IS_FUNCTION(this)) {
+ if (%_IsSmi(length) && length >= 0 && length < 0x800000 &&
+ IS_SPEC_FUNCTION(this)) {
return length;
}
}
@@ -441,7 +461,7 @@ function APPLY_PREPARE(args) {
throw %MakeRangeError('stack_overflow', []);
}
- if (!IS_FUNCTION(this)) {
+ if (!IS_SPEC_FUNCTION(this)) {
throw %MakeTypeError('apply_non_function', [ %ToString(this), typeof this ]);
}
@@ -609,13 +629,13 @@ function IsPrimitive(x) {
// ECMA-262, section 8.6.2.6, page 28.
function DefaultNumber(x) {
var valueOf = x.valueOf;
- if (IS_FUNCTION(valueOf)) {
+ if (IS_SPEC_FUNCTION(valueOf)) {
var v = %_CallFunction(x, valueOf);
if (%IsPrimitive(v)) return v;
}
var toString = x.toString;
- if (IS_FUNCTION(toString)) {
+ if (IS_SPEC_FUNCTION(toString)) {
var s = %_CallFunction(x, toString);
if (%IsPrimitive(s)) return s;
}
@@ -627,13 +647,13 @@ function DefaultNumber(x) {
// ECMA-262, section 8.6.2.6, page 28.
function DefaultString(x) {
var toString = x.toString;
- if (IS_FUNCTION(toString)) {
+ if (IS_SPEC_FUNCTION(toString)) {
var s = %_CallFunction(x, toString);
if (%IsPrimitive(s)) return s;
}
var valueOf = x.valueOf;
- if (IS_FUNCTION(valueOf)) {
+ if (IS_SPEC_FUNCTION(valueOf)) {
var v = %_CallFunction(x, valueOf);
if (%IsPrimitive(v)) return v;
}
« no previous file with comments | « src/runtime.cc ('k') | src/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698