diff options
author | plesner@google.com <plesner@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 14:08:32 +0000 |
---|---|---|
committer | plesner@google.com <plesner@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-09 14:08:32 +0000 |
commit | 1d9391a37096df5cc7e1221a04c52157dcebadc0 (patch) | |
tree | b235347ff0042ada369bfc5b6578256d190423d0 /webkit/port/bindings | |
parent | 36c5f9daa982de0aad713c1557337b93452a74f1 (diff) | |
download | chromium_src-1d9391a37096df5cc7e1221a04c52157dcebadc0.zip chromium_src-1d9391a37096df5cc7e1221a04c52157dcebadc0.tar.gz chromium_src-1d9391a37096df5cc7e1221a04c52157dcebadc0.tar.bz2 |
Fixed Functions' toString following hotmail fix.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6582 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/port/bindings')
-rw-r--r-- | webkit/port/bindings/v8/v8_proxy.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp index d55fdef..30ebfbd 100644 --- a/webkit/port/bindings/v8/v8_proxy.cpp +++ b/webkit/port/bindings/v8/v8_proxy.cpp @@ -1387,6 +1387,30 @@ v8::Local<v8::Function> V8Proxy::GetConstructor(V8ClassIndex::V8WrapperType t) } +// Get the string 'toString'. +static v8::Persistent<v8::String> GetToStringName() { + static v8::Persistent<v8::String> value; + if (value.IsEmpty()) + value = v8::Persistent<v8::String>::New(v8::String::New("toString")); + return value; +} + + +static v8::Handle<v8::Value> ConstructorToString(const v8::Arguments& args) { + // The DOM constructors' toString functions grab the current toString + // for Functions by taking the toString function of itself and then + // calling it with the constructor as its receiver. This means that + // changes to the Function prototype chain or toString function are + // reflected when printing DOM constructors. The only wart is that + // changes to a DOM constructor's toString's toString will cause the + // toString of the DOM constructor itself to change. This is extremely + // obscure and unlikely to be a problem. + v8::Handle<v8::Value> val = args.Callee()->Get(GetToStringName()); + if (!val->IsFunction()) return v8::String::New(""); + return v8::Handle<v8::Function>::Cast(val)->Call(args.This(), 0, NULL); +} + + v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( V8ClassIndex::V8WrapperType type) { @@ -1398,6 +1422,18 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( // not found FunctionTemplateFactory factory = V8ClassIndex::GetFactory(type); v8::Persistent<v8::FunctionTemplate> desc = factory(); + // DOM constructors are functions and should print themselves as such. + // However, we will later replace their prototypes with Object + // prototypes so we need to explicitly override toString on the + // instance itself. If we later make DOM constructors full objects + // we can give them class names instead and Object.prototype.toString + // will work so we can remove this code. + static v8::Persistent<v8::FunctionTemplate> to_string_template; + if (to_string_template.IsEmpty()) { + to_string_template = v8::Persistent<v8::FunctionTemplate>::New( + v8::FunctionTemplate::New(ConstructorToString)); + } + desc->Set(GetToStringName(), to_string_template); switch (type) { case V8ClassIndex::CSSSTYLEDECLARATION: // The named property handler for style declarations has a |