OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "bindings/core/v8/PrivateScriptRunner.h" | 6 #include "bindings/core/v8/PrivateScriptRunner.h" |
7 | 7 |
8 #include "bindings/core/v8/DOMWrapperWorld.h" | 8 #include "bindings/core/v8/DOMWrapperWorld.h" |
9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 message->GetLineNumber(); | 33 message->GetLineNumber(); |
34 | 34 |
35 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName (); | 35 v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName (); |
36 String fileName = "Unknown JavaScript file"; | 36 String fileName = "Unknown JavaScript file"; |
37 if (!resourceName.IsEmpty() && resourceName->IsString()) | 37 if (!resourceName.IsEmpty() && resourceName->IsString()) |
38 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName)); | 38 fileName = toCoreString(v8::Handle<v8::String>::Cast(resourceName)); |
39 int lineNumber = message->GetLineNumber(); | 39 int lineNumber = message->GetLineNumber(); |
40 v8::Handle<v8::String> errorMessage = message->Get(); | 40 v8::Handle<v8::String> errorMessage = message->Get(); |
41 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data()); | 41 fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, to CoreString(errorMessage).utf8().data()); |
42 } | 42 } |
43 static void functionImport(const v8::FunctionCallbackInfo<v8::Value>& args); | |
43 | 44 |
44 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St ring scriptClassName, const char* source, size_t size) | 45 static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, St ring scriptClassName, const char* source, size_t size) |
45 { | 46 { |
46 v8::TryCatch block; | 47 v8::TryCatch block; |
47 String sourceString(source, size); | 48 String sourceString(source, size); |
48 String fileName = scriptClassName + ".js"; | 49 String fileName = scriptClassName + ".js"; |
50 | |
51 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | |
52 v8::Handle<v8::Object> global = context->Global(); | |
53 | |
54 v8::Handle<v8::Value> functionImportObject = global->Get(v8String(isolate, " Import")); | |
55 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
| |
56 global->Set(v8String(isolate, "Import"), v8::FunctionTemplate::New(isola te, functionImport)->GetFunction()); | |
57 | |
49 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola te, sourceString), fileName, TextPosition::minimumPosition(), 0, 0, isolate, Not SharableCrossOrigin); | 58 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isola te, sourceString), fileName, TextPosition::minimumPosition(), 0, 0, isolate, Not SharableCrossOrigin); |
50 if (block.HasCaught()) { | 59 if (block.HasCaught()) { |
51 fprintf(stderr, "Private script error: Compile failed. (Class name = %s) \n", scriptClassName.utf8().data()); | 60 fprintf(stderr, "Private script error: Compile failed. (Class name = %s) \n", scriptClassName.utf8().data()); |
52 dumpV8Message(block.Message()); | 61 dumpV8Message(block.Message()); |
53 RELEASE_ASSERT_NOT_REACHED(); | 62 RELEASE_ASSERT_NOT_REACHED(); |
54 } | 63 } |
55 | 64 |
56 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(iso late, script); | 65 v8::Handle<v8::Value> result = V8ScriptRunner::runCompiledInternalScript(iso late, script); |
57 if (block.HasCaught()) { | 66 if (block.HasCaught()) { |
58 fprintf(stderr, "Private script error: installClass() failed. (Class nam e = %s)\n", scriptClassName.utf8().data()); | 67 fprintf(stderr, "Private script error: installClass() failed. (Class nam e = %s)\n", scriptClassName.utf8().data()); |
59 dumpV8Message(block.Message()); | 68 dumpV8Message(block.Message()); |
60 RELEASE_ASSERT_NOT_REACHED(); | 69 RELEASE_ASSERT_NOT_REACHED(); |
61 } | 70 } |
62 return result; | 71 return result; |
63 } | 72 } |
64 | 73 |
74 void functionImport(const v8::FunctionCallbackInfo<v8::Value>& args) | |
75 { | |
76 v8::Isolate* isolate = args.GetIsolate(); | |
77 RELEASE_ASSERT(isolate && (args.Length() == 1)); | |
78 | |
79 String resourceFileName = toCoreString(args[0]->ToString()); | |
80 String resourceData = loadResourceAsASCIIString(resourceFileName.utf8().data ()); | |
81 RELEASE_ASSERT(resourceData.length()); | |
82 | |
83 if (resourceFileName.endsWith(".js")) { | |
84 compileAndRunPrivateScript(isolate, resourceFileName.replace(".js", ""), resourceData.utf8().data(), resourceData.length()); | |
85 } else if (resourceFileName.endsWith(".css")) { | |
86 v8::Handle<v8::Object> global = isolate->GetCurrentContext()->Global(); | |
87 global->Set(v8String(isolate, "css" + resourceFileName.replace(".css", " ")), v8String(isolate, resourceData)); | |
88 } | |
89 } | |
90 | |
65 // FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the JS files | 91 // FIXME: If we have X.js, XPartial-1.js and XPartial-2.js, currently all of the JS files |
66 // are compiled when any of the JS files is requested. Ideally we should avoid c ompiling | 92 // are compiled when any of the JS files is requested. Ideally we should avoid c ompiling |
67 // unrelated JS files. For example, if a method in XPartial-1.js is requested, w e just | 93 // unrelated JS files. For example, if a method in XPartial-1.js is requested, w e just |
68 // need to compile X.js and XPartial-1.js, and don't need to compile XPartial-2. js. | 94 // need to compile X.js and XPartial-1.js, and don't need to compile XPartial-2. js. |
69 static void installPrivateScript(v8::Isolate* isolate, String className) | 95 static void installPrivateScript(v8::Isolate* isolate, String className) |
70 { | 96 { |
71 int compiledScriptCount = 0; | 97 int compiledScriptCount = 0; |
72 // |kPrivateScriptSourcesForTesting| is defined in V8PrivateScriptSources.h, which is auto-generated | 98 // |kPrivateScriptSourcesForTesting| is defined in V8PrivateScriptSources.h, which is auto-generated |
73 // by make_private_script_source.py. | 99 // by make_private_script_source.py. |
74 #ifndef NDEBUG | 100 #ifndef NDEBUG |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(method), scriptState->executionContext(), holder, argc, argv, scr iptState->isolate()); | 320 v8::Handle<v8::Value> result = V8ScriptRunner::callFunction(v8::Handle<v8::F unction>::Cast(method), scriptState->executionContext(), holder, argc, argv, scr iptState->isolate()); |
295 if (block.HasCaught()) { | 321 if (block.HasCaught()) { |
296 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className); | 322 rethrowExceptionInPrivateScript(scriptState->isolate(), block, scriptSta teInUserScript, ExceptionState::ExecutionContext, methodName, className); |
297 block.ReThrow(); | 323 block.ReThrow(); |
298 return v8::Handle<v8::Value>(); | 324 return v8::Handle<v8::Value>(); |
299 } | 325 } |
300 return result; | 326 return result; |
301 } | 327 } |
302 | 328 |
303 } // namespace blink | 329 } // namespace blink |
OLD | NEW |