Commit 8ed891c8 authored by vivek.vg@samsung.com's avatar vivek.vg@samsung.com

Reland [blink-in-js] Migrate resources required for blink-in-js to grd - part 3

The earlier commit for this was reverted here https://codereview.chromium.org/557543004
as it broke the compilation on Linux GN (dbg) which is tree closer.
http://build.chromium.org/p/chromium.linux/builders/Linux%20GN%20(dbg)

Adding the changes required, the flag --for-testing, in the Source/core/BUILD.gn to include
this flag.

BUG=312586

Review URL: https://codereview.chromium.org/569063002

git-svn-id: svn://svn.chromium.org/blink/trunk@181971 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 04e5fb3b
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "core/PrivateScriptSourcesForTesting.h" #include "core/PrivateScriptSourcesForTesting.h"
#endif #endif
#include "core/dom/ExceptionCode.h" #include "core/dom/ExceptionCode.h"
#include "platform/PlatformResourceLoader.h"
namespace blink { namespace blink {
...@@ -39,10 +40,10 @@ static void dumpV8Message(v8::Handle<v8::Message> message) ...@@ -39,10 +40,10 @@ static void dumpV8Message(v8::Handle<v8::Message> message)
fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, toCoreString(errorMessage).utf8().data()); fprintf(stderr, "%s (line %d): %s\n", fileName.utf8().data(), lineNumber, toCoreString(errorMessage).utf8().data());
} }
static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, String scriptClassName, const unsigned char* source, size_t size) static v8::Handle<v8::Value> compileAndRunPrivateScript(v8::Isolate* isolate, String scriptClassName, const char* source, size_t size)
{ {
v8::TryCatch block; v8::TryCatch block;
String sourceString(reinterpret_cast<const char*>(source), size); String sourceString(source, size);
String fileName = scriptClassName + ".js"; String fileName = scriptClassName + ".js";
v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isolate, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSharableCrossOrigin, V8CacheOptionsOff); v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isolate, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSharableCrossOrigin, V8CacheOptionsOff);
if (block.HasCaught()) { if (block.HasCaught()) {
...@@ -82,7 +83,8 @@ static void installPrivateScript(v8::Isolate* isolate, String className) ...@@ -82,7 +83,8 @@ static void installPrivateScript(v8::Isolate* isolate, String className)
// by make_private_script_source.py. // by make_private_script_source.py.
for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) { for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
if (className == kPrivateScriptSources[index].className) { if (className == kPrivateScriptSources[index].className) {
compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].scriptClassName, kPrivateScriptSources[index].source, kPrivateScriptSources[index].size); String resourceData = loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile);
compileAndRunPrivateScript(isolate, kPrivateScriptSources[index].scriptClassName, resourceData.utf8().data(), resourceData.length());
compiledScriptCount++; compiledScriptCount++;
} }
} }
...@@ -107,7 +109,8 @@ static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate) ...@@ -107,7 +109,8 @@ static v8::Handle<v8::Value> installPrivateScriptRunner(v8::Isolate* isolate)
fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data()); fprintf(stderr, "Private script error: Target source code was not found. (Class name = %s)\n", className.utf8().data());
RELEASE_ASSERT_NOT_REACHED(); RELEASE_ASSERT_NOT_REACHED();
} }
return compileAndRunPrivateScript(isolate, className, kPrivateScriptSources[index].source, kPrivateScriptSources[index].size); String resourceData = loadResourceAsASCIIString(kPrivateScriptSources[index].resourceFile);
return compileAndRunPrivateScript(isolate, className, resourceData.utf8().data(), resourceData.length());
} }
static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptState, String className) static v8::Handle<v8::Object> classObjectOfPrivateScript(ScriptState* scriptState, String className)
......
...@@ -9,6 +9,7 @@ Usage: ...@@ -9,6 +9,7 @@ Usage:
python make_private_script_source.py DESTINATION_FILE SOURCE_FILES python make_private_script_source.py DESTINATION_FILE SOURCE_FILES
""" """
import optparse
import os import os
import re import re
import sys import sys
...@@ -32,34 +33,51 @@ def extract_partial_interface_name(filename): ...@@ -32,34 +33,51 @@ def extract_partial_interface_name(filename):
def main(): def main():
output_filename = sys.argv[1] parser = optparse.OptionParser()
input_filenames = sys.argv[2:] parser.add_option('--for-testing', action="store_true", default=False)
options, args = parser.parse_args()
output_filename = args[0]
input_filenames = args[1:]
source_name, ext = os.path.splitext(os.path.basename(output_filename)) source_name, ext = os.path.splitext(os.path.basename(output_filename))
contents = [] contents = []
for input_filename in input_filenames: contents.append('#ifndef %s_h\n' % source_name)
class_name, ext = os.path.splitext(os.path.basename(input_filename)) contents.append('#define %s_h\n' % source_name)
with open(input_filename) as input_file: if options.for_testing:
input_text = input_file.read() for input_filename in input_filenames:
hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text] class_name, ext = os.path.splitext(os.path.basename(input_filename))
contents.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n\n' % ( with open(input_filename) as input_file:
class_name, ', '.join(hex_values))) input_text = input_file.read()
hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text]
contents.append('const char kSourceOf%s[] = {\n %s\n};\n\n' % (
class_name, ', '.join(hex_values)))
contents.append('struct %s {' % source_name) contents.append('struct %s {' % source_name)
contents.append(""" contents.append("""
const char* scriptClassName; const char* scriptClassName;
const char* className; const char* className;
const unsigned char* source; """)
size_t size; if options.for_testing:
contents.append("""
const char* source;
size_t size;""")
else:
contents.append('const char* resourceFile;')
contents.append("""
}; };
""") """)
contents.append('struct %s k%s[] = {\n' % (source_name, source_name)) contents.append('struct %s k%s[] = {\n' % (source_name, source_name))
for input_filename in input_filenames: for input_filename in input_filenames:
script_class_name, ext = os.path.splitext(os.path.basename(input_filename)) script_class_name, ext = os.path.splitext(os.path.basename(input_filename))
class_name = extract_partial_interface_name(input_filename) or script_class_name class_name = extract_partial_interface_name(input_filename) or script_class_name
contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (script_class_name, class_name, script_class_name, script_class_name)) if options.for_testing:
contents.append(' { "%s", "%s", kSourceOf%s, sizeof(kSourceOf%s) },\n' % (script_class_name, class_name, script_class_name, script_class_name))
else:
contents.append(' { "%s", "%s", "%s.js" },\n' % (script_class_name, class_name, script_class_name))
contents.append('};\n') contents.append('};\n')
contents.append('#endif // %s_h\n' % source_name)
with open(output_filename, 'w') as output_file: with open(output_filename, 'w') as output_file:
output_file.write("".join(contents)) output_file.write("".join(contents))
......
...@@ -942,7 +942,8 @@ action("make_core_generated_private_script_for_testing") { ...@@ -942,7 +942,8 @@ action("make_core_generated_private_script_for_testing") {
"$blink_core_output_dir/PrivateScriptSourcesForTesting.h", "$blink_core_output_dir/PrivateScriptSourcesForTesting.h",
] ]
args = rebase_path(outputs, root_build_dir) args = [ "--for-testing" ]
args += rebase_path(outputs, root_build_dir)
args += rebase_path(inputs, root_build_dir) args += rebase_path(inputs, root_build_dir)
deps = make_core_generated_deps deps = make_core_generated_deps
......
...@@ -183,6 +183,7 @@ ...@@ -183,6 +183,7 @@
'action': [ 'action': [
'python', 'python',
'../build/scripts/make_private_script_source.py', '../build/scripts/make_private_script_source.py',
'--for-testing',
'<@(_outputs)', '<@(_outputs)',
'<@(_private_script_files)' '<@(_private_script_files)'
], ],
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "PlatformResourceLoader.h"
#include "public/platform/Platform.h"
#include "public/platform/WebData.h"
namespace blink {
String loadResourceAsASCIIString(const char* resource)
{
const WebData& resourceData = Platform::current()->loadResource(resource);
String dataString(resourceData.data(), resourceData.size());
ASSERT(!dataString.isEmpty() && dataString.containsOnlyASCII());
return dataString;
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PlatformResourceLoader_h
#define PlatformResourceLoader_h
#include "platform/PlatformExport.h"
#include "wtf/text/WTFString.h"
namespace blink {
PLATFORM_EXPORT String loadResourceAsASCIIString(const char* resource);
} // namespace blink
#endif // PlatformResourceLoader_h
...@@ -91,6 +91,8 @@ ...@@ -91,6 +91,8 @@
'PlatformKeyboardEvent.cpp', 'PlatformKeyboardEvent.cpp',
'PlatformKeyboardEvent.h', 'PlatformKeyboardEvent.h',
'PlatformMouseEvent.h', 'PlatformMouseEvent.h',
'PlatformResourceLoader.cpp',
'PlatformResourceLoader.h',
'PlatformScreen.cpp', 'PlatformScreen.cpp',
'PlatformScreen.h', 'PlatformScreen.h',
'PlatformThreadData.cpp', 'PlatformThreadData.cpp',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment