Chromium Code Reviews| Index: Source/bindings/core/v8/PrivateScriptRunner.cpp |
| diff --git a/Source/bindings/core/v8/PrivateScriptRunner.cpp b/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| index 9dcc4cc107717fb46fe5e48163afc4dbd84e41a1..d1b822f7f49f21b6b14c042019a56accb3417cfc 100644 |
| --- a/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| +++ b/Source/bindings/core/v8/PrivateScriptRunner.cpp |
| @@ -40,12 +40,21 @@ static void dumpV8Message(v8::Handle<v8::Message> message) |
| v8::Handle<v8::String> errorMessage = message->Get(); |
| fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, toCoreString(errorMessage).utf8().data()); |
| } |
| +static void functionImport(const v8::FunctionCallbackInfo<v8::Value>& args); |
| static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, String scriptClassName, const char* source, size_t size) |
| { |
| v8::TryCatch block; |
| String sourceString(source, size); |
| String fileName = scriptClassName + ".js"; |
| + |
| + v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| + v8::Handle<v8::Object> global = context->Global(); |
| + |
| + v8::Handle<v8::Value> functionImportObject = global->Get(v8String(isolate, "Import")); |
| + if (isUndefinedOrNull(functionImportObject)) |
|
haraken
2014/11/25 09:41:41
RELEASE_ASSERT(functionImportObject.IsEmpty() || f
vivekg
2014/11/25 11:30:32
If I change to
RELEASE_ASSERT(functionImportObje
|
| + global->Set(v8String(isolate, "Import"), v8::FunctionTemplate::New(isolate, functionImport)->GetFunction()); |
| + |
| v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isolate, sourceString), fileName, TextPosition::minimumPosition(), 0, 0, isolate, NotSharableCrossOrigin); |
| if (block.HasCaught()) { |
| fprintf(stderr, "Private script error: Compile failed. (Class name = %s)\n", scriptClassName.utf8().data()); |
| @@ -62,6 +71,23 @@ static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St |
| return result; |
| } |
| +void functionImport(const v8::FunctionCallbackInfo<v8::Value>& args) |
| +{ |
| + v8::Isolate* isolate = args.GetIsolate(); |
| + RELEASE_ASSERT(isolate && (args.Length() == 1)); |
| + |
| + String resourceFileName = toCoreString(args[0]->ToString()); |
| + String resourceData = loadResourceAsASCIIString(resourceFileName.utf8().data()); |
| + RELEASE_ASSERT(resourceData.length()); |
| + |
| + if (resourceFileName.endsWith(".js")) { |
| + compileAndRunPrivateScript(isolate, resourceFileName.replace(".js", ""), resourceData.utf8().data(), resourceData.length()); |
| + } else if (resourceFileName.endsWith(".css")) { |
| + v8::Handle<v8::Object> global = isolate->GetCurrentContext()->Global(); |
| + global->Set(v8String(isolate, "css" + resourceFileName.replace(".css", "")), v8String(isolate, resourceData)); |
| + } |
| +} |
| + |
| // FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the JS files |
| // are compiled when any of the JS files is requested. Ideally we should avoid compiling |
| // unrelated JS files. For example, if a method in XPartial-1.js is requested, we just |