Changeset 218316 in webkit
- Timestamp:
- Jun 14, 2017, 10:57:27 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSWrapperMap.mm
r217240 r218316 1 1 /* 2 * Copyright (C) 2013-2015 Apple Inc. All rights reserved.2 * Copyright (C) 2013-2015, 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 413 413 Protocol *exportProtocol = getJSExportProtocol(); 414 414 for (Class currentClass = cls; currentClass; currentClass = class_getSuperclass(currentClass)) { 415 forEachProtocolImplementingProtocol(currentClass, exportProtocol, ^(Protocol *protocol ) {415 forEachProtocolImplementingProtocol(currentClass, exportProtocol, ^(Protocol *protocol, bool&) { 416 416 forEachMethodInProtocol(protocol, YES, YES, ^(SEL selector, const char*) { 417 417 const char* name = sel_getName(selector); … … 491 491 492 492 Protocol *exportProtocol = getJSExportProtocol(); 493 forEachProtocolImplementingProtocol(m_class, exportProtocol, ^(Protocol *protocol ){493 forEachProtocolImplementingProtocol(m_class, exportProtocol, ^(Protocol *protocol, bool&){ 494 494 copyPrototypeProperties(context, m_class, protocol, prototype); 495 495 copyMethodsToObject(context, m_class, protocol, NO, constructor); … … 588 588 589 589 // Skip internal classes beginning with '_' - just copy link to the parent class's info. 590 if ('_' == *class_getName(cls)) 591 return m_classMap[cls] = [self classInfoForClass:class_getSuperclass(cls)]; 590 if ('_' == *class_getName(cls)) { 591 bool conformsToExportProtocol = false; 592 forEachProtocolImplementingProtocol(cls, getJSExportProtocol(), [&conformsToExportProtocol](Protocol *, bool& stop) { 593 conformsToExportProtocol = true; 594 stop = true; 595 }); 596 597 if (!conformsToExportProtocol) 598 return m_classMap[cls] = [self classInfoForClass:class_getSuperclass(cls)]; 599 } 592 600 593 601 return m_classMap[cls] = [[[JSObjCClassInfo alloc] initForClass:cls] autorelease]; -
trunk/Source/JavaScriptCore/API/ObjcRuntimeExtras.h
r185122 r218316 1 1 /* 2 * Copyright (C) 2013 Apple Inc. All rights reserved.2 * Copyright (C) 2013, 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 43 43 } 44 44 45 inline void forEachProtocolImplementingProtocol(Class cls, Protocol *target, void (^callback)(Protocol * ))45 inline void forEachProtocolImplementingProtocol(Class cls, Protocol *target, void (^callback)(Protocol *, bool& stop)) 46 46 { 47 47 ASSERT(cls); … … 57 57 free(protocols); 58 58 59 bool stop = false; 59 60 while (!worklist.isEmpty()) { 60 61 Protocol *protocol = worklist.last(); … … 66 67 67 68 // If it implements the protocol, make the callback. 68 if (protocolImplementsProtocol(protocol, target)) 69 callback(protocol); 69 if (protocolImplementsProtocol(protocol, target)) { 70 callback(protocol, stop); 71 if (stop) 72 break; 73 } 70 74 71 75 // Add incorporated protocols to the worklist. -
trunk/Source/JavaScriptCore/API/tests/JSExportTests.mm
r217517 r218316 1 1 /* 2 * Copyright (C) 2014 Apple Inc. All rights reserved.2 * Copyright (C) 2014, 2017 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 81 81 @end 82 82 83 @interface NoUnderscorePrefix : NSObject 84 @end 85 86 @implementation NoUnderscorePrefix 87 @end 88 89 @interface _UnderscorePrefixNoExport : NoUnderscorePrefix 90 @end 91 92 @implementation _UnderscorePrefixNoExport 93 @end 94 95 @protocol Initializing <JSExport> 96 - (instancetype)init; 97 @end 98 99 @interface _UnderscorePrefixWithExport : NoUnderscorePrefix <Initializing> 100 @end 101 102 @implementation _UnderscorePrefixWithExport 103 @end 104 83 105 @implementation JSExportTests 84 106 + (void) exportInstanceMethodWithIdProtocolTest … … 124 146 checkResult(@"Dynamically generated JSExport-ed protocols are ignored", [value isUndefined] && !!context.exception); 125 147 } 148 149 + (void)classNamePrefixedWithUnderscoreTest 150 { 151 JSContext *context = [[JSContext alloc] init]; 152 153 context[@"_UnderscorePrefixNoExport"] = [_UnderscorePrefixNoExport class]; 154 context[@"_UnderscorePrefixWithExport"] = [_UnderscorePrefixWithExport class]; 155 156 checkResult(@"Non-underscore-prefixed ancestor class used when there are no exports", [context[@"_UnderscorePrefixNoExport"] toObject] == [NoUnderscorePrefix class]); 157 checkResult(@"Underscore-prefixed class used when there are exports", [context[@"_UnderscorePrefixWithExport"] toObject] == [_UnderscorePrefixWithExport class]); 158 159 JSValue *withExportInstance = [context evaluateScript:@"new _UnderscorePrefixWithExport()"]; 160 checkResult(@"Exports present on underscore-prefixed class", !context.exception && !withExportInstance.isUndefined); 161 } 162 126 163 @end 127 164 … … 172 209 [JSExportTests exportInstanceMethodWithClassProtocolTest]; 173 210 [JSExportTests exportDynamicallyGeneratedProtocolTest]; 211 [JSExportTests classNamePrefixedWithUnderscoreTest]; 174 212 } 175 213 wrapperLifetimeIsTiedToGlobalObject(); -
trunk/Source/JavaScriptCore/ChangeLog
r218312 r218316 1 2017-06-14 Dan Bernstein <mitz@apple.com> 2 3 [Cocoa] Objective-C class whose name begins with an underscore can’t be exported to JavaScript 4 https://bugs.webkit.org/show_bug.cgi?id=168578 5 6 Reviewed by Geoff Garen. 7 8 * API/JSWrapperMap.mm: 9 (allocateConstructorForCustomClass): Updated for change to forEachProtocolImplementingProtocol. 10 (-[JSObjCClassInfo allocateConstructorAndPrototype]): Ditto. 11 (-[JSWrapperMap classInfoForClass:]): If the class name begins with an underscore, check if 12 it defines conformance to a JSExport-derived protocol and if so, avoid using the 13 superclass as a substitute as we’d normally do. 14 15 * API/ObjcRuntimeExtras.h: 16 (forEachProtocolImplementingProtocol): Added a "stop" argument to the block to let callers 17 bail out. 18 19 * API/tests/JSExportTests.mm: 20 (+[JSExportTests classNamePrefixedWithUnderscoreTest]): New test for this. 21 (runJSExportTests): Run new test. 22 1 23 2017-06-14 Yusuke Suzuki <utatane.tea@gmail.com> 2 24
Note:
See TracChangeset
for help on using the changeset viewer.