Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / scripts / code_generator_v8.pm
index 910824d..239b85a 100644 (file)
@@ -8,7 +8,7 @@
 # Copyright (C) Research In Motion Limited 2010. All rights reserved.
 # Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
 # Copyright (C) 2012 Ericsson AB. All rights reserved.
-# Copyright (C) 2013 Samsung Electronics. All rights reserved.
+# Copyright (C) 2013, 2014 Samsung Electronics. All rights reserved.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
@@ -216,7 +216,6 @@ my %domNodeTypes = ("Attr" => 1,
                     "Notation" => 1,
                     "ProcessingInstruction" => 1,
                     "ShadowRoot" => 1,
-                    "SVGDocument" => 1,
                     "Text" => 1,
                     "TestNode" => 1,
                     "TestInterfaceDocument" => 1,
@@ -244,13 +243,14 @@ my %svgTypeNewPropertyImplementation = (
     "SVGPointList" => 1,
     "SVGPreserveAspectRatio" => 1,
     "SVGRect" => 1,
+    "SVGString" => 1,
+    "SVGStringList" => 1,
 );
 
 my %svgTypeNeedingTearOff = (
     "SVGAngle" => "SVGPropertyTearOff<SVGAngle>",
     "SVGMatrix" => "SVGMatrixTearOff",
     "SVGPathSegList" => "SVGPathSegListPropertyTearOff",
-    "SVGStringList" => "SVGStaticListPropertyTearOff<SVGStringList>",
     "SVGTransform" => "SVGPropertyTearOff<SVGTransform>",
     "SVGTransformList" => "SVGTransformListPropertyTearOff"
 );
@@ -412,7 +412,8 @@ sub GenerateInterface
     # FIXME: newlines should be generated by Block::toString().
     my $nameSpaceWebCoreBegin = "namespace WebCore {\n";
     my $nameSpaceWebCoreEnd = "} // namespace WebCore";
-    $nameSpaceWebCoreBegin = "$nameSpaceWebCoreBegin\n" if !$interface->isCallback;
+    $nameSpaceWebCoreBegin = "$nameSpaceWebCoreBegin\n" unless $interface->isCallback;
+    $nameSpaceWebCoreBegin = "\n$nameSpaceWebCoreBegin" if $interface->isCallback;
     $implementation{nameSpaceWebCore} = new Block("Namespace WebCore", $nameSpaceWebCoreBegin, $nameSpaceWebCoreEnd);
     $implementation{nameSpaceInternal} = new Block("Internal namespace", "namespace $internalNamespace {\n", "} // namespace $internalNamespace\n");
 
@@ -461,22 +462,35 @@ sub AddIncludesForType
 
     $type = $1 if $type =~ /SVG\w+TearOff<(\w+)>/;
 
-    # Default includes
-    if ($type eq "SerializedScriptValue") {
-        AddToImplIncludes("bindings/v8/SerializedScriptValue.h");
-    } elsif ($type eq "any" || IsCallbackFunctionType($type)) {
+    # Handle non-wrapper types explicitly
+    if ($type eq "any" || IsCallbackFunctionType($type)) {
         AddToImplIncludes("bindings/v8/ScriptValue.h");
-    } elsif ($type eq "Promise") {
-        AddToImplIncludes("bindings/v8/ScriptPromise.h");
+    } elsif ($type eq "CompareHow") {
+    } elsif ($type eq "Dictionary") {
+        AddToImplIncludes("bindings/v8/Dictionary.h");
     } elsif ($type eq "EventHandler") {
         AddToImplIncludes("bindings/v8/V8AbstractEventListener.h");
         AddToImplIncludes("bindings/v8/V8EventListenerList.h");
-    } elsif ($type eq "Dictionary") {
-        AddToImplIncludes("bindings/v8/Dictionary.h");
+    } elsif ($type eq "EventListener") {
+        AddToImplIncludes("bindings/v8/BindingSecurity.h");
+        AddToImplIncludes("bindings/v8/V8EventListenerList.h");
+        AddToImplIncludes("core/frame/DOMWindow.h");
+    } elsif ($type eq "MediaQueryListListener") {
+        AddToImplIncludes("core/css/MediaQueryListListener.h");
+    } elsif ($type eq "Promise") {
+        AddToImplIncludes("bindings/v8/ScriptPromise.h");
+    } elsif ($type eq "SerializedScriptValue") {
+        AddToImplIncludes("bindings/v8/SerializedScriptValue.h");
     } elsif (IsTypedArrayType($type)) {
         AddToImplIncludes("bindings/v8/custom/V8${type}Custom.h");
     } elsif (my $arrayType = GetArrayType($type)) {
         AddIncludesForType($arrayType);
+    } elsif (my $sequenceType = GetSequenceType($type)) {
+        AddIncludesForType($sequenceType);
+    } elsif (IsUnionType($type)) {
+        for my $unionMemberType (@{$type->unionMemberTypes}) {
+            AddIncludesForType($unionMemberType);
+        }
     } else {
         AddToImplIncludes("V8${type}.h");
     }
@@ -711,6 +725,7 @@ sub GenerateHeader
     AddToHeaderIncludes("bindings/v8/WrapperTypeInfo.h");
     AddToHeaderIncludes("bindings/v8/V8Binding.h");
     AddToHeaderIncludes("bindings/v8/V8DOMWrapper.h");
+    AddToHeaderIncludes("heap/Handle.h");
     AddToHeaderIncludes(HeaderFilesForInterface($interfaceName, $implClassName));
     foreach my $headerInclude (sort keys(%headerIncludes)) {
         $header{includes}->add("#include \"${headerInclude}\"\n");
@@ -749,10 +764,11 @@ END
     {
         return fromInternalPointer(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex));
     }
-    static void derefObject(void*);
     static const WrapperTypeInfo wrapperTypeInfo;
 END
 
+    $header{classPublic}->add("    static void derefObject(void*);\n");
+
     if (NeedsVisitDOMWrapper($interface)) {
         $header{classPublic}->add("    static void visitDOMWrapper(void*, const v8::Persistent<v8::Object>&, v8::Isolate*);\n");
     }
@@ -767,7 +783,7 @@ END
 
     if ($interfaceName eq "Window") {
         $header{classPublic}->add(<<END);
-    static v8::Handle<v8::ObjectTemplate> GetShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
+    static v8::Handle<v8::ObjectTemplate> getShadowObjectTemplate(v8::Isolate*, WrapperWorldType);
 END
     }
 
@@ -900,11 +916,11 @@ END
     $header{classPublic}->add("\n");  # blank line to separate classPrivate
 
     my $customToV8 = ExtendedAttributeContains($interface->extendedAttributes->{"Custom"}, "ToV8");
+    my $passRefPtrType = GetPassRefPtrType($interface);
     if (!$customToV8) {
-        my $createWrapperArgumentType = GetPassRefPtrType($nativeType);
         $header{classPrivate}->add(<<END);
     friend v8::Handle<v8::Object> wrap(${nativeType}*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
-    static v8::Handle<v8::Object> createWrapper(${createWrapperArgumentType}, v8::Handle<v8::Object> creationContext, v8::Isolate*);
+    static v8::Handle<v8::Object> createWrapper(${passRefPtrType}, v8::Handle<v8::Object> creationContext, v8::Isolate*);
 END
     }
 
@@ -1015,25 +1031,25 @@ END
 
     $header{nameSpaceWebCore}->add(<<END);
 
-inline v8::Handle<v8::Value> toV8(PassRefPtr<${nativeType} > impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+inline v8::Handle<v8::Value> toV8($passRefPtrType impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     return toV8(impl.get(), creationContext, isolate);
 }
 
 template<class CallbackInfo>
-inline void v8SetReturnValue(const CallbackInfo& callbackInfo, PassRefPtr<${nativeType} > impl)
+inline void v8SetReturnValue(const CallbackInfo& callbackInfo, $passRefPtrType impl)
 {
     v8SetReturnValue(callbackInfo, impl.get());
 }
 
 template<class CallbackInfo>
-inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, PassRefPtr<${nativeType} > impl)
+inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, $passRefPtrType impl)
 {
     v8SetReturnValueForMainWorld(callbackInfo, impl.get());
 }
 
 template<class CallbackInfo, class Wrappable>
-inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<${nativeType} > impl, Wrappable* wrappable)
+inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, $passRefPtrType impl, Wrappable* wrappable)
 {
     v8SetReturnValueFast(callbackInfo, impl.get(), wrappable);
 }
@@ -1041,7 +1057,7 @@ inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<${
 END
 
     if ($interface->extendedAttributes->{"EventConstructor"}) {
-        $header{nameSpaceWebCore}->add("bool initialize${implClassName}(${implClassName}Init&, const Dictionary&, ExceptionState&, const String& = \"\");\n\n");
+        $header{nameSpaceWebCore}->add("bool initialize${implClassName}(${implClassName}Init&, const Dictionary&, ExceptionState&, const v8::FunctionCallbackInfo<v8::Value>& info, const String& = \"\");\n\n");
     }
 }
 
@@ -1055,6 +1071,13 @@ sub GetInternalFields
         InheritsInterface($interface, "EventTarget")) {
         push(@customInternalFields, "eventListenerCacheIndex");
     }
+    # Persistent handle is stored in the last internal field.
+    # FIXME: Remove this internal field. Since we need either of a persistent handle
+    # (if the object is in oilpan) or a C++ pointer to the DOM object (if the object is not in oilpan),
+    # we can share the internal field between the two cases.
+    if (IsWillBeGarbageCollectedType($interface->name)) {
+        push(@customInternalFields, "persistentHandleIndex");
+    }
     return @customInternalFields;
 }
 
@@ -1088,7 +1111,7 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
     my $hasCustomIndexedDeleters = $indexedDeleterFunction && $indexedDeleterFunction->extendedAttributes->{"Custom"};
 
     my $namedGetterFunction = GetNamedGetterFunction($interface);
-    my $hasCustomNamedGetter = $namedGetterFunction && $namedGetterFunction->extendedAttributes->{"Custom"};
+    my $hasCustomNamedGetter = $namedGetterFunction && HasCustomPropertyGetter($namedGetterFunction->extendedAttributes);
 
     my $namedSetterFunction = GetNamedSetterFunction($interface);
     my $hasCustomNamedSetter = $namedSetterFunction && $namedSetterFunction->extendedAttributes->{"Custom"};
@@ -1097,7 +1120,8 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
     my $hasCustomNamedDeleter = $namedDeleterFunction && $namedDeleterFunction->extendedAttributes->{"Custom"};
 
     my $namedEnumeratorFunction = $namedGetterFunction && !$namedGetterFunction->extendedAttributes->{"NotEnumerable"};
-    my $hasCustomNamedEnumerator = $namedGetterFunction && $namedGetterFunction->extendedAttributes->{"CustomEnumerateProperty"};
+    my $hasCustomNamedEnumerator = $namedEnumeratorFunction && ExtendedAttributeContains($namedGetterFunction->extendedAttributes->{"Custom"}, "PropertyEnumerator");
+    my $hasCustomNamedQuery = $namedEnumeratorFunction && ExtendedAttributeContains($namedGetterFunction->extendedAttributes->{"Custom"}, "PropertyQuery");
 
     if ($hasCustomIndexedGetter) {
         $header{classPublic}->add("    static void indexedPropertyGetterCustom(uint32_t, const v8::PropertyCallbackInfo<v8::Value>&);\n");
@@ -1119,13 +1143,16 @@ sub GenerateHeaderNamedAndIndexedPropertyAccessors
         $header{classPublic}->add("    static void namedPropertySetterCustom(v8::Local<v8::String>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<v8::Value>&);\n");
     }
 
+    if ($hasCustomNamedQuery) {
+        $header{classPublic}->add("    static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&);\n");
+    }
+
     if ($hasCustomNamedDeleter) {
         $header{classPublic}->add("    static void namedPropertyDeleterCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Boolean>&);\n");
     }
 
     if ($hasCustomNamedEnumerator) {
         $header{classPublic}->add("    static void namedPropertyEnumeratorCustom(const v8::PropertyCallbackInfo<v8::Array>&);\n");
-        $header{classPublic}->add("    static void namedPropertyQueryCustom(v8::Local<v8::String>, const v8::PropertyCallbackInfo<v8::Integer>&);\n");
     }
 }
 
@@ -1192,6 +1219,13 @@ sub HasCustomMethod
     return $attrExt->{"Custom"};
 }
 
+sub HasCustomPropertyGetter
+{
+    my $attrExt = shift;
+    my $custom = $attrExt->{"Custom"};
+    return $custom && ($custom eq "VALUE_IS_MISSING" || ExtendedAttributeContains($custom, "PropertyGetter"));
+}
+
 sub IsReadonly
 {
     my $attribute = shift;
@@ -1256,7 +1290,7 @@ static void ${funcName}OriginSafeMethodGetter${forMainWorldSuffix}(const v8::Pro
         return;
     }
     ${implClassName}* imp = ${v8ClassName}::toNative(holder);
-    if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError)) {
+    if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), DoNotReportSecurityError)) {
         static int sharedTemplateUniqueKey;
         v8::Handle<v8::FunctionTemplate> sharedTemplate = data->privateTemplate(currentWorldType, &sharedTemplateUniqueKey, $newTemplateParams, $functionLength);
         v8SetReturnValue(info, sharedTemplate->GetFunction());
@@ -1302,7 +1336,7 @@ static void ${implClassName}OriginSafeMethodSetter(v8::Local<v8::String> name, v
     ${implClassName}* imp = ${v8ClassName}::toNative(holder);
     v8::String::Utf8Value attributeName(name);
     ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "${interfaceName}", info.Holder(), info.GetIsolate());
-    if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)) {
+    if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), exceptionState)) {
         exceptionState.throwIfNeeded();
         return;
     }
@@ -1345,7 +1379,7 @@ sub GenerateFeatureObservation
 
     if ($measureAs) {
         AddToImplIncludes("core/frame/UseCounter.h");
-        return "    UseCounter::count(activeExecutionContext(), UseCounter::${measureAs});\n";
+        return "    UseCounter::count(activeExecutionContext(info.GetIsolate()), UseCounter::${measureAs});\n";
     }
 
     return "";
@@ -1356,7 +1390,7 @@ sub GenerateDeprecationNotification
     my $deprecateAs = shift;
     if ($deprecateAs) {
         AddToImplIncludes("core/frame/UseCounter.h");
-        return "    UseCounter::countDeprecation(activeExecutionContext(), UseCounter::${deprecateAs});\n";
+        return "    UseCounter::countDeprecation(activeExecutionContext(info.GetIsolate()), UseCounter::${deprecateAs});\n";
     }
     return "";
 }
@@ -1565,7 +1599,7 @@ END
     # Generate security checks if necessary
     if ($attribute->extendedAttributes->{"CheckSecurity"}) {
         AddToImplIncludes("bindings/v8/BindingSecurity.h");
-        $code .= "    if (!BindingSecurity::shouldAllowAccessToNode(imp->" . GetImplName($attribute) . "(), exceptionState)) {\n";
+        $code .= "    if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), imp->" . GetImplName($attribute) . "(), exceptionState)) {\n";
         $code .= "        v8SetReturnValueNull(info);\n";
         $code .= "        exceptionState.throwIfNeeded();\n";
         $code .= "        return;\n";
@@ -1748,7 +1782,6 @@ END
         } else {
             $functionName = "imp->${functionName}";
         }
-        push(@arguments, "isolatedWorldForIsolate(info.GetIsolate())");
         $code .= "    EventListener* jsValue = ${functionName}(" . join(", ", @arguments) . ");\n";
         $code .= "    v8SetReturnValue(info, jsValue ? v8::Handle<v8::Value>(V8AbstractEventListener::cast(jsValue)->getListenerObject(imp->executionContext())) : v8::Handle<v8::Value>(v8::Null(info.GetIsolate())));\n";
     } else {
@@ -1831,7 +1864,7 @@ END
     ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());
     v8::String::Utf8Value attributeName(name);
     ExceptionState exceptionState(ExceptionState::SetterContext, *attributeName, "${interfaceName}", info.Holder(), info.GetIsolate());
-    if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)) {
+    if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), exceptionState)) {
         exceptionState.throwIfNeeded();
         return;
     }
@@ -2100,8 +2133,7 @@ END
             } else {
                 $attrImplName = "imp->${attrImplName}";
             }
-            push(@arguments, "isolatedWorldForIsolate(info.GetIsolate())");
-            $code .= "    transferHiddenDependency(info.Holder(), ${attrImplName}(" . join(", ", @arguments) . "), jsValue, ${v8ClassName}::eventListenerCacheIndex, info.GetIsolate());\n";
+            $code .= "    moveEventListenerToNewWrapper(info.Holder(), ${attrImplName}(" . join(", ", @arguments) . "), jsValue, ${v8ClassName}::eventListenerCacheIndex, info.GetIsolate());\n";
         }
         my ($functionName, @arguments) = SetterExpression($interfaceName, $attribute);
         if ($implementedBy) {
@@ -2116,7 +2148,6 @@ END
         } else {
             push(@arguments, "V8EventListenerList::getEventListener(jsValue, true, ListenerFindOrCreate)");
         }
-        push(@arguments, "isolatedWorldForIsolate(info.GetIsolate())");
         $code .= "    ${functionName}(" . join(", ", @arguments) . ");\n";
     } else {
         my ($functionName, @arguments) = SetterExpression($interfaceName, $attribute);
@@ -2169,6 +2200,24 @@ END
     $implementation{nameSpaceInternal}->add($code);
 }
 
+sub NullOrOptionalCheck
+{
+    my $parameter = shift;
+    my $value = shift;
+
+    # If undefined is passed for an optional argument, the argument should be
+    # treated as missing; otherwise undefined is not allowed.
+    if ($parameter->isNullable) {
+        if ($parameter->isOptional) {
+            return "isUndefinedOrNull($value)";
+        }
+        return "${value}->IsNull()";
+    }
+    if ($parameter->isOptional) {
+        return "${value}->IsUndefined()";
+    }
+}
+
 sub GenerateParametersCheckExpression
 {
     my $numParameters = shift;
@@ -2182,6 +2231,8 @@ sub GenerateParametersCheckExpression
         my $value = "info[$parameterIndex]";
         my $type = $parameter->type;
 
+        my $undefinedOrNullCheck = NullOrOptionalCheck($parameter, $value);
+
         # Only DOMString, wrapper types, and (to some degree) non-wrapper types
         # are checked.
         #
@@ -2220,8 +2271,8 @@ sub GenerateParametersCheckExpression
             }
         } elsif ($nonWrapperTypes{$type}) {
             # Non-wrapper types are just objects: we don't distinguish type
-            if ($parameter->isNullable) {
-                push(@andExpression, "${value}->IsNull() || ${value}->IsObject()");
+            if ($undefinedOrNullCheck) {
+                push(@andExpression, "$undefinedOrNullCheck || ${value}->IsObject()");
             } else {
                 push(@andExpression, "${value}->IsObject()");
             }
@@ -2300,9 +2351,6 @@ sub GenerateOverloadedFunction
 static void ${name}Method${forMainWorldSuffix}(const v8::FunctionCallbackInfo<v8::Value>& info)
 {
 END
-    $code .= GenerateFeatureObservation($function->extendedAttributes->{"MeasureAs"});
-    $code .= GenerateDeprecationNotification($function->extendedAttributes->{"DeprecateAs"});
-
     foreach my $overload (@{$function->{overloads}}) {
         my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersCheck($overload);
         $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams);
@@ -2386,6 +2434,14 @@ sub GenerateFunction
     my $implName = GetImplName($function);
     my $funcExt = $function->extendedAttributes;
 
+    # Add includes for types even if custom
+    my $returnType = $function->type;
+    AddIncludesForType($returnType);
+    foreach my $parameter (@{$function->parameters}) {
+        my $paramType = $parameter->type;
+        AddIncludesForType($paramType);
+    }
+
     if (HasCustomMethod($funcExt) || $name eq "") {
         return;
     }
@@ -2409,6 +2465,7 @@ sub GenerateFunction
     #   - takes a parameter that might raise an exception on conversion.
     #
     my $isEventListener = $name eq "addEventListener" || $name eq "removeEventListener";
+    my $isEventDispatcher = $name eq "dispatchEvent";
     my $isSecurityCheckNecessary = $interface->extendedAttributes->{"CheckSecurity"} && !$function->extendedAttributes->{"DoNotCheckSecurity"};
     my $raisesExceptions = $function->extendedAttributes->{"RaisesException"};
     my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($interfaceName);
@@ -2419,30 +2476,34 @@ sub GenerateFunction
         $code .= "    ExceptionState exceptionState(ExceptionState::ExecutionContext, \"${unoverloadedName}\", \"${interfaceName}\", info.Holder(), info.GetIsolate());\n";
     }
 
-    if ($isEventListener) {
-        my $lookupType = ($name eq "addEventListener") ? "OrCreate" : "Only";
-        my $passRefPtrHandling = ($name eq "addEventListener") ? "" : ".get()";
-        my $hiddenDependencyAction = ($name eq "addEventListener") ? "create" : "remove";
-
+    if ($isEventListener || $isEventDispatcher) {
         AddToImplIncludes("bindings/v8/BindingSecurity.h");
         AddToImplIncludes("bindings/v8/V8EventListenerList.h");
         AddToImplIncludes("core/frame/DOMWindow.h");
         $code .= <<END;
     EventTarget* impl = ${v8ClassName}::toNative(info.Holder());
     if (DOMWindow* window = impl->toDOMWindow()) {
-        if (!BindingSecurity::shouldAllowAccessToFrame(window->frame(), exceptionState)) {
+        if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), window->frame(), exceptionState)) {
             exceptionState.throwIfNeeded();
             return;
         }
         if (!window->document())
             return;
     }
+END
+    }
+    if ($isEventListener) {
+        my $lookupType = ($name eq "addEventListener") ? "OrCreate" : "Only";
+        my $passRefPtrHandling = ($name eq "addEventListener") ? "" : ".get()";
+        my $hiddenValueAction = ($name eq "addEventListener") ? "addHiddenValueToArray" : "removeHiddenValueFromArray";
+
+        $code .= <<END;
     RefPtr<EventListener> listener = V8EventListenerList::getEventListener(info[1], false, ListenerFind${lookupType});
     if (listener) {
         V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<WithNullCheck>, eventName, info[0]);
         impl->${implName}(eventName, listener${passRefPtrHandling}, info[2]->BooleanValue());
         if (!impl->toNode())
-            ${hiddenDependencyAction}HiddenDependency(info.Holder(), info[1], ${v8ClassName}::eventListenerCacheIndex, info.GetIsolate());
+            ${hiddenValueAction}(info.Holder(), info[1], ${v8ClassName}::eventListenerCacheIndex, info.GetIsolate());
     }
 }
 END
@@ -2483,7 +2544,7 @@ END
         # We have not find real use cases yet.
         AddToImplIncludes("bindings/v8/BindingSecurity.h");
         $code .= <<END;
-    if (!BindingSecurity::shouldAllowAccessToFrame(imp->frame(), exceptionState)) {
+    if (!BindingSecurity::shouldAllowAccessToFrame(info.GetIsolate(), imp->frame(), exceptionState)) {
         exceptionState.throwIfNeeded();
         return;
     }
@@ -2492,7 +2553,7 @@ END
 
     if ($function->extendedAttributes->{"CheckSecurity"}) {
         AddToImplIncludes("bindings/v8/BindingSecurity.h");
-        $code .= "    if (!BindingSecurity::shouldAllowAccessToNode(imp->" . GetImplName($function) . "(exceptionState), exceptionState)) {\n";
+        $code .= "    if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), imp->" . GetImplName($function) . "(exceptionState), exceptionState)) {\n";
         $code .= "        v8SetReturnValueNull(info);\n";
         $code .= "        exceptionState.throwIfNeeded();\n";
         $code .= "        return;\n";
@@ -2530,7 +2591,7 @@ sub GenerateCallWith
         AddToImplIncludes("bindings/v8/ScriptState.h");
     }
     if (ExtendedAttributeContains($callWith, "ExecutionContext")) {
-        $code .= $indent . "ExecutionContext* scriptContext = getExecutionContext();\n";
+        $code .= $indent . "ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate());\n";
         push(@callWithArgs, "scriptContext");
     }
     if ($function and ExtendedAttributeContains($callWith, "ScriptArguments")) {
@@ -2540,10 +2601,10 @@ sub GenerateCallWith
         AddToImplIncludes("core/inspector/ScriptArguments.h");
     }
     if (ExtendedAttributeContains($callWith, "ActiveWindow")) {
-        push(@callWithArgs, "activeDOMWindow()");
+        push(@callWithArgs, "activeDOMWindow(info.GetIsolate())");
     }
     if (ExtendedAttributeContains($callWith, "FirstWindow")) {
-        push(@callWithArgs, "firstDOMWindow()");
+        push(@callWithArgs, "firstDOMWindow(info.GetIsolate())");
     }
     return ([@callWithArgs], $code);
 }
@@ -2635,7 +2696,7 @@ END
                 }
                 $parameterCheckString .= "            return;\n";
                 $parameterCheckString .= "        }\n";
-                $parameterCheckString .= "        $parameterName = ${v8ClassName}::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), getExecutionContext());\n";
+                $parameterCheckString .= "        $parameterName = ${v8ClassName}::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), currentExecutionContext(info.GetIsolate()));\n";
                 $parameterCheckString .= "    }\n";
             } else {
                 $parameterCheckString .= "    if (info.Length() <= $paramIndex || ";
@@ -2655,7 +2716,7 @@ END
                 $parameterCheckString .= "    }\n";
                 $parameterCheckString .= "    OwnPtr<" . $parameter->type . "> $parameterName = ";
                 $parameterCheckString .= "info[$paramIndex]->IsNull() ? nullptr : " if $parameter->isNullable;
-                $parameterCheckString .= "${v8ClassName}::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), getExecutionContext());\n";
+                $parameterCheckString .= "${v8ClassName}::create(v8::Handle<v8::Function>::Cast(info[$paramIndex]), currentExecutionContext(info.GetIsolate()));\n";
             }
         } elsif ($parameter->extendedAttributes->{"Clamp"}) {
                 my $nativeValue = "${parameterName}NativeValue";
@@ -2723,18 +2784,25 @@ END
                 $parameterCheckString .= "    }\n";
             }
         } else {
-            # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an
-            # interface type, then if the incoming value does not implement that interface, a TypeError
-            # is thrown rather than silently passing NULL to the C++ code.
-            # Per the Web IDL and ECMAScript specifications, incoming values can always be converted
-            # to both strings and numbers, so do not throw TypeError if the argument is of these
-            # types.
+            # If the [StrictTypeChecking] extended attribute is present, type
+            # check interface type arguments for correct type and nullability.
+            #
+            # If the argument is passed, and is not |undefined| or |null|, then
+            # it must implement the interface type, otherwise throw a TypeError
+            # If the parameter is nullable, then both |undefined| and |null|
+            # pass a NULL pointer to the C++ code, otherwise these also throw.
+            # Without [StrictTypeChecking], in all these cases NULL is silently
+            # passed to the C++ code.
+            #
+            # Per the Web IDL and ECMAScript specifications, incoming values
+            # can always be converted to primitive types and strings (including
+            # |undefined| and |null|), so do not throw TypeError for these.
             if ($function->extendedAttributes->{"StrictTypeChecking"} || $interface->extendedAttributes->{"StrictTypeChecking"}) {
                 my $argValue = "info[$paramIndex]";
                 my $argType = $parameter->type;
                 if (IsWrapperType($argType)) {
-                    my $undefinedNullCheck = $parameter->isNullable ? "isUndefinedOrNull($argValue)" : "${argValue}->IsUndefined()";
-                    $parameterCheckString .= "    if (info.Length() > $paramIndex && !$undefinedNullCheck && !V8${argType}::hasInstance($argValue, info.GetIsolate())) {\n";
+                    my $undefinedNullCheck = $parameter->isNullable ? " !isUndefinedOrNull($argValue) &&" : "";
+                    $parameterCheckString .= "    if (info.Length() > $paramIndex &&$undefinedNullCheck !V8${argType}::hasInstance($argValue, info.GetIsolate())) {\n";
                     if ($hasExceptionState) {
                         $parameterCheckString .= "        exceptionState.throwTypeError(\"parameter $humanFriendlyIndex is not of type \'$argType\'.\");\n";
                         $parameterCheckString .= "        exceptionState.throwIfNeeded();\n";
@@ -2848,11 +2916,11 @@ END
     if ($interface->extendedAttributes->{"ConstructorCallWith"}) {
         if (ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "ExecutionContext")) {
             push(@beforeArgumentList, "context");
-            $code .= "    ExecutionContext* context = getExecutionContext();\n";
+            $code .= "    ExecutionContext* context = currentExecutionContext(info.GetIsolate());\n";
         }
         if (ExtendedAttributeContains($interface->extendedAttributes->{"ConstructorCallWith"}, "Document")) {
             push(@beforeArgumentList, "document");
-            $code .= "    Document& document = *toDocument(getExecutionContext());\n";
+            $code .= "    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));\n";
         }
     }
 
@@ -2873,7 +2941,8 @@ END
     }
 
     my $argumentString = join(", ", @beforeArgumentList, @argumentList, @afterArgumentList);
-    $code .= "    RefPtr<${implClassName}> impl = ${implClassName}::create(${argumentString});\n";
+    my $refPtrType = IsWillBeGarbageCollectedType($interfaceName) ? "RefPtrWillBeRawPtr<$implClassName>" : "RefPtr<$implClassName>";
+    $code .= "    $refPtrType impl = ${implClassName}::create(${argumentString});\n";
     $code .= "    v8::Handle<v8::Object> wrapper = info.Holder();\n";
 
     if ($constructorRaisesException) {
@@ -2990,7 +3059,7 @@ END
     ${implClassName}Init eventInit;
     if (info.Length() >= 2) {
         V8TRYCATCH_VOID(Dictionary, options, Dictionary(info[1], info.GetIsolate()));
-        if (!initialize${implClassName}(eventInit, options, exceptionState)) {
+        if (!initialize${implClassName}(eventInit, options, exceptionState, info)) {
             exceptionState.throwIfNeeded();
             return;
         }
@@ -3040,7 +3109,7 @@ END
         #    and thus passing it around would cause leakage.
         # 2) Errors cannot be cloned (or serialized):
         # http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#safe-passing-of-structured-data
-        $implementation{nameSpaceInternal}->add("    if (isolatedWorldForIsolate(info.GetIsolate())) {\n");
+        $implementation{nameSpaceInternal}->add("    if (DOMWrapperWorld::current(info.GetIsolate())->isIsolatedWorld()) {\n");
         foreach my $attrName (@anyAttributeNames) {
             my $setter = "setSerialized" . FirstLetterToUpperCase($attrName);
             $implementation{nameSpaceInternal}->add(<<END);
@@ -3061,7 +3130,7 @@ END
 
     my $code = "";
     $code .= <<END;
-bool initialize${implClassName}(${implClassName}Init& eventInit, const Dictionary& options, ExceptionState& exceptionState, const String& forEventName)
+bool initialize${implClassName}(${implClassName}Init& eventInit, const Dictionary& options, ExceptionState& exceptionState, const v8::FunctionCallbackInfo<v8::Value>& info, const String& forEventName)
 {
     Dictionary::ConversionContext conversionContext(forEventName.isEmpty() ? String("${interfaceName}") : forEventName, "", exceptionState);
 END
@@ -3069,7 +3138,7 @@ END
     if ($interface->parent) {
         my $interfaceBase = $interface->parent;
         $code .= <<END;
-    if (!initialize${interfaceBase}(eventInit, options, exceptionState, forEventName.isEmpty() ? String("${interfaceName}") : forEventName))
+    if (!initialize${interfaceBase}(eventInit, options, exceptionState, info, forEventName.isEmpty() ? String("${interfaceName}") : forEventName))
         return false;
 
 END
@@ -3124,18 +3193,12 @@ sub GenerateNamedConstructor
     my @beforeArgumentList;
     my @afterArgumentList;
 
-    my $toActiveDOMObject = "0";
-    if (InheritsExtendedAttribute($interface, "ActiveDOMObject")) {
-        $toActiveDOMObject = "${v8ClassName}::toActiveDOMObject";
-    }
-
-    my $toEventTarget = "0";
-    if (InheritsInterface($interface, "EventTarget")) {
-        $toEventTarget = "${v8ClassName}::toEventTarget";
-    }
+    my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObject") ? "${v8ClassName}::toActiveDOMObject" : "0";
+    my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8ClassName}::toEventTarget" : "0";
+    my $derefObject = "${v8ClassName}::derefObject";
 
     $implementation{nameSpaceWebCore}->add(<<END);
-const WrapperTypeInfo ${v8ClassName}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, ${v8ClassName}Constructor::domTemplate, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, 0, ${v8ClassName}::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype };
+const WrapperTypeInfo ${v8ClassName}Constructor::wrapperTypeInfo = { gin::kEmbedderBlink, ${v8ClassName}Constructor::domTemplate, $derefObject, $toActiveDOMObject, $toEventTarget, 0, ${v8ClassName}::installPerContextEnabledMethods, 0, WrapperTypeObjectPrototype, false };
 
 END
 
@@ -3148,7 +3211,7 @@ END
     $code .= $maybeDeprecateFeature if $maybeDeprecateFeature;
     $code .= GenerateConstructorHeader($function->extendedAttributes->{"NamedConstructor"});
     $code .= <<END;
-    Document* document = currentDocument();
+    Document* document = currentDocument(info.GetIsolate());
     ASSERT(document);
 
     // Make sure the document is added to the DOM Node map. Otherwise, the ${implClassName} instance
@@ -3531,10 +3594,8 @@ sub GenerateIsNullExpression
         my $types = $type->unionMemberTypes;
         my @expression = ();
         for my $i (0 .. scalar(@$types)-1) {
-            my $unionMemberType = $types->[$i];
-            my $unionMemberVariable = $variableName . $i;
-            my $isNull = GenerateIsNullExpression($unionMemberType, $unionMemberVariable);
-            push @expression, $isNull;
+            my $unionMemberEnabledVariable = $variableName . $i . "Enabled";
+            push @expression, "!${unionMemberEnabledVariable}";
         }
         return join " && ", @expression;
     }
@@ -3583,6 +3644,9 @@ sub GenerateImplementationIndexedPropertyAccessors
 
     my $indexedGetterFunction = GetIndexedGetterFunction($interface);
     if ($indexedGetterFunction) {
+        # includes for return type even if custom
+        my $returnType = $indexedGetterFunction->type;
+        AddIncludesForType($returnType);
         my $hasCustomIndexedGetter = $indexedGetterFunction->extendedAttributes->{"Custom"};
         if (!$hasCustomIndexedGetter) {
             GenerateImplementationIndexedPropertyGetter($interface, $indexedGetterFunction);
@@ -3592,6 +3656,7 @@ sub GenerateImplementationIndexedPropertyAccessors
 
     my $indexedSetterFunction = GetIndexedSetterFunction($interface);
     if ($indexedSetterFunction) {
+        AddIncludesForType($indexedSetterFunction->parameters->[1]->type);  # includes for argument type even if custom
         my $hasCustomIndexedSetter = $indexedSetterFunction->extendedAttributes->{"Custom"};
         if (!$hasCustomIndexedSetter) {
             GenerateImplementationIndexedPropertySetter($interface, $indexedSetterFunction);
@@ -3644,19 +3709,19 @@ sub GenerateImplementationIndexedPropertyGetter
     my $indexedGetterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($indexedGetterFunction);
+    my $methodName = GetImplName($indexedGetterFunction) || "anonymousIndexedGetter";
 
     my $returnType = $indexedGetterFunction->type;
     my $nativeType = GetNativeType($returnType);
-    my $nativeValue = "element";
+    my $nativeValue = "result";
     $nativeValue .= ".release()" if (IsRefPtrType($returnType));
-    my $isNull = GenerateIsNullExpression($returnType, "element");
-    my $returnJSValueCode = NativeToJSValue($indexedGetterFunction->type, $indexedGetterFunction->extendedAttributes, $nativeValue, "    ", "", "info.GetIsolate()", "info", "collection", "", "return");
+    my $isNull = GenerateIsNullExpression($returnType, "result");
+    my $returnJSValueCode = NativeToJSValue($indexedGetterFunction->type, $indexedGetterFunction->extendedAttributes, $nativeValue, "    ", "", "info.GetIsolate()", "info", "imp", "", "return");
     my $raisesExceptions = $indexedGetterFunction->extendedAttributes->{"RaisesException"};
-    my $methodCallCode = GenerateMethodCall($returnType, "element", "collection->${methodName}", "index", $raisesExceptions);
+    my $methodCallCode = GenerateMethodCall($returnType, "result", "imp->${methodName}", "index", $raisesExceptions);
     my $getterCode = "static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo<v8::Value>& info)\n";
     $getterCode .= "{\n";
-    $getterCode .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
+    $getterCode .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
     if ($raisesExceptions) {
         $getterCode .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
     }
@@ -3743,7 +3808,7 @@ sub GenerateImplementationIndexedPropertySetter
     my $indexedSetterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($indexedSetterFunction);
+    my $methodName = GetImplName($indexedSetterFunction) || "anonymousIndexedSetter";
     my $interfaceName = $interface->name;
 
     my $type = $indexedSetterFunction->parameters->[1]->type;
@@ -3754,6 +3819,10 @@ sub GenerateImplementationIndexedPropertySetter
     my $code = "static void indexedPropertySetter(uint32_t index, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)\n";
     $code .= "{\n";
 
+    my $asSetterValue = 0;
+    $code .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
+    $code .= JSValueToNativeStatement($indexedSetterFunction->parameters->[1]->type, $indexedSetterFunction->extendedAttributes, $asSetterValue, "jsValue", "propertyValue", "    ", "info.GetIsolate()");
+
     my $extraArguments = "";
     if ($raisesExceptions || IsIntegerType($type)) {
         $code .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
@@ -3762,23 +3831,17 @@ sub GenerateImplementationIndexedPropertySetter
         }
     }
 
-    my $asSetterValue = 0;
-    $code .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
-    $code .= JSValueToNativeStatement($indexedSetterFunction->parameters->[1]->type, $indexedSetterFunction->extendedAttributes, $asSetterValue, "jsValue", "propertyValue", "    ", "info.GetIsolate()");
-
-    my @conditions = ();
-    my @statements = ();
-    if ($treatNullAs && $treatNullAs ne "NullString") {
-        push @conditions, "jsValue->IsNull()";
-        push @statements, "collection->${treatNullAs}(index$extraArguments);";
+    if ($indexedSetterFunction->extendedAttributes->{"StrictTypeChecking"} && IsWrapperType($type)) {
+        $code .= <<END;
+    if (!isUndefinedOrNull(jsValue) && !V8${type}::hasInstance(jsValue, info.GetIsolate())) {
+        exceptionState.throwTypeError("The provided value is not of type '$type'.");
+        exceptionState.throwIfNeeded();
+        return;
     }
-    if ($treatUndefinedAs && $treatUndefinedAs ne "NullString") {
-        push @conditions, "jsValue->IsUndefined()";
-        push @statements, "collection->${treatUndefinedAs}(index$extraArguments);";
+END
     }
-    push @conditions, "";
-    push @statements, "collection->${methodName}(index, propertyValue$extraArguments);";
-    $code .= GenerateIfElseStatement("bool", "result", \@conditions, \@statements);
+
+    $code .= "    bool result = imp->${methodName}(index, propertyValue$extraArguments);\n";
 
     if ($raisesExceptions) {
         $code .= "    if (exceptionState.throwIfNeeded())\n";
@@ -3800,8 +3863,13 @@ sub GenerateImplementationNamedPropertyAccessors
     my $v8ClassName = GetV8ClassName($interface);
 
     my $namedGetterFunction = GetNamedGetterFunction($interface);
+    my $namedEnumeratorFunction = $namedGetterFunction && !$namedGetterFunction->extendedAttributes->{"NotEnumerable"};
+
     if ($namedGetterFunction) {
-        my $hasCustomNamedGetter = $namedGetterFunction->extendedAttributes->{"Custom"};
+        # includes for return type even if custom
+        my $returnType = $namedGetterFunction->type;
+        AddIncludesForType($returnType);
+        my $hasCustomNamedGetter = HasCustomPropertyGetter($namedGetterFunction->extendedAttributes);
         if (!$hasCustomNamedGetter) {
             GenerateImplementationNamedPropertyGetter($interface, $namedGetterFunction);
         }
@@ -3810,6 +3878,7 @@ sub GenerateImplementationNamedPropertyAccessors
 
     my $namedSetterFunction = GetNamedSetterFunction($interface);
     if ($namedSetterFunction) {
+        AddIncludesForType($namedSetterFunction->parameters->[1]->type);  # includes for argument type even if custom
         my $hasCustomNamedSetter = $namedSetterFunction->extendedAttributes->{"Custom"};
         if (!$hasCustomNamedSetter) {
             GenerateImplementationNamedPropertySetter($interface, $namedSetterFunction);
@@ -3817,6 +3886,14 @@ sub GenerateImplementationNamedPropertyAccessors
         GenerateImplementationNamedPropertySetterCallback($interface, $hasCustomNamedSetter);
     }
 
+    if ($namedEnumeratorFunction) {
+        my $hasCustomNamedQuery = ExtendedAttributeContains($namedGetterFunction->extendedAttributes->{"Custom"}, "PropertyQuery");
+        if (!$hasCustomNamedQuery) {
+            GenerateImplementationNamedPropertyQuery($interface);
+        }
+        GenerateImplementationNamedPropertyQueryCallback($interface, $hasCustomNamedQuery);
+    }
+
     my $namedDeleterFunction = GetNamedDeleterFunction($interface);
     if ($namedDeleterFunction) {
         my $hasCustomNamedDeleter = $namedDeleterFunction->extendedAttributes->{"Custom"};
@@ -3826,15 +3903,12 @@ sub GenerateImplementationNamedPropertyAccessors
         GenerateImplementationNamedPropertyDeleterCallback($interface, $hasCustomNamedDeleter);
     }
 
-    my $namedEnumeratorFunction = $namedGetterFunction && !$namedGetterFunction->extendedAttributes->{"NotEnumerable"};
     if ($namedEnumeratorFunction) {
-        my $hasCustomNamedEnumerator = $namedGetterFunction->extendedAttributes->{"CustomEnumerateProperty"};
+        my $hasCustomNamedEnumerator = ExtendedAttributeContains($namedGetterFunction->extendedAttributes->{"Custom"}, "PropertyEnumerator");
         if (!$hasCustomNamedEnumerator) {
             GenerateImplementationNamedPropertyEnumerator($interface);
-            GenerateImplementationNamedPropertyQuery($interface);
         }
         GenerateImplementationNamedPropertyEnumeratorCallback($interface, $hasCustomNamedEnumerator);
-        GenerateImplementationNamedPropertyQueryCallback($interface, $hasCustomNamedEnumerator);
     }
 
     my $subCode = "";
@@ -3993,7 +4067,7 @@ sub GenerateMethodCall
         return $code;
     } else {
         my $nativeType = GetNativeType($returnType);
-        return "    ${nativeType} element = ${functionExpression}(" . (join ", ", @arguments) . ");"
+        return "    ${nativeType} result = ${functionExpression}(" . (join ", ", @arguments) . ");"
     }
 }
 
@@ -4003,28 +4077,26 @@ sub GenerateImplementationNamedPropertyGetter
     my $namedGetterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($namedGetterFunction);
+    my $methodName = GetImplName($namedGetterFunction) || "anonymousNamedGetter";
 
     my $returnType = $namedGetterFunction->type;
-    my $isNull = GenerateIsNullExpression($returnType, "element");
-    my $nativeValue = "element";
+    my $isNull = GenerateIsNullExpression($returnType, "result");
+    my $nativeValue = "result";
     $nativeValue .= ".release()" if (IsRefPtrType($returnType));
-    my $returnJSValueCode = NativeToJSValue($namedGetterFunction->type, $namedGetterFunction->extendedAttributes, $nativeValue, "    ", "", "info.GetIsolate()", "info", "collection", "", "return");
+    my $returnJSValueCode = NativeToJSValue($namedGetterFunction->type, $namedGetterFunction->extendedAttributes, $nativeValue, "    ", "", "info.GetIsolate()", "info", "imp", "", "return");
     my $raisesExceptions = $namedGetterFunction->extendedAttributes->{"RaisesException"};
-    my $methodCallCode = GenerateMethodCall($returnType, "element", "collection->${methodName}", "propertyName", $raisesExceptions);
+    my $methodCallCode = GenerateMethodCall($returnType, "result", "imp->${methodName}", "propertyName", $raisesExceptions);
 
     my $code = "static void namedPropertyGetter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Value>& info)\n";
     $code .= "{\n";
-    if (!$namedGetterFunction->extendedAttributes->{"OverrideBuiltins"}) {
-        $code .= "    if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())\n";
-        $code .= "        return;\n";
-        $code .= "    if (info.Holder()->HasRealNamedCallbackProperty(name))\n";
-        $code .= "        return;\n";
+    if (!$interface->extendedAttributes->{"OverrideBuiltins"}) {
         $code .= "    if (info.Holder()->HasRealNamedProperty(name))\n";
         $code .= "        return;\n";
+        $code .= "    if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())\n";
+        $code .= "        return;\n";
+        $code .= "\n";
     }
-    $code .= "\n";
-    $code .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
+    $code .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
     $code .= "    AtomicString propertyName = toCoreAtomicString(name);\n";
     if ($raisesExceptions) {
         $code .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
@@ -4034,14 +4106,9 @@ sub GenerateImplementationNamedPropertyGetter
         $code .= "    if (exceptionState.throwIfNeeded())\n";
         $code .= "        return;\n";
     }
-    if (IsUnionType($returnType)) {
-        $code .= "${returnJSValueCode}\n";
-        $code .= "    return;\n";
-    } else {
-        $code .= "    if (${isNull})\n";
-        $code .= "        return;\n";
-        $code .= $returnJSValueCode . "\n";
-    }
+    $code .= "    if (${isNull})\n";
+    $code .= "        return;\n";
+    $code .= $returnJSValueCode . "\n";
     $code .= "}\n\n";
     $implementation{nameSpaceInternal}->add($code);
 }
@@ -4052,7 +4119,7 @@ sub GenerateImplementationNamedPropertySetter
     my $namedSetterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($namedSetterFunction);
+    my $methodName = GetImplName($namedSetterFunction) || "anonymousNamedSetter";
     my $interfaceName = $interface->name;
 
     my $type = $namedSetterFunction->parameters->[1]->type;
@@ -4062,15 +4129,19 @@ sub GenerateImplementationNamedPropertySetter
 
     my $code = "static void namedPropertySetter(v8::Local<v8::String> name, v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<v8::Value>& info)\n";
     $code .= "{\n";
-    if (!$namedSetterFunction->extendedAttributes->{"OverrideBuiltins"}) {
-        $code .= "    if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())\n";
-        $code .= "        return;\n";
-        $code .= "    if (info.Holder()->HasRealNamedCallbackProperty(name))\n";
-        $code .= "        return;\n";
+    if (!$interface->extendedAttributes->{"OverrideBuiltins"}) {
         $code .= "    if (info.Holder()->HasRealNamedProperty(name))\n";
         $code .= "        return;\n";
+        $code .= "    if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(name).IsEmpty())\n";
+        $code .= "        return;\n";
+        $code .= "\n";
     }
 
+    my $asSetterValue = 0;
+    $code .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
+    $code .= JSValueToNativeStatement($namedSetterFunction->parameters->[0]->type, $namedSetterFunction->extendedAttributes, $asSetterValue, "name", "propertyName", "    ", "info.GetIsolate()");
+    $code .= JSValueToNativeStatement($namedSetterFunction->parameters->[1]->type, $namedSetterFunction->extendedAttributes, $asSetterValue, "jsValue", "propertyValue", "    ", "info.GetIsolate()");
+
     my $extraArguments = "";
     if ($raisesExceptions || IsIntegerType($type)) {
         $code .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
@@ -4079,31 +4150,13 @@ sub GenerateImplementationNamedPropertySetter
         }
     }
 
-    my $asSetterValue = 0;
-    $code .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
-    $code .= JSValueToNativeStatement($namedSetterFunction->parameters->[0]->type, $namedSetterFunction->extendedAttributes, $asSetterValue, "name", "propertyName", "    ", "info.GetIsolate()");
-    $code .= JSValueToNativeStatement($namedSetterFunction->parameters->[1]->type, $namedSetterFunction->extendedAttributes, $asSetterValue, "jsValue", "propertyValue", "    ", "info.GetIsolate()");
-
-    my @conditions = ();
-    my @statements = ();
-    if ($treatNullAs && $treatNullAs ne "NullString") {
-        push @conditions, "jsValue->IsNull()";
-        push @statements, "collection->${treatNullAs}(propertyName$extraArguments);";
-    }
-    if ($treatUndefinedAs && $treatUndefinedAs ne "NullString") {
-        push @conditions, "jsValue->IsUndefined()";
-        push @statements, "collection->${treatUndefinedAs}(propertyName$extraArguments);";
-    }
-    push @conditions, "";
-    push @statements, "collection->${methodName}(propertyName, propertyValue$extraArguments);";
-    $code .= GenerateIfElseStatement("bool", "result", \@conditions, \@statements);
-
-    $code .= "    if (!result)\n";
-    $code .= "        return;\n";
+    $code .= "    bool result = imp->$methodName(propertyName, propertyValue$extraArguments);\n";
     if ($raisesExceptions) {
         $code .= "    if (exceptionState.throwIfNeeded())\n";
         $code .= "        return;\n";
     }
+    $code .= "    if (!result)\n";
+    $code .= "        return;\n";
     $code .= "    v8SetReturnValue(info, jsValue);\n";
     $code .= "}\n\n";
     $implementation{nameSpaceInternal}->add($code);
@@ -4115,19 +4168,19 @@ sub GenerateImplementationIndexedPropertyDeleter
     my $indexedDeleterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($indexedDeleterFunction);
+    my $methodName = GetImplName($indexedDeleterFunction) || "anonymousIndexedDeleter";
 
     my $raisesExceptions = $indexedDeleterFunction->extendedAttributes->{"RaisesException"};
 
-    my $code = "static void indexedPropertyDeleter(unsigned index, const v8::PropertyCallbackInfo<v8::Boolean>& info)\n";
+    my $code = "static void indexedPropertyDeleter(uint32_t index, const v8::PropertyCallbackInfo<v8::Boolean>& info)\n";
     $code .= "{\n";
-    $code .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
+    $code .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
     my $extraArguments = "";
     if ($raisesExceptions) {
         $code .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
         $extraArguments = ", exceptionState";
     }
-    $code .= "    DeleteResult result = collection->${methodName}(index$extraArguments);\n";
+    $code .= "    DeleteResult result = imp->${methodName}(index$extraArguments);\n";
     if ($raisesExceptions) {
         $code .= "    if (exceptionState.throwIfNeeded())\n";
         $code .= "        return;\n";
@@ -4144,20 +4197,20 @@ sub GenerateImplementationNamedPropertyDeleter
     my $namedDeleterFunction = shift;
     my $implClassName = GetImplName($interface);
     my $v8ClassName = GetV8ClassName($interface);
-    my $methodName = GetImplName($namedDeleterFunction);
+    my $methodName = GetImplName($namedDeleterFunction) || "anonymousNamedDeleter";
 
     my $raisesExceptions = $namedDeleterFunction->extendedAttributes->{"RaisesException"};
 
     my $code = "static void namedPropertyDeleter(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Boolean>& info)\n";
     $code .= "{\n";
-    $code .= "    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());\n";
+    $code .= "    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());\n";
     $code .= "    AtomicString propertyName = toCoreAtomicString(name);\n";
     my $extraArguments = "";
     if ($raisesExceptions) {
         $code .= "    ExceptionState exceptionState(info.Holder(), info.GetIsolate());\n";
         $extraArguments .= ", exceptionState";
     }
-    $code .= "    DeleteResult result = collection->${methodName}(propertyName$extraArguments);\n";
+    $code .= "    DeleteResult result = imp->${methodName}(propertyName$extraArguments);\n";
     if ($raisesExceptions) {
         $code .= "    if (exceptionState.throwIfNeeded())\n";
         $code .= "        return;\n";
@@ -4177,10 +4230,10 @@ sub GenerateImplementationNamedPropertyEnumerator
     $implementation{nameSpaceInternal}->add(<<END);
 static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
 {
-    ExceptionState exceptionState(info.Holder(), info.GetIsolate());
-    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());
+    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());
     Vector<String> names;
-    collection->namedPropertyEnumerator(names, exceptionState);
+    ExceptionState exceptionState(info.Holder(), info.GetIsolate());
+    imp->namedPropertyEnumerator(names, exceptionState);
     if (exceptionState.throwIfNeeded())
         return;
     v8::Handle<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
@@ -4201,10 +4254,10 @@ sub GenerateImplementationNamedPropertyQuery
     $implementation{nameSpaceInternal}->add(<<END);
 static void namedPropertyQuery(v8::Local<v8::String> name, const v8::PropertyCallbackInfo<v8::Integer>& info)
 {
-    ${implClassName}* collection = ${v8ClassName}::toNative(info.Holder());
+    ${implClassName}* imp = ${v8ClassName}::toNative(info.Holder());
     AtomicString propertyName = toCoreAtomicString(name);
     ExceptionState exceptionState(info.Holder(), info.GetIsolate());
-    bool result = collection->namedPropertyQuery(propertyName, exceptionState);
+    bool result = imp->namedPropertyQuery(propertyName, exceptionState);
     if (exceptionState.throwIfNeeded())
         return;
     if (!result)
@@ -4255,6 +4308,8 @@ sub GenerateImplementation
     AddToImplIncludes("core/dom/ContextFeatures.h");
     AddToImplIncludes("core/dom/Document.h");
     AddToImplIncludes("platform/TraceEvent.h");
+    AddToImplIncludes("wtf/GetPtr.h");
+    AddToImplIncludes("wtf/RefPtr.h");
 
     AddIncludesForType($interfaceName);
     if ($interface->extendedAttributes->{"CheckSecurity"}) {
@@ -4264,6 +4319,7 @@ sub GenerateImplementation
     my $toActiveDOMObject = InheritsExtendedAttribute($interface, "ActiveDOMObject") ? "${v8ClassName}::toActiveDOMObject" : "0";
     my $toEventTarget = InheritsInterface($interface, "EventTarget") ? "${v8ClassName}::toEventTarget" : "0";
     my $visitDOMWrapper = NeedsVisitDOMWrapper($interface) ? "${v8ClassName}::visitDOMWrapper" : "0";
+    my $derefObject = "${v8ClassName}::derefObject";
 
     # Find the super descriptor.
     my $parentClass = "";
@@ -4311,8 +4367,10 @@ END
         $implementation{nameSpaceWebCore}->addHeader($code);
     }
 
-    my $code = "const WrapperTypeInfo ${v8ClassName}::wrapperTypeInfo = { gin::kEmbedderBlink, ${v8ClassName}::domTemplate, ${v8ClassName}::derefObject, $toActiveDOMObject, $toEventTarget, ";
-    $code .= "$visitDOMWrapper, ${v8ClassName}::installPerContextEnabledMethods, $parentClassInfo, $WrapperTypePrototype };\n";
+    my $code = "const WrapperTypeInfo ${v8ClassName}::wrapperTypeInfo = { gin::kEmbedderBlink, ${v8ClassName}::domTemplate, $derefObject, $toActiveDOMObject, $toEventTarget, ";
+    $code .= "$visitDOMWrapper, ${v8ClassName}::installPerContextEnabledMethods, $parentClassInfo, $WrapperTypePrototype, ";
+    $code .= IsWillBeGarbageCollectedType($interfaceName) ? "true" : "false";
+    $code .=  " };\n";
     $implementation{nameSpaceWebCore}->addHeader($code);
 
     $implementation{nameSpaceInternal}->add("template <typename T> void V8_USE(T) { }\n\n");
@@ -4387,7 +4445,7 @@ END
     my $needsDomainSafeFunctionSetter = 0;
     # Generate methods for functions.
     foreach my $function (@{$interface->functions}) {
-        next if $function->name eq "";
+        next if $function->name eq "";  # Skip anonymous special operations
         my @worldSuffixes = ("");
         if ($function->extendedAttributes->{"PerWorldBindings"}) {
             push(@worldSuffixes, "ForMainWorld");
@@ -4546,6 +4604,7 @@ static void configureShadowObjectTemplate(v8::Handle<v8::ObjectTemplate> templ,
     templ->SetAccessCheckCallbacks(V8Window::namedSecurityCheckCustom, V8Window::indexedSecurityCheckCustom, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8Window::wrapperTypeInfo)));
     templ->SetInternalFieldCount(V8Window::internalFieldCount);
 }
+
 END
     }
 
@@ -4806,7 +4865,7 @@ END
 
     if ($interfaceName eq "Window") {
         $implementation{nameSpaceWebCore}->add(<<END);
-v8::Handle<v8::ObjectTemplate> V8Window::GetShadowObjectTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
+v8::Handle<v8::ObjectTemplate> V8Window::getShadowObjectTemplate(v8::Isolate* isolate, WrapperWorldType currentWorldType)
 {
     if (currentWorldType == MainWorld) {
         DEFINE_STATIC_LOCAL(v8::Persistent<v8::ObjectTemplate>, V8WindowShadowObjectCacheForMainWorld, ());
@@ -4834,15 +4893,21 @@ v8::Handle<v8::ObjectTemplate> V8Window::GetShadowObjectTemplate(v8::Isolate* is
 END
     }
 
-    GenerateSpecialWrap($interface, $v8ClassName, $nativeType);
-    GenerateToV8Converters($interface, $v8ClassName, $nativeType);
+    GenerateSpecialWrap($interface, $v8ClassName);
+    GenerateToV8Converters($interface, $v8ClassName);
 
-    $implementation{nameSpaceWebCore}->add(<<END);
-void ${v8ClassName}::derefObject(void* object)
-{
-    fromInternalPointer(object)->deref();
-}
+    $implementation{nameSpaceWebCore}->add("void ${v8ClassName}::derefObject(void* object)\n");
+    $implementation{nameSpaceWebCore}->add("{\n");
+    if (IsWillBeGarbageCollectedType($interface->name)) {
+        $implementation{nameSpaceWebCore}->add("#if !ENABLE(OILPAN)\n");
+    }
+    $implementation{nameSpaceWebCore}->add("    fromInternalPointer(object)->deref();\n");
+    if (IsWillBeGarbageCollectedType($interface->name)) {
+        $implementation{nameSpaceWebCore}->add("#endif // !ENABLE(OILPAN)\n");
+    }
+    $implementation{nameSpaceWebCore}->add("}\n\n");
 
+    $implementation{nameSpaceWebCore}->add(<<END);
 template<>
 v8::Handle<v8::Value> toV8NoInline(${nativeType}* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
@@ -4921,6 +4986,7 @@ END
     $header{classPrivate}->add(<<END);
     ${v8ClassName}(v8::Handle<v8::Function>, ExecutionContext*);
 
+    v8::Isolate* m_isolate;
     ScopedPersistent<v8::Function> m_callback;
     RefPtr<DOMWrapperWorld> m_world;
 END
@@ -4936,12 +5002,15 @@ sub GenerateCallbackImplementation
     AddToImplIncludes("bindings/v8/V8Binding.h");
     AddToImplIncludes("bindings/v8/V8Callback.h");
     AddToImplIncludes("wtf/Assertions.h");
+    AddToImplIncludes("wtf/GetPtr.h");
+    AddToImplIncludes("wtf/RefPtr.h");
 
     $implementation{nameSpaceWebCore}->add(<<END);
 ${v8ClassName}::${v8ClassName}(v8::Handle<v8::Function> callback, ExecutionContext* context)
     : ActiveDOMCallback(context)
-    , m_callback(toIsolate(context), callback)
-    , m_world(DOMWrapperWorld::current())
+    , m_isolate(toIsolate(context))
+    , m_callback(m_isolate, callback)
+    , m_world(DOMWrapperWorld::current(m_isolate))
 {
 }
 
@@ -4960,9 +5029,14 @@ END
         foreach my $function (@{$interface->functions}) {
             my $code = "";
             my @params = @{$function->parameters};
-            next if $function->extendedAttributes->{"Custom"};
 
+            # Add includes for types even if custom
             AddIncludesForType($function->type);
+            foreach my $param (@params) {
+                AddIncludesForType($param->type);
+            }
+            next if $function->extendedAttributes->{"Custom"};
+
             die "We only support callbacks that return boolean or void values.\n" unless ($function->type eq "boolean" || $function->type eq "void");
             my $defaultReturn = $function->type eq "boolean" ? " true" : "";
             $code .= GetNativeTypeForCallbacks($function->type) . " ${v8ClassName}::" . $function->name . "(";
@@ -4973,19 +5047,7 @@ END
                 push(@args, GetNativeTypeForCallbacks("any") . " thisValue");
             }
             foreach my $param (@params) {
-                my $paramName = $param->name;
-                my $type = $param->type;
-                my $arrayOrSequenceType = GetArrayOrSequenceType($type);
-
-                if ($arrayOrSequenceType) {
-                    if (IsRefPtrType($arrayOrSequenceType)) {
-                        AddIncludesForType($arrayOrSequenceType);
-                     }
-                } else {
-                    AddIncludesForType($type);
-                }
-
-                push(@args, GetNativeTypeForCallbacks($type) . " " . $paramName);
+                push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name);
             }
             $code .= join(", ", @args);
 
@@ -4993,8 +5055,7 @@ END
             $code .= "{\n";
             $code .= "    if (!canInvokeCallback())\n";
             $code .= "        return${defaultReturn};\n\n";
-            $code .= "    v8::Isolate* isolate = v8::Isolate::GetCurrent();\n";
-            $code .= "    v8::HandleScope handleScope(isolate);\n\n";
+            $code .= "    v8::HandleScope handleScope(m_isolate);\n\n";
             $code .= "    v8::Handle<v8::Context> v8Context = toV8Context(executionContext(), m_world.get());\n";
             $code .= "    if (v8Context.IsEmpty())\n";
             $code .= "        return${defaultReturn};\n\n";
@@ -5014,7 +5075,7 @@ END
             @args = ();
             foreach my $param (@params) {
                 my $paramName = $param->name;
-                $code .= NativeToJSValue($param->type, $param->extendedAttributes, $paramName, "    ", "v8::Handle<v8::Value> ${paramName}Handle =", "isolate", "") . "\n";
+                $code .= NativeToJSValue($param->type, $param->extendedAttributes, $paramName, "    ", "v8::Handle<v8::Value> ${paramName}Handle =", "m_isolate", "") . "\n";
                 $code .= "    if (${paramName}Handle.IsEmpty()) {\n";
                 $code .= "        if (!isScriptControllerTerminating())\n";
                 $code .= "            CRASH();\n";
@@ -5034,7 +5095,7 @@ END
             if ($function->type eq "boolean") {
                 $code .= "return ";
             }
-            $code .= "invokeCallback(m_callback.newLocal(isolate), ${thisObjectHandle}" . scalar(@args) . ", argv, executionContext(), isolate);\n";
+            $code .= "invokeCallback(m_callback.newLocal(m_isolate), ${thisObjectHandle}" . scalar(@args) . ", argv, executionContext(), m_isolate);\n";
             $code .= "}\n\n";
             $implementation{nameSpaceWebCore}->add($code);
         }
@@ -5045,7 +5106,7 @@ sub GenerateSpecialWrap
 {
     my $interface = shift;
     my $v8ClassName = shift;
-    my $nativeType = shift;
+    my $nativeType = GetNativeTypeForConversions($interface);
 
     my $specialWrap = $interface->extendedAttributes->{"SpecialWrapFor"};
     my $isDocument = InheritsInterface($interface, "Document");
@@ -5077,9 +5138,10 @@ END
         $code .= <<END;
     if (wrapper.IsEmpty())
         return wrapper;
-    if (!isolatedWorldForEnteredContext(isolate)) {
+    DOMWrapperWorld* world = DOMWrapperWorld::current(isolate);
+    if (world->isMainWorld()) {
         if (Frame* frame = impl->frame())
-            frame->script().windowShell(mainThreadNormalWorld())->updateDocumentWrapper(wrapper);
+            frame->script().windowShell(world)->updateDocumentWrapper(wrapper);
     }
 END
     }
@@ -5095,14 +5157,13 @@ sub GenerateToV8Converters
 {
     my $interface = shift;
     my $v8ClassName = shift;
-    my $nativeType = shift;
     my $interfaceName = $interface->name;
 
     if (ExtendedAttributeContains($interface->extendedAttributes->{"Custom"}, "ToV8")) {
         return;
     }
 
-    my $createWrapperArgumentType = GetPassRefPtrType($nativeType);
+    my $passRefPtrType = GetPassRefPtrType($interface);
 
     # FIXME: Do we really need to treat /SVG/ as dependent DOM objects?
     my $wrapperConfiguration = "WrapperConfiguration::Independent";
@@ -5115,7 +5176,7 @@ sub GenerateToV8Converters
 
     my $code = "";
     $code .= <<END;
-v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${createWrapperArgumentType} impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
+v8::Handle<v8::Object> ${v8ClassName}::createWrapper(${passRefPtrType} impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     ASSERT(impl);
     ASSERT(!DOMDataStore::containsWrapper<${v8ClassName}>(impl.get(), isolate));
@@ -5181,7 +5242,7 @@ sub GenerateSecurityCheckFunctions
 bool indexedSecurityCheck(v8::Local<v8::Object> host, uint32_t index, v8::AccessType type, v8::Local<v8::Value>)
 {
     $implClassName* imp =  ${v8ClassName}::toNative(host);
-    return BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError);
+    return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), imp->frame(), DoNotReportSecurityError);
 }
 
 END
@@ -5189,7 +5250,7 @@ END
 bool namedSecurityCheck(v8::Local<v8::Object> host, v8::Local<v8::Value> key, v8::AccessType type, v8::Local<v8::Value>)
 {
     $implClassName* imp =  ${v8ClassName}::toNative(host);
-    return BindingSecurity::shouldAllowAccessToFrame(imp->frame(), DoNotReportSecurityError);
+    return BindingSecurity::shouldAllowAccessToFrame(v8::Isolate::GetCurrent(), imp->frame(), DoNotReportSecurityError);
 }
 
 END
@@ -5224,11 +5285,8 @@ sub GenerateFunctionCallString
     my $implClassName = GetImplName($interface);
     my $name = GetImplName($function);
     my $returnType = $function->type;
-    my $nativeReturnType = GetNativeType($returnType, {}, "");
     my $code = "";
-
     my $isSVGTearOffType = (IsSVGTypeNeedingTearOff($returnType) and not $interfaceName =~ /List$/);
-    $nativeReturnType = GetSVGWrappedTypeNeedingTearOff($returnType) if $isSVGTearOffType;
 
     my $index = 0;
     my $humanFriendlyIndex = $index + 1;
@@ -5296,6 +5354,22 @@ END
         $humanFriendlyIndex = $index + 1;
     }
 
+    # Support for returning a union type.
+    if (IsUnionType($returnType)) {
+        my $types = $returnType->unionMemberTypes;
+        for my $i (0 .. scalar(@$types)-1) {
+            my $unionMemberType = $types->[$i];
+            my $unionMemberNativeType = GetNativeType($unionMemberType);
+            my $unionMemberNumber = $i + 1;
+            my $unionMemberVariable = "result" . $i;
+            my $unionMemberEnabledVariable = "result" . $i . "Enabled";
+            $code .= "    bool ${unionMemberEnabledVariable} = false;\n";
+            $code .= "    ${unionMemberNativeType} ${unionMemberVariable};\n";
+            push @arguments, $unionMemberEnabledVariable;
+            push @arguments, $unionMemberVariable;
+        }
+    }
+
     if ($function->extendedAttributes->{"RaisesException"}) {
         push @arguments, "exceptionState";
     }
@@ -5305,9 +5379,12 @@ END
     my $return = "result";
     my $returnIsRef = IsRefPtrType($returnType);
 
-    if ($returnType eq "void") {
+    if ($returnType eq "void" || IsUnionType($returnType)) {
         $code .= $indent . "$functionString;\n";
     } elsif (ExtendedAttributeContains($callWith, "ScriptState") or $function->extendedAttributes->{"RaisesException"}) {
+        my $nativeReturnType = GetNativeType($returnType, {}, "");
+        $nativeReturnType = GetSVGWrappedTypeNeedingTearOff($returnType) if $isSVGTearOffType;
+
         $code .= $indent . $nativeReturnType . " result = $functionString;\n";
     } else {
         # Can inline the function call into the return statement to avoid overhead of using a Ref<> temporary
@@ -5422,7 +5499,13 @@ sub GetNativeType
     if (IsWrapperType($type)) {
         my $interface = ParseInterface($type);
         my $implClassName = GetImplName($interface);
-        return $isParameter ? "${implClassName}*" : "RefPtr<${implClassName}>";
+        if ($isParameter) {
+            return "$implClassName*";
+        } elsif (IsWillBeGarbageCollectedType($interface->name)) {
+            return "RefPtrWillBeRawPtr<$implClassName>";
+        } else {
+            return "RefPtr<$implClassName>";
+        }
     }
     return "RefPtr<$type>" if IsRefPtrType($type) and (not $isParameter or $nonWrapperTypes{$type});
 
@@ -5501,7 +5584,7 @@ sub JSValueToNative
         }
     }
     return "static_cast<Range::CompareHow>($value->Int32Value())" if $type eq "CompareHow";
-    return "toWebCoreDate($value)" if $type eq "Date";
+    return "toCoreDate($value)" if $type eq "Date";
 
     if ($type eq "DOMString" or IsEnumType($type)) {
         return $value;
@@ -5532,7 +5615,7 @@ sub JSValueToNative
     }
 
     if ($type eq "Window") {
-        return "toNativeDOMWindow($value, $getIsolate)";
+        return "toDOMWindow($value, $getIsolate)";
     }
 
     if ($type eq "MediaQueryListListener") {
@@ -5660,13 +5743,17 @@ sub NativeToJSValue
               $code .= "${indent}if (${unionMemberEnabledVariable}) {\n";
               $code .= "${returnJSValueCode}\n";
               $code .= "${indent}    return;\n";
-              $code .= "${indent}}\n";
+              $code .= "${indent}}";
             } else {
               $code .= "${indent}if (${unionMemberEnabledVariable})\n";
               $code .= "${returnJSValueCode}";
             }
             push @codes, $code;
         }
+        if ($isReturnValue) {
+            # Fall back to returning null if none of the union members results are returned.
+            push @codes, "${indent}v8SetReturnValueNull(${getCallbackInfo});";
+        }
         return join "\n", @codes;
     }
 
@@ -5778,9 +5865,6 @@ sub NativeToJSValue
         return "$indent$receiver $returnValue;";
     }
 
-    AddToImplIncludes("wtf/RefPtr.h");
-    AddToImplIncludes("wtf/GetPtr.h");
-
     if ($getScriptWrappable) {
         # FIXME: Use safe handles
         if ($isReturnValue) {
@@ -5861,10 +5945,12 @@ sub GetContextEnabledFunctionName
 
 sub GetPassRefPtrType
 {
-    my $v8ClassName = shift;
+    my $interface = shift;
+    my $nativeType = GetNativeTypeForConversions($interface);
 
-    my $angleBracketSpace = $v8ClassName =~ />$/ ? " " : "";
-    return "PassRefPtr<${v8ClassName}${angleBracketSpace}>";
+    my $willBe = IsWillBeGarbageCollectedType($interface->name) ? "WillBeRawPtr" : "";
+    my $extraSpace = $nativeType =~ />$/ ? " " : "";
+    return "PassRefPtr${willBe}<${nativeType}${extraSpace}>";
 }
 
 sub WriteFileIfChanged
@@ -5970,6 +6056,14 @@ sub IsTypedArrayType
     return 0;
 }
 
+sub IsWillBeGarbageCollectedType
+{
+    my $interfaceName = shift;
+    return 0 unless IsWrapperType($interfaceName);
+    my $interface = ParseInterface($interfaceName);
+    return $interface->extendedAttributes->{"WillBeGarbageCollected"};
+}
+
 sub IsRefPtrType
 {
     my $type = shift;