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 @@
#include "core/PrivateScriptSourcesForTesting.h"
#endif
#include "core/dom/ExceptionCode.h"
#include "platform/PlatformResourceLoader.h"
namespace blink {
......@@ -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());
}
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;
String sourceString(reinterpret_cast<const char*>(source), size);
String sourceString(source, size);
String fileName = scriptClassName + ".js";
v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(v8String(isolate, sourceString), fileName, TextPosition::minimumPosition(), 0, isolate, NotSharableCrossOrigin, V8CacheOptionsOff);
if (block.HasCaught()) {
......@@ -82,7 +83,8 @@ static void installPrivateScript(v8::Isolate* isolate, String className)
// by make_private_script_source.py.
for (size_t index = 0; index < WTF_ARRAY_LENGTH(kPrivateScriptSources); index++) {
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++;
}
}
......@@ -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());
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)
......
......@@ -9,6 +9,7 @@ Usage:
python make_private_script_source.py DESTINATION_FILE SOURCE_FILES
"""
import optparse
import os
import re
import sys
......@@ -32,34 +33,51 @@ def extract_partial_interface_name(filename):
def main():
output_filename = sys.argv[1]
input_filenames = sys.argv[2:]
parser = optparse.OptionParser()
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))
contents = []
contents.append('#ifndef %s_h\n' % source_name)
contents.append('#define %s_h\n' % source_name)
if options.for_testing:
for input_filename in input_filenames:
class_name, ext = os.path.splitext(os.path.basename(input_filename))
with open(input_filename) as input_file:
input_text = input_file.read()
hex_values = ['0x{0:02x}'.format(ord(char)) for char in input_text]
contents.append('const unsigned char kSourceOf%s[] = {\n %s\n};\n\n' % (
contents.append('const char kSourceOf%s[] = {\n %s\n};\n\n' % (
class_name, ', '.join(hex_values)))
contents.append('struct %s {' % source_name)
contents.append("""
const char* scriptClassName;
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))
for input_filename in input_filenames:
script_class_name, ext = os.path.splitext(os.path.basename(input_filename))
class_name = extract_partial_interface_name(input_filename) or 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('#endif // %s_h\n' % source_name)
with open(output_filename, 'w') as output_file:
output_file.write("".join(contents))
......
......@@ -942,7 +942,8 @@ action("make_core_generated_private_script_for_testing") {
"$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)
deps = make_core_generated_deps
......
......@@ -183,6 +183,7 @@
'action': [
'python',
'../build/scripts/make_private_script_source.py',
'--for-testing',
'<@(_outputs)',
'<@(_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 @@
'PlatformKeyboardEvent.cpp',
'PlatformKeyboardEvent.h',
'PlatformMouseEvent.h',
'PlatformResourceLoader.cpp',
'PlatformResourceLoader.h',
'PlatformScreen.cpp',
'PlatformScreen.h',
'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