# 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
"Notation" => 1,
"ProcessingInstruction" => 1,
"ShadowRoot" => 1,
- "SVGDocument" => 1,
"Text" => 1,
"TestNode" => 1,
"TestInterfaceDocument" => 1,
"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"
);
# 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");
$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");
}
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");
{
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");
}
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
}
$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
}
$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);
}
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");
}
}
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;
}
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"};
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");
$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");
}
}
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;
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());
${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;
}
if ($measureAs) {
AddToImplIncludes("core/frame/UseCounter.h");
- return " UseCounter::count(activeExecutionContext(), UseCounter::${measureAs});\n";
+ return " UseCounter::count(activeExecutionContext(info.GetIsolate()), UseCounter::${measureAs});\n";
}
return "";
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 "";
}
# 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";
} 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 {
${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;
}
} 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) {
} 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);
$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;
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.
#
}
} 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()");
}
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);
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;
}
# - 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);
$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
# 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;
}
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";
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")) {
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);
}
}
$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 || ";
$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";
$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";
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";
}
}
}
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) {
${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;
}
# 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);
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
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
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
$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
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;
}
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);
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);
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";
}
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;
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";
}
}
- 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";
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);
}
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);
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"};
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 = "";
return $code;
} else {
my $nativeType = GetNativeType($returnType);
- return " ${nativeType} element = ${functionExpression}(" . (join ", ", @arguments) . ");"
+ return " ${nativeType} result = ${functionExpression}(" . (join ", ", @arguments) . ");"
}
}
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";
$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);
}
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;
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";
}
}
- 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);
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";
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";
$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());
$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)
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"}) {
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 = "";
$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");
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");
templ->SetAccessCheckCallbacks(V8Window::namedSecurityCheckCustom, V8Window::indexedSecurityCheckCustom, v8::External::New(isolate, const_cast<WrapperTypeInfo*>(&V8Window::wrapperTypeInfo)));
templ->SetInternalFieldCount(V8Window::internalFieldCount);
}
+
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, ());
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)
{
$header{classPrivate}->add(<<END);
${v8ClassName}(v8::Handle<v8::Function>, ExecutionContext*);
+ v8::Isolate* m_isolate;
ScopedPersistent<v8::Function> m_callback;
RefPtr<DOMWrapperWorld> m_world;
END
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))
{
}
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 . "(";
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);
$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";
@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";
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);
}
{
my $interface = shift;
my $v8ClassName = shift;
- my $nativeType = shift;
+ my $nativeType = GetNativeTypeForConversions($interface);
my $specialWrap = $interface->extendedAttributes->{"SpecialWrapFor"};
my $isDocument = InheritsInterface($interface, "Document");
$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
}
{
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";
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));
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
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
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;
$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";
}
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
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});
}
}
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;
}
if ($type eq "Window") {
- return "toNativeDOMWindow($value, $getIsolate)";
+ return "toDOMWindow($value, $getIsolate)";
}
if ($type eq "MediaQueryListListener") {
$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;
}
return "$indent$receiver $returnValue;";
}
- AddToImplIncludes("wtf/RefPtr.h");
- AddToImplIncludes("wtf/GetPtr.h");
-
if ($getScriptWrappable) {
# FIXME: Use safe handles
if ($isReturnValue) {
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
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;