|
Lines 2126-2150
sub GenerateCallbackHeader
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec1
|
| 2126 |
# - Add default header template |
2126 |
# - Add default header template |
| 2127 |
push(@headerContent, GenerateHeaderContentHeader($dataNode)); |
2127 |
push(@headerContent, GenerateHeaderContentHeader($dataNode)); |
| 2128 |
|
2128 |
|
| 2129 |
if ("$interfaceName.h" lt "WorldContextHandle.h") { |
2129 |
my @unsortedIncludes = (); |
| 2130 |
push(@headerContent, "#include \"$interfaceName.h\"\n"); |
2130 |
push(@unsortedIncludes, "#include \"ActiveDOMCallback.h\""); |
| 2131 |
push(@headerContent, "#include \"WorldContextHandle.h\"\n"); |
2131 |
push(@unsortedIncludes, "#include \"$interfaceName.h\""); |
| 2132 |
} else { |
2132 |
push(@unsortedIncludes, "#include \"WorldContextHandle.h\""); |
| 2133 |
push(@headerContent, "#include \"WorldContextHandle.h\"\n"); |
2133 |
push(@unsortedIncludes, "#include <v8.h>"); |
| 2134 |
push(@headerContent, "#include \"$interfaceName.h\"\n"); |
2134 |
push(@unsortedIncludes, "#include <wtf/Forward.h>"); |
| 2135 |
} |
2135 |
push(@headerContent, join("\n", sort @unsortedIncludes)); |
| 2136 |
push(@headerContent, "#include <v8.h>\n"); |
|
|
| 2137 |
push(@headerContent, "#include <wtf/Forward.h>\n"); |
| 2138 |
|
2136 |
|
| 2139 |
push(@headerContent, "\nnamespace WebCore {\n\n"); |
2137 |
push(@headerContent, "\n\nnamespace WebCore {\n\n"); |
| 2140 |
push(@headerContent, "class $className : public $interfaceName {\n"); |
2138 |
push(@headerContent, "class ScriptExecutionContext;\n\n"); |
|
|
2139 |
push(@headerContent, "class $className : public $interfaceName, public ActiveDOMCallback {\n"); |
| 2141 |
|
2140 |
|
| 2142 |
push(@headerContent, <<END); |
2141 |
push(@headerContent, <<END); |
| 2143 |
public: |
2142 |
public: |
| 2144 |
static PassRefPtr<${className}> create(v8::Local<v8::Value> value) |
2143 |
static PassRefPtr<${className}> create(v8::Local<v8::Value> value, ScriptExecutionContext* context) |
| 2145 |
{ |
2144 |
{ |
| 2146 |
ASSERT(value->IsObject()); |
2145 |
ASSERT(value->IsObject()); |
| 2147 |
return adoptRef(new ${className}(value->ToObject())); |
2146 |
ASSERT(context); |
|
|
2147 |
return adoptRef(new ${className}(value->ToObject(), context)); |
| 2148 |
} |
2148 |
} |
| 2149 |
|
2149 |
|
| 2150 |
virtual ~${className}(); |
2150 |
virtual ~${className}(); |
|
Lines 2162-2172
END
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec2
|
| 2162 |
push(@headerContent, " COMPILE_ASSERT(false)"); |
2162 |
push(@headerContent, " COMPILE_ASSERT(false)"); |
| 2163 |
} |
2163 |
} |
| 2164 |
|
2164 |
|
| 2165 |
push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "(ScriptExecutionContext*"); |
2165 |
push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "("); |
|
|
2166 |
|
| 2167 |
my @args = (); |
| 2166 |
foreach my $param (@params) { |
2168 |
foreach my $param (@params) { |
| 2167 |
push(@headerContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name); |
2169 |
push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); |
| 2168 |
} |
2170 |
} |
| 2169 |
|
2171 |
push(@headerContent, join(", ", @args)); |
| 2170 |
push(@headerContent, ");\n"); |
2172 |
push(@headerContent, ");\n"); |
| 2171 |
} |
2173 |
} |
| 2172 |
} |
2174 |
} |
|
Lines 2174-2180
END
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec3
|
| 2174 |
push(@headerContent, <<END); |
2176 |
push(@headerContent, <<END); |
| 2175 |
|
2177 |
|
| 2176 |
private: |
2178 |
private: |
| 2177 |
${className}(v8::Local<v8::Object>); |
2179 |
${className}(v8::Local<v8::Object>, ScriptExecutionContext*); |
| 2178 |
|
2180 |
|
| 2179 |
v8::Persistent<v8::Object> m_callback; |
2181 |
v8::Persistent<v8::Object> m_callback; |
| 2180 |
WorldContextHandle m_worldContext; |
2182 |
WorldContextHandle m_worldContext; |
|
Lines 2206-2213
sub GenerateCallbackImplementation
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec4
|
| 2206 |
push(@implContent, "#include <wtf/Assertions.h>\n\n"); |
2208 |
push(@implContent, "#include <wtf/Assertions.h>\n\n"); |
| 2207 |
push(@implContent, "namespace WebCore {\n\n"); |
2209 |
push(@implContent, "namespace WebCore {\n\n"); |
| 2208 |
push(@implContent, <<END); |
2210 |
push(@implContent, <<END); |
| 2209 |
${className}::${className}(v8::Local<v8::Object> callback) |
2211 |
${className}::${className}(v8::Local<v8::Object> callback, ScriptExecutionContext* context) |
| 2210 |
: m_callback(v8::Persistent<v8::Object>::New(callback)) |
2212 |
: ActiveDOMCallback(context) |
|
|
2213 |
, m_callback(v8::Persistent<v8::Object>::New(callback)) |
| 2211 |
, m_worldContext(UseCurrentWorld) |
2214 |
, m_worldContext(UseCurrentWorld) |
| 2212 |
{ |
2215 |
{ |
| 2213 |
} |
2216 |
} |
|
Lines 2231-2252
END
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec5
|
| 2231 |
} |
2234 |
} |
| 2232 |
|
2235 |
|
| 2233 |
AddIncludesForType($function->signature->type); |
2236 |
AddIncludesForType($function->signature->type); |
| 2234 |
push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "(ScriptExecutionContext* context"); |
2237 |
push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "("); |
| 2235 |
|
2238 |
|
|
|
2239 |
my @args = (); |
| 2236 |
foreach my $param (@params) { |
2240 |
foreach my $param (@params) { |
| 2237 |
AddIncludesForType($param->type); |
2241 |
AddIncludesForType($param->type); |
| 2238 |
push(@implContent, ", " . GetNativeTypeForCallbacks($param->type) . " " . $param->name); |
2242 |
push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); |
| 2239 |
} |
2243 |
} |
|
|
2244 |
push(@implContent, join(", ", @args)); |
| 2240 |
|
2245 |
|
| 2241 |
push(@implContent, ")\n"); |
2246 |
push(@implContent, ")\n"); |
| 2242 |
push(@implContent, "{\n"); |
2247 |
push(@implContent, "{\n"); |
|
|
2248 |
push(@implContent, " if (!canInvokeCallback())\n"); |
| 2249 |
push(@implContent, " return true;\n\n"); |
| 2243 |
push(@implContent, " v8::HandleScope handleScope;\n\n"); |
2250 |
push(@implContent, " v8::HandleScope handleScope;\n\n"); |
| 2244 |
push(@implContent, " v8::Handle<v8::Context> v8Context = toV8Context(context, m_worldContext);\n"); |
2251 |
push(@implContent, " v8::Handle<v8::Context> v8Context = toV8Context(scriptExecutionContext(), m_worldContext);\n"); |
| 2245 |
push(@implContent, " if (v8Context.IsEmpty())\n"); |
2252 |
push(@implContent, " if (v8Context.IsEmpty())\n"); |
| 2246 |
push(@implContent, " return true;\n\n"); |
2253 |
push(@implContent, " return true;\n\n"); |
| 2247 |
push(@implContent, " v8::Context::Scope scope(v8Context);\n\n"); |
2254 |
push(@implContent, " v8::Context::Scope scope(v8Context);\n\n"); |
| 2248 |
|
2255 |
|
| 2249 |
my @argvs = (); |
2256 |
@args = (); |
| 2250 |
foreach my $param (@params) { |
2257 |
foreach my $param (@params) { |
| 2251 |
my $paramName = $param->name; |
2258 |
my $paramName = $param->name; |
| 2252 |
push(@implContent, " v8::Handle<v8::Value> ${paramName}Handle = toV8(${paramName});\n"); |
2259 |
push(@implContent, " v8::Handle<v8::Value> ${paramName}Handle = toV8(${paramName});\n"); |
|
Lines 2254-2267
END
WebCore/bindings/scripts/CodeGeneratorV8.pm_sec6
|
| 2254 |
push(@implContent, " CRASH();\n"); |
2261 |
push(@implContent, " CRASH();\n"); |
| 2255 |
push(@implContent, " return true;\n"); |
2262 |
push(@implContent, " return true;\n"); |
| 2256 |
push(@implContent, " }\n"); |
2263 |
push(@implContent, " }\n"); |
| 2257 |
push(@argvs, " ${paramName}Handle"); |
2264 |
push(@args, " ${paramName}Handle"); |
| 2258 |
} |
2265 |
} |
| 2259 |
|
2266 |
|
| 2260 |
push(@implContent, "\n v8::Handle<v8::Value> argv[] = {\n"); |
2267 |
push(@implContent, "\n v8::Handle<v8::Value> argv[] = {\n"); |
| 2261 |
push(@implContent, join(",\n", @argvs)); |
2268 |
push(@implContent, join(",\n", @args)); |
| 2262 |
push(@implContent, "\n };\n\n"); |
2269 |
push(@implContent, "\n };\n\n"); |
| 2263 |
push(@implContent, " bool callbackReturnValue = false;\n"); |
2270 |
push(@implContent, " bool callbackReturnValue = false;\n"); |
| 2264 |
push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, context);\n"); |
2271 |
push(@implContent, " return !invokeCallback(m_callback, " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n"); |
| 2265 |
push(@implContent, "}\n"); |
2272 |
push(@implContent, "}\n"); |
| 2266 |
} |
2273 |
} |
| 2267 |
} |
2274 |
} |