OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 crashIfV8IsDead(); | 194 crashIfV8IsDead(); |
195 return result; | 195 return result; |
196 } | 196 } |
197 | 197 |
198 void V8ScriptRunner::runModule(v8::Isolate* isolate, ExecutionContext* context,
V8ScriptModule& module) | 198 void V8ScriptRunner::runModule(v8::Isolate* isolate, ExecutionContext* context,
V8ScriptModule& module) |
199 { | 199 { |
200 TRACE_EVENT0("v8", "v8.runModule"); | 200 TRACE_EVENT0("v8", "v8.runModule"); |
201 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); | 201 TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution"); |
202 V8RecursionScope scope(isolate, context); | 202 V8RecursionScope scope(isolate, context); |
203 | 203 |
204 v8::Handle<v8::Function> constructor = V8PerContextData::from( | 204 StringBuilder hackedSource; |
205 isolate->GetCurrentContext())->functionConstructor(); | 205 hackedSource.append("(function("); |
206 v8::Handle<v8::Object> function = v8::Handle<v8::Object>::Cast( | 206 for (String& formal : module.formalDependencies) { |
207 constructor->CallAsConstructor(module.formalDependenciesAndSource.size()
, | 207 hackedSource.append(formal); |
208 module.formalDependenciesAndSource.data()
)); | 208 hackedSource.append(", "); |
209 if (!function.IsEmpty()) { | |
210 function->CallAsFunction(module.receiver, | |
211 module.resolvedDependencies.size(), | |
212 module.resolvedDependencies.data()); | |
213 } | 209 } |
| 210 hackedSource.append("module) {"); |
| 211 hackedSource.append(module.source); |
| 212 hackedSource.append("\n/**/})"); |
| 213 |
| 214 v8::Handle<v8::Script> script = compileScript( |
| 215 v8String(isolate, hackedSource.toString()), |
| 216 module.resourceName, |
| 217 module.textPosition, |
| 218 isolate, |
| 219 V8CacheOptionsOff); |
| 220 |
| 221 if (script.IsEmpty()) |
| 222 return; |
| 223 |
| 224 v8::Handle<v8::Value> scriptResult = script->Run(); |
| 225 |
| 226 auto arguments = module.resolvedDependencies; |
| 227 arguments.append(module.receiver); |
| 228 |
| 229 RELEASE_ASSERT(scriptResult->IsObject()); |
| 230 scriptResult.As<v8::Object>()->CallAsFunction( |
| 231 module.receiver, arguments.size(), arguments.data()); |
214 crashIfV8IsDead(); | 232 crashIfV8IsDead(); |
215 } | 233 } |
216 | 234 |
217 } // namespace blink | 235 } // namespace blink |
OLD | NEW |